[jbpm-commits] JBoss JBPM SVN: r3099 - in jbpm3/trunk/modules/integration/api: src/main/java/org/jbpm/integration/client and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Nov 26 05:54:40 EST 2008
Author: thomas.diesler at jboss.com
Date: 2008-11-26 05:54:40 -0500 (Wed, 26 Nov 2008)
New Revision: 3099
Added:
jbpm3/trunk/modules/integration/api/src/main/java/org/jbpm/integration/runtime/TokenAttachmentDelegate.java
Modified:
jbpm3/trunk/modules/integration/api/.classpath
jbpm3/trunk/modules/integration/api/src/main/java/org/jbpm/integration/client/TokenImpl.java
jbpm3/trunk/modules/integration/api/src/main/java/org/jbpm/integration/model/ProcessImpl.java
Log:
Add TokenAttachmentDelegate
Modified: jbpm3/trunk/modules/integration/api/.classpath
===================================================================
--- jbpm3/trunk/modules/integration/api/.classpath 2008-11-26 10:46:02 UTC (rev 3098)
+++ jbpm3/trunk/modules/integration/api/.classpath 2008-11-26 10:54:40 UTC (rev 3099)
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java"/>
- <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/cts/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
- <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
Modified: jbpm3/trunk/modules/integration/api/src/main/java/org/jbpm/integration/client/TokenImpl.java
===================================================================
--- jbpm3/trunk/modules/integration/api/src/main/java/org/jbpm/integration/client/TokenImpl.java 2008-11-26 10:46:02 UTC (rev 3098)
+++ jbpm3/trunk/modules/integration/api/src/main/java/org/jbpm/integration/client/TokenImpl.java 2008-11-26 10:54:40 UTC (rev 3099)
@@ -39,7 +39,9 @@
import org.jbpm.api.model.builder.ObjectNameFactory;
import org.jbpm.api.runtime.Attachments;
import org.jbpm.api.runtime.BasicAttachments;
+import org.jbpm.context.exe.ContextInstance;
import org.jbpm.integration.model.ProcessImpl;
+import org.jbpm.integration.runtime.TokenAttachmentDelegate;
/**
* An integration wrapper
@@ -53,14 +55,22 @@
private org.jbpm.graph.exe.Token oldToken;
private ProcessImpl procImpl;
- private Attachments att = new BasicAttachments();
+ private Attachments att;
public TokenImpl(ProcessImpl proc, org.jbpm.graph.exe.Token oldToken)
{
this.oldToken = oldToken;
this.procImpl = proc;
+
+ ContextInstance context = proc.getOldProcessInstance().getContextInstance();
+ this.att = new TokenAttachmentDelegate(this, context);
}
+ public org.jbpm.graph.exe.Token getOldToken()
+ {
+ return oldToken;
+ }
+
public ObjectName getKey()
{
return ObjectNameFactory.create(Constants.ID_DOMAIN + ":id=" + oldToken.getId());
Modified: jbpm3/trunk/modules/integration/api/src/main/java/org/jbpm/integration/model/ProcessImpl.java
===================================================================
--- jbpm3/trunk/modules/integration/api/src/main/java/org/jbpm/integration/model/ProcessImpl.java 2008-11-26 10:46:02 UTC (rev 3098)
+++ jbpm3/trunk/modules/integration/api/src/main/java/org/jbpm/integration/model/ProcessImpl.java 2008-11-26 10:54:40 UTC (rev 3099)
@@ -38,6 +38,7 @@
import org.jbpm.api.model.Process;
import org.jbpm.api.model.builder.ObjectNameFactory;
import org.jbpm.api.runtime.Attachments;
+import org.jbpm.api.runtime.Attachments.Key;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.integration.client.TokenImpl;
@@ -79,6 +80,11 @@
return procDef.getProcessEngine();
}
+ public ProcessInstance getOldProcessInstance()
+ {
+ return oldProc;
+ }
+
//@Override
public ProcessStatus getProcessStatus()
{
@@ -139,22 +145,41 @@
//@Override
public Token startProcess()
{
- setProcessStatus(ProcessStatus.Active);
- oldProc = new ProcessInstance(procDef.getOldProcessDefinition());
- Token rootToken = new TokenImpl(this, oldProc.getRootToken());
- rootToken.signal();
- return rootToken;
+ return startProcess(null);
}
//@Override
- public Token startProcess(Attachments att)
+ public Token startProcess(Attachments ctxData)
{
- throw new NotImplementedException();
+ setProcessStatus(ProcessStatus.Active);
+ oldProc = new ProcessInstance(procDef.getOldProcessDefinition());
+
+ // Create the root token
+ Token token = new TokenImpl(this, oldProc.getRootToken());
+
+ // Initialize the context data
+ if (ctxData != null)
+ {
+ Attachments tokenAtt = token.getAttachments();
+ for (Key key : ctxData.getAttachmentKeys())
+ {
+ Object val = ctxData.getAttachment(key.getClassPart(), key.getNamePart());
+ tokenAtt.addAttachment(key.getClassPart(), key.getNamePart(), val);
+ }
+ }
+
+ // Signal the root token
+ token.signal();
+
+ return token;
}
public Token getRootToken()
{
- return new TokenImpl(this, oldProc.getRootToken());
+ if (oldProc != null)
+ return new TokenImpl(this, oldProc.getRootToken());
+ else
+ return null;
}
public Set<Token> getTokens()
Added: jbpm3/trunk/modules/integration/api/src/main/java/org/jbpm/integration/runtime/TokenAttachmentDelegate.java
===================================================================
--- jbpm3/trunk/modules/integration/api/src/main/java/org/jbpm/integration/runtime/TokenAttachmentDelegate.java (rev 0)
+++ jbpm3/trunk/modules/integration/api/src/main/java/org/jbpm/integration/runtime/TokenAttachmentDelegate.java 2008-11-26 10:54:40 UTC (rev 3099)
@@ -0,0 +1,114 @@
+/*
+ * 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.integration.runtime;
+
+//$Id$
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jbpm.api.runtime.Attachments;
+import org.jbpm.context.exe.ContextInstance;
+import org.jbpm.integration.client.TokenImpl;
+
+/**
+ * An Attachment implementation that delegates to to the ContextInstance
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 26-Nov-2008
+ */
+public class TokenAttachmentDelegate implements Attachments
+{
+ private ContextInstance context;
+ private TokenImpl token;
+
+ public TokenAttachmentDelegate(TokenImpl token, ContextInstance context)
+ {
+ this.token = token;
+ this.context = context;
+ }
+
+ public <T> T addAttachment(Class<T> clazz, Object value)
+ {
+ return addAttachment(clazz, null, value);
+ }
+
+ public Object addAttachment(String name, Object value)
+ {
+ return addAttachment(null, name, value);
+ }
+
+ public <T> T addAttachment(Class<T> clazz, String name, Object value)
+ {
+ Key key = new Key(clazz, name);
+ context.createVariable(key.toString(), value, token.getOldToken());
+ return (T)value;
+ }
+
+ public <T> T getAttachment(Class<T> clazz)
+ {
+ return getAttachment(clazz, null);
+ }
+
+ public Object getAttachment(String name)
+ {
+ return getAttachment(null, name);
+ }
+
+ public <T> T getAttachment(Class<T> clazz, String name)
+ {
+ Key key = new Key(clazz, name);
+ return (T)context.getVariable(key.toString(), token.getOldToken());
+ }
+
+ public Collection<Key> getAttachmentKeys()
+ {
+ Set<Key> keys = new HashSet<Key>();
+ Set<String> strKeys = context.getVariables(token.getOldToken()).keySet();
+ for (String strKey : strKeys)
+ {
+ Key key = Key.valueOf(strKey);
+ if (key != null)
+ keys.add(key);
+ }
+ return keys;
+ }
+
+ public <T> T removeAttachment(Class<T> clazz, String name)
+ {
+ Key key = new Key(clazz, name);
+ T value = getAttachment(clazz, name);
+ context.deleteVariable(key.toString(), token.getOldToken());
+ return value;
+ }
+
+ public <T> T removeAttachment(Class<T> clazz)
+ {
+ return removeAttachment(clazz, null);
+ }
+
+ public Object removeAttachment(String name)
+ {
+ return removeAttachment(null, name);
+ }
+}
\ No newline at end of file
Property changes on: jbpm3/trunk/modules/integration/api/src/main/java/org/jbpm/integration/runtime/TokenAttachmentDelegate.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the jbpm-commits
mailing list