[jbpm-commits] JBoss JBPM SVN: r6747 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/svc and 4 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Oct 7 05:40:50 EDT 2010
Author: alex.guizar at jboss.com
Date: 2010-10-07 05:40:50 -0400 (Thu, 07 Oct 2010)
New Revision: 6747
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/HistoryService.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Converter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/BooleanToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ByteToLongConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/CharacterToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToLongConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DoubleToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToDoubleConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/IntegerToLongConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/SerializableToBytesConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ShortToLongConverter.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/eventlistener/EventListenerTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/DeserializeVariableTest.java
Log:
JBPM-2069 make converters handle null values consistently with conditions in their supports() method
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/HistoryService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/HistoryService.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/HistoryService.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -56,12 +56,12 @@
/** returns for each transitionName, the number of times that transition was taken */
Map<String, Number> choiceDistribution(String processDefinitionId, String activityName);
+ /** all the variables visible in the given history execution scope */
+ Set<String> getVariableNames(String executionId);
+
/** retrieves a variable */
- Set<String> getVariableNames(String processInstanceId);
+ Object getVariable(String executionId, String variableName);
/** retrieves a map of variables */
- Object getVariable(String processInstanceId, String variableName);
-
- /** all the variables visible in the given history execution scope */
- Map<String, ?> getVariables(String processInstanceId, Set<String> variableNames);
+ Map<String, ?> getVariables(String executionId, Set<String> variableNames);
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -81,17 +81,17 @@
return query;
}
- public Set<String> getVariableNames(String processInstanceId) {
- return commandService.execute(new GetHistoryVariableNamesCmd(processInstanceId));
+ public Set<String> getVariableNames(String executionId) {
+ return commandService.execute(new GetHistoryVariableNamesCmd(executionId));
}
- public Object getVariable(String processInstanceId, String variableName) {
- Set<String> variableNames = Collections.singleton(variableName);
- Map<String, ?> variables = commandService.execute(new GetHistoryVariablesCmd(processInstanceId, variableNames));
+ public Object getVariable(String executionId, String variableName) {
+ Map<String, ?> variables = commandService.execute(new GetHistoryVariablesCmd(executionId,
+ Collections.singleton(variableName)));
return variables.get(variableName);
}
- public Map<String, ?> getVariables(String processInstanceId, Set<String> variableNames) {
- return commandService.execute(new GetHistoryVariablesCmd(processInstanceId, variableNames));
+ public Map<String, ?> getVariables(String executionId, Set<String> variableNames) {
+ return commandService.execute(new GetHistoryVariablesCmd(executionId, variableNames));
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Converter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Converter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Converter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -28,20 +28,20 @@
/**
* @author Tom Baeyens
*/
-public interface Converter extends Serializable {
+public interface Converter<S, T> extends Serializable {
/**
- * is true if this converter supports the given type, false otherwise.
+ * is true if this converter supports the given value, false otherwise.
*/
boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable);
/**
* converts a given object to its persistable format.
*/
- Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable);
+ T convert(S o, ScopeInstanceImpl scopeInstance, Variable variable);
/**
* reverts a persisted object to its original formResourceName.
*/
- Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable);
+ S revert(T o, ScopeInstanceImpl scopeInstance, Variable variable);
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/BooleanToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/BooleanToStringConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/BooleanToStringConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,31 +25,22 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class BooleanToStringConverter implements Converter {
-
+public class BooleanToStringConverter implements Converter<Boolean, String> {
+
private static final long serialVersionUID = 1L;
-
+
public static final String TRUE_TEXT = "T";
public static final String FALSE_TEXT = "F";
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Boolean.class);
+ return value instanceof Boolean || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- String convertedValue = FALSE_TEXT;
- if (((Boolean)o).booleanValue()) {
- convertedValue = TRUE_TEXT;
- }
- return convertedValue;
+ public String convert(Boolean o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? o.booleanValue() ? TRUE_TEXT : FALSE_TEXT : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- Boolean revertedValue = Boolean.FALSE;
- if (TRUE_TEXT.equals(o)) {
- revertedValue = Boolean.TRUE;
- }
- return revertedValue;
+ public Boolean revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? TRUE_TEXT.equals(o) ? Boolean.TRUE : Boolean.FALSE : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ByteToLongConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ByteToLongConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ByteToLongConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,20 +25,19 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class ByteToLongConverter implements Converter {
-
+public class ByteToLongConverter implements Converter<Byte, Long> {
+
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Byte.class);
+ return value instanceof Byte || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Long( ((Number)o).longValue() );
+ public Long convert(Byte o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Long.valueOf(o.longValue()) : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Byte(((Long)o).byteValue());
+ public Byte revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Byte.valueOf(o.byteValue()) : null;
}
}
\ No newline at end of file
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/CharacterToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/CharacterToStringConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/CharacterToStringConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,20 +25,19 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class CharacterToStringConverter implements Converter {
+public class CharacterToStringConverter implements Converter<Character, String> {
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Character.class);
+ return value instanceof Character || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return o.toString();
+ public String convert(Character o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? o.toString() : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Character(((String)o).charAt(0));
+ public Character revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new Character(o.charAt(0)) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToLongConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToLongConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToLongConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -27,20 +27,19 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class DateToLongConverter implements Converter {
+public class DateToLongConverter implements Converter<Date, Long> {
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (Date.class.isAssignableFrom(value.getClass()));
+ return value instanceof Date || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Long(((Date)o).getTime());
+ public Long convert(Date o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Long.valueOf(o.getTime()) : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Date(((Long)o).longValue());
+ public Date revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new Date(o.longValue()) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToStringConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToStringConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -21,7 +21,6 @@
*/
package org.jbpm.pvm.internal.type.converter;
-import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -34,30 +33,29 @@
/**
* @author Tom Baeyens
*/
-public class DateToStringConverter implements Converter {
+public class DateToStringConverter implements Converter<Date, String> {
private static final long serialVersionUID = 1L;
private String format = "yyyy-MM-dd HH:mm:ss,SSS";
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- DateFormat dateFormat = new SimpleDateFormat(format);
- return dateFormat.format((Date) o);
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return value instanceof Date || value == null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public String convert(Date o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new SimpleDateFormat(format).format(o) : null;
+ }
+
+ public Date revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
try {
- DateFormat dateFormat = new SimpleDateFormat(format);
- return dateFormat.parseObject((String) o);
- } catch (ParseException e) {
+ return o != null ? new SimpleDateFormat(format).parse(o) : null;
+ }
+ catch (ParseException e) {
throw new JbpmException("invalid date format in date variable: " + o, e);
}
}
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- return ((value != null) && (value instanceof Date));
- }
-
public void setFormat(String format) {
this.format = format;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DoubleToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DoubleToStringConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DoubleToStringConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,21 +25,20 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class DoubleToStringConverter implements Converter {
+public class DoubleToStringConverter implements Converter<Double, String> {
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Double.class);
+ return value instanceof Double || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return o.toString();
+ public String convert(Double o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? o.toString() : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Double((String)o);
+ public Double revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new Double(o) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToDoubleConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToDoubleConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToDoubleConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,21 +25,20 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class FloatToDoubleConverter implements Converter {
+public class FloatToDoubleConverter implements Converter<Float, Double> {
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Float.class);
+ return value instanceof Float || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Double(((Float)o).doubleValue());
+ public Double convert(Float o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new Double(o.doubleValue()) : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Float(((Double)o).floatValue());
+ public Float revert(Double o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new Float(o.floatValue()) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToStringConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToStringConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,21 +25,20 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class FloatToStringConverter implements Converter {
+public class FloatToStringConverter implements Converter<Float, String> {
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Float.class);
+ return value instanceof Float || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return o.toString();
+ public String convert(Float o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? o.toString() : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Float((String)o);
+ public Float revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new Float(o) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/IntegerToLongConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/IntegerToLongConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/IntegerToLongConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,20 +25,19 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class IntegerToLongConverter implements Converter {
-
+public class IntegerToLongConverter implements Converter<Integer, Long> {
+
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (Integer.class.equals(value.getClass()));
+ return value instanceof Integer || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Long( ((Number)o).longValue() );
+ public Long convert(Integer o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Long.valueOf(o.longValue()) : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Integer(((Long)o).intValue());
+ public Integer revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Integer.valueOf(o.intValue()) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/SerializableToBytesConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/SerializableToBytesConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/SerializableToBytesConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -24,6 +24,7 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
@@ -38,56 +39,60 @@
import org.jbpm.pvm.internal.type.Variable;
import org.jbpm.pvm.internal.type.variable.BlobVariable;
-public class SerializableToBytesConverter implements Converter {
+public class SerializableToBytesConverter implements Converter<Object, byte[]> {
private static final long serialVersionUID = 1L;
-
+
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return Serializable.class.isAssignableFrom(value.getClass());
+ return value instanceof Serializable || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- byte[] bytes = null;
+ public byte[] convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ if (o == null) return null;
+
try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(o);
- oos.flush();
- bytes = baos.toByteArray();
+ // serialize object to byte array
+ ByteArrayOutputStream memoryStream = new ByteArrayOutputStream();
+ ObjectOutputStream objectStream = new ObjectOutputStream(memoryStream);
+ objectStream.writeObject(o);
+ objectStream.close();
+ byte[] bytes = memoryStream.toByteArray();
+ // allow for automatic update of serialized objects
Transaction transaction = EnvironmentImpl.getFromCurrent(Transaction.class, false);
- if (transaction!=null) {
- transaction.registerDeserializedObject(new DeserializedObject(o, scopeInstance, (BlobVariable) variable));
+ if (transaction != null) {
+ transaction.registerDeserializedObject(new DeserializedObject(o, scopeInstance,
+ (BlobVariable) variable));
}
-
- } catch (IOException e) {
- throw new JbpmException("couldn't serialize '"+o+"'", e);
+ return bytes;
}
-
- return bytes;
+ catch (IOException e) {
+ throw new JbpmException("failed to serialize: " + o, e);
+ }
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- byte[] bytes = (byte[]) o;
+ public Object revert(byte[] o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ if (o == null) return null;
+
try {
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStream objectStream = new DeploymentObjectInputStream(new ByteArrayInputStream(o),
+ scopeInstance.getExecution().getProcessDefinition().getDeploymentId());
+ Object object = objectStream.readObject();
+ objectStream.close();
- ObjectInputStream ois = null;
-
- ois = new DeploymentObjectInputStream(bais, scopeInstance.getExecution().getProcessDefinition().getDeploymentId());
-
- Object object = ois.readObject();
-
+ // allow for automatic update of deserialized objects
Transaction transaction = EnvironmentImpl.getFromCurrent(Transaction.class, false);
- if (transaction!=null) {
- transaction.registerDeserializedObject(new DeserializedObject(object, scopeInstance, (BlobVariable) variable));
+ if (transaction != null) {
+ transaction.registerDeserializedObject(new DeserializedObject(object, scopeInstance,
+ (BlobVariable) variable));
}
-
return object;
-
- } catch (Exception e) {
- throw new JbpmException("couldn't deserialize object", e);
}
+ catch (IOException ex) {
+ throw new JbpmException("failed to deserialize object", ex);
+ }
+ catch (ClassNotFoundException ex) {
+ throw new JbpmException("serialized class not found", ex);
+ }
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ShortToLongConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ShortToLongConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ShortToLongConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,20 +25,19 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class ShortToLongConverter implements Converter {
-
+public class ShortToLongConverter implements Converter<Short, Long> {
+
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Short.class);
+ return value instanceof Short || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Long( ((Number)o).longValue() );
+ public Long convert(Short o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Long.valueOf(o.longValue()) : null;
}
-
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Short(((Long)o).shortValue());
+
+ public Short revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Short.valueOf(o.shortValue()) : null;
}
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/eventlistener/EventListenerTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/eventlistener/EventListenerTest.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/eventlistener/EventListenerTest.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -29,6 +29,7 @@
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.listener.EventListener;
import org.jbpm.api.listener.EventListenerExecution;
+import org.jbpm.pvm.internal.util.CollectionUtil;
import org.jbpm.test.JbpmTestCase;
@@ -72,11 +73,7 @@
private static final long serialVersionUID = 1L;
public void notify(EventListenerExecution execution) {
Integer invocations = (Integer) execution.getVariable("invocations");
- if (invocations==null) {
- execution.setVariable("invocations", 1);
- } else {
- execution.setVariable("invocations", invocations+1);
- }
+ execution.setVariable("invocations", invocations != null ? invocations + 1 : 1);
}
}
@@ -108,6 +105,35 @@
assertEquals(3, executionService.getVariable(processInstanceId, "invocations"));
}
+ public void testProcessEndListenerPropagation() {
+ deployJpdlXmlString(
+ "<process name='Insurance claim' key='ICL' xmlns='http://jbpm.org/4.4/jpdl'>" +
+ " <variable name='invocations' type='integer' history='true' />" +
+ " <on event='end'>" +
+ " <event-listener propagation='enabled' class='"+PropagationEnabledListener.class.getName()+"' />" +
+ " </on>" +
+ " <start>" +
+ " <transition to='a' />" +
+ " </start>" +
+ " <state name='a'>" +
+ " <transition to='b' />" +
+ " </state>" +
+ " <end name='b' />" +
+ "</process>"
+ );
+
+ String processInstanceId = executionService.startProcessInstanceByKey("ICL").getId();
+
+ // the event listener is invoked once for the end event of the start activity
+ assertEquals(1, executionService.getVariable(processInstanceId, "invocations"));
+
+ executionService.signalExecutionById(processInstanceId);
+
+ // the listener is invoked twice more for the end event of activity a
+ // and the end event of the process
+ assertEquals("3", historyService.getVariable(processInstanceId, "invocations"));
+ }
+
public static class ActivityStartListener implements EventListener {
private static final long serialVersionUID = 1L;
public void notify(EventListenerExecution execution) {
@@ -197,7 +223,8 @@
private static final long serialVersionUID = 1L;
int i;
public void notify(EventListenerExecution execution) {
- List<Integer> order = (List<Integer>) execution.getVariable("order");
+ List<Integer> order = CollectionUtil.checkList((List<?>) execution.getVariable("order"),
+ Integer.class);
order.add(i);
execution.setVariable("order", order);
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/DeserializeVariableTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/DeserializeVariableTest.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/DeserializeVariableTest.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -3,91 +3,83 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
+import java.io.IOException;
import java.util.List;
+import org.codehaus.janino.CompileException;
+import org.codehaus.janino.Compiler;
import org.codehaus.janino.DebuggingInformation;
+import org.codehaus.janino.Parser.ParseException;
+import org.codehaus.janino.Scanner.ScanException;
import org.codehaus.janino.util.StringPattern;
import org.codehaus.janino.util.enumerator.EnumeratorSet;
+
+import org.jbpm.api.JbpmException;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.task.Task;
import org.jbpm.test.JbpmTestCase;
-
public class DeserializeVariableTest extends JbpmTestCase {
- String deploymentId;
-
protected void setUp() throws Exception {
-
super.setUp();
-
+
generateBeanClass();
-
- deploymentId = repositoryService.createDeployment()
- .addResourceFromClasspath("org/jbpm/test/variables/DeserializeTaskTest.jpdl.xml")
- .addResourceFromInputStream("org/jbpm/test/variables/Bean.class", new FileInputStream(new File("target/generated/org/jbpm/test/variables/Bean.class")))
- .deploy();
+ String deploymentId = repositoryService.createDeployment()
+ .addResourceFromClasspath("org/jbpm/test/variables/DeserializeTaskTest.jpdl.xml")
+ .addResourceFromInputStream("org/jbpm/test/variables/Bean.class",
+ new FileInputStream(new File("target/generated/org/jbpm/test/variables/Bean.class")))
+ .deploy();
+ registerDeployment(deploymentId);
}
- protected void tearDown() throws Exception {
- repositoryService.deleteDeploymentCascade(deploymentId);
- super.tearDown();
- }
-
-
public void testDeserializeVariable() {
ProcessInstance processInstance = executionService.startProcessInstanceByKey("DeserializeTaskTest");
String processInstanceId = processInstance.getId();
List<Task> tasks = taskService.findPersonalTasks("alex");
-
- assertTrue(tasks.size() == 1);
-
+ assertEquals(1, tasks.size());
+
Task task = tasks.get(0);
-
assertNotNull(taskService.getVariable(task.getId(), "bean"));
-
assertNotNull(executionService.getVariable(processInstanceId, "bean"));
-
+
taskService.completeTask(task.getId());
}
-
+
/**
- * This method is used to generate source class that will be used within a process but should not be
- * on class path while executing process but retrieved from db.
+ * This method is used to generate the bean class that will be used within a process. The
+ * class must not be in the classpath while executing the process. It must be retrieved from
+ * the database instead.
*
- * Uses Janinio to compile the source.
+ * Uses Janino to compile the source.
*/
- public void generateBeanClass() {
-
+ private void generateBeanClass() {
log.debug("Inside generateBeanClass method");
File directory = new File("target/generated/org/jbpm/test/variables");
if (!directory.exists()) {
log.debug("No generated class directory, about to create source file");
+ directory.mkdirs();
+
+ String source = "package org.jbpm.test.variables;\n"
+ + "import java.io.Serializable;\n"
+ + "public class Bean implements Serializable {\n"
+ + "private static final long serialVersionUID = -5510563444135221777L;\n"
+ + " private String value;\n"
+ + " public Bean getResult() {\n"
+ + " this.value = \"test\";\n"
+ + " return this;\n"
+ + " }\n"
+ + "}\n";
+
try {
- directory.mkdirs();
File sourceFile = new File(directory, "Bean.java");
FileWriter writer = new FileWriter(sourceFile);
-
- StringBuffer source = new StringBuffer();
-
- source.append("package org.jbpm.test.variables;\n");
- source.append("import java.io.Serializable;\n");
- source.append("public class Bean implements Serializable {\n");
- source.append("private static final long serialVersionUID = -5510563444135221777L;\n");
- source.append(" private String value;\n");
- source.append(" public Bean getResult() {\n");
- source.append(" this.value = \"test\";\n");
- source.append(" return this;\n");
- source.append(" }\n");
- source.append("}\n");
-
- writer.write(source.toString());
-
+ writer.write(source);
writer.close();
- log.debug("Source file create in " + directory.getAbsolutePath());
+ log.debug("Source file created in " + directory.getAbsolutePath());
File destinationDirectory = org.codehaus.janino.Compiler.NO_DESTINATION_DIRECTORY;
File[] optionalSourcePath = null;
@@ -97,22 +89,28 @@
String optionalCharacterEncoding = null;
boolean verbose = false;
EnumeratorSet debuggingInformation = DebuggingInformation.DEFAULT_DEBUGGING_INFORMATION;
- StringPattern[] warningHandlePatterns = org.codehaus.janino.Compiler.DEFAULT_WARNING_HANDLE_PATTERNS;
+ StringPattern[] warningHandlePatterns = Compiler.DEFAULT_WARNING_HANDLE_PATTERNS;
boolean rebuild = false;
-
- log.debug("About to run Janinio compiler");
-
- org.codehaus.janino.Compiler javac = new org.codehaus.janino.Compiler(optionalSourcePath, classPath, optionalExtDirs, optionalBootClassPath,
- destinationDirectory, optionalCharacterEncoding, verbose, debuggingInformation, warningHandlePatterns, rebuild);
- javac.compile(new File[] { sourceFile });
+ log.debug("About to run Janino compiler");
+ Compiler javac = new Compiler(optionalSourcePath, classPath, optionalExtDirs,
+ optionalBootClassPath, destinationDirectory, optionalCharacterEncoding, verbose,
+ debuggingInformation, warningHandlePatterns, rebuild);
+ javac.compile(new File[] { sourceFile });
log.debug("Class compiled successfully");
- } catch (Exception e) {
-
- log.error("Error while creating additional resources", e);
}
+ catch (ScanException e) {
+ throw new JbpmException("scan failed", e);
+ }
+ catch (ParseException e) {
+ throw new JbpmException("parse failed", e);
+ }
+ catch (CompileException e) {
+ throw new JbpmException("compile failed", e);
+ }
+ catch (IOException e) {
+ throw new JbpmException("i/o operation failed", e);
+ }
}
-
}
-
}
More information about the jbpm-commits
mailing list