Author: alex.guizar(a)jboss.com
Date: 2010-10-08 23:46:44 -0400 (Fri, 08 Oct 2010)
New Revision: 6749
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/ConverterType.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/DeserializedObject.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/DefaultTypeSet.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Type.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeMapping.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeSet.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.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/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/ClobVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DateVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DoubleVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateLongVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateStringVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/LongVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/NullVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/StringVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/TextVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/UnpersistableVariable.java
jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java
Log:
JBPM-2069 generalize Variable and its subclasses
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/ConverterType.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/ConverterType.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/ConverterType.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -28,6 +28,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import java.util.Map.Entry;
import org.hibernate.HibernateException;
import org.hibernate.type.ImmutableType;
@@ -41,12 +42,13 @@
*/
public class ConverterType extends ImmutableType implements ParameterizedType {
+ private final Map<Class<?>, String> converterNames = new
HashMap<Class<?>, String>();
+ private final Map<String, Converter<?, ?>> converters = new
HashMap<String, Converter<?, ?>>();
+
private static final long serialVersionUID = 1L;
- private static Map<Class<?>, String> converterNames = null;
- private static Map<String, Converter> converters = null;
- public Object fromStringValue(String arg0) throws HibernateException {
- return null;
+ public Object fromStringValue(String value) throws HibernateException {
+ return converters.get(value);
}
public Object get(ResultSet resultSet, String name) throws HibernateException,
SQLException {
@@ -54,17 +56,18 @@
return converters.get(converterName);
}
- public void set(PreparedStatement stmt, Object value, int index) throws
HibernateException, SQLException {
- String converterName = (value!=null ? converterNames.get(value.getClass()) : null);
- stmt.setString(index, converterName);
+ public void set(PreparedStatement statement, Object value, int index)
+ throws HibernateException, SQLException {
+ String converterName = value != null ? converterNames.get(value.getClass()) : null;
+ statement.setString(index, converterName);
}
public int sqlType() {
return Types.VARCHAR;
}
- public String toString(Object arg0) throws HibernateException {
- return null;
+ public String toString(Object value) throws HibernateException {
+ return value != null ? converterNames.get(value.getClass()) : null;
}
public String getName() {
@@ -76,21 +79,27 @@
}
public void setParameterValues(Properties properties) {
- converterNames = new HashMap<Class<?>, String>();
- converters = new HashMap<String, Converter>();
-
- for(Object key : properties.keySet()) {
- String converterClassName = (String) key;
+ for (Entry<Object, Object> entry : properties.entrySet()) {
+ String converterName = (String) entry.getKey();
+ String converterClassName = (String) entry.getValue();
try {
- Class< ? > converterClass = ReflectUtil.classForName(converterClassName);
+ Class<?> converterClass = ReflectUtil.classForName(converterClassName);
+ converterNames.put(converterClass, converterName);
- String converterName = properties.getProperty(converterClassName);
- converterNames.put(converterClass, converterName);
- Converter converter = (Converter) converterClass.newInstance();
- converters.put(converterName, converter);
- } catch (Exception e) {
- throw new JbpmException("couldn't initialize converter type
"+converterClassName, e);
+ try {
+ Converter<?, ?> converter = (Converter<?, ?>)
converterClass.newInstance();
+ converters.put(converterName, converter);
+ }
+ catch (InstantiationException e) {
+ throw new JbpmException("failed to instantiate " + converterClass,
e);
+ }
+ catch (IllegalAccessException e) {
+ throw new JbpmException(getClass() + " has no access to " +
converterClass, e);
+ }
}
+ catch (ClassNotFoundException e) {
+ throw new JbpmException("missing converter class: " +
converterClassName, e);
+ }
}
}
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -130,7 +130,7 @@
protected int priority = Priority.NORMAL;
- protected Map<String, Variable> systemVariables = new HashMap<String,
Variable>();
+ protected Map<String, Variable<?>> systemVariables = new HashMap<String,
Variable<?>>();
// persistent indicators of the current position ////////////////////////////
@@ -1003,12 +1003,12 @@
}
public void createSystemVariable(String key, Object value, String typeName) {
- Variable variable = createVariableObject(key, value, typeName, false);
+ Variable<?> variable = createVariableObject(key, value, typeName, false);
systemVariables.put(variable.getKey(), variable);
}
public void setSystemVariable(String key, Object value) {
- Variable variable = systemVariables.get(key);
+ Variable<?> variable = systemVariables.get(key);
if (variable!=null) {
log.debug("setting system variable '"+key+"' in
'"+this+"' to value '"+value+"'");
variable.setValue(value, this);
@@ -1020,7 +1020,7 @@
}
public Object getSystemVariable(String key) {
- Variable variable = systemVariables.get(key);
+ Variable<?> variable = systemVariables.get(key);
if (variable!=null) {
return variable.getValue(this);
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -49,7 +49,6 @@
import org.jbpm.pvm.internal.type.variable.UnpersistableVariable;
import org.jbpm.pvm.internal.util.Clock;
-
/**
* @author Tom Baeyens
*/
@@ -57,13 +56,13 @@
private static final long serialVersionUID = 1L;
private static Log log = Log.getLog(ScopeInstanceImpl.class.getName());
-
+
protected long dbid;
protected int dbversion;
protected boolean hasVariables;
- protected Map<String, Variable> variables = new HashMap<String,
Variable>();
-
+ protected Map<String, Variable<?>> variables = new HashMap<String,
Variable<?>>();
+
protected String state;
protected String suspendHistoryState;
@@ -75,11 +74,11 @@
protected void initializeVariables(ScopeElementImpl scope, ExecutionImpl
outerExecution) {
// loop over all variable definitions
List<VariableDefinitionImpl> variableDefinitions =
scope.getVariableDefinitions();
- if (!variableDefinitions.isEmpty()){
+ if (!variableDefinitions.isEmpty()) {
if (log.isTraceEnabled()) {
- log.trace("initializing variables in scope "+scope);
+ log.trace("initializing variables in " + scope);
}
- for (VariableDefinitionImpl variableDefinition: variableDefinitions) {
+ for (VariableDefinitionImpl variableDefinition : variableDefinitions) {
String key = variableDefinition.getName();
Object value = variableDefinition.getInitValue(outerExecution);
String typeName = variableDefinition.getTypeName();
@@ -94,189 +93,193 @@
}
public void createVariable(String key, Object value, String typeName, boolean
isHistoryEnabled) {
- Variable variable = createVariableObject(key, value, typeName, isHistoryEnabled);
- variables.put(variable.getKey(), variable);
+ Variable<?> variable = createVariableObject(key, value, typeName,
isHistoryEnabled);
+ variables.put(key, variable);
hasVariables = true;
}
- protected Variable createVariableObject(String key, Object value, String typeName,
boolean isHistoryEnabled) {
- log.debug("create variable '"+key+"' in
'"+this+"' with value '"+value+"'");
-
- Type type = findType(key, value, typeName);
- Variable variable;
+ protected <S> Variable<S> createVariableObject(String key, Object value,
String typeName,
+ boolean isHistoryEnabled) {
+ // if type does not actually match S, there is a configuration error
+ // and Variable.isStorable will eventually throw an exception
+ @SuppressWarnings("unchecked")
+ Type<S> type = (Type<S>) findType(key, value, typeName);
+ Variable<S> variable;
- if (type!=null) {
- Class<?> variableClass = type.getVariableClass();
+ if (type != null) {
+ Class<? extends Variable<S>> variableClass = type.getVariableClass();
try {
- log.trace("creating new "+type+" variable "+key);
- variable = (Variable) variableClass.newInstance();
- } catch (Exception e) {
- throw new JbpmException("couldn't instantiate variable instance class
'"+variableClass.getName()+"'");
+ log.trace("creating " + type + " variable '" + key +
"'");
+ variable = variableClass.newInstance();
}
- Converter converter = type.getConverter();
- variable.setConverter(converter);
-
- } else {
- if (value==null) {
- log.trace("creating null variable for "+key);
- variable = new NullVariable();
- } else {
- log.trace("creating new unpersistable variable for "+key);
- variable = new UnpersistableVariable();
+ catch (Exception e) {
+ throw new JbpmException("couldn't instantiate variable instance class
'"
+ + variableClass.getName() + "'");
}
+ Converter<?, S> converter = type.getConverter();
+ if (converter != null) variable.setConverter(converter);
}
+ else {
+ if (value == null) {
+ log.trace("creating null variable '" + key + "'");
+ variable = new NullVariable<S>();
+ }
+ else {
+ log.trace("creating unpersistable variable '" + key +
"'");
+ variable = new UnpersistableVariable<S>();
+ }
+ }
+ log.debug(this + " initializes '" + key + "' to " +
value);
variable.setKey(key);
variable.setExecution(getExecution());
variable.setTask(getTask());
variable.setHistoryEnabled(isHistoryEnabled);
variable.setValue(value, this);
-
+
long dbid = DbidGenerator.getDbidGenerator().getNextId();
variable.setDbid(dbid);
if (isHistoryEnabled) {
HistoryEvent.fire(new VariableCreate(variable));
}
-
+
return variable;
}
- private static Type findType(String key, Object value, String typeName) {
+ private static Type<?> findType(String key, Object value, String typeName) {
TypeSet typeSet = EnvironmentImpl.getFromCurrent(TypeSet.class, false);
if (typeSet == null) return null;
- Type type;
- if (typeName == null || (type = typeSet.findTypeByName(typeName)) == null) {
- type = typeSet.findTypeByMatch(key, value);
+ // find type by name
+ if (typeName != null) {
+ Type<?> type = typeSet.findTypeByName(typeName);
+ if (type != null) return type;
}
- return type;
+
+ // find type by value class
+ return typeSet.findTypeByMatch(key, value);
}
public void setVariable(String key, Object value) {
- if (key==null) {
- throw new JbpmException("variableName is null");
+ if (key == null) {
+ throw new IllegalArgumentException("variable name is null");
}
+ setVariableNoCheck(key, value);
+ }
- Variable variable = getVariableObject(key);
- // if there is already a variable instance and it doesn't support the current
type...
- if ( (variable!=null)
- && (!variable.supports(value, this))
- ) {
- // delete the old variable instance
- log.debug("variable type change. deleting '"+key+"' from
'"+this+"'");
+ private <S> void setVariableNoCheck(String key, Object value) {
+ // if type does not actually match S, there is a configuration error
+ // and Variable.isStorable will eventually throw an exception
+ @SuppressWarnings("unchecked")
+ Variable<S> variable = (Variable<S>) getVariableObject(key);
+
+ // if variable exists already but does not support the given value
+ if (variable != null && !variable.supports(value, this)) {
+ // remove old variable
+ log.debug(this + " deletes '" + key + "' due to type
change");
removeVariable(key);
variable = null;
}
- if (variable!=null) {
- log.debug("updating variable '"+key+"' in
'"+this+"' to value '"+value+"'");
+ if (variable != null) {
+ log.debug(this + " sets '" + key + "' to " + value);
variable.setValue(value, this);
- } else if (getParentVariableScope()==null) {
- createVariable(key, value, null, false);
- } else {
- getParentVariableScope().setVariable(key,value);
}
+ else {
+ ScopeInstanceImpl parentScope = getParentVariableScope();
+ if (parentScope == null) {
+ createVariable(key, value, null, false);
+ }
+ else {
+ parentScope.setVariableNoCheck(key, value);
+ }
+ }
}
public void setVariables(Map<String, ?> variables) {
- if (variables!=null) {
+ if (variables != null) {
for (Map.Entry<String, ?> entry : variables.entrySet()) {
setVariable(entry.getKey(), entry.getValue());
}
}
}
-
+
public Object getVariable(String key) {
- Variable variable = getVariableObject(key);
- if (variable!=null) {
+ Variable<?> variable = getVariableObject(key);
+ if (variable != null) {
return variable.getValue(this);
}
-
+
ScopeInstanceImpl parentScope = getParentVariableScope();
- if (parentScope!=null) {
+ if (parentScope != null) {
return parentScope.getVariable(key);
}
return null;
}
- public Variable getVariableObject(String key) {
- return (hasVariables ? (Variable) variables.get(key) : null);
+ public Variable<?> getVariableObject(String key) {
+ return hasVariables ? variables.get(key) : null;
}
public boolean hasVariable(String key) {
ScopeInstanceImpl parentScope = getParentVariableScope();
- return ( (hasVariables && variables.containsKey(key))
- || (parentScope!=null && parentScope.hasVariable(key))
- );
+ return (hasVariables && variables.containsKey(key))
+ || (parentScope != null && parentScope.hasVariable(key));
}
public Set<String> getVariableKeys() {
- Set<String> variableKeys = null;
ScopeInstanceImpl parentScope = getParentVariableScope();
- if (parentScope!=null) {
- variableKeys = parentScope.getVariableKeys();
- } else {
- variableKeys = new TreeSet<String>();
- }
- if (hasVariables) {
- variableKeys.addAll(variables.keySet());
- }
+ Set<String> variableKeys = parentScope != null ? parentScope.getVariableKeys()
+ : new TreeSet<String>();
+
+ if (hasVariables) variableKeys.addAll(variables.keySet());
return variableKeys;
}
public Map<String, Object> getVariables() {
- Map<String, Object> values = null;
ScopeInstanceImpl parentScope = getParentVariableScope();
- if (parentScope!=null) {
- values = parentScope.getVariables();
- } else {
- values = new TreeMap<String, Object>();
- }
+ Map<String, Object> values = parentScope != null ? parentScope.getVariables()
+ : new TreeMap<String, Object>();
+
if (hasVariables) {
- for (Map.Entry<String, Variable> entry: variables.entrySet()) {
+ for (Map.Entry<String, Variable<?>> entry : variables.entrySet()) {
String name = entry.getKey();
- Variable variable = entry.getValue();
- Object value = variable.getValue(this);
- values.put(name, value);
+ Variable<?> variable = entry.getValue();
+ values.put(name, variable.getValue(this));
}
}
return values;
}
-
+
public boolean hasVariables() {
ScopeInstanceImpl parentScope = getParentVariableScope();
- return ( hasVariables
- || (parentScope!=null && parentScope.hasVariables())
- );
+ return hasVariables || (parentScope != null && parentScope.hasVariables());
}
public boolean removeVariable(String key) {
- Variable variable = null;
if (hasVariables) {
- variable = variables.remove(key);
- if (variables.isEmpty()) {
- hasVariables = false;
- }
- if (variable!=null) {
+ Variable<?> variable = variables.remove(key);
+ if (variable != null) {
+ hasVariables = !variables.isEmpty();
return true;
}
}
+
ScopeInstanceImpl parentScope = getParentVariableScope();
- if (parentScope!=null) {
- return parentScope.removeVariable(key);
- }
- // the actual value is not returned to prevent that an object
- // has to be fetched from the db for it to be deleted
+ if (parentScope != null) return parentScope.removeVariable(key);
+
+ // actual value is not returned to avoid fetching an object from the database
+ // only to delete it afterwards
return false;
}
public void removeVariables() {
if (hasVariables) {
variables.clear();
+ hasVariables = false;
}
- hasVariables = false;
}
// timers ///////////////////////////////////////////////////////////////////
@@ -284,51 +287,55 @@
protected TimerImpl newTimer() {
return new TimerImpl();
}
-
+
public TimerImpl createTimer() {
return createTimer(null);
}
public TimerImpl createTimer(TimerDefinitionImpl timerDefinition) {
if (log.isDebugEnabled()) {
- log.debug("creating timer on "+this.toString());
+ log.debug("creating timer on " + this.toString());
}
TimerImpl timer = newTimer();
timer.setExecution(getTimerExecution());
-
- if (timerDefinition!=null) {
+
+ if (timerDefinition != null) {
timer.setEventName(timerDefinition.getEventName());
timer.setSignalName(timerDefinition.getSignalName());
timer.setDueDate(timerDefinition.getDueDate());
timer.setDueDateDescription(timerDefinition.getDueDateDescription());
-
+
if (timer.getDueDate() == null && timerDefinition.getCronExpression() !=
null) {
try {
timer.setDueDate(new
CronExpression(timerDefinition.getCronExpression()).getNextValidTimeAfter(Clock.getTime()));
- } catch (ParseException pe) {
- throw new JbpmException("Can't parse cron expression " +
timerDefinition.getCronExpression(), pe);
}
+ catch (ParseException pe) {
+ throw new JbpmException("Can't parse cron expression "
+ + timerDefinition.getCronExpression(), pe);
+ }
}
-
+
Boolean isExclusive = timerDefinition.isExclusive();
- if (isExclusive!=null) {
+ if (isExclusive != null) {
timer.setExclusive(isExclusive);
}
Integer retries = timerDefinition.getRetries();
- if (retries!=null) {
+ if (retries != null) {
timer.setRetries(retries);
- }
- // support for repeat attribute given as expression
+ }
+ // support for repeat attribute given as expression
// only if repeat is specified
if (timerDefinition.getRepeat() != null) {
- Object repeatEl = Expression.create(timerDefinition.getRepeat(),
Expression.LANGUAGE_UEL_VALUE).evaluate();
+ Object repeatEl = Expression.create(timerDefinition.getRepeat(),
+ Expression.LANGUAGE_UEL_VALUE).evaluate();
timer.setRepeat(repeatEl.toString());
- } else {
+ }
+ else {
timer.setRepeat(timerDefinition.getRepeat());
}
}
-
+
return timer;
}
@@ -336,7 +343,7 @@
// initialize the timers
Set<TimerDefinitionImpl> timerDefinitions = scope.getTimerDefinitions();
if (!timerDefinitions.isEmpty()) {
- for (TimerDefinitionImpl timerDefinition: timerDefinitions) {
+ for (TimerDefinitionImpl timerDefinition : timerDefinitions) {
TimerImpl timer = createTimer(timerDefinition);
timer.schedule();
}
@@ -370,7 +377,6 @@
this.state = state;
}
-
/** @see Execution#getState() */
public String getState() {
return state;
@@ -379,7 +385,7 @@
/** @see Execution#isActive() */
public boolean isActive() {
return Execution.STATE_ACTIVE_ROOT.equals(state)
- || Execution.STATE_ACTIVE_CONCURRENT.equals(state);
+ || Execution.STATE_ACTIVE_CONCURRENT.equals(state);
}
public boolean isSuspended() {
@@ -387,7 +393,7 @@
}
// customizable methods /////////////////////////////////////////////////////
-
+
public ExecutionImpl getExecution() {
return null;
}
@@ -405,13 +411,15 @@
}
// getters and setters //////////////////////////////////////////////////////
-
+
public long getDbid() {
return dbid;
}
+
public Object getElContext() {
return elContext;
}
+
public void setElContext(Object elContext) {
this.elContext = elContext;
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/DeserializedObject.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/DeserializedObject.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/DeserializedObject.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -55,7 +55,7 @@
&& (currentValue==deserializedObject)
) {
// next, we check if the serialized object was actually changed or not
- byte[] newBytes = (byte[]) serializableToBytesConverter.convert(currentValue, null,
null);
+ byte[] newBytes = serializableToBytesConverter.convert(currentValue, null, null);
byte[] persistedBytes = blobVariable.getLob().extractBytes();
// if it is changed
if (!Arrays.equals(persistedBytes, newBytes)) {
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-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Converter.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -26,22 +26,24 @@
import org.jbpm.pvm.internal.model.ScopeInstanceImpl;
/**
+ * Bidirectional conversion between a value T and its storable representation S.
+ *
* @author Tom Baeyens
*/
-public interface Converter<S, T> extends Serializable {
+public interface Converter<T, S> extends Serializable {
/**
* is true if this converter supports the given value, false otherwise.
*/
- boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable);
-
+ boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable<S>
variable);
+
/**
* converts a given object to its persistable format.
*/
- T convert(S o, ScopeInstanceImpl scopeInstance, Variable variable);
+ S convert(T o, ScopeInstanceImpl scopeInstance, Variable<S> variable);
/**
* reverts a persisted object to its original formResourceName.
*/
- S revert(T o, ScopeInstanceImpl scopeInstance, Variable variable);
+ T revert(S o, ScopeInstanceImpl scopeInstance, Variable<S> variable);
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/DefaultTypeSet.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/DefaultTypeSet.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/DefaultTypeSet.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -25,7 +25,6 @@
import java.util.ArrayList;
import java.util.List;
-
/**
* @author Tom Baeyens
*/
@@ -35,36 +34,28 @@
protected List<TypeMapping> typeMappings;
- public Type findTypeByMatch(String key, Object value) {
- if (typeMappings!=null) {
- for (TypeMapping typeMapping: typeMappings) {
- if (typeMapping.matches(key, value)) {
- return typeMapping.getType();
- }
+ public Type<?> findTypeByMatch(String key, Object value) {
+ if (typeMappings != null) {
+ for (TypeMapping typeMapping : typeMappings) {
+ if (typeMapping.matches(key, value)) return typeMapping.getType();
}
}
-
+
return null;
}
- public Type findTypeByName(String typeName) {
- if ( (typeMappings!=null)
- && (typeName!=null)
- ) {
- for (TypeMapping typeMapping: typeMappings) {
- Type type = typeMapping.getType();
- if (typeName.equals(type.getName())) {
- return type;
- }
+ public Type<?> findTypeByName(String typeName) {
+ if (typeMappings != null && typeName != null) {
+ for (TypeMapping typeMapping : typeMappings) {
+ Type<?> type = typeMapping.getType();
+ if (typeName.equals(type.getName())) return type;
}
}
return null;
}
public void addTypeMapping(TypeMapping typeMapping) {
- if (typeMappings==null) {
- typeMappings = new ArrayList<TypeMapping>();
- }
+ if (typeMappings == null) typeMappings = new ArrayList<TypeMapping>();
typeMappings.add(typeMapping);
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Type.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Type.java 2010-10-08
09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Type.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -23,52 +23,57 @@
import java.io.Serializable;
-import org.jbpm.pvm.internal.util.ReflectUtil;
-
-
-/** a variable type.
+/**
+ * a variable type.
+ *
* @author Tom Baeyens
*/
-public class Type implements Serializable {
+public class Type<S> implements Serializable {
private static final long serialVersionUID = 1L;
-
+
protected String name;
- protected Converter converter;
- protected Class<?> variableClass;
+ protected Converter<?, S> converter;
+ protected Class<? extends Variable<S>> variableClass;
public String toString() {
- if (name!=null) {
+ if (name != null) {
return name;
}
StringBuilder text = new StringBuilder();
- if (converter!=null) {
+ if (converter != null) {
text.append(converter.toString());
text.append("-->");
}
- if (variableClass!=null) {
+ if (variableClass != null) {
text.append(variableClass.getSimpleName());
- } else {
+ }
+ else {
text.append("undefined");
}
return text.toString();
}
-
- public Converter getConverter() {
+
+ public Converter<?, S> getConverter() {
return converter;
}
- public void setConverter(Converter converter) {
+
+ public void setConverter(Converter<?, S> converter) {
this.converter = converter;
}
- public Class< ? > getVariableClass() {
+
+ public Class<? extends Variable<S>> getVariableClass() {
return variableClass;
}
- public void setVariableClass(Class< ? > variableClass) {
+
+ public void setVariableClass(Class<? extends Variable<S>> variableClass) {
this.variableClass = variableClass;
}
+
public String getName() {
return name;
}
+
public void setName(String name) {
this.name = name;
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeMapping.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeMapping.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeMapping.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -2,32 +2,34 @@
import java.io.Serializable;
-
public class TypeMapping implements Serializable {
- Matcher matcher;
- Type type;
+ private Matcher matcher;
+ private Type<?> type;
private static final long serialVersionUID = 1L;
-
+
public boolean matches(String name, Object value) {
return matcher.matches(name, value);
}
-
- public String toString() {
- return "("+matcher+"-->"+type+")";
+
+ public Matcher getMatcher() {
+ return matcher;
}
-
+
public void setMatcher(Matcher matcher) {
this.matcher = matcher;
}
- public Type getType() {
+
+ public Type<?> getType() {
return type;
}
- public void setType(Type type) {
+
+ public void setType(Type<?> type) {
this.type = type;
}
- public Matcher getMatcher() {
- return matcher;
+
+ public String toString() {
+ return "(" + matcher + "-->" + type + ")";
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeSet.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeSet.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeSet.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -27,7 +27,7 @@
*/
public interface TypeSet {
- Type findTypeByMatch(String key, Object value);
- Type findTypeByName(String typeName);
+ Type<?> findTypeByMatch(String key, Object value);
+ Type<?> findTypeByName(String typeName);
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -33,136 +33,170 @@
import org.jbpm.pvm.internal.task.TaskImpl;
/**
- * is a jbpm-internal class that serves as a base class for classes
- * that store variable values in the database.
+ * Container that stores values of type S in the database.
*/
-public abstract class Variable implements Serializable {
+public abstract class Variable<S> implements Serializable {
private static final long serialVersionUID = 1L;
-
+
protected long dbid = -1;
protected int dbversion;
-
+
protected String key;
- protected Converter converter;
+ protected Converter<?, S> converter;
protected String textValue;
protected boolean isHistoryEnabled;
-
+
protected ExecutionImpl execution;
protected TaskImpl task;
-
+
// constructors /////////////////////////////////////////////////////////////
-
+
// abstract methods /////////////////////////////////////////////////////////
/**
* is true if this variable-instance supports the given value, false otherwise.
*/
public abstract boolean isStorable(Object value);
+
/**
* is the value, stored by this variable instance.
*/
- protected abstract Object getObject();
+ protected abstract S getObject();
+
/**
* stores the value in this variable instance.
*/
- protected abstract void setObject(Object value);
+ protected abstract void setObject(S value);
// variable management //////////////////////////////////////////////////////
public boolean supports(Object value, ScopeInstanceImpl scopeInstance) {
- if (converter!=null) {
- return converter.supports(value, scopeInstance, this);
- }
- return isStorable(value);
+ return converter != null ? converter.supports(value, scopeInstance, this)
+ : isStorable(value);
}
- public void setValue(Object value, ScopeInstanceImpl scopeInstance) {
- if (converter!=null) {
+ public <T> void setValue(T value, ScopeInstanceImpl scopeInstance) {
+ if (converter != null) {
if (!converter.supports(value, scopeInstance, this)) {
- throw new JbpmException("the converter
'"+converter.getClass().getName()+"' in variable instance
'"+this.getClass().getName()+"' does not support values of type
'"+value.getClass().getName()+"'. to change the type of a variable, you
have to delete it first");
+ throw new JbpmException(converter.getClass().getSimpleName() + " does not
support "
+ + value);
}
+
// default set of text value required for BlobVariable to be set before converting
// for other types will be reset by setObject method
if (value != null) {
- this.textValue = value.toString();
+ textValue = value.toString();
}
- value = converter.convert(value, scopeInstance, this);
+
+ // converter said it supports value
+ @SuppressWarnings("unchecked")
+ Converter<T, S> typeConverter = (Converter<T, S>) converter;
+ S storeValue = typeConverter.convert(value, scopeInstance, this);
+ if (storeValue != null && !isStorable(storeValue)) {
+ throw new JbpmException(getClass().getSimpleName() + " does not support
value: "
+ + storeValue);
+ }
+ setObject(storeValue);
}
- if (value!=null && !isStorable(value)) {
- throw new JbpmException("variable instance
'"+getClass().getName()+"' does not support values of type
'"+value.getClass().getName()+"'. to change the type of a variable, you
have to delete it first");
+ else {
+ if (value != null && !isStorable(value)) {
+ throw new JbpmException(getClass().getSimpleName() + " does not support
value: "
+ + value);
+ }
+
+ // this variable said value is storable
+ @SuppressWarnings("unchecked")
+ S storeValue = (S) value;
+ setObject(storeValue);
}
- setObject(value);
-
- HistorySession historySession = EnvironmentImpl.getFromCurrent(HistorySession.class,
false);
- if (isHistoryEnabled && historySession!=null && getDbid()!=-1) {
+
+ if (isHistoryEnabled && dbid != -1
+ && EnvironmentImpl.getFromCurrent(HistorySession.class, false) != null) {
HistoryEvent.fire(new VariableUpdate(this));
}
}
public Object getValue(ScopeInstanceImpl scopeInstance) {
- Object value = getObject();
- if (value!=null && converter!=null) {
- value = converter.revert(value, scopeInstance, this);
+ S storeValue = getObject();
+ if (converter != null)
+ return converter.revert(storeValue, scopeInstance, this);
+ else {
+ return storeValue;
}
- return value;
}
-
+
// utility methods /////////////////////////////////////////////////////////
public String toString() {
- return "${"+key+"}";
+ return "${" + key + "}";
}
- public Type getType() {
- Type type = new Type();
+ public Type<S> getType() {
+ // getClass() returns raw type
+ @SuppressWarnings("unchecked")
+ Class<? extends Variable<S>> variableClass = (Class<? extends
Variable<S>>) getClass();
+
+ Type<S> type = new Type<S>();
type.setConverter(converter);
- type.setVariableClass(getClass());
+ type.setVariableClass(variableClass);
return type;
}
-
+
public ExecutionImpl getProcessInstance() {
- return execution!=null ? execution.getProcessInstance() : null;
+ return execution != null ? execution.getProcessInstance() : null;
}
// getters and setters //////////////////////////////////////////////////////
-
+
public String getKey() {
return key;
}
+
public long getDbid() {
return dbid;
}
- public Converter getConverter() {
+
+ public Converter<?, S> getConverter() {
return converter;
}
- public void setConverter(Converter converter) {
+
+ public void setConverter(Converter<?, S> converter) {
this.converter = converter;
}
+
public void setKey(String key) {
this.key = key;
}
+
public String getTextValue() {
return textValue;
}
+
public ExecutionImpl getExecution() {
return execution;
}
+
public void setExecution(ExecutionImpl execution) {
this.execution = execution;
}
+
public TaskImpl getTask() {
return task;
}
+
public void setTask(TaskImpl task) {
this.task = task;
}
+
public boolean isHistoryEnabled() {
return isHistoryEnabled;
}
+
public void setHistoryEnabled(boolean isHistoryEnabled) {
this.isHistoryEnabled = isHistoryEnabled;
}
+
public void setDbid(long dbid) {
this.dbid = dbid;
}
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-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/BooleanToStringConverter.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -32,15 +32,16 @@
public static final String TRUE_TEXT = "T";
public static final String FALSE_TEXT = "F";
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable
variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<String> variable) {
return value instanceof Boolean || value == null;
}
- public String convert(Boolean o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public String convert(Boolean o, ScopeInstanceImpl scopeInstance,
Variable<String> variable) {
return o != null ? o.booleanValue() ? TRUE_TEXT : FALSE_TEXT : null;
}
- public Boolean revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Boolean revert(String o, ScopeInstanceImpl scopeInstance, Variable<String>
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-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ByteToLongConverter.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -29,15 +29,15 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable
variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
Variable<Long> variable) {
return value instanceof Byte || value == null;
}
- public Long convert(Byte o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Long convert(Byte o, ScopeInstanceImpl scopeInstance, Variable<Long>
variable) {
return o != null ? Long.valueOf(o.longValue()) : null;
}
- public Byte revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Byte revert(Long o, ScopeInstanceImpl scopeInstance, Variable<Long>
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-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/CharacterToStringConverter.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -29,15 +29,16 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable
variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<String> variable) {
return value instanceof Character || value == null;
}
- public String convert(Character o, ScopeInstanceImpl scopeInstance, Variable variable)
{
+ public String convert(Character o, ScopeInstanceImpl scopeInstance,
Variable<String> variable) {
return o != null ? o.toString() : null;
}
- public Character revert(String o, ScopeInstanceImpl scopeInstance, Variable variable)
{
+ public Character revert(String o, ScopeInstanceImpl scopeInstance,
Variable<String> 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-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToLongConverter.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -31,15 +31,15 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable
variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
Variable<Long> variable) {
return value instanceof Date || value == null;
}
- public Long convert(Date o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Long convert(Date o, ScopeInstanceImpl scopeInstance, Variable<Long>
variable) {
return o != null ? Long.valueOf(o.getTime()) : null;
}
- public Date revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Date revert(Long o, ScopeInstanceImpl scopeInstance, Variable<Long>
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-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToStringConverter.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -39,15 +39,16 @@
private String format = "yyyy-MM-dd HH:mm:ss,SSS";
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable
variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<String> variable) {
return value instanceof Date || value == null;
}
- public String convert(Date o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public String convert(Date o, ScopeInstanceImpl scopeInstance, Variable<String>
variable) {
return o != null ? new SimpleDateFormat(format).format(o) : null;
}
- public Date revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Date revert(String o, ScopeInstanceImpl scopeInstance, Variable<String>
variable) {
try {
return o != null ? new SimpleDateFormat(format).parse(o) : null;
}
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-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DoubleToStringConverter.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -29,15 +29,16 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable
variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<String> variable) {
return value instanceof Double || value == null;
}
- public String convert(Double o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public String convert(Double o, ScopeInstanceImpl scopeInstance, Variable<String>
variable) {
return o != null ? o.toString() : null;
}
- public Double revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Double revert(String o, ScopeInstanceImpl scopeInstance, Variable<String>
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-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToDoubleConverter.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -29,15 +29,16 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable
variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<Double> variable) {
return value instanceof Float || value == null;
}
- public Double convert(Float o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Double convert(Float o, ScopeInstanceImpl scopeInstance, Variable<Double>
variable) {
return o != null ? new Double(o.doubleValue()) : null;
}
- public Float revert(Double o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Float revert(Double o, ScopeInstanceImpl scopeInstance, Variable<Double>
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-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToStringConverter.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -29,15 +29,16 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable
variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<String> variable) {
return value instanceof Float || value == null;
}
- public String convert(Float o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public String convert(Float o, ScopeInstanceImpl scopeInstance, Variable<String>
variable) {
return o != null ? o.toString() : null;
}
- public Float revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Float revert(String o, ScopeInstanceImpl scopeInstance, Variable<String>
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-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/IntegerToLongConverter.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -29,15 +29,15 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable
variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
Variable<Long> variable) {
return value instanceof Integer || value == null;
}
- public Long convert(Integer o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Long convert(Integer o, ScopeInstanceImpl scopeInstance, Variable<Long>
variable) {
return o != null ? Long.valueOf(o.longValue()) : null;
}
- public Integer revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Integer revert(Long o, ScopeInstanceImpl scopeInstance, Variable<Long>
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-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/SerializableToBytesConverter.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -24,7 +24,6 @@
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;
@@ -43,11 +42,12 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable
variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<byte[]> variable) {
return value instanceof Serializable || value == null;
}
- public byte[] convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public byte[] convert(Object o, ScopeInstanceImpl scopeInstance, Variable<byte[]>
variable) {
if (o == null) return null;
try {
@@ -61,7 +61,8 @@
// allow for automatic update of serialized objects
Transaction transaction = EnvironmentImpl.getFromCurrent(Transaction.class,
false);
if (transaction != null) {
- transaction.registerDeserializedObject(new DeserializedObject(o, scopeInstance,
+ transaction.registerDeserializedObject(new DeserializedObject(o,
+ scopeInstance,
(BlobVariable) variable));
}
return bytes;
@@ -71,7 +72,7 @@
}
}
- public Object revert(byte[] o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Object revert(byte[] o, ScopeInstanceImpl scopeInstance, Variable<byte[]>
variable) {
if (o == null) return null;
try {
@@ -83,7 +84,8 @@
// allow for automatic update of deserialized objects
Transaction transaction = EnvironmentImpl.getFromCurrent(Transaction.class,
false);
if (transaction != null) {
- transaction.registerDeserializedObject(new DeserializedObject(object,
scopeInstance,
+ transaction.registerDeserializedObject(new DeserializedObject(object,
+ scopeInstance,
(BlobVariable) variable));
}
return object;
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-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ShortToLongConverter.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -29,15 +29,15 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable
variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
Variable<Long> variable) {
return value instanceof Short || value == null;
}
- public Long convert(Short o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Long convert(Short o, ScopeInstanceImpl scopeInstance, Variable<Long>
variable) {
return o != null ? Long.valueOf(o.longValue()) : null;
}
- public Short revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Short revert(Long o, ScopeInstanceImpl scopeInstance, Variable<Long>
variable) {
return o != null ? Short.valueOf(o.shortValue()) : null;
}
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -27,35 +27,33 @@
import org.jbpm.pvm.internal.session.DbSession;
import org.jbpm.pvm.internal.type.Variable;
-public class BlobVariable extends Variable {
+public class BlobVariable extends Variable<byte[]> {
private static final long serialVersionUID = 1L;
-
- protected Lob lob = null;
- protected Object cachedValue = null;
+ protected Lob lob;
+ protected Object cachedValue;
+
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (byte[].class.isAssignableFrom(value.getClass()));
+ return value instanceof byte[] || value == null;
}
- public Object getObject() {
- if (lob==null) return null;
- return lob.extractBytes();
+ public byte[] getObject() {
+ return lob != null ? lob.extractBytes() : null;
}
- public void setObject(Object value) {
- if (this.lob!=null) {
+ public void setObject(byte[] value) {
+ if (lob != null) {
DbSession dbSession = EnvironmentImpl.getFromCurrent(DbSession.class, false);
- if (dbSession!=null) {
- dbSession.delete(this.lob);
+ if (dbSession != null) {
+ dbSession.delete(lob);
}
}
- this.lob = new Lob((byte[])value, true);
+ lob = value != null ? new Lob(value, true) : null;
}
-
+
public Object getValue(ScopeInstanceImpl scopeInstance) {
- if (cachedValue!=null) {
+ if (cachedValue != null) {
return cachedValue;
}
cachedValue = super.getValue(scopeInstance);
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/ClobVariable.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/ClobVariable.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/ClobVariable.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -21,30 +21,36 @@
*/
package org.jbpm.pvm.internal.type.variable;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.lob.Lob;
+import org.jbpm.pvm.internal.session.DbSession;
import org.jbpm.pvm.internal.type.Variable;
/**
* @author Tom Baeyens
*/
-public class ClobVariable extends Variable {
+public class ClobVariable extends Variable<char[]> {
private static final long serialVersionUID = 1L;
- protected Lob lob = null;
+ protected Lob lob;
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (char[].class.isAssignableFrom(value.getClass()));
+ return value instanceof char[] || value == null;
}
- public Object getObject() {
- if (lob==null) return null;
- return lob.extractChars();
+ public char[] getObject() {
+ return lob != null ? lob.extractChars() : null;
}
- public void setObject(Object value) {
- this.lob = new Lob((char[])value, true);
+ public void setObject(char[] value) {
+ if (lob != null) {
+ DbSession dbSession = EnvironmentImpl.getFromCurrent(DbSession.class, false);
+ if (dbSession != null) {
+ dbSession.delete(lob);
+ }
+ }
+ lob = value != null ? new Lob(value, true) : null;
}
public Lob getLob() {
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DateVariable.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DateVariable.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DateVariable.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -26,31 +26,25 @@
import org.jbpm.pvm.internal.type.Variable;
+public class DateVariable extends Variable<Date> {
-public class DateVariable extends Variable {
-
private static final long serialVersionUID = 1L;
-
- private static final String dateFormat = "dd/MM/yyyy HH:mm:ss";
-
- protected Date date = null;
+ private static final String dateFormat = "dd/MM/yyyy HH:mm:ss,SSS";
+
+ protected Date date;
+
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (Date.class.isAssignableFrom(value.getClass()));
+ return value instanceof Date || value == null;
}
- public Object getObject() {
+ public Date getObject() {
return date;
}
- public void setObject(Object value) {
- this.date = (Date) value;
- if (value!=null) {
- this.textValue = new SimpleDateFormat(dateFormat).format(value);
- } else {
- this.textValue = null;
- }
+ public void setObject(Date value) {
+ date = value;
+ textValue = value != null ? new SimpleDateFormat(dateFormat).format(value) : null;
}
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DoubleVariable.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DoubleVariable.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DoubleVariable.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -23,28 +23,22 @@
import org.jbpm.pvm.internal.type.Variable;
+public class DoubleVariable extends Variable<Double> {
-public class DoubleVariable extends Variable {
-
private static final long serialVersionUID = 1L;
-
- protected Double d = null;
+ protected Double d;
+
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (Double.class==value.getClass());
+ return value instanceof Double || value == null;
}
- public Object getObject() {
+ public Double getObject() {
return d;
}
- public void setObject(Object value) {
- this.d = (Double) value;
- if (value!=null) {
- this.textValue = value.toString();
- } else {
- this.textValue = null;
- }
+ public void setObject(Double value) {
+ d = value;
+ textValue = value != null ? value.toString() : null;
}
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateLongVariable.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateLongVariable.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateLongVariable.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -23,22 +23,21 @@
import org.jbpm.pvm.internal.type.Variable;
+public class HibernateLongVariable<S> extends Variable<S> {
-public class HibernateLongVariable extends Variable {
-
private static final long serialVersionUID = 1L;
-
- protected Object hibernatable = null;
+ protected S hibernatable;
+
public boolean isStorable(Object value) {
return true;
}
- public Object getObject() {
+ public S getObject() {
return hibernatable;
}
- public void setObject(Object value) {
- this.hibernatable = value;
+ public void setObject(S value) {
+ hibernatable = value;
}
}
\ No newline at end of file
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateStringVariable.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateStringVariable.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateStringVariable.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -23,22 +23,21 @@
import org.jbpm.pvm.internal.type.Variable;
+public class HibernateStringVariable<S> extends Variable<S> {
-public class HibernateStringVariable extends Variable {
-
private static final long serialVersionUID = 1L;
-
- protected Object hibernatable = null;
+ protected S hibernatable;
+
public boolean isStorable(Object value) {
return true;
}
- public Object getObject() {
+ public S getObject() {
return hibernatable;
}
- public void setObject(Object value) {
- this.hibernatable = value;
+ public void setObject(S value) {
+ hibernatable = value;
}
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/LongVariable.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/LongVariable.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/LongVariable.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -23,29 +23,23 @@
import org.jbpm.pvm.internal.type.Variable;
+public class LongVariable extends Variable<Long> {
-public class LongVariable extends Variable {
-
private static final long serialVersionUID = 1L;
-
- protected Long l = null;
+ protected Long l;
+
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (Long.class==value.getClass());
+ return value instanceof Long || value == null;
}
- public Object getObject() {
+ public Long getObject() {
return l;
}
- public void setObject(Object value) {
- this.l = (Long) value;
- if (value!=null) {
- this.textValue = value.toString();
- } else {
- this.textValue = null;
- }
+ public void setObject(Long value) {
+ l = value;
+ textValue = value != null ? value.toString() : null;
}
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/NullVariable.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/NullVariable.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/NullVariable.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -2,19 +2,18 @@
import org.jbpm.pvm.internal.type.Variable;
+public class NullVariable<S> extends Variable<S> {
-public class NullVariable extends Variable {
-
private static final long serialVersionUID = 1L;
- protected Object getObject() {
- return null;
- }
-
public boolean isStorable(Object value) {
- return (value==null);
+ return value == null;
}
-
- protected void setObject(Object value) {
+
+ protected S getObject() {
+ return null;
}
+
+ protected void setObject(S value) {
+ }
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/StringVariable.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/StringVariable.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/StringVariable.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -23,28 +23,22 @@
import org.jbpm.pvm.internal.type.Variable;
+public class StringVariable extends Variable<String> {
-public class StringVariable extends Variable {
-
private static final long serialVersionUID = 1L;
-
- protected String string = null;
+ protected String string;
+
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (String.class==value.getClass());
+ return value instanceof String || value == null;
}
- public Object getObject() {
+ public String getObject() {
return string;
}
- public void setObject(Object value) {
- this.string = (String) value;
- if (value!=null) {
- this.textValue = string;
- } else {
- this.textValue = null;
- }
+ public void setObject(String value) {
+ string = value;
+ textValue = value;
}
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/TextVariable.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/TextVariable.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/TextVariable.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -24,29 +24,22 @@
import org.jbpm.pvm.internal.type.Variable;
-public class TextVariable extends Variable {
+public class TextVariable extends Variable<char[]> {
private static final long serialVersionUID = 1L;
- protected String text = null;
+ protected char[] text;
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (char[].class==value.getClass());
+ return value instanceof char[] || value == null;
}
- public Object getObject() {
- if (text==null) {
- return null;
- }
- return text.toCharArray();
+ public char[] getObject() {
+ return text;
}
- public void setObject(Object value) {
- if (value!=null) {
- this.text = new String((char[])value);
- } else {
- this.text = null;
- }
+ public void setObject(char[] value) {
+ text = value;
+ textValue = new String(value);
}
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/UnpersistableVariable.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/UnpersistableVariable.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/UnpersistableVariable.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -2,26 +2,24 @@
import org.jbpm.pvm.internal.type.Variable;
-
/**
- * uses the cache in variable instance to store any object
- * without persisting it.
+ * uses the cache in variable instance to store any object without persisting it.
*/
-public class UnpersistableVariable extends Variable {
-
+public class UnpersistableVariable<S> extends Variable<S> {
+
private static final long serialVersionUID = 1L;
-
- Object value;
- protected Object getObject() {
- return value;
- }
+ protected S value;
public boolean isStorable(Object value) {
return true;
}
- protected void setObject(Object value) {
+ protected S getObject() {
+ return value;
+ }
+
+ protected void setObject(S value) {
this.value = value;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2010-10-08 09:25:57
UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2010-10-09 03:46:44
UTC (rev 6749)
@@ -5,17 +5,17 @@
<!-- ### TYPEDEFS ####################################################### -->
<typedef name="converter"
class="org.jbpm.pvm.internal.hibernate.ConverterType">
- <param
name="org.jbpm.pvm.internal.type.converter.BooleanToStringConverter"
>bool-str</param>
- <param name="org.jbpm.pvm.internal.type.converter.ByteToLongConverter"
>byte-long</param>
- <param
name="org.jbpm.pvm.internal.type.converter.CharacterToStringConverter"
>char-str</param>
- <param name="org.jbpm.pvm.internal.type.converter.DateToLongConverter"
>date-long</param>
- <param name="org.jbpm.pvm.internal.type.converter.DateToStringConverter"
>date-str</param>
- <param
name="org.jbpm.pvm.internal.type.converter.DoubleToStringConverter"
>double-str</param>
- <param
name="org.jbpm.pvm.internal.type.converter.FloatToDoubleConverter"
>float-double</param>
- <param
name="org.jbpm.pvm.internal.type.converter.FloatToStringConverter"
>float-str</param>
- <param
name="org.jbpm.pvm.internal.type.converter.IntegerToLongConverter"
>int-long</param>
- <param
name="org.jbpm.pvm.internal.type.converter.SerializableToBytesConverter">ser-bytes</param>
- <param name="org.jbpm.pvm.internal.type.converter.ShortToLongConverter"
>short-long</param>
+ <param
name="bool-str">org.jbpm.pvm.internal.type.converter.BooleanToStringConverter</param>
+ <param
name="byte-long">org.jbpm.pvm.internal.type.converter.ByteToLongConverter</param>
+ <param
name="char-str">org.jbpm.pvm.internal.type.converter.CharacterToStringConverter</param>
+ <param
name="date-long">org.jbpm.pvm.internal.type.converter.DateToLongConverter</param>
+ <param
name="date-str">org.jbpm.pvm.internal.type.converter.DateToStringConverter</param>
+ <param
name="double-str">org.jbpm.pvm.internal.type.converter.DoubleToStringConverter</param>
+ <param
name="float-double">org.jbpm.pvm.internal.type.converter.FloatToDoubleConverter</param>
+ <param
name="float-str">org.jbpm.pvm.internal.type.converter.FloatToStringConverter</param>
+ <param
name="int-long">org.jbpm.pvm.internal.type.converter.IntegerToLongConverter</param>
+ <param
name="ser-bytes">org.jbpm.pvm.internal.type.converter.SerializableToBytesConverter</param>
+ <param
name="short-long">org.jbpm.pvm.internal.type.converter.ShortToLongConverter</param>
</typedef>
<!-- ### EXECUTION ############################################# -->
Modified:
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java 2010-10-08
09:25:57 UTC (rev 6748)
+++
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java 2010-10-09
03:46:44 UTC (rev 6749)
@@ -27,7 +27,7 @@
import java.io.Serializable;
import java.util.Arrays;
import java.util.Calendar;
-import java.util.GregorianCalendar;
+import java.util.Date;
import org.jbpm.pvm.activities.WaitState;
import org.jbpm.pvm.internal.builder.ProcessDefinitionBuilder;
@@ -45,249 +45,200 @@
public class VariableAutoTypeResolutionTest extends EnvironmentTestCase {
public static ExecutionImpl startProcessInstance() {
- return (ExecutionImpl) ProcessDefinitionBuilder
- .startProcess()
- .startActivity(WaitState.class).initial()
+ return (ExecutionImpl) ProcessDefinitionBuilder.startProcess()
+ .startActivity(WaitState.class)
+ .initial()
.endActivity()
- .endProcess()
- .startProcessInstance();
+ .endProcess()
+ .startProcessInstance();
}
-
+
public void testStringVariable() {
+ final String value = "hello";
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", "hello");
-
- Variable variable = execution.getVariableObject("v");
-
- assertEquals(StringVariable.class, variable.getClass());
- StringVariable stringVariable = (StringVariable) variable;
- assertEquals("hello", stringVariable.getObject());
-
- assertEquals("hello", execution.getVariable("v"));
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
+
+ StringVariable stringVariable = (StringVariable)
execution.getVariableObject("v");
+ assertEquals(value, stringVariable.getObject());
}
public void testLongVariable() {
+ final Long value = Long.valueOf(5);
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Long(5));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(LongVariable.class, variable.getClass());
- LongVariable longVariable = (LongVariable) variable;
- assertEquals(new Long(5), longVariable.getObject());
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
- assertEquals(new Long(5), execution.getVariable("v"));
+ LongVariable longVariable = (LongVariable)
execution.getVariableObject("v");
+ assertEquals(value, longVariable.getObject());
}
public void testDoubleVariable() {
+ final Double value = new Double(5.5);
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Double(5.5));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(DoubleVariable.class, variable.getClass());
- DoubleVariable doubleVariable = (DoubleVariable) variable;
- assertEquals(new Double(5.5), doubleVariable.getObject());
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
- assertEquals(new Double(5.5), execution.getVariable("v"));
+ DoubleVariable doubleVariable = (DoubleVariable)
execution.getVariableObject("v");
+ assertEquals(value, doubleVariable.getObject());
}
public void testDateVariable() {
- ExecutionImpl execution = startProcessInstance();
-
- Calendar calendar = new GregorianCalendar();
- calendar.set(Calendar.YEAR, 2007);
- calendar.set(Calendar.MONTH, 10); // (10 == november)
- calendar.set(Calendar.DAY_OF_MONTH, 22);
- calendar.set(Calendar.HOUR_OF_DAY, 15);
- calendar.set(Calendar.MINUTE, 28);
- calendar.set(Calendar.SECOND, 57);
+ Calendar calendar = Calendar.getInstance();
+ calendar.set(2007, Calendar.NOVEMBER, 22, 15, 28, 57);
calendar.set(Calendar.MILLISECOND, 374);
-
- execution.setVariable("v", calendar.getTime());
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(StringVariable.class, variable.getClass());
- StringVariable stringVariable = (StringVariable) variable;
- assertEquals("2007-11-22 15:28:57,374", stringVariable.getObject());
+ final Date date = calendar.getTime();
- assertEquals(calendar.getTime(), execution.getVariable("v"));
+ ExecutionImpl execution = startProcessInstance();
+ execution.setVariable("v", date);
+ assertEquals(date, execution.getVariable("v"));
+
+ StringVariable stringVariable = (StringVariable)
execution.getVariableObject("v");
+ assertEquals("2007-11-22 15:28:57,374", stringVariable.getObject());
}
public void testBooleanVariable() {
ExecutionImpl execution = startProcessInstance();
+ execution.setVariable("t", Boolean.TRUE);
+ execution.setVariable("f", Boolean.FALSE);
+ assertEquals(Boolean.TRUE, execution.getVariable("t"));
+ assertEquals(Boolean.FALSE, execution.getVariable("f"));
- execution.setVariable("affirmative", Boolean.TRUE);
- execution.setVariable("negative", Boolean.FALSE);
-
- Variable variable = execution.getVariableObject("affirmative");
- assertEquals(StringVariable.class, variable.getClass());
- StringVariable stringVariable = (StringVariable) variable;
+ StringVariable stringVariable = (StringVariable)
execution.getVariableObject("t");
assertEquals("T", stringVariable.getObject());
-
- variable = execution.getVariableObject("negative");
- assertEquals(StringVariable.class, variable.getClass());
- stringVariable = (StringVariable) variable;
- assertEquals("F", stringVariable.getObject());
- assertEquals(Boolean.TRUE, execution.getVariable("affirmative"));
- assertEquals(Boolean.FALSE, execution.getVariable("negative"));
+ stringVariable = (StringVariable) execution.getVariableObject("f");
+ assertEquals("F", stringVariable.getObject());
}
public void testCharacterVariable() {
+ final Character value = Character.valueOf('c');
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Character('c'));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(StringVariable.class, variable.getClass());
- StringVariable stringVariable = (StringVariable) variable;
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
+
+ StringVariable stringVariable = (StringVariable)
execution.getVariableObject("v");
assertEquals("c", stringVariable.getObject());
-
- assertEquals(new Character('c'), execution.getVariable("v"));
}
public void testByteVariable() {
+ final Byte value = Byte.valueOf((byte) 78);
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Byte((byte)78));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(LongVariable.class, variable.getClass());
- LongVariable longVariable = (LongVariable) variable;
- assertEquals(new Long(78), longVariable.getObject());
-
- assertEquals(new Byte((byte)78), execution.getVariable("v"));
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
+
+ LongVariable longVariable = (LongVariable)
execution.getVariableObject("v");
+ assertEquals(Long.valueOf(78), longVariable.getObject());
}
public void testShortVariable() {
+ final Short value = Short.valueOf((short) 78);
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Short((short)78));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(LongVariable.class, variable.getClass());
- LongVariable longVariable = (LongVariable) variable;
- assertEquals(new Long(78), longVariable.getObject());
-
- assertEquals(new Short((short)78), execution.getVariable("v"));
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
+
+ LongVariable longVariable = (LongVariable)
execution.getVariableObject("v");
+ assertEquals(Long.valueOf(78), longVariable.getObject());
}
public void testIntegerVariable() {
+ final Integer value = new Integer(78);
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Integer(78));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(LongVariable.class, variable.getClass());
- LongVariable longVariable = (LongVariable) variable;
- assertEquals(new Long(78), longVariable.getObject());
-
- assertEquals(new Integer(78), execution.getVariable("v"));
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
+
+ LongVariable longVariable = (LongVariable)
execution.getVariableObject("v");
+ assertEquals(Long.valueOf(78), longVariable.getObject());
}
public void testFloatVariable() {
+ final Float value = new Float(78.5);
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Float(78.65));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(DoubleVariable.class, variable.getClass());
- DoubleVariable doubleVariable = (DoubleVariable) variable;
- assertEquals(new Double((float)78.65), doubleVariable.getObject());
-
- assertEquals(new Float(78.65), execution.getVariable("v"));
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
+
+ DoubleVariable doubleVariable = (DoubleVariable)
execution.getVariableObject("v");
+ assertEquals(new Double(78.5), doubleVariable.getObject());
}
public void testBytesVariable() {
+ final byte[] bytes = new byte[1024];
+ Arrays.fill(bytes, (byte) 0xBE);
+
ExecutionImpl execution = startProcessInstance();
-
- byte[] bytes = generateBytes("a lot of bytes ", 500);
execution.setVariable("v", bytes);
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(BlobVariable.class, variable.getClass());
-
- BlobVariable blobVariable = (BlobVariable) variable;
- byte[] blobVariableBytes = (byte[]) blobVariable.getValue(execution);
- assertTrue(Arrays.equals(bytes, blobVariableBytes));
+ assert Arrays.equals(bytes, (byte[]) execution.getVariable("v"));
+
+ BlobVariable blobVariable = (BlobVariable)
execution.getVariableObject("v");
+ assert Arrays.equals(bytes, blobVariable.getObject());
}
public void testCharsVariable() {
+ char[] chars = new char[1024];
+
ExecutionImpl execution = startProcessInstance();
-
- char[] chars = generateChars("a lot of bytes ", 500);
- assertTrue(chars.length>4500);
execution.setVariable("v", chars);
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(TextVariable.class, variable.getClass());
-
- assertTrue(Arrays.equals(chars, (char[]) execution.getVariable("v")));
+ assert Arrays.equals(chars, (char[]) execution.getVariable("v"));
+
+ TextVariable textVariable = (TextVariable)
execution.getVariableObject("v");
+ assert Arrays.equals(chars, textVariable.getObject());
}
public static class TestSerializable implements Serializable {
+
+ private final int member;
+
private static final long serialVersionUID = 1L;
- int member;
- TestSerializable(int member){this.member = member;}
- public boolean equals(Object o) {
- if (! (o instanceof TestSerializable)) return false;
- return ( member == ((TestSerializable)o).member );
+
+ TestSerializable(int member) {
+ this.member = member;
}
+
+ @Override
+ public int hashCode() {
+ return member;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (!(obj instanceof TestSerializable)) return false;
+
+ TestSerializable other = (TestSerializable) obj;
+ return member == other.member;
+ }
+
}
public void testSerializableVariable() throws Exception {
+ final TestSerializable value = new TestSerializable(76);
+
ExecutionImpl execution = startProcessInstance();
-
- TestSerializable testSerializable = new TestSerializable(76);
- execution.setVariable("v", testSerializable);
-
- Variable variable = execution.getVariableObject("v");
-
- assertEquals(BlobVariable.class, variable.getClass());
- BlobVariable blobVariable = (BlobVariable) variable;
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
- // blobVariable.getObject(); is used to get the bare bytes.
- // blobVariable.getValue() would also use the converter and
- // then the deserialized object is returned
- // ...good idea i'll test that as well below :-)
- byte[] blobVariableBytes = (byte[]) blobVariable.getObject();
- byte[] expected = serialize(testSerializable);
-
- assertTrue(Arrays.equals(expected, blobVariableBytes));
-
- Object deserialized = blobVariable.getValue(execution);
- assertNotNull(deserialized);
- assertEquals(testSerializable, deserialized);
+ BlobVariable blobVariable = (BlobVariable)
execution.getVariableObject("v");
+ assert Arrays.equals(serialize(value), blobVariable.getObject());
}
- private byte[] serialize(TestSerializable testSerializable) {
+ private static byte[] serialize(Object obj) {
try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(testSerializable);
- oos.flush();
- oos.close();
- return baos.toByteArray();
- } catch (IOException e) {
- throw new RuntimeException("couldn't serialize", e);
+ ByteArrayOutputStream memoryStream = new ByteArrayOutputStream();
+ ObjectOutputStream objectStream = new ObjectOutputStream(memoryStream);
+ objectStream.writeObject(obj);
+ objectStream.close();
+ return memoryStream.toByteArray();
}
- }
-
- String generateString(String base, int multiplier) {
- StringBuilder text = new StringBuilder();
- for (int i=0; i<multiplier; i++) {
- text.append(base);
+ catch (IOException e) {
+ throw new AssertionError(e);
}
- return text.toString();
}
-
- byte[] generateBytes(String base, int multiplier) {
- return generateString(base, multiplier).getBytes();
- }
-
- char[] generateChars(String base, int multiplier) {
- return generateString(base, multiplier).toCharArray();
- }
}