Revision: 1283
Author: plorenz
Date: Sun Feb 3 19:26:44 2013
Log: Add custom data to process definitions. Not available to runtime
yet.
http://code.google.com/p/sarasvati/source/detail?r=1283
Modified:
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/load/definition/ProcessDefinition.java
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/xml/XmlProcessDefinition.java
/java/trunk/sarasvati-core/src/main/resources/ProcessDefinition.xsd
/java/trunk/sarasvati-core/src/test/java/com/googlecode/sarasvati/unittest/load/LoaderTest.java
=======================================
---
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/load/definition/ProcessDefinition.java
Wed Nov 4 08:26:27 2009
+++
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/load/definition/ProcessDefinition.java
Sun Feb 3 19:26:44 2013
@@ -45,6 +45,11 @@
*/
String getMessageDigest ();
+ /**
+ * @return Any custom data for the process definition
+ */
+ CustomDefinition getCustom();
+
/**
* @return A list of the nodes defined in the process definition
*/
@@ -54,4 +59,9 @@
* @return A list of the externals defined in the process definition.
*/
List<? extends ExternalDefinition> getExternals ();
+
+ /**
+ * @return A list of custom xml elements of the process.
+ */
+ List<Object> getCustomProcessData();
}
=======================================
---
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/xml/XmlProcessDefinition.java
Tue Aug 2 19:04:19 2011
+++
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/xml/XmlProcessDefinition.java
Sun Feb 3 19:26:44 2013
@@ -24,6 +24,9 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Map.Entry;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@@ -37,6 +40,7 @@
import com.googlecode.sarasvati.load.definition.ExternalDefinition;
import com.googlecode.sarasvati.load.definition.NodeDefinition;
import com.googlecode.sarasvati.load.definition.ProcessDefinition;
+import com.googlecode.sarasvati.load.properties.DOMToObjectLoadHelper;
import com.googlecode.sarasvati.util.SvUtil;
@XmlRootElement(name = "process-definition")
@@ -52,6 +56,9 @@
@XmlElement(name = "external")
protected List<XmlExternal> externals = new ArrayList<XmlExternal>();
+ @XmlElement(name="custom")
+ protected XmlCustom custom;
+
@XmlTransient
protected String messageDigest = null;
@@ -87,6 +94,23 @@
{
this.externals = externals;
}
+
+ @Override
+ public List<Object> getCustomProcessData()
+ {
+ return custom != null? custom.getCustom() : Collections.emptyList();
+ }
+
+ @Override
+ public XmlCustom getCustom()
+ {
+ return custom;
+ }
+
+ public void setCustom(XmlCustom custom)
+ {
+ this.custom = custom;
+ }
@Override
public String getMessageDigest () throws SarasvatiLoadException
@@ -101,6 +125,18 @@
MessageDigest digest = MessageDigest.getInstance( "SHA1" );
digest.update( name.getBytes() );
+ Map<String, String> customProps = new TreeMap<String, String>();
+ DOMToObjectLoadHelper.loadCustomIntoMap( custom, customProps );
+
+ for ( Entry<String, String> entry : customProps.entrySet() )
+ {
+ digest.update( entry.getKey().getBytes() );
+ if ( !SvUtil.isBlankOrNull( entry.getValue() ) )
+ {
+ digest.update( entry.getValue().getBytes() );
+ }
+ }
+
for ( XmlNode node : nodes )
{
node.addToDigest( digest );
@@ -130,6 +166,11 @@
buf.append( getName() );
buf.append( "\">\n" );
+ if (custom != null) {
+ buf.append( custom );
+ buf.append( "\n" );
+ }
+
for (NodeDefinition node : nodes)
{
buf.append( node );
=======================================
--- /java/trunk/sarasvati-core/src/main/resources/ProcessDefinition.xsd Sun
Oct 28 18:44:04 2012
+++ /java/trunk/sarasvati-core/src/main/resources/ProcessDefinition.xsd Sun
Feb 3 19:26:44 2013
@@ -16,6 +16,14 @@
</xs:annotation>
<xs:sequence>
+ <xs:element name="custom" minOccurs="0" maxOccurs="1">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:any namespace="##any" minOccurs="0"
maxOccurs="unbounded" processContents="lax"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
<xs:element name="node" type="Node" minOccurs="1"
maxOccurs="unbounded" >
<xs:annotation>
<xs:documentation>
=======================================
---
/java/trunk/sarasvati-core/src/test/java/com/googlecode/sarasvati/unittest/load/LoaderTest.java
Mon Oct 3 18:42:35 2011
+++
/java/trunk/sarasvati-core/src/test/java/com/googlecode/sarasvati/unittest/load/LoaderTest.java
Sun Feb 3 19:26:44 2013
@@ -1,14 +1,22 @@
package com.googlecode.sarasvati.unittest.load;
import java.io.File;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.List;
+
+import javax.xml.bind.JAXBException;
import junit.framework.Assert;
import org.junit.Test;
+import org.w3c.dom.Element;
import com.googlecode.sarasvati.Engine;
import com.googlecode.sarasvati.load.SarasvatiLoadException;
import com.googlecode.sarasvati.mem.MemEngine;
+import com.googlecode.sarasvati.xml.XmlLoader;
+import com.googlecode.sarasvati.xml.XmlProcessDefinition;
public class LoaderTest
{
@@ -32,6 +40,49 @@
Assert.assertNotNull( "Graph should be loaded",
engine.getRepository().getLatestGraph( "external-present" ) );
Assert.assertNotNull( "Graph should be loaded",
engine.getRepository().getLatestGraph( "external" ) );
}
+
+ @Test
+ public void testCustomProcessData() throws Exception
+ {
+ String wf = "<process-definition name='test' "
+ + "
xmlns='
http://sarasvati.googlecode.com/ProcessDefinition'>"
+ + " <custom><testdata/></custom>"
+ + " <node type='wait' name='nodeA'/>"
+ + "</process-definition>";
+ StringLoader loader = new StringLoader();
+ XmlProcessDefinition def = loader.load( wf );
+ List<Object> customData = def.getCustomProcessData();
+ Assert.assertNotNull( customData );
+ Assert.assertEquals( 1, customData.size() );
+
+ Element elem = (Element)customData.get(0);
+ Assert.assertEquals( "testdata", elem.getLocalName() );
+ }
+
+ @Test
+ public void testCustomProcessDataNeverNull() throws Exception
+ {
+ String wf = "<process-definition name='test' "
+ + "
xmlns='
http://sarasvati.googlecode.com/ProcessDefinition'>"
+ + " <node type='wait' name='nodeA'/>"
+ + "</process-definition>";
+
+ StringLoader loader = new StringLoader();
+ XmlProcessDefinition def = loader.load( wf );
+ List<Object> customData = def.getCustomProcessData();
+ Assert.assertNotNull( customData );
+ Assert.assertEquals( 0, customData.size() );
+ }
+}
+
+
+class StringLoader extends XmlLoader
+{
+ public XmlProcessDefinition load( String content ) throws JAXBException
+ {
+ Reader reader = new StringReader( content );
+ return (XmlProcessDefinition)getUnmarshaller().unmarshal( reader );
+ }
}