incubator-agila-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject svn commit: r365997 [2/3] - in /incubator/agila/trunk/modules/bpel: ./ client/api/src/java/org/apache/agila/bpel/client/ client/web/src/java/org/apache/agila/bpel/web/common/ client/web/src/java/org/apache/agila/bpel/web/deployer/action/ client/web/src...
Date Wed, 04 Jan 2006 21:21:04 GMT
Modified: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/definition/impl/dao/ActivityDAO.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/definition/impl/dao/ActivityDAO.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/definition/impl/dao/ActivityDAO.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/definition/impl/dao/ActivityDAO.java Wed Jan  4 13:19:47 2006
@@ -58,6 +58,12 @@
 //            "WHERE event.partnerLink = (:partner) AND event.portType = (:portType) " +
 //            "AND event.operation = (:operation)";
 
+    private static String FIND_ACTIVITYS_BY_CONTAINER =
+        "FROM org.apache.agila.bpel.engine.priv.core.definition.impl.ActivityImpl as activity " +
+        "INNER JOIN pick.activityContainer as container  WHERE container.id = (:id)";
+    
+    
+    
     public static StructuredActivityImpl findContainer(Long containerId) throws DBSessionException {
         Session session = DBSessionManager.getActiveSession();
 
@@ -140,6 +146,28 @@
             results = byInvoker.list();
         } catch (HibernateException e) {
             log.error("Problem when finding receives by invoker.", e);
+            throw new DBSessionException(e);
+        }
+        return results;
+    }
+
+    /**
+     * finds all activities for the given container activity
+     * 
+     * @param container structured activity which may or may not contains activities
+     * @return list of activities or null if nothing was found
+     * @throws DBSessionException
+     */
+    public static List findActivitiesByContainer(StructuredActivityImpl container) throws DBSessionException {
+        Session session = DBSessionManager.getActiveSession();
+
+        List results = null;
+        try {
+            Query byInvoker = session.createQuery(FIND_ACTIVITYS_BY_CONTAINER);
+            byInvoker.setParameter(PARTNER_PARAM, container.getId());
+            results = byInvoker.list();
+        } catch (HibernateException e) {
+            log.error("Problem when finding activities by container.", e);
             throw new DBSessionException(e);
         }
         return results;

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/ExecutionContext.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/ExecutionContext.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/ExecutionContext.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/ExecutionContext.java Wed Jan  4 13:19:47 2006
@@ -97,6 +97,8 @@
 	public Collection getEvents();
 
     public void execute();
+    
+    public void terminate();
 
     /**
      * Gets this execution context initial activity (the one whose execution

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/ProcessInstance.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/ProcessInstance.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/ProcessInstance.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/ProcessInstance.java Wed Jan  4 13:19:47 2006
@@ -73,6 +73,8 @@
 
     public void notifyExecution(ExecutionContext ec);
     public void notifyTermination(ExecutionContext ec);
+    
+    public void terminate();
 
     Audit audit() throws Exception;
 }

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/ProcessInstanceFactory.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/ProcessInstanceFactory.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/ProcessInstanceFactory.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/ProcessInstanceFactory.java Wed Jan  4 13:19:47 2006
@@ -17,15 +17,23 @@
 
 import org.apache.agila.bpel.engine.common.persistence.CreationException;
 import org.apache.agila.bpel.engine.common.persistence.DBSessionException;
+import org.apache.agila.bpel.engine.common.persistence.DeletionException;
 import org.apache.agila.bpel.engine.common.persistence.FinderException;
 import org.apache.agila.bpel.engine.common.persistence.XMLSessionException;
 import org.apache.agila.bpel.engine.exception.CorrelationViolationException;
+import org.apache.agila.bpel.engine.priv.core.definition.Activity;
 import org.apache.agila.bpel.engine.priv.core.definition.CorrelationSet;
 import org.apache.agila.bpel.engine.priv.core.definition.AgilaProcess;
+import org.apache.agila.bpel.engine.priv.core.definition.impl.CorrelationSetImpl;
+import org.apache.agila.bpel.engine.priv.core.definition.impl.InvokeImpl;
+import org.apache.agila.bpel.engine.priv.core.definition.impl.ReceiveImpl;
+import org.apache.agila.bpel.engine.priv.core.definition.impl.ReplyImpl;
+import org.apache.agila.bpel.engine.priv.core.definition.impl.StructuredActivityImpl;
 import org.apache.agila.bpel.engine.priv.core.dynamic.impl.ProcessInstanceImpl;
 import org.apache.agila.bpel.engine.priv.core.dynamic.impl.ValuedPropertyImpl;
 import org.apache.agila.bpel.engine.priv.core.dynamic.impl.dao.ProcessInstanceDAO;
 import org.apache.agila.bpel.engine.priv.core.dynamic.impl.xao.CorrelationXAO;
+import org.apache.agila.bpel.engine.priv.core.dynamic.impl.xao.VariableXAO;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -125,6 +133,106 @@
     return ProcessInstanceDAO.findInstanceByStatus(status);
   }
 
+/**
+ * deletes a process instance as well as it's variable and correlation instances 
+ * 
+ * @param instanceId a process instance id
+ * @throws FinderException
+ * @throws DeletionException
+ */
+  public static void deleteInstance(Long instanceId) throws FinderException, DeletionException {
+	  ProcessInstance instance = ProcessInstanceDAO.findById(instanceId);
+	  deleteReferencedVariables(instance);
+	  deleteReferencedCorrelations(instance);
+	  ProcessInstanceDAO.remove(instance);
+  }   
+  
+  /**
+   * removes all correlations referenced by the given process instance
+   * 
+   * @param processInstance process instance object 
+   */
+  private static void deleteReferencedCorrelations(ProcessInstance processInstance) {
+	  Collection cor = processInstance.getProcess().getCorrelationSets();
+	  if(cor != null)
+	  {
+		  for (Iterator iter = cor.iterator(); iter.hasNext();) {
+			  CorrelationSetImpl element = (CorrelationSetImpl) iter.next();
+			  VariableXAO.removeProcessDocument(
+					  element.getName(),
+					  VariableXAO.CORRELATION,
+					  processInstance.getId(),
+					  processInstance.getProcess().getName());
+		  }
+	  }
+  }
+
+  /**
+   * removes all variables referenced by the given process instance
+   * 
+   * @param processInstance process instance object 
+   */
+  public static void deleteReferencedVariables(ProcessInstance processInstance)
+  {
+	  deleteReferencedVariables(
+			  processInstance.getProcess().getActivity(),
+			  processInstance.getId(),
+			  processInstance.getProcess().getName());
+  }
+  
+  /**
+   * removes all variables referenced by the given activity (receive,reply,invoke)
+   * 
+   * @param activity the activity to test for referenced variables
+   * @param instanceId process instance ID
+   * @param processName process name
+   */
+  public static void deleteReferencedVariables(Activity activity, Long instanceId, String processName)
+  {
+	  if(activity instanceof StructuredActivityImpl)
+	  { 
+		  StructuredActivityImpl structured = (StructuredActivityImpl)activity;
+		  for (Iterator iter = structured.getActivities().iterator(); iter.hasNext();) {
+			  deleteReferencedVariables((Activity) iter.next(),instanceId, processName);
+		}
+	  } 	  
+	  else if(activity instanceof ReceiveImpl)
+	  {
+		  ReceiveImpl receive = (ReceiveImpl)activity;
+		  VariableXAO.removeProcessDocument(
+				  receive.getVariable(), VariableXAO.VARIABLE, instanceId, processName);
+	  } 
+	  else if (activity instanceof ReplyImpl) 
+	  {
+		  ReplyImpl reply = (ReplyImpl)activity;
+		  VariableXAO.removeProcessDocument(
+				  reply.getVariable(), VariableXAO.VARIABLE, instanceId, processName);		  
+	  }
+	  else if (activity instanceof InvokeImpl)
+	  {
+		  InvokeImpl invoke = (InvokeImpl)activity;
+		  VariableXAO.removeProcessDocument(
+				  invoke.getInputVariable(), VariableXAO.VARIABLE, instanceId, processName);		  
+		  VariableXAO.removeProcessDocument(
+				  invoke.getOutputVariable(), VariableXAO.VARIABLE, instanceId, processName);		  
+	  }
+	  
+  }
+  
+  
+  /**
+   * terminates a process instance if it still exists
+   * 
+   * @param instanceId instance id of process instance to terminate
+   * @throws FinderException
+   */
+  public static void terminateInstance(Long instanceId) throws FinderException {
+	  ProcessInstance instance = ProcessInstanceDAO.findById(instanceId);
+	  if (instance != null) {
+	  	instance.terminate();
+	  }
+  }  
+  
   private static void attachCorrelation(ProcessInstanceImpl instance, String correlationSetName, Map propertyValues, boolean create)
       throws DBSessionException, CorrelationViolationException {
     // If a process instance can be found with the same correlation there's a correlation error

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/BasicECImpl.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/BasicECImpl.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/BasicECImpl.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/BasicECImpl.java Wed Jan  4 13:19:47 2006
@@ -15,10 +15,20 @@
  */
 package org.apache.agila.bpel.engine.priv.core.dynamic.impl;
 
+import org.apache.agila.bpel.engine.common.persistence.PersistentDataAccess;
 import org.apache.agila.bpel.engine.priv.core.dynamic.BasicEC;
+import org.apache.agila.bpel.engine.priv.core.dynamic.ExecutionContext;
 
 /**
  * Please put some JavaDoc here.
  */
 public abstract class BasicECImpl extends ExecutionContextImpl implements BasicEC {
+
+    public void terminate() {
+        if (getStatus() == ExecutionContext.ACTIVE) {
+            this.setStatus(ExecutionContext.CANCELED);
+            PersistentDataAccess.update(this);
+        }
+    }
+
 }

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/ProcessInstanceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/ProcessInstanceImpl.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/ProcessInstanceImpl.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/ProcessInstanceImpl.java Wed Jan  4 13:19:47 2006
@@ -40,7 +40,7 @@
     private ExecutionContext childExecutionContext;
 
     private Collection properties = new HashSet();
-    
+
     // This map contains contextual data shared among several execution 
     // contexts, it's not persisted yet. 
     private Map contextualData = new HashMap();
@@ -102,61 +102,69 @@
     public void putContextualData(String key, Object value) {
         contextualData.put(key, value);
     }
-    
+
     public Object getContextualData(String key) {
         return contextualData.get(key);
     }
-    
+
     public void notifyExecution(ExecutionContext ec) {
         this.setStatus(ACTIVE);
-	    PersistentDataAccess.update(this);
+        PersistentDataAccess.update(this);
     }
 
     public void notifyTermination(ExecutionContext ec) {
-        this.setStatus(COMPLETED);        
-	    PersistentDataAccess.update(this);
+        this.setStatus(COMPLETED);
+        PersistentDataAccess.update(this);
+    }
+
+    public void terminate() {
+        if (this.getStatus() == ProcessInstance.ACTIVE) {
+            this.setStatus(CANCELED);
+            PersistentDataAccess.update(this);
+            getChildExecutionContext().terminate();
+        }
     }
 
     public Audit audit() throws Exception {
-    Audit audit = new Audit();
-    audit.setState(ProcessInstanceState.getInstance(this.getStatus()).getText());
-    audit.setTitle(this.getProcess().getName() + " (v. " + this.getProcess().getVersion() + ")");
-    audit.setProcessInstanceId(this.getId().longValue());
-    audit.setEvents(ExecutionEventFactory.findExecutionEvents(ExecutionEvent.REF_TYPE_PROCESS_INSTANCE, getId()));
-
-    ExecutionContext ec = this.getChildExecutionContext();
-    if (ec != null) {
-      audit.addEntry(ec.audit());
-    }
-    return audit;
-  }
-
-  public String toString() {
-    final StringBuffer buf = new StringBuffer();
-    buf.append("ProcessInstanceImpl");
-    buf.append("{id=").append(id);
-    buf.append(",status=").append(status);
-    buf.append("\n,process=");
-    if (process != null) {
-      buf.append("{version=").append(process.getVersion());
-      buf.append(",name=").append(process.getName());
-      buf.append(",namespace=").append(process.getNamespace());
-      buf.append('}');
-    }
-
-    buf.append("properties=");
-    ValuedProperty property = null;
-    for (Iterator propIter = properties.iterator(); propIter.hasNext();) {
-      property = (ValuedProperty) propIter.next();
-      buf.append("\n,property=").append(property);
-    }
-
-    buf.append(",childExecutionContext=");
-    if (childExecutionContext != null) {
-      buf.append(childExecutionContext);
-    }
-
-    buf.append('}');
-    return buf.toString();
-  }
+        Audit audit = new Audit();
+        audit.setState(ProcessInstanceState.getInstance(this.getStatus()).getText());
+        audit.setTitle(this.getProcess().getName() + " (v. " + this.getProcess().getVersion() + ")");
+        audit.setProcessInstanceId(this.getId().longValue());
+        audit.setEvents(ExecutionEventFactory.findExecutionEvents(ExecutionEvent.REF_TYPE_PROCESS_INSTANCE, getId()));
+
+        ExecutionContext ec = this.getChildExecutionContext();
+        if (ec != null) {
+            audit.addEntry(ec.audit());
+        }
+        return audit;
+    }
+
+    public String toString() {
+        final StringBuffer buf = new StringBuffer();
+        buf.append("ProcessInstanceImpl");
+        buf.append("{id=").append(id);
+        buf.append(",status=").append(status);
+        buf.append("\n,process=");
+        if (process != null) {
+            buf.append("{version=").append(process.getVersion());
+            buf.append(",name=").append(process.getName());
+            buf.append(",namespace=").append(process.getNamespace());
+            buf.append('}');
+        }
+
+        buf.append("properties=");
+        ValuedProperty property = null;
+        for (Iterator propIter = properties.iterator(); propIter.hasNext();) {
+            property = (ValuedProperty) propIter.next();
+            buf.append("\n,property=").append(property);
+        }
+
+        buf.append(",childExecutionContext=");
+        if (childExecutionContext != null) {
+            buf.append(childExecutionContext);
+        }
+
+        buf.append('}');
+        return buf.toString();
+    }
 }

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/StructuredECImpl.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/StructuredECImpl.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/StructuredECImpl.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/StructuredECImpl.java Wed Jan  4 13:19:47 2006
@@ -34,49 +34,49 @@
  */
 public abstract class StructuredECImpl extends ExecutionContextImpl implements StructuredEC {
 
-	private StructuredActivity activity;
-	private Set executionContextsSet = new HashSet();
+    private StructuredActivity activity;
+    private Set executionContextsSet = new HashSet();
 
-	public StructuredActivity getActivity() {
-		return activity;
-	}
-
-	public void setActivity(StructuredActivity activity) {
-		this.activity = activity;
-	}
-
-	/**
-	 * Do not use this method, its doesn't maintain activity indexes properly, use
-	 * the addActivity method instead.
-	 * @param exectutionContextsSet
-	 */
-	public void setExecutionContextsSet(Set exectutionContextsSet) {
-		this.executionContextsSet = exectutionContextsSet;
-	}
-
-	public Set getExecutionContextsSet() {
-		return executionContextsSet;
-	}
-
-	public List getExecutionContexts() {
-		// Making sure the set is ordered before using it to create the List.
-		SortedSet sortedSet = new TreeSet(executionContextsSet);
-		return new ArrayList(sortedSet);
-	}
-
-	public void addExecutionContext(ExecutionContext ec) {
-		ExecutionContextImpl impl = (ExecutionContextImpl) ec;
-		impl.setIndex(nextECIndex());
-		getExecutionContextsSet().add(ec);
-		impl.setContainer(this);
-	}
+    public StructuredActivity getActivity() {
+        return activity;
+    }
+
+    public void setActivity(StructuredActivity activity) {
+        this.activity = activity;
+    }
+
+    /**
+     * Do not use this method, its doesn't maintain activity indexes properly, use
+     * the addActivity method instead.
+     * @param exectutionContextsSet
+     */
+    public void setExecutionContextsSet(Set exectutionContextsSet) {
+        this.executionContextsSet = exectutionContextsSet;
+    }
+
+    public Set getExecutionContextsSet() {
+        return executionContextsSet;
+    }
+
+    public List getExecutionContexts() {
+        // Making sure the set is ordered before using it to create the List.
+        SortedSet sortedSet = new TreeSet(executionContextsSet);
+        return new ArrayList(sortedSet);
+    }
+
+    public void addExecutionContext(ExecutionContext ec) {
+        ExecutionContextImpl impl = (ExecutionContextImpl) ec;
+        impl.setIndex(nextECIndex());
+        getExecutionContextsSet().add(ec);
+        impl.setContainer(this);
+    }
 
     /**
      * Returns the origin activity of the passed child execution context.
      * @param ec the execution context to get origin activity for
      * @return
      */
-	public abstract Activity getActivityForChildContext(ExecutionContext ec);
+    public abstract Activity getActivityForChildContext(ExecutionContext ec);
 
     /**
      * Returns the execution context created in this structured execution from
@@ -97,45 +97,54 @@
      */
     public abstract void notifyTermination(ExecutionContext ec);
 
-	private int nextECIndex() {
-		int index = 0;
-		for (Iterator ecIterator = getExecutionContextsSet().iterator(); ecIterator.hasNext();) {
-			ExecutionContextImpl ecImpl = (ExecutionContextImpl) ecIterator.next();
-			if (ecImpl.getIndex() > index)
-				index = ecImpl.getIndex();
-		}
-		return index + 1;
-	}
-
-  public AuditEntry audit() throws Exception {
-    AuditEntry auditEntry = super.audit();
-    ExecutionContext executionContext = null;
-    List executionContexts = this.getExecutionContexts();
-    for (Iterator ecIter = executionContexts.iterator(); ecIter.hasNext();) {
-      executionContext = (ExecutionContext) ecIter.next();
-      auditEntry.addEntry(executionContext.audit());
-    }
-    return auditEntry;
-  }
-
-  public String toString() {
-    final StringBuffer buf = new StringBuffer();
-    buf.append(super.toString()).append(" ::: ");
-    buf.append("StructuredECImpl");
-    buf.append("{");
-    if (activity != null) {
-      buf.append("(ref)activity=" + activity);
-    }
-    buf.append("}");
-
-    buf.append(",childExecContexts=");
-    ExecutionContext executionContext = null;
-    List executionContexts = this.getExecutionContexts();
-    for (Iterator ecIter = executionContexts.iterator(); ecIter.hasNext();) {
-      executionContext = (ExecutionContext) ecIter.next();
-      buf.append("\n,executionContext=").append(executionContext);
+    public void terminate() {
+        for (Iterator ecIterator = getExecutionContexts().iterator(); ecIterator.hasNext();) {
+            ExecutionContextImpl ecImpl = (ExecutionContextImpl) ecIterator.next();
+            if (ecImpl.getStatus() == ExecutionContext.ACTIVE) {
+                ecImpl.terminate();
+            }
+        }
+    }
+
+    private int nextECIndex() {
+        int index = 0;
+        for (Iterator ecIterator = getExecutionContextsSet().iterator(); ecIterator.hasNext();) {
+            ExecutionContextImpl ecImpl = (ExecutionContextImpl) ecIterator.next();
+            if (ecImpl.getIndex() > index)
+                index = ecImpl.getIndex();
+        }
+        return index + 1;
     }
 
-    return buf.toString();
-  }
+    public AuditEntry audit() throws Exception {
+        AuditEntry auditEntry = super.audit();
+        ExecutionContext executionContext = null;
+        List executionContexts = this.getExecutionContexts();
+        for (Iterator ecIter = executionContexts.iterator(); ecIter.hasNext();) {
+            executionContext = (ExecutionContext) ecIter.next();
+            auditEntry.addEntry(executionContext.audit());
+        }
+        return auditEntry;
+    }
+
+    public String toString() {
+        final StringBuffer buf = new StringBuffer();
+        buf.append(super.toString()).append(" ::: ");
+        buf.append("StructuredECImpl");
+        buf.append("{");
+        if (activity != null) {
+            buf.append("(ref)activity=" + activity);
+        }
+        buf.append("}");
+
+        buf.append(",childExecContexts=");
+        ExecutionContext executionContext = null;
+        List executionContexts = this.getExecutionContexts();
+        for (Iterator ecIter = executionContexts.iterator(); ecIter.hasNext();) {
+            executionContext = (ExecutionContext) ecIter.next();
+            buf.append("\n,executionContext=").append(executionContext);
+        }
+
+        return buf.toString();
+    }
 }

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/dao/ExecutionContextDAO.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/dao/ExecutionContextDAO.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/dao/ExecutionContextDAO.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/dao/ExecutionContextDAO.java Wed Jan  4 13:19:47 2006
@@ -15,7 +15,10 @@
  */
 package org.apache.agila.bpel.engine.priv.core.dynamic.impl.dao;
 
+import java.io.Serializable;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import net.sf.hibernate.HibernateException;
 import net.sf.hibernate.Query;
@@ -23,8 +26,11 @@
 
 import org.apache.agila.bpel.engine.common.persistence.DBSessionException;
 import org.apache.agila.bpel.engine.common.persistence.DBSessionManager;
+import org.apache.agila.bpel.engine.common.persistence.DeletionException;
 import org.apache.agila.bpel.engine.common.persistence.PersistentDataAccess;
 import org.apache.agila.bpel.engine.priv.core.definition.impl.ActivityImpl;
+import org.apache.agila.bpel.engine.priv.core.dynamic.impl.ExecutionContextImpl;
+import org.apache.agila.bpel.engine.priv.core.dynamic.impl.StructuredECImpl;
 
 /**
  * Please put some JavaDoc here.
@@ -68,5 +74,34 @@
             throw new DBSessionException(e);
         }
         return ecs;
+    }
+    
+    /**
+     * Remove structured execution context's childs execution context, it's own 
+     * execution context an refresh the cache 
+     * 
+     * @param executionContext ec to remove
+     * @throws DeletionException
+     */
+	public static void remove(ExecutionContextImpl executionContext) throws DeletionException {
+        if (executionContext instanceof StructuredECImpl) {
+			StructuredECImpl structuredECImpl = (StructuredECImpl) executionContext;
+			Set executionContexts = structuredECImpl.getExecutionContextsSet();
+			for (Iterator iter = executionContexts.iterator(); iter
+					.hasNext();) {
+				ExecutionContextImpl child = (ExecutionContextImpl) iter.next();
+				remove(child);					
+			}
+			structuredECImpl.getActivity().getExecutionContexts().remove(structuredECImpl);
+			try {			
+				Serializable activityId = ((ActivityImpl) structuredECImpl.getActivity()).getId();
+				DBSessionManager.getActiveSession().getSessionFactory().evictCollection("org.apache.agila.bpel.engine.priv.core.definition.impl.StructuredActivityImpl.executionContexts", activityId);
+			} catch (HibernateException e) {
+				throw new DeletionException(e);
+			} catch (DBSessionException e) {
+				throw new DeletionException(e);
+			}		
+		}
+		PersistentDataAccess.remove(executionContext);		
     }
 }

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/dao/ProcessInstanceDAO.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/dao/ProcessInstanceDAO.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/dao/ProcessInstanceDAO.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/dao/ProcessInstanceDAO.java Wed Jan  4 13:19:47 2006
@@ -15,22 +15,28 @@
  */
 package org.apache.agila.bpel.engine.priv.core.dynamic.impl.dao;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import net.sf.hibernate.HibernateException;
 import net.sf.hibernate.Query;
 import net.sf.hibernate.Session;
 
 import org.apache.agila.bpel.engine.common.persistence.DBSessionException;
 import org.apache.agila.bpel.engine.common.persistence.DBSessionManager;
