diff -Nur src1/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java src2/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java --- src1/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java 2009-03-09 23:30:08.000000000 +0100 +++ src2/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java 2009-12-18 09:43:12.000000000 +0100 @@ -32,13 +32,14 @@ import org.jbpm.JbpmConfiguration; import org.jbpm.JbpmException; import org.jbpm.bytes.ByteArray; -import org.jbpm.context.exe.ContextConverter; +import org.jbpm.context.exe.ProcessDefinitionContextConverter; import org.jbpm.db.hibernate.Converters; import org.jbpm.graph.def.ProcessDefinition; import org.jbpm.graph.exe.Token; import org.jbpm.util.CustomLoaderObjectInputStream; -public class SerializableToByteArrayConverter implements ContextConverter { +public class SerializableToByteArrayConverter implements + ProcessDefinitionContextConverter { private static final long serialVersionUID = 1L; @@ -66,27 +67,30 @@ } public Serializable revert(ByteArray o) { - return revert(o, null); + return revert(o, (ProcessDefinition) null); } public Serializable revert(ByteArray o, Token token) { + return revert(o, token != null ? token.getProcessInstance() + .getProcessDefinition() : null); + } + + public Serializable revert(ByteArray o, ProcessDefinition processDefinition) { InputStream memoryStream = new ByteArrayInputStream(o.getBytes()); try { ObjectInputStream objectStream; - if (token != null) { - ProcessDefinition processDefinition = token.getProcessInstance().getProcessDefinition(); - ClassLoader classLoader = JbpmConfiguration.getProcessClassLoader(processDefinition); - objectStream = new CustomLoaderObjectInputStream(memoryStream, classLoader); - } - else { + if (processDefinition != null) { + ClassLoader classLoader = JbpmConfiguration + .getProcessClassLoader(processDefinition); + objectStream = new CustomLoaderObjectInputStream(memoryStream, + classLoader); + } else { objectStream = new ObjectInputStream(memoryStream); } return (Serializable) objectStream.readObject(); - } - catch (IOException e) { + } catch (IOException e) { throw new JbpmException("failed to read object", e); - } - catch (ClassNotFoundException e) { + } catch (ClassNotFoundException e) { throw new JbpmException("serialized object class not found", e); } } diff -Nur src1/org/jbpm/context/exe/ProcessDefinitionContextConverter.java src2/org/jbpm/context/exe/ProcessDefinitionContextConverter.java --- src1/org/jbpm/context/exe/ProcessDefinitionContextConverter.java 1970-01-01 01:00:00.000000000 +0100 +++ src2/org/jbpm/context/exe/ProcessDefinitionContextConverter.java 2009-12-18 09:41:16.000000000 +0100 @@ -0,0 +1,33 @@ +package org.jbpm.context.exe; + +import org.jbpm.graph.def.ProcessDefinition; + +/** + * Converter able to revert an object also given the context of just a process + * definition. + * + * @author Mauro Molinari + * @param + * the type of the object in its original form + * @param + * the type of the object in its persisted form + * @see JBPM-2692 + * + */ +public interface ProcessDefinitionContextConverter extends + ContextConverter { + + /** + * Reverts a persisted object to its original form, in the context of the + * given process definition. + * + * @param o + * the object in its persisted form + * @param processDefinition + * the process definition + * @return the object in its original form + * + */ + S revert(T o, ProcessDefinition processDefinition); +} \ No newline at end of file diff -Nur src1/org/jbpm/context/exe/VariableInstance.hbm.xml src2/org/jbpm/context/exe/VariableInstance.hbm.xml --- src1/org/jbpm/context/exe/VariableInstance.hbm.xml 2009-03-09 23:30:18.000000000 +0100 +++ src2/org/jbpm/context/exe/VariableInstance.hbm.xml 2009-12-17 17:52:32.000000000 +0100 @@ -40,6 +40,10 @@ column="PROCESSINSTANCE_" foreign-key="FK_VARINST_PRCINST" index="IDX_VARINST_PRCINS" /> + + diff -Nur src1/org/jbpm/context/exe/VariableInstance.java src2/org/jbpm/context/exe/VariableInstance.java --- src1/org/jbpm/context/exe/VariableInstance.java 2009-03-09 23:30:08.000000000 +0100 +++ src2/org/jbpm/context/exe/VariableInstance.java 2009-12-18 12:03:18.000000000 +0100 @@ -27,6 +27,7 @@ import org.jbpm.context.exe.variableinstance.NullInstance; import org.jbpm.context.exe.variableinstance.UnpersistableInstance; import org.jbpm.context.log.VariableCreateLog; +import org.jbpm.graph.def.ProcessDefinition; import org.jbpm.graph.exe.ProcessInstance; import org.jbpm.graph.exe.Token; @@ -48,6 +49,8 @@ protected Object valueCache = null; protected boolean isValueCached = false; + protected ProcessDefinition processDefinition = null; + // constructors ///////////////////////////////////////////////////////////// public VariableInstance() { @@ -67,6 +70,8 @@ if (token != null) { variableInstance.token = token; variableInstance.processInstance = token.getProcessInstance(); + variableInstance.processDefinition = + token.getProcessInstance().getProcessDefinition(); token.addLog(new VariableCreateLog(variableInstance)); } variableInstance.setValue(value); @@ -140,11 +145,14 @@ } Object value = getObject(); if (value != null && converter != null) { - if (converter instanceof ContextConverter && token != null) { + if (converter instanceof ContextConverter && token != null) { ContextConverter contextConverter = (ContextConverter) converter; value = contextConverter.revert(value, token); - } - else { + } else if (converter instanceof ProcessDefinitionContextConverter + && processDefinition != null) { + ProcessDefinitionContextConverter contextConverter = (ProcessDefinitionContextConverter) converter; + value = contextConverter.revert(value, processDefinition); + } else { value = converter.revert(value); } valueCache = value; @@ -161,6 +169,7 @@ // utility methods ///////////////////////////////////////////////////////// + @Override public String toString() { return "${" + name + "}"; } @@ -179,6 +188,11 @@ return token; } + public ProcessDefinition getProcessDefinition() + { + return processDefinition; + } + public void setTokenVariableMap(TokenVariableMap tokenVariableMap) { this.tokenVariableMap = tokenVariableMap; }