[jbpm-commits] JBoss JBPM SVN: r3859 - in jbpm3/trunk: modules/core/src/main/java/org/jbpm/context/exe and 11 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Feb 12 21:11:33 EST 2009
Author: alex.guizar at jboss.com
Date: 2009-02-12 21:11:33 -0500 (Thu, 12 Feb 2009)
New Revision: 3859
Added:
jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/exe/jbpm.converter.properties
jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm1024/
jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm1024/CustomSerializable.zip
Removed:
jbpm3/trunk/modules/core/src/main/resources/org/jbpm/db/hibernate/
jbpm3/trunk/modules/core/src/test/resources/org/jbpm/context/exe/CustomSerializable.zip
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/VariableInstance.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/IoUtil.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/XmlUtil.java
jbpm3/trunk/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml
jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1024/JBPM1024Test.java
jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm.test.cfg.xml
jbpm3/trunk/modules/identity/src/main/java/org/jbpm/identity/xml/IdentityXmlParser.java
jbpm3/trunk/pom.xml
Log:
clean up converters;
close exhausted streams;
fill in project info
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-12 22:54:24 UTC (rev 3858)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/JbpmType.java 2009-02-13 02:11:33 UTC (rev 3859)
@@ -31,60 +31,70 @@
import org.jbpm.configuration.ObjectFactory;
import org.jbpm.configuration.ObjectFactoryParser;
import org.jbpm.util.ClassLoaderUtil;
+import org.jbpm.util.CollectionUtil;
/**
- * specifies for one java-type how jbpm is able to persist objects of that type in the database.
+ * specifies for one java-type how jbpm is able to persist objects of that type in the database.
*/
public class JbpmType {
-
- static Map jbpmTypesCache = new HashMap();
-
+
+ static Map<ObjectFactory, List<JbpmType>> jbpmTypesCache = new HashMap<ObjectFactory, List<JbpmType>>();
+
JbpmTypeMatcher jbpmTypeMatcher = null;
Converter converter = null;
- Class variableInstanceClass = null;
+ Class<? extends VariableInstance> variableInstanceClass = null;
- public JbpmType(JbpmTypeMatcher jbpmTypeMatcher, Converter converter, Class variableInstanceClass) {
+ public JbpmType(JbpmTypeMatcher jbpmTypeMatcher, Converter converter,
+ Class<? extends VariableInstance> variableInstanceClass) {
this.jbpmTypeMatcher = jbpmTypeMatcher;
this.converter = converter;
this.variableInstanceClass = variableInstanceClass;
}
-
+
public boolean matches(Object value) {
return jbpmTypeMatcher.matches(value);
}
-
+
public VariableInstance newVariableInstance() {
VariableInstance variableInstance = null;
try {
- variableInstance = (VariableInstance) variableInstanceClass.newInstance();
+ variableInstance = variableInstanceClass.newInstance();
variableInstance.converter = converter;
- } catch (Exception e) {
- throw new JbpmException("couldn't instantiate variable instance class '"+variableInstanceClass.getName()+"'");
}
+ catch (Exception e) {
+ throw new JbpmException("couldn't instantiate variable instance class '"
+ + variableInstanceClass.getName()
+ + "'");
+ }
return variableInstance;
}
- public static List getJbpmTypes() {
- List jbpmTypes = null;
- synchronized(jbpmTypesCache) {
- ObjectFactory objectFactory = JbpmConfiguration.Configs.getObjectFactory();
- jbpmTypes = (List) jbpmTypesCache.get(objectFactory);
- if (jbpmTypes==null) {
- if (JbpmConfiguration.Configs.hasObject("jbpm.types")) {
- jbpmTypes = (List) JbpmConfiguration.Configs.getObject("jbpm.types");
- } else {
+ public static List<JbpmType> getJbpmTypes() {
+ List<JbpmType> jbpmTypes = null;
+ ObjectFactory objectFactory = JbpmConfiguration.Configs.getObjectFactory();
+ synchronized (jbpmTypesCache) {
+ jbpmTypes = jbpmTypesCache.get(objectFactory);
+
+ if (jbpmTypes == null) {
+ if (objectFactory.hasObject("jbpm.types")) {
+ jbpmTypes = CollectionUtil.checkList((List<?>) objectFactory.createObject("jbpm.types"),
+ JbpmType.class);
+ }
+ else {
jbpmTypes = getDefaultJbpmTypes();
}
+
jbpmTypesCache.put(objectFactory, jbpmTypes);
}
}
return jbpmTypes;
}
- private static List getDefaultJbpmTypes() {
+ private static List<JbpmType> getDefaultJbpmTypes() {
String resource = JbpmConfiguration.Configs.getString("resource.varmapping");
InputStream is = ClassLoaderUtil.getStream(resource);
ObjectFactory objectFactory = ObjectFactoryParser.parseInputStream(is);
- return (List) objectFactory.createObject("jbpm.types");
+ return CollectionUtil.checkList((List<?>) objectFactory.createObject("jbpm.types"),
+ JbpmType.class);
}
}
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-12 22:54:24 UTC (rev 3858)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/VariableInstance.java 2009-02-13 02:11:33 UTC (rev 3859)
@@ -22,7 +22,6 @@
package org.jbpm.context.exe;
import java.io.Serializable;
-import java.util.Iterator;
import org.jbpm.JbpmException;
import org.jbpm.context.exe.converter.SerializableToByteArrayConverter;
@@ -33,167 +32,157 @@
import org.jbpm.graph.exe.Token;
/**
- * is a jbpm-internal class that serves as a base class for classes that store
- * variable values in the database.
+ * is a jbpm-internal class that serves as a base class for classes that store variable values in
+ * the database.
*/
public abstract class VariableInstance implements Serializable {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- long id = 0;
- int version = 0;
- protected String name = null;
- protected Token token = null;
- protected TokenVariableMap tokenVariableMap = null;
- protected ProcessInstance processInstance = null;
- protected Converter converter = null;
- protected Object valueCache = null;
- protected boolean isValueCached = false;
+ long id = 0;
+ int version = 0;
+ protected String name = null;
+ protected Token token = null;
+ protected TokenVariableMap tokenVariableMap = null;
+ protected ProcessInstance processInstance = null;
+ protected Converter converter = null;
+ protected Object valueCache = null;
+ protected boolean isValueCached = false;
- // constructors /////////////////////////////////////////////////////////////
+ // constructors /////////////////////////////////////////////////////////////
- public VariableInstance() {}
+ public VariableInstance() {
+ }
- public static VariableInstance create(Token token, String name, Object value) {
+ public static VariableInstance create(Token token, String name, Object value) {
- VariableInstance variableInstance = null;
- if(value == null) {
- variableInstance = new NullInstance();
- }
- else {
- variableInstance = createVariableInstance(value);
- }
+ VariableInstance variableInstance = null;
+ if (value == null) {
+ variableInstance = new NullInstance();
+ }
+ else {
+ variableInstance = createVariableInstance(value);
+ }
- variableInstance.token = token;
- variableInstance.name = name;
- variableInstance.processInstance = (token != null ? token
- .getProcessInstance() : null);
- if(token != null) {
- token.addLog(new VariableCreateLog(variableInstance));
- }
- variableInstance.setValue(value);
- return variableInstance;
- }
+ variableInstance.token = token;
+ variableInstance.name = name;
+ variableInstance.processInstance = (token != null ? token.getProcessInstance() : null);
+ if (token != null) {
+ token.addLog(new VariableCreateLog(variableInstance));
+ }
+ variableInstance.setValue(value);
+ return variableInstance;
+ }
- public static VariableInstance createVariableInstance(Object value) {
- VariableInstance variableInstance = null;
+ public static VariableInstance createVariableInstance(Object value) {
+ for (JbpmType jbpmType : JbpmType.getJbpmTypes()) {
+ if (jbpmType.matches(value)) {
+ return jbpmType.newVariableInstance();
+ }
+ }
+ return new UnpersistableInstance();
+ }
- Iterator iter = JbpmType.getJbpmTypes().iterator();
- while((iter.hasNext()) && (variableInstance == null)) {
- JbpmType jbpmType = (JbpmType) iter.next();
+ // abstract methods /////////////////////////////////////////////////////////
- if(jbpmType.matches(value)) {
- variableInstance = jbpmType.newVariableInstance();
- }
- }
+ /**
+ * is true if this variable-instance supports the given value, false otherwise.
+ */
+ public abstract boolean isStorable(Object value);
- if(variableInstance == null) {
- variableInstance = new UnpersistableInstance();
- }
+ /**
+ * is the value, stored by this variable instance.
+ */
+ protected abstract Object getObject();
- return variableInstance;
- }
+ /**
+ * stores the value in this variable instance.
+ */
+ protected abstract void setObject(Object value);
- // abstract methods /////////////////////////////////////////////////////////
+ // variable management //////////////////////////////////////////////////////
- /**
- * is true if this variable-instance supports the given value, false
- * otherwise.
- */
- public abstract boolean isStorable(Object value);
+ public boolean supports(Object value) {
+ if (converter != null) {
+ return converter.supports(value);
+ }
+ return isStorable(value);
+ }
- /**
- * is the value, stored by this variable instance.
- */
- protected abstract Object getObject();
+ public void setValue(Object value) {
+ valueCache = value;
+ isValueCached = true;
- /**
- * stores the value in this variable instance.
- */
- protected abstract void setObject(Object value);
+ if (converter != null) {
+ if (!converter.supports(value)) {
+ 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");
+ }
+ value = converter.convert(value);
+ }
+ if ((value != null) && (!this.isStorable(value))) {
+ throw new JbpmException("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");
+ }
+ setObject(value);
+ }
- // variable management //////////////////////////////////////////////////////
+ public Object getValue() {
+ if (isValueCached) {
+ 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());
+ }
+ else {
+ value = converter.revert(value);
+ }
+ valueCache = value;
+ isValueCached = true;
+ }
+ return value;
+ }
- public boolean supports(Object value) {
- if(converter != null) {
- return converter.supports(value);
- }
- return isStorable(value);
- }
+ public void removeReferences() {
+ tokenVariableMap = null;
+ token = null;
+ processInstance = null;
+ }
- public void setValue(Object value) {
- valueCache = value;
- isValueCached = true;
+ // utility methods /////////////////////////////////////////////////////////
- if(converter != null) {
- if(!converter.supports(value)) {
- 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");
- }
- value = converter.convert(value);
- }
- if((value != null) && (!this.isStorable(value))) {
- throw new JbpmException("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");
- }
- setObject(value);
- }
+ public String toString() {
+ return "${" + name + "}";
+ }
- public Object getValue() {
- if(isValueCached) {
- 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());
- }
- else {
- value = converter.revert(value);
- }
- valueCache = value;
- isValueCached = true;
- }
- return value;
- }
+ // getters and setters //////////////////////////////////////////////////////
- public void removeReferences() {
- tokenVariableMap = null;
- token = null;
- processInstance = null;
- }
+ public String getName() {
+ return name;
+ }
- // utility methods /////////////////////////////////////////////////////////
+ public ProcessInstance getProcessInstance() {
+ return processInstance;
+ }
- public String toString() {
- return "${" + name + "}";
- }
+ public Token getToken() {
+ return token;
+ }
- // getters and setters //////////////////////////////////////////////////////
+ public void setTokenVariableMap(TokenVariableMap tokenVariableMap) {
+ this.tokenVariableMap = tokenVariableMap;
+ }
- public String getName() {
- return name;
- }
-
- public ProcessInstance getProcessInstance() {
- return processInstance;
- }
-
- public Token getToken() {
- return token;
- }
-
- public void setTokenVariableMap(TokenVariableMap tokenVariableMap) {
- this.tokenVariableMap = tokenVariableMap;
- }
-
- // private static Log log = LogFactory.getLog(VariableInstance.class);
+ // private static Log log = LogFactory.getLog(VariableInstance.class);
}
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-12 22:54:24 UTC (rev 3858)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java 2009-02-13 02:11:33 UTC (rev 3859)
@@ -34,7 +34,6 @@
import org.jbpm.bytes.ByteArray;
import org.jbpm.context.exe.Converter;
import org.jbpm.graph.def.ProcessDefinition;
-import org.jbpm.util.ClassLoaderUtil;
import org.jbpm.util.CustomLoaderObjectInputStream;
public class SerializableToByteArrayConverter implements Converter {
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-12 22:54:24 UTC (rev 3858)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java 2009-02-13 02:11:33 UTC (rev 3859)
@@ -22,7 +22,6 @@
package org.jbpm.db.hibernate;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
@@ -37,53 +36,53 @@
/**
* provides access to the list of converters and ensures that the converter objects are unique.
*/
-public abstract class Converters {
-
- static final int CONVERTERS_BY_CLASS_NAMES = 0;
- static final int CONVERTERS_BY_DATABASE_ID = 1;
- static final int CONVERTERS_IDS = 2;
+public class Converters {
- static Map converterMapsMap = new HashMap();
-
+ private static Map<ObjectFactory, ConverterMaps> converterMapsMap = new HashMap<ObjectFactory, ConverterMaps>();
+
+ private Converters() {
+ // hide default constructor to prevent instantiation
+ }
+
// public methods
public static Converter getConverterByClassName(String className) {
- Converter converter = (Converter) getConvertersByClassNames().get(className);
- if (converter==null) {
- throw new JbpmException("converter '"+className+"' is not declared in jbpm.converter.properties");
+ Converter converter = getConvertersByClassNames().get(className);
+ if (converter == null) {
+ throw new JbpmException("converter '" + className + "' is not declared in resource.converter");
}
- return converter;
+ return converter;
}
public static Converter getConverterByDatabaseId(String converterDatabaseId) {
- return (Converter) getConvertersByDatabaseId().get(converterDatabaseId);
+ return getConvertersByDatabaseId().get(converterDatabaseId);
}
public static String getConverterId(Converter converter) {
- return (String) getConvertersIds().get(converter);
+ return getConvertersIds().get(converter);
}
// maps class names to unique converter objects
- static Map getConvertersByClassNames() {
- return getConverterMaps()[CONVERTERS_BY_CLASS_NAMES];
+ static Map<String, Converter> getConvertersByClassNames() {
+ return getConverterMaps().getConvertersByClassNames();
}
- // maps converter database-id-strings to unique converter objects
- static Map getConvertersByDatabaseId() {
- return getConverterMaps()[CONVERTERS_BY_DATABASE_ID];
+ // maps converter database-id-strings to unique converter objects
+ static Map<String, Converter> getConvertersByDatabaseId() {
+ return getConverterMaps().getConvertersByDatabaseId();
}
-
+
// maps unique converter objects to their database-id-string
- static Map getConvertersIds() {
- return getConverterMaps()[CONVERTERS_IDS];
+ static Map<Converter, String> getConvertersIds() {
+ return getConverterMaps().getConvertersIds();
}
- static Map[] getConverterMaps() {
- Map[] converterMaps = null;
- synchronized(converterMapsMap) {
- ObjectFactory objectFactory = JbpmConfiguration.Configs.getObjectFactory();
- converterMaps = (Map[]) converterMapsMap.get(objectFactory);
- if (converterMaps==null) {
+ 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);
}
@@ -91,44 +90,65 @@
return converterMaps;
}
- static Map[] createConverterMaps(ObjectFactory objectFactory) {
- Map[] converterMaps = new Map[3];
- converterMaps[CONVERTERS_BY_CLASS_NAMES] = new HashMap();
- converterMaps[CONVERTERS_BY_DATABASE_ID] = new HashMap();
- converterMaps[CONVERTERS_IDS] = new HashMap();
-
- Map convertersByClassNames = converterMaps[CONVERTERS_BY_CLASS_NAMES];
- Map convertersByDatabaseId = converterMaps[CONVERTERS_BY_DATABASE_ID];
- Map convertersIds = converterMaps[CONVERTERS_IDS];
-
- Properties converterProperties = null;
+ static ConverterMaps createConverterMaps(ObjectFactory objectFactory) {
+ Properties converterProperties;
if (objectFactory.hasObject("resource.converter")) {
String resource = (String) objectFactory.createObject("resource.converter");
converterProperties = ClassLoaderUtil.getProperties(resource);
- } else {
+ }
+ else {
converterProperties = new Properties();
}
- Iterator iter = converterProperties.keySet().iterator();
- while (iter.hasNext()) {
- String converterDatabaseId = (String) iter.next();
- if (converterDatabaseId.length()!=1) throw new JbpmException("converter-ids must be of length 1 (to be stored in a char)");
- if (convertersByDatabaseId.containsKey(converterDatabaseId)) throw new JbpmException("duplicate converter id : '"+converterDatabaseId+"'");
- String converterClassName = converterProperties.getProperty(converterDatabaseId);
+ 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 converterClass = ClassLoaderUtil.classForName(converterClassName);
- Converter converter = (Converter) converterClass.newInstance();
- log.debug("adding converter '"+converterDatabaseId+"', '"+converterClassName+"'");
- convertersByClassNames.put(converterClassName, converter);
- convertersByDatabaseId.put(converterDatabaseId, converter);
- convertersIds.put(converter, converterDatabaseId);
- } catch (Exception e) {
- // NOTE that Error's are not caught because that might halt the JVM and mask the original Error.
- log.debug("couldn't instantiate converter '"+converterClassName+"': "+e);
+ 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);
+ }
}
- return converterMaps;
+ 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);
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/IoUtil.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/IoUtil.java 2009-02-12 22:54:24 UTC (rev 3858)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/IoUtil.java 2009-02-13 02:11:33 UTC (rev 3859)
@@ -26,40 +26,30 @@
import java.io.InputStream;
import java.io.OutputStream;
-public class IoUtil
-{
+public class IoUtil {
private static final int BUFFERSIZE = 4096;
- // hide default constructor
- private IoUtil()
- {
+ private IoUtil() {
+ // hide default constructor to prevent instantiation
}
- public static byte[] readBytes(InputStream inputStream) throws IOException
- {
- if (inputStream == null)
- throw new IllegalArgumentException("InputStream cannot be null");
-
+ public static byte[] readBytes(InputStream inputStream) throws IOException {
+ if (inputStream == null) throw new IllegalArgumentException("InputStream cannot be null");
+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
transfer(inputStream, outputStream);
- byte[] bytes = outputStream.toByteArray();
- outputStream.close();
- return bytes;
+ return outputStream.toByteArray();
}
- public static int transfer(InputStream in, OutputStream out) throws IOException
- {
+ public static int transfer(InputStream in, OutputStream out) throws IOException {
if (in == null || out == null)
throw new IllegalArgumentException("In/OutStream cannot be null");
-
+
int total = 0;
byte[] buffer = new byte[BUFFERSIZE];
- int bytesRead = in.read(buffer);
- while (bytesRead != -1)
- {
+ for (int bytesRead; (bytesRead = in.read(buffer)) != -1;) {
out.write(buffer, 0, bytesRead);
total += bytesRead;
- bytesRead = in.read(buffer);
}
return total;
}
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/XmlUtil.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/XmlUtil.java 2009-02-12 22:54:24 UTC (rev 3858)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/XmlUtil.java 2009-02-13 02:11:33 UTC (rev 3859)
@@ -22,6 +22,7 @@
package org.jbpm.util;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -31,7 +32,6 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
@@ -46,6 +46,7 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
public class XmlUtil {
@@ -59,10 +60,10 @@
}
/**
- * @param isJbpmConfiguration specifies if the resource should be loaded
- * with the "limited" bootstrap class loader for jbpm config.
+ * @param isJbpmConfiguration specifies if the resource should be loaded with the "limited"
+ * bootstrap class loader for jbpm config.
*/
- public static Document parseXmlResource(String resource, boolean isJbpmConfiguration) {
+ public static Document parseXmlResource(String resource, boolean isJbpmConfiguration) {
// decide which class loading mechanism to use for loading the jbpm
// configuration (see https://jira.jboss.org/jira/browse/JBPM-1148)
InputStream inputStream = null;
@@ -70,49 +71,62 @@
inputStream = ClassLoaderUtil.getJbpmConfigurationStream(resource);
else
inputStream = ClassLoaderUtil.getStream(resource);
-
+
if (inputStream == null)
- throw new IllegalArgumentException("Cannot load resource: " + resource);
- InputSource inputSource = new InputSource(inputStream);
- return parseXmlInputSource(inputSource);
+ throw new IllegalArgumentException("Cannot load resource: " + resource);
+
+ return parseXmlInputStream(inputStream);
}
public static Document parseXmlInputStream(InputStream inputStream) {
Document document = null;
try {
- document = getDocumentBuilder().parse(inputStream);
- } catch (Exception e) {
- throw new XmlException("couldn't parse xml", e);
+ document = getDocumentBuilder().parse(inputStream);
+ inputStream.close();
}
+ catch (IOException e) {
+ throw new XmlException("could not read xml stream", e);
+ }
+ catch (SAXException e) {
+ throw new XmlException("could not parse xml document", e);
+ }
return document;
}
public static Document parseXmlInputSource(InputSource inputSource) {
Document document = null;
try {
- document = getDocumentBuilder().parse(inputSource);
- } catch (Exception e) {
- throw new XmlException("couldn't parse xml", e);
+ document = getDocumentBuilder().parse(inputSource);
}
+ catch (IOException e) {
+ throw new XmlException("could not read xml stream", e);
+ }
+ catch (SAXException e) {
+ throw new XmlException("could not parse xml document", e);
+ }
return document;
}
- public static DocumentBuilder getDocumentBuilder() throws FactoryConfigurationError, ParserConfigurationException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- return factory.newDocumentBuilder();
+ public static DocumentBuilder getDocumentBuilder() {
+ try {
+ return DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ }
+ catch (ParserConfigurationException e) {
+ throw new XmlException("could not create document builder", e);
+ }
}
- public static Iterator elementIterator(Element element, String tagName) {
+ public static Iterator<Element> elementIterator(Element element, String tagName) {
return elements(element, tagName).iterator();
}
- public static List elements(Element element, String tagName) {
+ public static List<Element> elements(Element element, String tagName) {
NodeList nodeList = element.getElementsByTagName(tagName);
- List elements = new ArrayList(nodeList.getLength());
- for (int i=0; i<nodeList.getLength(); i++) {
+ List<Element> elements = new ArrayList<Element>(nodeList.getLength());
+ for (int i = 0; i < nodeList.getLength(); i++) {
Node child = nodeList.item(i);
- if(child.getParentNode()==element) {
- elements.add(child);
+ if (child.getParentNode() == element) {
+ elements.add((Element) child);
}
}
return elements;
@@ -121,71 +135,71 @@
public static Element element(Element element, String name) {
Element childElement = null;
NodeList nodeList = element.getElementsByTagName(name);
- if (nodeList.getLength()>0) {
+ if (nodeList.getLength() > 0) {
childElement = (Element) nodeList.item(0);
}
return childElement;
}
- public static Iterator elementIterator(Element element) {
+ public static Iterator<Element> elementIterator(Element element) {
return elements(element).iterator();
}
- public static List elements(Element element) {
- List elements = new ArrayList();
+ public static List<Element> elements(Element element) {
+ List<Element> elements = new ArrayList<Element>();
NodeList nodeList = element.getChildNodes();
- for (int i=0; i<nodeList.getLength(); i++) {
+ for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
- if ( (node instanceof Element)
- && (element==node.getParentNode())
- ){
- elements.add(node);
+ if (node instanceof Element) {
+ elements.add((Element) node);
}
}
return elements;
}
-
public static Element element(Element element) {
- Element onlyChild = null;
- List elements = elements(element);
- if (! elements.isEmpty()) {
- onlyChild = (Element) elements.get(0);
+ NodeList nodeList = element.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node instanceof Element) {
+ return (Element) node;
+ }
}
- return onlyChild;
+ return null;
}
public static String toString(Element element) {
- if (element==null) return "null";
+ if (element == null) return "null";
Source source = new DOMSource(element);
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
Result result = new StreamResult(printWriter);
-
+
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(source, result);
- } catch (Exception e) {
- throw new XmlException("couldn't write element '"+element.getTagName()+"' to string", e);
}
-
+ catch (Exception e) {
+ throw new XmlException("couldn't write element '" + element.getTagName() + "' to string", e);
+ }
+
printWriter.close();
return stringWriter.toString();
}
public static String getContentText(Element element) {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder text = new StringBuilder();
NodeList nodeList = element.getChildNodes();
- for (int i=0; i<nodeList.getLength(); i++) {
+ for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node instanceof CharacterData) {
CharacterData characterData = (CharacterData) node;
- buffer.append(characterData.getData());
+ text.append(characterData.getData());
}
}
- return buffer.toString();
+ return text.toString();
}
}
\ No newline at end of file
Copied: jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/exe/jbpm.converter.properties (from rev 3848, jbpm3/trunk/modules/core/src/main/resources/org/jbpm/db/hibernate/jbpm.converter.properties)
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/exe/jbpm.converter.properties (rev 0)
+++ jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/exe/jbpm.converter.properties 2009-02-13 02:11:33 UTC (rev 3859)
@@ -0,0 +1,17 @@
+# 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/default.jbpm.cfg.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml 2009-02-12 22:54:24 UTC (rev 3858)
+++ jbpm3/trunk/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml 2009-02-13 02:11:33 UTC (rev 3859)
@@ -1,11 +1,10 @@
<jbpm-configuration>
<!--
- This configuration is used when there is no jbpm.cfg.xml file found in the
- root of the classpath. It is a very basic configuration without persistence
- and message services. Only the authorization service installed.
- You can parse and create processes, but when you try to use one of the
- unavailable services, you'll get an exception.
+ This configuration file describes the default objects available to every
+ JbpmConfiguration instance obtained through the jBPM API.
+ Any custom object provided through an input source is added to
+ the default objects here, and overwrites any object with the same name.
-->
<jbpm-context>
@@ -25,7 +24,7 @@
<!-- 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/db/hibernate/jbpm.converter.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" />
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1024/JBPM1024Test.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1024/JBPM1024Test.java 2009-02-12 22:54:24 UTC (rev 3858)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1024/JBPM1024Test.java 2009-02-13 02:11:33 UTC (rev 3859)
@@ -30,38 +30,39 @@
import org.jbpm.instantiation.ProcessClassLoader;
/**
- * Serializable variables are not being deserialized when retrieved from process
+ * Serializable variables are not being deserialized when retrieved from process.
+ * <p>
+ * The test case examines a serializable variable whose class file is stored in the process
+ * definition.
+ * </p>
*
- * https://jira.jboss.org/jira/browse/JBPM-1024
- *
- * Tests a serializable variable whose class file is stored in the process definition.
- *
+ * @see <a href="https://jira.jboss.org/jira/browse/JBPM-1024">JBPM-1024</a>
* @author Alejandro Guizar
*/
-public class JBPM1024Test extends AbstractDbTestCase
-{
+public class JBPM1024Test extends AbstractDbTestCase {
- public void testCustomSerializableVariableClass() throws IOException
- {
+ public void testCustomSerializableVariableClass() throws IOException {
// create and save the process definition
- ProcessDefinition processDefinition = ProcessDefinition.parseParResource("org/jbpm/context/exe/CustomSerializable.zip");
- graphSession.saveProcessDefinition(processDefinition);
- try
- {
+ ProcessDefinition processDefinition = ProcessDefinition.parseParResource("org/jbpm/jbpm1024/CustomSerializable.zip");
+ graphSession.deployProcessDefinition(processDefinition);
+
+ newTransaction();
+ try {
// create the process instance
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance = saveAndReload(processInstance);
// get the custom object from the context instance
- Object customSerializable = processInstance.getContextInstance().getVariable("custom serializable");
+ Object customSerializable = processInstance.getContextInstance().getVariable(
+ "custom serializable");
assertTrue(customSerializable instanceof Serializable);
- assertSame(ProcessClassLoader.class, customSerializable.getClass().getClassLoader().getClass());
+ assertSame(ProcessClassLoader.class, customSerializable.getClass()
+ .getClassLoader()
+ .getClass());
assertEquals("1984", customSerializable.toString());
}
- finally
- {
+ finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
-
}
}
Deleted: jbpm3/trunk/modules/core/src/test/resources/org/jbpm/context/exe/CustomSerializable.zip
===================================================================
(Binary files differ)
Modified: jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm.test.cfg.xml
===================================================================
--- jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm.test.cfg.xml 2009-02-12 22:54:24 UTC (rev 3858)
+++ jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm.test.cfg.xml 2009-02-13 02:11:33 UTC (rev 3859)
@@ -1,2 +1 @@
-<jbpm-configuration>
-</jbpm-configuration>
+<jbpm-configuration />
Added: jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm1024/CustomSerializable.zip
===================================================================
(Binary files differ)
Property changes on: jbpm3/trunk/modules/core/src/test/resources/org/jbpm/jbpm1024/CustomSerializable.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: jbpm3/trunk/modules/identity/src/main/java/org/jbpm/identity/xml/IdentityXmlParser.java
===================================================================
--- jbpm3/trunk/modules/identity/src/main/java/org/jbpm/identity/xml/IdentityXmlParser.java 2009-02-12 22:54:24 UTC (rev 3858)
+++ jbpm3/trunk/modules/identity/src/main/java/org/jbpm/identity/xml/IdentityXmlParser.java 2009-02-13 02:11:33 UTC (rev 3859)
@@ -31,6 +31,7 @@
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
+import org.jbpm.JbpmException;
import org.jbpm.identity.Entity;
import org.jbpm.identity.Group;
import org.jbpm.identity.Membership;
@@ -62,7 +63,7 @@
document = new SAXReader().read(inputStream);
}
catch (DocumentException e) {
- throw new RuntimeException("couldn't parse identities from stream '" + inputStream + "'");
+ throw new JbpmException("could not parse identities", e);
}
Element identitiesRootElement = document.getRootElement();
@@ -112,7 +113,7 @@
if (parentName != null) {
Group parent = groups.get(parentName);
if (parent == null)
- throw new RuntimeException("unexisting parent group '" + parentName + "'");
+ throw new JbpmException("unexisting parent group '" + parentName + "'");
Group child = groups.get(childName);
parent.addChild(child);
@@ -125,12 +126,12 @@
String userName = membershipElement.attributeValue("user");
User user = users.get(userName);
if (user == null)
- throw new RuntimeException("unexisting membership user '" + userName + "'");
+ throw new JbpmException("unexisting membership user '" + userName + "'");
String groupName = membershipElement.attributeValue("group");
Group group = groups.get(groupName);
if (group == null)
- throw new RuntimeException("unexisting membership group '" + groupName + "'");
+ throw new JbpmException("unexisting membership group '" + groupName + "'");
Membership membership = new Membership();
membership.setRole(membershipElement.attributeValue("role"));
Modified: jbpm3/trunk/pom.xml
===================================================================
--- jbpm3/trunk/pom.xml 2009-02-12 22:54:24 UTC (rev 3858)
+++ jbpm3/trunk/pom.xml 2009-02-13 02:11:33 UTC (rev 3859)
@@ -18,6 +18,7 @@
<packaging>pom</packaging>
<version>3.2.6-SNAPSHOT</version>
+ <url>http://www.jboss.org/jbossjbpm/</url>
<!-- Parent -->
<parent>
@@ -411,6 +412,21 @@
<scope>test</scope>
</dependency>
</dependencies>
+ <issueManagement>
+ <system>JIRA</system>
+ <url>https://jira.jboss.org/jira/browse/JBPM</url>
+ </issueManagement>
+ <ciManagement>
+ <system>Hudson</system>
+ <url>http://jbpm.dyndns.org:8280/hudson/</url>
+ </ciManagement>
+ <scm>
+ <url>http://anonsvn.jboss.org/repos/jbpm/jbpm3/</url>
+ </scm>
+ <organization>
+ <name>JBoss, a division of Red Hat</name>
+ <url>http://www.jboss.org/</url>
+ </organization>
<!-- Plugins -->
<build>
More information about the jbpm-commits
mailing list