+import org.apache.agila.bpel.engine.common.persistence.DeletionException;
 import org.apache.agila.bpel.engine.common.persistence.FinderException;
 import org.apache.agila.bpel.engine.common.persistence.PersistentDataAccess;
-import org.apache.agila.bpel.engine.priv.core.dynamic.ValuedProperty;
+import org.apache.agila.bpel.engine.priv.core.definition.impl.ProcessImpl;
 import org.apache.agila.bpel.engine.priv.core.dynamic.ProcessInstance;
+import org.apache.agila.bpel.engine.priv.core.dynamic.ValuedProperty;
+import org.apache.agila.bpel.engine.priv.core.dynamic.impl.ExecutionContextImpl;
 import org.apache.agila.bpel.engine.priv.core.dynamic.impl.ProcessInstanceImpl;
+import org.apache.agila.bpel.engine.priv.core.dynamic.impl.ValuedPropertyImpl;
 
 public class ProcessInstanceDAO extends PersistentDataAccess {
 
@@ -109,7 +115,6 @@
             Query byStatus = session.createQuery(FINDBY_STATUS);
 
             byStatus.setParameterList("status", status);
-
             instances = byStatus.list();
         } catch (net.sf.hibernate.HibernateException e) {
             throw new DBSessionException(e);
@@ -120,4 +125,33 @@
     public static ProcessInstance findById(Long id) throws FinderException {
       return (ProcessInstance) PersistentDataAccess.findById(id, ProcessInstanceImpl.class);
     }
+
+    
+    /**
+     * deletes a process instance DAO Object and all persistent references permanently
+     * @param processInstance process instance to delete
+     * @throws DeletionException
+     */
+	public static void remove(ProcessInstance processInstance) throws DeletionException {
+		ExecutionContextImpl executionContext = (ExecutionContextImpl) processInstance.getChildExecutionContext();
+		if (executionContext != null) {
+			ExecutionContextDAO.remove(executionContext);
+		}
+		Collection properties = processInstance.getProperties();
+		for (Iterator iter = properties.iterator(); iter
+				.hasNext();) {
+			ValuedPropertyImpl property = (ValuedPropertyImpl) iter.next();
+			PersistentDataAccess.remove(property);					
+		}
+		
+		PersistentDataAccess.remove(processInstance);
+		try {
+			Serializable processId = ((ProcessImpl) processInstance.getProcess()).getId();
+			DBSessionManager.getActiveSession().getSessionFactory().evictCollection("org.apache.agila.bpel.engine.priv.core.definition.impl.ProcessImpl.instances", processId);			
+		} catch (HibernateException e) {
+			throw new DeletionException(e);
+		} catch (DBSessionException e) {
+			throw new DeletionException(e);
+		}	
+	}
 }

Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/AbstractXAO.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/AbstractXAO.java?rev=365997&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/AbstractXAO.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/AbstractXAO.java Wed Jan  4 13:19:47 2006
@@ -0,0 +1,32 @@
+package org.apache.agila.bpel.engine.priv.core.dynamic.impl.xao;
+
+import org.apache.agila.bpel.engine.common.persistence.XMLDataAccess;
+import org.apache.agila.bpel.engine.common.persistence.XMLSessionException;
+import org.xmldb.api.base.Collection;
+
+public abstract class AbstractXAO extends XMLDataAccess{
+	
+	public static final String VARIABLE = "variable";
+	public static final String CORRELATION = "correlation";
+	public static final String ADDRESSING = "addressing";
+	
+    protected static Collection initializeCollection(String processName, String collectionName) throws XMLSessionException {
+        // Testing if the process collection already exist (doesn't if first execution)
+        Collection result = getCollection("/" + processName + "/" + collectionName);
+        if (result == null) {
+            Collection processColl = null;
+            try {
+                processColl = getCollection("/" + processName);
+            } catch (XMLSessionException e) { }
+            if (processColl == null) {
+                // When it doesn't exist, creating it
+                Collection rootColl = getRootCollection();
+                processColl = createCollection(rootColl, processName);
+            }
+            result = createCollection(processColl, collectionName);
+        }
+        return result;
+    }
+	
+
+}

Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/AddressingXAO.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/AddressingXAO.java?rev=365997&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/AddressingXAO.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/AddressingXAO.java Wed Jan  4 13:19:47 2006
@@ -0,0 +1,65 @@
+package org.apache.agila.bpel.engine.priv.core.dynamic.impl.xao;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.agila.bpel.engine.common.persistence.XMLSessionException;
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.xmldb.api.base.Collection;
+
+/**
+ * TODO : s.h. implementation not yet finished
+ * Class responsible for the addressing information
+ * 
+ * all asynchronous send messages should write their callback
+ * information to be able to find the target for incoming
+ * messages. The either messageId or correlationSet 
+ * will be used for correlation 
+ *  
+ * <br>
+ * Document format:
+ * <p>
+ * <code>
+ * 		&lt;addressing&gt; <br>
+ * 			&lt;msgId&gt;	&lt;/msgId&gt;  		<br>
+ * 			&lt;partner&gt;	&lt;/partner&gt; 	<br>
+ * 			&lt;namespace&gt;&lt;/namespace&gt;  	<br> 
+ * 			&lt;port&gt;		&lt;/port&gt;  		<br>
+ * 			&lt;operation&gt;&lt;/operation&gt;  	<br>
+ *  		&lt;/addressing&gt;
+ * </code>
+ * 
+ * 
+ * 
+ * @author steffen.horlacher@pansoft.de
+ *
+ */
+public class AddressingXAO extends AbstractXAO {
+
+	public static void createAddressing(String processName,
+			String targetPort, Long instanceId, Map properyValues)
+			throws XMLSessionException {
+
+		Collection correlColl = initializeCollection(processName, ADDRESSING);
+
+		// Preparing the correlation document
+		Document document = DocumentHelper.createDocument();
+		Element root = document.addElement("addressing").addAttribute(
+				"instanceid", "" + instanceId.longValue());
+		for (Iterator propValuesIter = properyValues.keySet().iterator(); propValuesIter
+				.hasNext();) {
+			String property = (String) propValuesIter.next();
+			root
+					.addElement("property")
+					.addAttribute("name", property)
+					.addAttribute("value", (String) properyValues.get(property));
+		}
+
+		// Inserting the document
+		insertDocument(correlColl, targetPort + instanceId.longValue(),
+				document);
+	}
+
+}

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/CorrelationXAO.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/CorrelationXAO.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/CorrelationXAO.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/CorrelationXAO.java Wed Jan  4 13:19:47 2006
@@ -18,34 +18,23 @@
 import java.util.Iterator;
 import java.util.Map;
 
