[jbpm-commits] JBoss JBPM SVN: r3876 - in jbpm3/trunk/modules/core/src: main/java/org/jbpm/configuration and 10 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Sat Feb 14 04:30:27 EST 2009


Author: alex.guizar at jboss.com
Date: 2009-02-14 04:30:27 -0500 (Sat, 14 Feb 2009)
New Revision: 3876

Added:
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/ContextConverter.java
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1914/
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1914/JBPM1914Test.java
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1914/ObjectToStringConverter.java
   jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm1914/
   jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm1914/jbpm.cfg.xml
   jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm1914/jbpm.varmapping.xml
Removed:
   jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/exe/jbpm.converter.properties
Modified:
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/configuration/JbpmTypeObjectInfo.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/Converter.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/JbpmType.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/VariableInstance.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/BooleanToStringConverter.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/ByteToLongConverter.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/BytesToByteArrayConverter.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/CharacterToStringConverter.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/DateToLongConverter.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/DoubleToStringConverter.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/FloatToDoubleConverter.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/FloatToStringConverter.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/IntegerToLongConverter.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/ShortToLongConverter.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java
   jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/exe/jbpm.varmapping.xml
   jbpm3/trunk/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp18InterleavedParallelRoutingTest.java
Log:
JBPM-1914: prevent ConverterEnumType from retrieving the default JbpmConfiguration in cases where the JbpmContext is closed before the Hibernate session is;
generalize converters

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -342,9 +342,6 @@
     return objectFactoryImpl;
   }
 