+import org.apache.agila.bpel.engine.common.persistence.XMLSessionException;
 import org.dom4j.Document;
 import org.dom4j.DocumentHelper;
 import org.dom4j.Element;
-import org.apache.agila.bpel.engine.common.persistence.XMLDataAccess;
-import org.apache.agila.bpel.engine.common.persistence.XMLSessionException;
 import org.xmldb.api.base.Collection;
 
 /**
  * An XML Access Object specialized for correlations.
  */
-public class CorrelationXAO extends XMLDataAccess {
+public class CorrelationXAO extends AbstractXAO {
 
     public static void createCorrelation(String processName, String correlationName, Long instanceId, Map properyValues)
             throws XMLSessionException {
-
-        Collection correlColl = getCollection("/" + processName + "/correlation/");
-        if (correlColl == null) {
-            // Testing if the process collection already exist (doesn't if first execution)
-            Collection processColl = getCollection("/" + processName + "/");
-            if (processColl == null) {
-                // When it doesn't exist, creating it
-                Collection rootColl = getRootCollection();
-                processColl = createCollection(rootColl, processName);
-            }
-            correlColl = createCollection(processColl, "correlation");
-        }
-
-        // Preparing the correlation document
+    	
+    		Collection correlColl = initializeCollection(processName,CORRELATION);
+    	
+    		// Preparing the correlation document
         Document document = DocumentHelper.createDocument();
         Element root = document.addElement("correlation")
                 .addAttribute("instanceid", ""+instanceId.longValue());

Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/PartnerLinkXAO.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/PartnerLinkXAO.java?rev=365997&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/PartnerLinkXAO.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/PartnerLinkXAO.java Wed Jan  4 13:19:47 2006
@@ -0,0 +1,14 @@
+package org.apache.agila.bpel.engine.priv.core.dynamic.impl.xao;
+
+
+/**
+ * TODO : s.h. implement me
+ * 
+ * 
+ * @author steffen.horlacher@pansoft.de
+ *
+ */
+public class PartnerLinkXAO extends AbstractXAO {
+
+
+}

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/VariableXAO.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/VariableXAO.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/VariableXAO.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/core/dynamic/impl/xao/VariableXAO.java Wed Jan  4 13:19:47 2006
@@ -20,27 +20,27 @@
 import java.util.Map;
 import java.util.StringTokenizer;
 
+import org.apache.agila.bpel.common.util.XMLUtil;
+import org.apache.agila.bpel.engine.common.persistence.FinderException;
+import org.apache.agila.bpel.engine.common.persistence.XMLSessionException;
 import org.dom4j.Document;
 import org.dom4j.DocumentHelper;
 import org.dom4j.Element;
 import org.dom4j.IllegalAddException;
-import org.dom4j.Node;
 import org.dom4j.Namespace;
+import org.dom4j.Node;
 import org.dom4j.tree.DefaultElement;
+import org.jaxen.JaxenException;
 import org.jaxen.SimpleNamespaceContext;
 import org.jaxen.dom4j.Dom4jXPath;
 import org.jaxen.expr.DefaultAbsoluteLocationPath;
 import org.jaxen.expr.DefaultNameStep;
-import org.apache.agila.bpel.common.util.XMLUtil;
-import org.apache.agila.bpel.engine.common.persistence.FinderException;
-import org.apache.agila.bpel.engine.common.persistence.XMLDataAccess;
-import org.apache.agila.bpel.engine.common.persistence.XMLSessionException;
 import org.xmldb.api.base.Collection;
-import org.jaxen.JaxenException;
 /**
  * An XML Access Object specialized for variable processing.
  */
-public class VariableXAO extends XMLDataAccess {
+public class VariableXAO extends AbstractXAO {
+
 
     public static Document getVariable(String processName, String variableName, Long instanceId) throws XMLSessionException, FinderException {
         Document varDoc = getDocument("/" + processName + "/variable", variableName + instanceId.longValue());
@@ -182,7 +182,7 @@
         if (!"message".equals(msg.getRootElement().getName())) {
             throw new IllegalArgumentException("The provided message element must be named 'message");
         }
-        Collection varColl = initializeVariableCollection(processName);
+        Collection varColl = initializeCollection(processName,VARIABLE);
 
         // Inserting the document
         insertDocument(varColl, variableName + instanceId.longValue(), msg);
@@ -202,7 +202,7 @@
         if (part != null && part.length() > 0) {
             msgPart = "message/" + msgPart;
         }
-        Collection processVariables = initializeVariableCollection(processName);
+        Collection processVariables = initializeCollection(processName,VARIABLE);
 
         Document sourceDoc = null;
         try {
@@ -315,7 +315,7 @@
         if (part != null && part.length() > 0) {
             msgPart = "message/" + msgPart;
         }
-        Collection processVariables = initializeVariableCollection(processName);
+        Collection processVariables = initializeCollection(processName,VARIABLE);
 
         Document sourceDoc = null;
         try {
@@ -377,24 +377,6 @@
         }
     }
 
-    private static Collection initializeVariableCollection(String processName) throws XMLSessionException {
-        // Testing if the process collection already exist (doesn't if first execution)
-        Collection result = getCollection("/" + processName + "/variable");
-        if (result == null) {
-            Collection processColl = null;
-            try {
-                processColl = getCollection("/" + processName);
-            } catch (XMLSessionException e) { }
-            if (processColl == null) {
-                // When it doesn't exist, creating it
-                Collection rootColl = getRootCollection();
-                processColl = createCollection(rootColl, processName);
-            }
-            result = createCollection(processColl, "variable");
-        }
-        return result;
-    }
-
     /**
      * Build a document creating the elements described by the provided part and XPath
      * query, placing the provided Node inside the final path.
@@ -612,4 +594,25 @@
     	if (str.indexOf("[") >= 0) return str.substring(0, str.indexOf("["));
     	else return str;
     }
+   
+    /**
+     * removes an process instance variable if it exists
+     * 
+     * @param variableName variable to delete
+     * @param collectionName collection of the variable
+     * @param instanceId process instance id
+     * @param processName process name of which the variable is instance of
+     * @throws XMLSessionException
+     */
+	public static void removeProcessDocument(String variableName, String collectionName, Long instanceId, String processName) {
+		try {
+			Collection col = getCollection("/" + processName + "/" + collectionName);
+			if(col != null)
+			{
+				deleteDocumentIfExists(col,variableName + instanceId.longValue());
+			}
+		} catch (XMLSessionException e) {
+            // TODO: failure handling
+		}
+	}
 }

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/MessageBroker.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/MessageBroker.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/MessageBroker.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/MessageBroker.java Wed Jan  4 13:19:47 2006
@@ -384,7 +384,7 @@
             buf.append(SEPARATOR);
             buf.append(operation);
             if (message != null) {
-                messages.put(buf.toString(), message);
+                messages.put (buf.toString(), message.clone());
             } else {
                 Document nullDoc = DocumentHelper.createDocument();
                 nullDoc.addElement("null");

Added: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/impl/AddressingWSMessageBroker.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/impl/AddressingWSMessageBroker.java?rev=365997&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/impl/AddressingWSMessageBroker.java (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/impl/AddressingWSMessageBroker.java Wed Jan  4 13:19:47 2006
@@ -0,0 +1,493 @@
+package org.apache.agila.bpel.engine.priv.messaging.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.rmi.RemoteException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Definition;
+import javax.wsdl.Service;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.wsdl.extensions.soap.SOAPBody;
+import javax.wsdl.extensions.soap.SOAPOperation;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+import javax.xml.rpc.ServiceException;
+
+import org.apache.agila.bpel.common.configuration.DeployerConfiguration;
+import org.apache.agila.bpel.engine.common.event.EventManager;
+import org.apache.agila.bpel.engine.common.persistence.FinderException;
+import org.apache.agila.bpel.engine.common.persistence.XMLDataAccess;
+import org.apache.agila.bpel.engine.common.persistence.XMLSessionException;
+import org.apache.agila.bpel.engine.exception.EngineRuntimeException;
+import org.apache.agila.bpel.engine.priv.core.definition.Activity;
+import org.apache.agila.bpel.engine.priv.core.definition.AgilaProcess;
+import org.apache.agila.bpel.engine.priv.core.definition.PartnerLink;
+import org.apache.agila.bpel.engine.priv.core.definition.PartnerLinkRole;
+import org.apache.agila.bpel.engine.priv.messaging.FilterException;
+import org.apache.agila.bpel.engine.priv.messaging.InvocationException;
+import org.apache.agila.bpel.engine.priv.messaging.MessageBroker;
+import org.apache.agila.bpel.engine.priv.messaging.MessageFilter;
+import org.apache.axis.MessageContext;
+import org.apache.axis.client.Call;
+import org.apache.axis.message.MessageElement;
+import org.apache.axis.message.SOAPBodyElement;
+import org.apache.axis.message.addressing.AddressingHeaders;
+import org.apache.axis.message.addressing.Constants;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.axis.message.addressing.ReferencePropertiesType;
+import org.apache.axis.server.AxisServer;
+import org.apache.axis.types.URI.MalformedURIException;
+import org.apache.axis.utils.XMLUtils;
+import org.apache.log4j.Logger;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.io.DOMReader;
+import org.dom4j.io.DOMWriter;
+import org.dom4j.io.SAXReader;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import EDU.oswego.cs.dl.util.concurrent.BoundedBuffer;
+import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
+
+/**
+ * Invokes a web service from a WSDL definition.
+ * 
+ * @author mriou
+ * @author norsch
+ * @author chudick
+ */
+public class AddressingWSMessageBroker extends MessageBroker {
+
+	private static Logger log = Logger.getLogger(WSMessageBroker.class);
+
+	/**
+	 * @TODO parameterize this
+	 */
+
+	private static final String SOAP_NS = "http://schemas.xmlsoap.org/wsdl/soap/";
+
+	private static final String AGILA_NS = "http://www.apache.org/agila";
+
+	private static DOMReader domReader = null;
+
+	private static DOMWriter domWriter = null;
+
+	protected void asyncSend(Activity sender, String partner, String portType, String operation, Document message) {
+		AgilaProcess process = sender.fetchProcess();
+		PartnerLink partnerLink = process.getPartnerLink(partner);
+
+		org.w3c.dom.Document wsdlDoc = getWSDLDesc(process.getNamespace(), process.getName());
+		Definition def = readWSDL(wsdlDoc);
+
+		String wsdlStringDoc = getDOMReader().read(wsdlDoc).asXML();
+		String nameSpaceURI = def.getTargetNamespace();
+		QName serviceName = getService(def, portType);
+		String[] wsdlAdditionalInfo = getWSDLAdditionalInfo(def, portType, operation);
+		String soapAction = wsdlAdditionalInfo[0];
+		String msgNS = null;
+		if (wsdlAdditionalInfo[1] != null && wsdlAdditionalInfo[1].length() > 0) {
+			msgNS = wsdlAdditionalInfo[1];
+		} else {
+			msgNS = nameSpaceURI;
+		}
+		String encoding = wsdlAdditionalInfo[2];
+		String operationStyle = wsdlAdditionalInfo[3];
+		InputStream wsdlDesc = new ByteArrayInputStream(wsdlStringDoc.getBytes());
+
+		Document preparedMsg = prepareMessage(message, operation, msgNS, encoding);
+
+		try {
+			sendMessageAsync(nameSpaceURI, serviceName, portType, operation, soapAction, wsdlDesc, preparedMsg,
+					operationStyle, partnerLink);
+
+		} catch (ServiceException e) {
+			log.error("Could not send message to " + portType + " : " + preparedMsg.asXML(), e);
+			EventManager.fireError(new Exception("Could not send message to " + portType + ". Reason:\n"
+					+ (e.getMessage() == null ? "unknown" : e.getMessage()) + "\nMessage:\n" + preparedMsg.asXML()));
+			throw new EngineRuntimeException(e);
+		} catch (RemoteException e) {
+			log.error("Could not send message to " + portType + " : " + preparedMsg.asXML(), e);
+			EventManager.fireError(new Exception("Could not send message to " + portType + ". Reason:\n"
+					+ (e.getMessage() == null ? "unknown" : e.getMessage()) + "\nMessage:\n" + preparedMsg.asXML()));
+			throw new EngineRuntimeException(e);
+		}
+	}
+
+	protected void asyncSend(Activity sender, String partner, String namespace, String portType, String operation,
+			Document message) {
+		 
+		asyncSend(sender, partner, portType, operation, message);
+	}
+
+	protected Document syncSend(Activity sender, String partner, String portType, String operation, Document message) {
+		AgilaProcess process = sender.fetchProcess();
+		org.w3c.dom.Document wsdlDoc = getWSDLDesc(process.getNamespace(), process.getName());
+		Definition def = readWSDL(wsdlDoc);
+
+		String wsdlStringDoc = getDOMReader().read(wsdlDoc).asXML();
+		String nameSpaceURI = def.getTargetNamespace();
+		QName serviceName = getService(def, portType);
+		String[] wsdlAdditionalInfo = getWSDLAdditionalInfo(def, portType, operation);
+		String soapAction = wsdlAdditionalInfo[0];
+		String msgNS = null;
+		if (wsdlAdditionalInfo[1] != null && wsdlAdditionalInfo[1].length() > 0) {
+			msgNS = wsdlAdditionalInfo[1];
+		} else {
+			msgNS = nameSpaceURI;
+		}
+		String encoding = wsdlAdditionalInfo[2];
+		String operationStyle = wsdlAdditionalInfo[3];
+		InputStream wsdlDesc = new ByteArrayInputStream(wsdlStringDoc.getBytes());
+
+		Document preparedMsg = prepareMessage(message, operation, msgNS, encoding);
+
+		Document result = null;
+		try {
+			result = sendMessage(nameSpaceURI, serviceName, portType, operation, soapAction, wsdlDesc, preparedMsg,
+					operationStyle);
+
+			MessageFilter.filterMessage(result);
+
+			result.getRootElement().setName("message");
+		} catch (ServiceException e) {
+			log.error("Could not send message to " + portType + " : " + preparedMsg.asXML(), e);
+			EventManager.fireError(new Exception("Could not send message to " + portType + ". Reason:\n"
+					+ (e.getMessage() == null ? "unknown" : e.getMessage()) + "\nMessage:\n" + preparedMsg.asXML()));
+			throw new EngineRuntimeException(e);
+		} catch (RemoteException e) {
+			log.error("Could not send message to " + portType + " : " + preparedMsg.asXML(), e);
+			EventManager.fireError(new Exception("Could not send message to " + portType + ". Reason:\n"
+					+ (e.getMessage() == null ? "unknown" : e.getMessage()) + "\nMessage:\n" + preparedMsg.asXML()));
+			throw new EngineRuntimeException(e);
+		} catch (FilterException e) {
+			log.error("Could not send message to " + portType + " : " + preparedMsg.asXML(), e);
+			EventManager.fireError(new Exception("Could not send message to " + portType + ". Reason:\n"
+					+ (e.getMessage() == null ? "unknown" : e.getMessage()) + "\nMessage:\n" + preparedMsg.asXML()));
+			throw new EngineRuntimeException(e);
+		}
+		log.debug("Received message : " + result.asXML());
+		return result;
+	}
+
+	protected Document syncSend(Activity sender, String partner, String namespace, String portType, String operation,
+			Document message) {
+		return syncSend(sender, partner, portType, operation, message);
+	}
+
+	private static org.dom4j.Document prepareMessage(Document doc, String elmtName, String namespace, String encoding) {
+		org.dom4j.QName qName = null;
+		if ("literal".equals(encoding)) {
+			qName = org.dom4j.QName.get(elmtName, "", namespace);
+		} else {
+			qName = org.dom4j.QName.get(elmtName, "ns1", namespace);
+		}
+		Document resultDoc = DocumentHelper.createDocument();
+		org.dom4j.Element root = DocumentHelper.createElement(qName);
+		resultDoc.add(root);
+		List elmtList = doc.getRootElement().elements();
+		for (int m = 0; m < elmtList.size(); m++) {
+			org.dom4j.Element detachedElmt = (org.dom4j.Element) ((org.dom4j.Element) elmtList.get(m)).detach();
+			detachedElmt.setQName(org.dom4j.QName.get(detachedElmt.getName(), "", namespace));
+			root.add(detachedElmt);
+		}
+		return resultDoc;
+	}
+
+	private static Definition readWSDL(org.w3c.dom.Document wsdlDesc) {
+		WSDLFactory factory = null;
+		try {
+			factory = WSDLFactory.newInstance();
+		} catch (WSDLException e) {
+			throw new InvocationException("Could not find WSDL factory.", e);
+		}
+		WSDLReader reader = factory.newWSDLReader();
+		reader.setFeature("javax.wsdl.verbose", true);
+		reader.setFeature("javax.wsdl.importDocuments", false);
+
+		Definition def = null;
+		try {
+			def = reader.readWSDL(null, wsdlDesc);
+		} catch (WSDLException e) {
+			throw new InvocationException("Could not read a WSDL document.", e);
+		}
+		return def;
+	}
+
+	private static org.w3c.dom.Document getWSDLDesc(String processNS, String processName) {
+		org.w3c.dom.Document document = null;
+		try {
+			document = XMLDataAccess.getDOMDocument("/process/def", "" + (processNS + processName).hashCode());
+		} catch (XMLSessionException e) {
+			throw new InvocationException(e);
+		} catch (FinderException e) {
+			throw new InvocationException(e);
+		}
+		return document;
+	}
+
+	private static String[] getWSDLAdditionalInfo(Definition def, String portTypeName, String operationName) {
+		Map bindings = def.getBindings();
+		Binding portBinding = null;
+		if (bindings != null) {
+			for (Iterator bindingsIter = bindings.keySet().iterator(); bindingsIter.hasNext();) {
+				QName bindingName = (QName) bindingsIter.next();
+				Binding binding = (Binding) bindings.get(bindingName);
+				if (binding == null) {
+					throw new InvocationException("Service " + def.getTargetNamespace() + " with port " + portTypeName
+							+ " doesn't have any " + bindingName + " binding declared.");
+				}
+				if (binding.getPortType().getQName().getLocalPart().equals(portTypeName)) {
+					if (binding.getBindingOperation(operationName, null, null) == null) {
+						throw new InvocationException("Service " + def.getTargetNamespace() + " with port "
+								+ portTypeName + " doesn't have the operation " + operationName
+								+ " declared in the port binding.");
+					}
+					portBinding = binding;
+					break;
+				}
+			}
+		}
+		if (portBinding == null) {
+			throw new InvocationException("Could not find a binding for port " + portTypeName + " in service "
+					+ def.getTargetNamespace());
+		}
+
+		// Extracting operation style (message or rpc)
+		String operationStyle = null;
+		List portBindingExts = portBinding.getExtensibilityElements();
+		for (int m = 0; m < portBindingExts.size(); m++) {
+			ExtensibilityElement extElmt = (ExtensibilityElement) portBindingExts.get(m);
+			if (SOAP_NS.equals(extElmt.getElementType().getNamespaceURI())) {
+				operationStyle = ((SOAPBinding) extElmt).getStyle();
+			}
+		}
+		if (operationStyle == null || (!"rpc".equals(operationStyle) && !"document".equals(operationStyle))) {
+			throw new InvocationException("Could not get the operation style associated with the binding, please "
+					+ "make sure that you have a soap:binding element in your binding "
+					+ "declaration defining a style (rpc/document)");
+		}
+
+		String soapAction = null;
+		BindingOperation bindingOperation = portBinding.getBindingOperation(operationName, null, null);
+		List extensibilityElmts = bindingOperation.getExtensibilityElements();
+		for (int m = 0; m < extensibilityElmts.size(); m++) {
+			ExtensibilityElement extensibilityElement = (ExtensibilityElement) extensibilityElmts.get(m);
+			if (SOAP_NS.equals(extensibilityElement.getElementType().getNamespaceURI())) {
+				soapAction = ((SOAPOperation) extensibilityElement).getSoapActionURI();
+				break;
+			}
+		}
+
+		String msgUrl = null;
+		String encoding = null;
+		List bindingInputExt = bindingOperation.getBindingInput().getExtensibilityElements();
+		for (int m = 0; m < bindingInputExt.size(); m++) {
+			ExtensibilityElement extensibilityElement = (ExtensibilityElement) bindingInputExt.get(m);
+			extensibilityElement.getElementType().getNamespaceURI();
+			if (SOAP_NS.equals(extensibilityElement.getElementType().getNamespaceURI())) {
+				SOAPBody soapBodyExt = (SOAPBody) extensibilityElement;
+
+				msgUrl = soapBodyExt.getNamespaceURI();
+				encoding = soapBodyExt.getUse();
+			}
+
+		}
+
+		if (soapAction == null) {
+			log.info("No SOAPAction could be found for service " + def.getTargetNamespace() + " no SOAPAction element "
+					+ "will be included in the message.");
+		}
+
+		String[] result = new String[4];
+		result[0] = soapAction;
+		result[1] = msgUrl;
+		result[2] = encoding;
+		result[3] = operationStyle;
+
+		return result;
+	}
+
+	private static QName getService(Definition def, String port) {
+		Map services = def.getServices();
+		for (Iterator serviceIter = services.keySet().iterator(); serviceIter.hasNext();) {
+			QName serviceQName = (QName) serviceIter.next();
+			Service service = (Service) services.get(serviceQName);
+			if (service.getPort(port) != null) {
+				return service.getQName();
+			}
+		}
+		throw new InvocationException("No service have been defined for portType " + port);
+	}
+
+	private static Document sendMessage(String nameSpaceURI, QName serviceQName, String portType, String operation,
+			String soapAction, InputStream wsdlDesc, Document sentDoc, String operationStyle) throws ServiceException,
+			RemoteException {
+
+		org.w3c.dom.Document domDoc = getDomDoc(sentDoc);
+
+		Call call = createCall(nameSpaceURI, serviceQName, portType, operation, soapAction, wsdlDesc);
+
+		SOAPBodyElement[] input = setupInput(sentDoc, operationStyle, domDoc);
+
+		Vector results = (Vector) call.invoke(input);
+
+		// TODO (maybe protocol/log it)
+		MessageContext mc = call.getMessageContext();
+		log.info("============= Response ==============");
+		try {
+			XMLUtils.PrettyElementToStream(mc.getResponseMessage().getSOAPEnvelope().getAsDOM(), System.out);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+		org.w3c.dom.Document result = null;
+		try {
+			result = ((SOAPBodyElement) results.get(0)).getAsDocument();
+		} catch (Exception e) {
+			throw new ServiceException(e);
+		}
+		return getDOMReader().read(result);
+	}
+
+	private static org.w3c.dom.Document getDomDoc(Document sentDoc) throws ServiceException {
+		org.w3c.dom.Document domDoc = null;
+		try {
+			domDoc = getDOMWriter().write(sentDoc);
+		} catch (DocumentException e) {
+			throw new ServiceException(e);
+		}
+		return domDoc;
+	}
+
+	private static Call createCall(String nameSpaceURI, QName serviceQName, String portType, String operation,
+			String soapAction, InputStream wsdlDesc) throws ServiceException {
+		org.apache.axis.client.Service service = new org.apache.axis.client.Service(wsdlDesc, serviceQName);
+		QName portQName = new QName(nameSpaceURI, portType);
+		Call call = (Call) service.createCall(portQName, operation);
+		call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
+		if (soapAction != null && soapAction.trim().length() > 0) {
+			call.setProperty(Call.SOAPACTION_URI_PROPERTY, soapAction);
+		}
+		return call;
+	}
+
+	private static SOAPBodyElement[] setupInput(Document sentDoc, String operationStyle, org.w3c.dom.Document domDoc) {
+		SOAPBodyElement[] input;
+		if ("rpc".equals(operationStyle)) {
+			input = new SOAPBodyElement[1];
+			input[0] = new SOAPBodyElement(domDoc.getDocumentElement());
+		} else {
+			input = new SOAPBodyElement[sentDoc.getRootElement().elements().size()];
+			NodeList nodeList = domDoc.getDocumentElement().getChildNodes();
+			int elmtCount = 0;
+			for (int m = 0; m < nodeList.getLength(); m++) {
+				if (nodeList.item(m).getNodeType() == Node.ELEMENT_NODE) {
+					input[elmtCount] = new SOAPBodyElement((Element) nodeList.item(m));
+				}
+			}
+		}
+		return input;
+	}
+
+	private void sendMessageAsync(String nameSpaceURI, QName serviceQName, String portType, String operation,
+			String soapAction, InputStream wsdlDesc, Document sentDoc, String operationStyle, PartnerLink partnerLink)
+			throws ServiceException, RemoteException {
+
+		org.w3c.dom.Document domDoc = null;
+		try {
+			domDoc = getDOMWriter().write(sentDoc);
+		} catch (DocumentException e) {
+			throw new ServiceException(e);
+		}
+
+		Call call = createCall(nameSpaceURI, serviceQName, portType, operation, soapAction, wsdlDesc);
+
+		AxisServer.getCurrentMessageContext();
+
+		SOAPBodyElement[] input = setupInput(sentDoc, operationStyle, domDoc);
+
+		PartnerLinkRole role = partnerLink.getMyRole();
+		if (role != null) {
+
+			AddressingHeaders headers;
+			try {
+				headers = setUpAddressing(partnerLink.getName(), role.getPortType(), "onResult", role.getNamespace());
+				call.setProperty(Constants.ENV_ADDRESSING_REQUEST_HEADERS, headers);
+			} catch (MalformedURIException e1) {
+				log.error("Could not send message to " + portType + " : " + sentDoc.asXML(), e1);
+				EventManager.fireError(new Exception("Could not send message to " + portType + ". Reason:\n"
+						+ (e1.getMessage() == null ? "unknown" : e1.getMessage()) + "\nMessage:\n" + sentDoc.asXML()));
+				throw new EngineRuntimeException(e1);
+
+			}
+
+		}
+
+		call.invokeOneWay(input);
+
+	}
+
+	private static DOMReader getDOMReader() {
+		if (domReader == null) {
+			domReader = new DOMReader();
+		}
+		return domReader;
+	}
+
+	private static DOMWriter getDOMWriter() {
+		if (domWriter == null) {
+			domWriter = new DOMWriter();
+		}
+		return domWriter;
+	}
+
+	private static AddressingHeaders setUpAddressing(String callbackPartner, String callbackPort,
+			String callbackOperation, String callbackPortNamespace) throws MalformedURIException {
+
+		String replyToURL = DeployerConfiguration.getAxisUrl();
+		if (!replyToURL.endsWith("/")) {
+			replyToURL += "/";
+		}
+		replyToURL += "services/";
+		replyToURL += "AgilaEngine";
+
+		MessageElement partner = createHeaderElement("partner", callbackPartner);
+		MessageElement port = createHeaderElement("port", callbackPort);
+		MessageElement operation = createHeaderElement("operation", callbackOperation);
+		MessageElement namespace = createHeaderElement("namespace", callbackPortNamespace);
+
+		ReferencePropertiesType refType = new ReferencePropertiesType();
+		refType.set_any(new MessageElement[] { partner, port, operation, namespace });
+
+		EndpointReference replyTo = new EndpointReference(replyToURL);
+		replyTo.setProperties(refType);
+
+		AddressingHeaders headers = new AddressingHeaders();
+		headers.setReplyTo(replyTo);
+
+		return headers;
+	}
+
+	private static MessageElement createHeaderElement(String name, String value) {
+		MessageElement element = new MessageElement();
+		element.setNamespaceURI(AGILA_NS);
+		element.setName(name);
+		element.setValue(value);
+		element.setPrefix("agila");
+		return element;
+	}
+
+}

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/impl/PickECAsReceiveEC.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/impl/PickECAsReceiveEC.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/impl/PickECAsReceiveEC.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/java/org/apache/agila/bpel/engine/priv/messaging/impl/PickECAsReceiveEC.java Wed Jan  4 13:19:47 2006
@@ -65,7 +65,11 @@
     public void execute() {
         pickEC.execute();
     }
-
+    
+    public void terminate() {
+    		pickEC.terminate();
+    }
+    
     public AuditEntry audit() throws Exception {
       return pickEC.audit();
     }

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/agila-configuration.xml
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/agila-configuration.xml?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/agila-configuration.xml (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/agila-configuration.xml Wed Jan  4 13:19:47 2006
@@ -9,7 +9,9 @@
         <resource>org.apache.agila.bpel.engine.common.persistence.XMLSessionManager</resource>
     </transaction>
     <event-listeners>
+    <!-- 
         <listener>org.apache.agila.bpel.engine.common.event.DebuggingListener</listener>
+     -->    
     </event-listeners>
     <tools>
         <xindice>

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/hibernate.cfg.xml
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/hibernate.cfg.xml?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/hibernate.cfg.xml (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/hibernate.cfg.xml Wed Jan  4 13:19:47 2006
@@ -45,6 +45,8 @@
         <mapping resource="org/apache/agila/bpel/engine/executionevent.hbm.xml"/>
         <mapping resource="org/apache/agila/bpel/engine/link.hbm.xml"/>
         <mapping resource="org/apache/agila/bpel/engine/messageevent.hbm.xml"/>
+        <mapping resource="org/apache/agila/bpel/engine/partnerlinkrole.hbm.xml"/>
+        <mapping resource="org/apache/agila/bpel/engine/partnerlink.hbm.xml"/>
         <mapping resource="org/apache/agila/bpel/engine/process.hbm.xml"/>
         <mapping resource="org/apache/agila/bpel/engine/processinstance.hbm.xml"/>
         <mapping resource="org/apache/agila/bpel/engine/property.hbm.xml"/>

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/loop-defs.xml
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/loop-defs.xml?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/loop-defs.xml (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/loop-defs.xml Wed Jan  4 13:19:47 2006
@@ -1,8 +1,28 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <definitions targetNamespace="http://www.apache.org/agila/examples/loop/service/" 
 		xmlns:bpel="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
-		xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
+		xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
+		xmlns:test="http://test.test.de"
+		xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/">
+
 	<bpel:property name="counterId" type="xsd:string"/>
 	<bpel:propertyAlias propertyName="counterId" messageType="counterMsg" part="main" query="/counterId"/>
 	<bpel:propertyAlias propertyName="counterId" messageType="otherMsg" part="main" query="/counterId"/>
+
+	<plnk:partnerLinkType name="loopPartnerLinkType">
+		<plnk:role name="loopService">
+			<plnk:portType name="test:loopPortType" />
+		</plnk:role>
+	</plnk:partnerLinkType>
+
+
+	<plnk:partnerLinkType name="snoopPartnerLinkType">
+		<plnk:role name="snoopService">
+			<plnk:portType name="snoopPortType" />
+		</plnk:role>
+		<plnk:role name="snoopServicePartner">
+			<plnk:portType name="snoopCallbackPortType" />
+		</plnk:role> 
+	</plnk:partnerLinkType>	
+	
 </definitions>

Modified: incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/loop.xml
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/loop.xml?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/loop.xml (original)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/loop.xml Wed Jan  4 13:19:47 2006
@@ -11,9 +11,11 @@
 		<correlationSet name="counterCorrel" properties="def:counterId"/>
 	</correlationSets>
 	<partnerLinks>
-        	<partnerLink name="loopPartner" partnerLinkType="lns:loopPartnerLinkType" myRole="loopService"/>
-	</partnerLinks>
+        	<partnerLink name="loopPartner" partnerLinkType="def:loopPartnerLinkType" myRole="loopService"/>
 
+        	<partnerLink name="snoopPartner" partnerLinkType="def:snoopPartnerLinkType" myRole="snoopService" partnerRole="snoopServicePartner"/>
+	</partnerLinks>
+	
 	<sequence>
 		<receive partnerLink="loopPartner" portType="loopPort" operation="loopOp" variable="loopVar" createInstance="yes">
 			<correlations>

Added: incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-terminate-defs.xml
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-terminate-defs.xml?rev=365997&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-terminate-defs.xml (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-terminate-defs.xml Wed Jan  4 13:19:47 2006
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<definitions targetNamespace="http://www.apache.org/agila/test/terminate/service/"
+    xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
+
+</definitions>

Added: incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-terminate-msg.xml
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-terminate-msg.xml?rev=365997&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-terminate-msg.xml (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-terminate-msg.xml Wed Jan  4 13:19:47 2006
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<agila-msg xmlns="http://www.apache.org/agila/types/message">
+    <partner>admin</partner>
+    <port>requestDocPT</port>
+    <operation>requestDoc</operation>
+    <message>
+        <amount>5000</amount>
+    </message>
+</agila-msg> 

Added: incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-terminate.xml
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-terminate.xml?rev=365997&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-terminate.xml (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-terminate.xml Wed Jan  4 13:19:47 2006
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+
+<process name="test-wait"
+    targetNamespace="http://www.apache.org/agila/test/terminate/process/"
+    xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
+    xmlns:wsdl="http://www.apache.org/agila/test/terminate/service/"
+    abstractProcess="no">
+
+<partnerLinks> 
+	<partnerLink name="admin" partnerLinkType="wsdl:requestDocPLT" myRole="docApprovalService"/> 
+</partnerLinks> 
+
+<variables> 
+	<variable name="someVar" messageType="wsdl:someVarType"/> 
+</variables>
+ 
+<sequence> 
+	<receive partnerLink="admin" portType="requestDocPT" operation="requestDoc" variable="someVar" createInstance="yes"/> 
+ 
+	<terminate/> 
+
+</sequence> 
+</process> 

Added: incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-wait-defs.xml
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-wait-defs.xml?rev=365997&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-wait-defs.xml (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-wait-defs.xml Wed Jan  4 13:19:47 2006
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<definitions targetNamespace="http://www.apache.org/agila/test/wait/service/"
+    xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
+
+</definitions>

Added: incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-wait-msg.xml
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-wait-msg.xml?rev=365997&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-wait-msg.xml (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-wait-msg.xml Wed Jan  4 13:19:47 2006
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<agila-msg xmlns="http://www.apache.org/agila/types/message">
+    <partner>admin</partner>
+    <port>requestDocPT</port>
+    <operation>requestDoc</operation>
+    <message>
+        <amount>5000</amount>
+    </message>
+</agila-msg> 

Added: incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-wait.xml
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-wait.xml?rev=365997&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-wait.xml (added)
+++ incubator/agila/trunk/modules/bpel/engine/core/src/test/resources/test-wait.xml Wed Jan  4 13:19:47 2006
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+
+<process name="test-wait"
+    targetNamespace="http://www.apache.org/agila/test/wait/process/"
+    xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
+    xmlns:wsdl="http://www.apache.org/agila/test/wait/service/"
+    abstractProcess="no">
+
+<partnerLinks> 
+	<partnerLink name="admin" partnerLinkType="wsdl:requestDocPLT" myRole="docApprovalService"/> 
+</partnerLinks> 
+
+<variables> 
+	<variable name="someVar" messageType="wsdl:someVarType"/> 
+</variables>
+ 
+<sequence> 
+	<receive partnerLink="admin" portType="requestDocPT" operation="requestDoc" variable="someVar" createInstance="yes"/> 
+ 
+	<wait until="2005-05-14T23:45:00+02:00"/> 
+
+	<invoke partnerLink="admin" portType="somePort" operation="someOp" inputVariable="someVar"/>
+	
+	<pick> 
+		<onMessage partnerLink="admin" portType="requestDocPT" operation="requestDoc" variable="someVar">
+			<invoke partnerLink="admin" portType="somePort" operation="someOp" inputVariable="someVar"/>
+		</onMessage>
+		<onAlarm until="2005-05-14T23:45:30+02:00"> 
+			<invoke partnerLink="admin" portType="somePort" operation="someOp" inputVariable="someVar"/>
+		</onAlarm> 
+	</pick>
+ 
+</sequence> 
+</process> 

Modified: incubator/agila/trunk/modules/bpel/engine/deployer/src/java/org/apache/agila/bpel/deployer/priv/AgilaDeployerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpel/engine/deployer/src/java/org/apache/agila/bpel/deployer/priv/AgilaDeployerImpl.java?rev=365997&r1=365996&r2=365997&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpel/engine/deployer/src/java/org/apache/agila/bpel/deployer/priv/AgilaDeployerImpl.java (original)
+++ incubator/agila/trunk/modules/bpel/engine/deployer/src/java/org/apache/agila/bpel/deployer/priv/AgilaDeployerImpl.java Wed Jan  4 13:19:47 2006
@@ -23,7 +23,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
-import java.util.ArrayList;
 
 import org.apache.axis.client.AdminClient;
 import org.apache.axis.utils.Options;
@@ -49,11 +48,13 @@
 import org.apache.agila.bpel.engine.common.persistence.XMLDataAccess;
 import org.apache.agila.bpel.engine.common.transaction.TransactionException;
 import org.apache.agila.bpel.engine.common.transaction.TransactionManager;
+import org.apache.agila.bpel.engine.priv.core.definition.PartnerLinkRole;
 import org.apache.agila.bpel.engine.priv.core.definition.ProcessFactory;
 import org.apache.agila.bpel.engine.priv.core.definition.Property;
 import org.apache.agila.bpel.engine.priv.core.definition.AgilaProcess;
 import org.apache.agila.bpel.engine.priv.AgilaEngineAdminImpl;
 
+
 import org.xmldb.api.base.Collection;
 
 /**
@@ -113,7 +114,7 @@
  */
 public class AgilaDeployerImpl implements AgilaDeployer {
 
-    public static final String NS_SEPARATOR = ":";
+
     public static final String SPACE = " ";
     public static final String XMLNS = "xmlns";
     public static final String DEFINITIONS = "definitions";
@@ -121,6 +122,7 @@
     private Logger log = Logger.getLogger(AgilaDeployerImpl.class);
     private static final String TILD = "~";
     private static final String BPEL_NS = "http://schemas.xmlsoap.org/ws/2003/03/business-process/";
+    private static final String PLNK_NS = "http://schemas.xmlsoap.org/ws/2003/05/partner-link/";
 
     private WSDLValidator wsdlValidator = null;
     private BPELValidator bpelValidator = null;
@@ -362,8 +364,7 @@
             deployDefinitions(defDoc, tp);
             deployVariables(processElement.element("variables"), tp);
             deployCorrelationSets(processElement.element("correlationSets"), tp);
-
-            // todo implements 'partnerLinks' elements
+            deployPartnerLinks(processElement.element("partnerLinks"), defDoc, tp);
             // todo implements 'partners' elements
             // todo implements 'faultHandlers' elements
             // todo implements 'compensationHandlers' elements
@@ -390,7 +391,9 @@
         }
     }
 
-    private void saveProcess(Document processDoc, Document defDoc, String processName) throws DeploymentException {
+
+
+	private void saveProcess(Document processDoc, Document defDoc, String processName) throws DeploymentException {
         try {
             Collection processColl = XMLDataAccess.getCollection("/process");
             Collection processDefColl = XMLDataAccess.getCollection("/process/def");
@@ -615,12 +618,159 @@
             }
         }
     }
+    
+    /**
+     * Deployment of the PartnerLink element
+     * <p/>
+	 * <partnerLink name="ncname" partnerLinkType="qname"
+	 * myRole="ncname"? partnerRole="ncname"?>+
+	 * </partnerLink>
+     * 
+     * @param element the partnerLinks DOM element.
+     * @param wsdlDoc the WSDL Document
+     * @param tp      the parent process
+     * @throws DeploymentException 
+     */
+    private void deployPartnerLinks(Element element, Document wsdlDoc, AgilaProcess tp) throws DeploymentException{
+    		try{
+    		if(element != null)
+    		{
+    			for (Iterator partnerLinkIter = element.elementIterator("partnerLink"); partnerLinkIter.hasNext();) {
+				Element partnerLinkElement = (Element) partnerLinkIter.next();
+				String name = partnerLinkElement.valueOf("@name");
+				String partnerLinkType = partnerLinkElement.valueOf("@partnerLinkType");
+				String myRole = partnerLinkElement.valueOf("@myRole");
+				String partnerRole = partnerLinkElement.valueOf("@partnerRole");
+
+				// plnkType namespace from bpel file
+				String partnerLinkTypeNS = NSUtil.findAsQname(partnerLinkType,partnerLinkElement).getNamespaceURI();
+				
+				partnerLinkType = NSUtil.extractElementName(partnerLinkType);
+                HashMap nsMap = new HashMap(1);
+                nsMap.put("plnk", PLNK_NS);
+
+                PartnerLinkRole myRoleObj = null;
+                PartnerLinkRole partnerRoleObj = null;
+                Namespace plnk = new Namespace("plnk",PLNK_NS);
+                Iterator plnkTypeIterator = wsdlDoc.getRootElement().elementIterator(new QName("partnerLinkType",plnk));
+                Element partnerLinkTypeElement = null;
+                for (Iterator iter = plnkTypeIterator; iter.hasNext();) {
+					Element plnkType = (Element) iter.next();
+					if(plnkType.valueOf("@name").equals(partnerLinkType))
+					{
+						// TODO: s.h. test namespace of name attribute to match with bpel file
+						partnerLinkTypeElement = plnkType;
+						break;
+					}
+					
+				}
+
+                if(partnerLinkElement != null)
+                {
+                    QName myRoleQname = null;
+
+                    if(myRole != null && !"".equalsIgnoreCase(myRole))
+                    {
+                    		Element myRolePortTypeElement = null;
+                    		for (Iterator iter = partnerLinkTypeElement.elementIterator(new QName("role",plnk)); iter.hasNext();) {
+                    			Element role = (Element) iter.next();
+                    			if(role.valueOf("@name").equals(myRole))
+                    			{
+                    				myRolePortTypeElement = role.element(new QName("portType",plnk));
+                    				String myRolePortType = myRolePortTypeElement.valueOf("@name");
+                    				myRoleQname = NSUtil.findAsQname(myRolePortType,myRolePortTypeElement); 
+                    				break;
+                    			}
+                    		}
+                    	   myRoleObj = ProcessFactory.addPartnerLinkRole(myRole,myRoleQname.getName(),myRoleQname.getNamespaceURI());
+                    }
+                    
+                    if(partnerRole != null && !"".equalsIgnoreCase(partnerRole))
+                    {
+                        QName pRoleQname = null;
+                        
+                    		Element partnerRolePortTypeElement = null;
+                    		for (Iterator iter = partnerLinkTypeElement.elementIterator(new QName("role",plnk)); iter.hasNext();) {
+                    			Element role = (Element) iter.next();
+                    			if(role.valueOf("@name").equals(partnerRole))
+                    			{
+                    				partnerRolePortTypeElement = role.element(new QName("portType",plnk));
+                    				String partnerRolePortType = partnerRolePortTypeElement.valueOf("@name");
+                    				pRoleQname = NSUtil.findAsQname(partnerRolePortType,partnerRolePortTypeElement);
+                    				break;
+                    			}
+    							
+                    		}
+                    	   partnerRoleObj = ProcessFactory.addPartnerLinkRole(partnerRole,pRoleQname.getName(),pRoleQname.getNamespaceURI());
+                    }
+
+                	
+                }else
+                {
+                		throw new DeploymentException("partnerLinkType element not found in WSDL. Definition in BPEL: " + partnerLinkTypeNS + ":" + partnerLinkType);
+                }
+                
+                ProcessFactory.addPartnerLink(tp,name,partnerLinkType,myRoleObj,partnerRoleObj);
+
+                
+
+    			}
+    		}
+    			}catch(Exception e)
+    			{
+    				throw new DeploymentException(e);
+    			}
+    		}
+ 
+//    	
+//    	
+//    		Element rootElement = wsdlDoc.element("correlationSets").getRootElement();
+//        Iterator propertyAlias = rootElement.elementIterator("propertyAlias");
+//        Map addedProperty = new HashMap();
+//        try {
+//            while (propertyAlias.hasNext()) {
+//                Element e = (Element) propertyAlias.next();
+//                String propertyName = e.valueOf("@propertyName");
+//
+//                XPath xpathSelector = DocumentHelper.createXPath("//*/defaultNS:property[@name=\"" + propertyName + "\"]");
+//                HashMap nsMap = new HashMap(1);
+//                nsMap.put("defaultNS", BPEL_NS);
+//                xpathSelector.setNamespaceURIs(nsMap);
+//                Node propNode = xpathSelector.selectSingleNode(doc);
+//
+//                Property prop = (Property) addedProperty.get(propertyName);
+//                if (propNode != null && prop == null) {
+//                    prop = ProcessFactory.addProperty(tp,
+//                            propertyName, propNode.valueOf("@type"));
+//                    addedProperty.put(propertyName, prop);
+//                }
+//                if (prop != null) {
+//                    ProcessFactory.addPropertyAlias(prop, e.valueOf("@messageType"),
+//                            e.valueOf("@part"), e.valueOf("@query"));
+//                } else {
+//                    log.error("A propertyAlias is defined without property : " + propertyName);
+//                    throw new DeploymentException("a propertyAlias is defined without property : " + propertyName);
+//                }
+//            }
+//            Iterator properties = rootElement.elementIterator("property");
+//            while (properties.hasNext()) {
+//                Element e = (Element) properties.next();
+//                String name = e.valueOf("@name");
+//                if (addedProperty.containsKey(name) == false) {
+//                    ProcessFactory.addProperty(tp, name, e.valueOf("@type"));
+//                }
+//            }
+//        } catch (Exception e) {
+//            throw new DeploymentException(e);
+//        }
+		
+	
 
     private String truncNamespace(String nsProps) {
         StringBuffer properties = new StringBuffer();
         for (StringTokenizer nsTokenizer = new StringTokenizer(nsProps); nsTokenizer.hasMoreTokens();) {
             String nsProp = nsTokenizer.nextToken();
-            int index = nsProp.lastIndexOf(NS_SEPARATOR);
+            int index = nsProp.lastIndexOf(NSUtil.NS_SEPARATOR);
             properties.append(nsProp.substring(index + 1));
             if (nsTokenizer.hasMoreTokens()) {
                 properties.append(SPACE);



Mime
View raw message