-  /**
-   * create an ObjectFacotory from an XML string.
-   */
   public static JbpmConfiguration parseXmlString(String xml) {
     log.debug("creating jbpm configuration from xml string");
     InputStream inputStream = null;

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/configuration/JbpmTypeObjectInfo.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/configuration/JbpmTypeObjectInfo.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/configuration/JbpmTypeObjectInfo.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -23,6 +23,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.jbpm.JbpmException;
 import org.jbpm.context.exe.Converter;
 import org.jbpm.context.exe.JbpmType;
 import org.jbpm.context.exe.JbpmTypeMatcher;
@@ -35,71 +36,112 @@
 public class JbpmTypeObjectInfo extends AbstractObjectInfo {
 
   private static final long serialVersionUID = 1L;
-  
+
   ObjectInfo typeMatcherObjectInfo = null;
-  Converter converter = null;
-  Class variableInstanceClass = null;
-  
+  Converter<?, ?> converter = null;
+  Class<? extends VariableInstance> variableInstanceClass = null;
+
   public JbpmTypeObjectInfo(Element jbpmTypeElement, ObjectFactoryParser objectFactoryParser) {
     super(jbpmTypeElement, objectFactoryParser);
-  
+
+    Element typeMatcherElement = XmlUtil.element(jbpmTypeElement, "matcher");
+    if (typeMatcherElement == null) {
+      throw new ConfigurationException("matcher is a required element in a jbpm-type: "
+          + XmlUtil.toString(jbpmTypeElement));
+    }
+    Element typeMatcherBeanElement = XmlUtil.element(typeMatcherElement);
+    typeMatcherObjectInfo = objectFactoryParser.parse(typeMatcherBeanElement);
+
+    Element converterElement = XmlUtil.element(jbpmTypeElement, "converter");
+    if (converterElement != null) {
+      if (!converterElement.hasAttribute("class")) {
+        throw new ConfigurationException("class attribute is required in a converter element: "
+            + XmlUtil.toString(jbpmTypeElement));
+      }
+      String converterClassName = converterElement.getAttribute("class");
+      converter = Converters.getConverterByClassName(converterClassName);
+    }
+
+    Element variableInstanceElement = XmlUtil.element(jbpmTypeElement, "variable-instance");
+    if (!variableInstanceElement.hasAttribute("class")) {
+      throw new ConfigurationException(
+          "class is a required attribute in element variable-instance: "
+              + XmlUtil.toString(jbpmTypeElement));
+    }
+
+    String variableInstanceClassName = variableInstanceElement.getAttribute("class");
     try {
-      Element typeMatcherElement = XmlUtil.element(jbpmTypeElement, "matcher");
-      if (typeMatcherElement==null) {
-        throw new ConfigurationException("matcher is a required element in a jbpm-type: "+XmlUtil.toString(jbpmTypeElement));
-      }
-      Element typeMatcherBeanElement = XmlUtil.element(typeMatcherElement);
-      typeMatcherObjectInfo = objectFactoryParser.parse(typeMatcherBeanElement);
-      
-      Element converterElement = XmlUtil.element(jbpmTypeElement, "converter");
-      if (converterElement!=null) {
-        if (! converterElement.hasAttribute("class")) {
-          throw new ConfigurationException("class attribute is required in a converter element: "+XmlUtil.toString(jbpmTypeElement));
-        }
-        String converterClassName = converterElement.getAttribute("class");
-        converter = Converters.getConverterByClassName(converterClassName);
-      }
-      
-      Element variableInstanceElement = XmlUtil.element(jbpmTypeElement, "variable-instance");
-      if (! variableInstanceElement.hasAttribute("class")) {
-        throw new ConfigurationException("class is a required attribute in element variable-instance: "+XmlUtil.toString(jbpmTypeElement));
-      }
-      String variableInstanceClassName = variableInstanceElement.getAttribute("class");
-      variableInstanceClass = ClassLoaderUtil.classForName(variableInstanceClassName);
-      if (! VariableInstance.class.isAssignableFrom(variableInstanceClass)) {
-        throw new ConfigurationException("variable instance class '"+variableInstanceClassName+"' is not a VariableInstance");
-      }
-    } catch (ConfigurationException e){
-      throw e;
-    } catch (Exception e) {
-      // NOTE that Error's are not caught because that might halt the JVM and mask the original Error.
-      // Probably the user doesn't need support for this type and doesn't have a required library in the path.
-      // So let's log and ignore
-      log.debug("jbpm variables type "+XmlUtil.toString(jbpmTypeElement)+" couldn't be instantiated properly: "+e.toString());
-      // now, let's make sure that this JbpmType is ignored by always returning false in the JbpmTypeMatcher
-      typeMatcherObjectInfo = new ObjectInfo() {
-        private static final long serialVersionUID = 1L;
-        public boolean hasName() {return false;}
-        public String getName() {return null;}
-        public boolean isSingleton() {return true;}
-        public Object createObject(ObjectFactoryImpl objectFactory) {
-          return new JbpmTypeMatcher() {
-            private static final long serialVersionUID = 1L;
-            public boolean matches(Object value) {
-              return false;
-            }
-          };
-        }
-      };
+      variableInstanceClass = ClassLoaderUtil.classForName(variableInstanceClassName).asSubclass(
+          VariableInstance.class);
+    }
+    catch (JbpmException e) {
+      // Client probably does not need support for this type and omitted the dependency
+      // So let us log and ignore
+      log.debug("could not instantiate jbpm type" + XmlUtil.toString(jbpmTypeElement), e);
+      // make sure this JbpmType is ignored by always returning false in the JbpmTypeMatcher
+      typeMatcherObjectInfo = NoObjectInfo.getInstance();
       converter = null;
       variableInstanceClass = null;
     }
   }
 
+  static class NoObjectInfo implements ObjectInfo {
+
+    private static final long serialVersionUID = 1L;
+
+    private static ObjectInfo instance;
+
+    private NoObjectInfo() {
+      // hide default constructor to prevent instantiation
+    }
+
+    public boolean hasName() {
+      return false;
+    }
+
+    public String getName() {
+      return null;
+    }
+
+    public boolean isSingleton() {
+      return true;
+    }
+
+    public Object createObject(ObjectFactoryImpl objectFactory) {
+      return NoTypeMatcher.getInstance();
+    }
+
+    static ObjectInfo getInstance() {
+      if (instance == null) {
+        instance = new NoObjectInfo();
+      }
+      return instance;
+    }
+  }
+
+  static class NoTypeMatcher implements JbpmTypeMatcher {
+
+    private static final long serialVersionUID = 1L;
+
+    static final JbpmTypeMatcher instance = new NoTypeMatcher();
+
+    private NoTypeMatcher() {
+      // hide default constructor to prevent instantiation
+    }
+
+    public boolean matches(Object value) {
+      return false;
+    }
+
+    static JbpmTypeMatcher getInstance() {
+      return instance;
+    }
+  }
+
   public Object createObject(ObjectFactoryImpl objectFactory) {
     JbpmTypeMatcher jbpmTypeMatcher = (JbpmTypeMatcher) objectFactory.createObject(typeMatcherObjectInfo);
     return new JbpmType(jbpmTypeMatcher, converter, variableInstanceClass);
   }
-  
+
   private static Log log = LogFactory.getLog(JbpmTypeObjectInfo.class);
 }

Added: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/ContextConverter.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/ContextConverter.java	                        (rev 0)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/ContextConverter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.context.exe;
+
+import org.jbpm.graph.exe.Token;
+
+/**
+ * @author Alejandro Guizar
+ */
+public interface ContextConverter<S, T> extends Converter<S, T> {
+
+  /**
+   * reverts a persisted object to its original form,
+   * in the context of the given token.
+   */
+  S revert(T o, Token token);
+}

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/Converter.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/Converter.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/Converter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -21,13 +21,13 @@
  */
 package org.jbpm.context.exe;
 
-import java.io.*;
+import java.io.Serializable;
 
 /**
  * converts plain objects to objects that are 
  * persistable via a subclass of VariableInstance. 
  */
-public interface Converter extends Serializable {
+public interface Converter<S, T> extends Serializable {
 
   /**
    * is true if this converter supports the given type, false otherwise.
@@ -37,10 +37,10 @@
   /**
    * converts a given object to its persistable format.
    */
-  Object convert(Object o);
+  T convert(S o);
 
   /**
    * reverts a persisted object to its original form.
    */
-  Object revert(Object o);
+  S revert(T o);
 }

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/JbpmType.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/JbpmType.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/JbpmType.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -40,9 +40,9 @@
 
   static Map<ObjectFactory, List<JbpmType>> jbpmTypesCache = new HashMap<ObjectFactory, List<JbpmType>>();
 
-  JbpmTypeMatcher jbpmTypeMatcher = null;
-  Converter converter = null;
-  Class<? extends VariableInstance> variableInstanceClass = null;
+  final JbpmTypeMatcher jbpmTypeMatcher;
+  final Converter converter;
+  final Class<? extends VariableInstance> variableInstanceClass;
 
   public JbpmType(JbpmTypeMatcher jbpmTypeMatcher, Converter converter,
       Class<? extends VariableInstance> variableInstanceClass) {
@@ -51,6 +51,10 @@
     this.variableInstanceClass = variableInstanceClass;
   }
 
+  public Converter getConverter() {
+    return converter;
+  }
+
   public boolean matches(Object value) {
     return jbpmTypeMatcher.matches(value);
   }

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/VariableInstance.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/VariableInstance.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/VariableInstance.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -24,7 +24,6 @@
 import java.io.Serializable;
 
 import org.jbpm.JbpmException;
-import org.jbpm.context.exe.converter.SerializableToByteArrayConverter;
 import org.jbpm.context.exe.variableinstance.NullInstance;
 import org.jbpm.context.exe.variableinstance.UnpersistableInstance;
 import org.jbpm.context.log.VariableCreateLog;
@@ -45,7 +44,7 @@
   protected Token token = null;
   protected TokenVariableMap tokenVariableMap = null;
   protected ProcessInstance processInstance = null;
-  protected Converter converter = null;
+  protected Converter<? super Object, ? super Object> converter = null;
   protected Object valueCache = null;
   protected boolean isValueCached = false;
 
@@ -64,10 +63,10 @@
       variableInstance = createVariableInstance(value);
     }
 
-    variableInstance.token = token;
     variableInstance.name = name;
-    variableInstance.processInstance = (token != null ? token.getProcessInstance() : null);
     if (token != null) {
+      variableInstance.token = token;
+      variableInstance.processInstance = token.getProcessInstance();
       token.addLog(new VariableCreateLog(variableInstance));
     }
     variableInstance.setValue(value);
@@ -140,10 +139,10 @@
       return valueCache;
     }
     Object value = getObject();
-    if ((value != null) && (converter != null)) {
-      if (converter instanceof SerializableToByteArrayConverter && processInstance != null) {
-        SerializableToByteArrayConverter s2bConverter = (SerializableToByteArrayConverter) converter;
-        value = s2bConverter.revert(value, processInstance.getProcessDefinition());
+    if (value != null && converter != null) {
+      if (converter instanceof ContextConverter && token != null) {
+        ContextConverter<?, ? super Object> contextConverter = (ContextConverter<?, ? super Object>) converter;
+        value = contextConverter.revert(value, token);
       }
       else {
         value = converter.revert(value);

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/BooleanToStringConverter.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/BooleanToStringConverter.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/BooleanToStringConverter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -21,29 +21,33 @@
  */
 package org.jbpm.context.exe.converter;
 
-import org.jbpm.context.exe.*;
+import org.jbpm.context.exe.Converter;
+import org.jbpm.db.hibernate.Converters;
 
-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 BooleanToStringConverter() {
+    Converters.registerConverter("B", this);
+  }
+
   public boolean supports(Object value) {
-    if (value==null) return true;
-    return (value.getClass()==Boolean.class);
+    return value instanceof Boolean;
   }
 
-  public Object convert(Object o) {
+  public String convert(Boolean o) {
     String convertedValue = FALSE_TEXT;
-    if (((Boolean)o).booleanValue()) {
+    if (o.booleanValue()) {
       convertedValue = TRUE_TEXT;
     }
     return convertedValue;
   }
 
-  public Object revert(Object o) {
+  public Boolean revert(String o) {
     Boolean revertedValue = Boolean.FALSE;
     if (TRUE_TEXT.equals(o)) {
       revertedValue = Boolean.TRUE;

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/ByteToLongConverter.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/ByteToLongConverter.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/ByteToLongConverter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -21,22 +21,26 @@
  */
 package org.jbpm.context.exe.converter;
 
-import org.jbpm.context.exe.*;
+import org.jbpm.context.exe.Converter;
+import org.jbpm.db.hibernate.Converters;
 
-public class ByteToLongConverter implements Converter {
-  
+public class ByteToLongConverter implements Converter<Byte, Long> {
+
   private static final long serialVersionUID = 1L;
 
+  public ByteToLongConverter() {
+    Converters.registerConverter("E", this);
+  }
+
   public boolean supports(Object value) {
-    if (value==null) return true;
-    return (value.getClass()==Byte.class);
+    return value instanceof Byte;
   }
 
-  public Object convert(Object o) {
-    return new Long( ((Number)o).longValue() );
+  public Long convert(Byte o) {
+    return o.longValue();
   }
 
-  public Object revert(Object o) {
-    return new Byte(((Long)o).byteValue());
+  public Byte revert(Long o) {
+    return o.byteValue();
   }
 }
\ No newline at end of file

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/BytesToByteArrayConverter.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/BytesToByteArrayConverter.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/BytesToByteArrayConverter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -23,22 +23,26 @@
 
 import org.jbpm.bytes.ByteArray;
 import org.jbpm.context.exe.Converter;
+import org.jbpm.db.hibernate.Converters;
 
-public class BytesToByteArrayConverter implements Converter {
+public class BytesToByteArrayConverter implements Converter<byte[], ByteArray> {
 
   private static final long serialVersionUID = 1L;
 
+  public BytesToByteArrayConverter() {
+    Converters.registerConverter("Y", this);
+  }
+
   public boolean supports(Object value) {
-    if (value==null) return true;
-    return (value.getClass()==byte[].class);
+    return value instanceof byte[];
   }
 
-  public Object convert(Object o) {
-    return new ByteArray((byte[]) o);
+  public ByteArray convert(byte[] o) {
+    return new ByteArray(o);
   }
 
-  public Object revert(Object o) {
-    return ((ByteArray)o).getBytes();
+  public byte[] revert(ByteArray o) {
+    return o.getBytes();
   }
 
 }

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/CharacterToStringConverter.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/CharacterToStringConverter.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/CharacterToStringConverter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -21,22 +21,26 @@
  */
 package org.jbpm.context.exe.converter;
 
-import org.jbpm.context.exe.*;
+import org.jbpm.context.exe.Converter;
+import org.jbpm.db.hibernate.Converters;
 
-public class CharacterToStringConverter implements Converter {
+public class CharacterToStringConverter implements Converter<Character, String> {
 
   private static final long serialVersionUID = 1L;
 
+  public CharacterToStringConverter() {
+    Converters.registerConverter("C", this);
+  }
+
   public boolean supports(Object value) {
-    if (value==null) return true;
-    return (value.getClass()==Character.class);
+    return value instanceof Character;
   }
 
-  public Object convert(Object o) {
+  public String convert(Character o) {
     return o.toString();
   }
 
-  public Object revert(Object o) {
-    return new Character(((String)o).charAt(0));
+  public Character revert(String o) {
+    return o.charAt(0);
   }
 }

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/DateToLongConverter.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/DateToLongConverter.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/DateToLongConverter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -21,23 +21,28 @@
  */
 package org.jbpm.context.exe.converter;
 
-import java.util.*;
-import org.jbpm.context.exe.*;
+import java.util.Date;
 
-public class DateToLongConverter implements Converter {
+import org.jbpm.context.exe.Converter;
+import org.jbpm.db.hibernate.Converters;
 
+public class DateToLongConverter implements Converter<Date, Long> {
+
   private static final long serialVersionUID = 1L;
 
+  public DateToLongConverter() {
+    Converters.registerConverter("A", this);
+  }
+
   public boolean supports(Object value) {
-    if (value==null) return true;
-    return (Date.class.isAssignableFrom(value.getClass()));
+    return value instanceof Date;
   }
 
-  public Object convert(Object o) {
-    return new Long(((Date)o).getTime());
+  public Long convert(Date o) {
+    return o.getTime();
   }
 
-  public Object revert(Object o) {
-    return new Date(((Long)o).longValue());
+  public Date revert(Long o) {
+    return new Date(o);
   }
 }

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/DoubleToStringConverter.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/DoubleToStringConverter.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/DoubleToStringConverter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -21,23 +21,27 @@
  */
 package org.jbpm.context.exe.converter;
 
-import org.jbpm.context.exe.*;
+import org.jbpm.context.exe.Converter;
+import org.jbpm.db.hibernate.Converters;
 
-public class DoubleToStringConverter implements Converter {
+public class DoubleToStringConverter implements Converter<Double, String> {
 
   private static final long serialVersionUID = 1L;
 
+  public DoubleToStringConverter() {
+    Converters.registerConverter("D", this);
+  }
+
   public boolean supports(Object value) {
-    if (value==null) return true;
-    return (value.getClass()==Double.class);
+    return value instanceof Double;
   }
 
-  public Object convert(Object o) {
+  public String convert(Double o) {
     return o.toString();
   }
 
-  public Object revert(Object o) {
-    return new Double((String)o);
+  public Double revert(String o) {
+    return new Double(o);
   }
 
 }

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/FloatToDoubleConverter.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/FloatToDoubleConverter.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/FloatToDoubleConverter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -22,22 +22,26 @@
 package org.jbpm.context.exe.converter;
 
 import org.jbpm.context.exe.Converter;
+import org.jbpm.db.hibernate.Converters;
 
-public class FloatToDoubleConverter implements Converter {
+public class FloatToDoubleConverter implements Converter<Float, Double> {
 
   private static final long serialVersionUID = 1L;
 
+  public FloatToDoubleConverter() {
+    Converters.registerConverter("G", this);
+  }
+
   public boolean supports(Object value) {
-    if (value==null) return true;
-    return (value.getClass()==Float.class);
+    return value instanceof Float;
   }
 
-  public Object convert(Object o) {
-    return new Double(((Float)o).doubleValue());
+  public Double convert(Float o) {
+    return o.doubleValue();
   }
 
-  public Object revert(Object o) {
-    return new Float(((Double)o).floatValue());
+  public Float revert(Double o) {
+    return o.floatValue();
   }
 
 }

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/FloatToStringConverter.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/FloatToStringConverter.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/FloatToStringConverter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -21,23 +21,27 @@
  */
 package org.jbpm.context.exe.converter;
 
-import org.jbpm.context.exe.*;
+import org.jbpm.context.exe.Converter;
+import org.jbpm.db.hibernate.Converters;
 
-public class FloatToStringConverter implements Converter {
+public class FloatToStringConverter implements Converter<Float, String> {
 
   private static final long serialVersionUID = 1L;
 
+  public FloatToStringConverter() {
+    Converters.registerConverter("F", this);
+  }
+
   public boolean supports(Object value) {
-    if (value==null) return true;
-    return (value.getClass()==Float.class);
+    return value instanceof Float;
   }
 
-  public Object convert(Object o) {
+  public String convert(Float o) {
     return o.toString();
   }
 
-  public Object revert(Object o) {
-    return new Float((String)o);
+  public Float revert(String o) {
+    return new Float(o);
   }
 
 }

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/IntegerToLongConverter.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/IntegerToLongConverter.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/IntegerToLongConverter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -21,22 +21,26 @@
  */
 package org.jbpm.context.exe.converter;
 
-import org.jbpm.context.exe.*;
+import org.jbpm.context.exe.Converter;
+import org.jbpm.db.hibernate.Converters;
 
-public class IntegerToLongConverter implements Converter {
-  
+public class IntegerToLongConverter implements Converter<Integer, Long> {
+
   private static final long serialVersionUID = 1L;
 
+  public IntegerToLongConverter() {
+    Converters.registerConverter("I", this);
+  }
+
   public boolean supports(Object value) {
-    if (value==null) return true;
-    return (Integer.class.equals(value.getClass()));
+    return value instanceof Integer;
   }
 
-  public Object convert(Object o) {
-    return new Long( ((Number)o).longValue() );
+  public Long convert(Integer o) {
+    return o.longValue();
   }
 
-  public Object revert(Object o) {
-    return new Integer(((Long)o).intValue());
+  public Integer revert(Long o) {
+    return o.intValue();
   }
 }

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -32,62 +32,62 @@
 import org.jbpm.JbpmConfiguration;
 import org.jbpm.JbpmException;
 import org.jbpm.bytes.ByteArray;
-import org.jbpm.context.exe.Converter;
+import org.jbpm.context.exe.ContextConverter;
+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 Converter {
+public class SerializableToByteArrayConverter implements ContextConverter<Serializable, ByteArray> {
 
-	private static final long serialVersionUID = 1L;
+  private static final long serialVersionUID = 1L;
 
-	public boolean supports(Object value) {
-		if(value == null)
-			return true;
-		return Serializable.class.isAssignableFrom(value.getClass());
-	}
+  public SerializableToByteArrayConverter() {
+    Converters.registerConverter("R", this);
+  }
 
-	public Object convert(Object o) {
-		byte[] bytes = null;
-		try {
-			ByteArrayOutputStream memoryStream = new ByteArrayOutputStream();
-			ObjectOutputStream objectStream = new ObjectOutputStream(memoryStream);
-			objectStream.writeObject(o);
-			objectStream.flush();
-			bytes = memoryStream.toByteArray();
-		}
-		catch(IOException e) {
-			throw new JbpmException("couldn't serialize '" + o + "'", e);
-		}
-		return new ByteArray(bytes);
-	}
+  public boolean supports(Object value) {
+    return value instanceof Serializable;
+  }
 
-	public Object revert(Object o) {
-		ByteArray byteArray = (ByteArray) o;
-		InputStream memoryStream = new ByteArrayInputStream(byteArray.getBytes());
-		try {
-			ObjectInputStream objectStream = new ObjectInputStream(memoryStream);
-			return objectStream.readObject();
-		}
-		catch(IOException ex) {
-			throw new JbpmException("failed to read object", ex);
-		}
-		catch(ClassNotFoundException ex) {
-			throw new JbpmException("serialized object class not found", ex);
-		}
-	}
+  public ByteArray convert(Serializable o) {
+    byte[] bytes = null;
+    try {
+      ByteArrayOutputStream memoryStream = new ByteArrayOutputStream();
+      ObjectOutputStream objectStream = new ObjectOutputStream(memoryStream);
+      objectStream.writeObject(o);
+      objectStream.flush();
+      bytes = memoryStream.toByteArray();
+    }
+    catch (IOException e) {
+      throw new JbpmException("could not serialize: " + o, e);
+    }
+    return new ByteArray(bytes);
+  }
 
-	public Object revert(Object o, ProcessDefinition processDefinition) {
-		ByteArray byteArray = (ByteArray) o;
-		InputStream memoryStream = new ByteArrayInputStream(byteArray.getBytes());
-		try {
-		  ObjectInputStream objectStream = new CustomLoaderObjectInputStream(memoryStream, JbpmConfiguration.getProcessClassLoader(processDefinition));
-			return objectStream.readObject();
-		}
-		catch(IOException ex) {
-			throw new JbpmException("failed to read object", ex);
-		}
-		catch(ClassNotFoundException ex) {
-			throw new JbpmException("serialized object class not found", ex);
-		}
-	}
+  public Serializable revert(ByteArray o) {
+    return revert(o, null);
+  }
+
+  public Serializable revert(ByteArray o, Token token) {
+    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 {
+        objectStream = new ObjectInputStream(memoryStream);
+      }
+      return (Serializable) objectStream.readObject();
+    }
+    catch (IOException e) {
+      throw new JbpmException("failed to read object", e);
+    }
+    catch (ClassNotFoundException e) {
+      throw new JbpmException("serialized object class not found", e);
+    }
+  }
 }

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/ShortToLongConverter.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/ShortToLongConverter.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/ShortToLongConverter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -21,22 +21,27 @@
  */
 package org.jbpm.context.exe.converter;
 
-import org.jbpm.context.exe.*;
+import org.jbpm.context.exe.Converter;
+import org.jbpm.db.hibernate.Converters;
 
-public class ShortToLongConverter implements Converter {
-  
+public class ShortToLongConverter implements Converter<Short, Long> {
+
   private static final long serialVersionUID = 1L;
 
+  public ShortToLongConverter() {
+    Converters.registerConverter("H", this);
+  }
+
   public boolean supports(Object value) {
-    if (value==null) return true;
-    return (value.getClass()==Short.class);
+    if (value == null) return true;
+    return (value.getClass() == Short.class);
   }
 
-  public Object convert(Object o) {
-    return new Long( ((Number)o).longValue() );
+  public Long convert(Short o) {
+    return o.longValue();
   }
-  
-  public Object revert(Object o) {
-    return new Short(((Long)o).shortValue());
+
+  public Short revert(Long o) {
+    return o.shortValue();
   }
 }

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -23,14 +23,12 @@
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Properties;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.jbpm.JbpmConfiguration;
 import org.jbpm.JbpmException;
-import org.jbpm.configuration.ObjectFactory;
 import org.jbpm.context.exe.Converter;
+import org.jbpm.context.exe.JbpmType;
 import org.jbpm.util.ClassLoaderUtil;
 
 /**
@@ -38,7 +36,12 @@
  */
 public class Converters {
 
-  private static Map<ObjectFactory, ConverterMaps> converterMapsMap = new HashMap<ObjectFactory, ConverterMaps>();
+  // maps class names to unique converter objects
+  private static final Map<String, Converter<?, ?>> convertersByClassNames = new HashMap<String, Converter<?, ?>>();
+  // maps converter database-id-strings to unique converter objects
+  private static final Map<String, Converter<?, ?>> convertersByDatabaseId = new HashMap<String, Converter<?, ?>>();
+  // maps unique converter objects to their database-id-string
+  private static final Map<Converter<?, ?>, String> convertersIds = new HashMap<Converter<?, ?>, String>();
 
   private Converters() {
     // hide default constructor to prevent instantiation
@@ -46,110 +49,54 @@
 
   // public methods
 
-  public static Converter getConverterByClassName(String className) {
-    Converter converter = getConvertersByClassNames().get(className);
+  public static Converter<?, ?> getConverterByClassName(String className) {
+    Converter<?, ?> converter = convertersByClassNames.get(className);
     if (converter == null) {
-      throw new JbpmException("converter '" + className + "' is not declared in resource.converter");
+      Class<? extends Converter<?, ?>> converterClass = getConverterClass(className);
+      try {
+        // the converter will register itself
+        converter = converterClass.newInstance();
+      }
+      catch (InstantiationException e) {
+        log.debug("could not instantiate converter '" + className + "': " + e);
+      }
+      catch (IllegalAccessException e) {
+        log.debug("could not access converter: '" + className + "': " + e);
+      }
     }
     return converter;
   }
 
-  public static Converter getConverterByDatabaseId(String converterDatabaseId) {
-    return getConvertersByDatabaseId().get(converterDatabaseId);
+  public static Converter<?, ?> getConverterByDatabaseId(String databaseId) {
+    if (convertersByDatabaseId.isEmpty()) {
+      JbpmType.getJbpmTypes();
+    }
+    return convertersByDatabaseId.get(databaseId);
   }
 
-  public static String getConverterId(Converter converter) {
-    return getConvertersIds().get(converter);
+  public static String getConverterId(Converter<?, ?> converter) {
+    // the converter has registered itself during instantiation
+    // hence there is no need to check whether the map is populated already
+    return convertersIds.get(converter);
   }
 
-  // maps class names to unique converter objects
-  static Map<String, Converter> getConvertersByClassNames() {
-    return getConverterMaps().getConvertersByClassNames();
-  }
+  public static void registerConverter(String databaseId, Converter<?, ?> converter) {
+    if (databaseId.length() != 1)
+      throw new JbpmException("converter-ids must be of length 1 (to be stored in a char)");
+    if (convertersByDatabaseId.containsKey(databaseId))
+      throw new JbpmException("duplicate converter id: '" + databaseId + "'");
 
-  // maps converter database-id-strings to unique converter objects
-  static Map<String, Converter> getConvertersByDatabaseId() {
-    return getConverterMaps().getConvertersByDatabaseId();
+    log.debug("adding converter '" + databaseId + "', '" + converter + "'");
+    convertersByClassNames.put(converter.getClass().getName(), converter);
+    convertersByDatabaseId.put(databaseId, converter);
+    convertersIds.put(converter, databaseId);
   }
 
-  // maps unique converter objects to their database-id-string
-  static Map<Converter, String> getConvertersIds() {
-    return getConverterMaps().getConvertersIds();
+  @SuppressWarnings("unchecked")
+  private static Class<? extends Converter<?, ?>> getConverterClass(String className) {
+    return (Class<? extends Converter<?, ?>>) ClassLoaderUtil.classForName(className).asSubclass(
+        Converter.class);
   }
 
-  static ConverterMaps getConverterMaps() {
-    ObjectFactory objectFactory = JbpmConfiguration.Configs.getObjectFactory();
-    ConverterMaps converterMaps;
-    synchronized (converterMapsMap) {
-      converterMaps = converterMapsMap.get(objectFactory);
-      if (converterMaps == null) {
-        converterMaps = createConverterMaps(objectFactory);
-        converterMapsMap.put(objectFactory, converterMaps);
-      }
-    }
-    return converterMaps;
-  }
-
-  static ConverterMaps createConverterMaps(ObjectFactory objectFactory) {
-    Properties converterProperties;
-    if (objectFactory.hasObject("resource.converter")) {
-      String resource = (String) objectFactory.createObject("resource.converter");
-      converterProperties = ClassLoaderUtil.getProperties(resource);
-    }
-    else {
-      converterProperties = new Properties();
-    }
-
-    ConverterMaps converterMaps = new ConverterMaps();
-    for (Map.Entry<Object, Object> entry : converterProperties.entrySet()) {
-      String databaseId = (String) entry.getKey();
-      String className = (String) entry.getValue();
-      converterMaps.registerConverter(databaseId, className);
-    }
-
-    return converterMaps;
-  }
-
-  static class ConverterMaps {
-
-    private final Map<String, Converter> convertersByClassNames = new HashMap<String, Converter>();
-    private final Map<String, Converter> convertersByDatabaseId = new HashMap<String, Converter>();
-    private final Map<Converter, String> convertersIds = new HashMap<Converter, String>();
-
-    public void registerConverter(String databaseId, String className) {
-      if (databaseId.length() != 1)
-        throw new JbpmException("converter-ids must be of length 1 (to be stored in a char)");
-      if (convertersByDatabaseId.containsKey(databaseId))
-        throw new JbpmException("duplicate converter id: '" + databaseId + "'");
-
-      try {
-        Class<? extends Converter> converterClass = ClassLoaderUtil.classForName(className)
-            .asSubclass(Converter.class);
-        Converter converter = converterClass.newInstance();
-        log.debug("adding converter '" + databaseId + "', '" + className + "'");
-        convertersByClassNames.put(className, converter);
-        convertersByDatabaseId.put(databaseId, converter);
-        convertersIds.put(converter, databaseId);
-      }
-      catch (Exception e) {
-        // NOTE that Errors are not caught because that might mask the original Error
-        // and halt the JVM
-        log.debug("couldn't instantiate converter '" + className + "': " + e);
-      }
-    }
-
-    public Map<String, Converter> getConvertersByClassNames() {
-      return convertersByClassNames;
-    }
-
-    public Map<String, Converter> getConvertersByDatabaseId() {
-      return convertersByDatabaseId;
-    }
-
-    public Map<Converter, String> getConvertersIds() {
-      return convertersIds;
-    }
-  }
-
   private static Log log = LogFactory.getLog(Converters.class);
 }

Deleted: jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/exe/jbpm.converter.properties
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/exe/jbpm.converter.properties	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/exe/jbpm.converter.properties	2009-02-14 09:30:27 UTC (rev 3876)
@@ -1,17 +0,0 @@
-# this file contains the mappings between converter types 
-# and the char that is used in the database.  this mapping 
-# is used by the ConverterEnumType to store the VariableInstance 
-# converter field.  The Converters class provides singleton access 
-# to these converter classes.
-
-B org.jbpm.context.exe.converter.BooleanToStringConverter
-Y org.jbpm.context.exe.converter.BytesToByteArrayConverter
-E org.jbpm.context.exe.converter.ByteToLongConverter
-C org.jbpm.context.exe.converter.CharacterToStringConverter
-A org.jbpm.context.exe.converter.DateToLongConverter
-D org.jbpm.context.exe.converter.DoubleToStringConverter
-F org.jbpm.context.exe.converter.FloatToStringConverter
-G org.jbpm.context.exe.converter.FloatToDoubleConverter
-I org.jbpm.context.exe.converter.IntegerToLongConverter
-R org.jbpm.context.exe.converter.SerializableToByteArrayConverter
-H org.jbpm.context.exe.converter.ShortToLongConverter

Modified: jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/exe/jbpm.varmapping.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/exe/jbpm.varmapping.xml	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/exe/jbpm.varmapping.xml	2009-02-14 09:30:27 UTC (rev 3876)
@@ -12,7 +12,7 @@
 <jbpm-types>
 
   <list name="jbpm.types" singleton="true">
-  
+
     <!-- java.lang.String -->
     <jbpm-type>
       <matcher>
@@ -22,7 +22,7 @@
       </matcher>
       <variable-instance class="org.jbpm.context.exe.variableinstance.StringInstance" />
     </jbpm-type>
-      
+
     <!-- java.lang.Boolean -->
     <jbpm-type>
       <matcher>
@@ -33,7 +33,7 @@
       <converter class="org.jbpm.context.exe.converter.BooleanToStringConverter" />
       <variable-instance class="org.jbpm.context.exe.variableinstance.StringInstance" />
     </jbpm-type>
-      
+
     <!-- java.lang.Character -->
     <jbpm-type>
       <matcher>
@@ -44,7 +44,7 @@
       <converter class="org.jbpm.context.exe.converter.CharacterToStringConverter" />
       <variable-instance class="org.jbpm.context.exe.variableinstance.StringInstance" />
     </jbpm-type>
-      
+
     <!-- java.lang.Long -->
     <jbpm-type>
       <matcher>
@@ -65,7 +65,7 @@
       <converter class="org.jbpm.context.exe.converter.ByteToLongConverter" />
       <variable-instance class="org.jbpm.context.exe.variableinstance.LongInstance" />
     </jbpm-type>
-  
+
     <!-- java.lang.Short -->
     <jbpm-type>
       <matcher>
@@ -76,7 +76,7 @@
       <converter class="org.jbpm.context.exe.converter.ShortToLongConverter" />
       <variable-instance class="org.jbpm.context.exe.variableinstance.LongInstance" />
     </jbpm-type>
-  
+
     <!-- java.lang.Integer -->
     <jbpm-type>
       <matcher>
@@ -87,7 +87,7 @@
       <converter class="org.jbpm.context.exe.converter.IntegerToLongConverter" />
       <variable-instance class="org.jbpm.context.exe.variableinstance.LongInstance" />
     </jbpm-type>
-  
+
     <!-- java.lang.Double -->
     <jbpm-type>
       <matcher>
@@ -97,7 +97,7 @@
       </matcher>
       <variable-instance class="org.jbpm.context.exe.variableinstance.DoubleInstance" />
     </jbpm-type>
-  
+
     <!-- java.lang.Float -->
     <jbpm-type>
       <matcher>
@@ -108,7 +108,7 @@
       <converter class="org.jbpm.context.exe.converter.FloatToDoubleConverter" />
       <variable-instance class="org.jbpm.context.exe.variableinstance.DoubleInstance" />
     </jbpm-type>
-  
+
     <!-- java.util.Date -->
     <jbpm-type>
       <matcher>
@@ -118,7 +118,7 @@
       </matcher>
       <variable-instance class="org.jbpm.context.exe.variableinstance.DateInstance" />
     </jbpm-type>
-  
+
     <!-- byte[] -->
     <jbpm-type>
       <matcher>
@@ -129,7 +129,7 @@
       <converter class="org.jbpm.context.exe.converter.BytesToByteArrayConverter" />
       <variable-instance class="org.jbpm.context.exe.variableinstance.ByteArrayInstance" />
     </jbpm-type>
-  
+
     <!-- hibernatable long id types -->
     <jbpm-type>
       <matcher>
@@ -137,7 +137,7 @@
       </matcher>
       <variable-instance class="org.jbpm.context.exe.variableinstance.HibernateLongInstance" />
     </jbpm-type>
-  
+
     <!-- hibernatable string id types -->
     <jbpm-type>
       <matcher>
@@ -145,16 +145,7 @@
       </matcher>
       <variable-instance class="org.jbpm.context.exe.variableinstance.HibernateStringInstance" />
     </jbpm-type>
-  
-    <!-- java.io.Serializable -->
-    <jbpm-type>
-      <matcher>
-        <bean class="org.jbpm.context.exe.matcher.SerializableMatcher" />
-      </matcher>
-      <converter class="org.jbpm.context.exe.converter.SerializableToByteArrayConverter" />
-      <variable-instance class="org.jbpm.context.exe.variableinstance.ByteArrayInstance" />
-    </jbpm-type>
-  
+
     <!-- hibernatable ejb3 types -->
     <jbpm-type>
       <matcher>
@@ -162,15 +153,24 @@
       </matcher>
       <variable-instance class="org.jbpm.context.exe.variableinstance.Ejb3Instance" />
     </jbpm-type>
-    
+
     <!-- JSR 170 JCR Node -->
     <jbpm-type>
       <matcher>
         <bean class="org.jbpm.context.exe.matcher.JcrNodeMatcher" />
       </matcher>
       <variable-instance class="org.jbpm.context.exe.variableinstance.JcrNodeInstance" />
-    </jbpm-type>    
-    
+    </jbpm-type>
+
+    <!-- java.io.Serializable -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.SerializableMatcher" />
+      </matcher>
+      <converter class="org.jbpm.context.exe.converter.SerializableToByteArrayConverter" />
+      <variable-instance class="org.jbpm.context.exe.variableinstance.ByteArrayInstance" />
+    </jbpm-type>
+
   </list>
 
 </jbpm-types>

Modified: jbpm3/trunk/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml	2009-02-14 09:30:27 UTC (rev 3876)
@@ -24,7 +24,6 @@
   <!-- configuration resource files pointing to default configuration files in jbpm-{version}.jar -->
   <string name="resource.business.calendar" value="org/jbpm/calendar/jbpm.business.calendar.properties" />
   <string name="resource.default.modules" value="org/jbpm/graph/def/jbpm.default.modules.properties" />
-  <string name="resource.converter" value="org/jbpm/context/exe/jbpm.converter.properties" />
   <string name="resource.action.types" value="org/jbpm/graph/action/action.types.xml" />
   <string name="resource.node.types" value="org/jbpm/graph/node/node.types.xml" />
   <string name="resource.parsers" value="org/jbpm/jpdl/par/jbpm.parsers.xml" />

Added: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1914/JBPM1914Test.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1914/JBPM1914Test.java	                        (rev 0)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1914/JBPM1914Test.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.jbpm1914;
+
+import java.io.IOException;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.jbpm.db.AbstractDbTestCase;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+
+/**
+ * Problem in retrieving variables of Serializable objects.
+ * 
+ * @see <a href="https://jira.jboss.org/jira/browse/JBPM-1914">JBPM-1914</a>
+ * @author Alejandro Guizar
+ */
+public class JBPM1914Test extends AbstractDbTestCase {
+
+  @Override
+  protected String getJbpmTestConfig() {
+    return "org/jbpm/jbpm1914/jbpm.cfg.xml";
+  }
+
+  public void testCustomSerializableVariableClass() throws IOException {
+    // create and save the process definition
+    ProcessDefinition processDefinition = ProcessDefinition.parseParResource("org/jbpm/jbpm1024/CustomSerializable.zip");
+    graphSession.deployProcessDefinition(processDefinition);
+    SessionFactory sessionFactory = jbpmContext.getSessionFactory();
+
+    commitAndCloseSession();
+    try {
+      Session session = sessionFactory.openSession();
+      Transaction transaction = session.beginTransaction();
+
+      jbpmContext = jbpmConfiguration.createJbpmContext();
+      jbpmContext.setSession(session);
+
+      // create the process instance
+      ProcessInstance processInstance = new ProcessInstance(processDefinition);
+      jbpmContext.save(processInstance);
+      jbpmContext.close();
+
+      transaction.commit();
+      session.close();
+
+      // get the custom object from the context instance
+      beginSessionTransaction();
+      processInstance = jbpmContext.loadProcessInstance(processInstance.getId());
+      Object customSerializable = processInstance.getContextInstance().getVariable(
+          "custom serializable");
+      assertEquals("org.jbpm.context.exe.CustomSerializableClass", customSerializable.getClass()
+          .getName());
+      assertEquals("1984", customSerializable.toString());
+    }
+    finally {
+      newTransaction();
+      jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
+    }
+  }
+}

Added: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1914/ObjectToStringConverter.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1914/ObjectToStringConverter.java	                        (rev 0)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1914/ObjectToStringConverter.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.jbpm1914;
+
+import java.lang.reflect.Constructor;
+
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmException;
+import org.jbpm.context.exe.ContextConverter;
+import org.jbpm.db.hibernate.Converters;
+import org.jbpm.graph.exe.Token;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class ObjectToStringConverter implements ContextConverter<Object, String> {
+
+  private static final long serialVersionUID = 1L;
+  private static final char SEPARATOR = ';';
+
+  public ObjectToStringConverter() {
+    Converters.registerConverter("$", this);
+  }
+
+  public String convert(Object o) {
+    return o.getClass().getName() + SEPARATOR + o;
+  }
+
+  public Object revert(String o) {
+    return revert(o, null);
+  }
+
+  public Object revert(String o, Token token) {
+    int separatorIndex = o.indexOf(SEPARATOR);
+    try {
+      ClassLoader classLoader = null;
+      if (token != null) {
+        classLoader = JbpmConfiguration.getProcessClassLoader(token.getProcessInstance()
+            .getProcessDefinition());
+      }
+      Class<?> type = Class.forName(o.substring(0, separatorIndex), true, classLoader);
+      Constructor<?> constructor = type.getConstructor(String.class);
+
+      return constructor.newInstance(o.substring(separatorIndex + 1));
+    }
+    catch (RuntimeException e) {
+      throw e;
+    }
+    catch (Exception e) {
+      throw new JbpmException("could not revert: " + o, e);
+    }
+  }
+
+  public boolean supports(Object value) {
+    return true;
+  }
+
+}

Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp18InterleavedParallelRoutingTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp18InterleavedParallelRoutingTest.java	2009-02-13 17:09:13 UTC (rev 3875)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/patterns/Wfp18InterleavedParallelRoutingTest.java	2009-02-14 09:30:27 UTC (rev 3876)
@@ -69,13 +69,13 @@
   private State d = (State) processDefinition.getNode("d");
   private State e = (State) processDefinition.getNode("e");
   
-  private static String[][] scenarioSequences = new String[][] {
-    new String[] {"b", "c", "d"},
-    new String[] {"b", "d", "c"},
-    new String[] {"c", "b", "d"},
-    new String[] {"c", "d", "b"},
-    new String[] {"d", "b", "c"},
-    new String[] {"d", "c", "b"}
+  private static String[][] scenarioSequences = {
+    {"b", "c", "d"},
+    {"b", "d", "c"},
+    {"c", "b", "d"},
+    {"c", "d", "b"},
+    {"d", "b", "c"},
+    {"d", "c", "b"}
   };
   
   public class ScenarioInterleaver implements InterleaveStart.Interleaver {

Added: jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm1914/jbpm.cfg.xml
===================================================================
--- jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm1914/jbpm.cfg.xml	                        (rev 0)
+++ jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm1914/jbpm.cfg.xml	2009-02-14 09:30:27 UTC (rev 3876)
@@ -0,0 +1,3 @@
+<jbpm-configuration>
+  <string name="resource.varmapping" value="org/jbpm/jbpm1914/jbpm.varmapping.xml" />
+</jbpm-configuration>
\ No newline at end of file

Added: jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm1914/jbpm.varmapping.xml
===================================================================
--- jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm1914/jbpm.varmapping.xml	                        (rev 0)
+++ jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm1914/jbpm.varmapping.xml	2009-02-14 09:30:27 UTC (rev 3876)
@@ -0,0 +1,187 @@
+<!--
+# This file specifies how jbpm will store variables into the database.
+#
+# If jbpm needs to determine how to store a variable into the database, 
+# the jbpm-types below or scanned in sequence as they are specified here.
+# For each jbpm-type, jbpm will see if the give variable object matches 
+# with the matcher bean.  If there is a match, the converter (optional)
+# and the variable instance will be used to store and retrieve 
+# the variable value for the rest of its lifetime till the variable is 
+# deleted. 
+-->
+<jbpm-types>
+
+  <list name="jbpm.types" singleton="true">
+
+    <!-- java.lang.String -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
+          <field name="className"><string value="java.lang.String" /></field>
+        </bean>
+      </matcher>
+      <variable-instance class="org.jbpm.context.exe.variableinstance.StringInstance" />
+    </jbpm-type>
+
+    <!-- java.lang.Boolean -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
+          <field name="className"><string value="java.lang.Boolean" /></field>
+        </bean>
+      </matcher>
+      <converter class="org.jbpm.context.exe.converter.BooleanToStringConverter" />
+      <variable-instance class="org.jbpm.context.exe.variableinstance.StringInstance" />
+    </jbpm-type>
+
+    <!-- java.lang.Character -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
+          <field name="className"><string value="java.lang.Character" /></field>
+        </bean>
+      </matcher>
+      <converter class="org.jbpm.context.exe.converter.CharacterToStringConverter" />
+      <variable-instance class="org.jbpm.context.exe.variableinstance.StringInstance" />
+    </jbpm-type>
+
+    <!-- java.lang.Long -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
+          <field name="className"><string value="java.lang.Long" /></field>
+        </bean>
+      </matcher>
+      <variable-instance class="org.jbpm.context.exe.variableinstance.LongInstance" />
+    </jbpm-type>
+
+    <!-- java.lang.Byte -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
+          <field name="className"><string value="java.lang.Byte" /></field>
+        </bean>
+      </matcher>
+      <converter class="org.jbpm.context.exe.converter.ByteToLongConverter" />
+      <variable-instance class="org.jbpm.context.exe.variableinstance.LongInstance" />
+    </jbpm-type>
+
+    <!-- java.lang.Short -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
+          <field name="className"><string value="java.lang.Short" /></field>
+        </bean>
+      </matcher>
+      <converter class="org.jbpm.context.exe.converter.ShortToLongConverter" />
+      <variable-instance class="org.jbpm.context.exe.variableinstance.LongInstance" />
+    </jbpm-type>
+
+    <!-- java.lang.Integer -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
+          <field name="className"><string value="java.lang.Integer" /></field>
+        </bean>
+      </matcher>
+      <converter class="org.jbpm.context.exe.converter.IntegerToLongConverter" />
+      <variable-instance class="org.jbpm.context.exe.variableinstance.LongInstance" />
+    </jbpm-type>
+
+    <!-- java.lang.Double -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
+          <field name="className"><string value="java.lang.Double" /></field>
+        </bean>
+      </matcher>
+      <variable-instance class="org.jbpm.context.exe.variableinstance.DoubleInstance" />
+    </jbpm-type>
+
+    <!-- java.lang.Float -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
+          <field name="className"><string value="java.lang.Float" /></field>
+        </bean>
+      </matcher>
+      <converter class="org.jbpm.context.exe.converter.FloatToDoubleConverter" />
+      <variable-instance class="org.jbpm.context.exe.variableinstance.DoubleInstance" />
+    </jbpm-type>
+
+    <!-- java.util.Date -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
+          <field name="className"><string value="java.util.Date" /></field>
+        </bean>
+      </matcher>
+      <variable-instance class="org.jbpm.context.exe.variableinstance.DateInstance" />
+    </jbpm-type>
+
+    <!-- byte[] -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
+          <field name="className"><string value="[B" /></field>
+        </bean>
+      </matcher>
+      <converter class="org.jbpm.context.exe.converter.BytesToByteArrayConverter" />
+      <variable-instance class="org.jbpm.context.exe.variableinstance.ByteArrayInstance" />
+    </jbpm-type>
+
+    <!-- hibernatable long id types -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.HibernateLongIdMatcher" />
+      </matcher>
+      <variable-instance class="org.jbpm.context.exe.variableinstance.HibernateLongInstance" />
+    </jbpm-type>
+
+    <!-- hibernatable string id types -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.HibernateStringIdMatcher" />
+      </matcher>
+      <variable-instance class="org.jbpm.context.exe.variableinstance.HibernateStringInstance" />
+    </jbpm-type>
+
+    <!-- hibernatable ejb3 types -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.Ejb3Matcher" />
+      </matcher>
+      <variable-instance class="org.jbpm.context.exe.variableinstance.Ejb3Instance" />
+    </jbpm-type>
+
+    <!-- JSR 170 JCR Node -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.JcrNodeMatcher" />
+      </matcher>
+      <variable-instance class="org.jbpm.context.exe.variableinstance.JcrNodeInstance" />
+    </jbpm-type>
+
+    <!-- custom serializable class -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
+          <field name="className"><string value="org.jbpm.context.exe.CustomSerializableClass" /></field>
+        </bean>
+      </matcher>
+      <converter class="org.jbpm.jbpm1914.ObjectToStringConverter" />
+      <variable-instance class="org.jbpm.context.exe.variableinstance.StringInstance" />
+    </jbpm-type>
+
+    <!-- java.io.Serializable -->
+    <jbpm-type>
+      <matcher>
+        <bean class="org.jbpm.context.exe.matcher.SerializableMatcher" />
+      </matcher>
+      <converter class="org.jbpm.context.exe.converter.SerializableToByteArrayConverter" />
+      <variable-instance class="org.jbpm.context.exe.variableinstance.ByteArrayInstance" />
+    </jbpm-type>
+
+  </list>
+
+</jbpm-types>




More information about the jbpm-commits mailing list