You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mr...@apache.org on 2008/09/10 21:07:05 UTC

svn commit: r693931 [6/12] - in /ode/trunk: bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/ bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/ bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/ runtimes/...

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/CompensationHandler.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/CompensationHandler.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/CompensationHandler.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/CompensationHandler.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.rtrep.v1;
+
+import org.apache.ode.bpel.rtrep.v1.channels.CompensationChannel;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Set;
+
+
+/**
+ * A handle to a compensation handler.
+ */
+public class CompensationHandler implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /** The scope to which this compensation handler belongs. */
+    final ScopeFrame compensated;
+
+    /** Compensation activation channel. */
+    final CompensationChannel compChannel;
+
+    /** Time that the scope was started. */
+    final long scopeStartTime;
+
+    /** Time that the scope was completed. */
+    final long scopeEndTime;
+
+    CompensationHandler(ScopeFrame compensated, CompensationChannel compChannel, long scopeStartTime, long scopeEndTime) {
+        assert compChannel != null;
+
+        this.compensated = compensated;
+        this.compChannel = compChannel;
+        this.scopeEndTime = scopeEndTime;
+        this.scopeStartTime = scopeStartTime;
+    }
+
+    public String toString() {
+        StringBuffer buf = new StringBuffer("{CompensationHandler ch=");
+        buf.append(compChannel);
+        buf.append(", scope=");
+        buf.append(compensated);
+        buf.append("}");
+        return buf.toString();
+    }
+
+    static Set<CompensationHandler> emptySet() {
+        return Collections.emptySet();
+    }
+
+}

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/CorrelationSetInstance.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/CorrelationSetInstance.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/CorrelationSetInstance.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/CorrelationSetInstance.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.rtrep.v1;
+
+import org.apache.ode.bpel.rtrep.v1.OScope;
+import org.apache.ode.bpel.rapi.CorrelationSet;
+
+public class CorrelationSetInstance implements CorrelationSet {
+    public OScope.CorrelationSet declaration;
+    public Long scopeInstance;
+
+    public CorrelationSetInstance(Long scopeInstanceId, OScope.CorrelationSet cset) {
+        this.scopeInstance = scopeInstanceId;
+        this.declaration = cset;
+    }
+
+    public String getName() {
+        return declaration.name;
+    }
+
+    public long getScopeId() {
+        return scopeInstance;
+    }
+}

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/DebugInfo.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/DebugInfo.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/DebugInfo.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/DebugInfo.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.rtrep.v1;
+
+import javax.xml.namespace.QName;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Information about the source that was used to create a compiled object.
+ */
+public class DebugInfo implements Serializable {
+    static final long serialVersionUID = -1L  ;
+
+    /** Source file / resource name. */
+    public final String sourceURI;
+
+    /** Source line number (start). */
+    public final int startLine;
+
+    /** Source line number (end). */
+    public final int endLine;
+
+    public String description;
+
+    public HashMap<QName, Object> extensibilityElements = new HashMap<QName, Object>();
+
+    public DebugInfo(String sourceURI, int startLine, int endLine, Map<QName, Object> extElmt) {
+        this.sourceURI = sourceURI;
+        this.startLine = startLine;
+        this.endLine = endLine;
+        if (extElmt != null && extElmt.size() > 0) {
+            this.extensibilityElements = new HashMap<QName, Object>(extElmt);
+        }
+    }
+
+    public DebugInfo(String sourceURI, int line, Map<QName, Object> extElmt) {
+        this(sourceURI, line, line, extElmt);
+    }
+
+}

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EH_ALARM.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EH_ALARM.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EH_ALARM.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EH_ALARM.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,245 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.rtrep.v1;
+
+import org.apache.ode.bpel.common.FaultException;
+import org.apache.ode.bpel.rtrep.v1.channels.EventHandlerControlChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.EventHandlerControlChannelListener;
+import org.apache.ode.bpel.rtrep.v1.channels.FaultData;
+import org.apache.ode.bpel.rtrep.v1.channels.ParentScopeChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.ParentScopeChannelListener;
+import org.apache.ode.bpel.rtrep.v1.channels.TerminationChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.TerminationChannelListener;
+import org.apache.ode.bpel.rtrep.v1.channels.TimerResponseChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.TimerResponseChannelListener;
+import org.apache.ode.jacob.SynchChannel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Calendar;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Date;
+
+import org.w3c.dom.Element;
+
+/**
+ * Alarm event handler. This process template manages a single alarm event handler.
+ * It acts like an activity in that it can be terminated, but also adds a channel for
+ * "soft" termination (aka stopping) to deal with the case when the scope that owns
+ * the event handler completes naturally.
+ */
+class EH_ALARM extends BpelJacobRunnable {
+
+    private static final Log __log = LogFactory.getLog(EH_ALARM.class);
+
+    private static final long serialVersionUID = 1L;
+
+    private ParentScopeChannel _psc;
+    private TerminationChannel _tc;
+    private OEventHandler.OAlarm _oalarm;
+    private ScopeFrame _scopeFrame;
+    private EventHandlerControlChannel _cc;
+    private Set<CompensationHandler> _comps = new HashSet<CompensationHandler>();
+
+    /**
+     * Concretion constructor.
+     * @param psc a link to our parent.
+     * @param tc channel we listen on for termination requests
+     * @param cc channel we listen on for "stop" requests
+     * @param o our prototype / compiled representation
+     * @param scopeFrame the {@link ScopeFrame} in which we are executing
+     */
+    EH_ALARM(ParentScopeChannel psc, TerminationChannel tc, EventHandlerControlChannel cc, OEventHandler.OAlarm o, ScopeFrame scopeFrame) {
+        _psc = psc;
+        _tc = tc;
+        _cc = cc;
+        _scopeFrame = scopeFrame;
+        _oalarm  = o;
+    }
+
+    public void run() {
+
+        Calendar alarm = Calendar.getInstance();
+
+        if (_oalarm.forExpr != null)
+            try {
+                getBpelRuntime().getExpLangRuntime().evaluateAsDuration(_oalarm.forExpr, getEvaluationContext()).addTo(alarm);
+            } catch (FaultException e) {
+                __log.error(e);
+                _psc.completed(createFault(e.getQName(),_oalarm.forExpr), _comps);
+                return;
+            }
+        else if (_oalarm.untilExpr != null)
+            try {
+                alarm.setTime(getBpelRuntime().getExpLangRuntime().evaluateAsDate(_oalarm.untilExpr, getEvaluationContext()).getTime());
+            } catch (FaultException e) {
+                __log.error(e);
+                _psc.completed(createFault(e.getQName(),_oalarm.untilExpr), _comps);
+                return;
+            }
+
+        // We reduce to waiting for the alarm to be triggered.
+        instance(new WAIT(alarm));
+    }
+
+    protected EvaluationContext getEvaluationContext() {
+        return new ExprEvaluationContextImpl(_scopeFrame,getBpelRuntime());
+    }
+
+    /**
+     * Template used to wait until a given time, reduing to a {@link FIRE} after the
+     * elapsed time. This template also monitors the termination and event-control channels
+     * for requests from parent.
+     */
+    private class WAIT extends BpelJacobRunnable {
+        private static final long serialVersionUID = -1426724996925898213L;
+        Calendar _alarm;
+
+        /**
+         * Concretion constructor.
+         * @param alarm date at which time to fire
+         */
+        WAIT(Calendar alarm) {
+            _alarm = alarm;
+        }
+
+        public void run() {
+            Calendar now = Calendar.getInstance();
+
+            if (now.before(_alarm)) {
+                TimerResponseChannel trc = newChannel(TimerResponseChannel.class);
+                getBpelRuntime().registerTimer(trc,_alarm.getTime());
+                object(false,new TimerResponseChannelListener(trc){
+                    private static final long serialVersionUID = 1110683632756756017L;
+
+                    public void onTimeout() {
+                        // This is what we are waiting for, fire the activity
+                        instance(new FIRE());
+                    }
+
+                    public void onCancel() {
+                        _psc.completed(null, _comps);
+                    }
+                }.or(new EventHandlerControlChannelListener(_cc) {
+                    private static final long serialVersionUID = -7750428941445331236L;
+
+                    public void stop() {
+                        _psc.completed(null, _comps);
+                    }
+
+                }.or(new TerminationChannelListener(_tc) {
+                    private static final long serialVersionUID = 6100105997983514609L;
+
+                    public void terminate() {
+                        _psc.completed(null, _comps);
+                    }
+                })));
+            } else /* now is later then alarm time */ {
+                // If the alarm has passed we fire the nested activity
+                ActivityInfo child = new ActivityInfo(genMonotonic(),
+                        _oalarm.activity,
+                        newChannel(TerminationChannel.class), newChannel(ParentScopeChannel.class));
+                instance(createChild(child, _scopeFrame, new LinkFrame(null) ));
+                instance(new ACTIVE(child));
+            }
+
+        }
+    }
+
+    /**
+     * Snipped that fires the alarm activity.
+     */
+    private class FIRE extends BpelJacobRunnable {
+        private static final long serialVersionUID = -7261315204412433250L;
+
+        public void run() {
+            // Start the child activity.
+            ActivityInfo child = new ActivityInfo(genMonotonic(),
+                    _oalarm.activity,
+                    newChannel(TerminationChannel.class), newChannel(ParentScopeChannel.class));
+            instance(createChild(child, _scopeFrame, new LinkFrame(null) ));
+            instance(new ACTIVE(child));
+        }
+    }
+
+    /**
+     * Snippet that is used to monitor a running activity.
+     */
+    private class ACTIVE extends BpelJacobRunnable {
+        private static final long serialVersionUID = -2166253425722769701L;
+
+        private ActivityInfo _activity;
+
+        /** Indicates whether our parent has requested a stop. */
+        private boolean _stopped = false;
+
+        ACTIVE(ActivityInfo activity) {
+            _activity = activity;
+        }
+
+        public void run() {
+            object(false,new ParentScopeChannelListener(_activity.parent){
+                private static final long serialVersionUID = -3357030137175178040L;
+
+                public void compensate(OScope scope, SynchChannel ret) {
+                    _psc.compensate(scope,ret);
+                    instance(ACTIVE.this);
+                }
+
+                public void completed(FaultData faultData, Set<CompensationHandler> compensations) {
+                    _comps.addAll(compensations);
+                    if (!_stopped && _oalarm.repeatExpr != null) {
+                        Calendar next = Calendar.getInstance();
+                        try {
+                            getBpelRuntime().getExpLangRuntime().evaluateAsDuration(_oalarm.forExpr, getEvaluationContext()).addTo(next);
+                        } catch (FaultException e) {
+                            __log.error(e);
+                            _psc.completed(createFault(e.getQName(),_oalarm.forExpr), _comps);
+                            return;
+                        }
+                        instance(new WAIT(next));
+                    } else {
+                        _psc.completed(faultData, _comps);
+                    }
+                }
+
+                public void cancelled() { completed(null, CompensationHandler.emptySet()); }
+                public void failure(String reason, Element data) { completed(null, CompensationHandler.emptySet()); }
+            }.or(new EventHandlerControlChannelListener(_cc) {
+                private static final long serialVersionUID = -3873619538789039424L;
+
+                public void stop() {
+                    _stopped = true;
+                    instance(ACTIVE.this);
+                }
+
+            }.or(new TerminationChannelListener(_tc) {
+                private static final long serialVersionUID = -4566956567870652885L;
+
+                public void terminate() {
+                    replication(_activity.self).terminate();
+                    _stopped = true;
+                    instance(ACTIVE.this);
+                }
+            })));
+
+        }
+    }
+}

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EH_EVENT.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EH_EVENT.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EH_EVENT.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EH_EVENT.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,327 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.rtrep.v1;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.common.CorrelationKey;
+import org.apache.ode.bpel.common.FaultException;
+import org.apache.ode.bpel.rtrep.v1.channels.EventHandlerControlChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.EventHandlerControlChannelListener;
+import org.apache.ode.bpel.rtrep.v1.channels.FaultData;
+import org.apache.ode.bpel.rtrep.v1.channels.ParentScopeChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.ParentScopeChannelListener;
+import org.apache.ode.bpel.rtrep.v1.channels.PickResponseChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.PickResponseChannelListener;
+import org.apache.ode.bpel.rtrep.v1.channels.TerminationChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.TerminationChannelListener;
+import org.apache.ode.bpel.evt.VariableModificationEvent;
+import org.apache.ode.bpel.rapi.InvalidProcessException;
+import org.apache.ode.jacob.ChannelListener;
+import org.apache.ode.jacob.SynchChannel;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Message event handler.
+ */
+class EH_EVENT extends BpelJacobRunnable {
+
+    private static final long serialVersionUID = 1L;
+
+    private static final Log __log = LogFactory.getLog(EH_EVENT.class);
+
+    private EventHandlerControlChannel _ehc;
+    private TerminationChannel _tc;
+    private ParentScopeChannel _psc;
+    private ScopeFrame _scopeFrame;
+    private OEventHandler.OEvent _oevent;
+
+    /** Registered compensation handlers. */
+    private Set<CompensationHandler> _comps = new HashSet<CompensationHandler>();
+
+    private FaultData _fault;
+
+    /** Active instances (we can have more than one!) */
+    private Set<ActivityInfo> _active = new HashSet<ActivityInfo>();
+
+    /** Whether a stop has been requested; if so no more new instances. */
+    private boolean _stopped;
+
+    /** Has a termination of this handler been requested. */
+    private boolean _terminated;
+
+    private boolean _childrenTerminated;
+
+
+    EH_EVENT(ParentScopeChannel psc,TerminationChannel tc, EventHandlerControlChannel ehc, OEventHandler.OEvent o, ScopeFrame scopeFrame) {
+        _scopeFrame = scopeFrame;
+        _oevent = o;
+        _tc = tc;
+        _psc = psc;
+        _ehc = ehc;
+    }
+
+
+    public void run() {
+        instance(new SELECT());
+    }
+
+    /**
+     * Terminate all the active activities.
+     */
+    private void terminateActive() {
+        if (!_childrenTerminated) {
+            for (ActivityInfo tact : _active) {
+                replication(tact.self).terminate();
+            }
+            _childrenTerminated = true;
+        }
+    }
+    /**
+     * Template that does the actual selection interaction with the runtime system, and
+     * then waits on the pick response channel.
+     */
+    class SELECT extends BpelJacobRunnable {
+
+        private static final long serialVersionUID = 1L;
+
+        /**
+         * @see org.apache.ode.jacob.JacobRunnable#run()
+         */
+        public void run() {
+            Selector selector;
+            try {
+                PickResponseChannel pickResponseChannel = newChannel(PickResponseChannel.class);
+                CorrelationKey key;
+                PartnerLinkInstance pLinkInstance = _scopeFrame.resolve(_oevent.partnerLink);
+                if (_oevent.matchCorrelation == null) {
+                    // Adding a route for opaque correlation. In this case correlation is done on "out-of-band" session id.
+                    String sessionId = getBpelRuntime().fetchMySessionId(pLinkInstance);
+                    key = new CorrelationKey(-1, new String[] {sessionId});
+                } else {
+                    if (!getBpelRuntime().isCorrelationInitialized(_scopeFrame.resolve(_oevent.matchCorrelation))) {
+                        throw new FaultException(_oevent.getOwner().constants.qnCorrelationViolation,"Correlation not initialized.");
+                    }
+                    key = getBpelRuntime().readCorrelation(_scopeFrame.resolve(_oevent.matchCorrelation));
+                    assert key != null;
+                }
+
+                selector =  new Selector(0,pLinkInstance,_oevent.operation.getName(), _oevent.operation.getOutput() == null, _oevent.messageExchangeId, key);
+                getBpelRuntime().select(pickResponseChannel, null, false, new Selector[] { selector} );
+                instance(new WAITING(pickResponseChannel));
+            } catch(FaultException e){
+                __log.error(e);
+                if (_fault == null) {
+                    _fault = createFault(e.getQName(), _oevent);
+                }
+                terminateActive();
+                instance(new WAITING(null));
+            }
+        }
+    }
+
+    /**
+     * Template that represents the waiting for a pick response.
+     */
+    private class WAITING extends BpelJacobRunnable {
+        private static final long serialVersionUID = 1L;
+        private PickResponseChannel _pickResponseChannel;
+
+        private WAITING(PickResponseChannel pickResponseChannel) {
+            _pickResponseChannel = pickResponseChannel;
+        }
+
+        public void run() {
+
+            if (!_active.isEmpty() || _pickResponseChannel != null) {
+                HashSet<ChannelListener> mlset = new HashSet<ChannelListener>();
+
+                if (!_terminated) {
+                    mlset.add(new TerminationChannelListener(_tc) {
+                        private static final long serialVersionUID = 7666910462948788042L;
+
+                        public void terminate() {
+                            terminateActive();
+                            _terminated = true;
+                            if (_pickResponseChannel != null)
+                                getBpelRuntime().cancel(_pickResponseChannel);
+                            instance(WAITING.this);
+                        }
+                    });
+
+                }
+
+                if (!_stopped) {
+                    mlset.add(new EventHandlerControlChannelListener(_ehc) {
+                        private static final long serialVersionUID = -1050788954724647970L;
+
+                        public void stop() {
+                            _stopped = true;
+                            if (_pickResponseChannel != null)
+                                getBpelRuntime().cancel(_pickResponseChannel);
+                            instance(WAITING.this);
+                        }
+                    });
+
+                }
+
+                for (final ActivityInfo ai : _active) {
+                    mlset.add(new ParentScopeChannelListener(ai.parent) {
+                        private static final long serialVersionUID = 5341207762415360982L;
+
+                        public void compensate(OScope scope, SynchChannel ret) {
+                            _psc.compensate(scope, ret);
+                            instance(WAITING.this);
+                        }
+
+                        public void completed(FaultData faultData, Set<CompensationHandler> compensations) {
+                            _active.remove(ai);
+                            _comps.addAll(compensations);
+                            if (faultData != null && _fault == null) {
+                                _fault = faultData;
+                                terminateActive();
+                                _psc.completed(_fault, _comps);
+                            } else
+                                instance(WAITING.this);
+                        }
+
+                        public void cancelled() { completed(null, CompensationHandler.emptySet()); }
+                        public void failure(String reason, Element data) { completed(null, CompensationHandler.emptySet()); }
+                    });
+                }
+
+                if (_pickResponseChannel != null)
+                    mlset.add(new PickResponseChannelListener(_pickResponseChannel) {
+                        private static final long serialVersionUID = -4929999153478677288L;
+
+
+                        public void onRequestRcvd(int selectorIdx, String mexId) {
+                            // The receipt of the message causes a new scope to be created:
+                            ScopeFrame ehScopeFrame = new ScopeFrame(_oevent,
+                                    getBpelRuntime().createScopeInstance(_scopeFrame.scopeInstanceId, _oevent),
+                                    _scopeFrame,
+                                    _comps,
+                                    _fault);
+
+                            if (_oevent.variable != null) {
+                                Element msgEl = getBpelRuntime().getMyRequest(mexId);
+
+                                if (msgEl != null) {
+                                    try {
+                                        VariableInstance vinst = ehScopeFrame.resolve(_oevent.variable);
+                                        getBpelRuntime().initializeVariable(vinst, _scopeFrame, msgEl);
+
+                                        VariableModificationEvent se = new VariableModificationEvent(vinst.declaration.name);
+                                        se.setNewValue(msgEl);
+                                        _scopeFrame.fillEventInfo(se);
+                                        if (_oevent.debugInfo != null)
+                                            se.setLineNo(_oevent.debugInfo.startLine);
+                                        getBpelRuntime().sendEvent(se);
+                                    } catch (Exception ex) {
+                                        __log.fatal(ex);
+                                        throw new InvalidProcessException(ex);
+                                    }
+                                }
+                            }
+
+
+                            try {
+                                for (OScope.CorrelationSet cset : _oevent.initCorrelations) {
+                                    initializeCorrelation(ehScopeFrame.resolve(cset), ehScopeFrame.resolve(_oevent.variable));
+                                }
+
+                                if (_oevent.partnerLink.hasPartnerRole()) {
+                                    // Trying to initialize partner epr based on a message-provided epr/session.
+                                    if (!getBpelRuntime().isPartnerRoleEndpointInitialized(ehScopeFrame
+                                            .resolve(_oevent.partnerLink)) || !_oevent.partnerLink.initializePartnerRole) {
+                                        Node fromEpr = getBpelRuntime().getSourceEPR(mexId);
+                                        if (fromEpr != null) {
+                                            getBpelRuntime().writeEndpointReference(
+                                                    ehScopeFrame.resolve(_oevent.partnerLink), (Element) fromEpr);
+                                        }
+                                    }
+
+                                    String partnersSessionId = getBpelRuntime().getSourceSessionId(mexId);
+                                    if (partnersSessionId != null)
+                                        getBpelRuntime().initializePartnersSessionId(ehScopeFrame.resolve(_oevent.partnerLink),
+                                                partnersSessionId);
+                                }
+
+
+
+
+                            } catch (FaultException e) {
+                                __log.error(e);
+                                if (_fault == null) {
+                                    _fault = createFault(e.getQName(), _oevent);
+                                    terminateActive();
+                                }
+                                instance(new WAITING(null));
+                                return;
+                            }
+
+
+
+                            // load 'onMessage' activity; we'll do this even if a stop/terminate has been
+                            // requested becasue we cannot undo the receipt of the message at this point.
+                            ActivityInfo child = new ActivityInfo(genMonotonic(),
+                                    _oevent.activity,
+                                    newChannel(TerminationChannel.class), newChannel(ParentScopeChannel.class));
+
+
+                            _active.add(child);
+
+                            LinkFrame lf = new LinkFrame(null);
+
+                            instance(new SCOPE(child,ehScopeFrame, lf));
+
+                            // If we previously terminated the other activiites, then we do the same
+                            // here; this is easier then undoing the receive.
+                            if (_childrenTerminated)
+                                replication(child.self).terminate();
+
+
+                            if (_terminated || _stopped || _fault != null)
+                                instance(new WAITING(null));
+                            else
+                                instance(new SELECT());
+                        }
+
+
+                        public void onTimeout() {
+                            instance(new WAITING(null));
+                        }
+
+                        public void onCancel() {
+                            instance(new WAITING(null));
+                        }
+                    });
+
+                object(false, mlset);
+            } else /* Nothing more to do. */ {
+                _psc.completed(_fault, _comps);
+            }
+        }
+
+    }
+}

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EMPTY.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EMPTY.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EMPTY.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EMPTY.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.rtrep.v1;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+/**
+ * JacobRunnable that performs the work of the <code>empty</code> activity.
+ */
+class EMPTY extends ACTIVITY {
+    private static final long serialVersionUID = 1L;
+    private static final Log __log = LogFactory.getLog(EMPTY.class);
+
+    public EMPTY(ActivityInfo self, ScopeFrame frame, LinkFrame linkFrame) {
+        super(self, frame, linkFrame);
+    }
+
+    public final void run() {
+        if (__log.isDebugEnabled()) {
+            __log.debug("<empty name=" + _self.o + ">");
+        }
+
+        _self.parent.completed(null, CompensationHandler.emptySet());
+    }
+}

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EvaluationContext.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EvaluationContext.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EvaluationContext.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EvaluationContext.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.rtrep.v1;
+
+import java.net.URI;
+
+import org.apache.ode.bpel.common.FaultException;
+import org.apache.ode.bpel.rtrep.v1.OExpression;
+import org.apache.ode.bpel.rtrep.v1.OLink;
+import org.apache.ode.bpel.rtrep.v1.OMessageVarType;
+import org.apache.ode.bpel.rtrep.v1.OProcess;
+import org.apache.ode.bpel.rtrep.v1.OScope;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Context for evaluating expressions. Implementations of the
+ * {@link ExpressionLanguageRuntime} interface use this interface to access BPEL
+ * variables, property sets and link statuses.
+ */
+public interface EvaluationContext {
+
+    /**
+     * Read the value of a BPEL variable.
+     *
+     * @param variable
+     *          variable to read
+     * @param part
+     *          the part (or <code>null</code>)
+     * @return the value of the variable, wrapped in a <code>Node</code>
+     */
+    Node readVariable(OScope.Variable variable, OMessageVarType.Part part) throws FaultException;
+
+    Node getPartData(Element message, OMessageVarType.Part part) throws FaultException;
+    /**
+     * Read the value of a BPEL property.
+     *
+     * @param variable
+     *          variable containing property
+     * @param property
+     *          property to read
+     * @return value of the property
+     */
+    String readMessageProperty(OScope.Variable variable, OProcess.OProperty property)
+            throws FaultException;
+
+    /**
+     * Obtain the status of a control link.
+     *
+     * @param olink
+     *          link to check
+     * @return <code>true</code> if the link is active, <code>false</code>
+     *         otherwise.
+     */
+    boolean isLinkActive(OLink olink) throws FaultException;
+
+    /**
+     * Obtain the root node.
+     *
+     * @return root node
+     */
+    Node getRootNode();
+
+    /**
+     * Evaluate a query expression.
+     *
+     * @param root
+     *          the root context
+     * @param expr
+     *          the query expression
+     * @return node returned by query
+     */
+    Node evaluateQuery(Node root, OExpression expr) throws FaultException;
+
+    /**
+     * Reads the current process instance id.
+     * @return instance id
+     */
+    Long getProcessId();
+
+    /**
+     * Indicates whether simple types should be narrowed to a Java type when
+     * using this evaluation context.
+     */
+    boolean narrowTypes();
+    
+	/**
+	 * Retrieves the base URI that the BPEL Process execution contextis running relative to.
+	 * 
+	 * @return URI - the URI representing the absolute physical file path location that this process is defined within.
+	 */
+	URI getBaseResourceURI();    
+}

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EventContextImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EventContextImpl.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EventContextImpl.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/EventContextImpl.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.rtrep.v1;
+
+import org.apache.ode.bpel.evt.EventContext;
+import org.apache.ode.bpel.rtrep.v1.OScope;
+import org.apache.ode.bpel.rtrep.v1.OScope.Variable;
+import org.apache.ode.utils.DOMUtils;
+import org.w3c.dom.Node;
+
+import java.util.Iterator;
+
+/**
+ * Bpel Event Context Implementation.
+ * @author Raja Balasubramanian
+ */
+public class EventContextImpl implements EventContext
+{
+    /**
+     * Scope Object used in this scope instance.
+     */
+    private OScope __scope;
+    /**
+     * Scope Instance ID
+     */
+    private Long __scopeInstanceId;
+    /**
+     * BPEL Runtime Context
+     */
+    private OdeInternalInstance __runtimeContext;
+
+    /**
+     * Constructor
+     * @param __scope Scope Object used in this scope instance.
+     * @param __scopeInstanceId Scope Instance ID
+     * @param __runtimeContext BPEL Runtime Context
+     */
+    public EventContextImpl(OScope __scope, Long __scopeInstanceId, OdeInternalInstance __runtimeContext)
+    {
+        this.__scope = __scope;
+        this.__scopeInstanceId = __scopeInstanceId;
+        this.__runtimeContext = __runtimeContext;
+    }
+
+    /**
+     * Get Variable data for the given variable name, for this scope instance
+     * @param varName Variable Name
+     * @return DOM Node as XML String. If no value exists or variable not initialized, NULL will be returnrd.
+     */
+    public String getVariableData(String varName)
+    {
+        String value = null;
+        try
+        {
+            Variable var = __scope.getVisibleVariable(varName);
+            VariableInstance varInstance = new VariableInstance(__scopeInstanceId, var);
+            Node varNode = __runtimeContext.fetchVariableData(varInstance, null, false);
+            value = DOMUtils.domToString(varNode);
+        }
+        catch(Throwable e)
+        {
+            //Don't throw any exception back to the caller. Just return null as value.
+        }
+        return value;
+    }
+
+    /**
+     * Get All variable names used in this scope Instance
+     * @return Array of Variable Names. If no variable(s) exists, null will be returned.
+     */
+    public String[] getVariableNames()
+    {
+        String[] __varNames = null;
+        try
+        {
+            int varSize = __scope.variables.size();
+            __varNames = new String[varSize];
+
+            Iterator<String> _varNames = __scope.variables.keySet().iterator();
+            int i = 0;
+            while(_varNames.hasNext())
+            {
+                __varNames[i++] = _varNames.next();
+            }
+        }
+        catch(Throwable e)
+        {
+            //Don't throw any exception back to the caller. Just return null as value.
+        }
+        return __varNames;
+    }
+
+    /**
+     * Get ScopeInstanceId
+     * @return scopeInstanceId
+     */
+    public Long getScopeInstanceId()
+    {
+        return __scopeInstanceId;
+    }
+}

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/ExprEvaluationContextImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/ExprEvaluationContextImpl.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/ExprEvaluationContextImpl.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/ExprEvaluationContextImpl.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.rtrep.v1;
+
+import java.net.URI;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.common.FaultException;
+import org.apache.ode.bpel.evt.ScopeEvent;
+import org.apache.ode.bpel.evt.VariableReadEvent;
+import org.apache.ode.bpel.rtrep.v1.OMessageVarType.Part;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * The context in which BPEL expressions are evaluated. This class is handed of
+ * the {@link org.apache.ode.bpel.rtrep.v1.OExpression} instances to provide access to
+ * variables, link statuses, and the like.
+ */
+public class ExprEvaluationContextImpl implements EvaluationContext {
+	private static final Log __log = LogFactory
+			.getLog(ExprEvaluationContextImpl.class);
+
+	private OdeInternalInstance _native;
+
+	private ScopeFrame _scopeInstance;
+
+	private Map<OLink, Boolean> _linkVals;
+
+	private Node _root;
+
+	public ExprEvaluationContextImpl(ScopeFrame scopeInstace,
+			OdeInternalInstance ntv) {
+		_native = ntv;
+		_scopeInstance = scopeInstace;
+	}
+
+	public ExprEvaluationContextImpl(ScopeFrame scopeInstace,
+			OdeInternalInstance ntv, Node root) {
+		this(scopeInstace, ntv);
+		_root = root;
+	}
+
+	public ExprEvaluationContextImpl(ScopeFrame scopeInstnce,
+			OdeInternalInstance ntv, Map<OLink, Boolean> linkVals) {
+		this(scopeInstnce, ntv);
+		_linkVals = linkVals;
+	}
+
+	public Node readVariable(OScope.Variable variable, OMessageVarType.Part part)
+			throws FaultException {
+		if (__log.isTraceEnabled())
+			__log.trace("readVariable(" + variable + "," + part + ")");
+
+		// TODO: check for null _scopeInstance
+
+		Node ret;
+		if (variable.type instanceof OConstantVarType) {
+			ret = ((OConstantVarType) variable.type).getValue();
+		} else {
+			VariableInstance varInstance = _scopeInstance.resolve(variable);
+			if (varInstance == null)
+				return null;
+			VariableReadEvent vre = new VariableReadEvent();
+			vre.setVarName(varInstance.declaration.name);
+			sendEvent(vre);
+			ret = _native.fetchVariableData(varInstance, _scopeInstance, part, false);
+		}
+		return ret;
+	}
+
+	public Node evaluateQuery(Node root, OExpression expr)
+			throws FaultException {
+        return _native.getExpLangRuntime()
+                .evaluateNode(expr, new ExprEvaluationContextImpl(_scopeInstance, _native, root));
+	}
+
+	public String readMessageProperty(OScope.Variable variable,
+			OProcess.OProperty property) throws FaultException {
+		VariableInstance varInstance = _scopeInstance.resolve(variable);
+		return _native.readProperty(varInstance, property);
+	}
+
+	public boolean isLinkActive(OLink olink) throws FaultException {
+		return _linkVals.get(olink);
+	}
+
+	public String toString() {
+		return "{ExprEvaluationContextImpl scopeInstance=" + _scopeInstance
+				+ ", activeLinks=" + _linkVals + "}";
+	}
+
+	public Node getRootNode() {
+		return _root;
+	}
+
+	public Node getPartData(Element message, Part part) throws FaultException {
+		return _native.getPartData(message, part);
+	}
+
+	public Long getProcessId() {
+		return _native.getPid();
+	}
+
+	public boolean narrowTypes() {
+		return true;
+	}
+
+	private void sendEvent(ScopeEvent se) {
+		_scopeInstance.fillEventInfo(se);
+		_native.sendEvent(se);
+	}
+
+	public URI getBaseResourceURI() {
+		return _native.getBaseResourceURI();
+	}
+
+}

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/ExpressionLanguageRuntime.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/ExpressionLanguageRuntime.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/ExpressionLanguageRuntime.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/ExpressionLanguageRuntime.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.rtrep.v1;
+
+import org.apache.ode.bpel.common.FaultException;
+import org.apache.ode.bpel.rtrep.v1.OExpression;
+import org.apache.ode.bpel.rtrep.common.ConfigurationException;
+import org.apache.ode.utils.xsd.Duration;
+import org.w3c.dom.Node;
+
+import java.util.Calendar;
+import java.util.List;
+import java.util.Map;
+
+public interface ExpressionLanguageRuntime {
+
+    /**
+     * Initialize the expression evaluation runtime.
+     * @param properties configuration properties
+     */
+    void initialize(Map properties) throws ConfigurationException;
+
+    String evaluateAsString(OExpression cexp, EvaluationContext ctx)
+            throws FaultException;
+
+    boolean evaluateAsBoolean(OExpression cexp, EvaluationContext ctx)
+            throws FaultException;
+
+    Number evaluateAsNumber(OExpression cexp, EvaluationContext ctx)
+            throws FaultException;
+
+    List evaluate(OExpression cexp, EvaluationContext ctx)
+            throws FaultException;
+
+    Calendar evaluateAsDate(OExpression cexp, EvaluationContext context)
+            throws FaultException;
+
+    Duration evaluateAsDuration(OExpression cexp, EvaluationContext context)
+            throws FaultException;
+
+    Node evaluateNode(OExpression cexp, EvaluationContext context)
+            throws FaultException;
+}

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/ExpressionLanguageRuntimeRegistry.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/ExpressionLanguageRuntimeRegistry.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/ExpressionLanguageRuntimeRegistry.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/ExpressionLanguageRuntimeRegistry.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.rtrep.v1;
+
+import org.apache.ode.bpel.common.FaultException;
+import org.apache.ode.bpel.rtrep.common.ConfigurationException;
+import org.apache.ode.utils.xsd.Duration;
+import org.w3c.dom.Node;
+
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A registry of {@link ExpressionLanguageRuntime} objects that is able to map
+ * a given expression to the appropriate language runtime.
+ */
+public class ExpressionLanguageRuntimeRegistry  {
+    private final Map<OExpressionLanguage, ExpressionLanguageRuntime> _runtimes =
+            new HashMap<OExpressionLanguage, ExpressionLanguageRuntime>();
+
+    public ExpressionLanguageRuntimeRegistry()  {}
+
+    public void registerRuntime(OExpressionLanguage oelang) throws ConfigurationException {
+        try {
+            String className = oelang.properties.get("runtime-class");
+            // backward compatibility.
+            className = className.replace("com.fs.pxe.","org.apache.ode.");
+            Class cls = Class.forName(className);
+            ExpressionLanguageRuntime elangRT = (ExpressionLanguageRuntime) cls.newInstance();
+            elangRT.initialize(oelang.properties);
+            _runtimes.put(oelang, elangRT);
+        } catch (ConfigurationException ce) {
+            throw ce;
+        } catch (IllegalAccessException e) {
+            throw new ConfigurationException("Illegal Access Error", e);
+        } catch (InstantiationException e) {
+            throw new ConfigurationException("Instantiation Error", e);
+        } catch (ClassNotFoundException e) {
+            throw new ConfigurationException("Class Not Found Error", e);
+        }
+
+    }
+
+    public String evaluateAsString(OExpression cexp, EvaluationContext ctx) throws FaultException {
+        return findRuntime(cexp).evaluateAsString(cexp, ctx);
+    }
+
+    public boolean evaluateAsBoolean(OExpression cexp, EvaluationContext ctx) throws FaultException {
+        return findRuntime(cexp).evaluateAsBoolean(cexp, ctx);
+    }
+
+    public Number evaluateAsNumber(OExpression cexp, EvaluationContext ctx) throws FaultException {
+        return findRuntime(cexp).evaluateAsNumber(cexp, ctx);
+    }
+
+    public List evaluate(OExpression cexp, EvaluationContext ctx) throws FaultException {
+        return findRuntime(cexp).evaluate(cexp, ctx);
+    }
+
+    public Node evaluateNode(OExpression cexp, EvaluationContext ctx) throws FaultException {
+        return findRuntime(cexp).evaluateNode(cexp, ctx);
+    }
+
+    public Calendar evaluateAsDate(OExpression cexp, EvaluationContext ctx) throws FaultException {
+        return findRuntime(cexp).evaluateAsDate(cexp, ctx);
+    }
+
+    public Duration evaluateAsDuration(OExpression cexp, EvaluationContext ctx) throws FaultException {
+        return findRuntime(cexp).evaluateAsDuration(cexp, ctx);
+    }
+
+    private ExpressionLanguageRuntime findRuntime(OExpression cexp) {
+        return _runtimes.get(cexp.expressionLanguage);
+    }
+
+}

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/FLOW.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/FLOW.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/FLOW.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/FLOW.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.rtrep.v1;
+
+import org.apache.ode.bpel.rtrep.v1.OActivity;
+import org.apache.ode.bpel.rtrep.v1.OFlow;
+import org.apache.ode.bpel.rtrep.v1.OLink;
+import org.apache.ode.bpel.rtrep.v1.OScope;
+import org.apache.ode.bpel.rtrep.v1.channels.FaultData;
+import org.apache.ode.bpel.rtrep.v1.channels.LinkStatusChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.ParentScopeChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.ParentScopeChannelListener;
+import org.apache.ode.bpel.rtrep.v1.channels.TerminationChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.TerminationChannelListener;
+import org.apache.ode.jacob.ChannelListener;
+import org.apache.ode.jacob.SynchChannel;
+import org.apache.ode.utils.stl.FilterIterator;
+import org.apache.ode.utils.stl.MemberOfFunction;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import org.w3c.dom.Element;
+
+class FLOW extends ACTIVITY {
+    private static final long serialVersionUID = 1L;
+
+    private OFlow _oflow;
+
+    private Set<ChildInfo> _children = new HashSet<ChildInfo>();
+
+    public FLOW(ActivityInfo self, ScopeFrame frame, LinkFrame linkFrame) {
+        super(self,frame, linkFrame);
+        _oflow = (OFlow) self.o;
+    }
+    
+    public void run() {
+        LinkFrame myLinkFrame = new LinkFrame(_linkFrame);
+        for (Iterator<OLink> i = _oflow.localLinks.iterator(); i.hasNext(); ) {
+            OLink link = i.next();
+            LinkStatusChannel lsc = newChannel(LinkStatusChannel.class);
+            myLinkFrame.links.put(link,new LinkInfo(link,lsc,lsc));
+        }
+
+        for (Iterator<OActivity> i = _oflow.parallelActivities.iterator(); i.hasNext();) {
+            OActivity ochild = i.next();
+            ChildInfo childInfo = new ChildInfo(
+                new ActivityInfo(genMonotonic(), ochild,
+                                 newChannel(TerminationChannel.class), newChannel(ParentScopeChannel.class)));
+            _children.add(childInfo);
+
+            instance(createChild(childInfo.activity,_scopeFrame, myLinkFrame));
+        }
+        instance(new ACTIVE());
+    }
+
+    private class ACTIVE extends BpelJacobRunnable {
+        private static final long serialVersionUID = -8494641460279049245L;
+        private FaultData _fault;
+        private HashSet<CompensationHandler> _compensations = new HashSet<CompensationHandler>();
+
+        public void run() {
+            Iterator<ChildInfo> active = active();
+            if (active.hasNext()) {
+                Set<ChannelListener> mlSet = new HashSet<ChannelListener>();
+                mlSet.add(new TerminationChannelListener(_self.self) {
+                    private static final long serialVersionUID = 2554750258974084466L;
+
+                    public void terminate() {
+                        for (Iterator<ChildInfo> i = active(); i.hasNext(); )
+                            replication(i.next().activity.self).terminate();
+                        instance(ACTIVE.this);
+                    }
+                });
+
+                for (;active.hasNext();) {
+                    final ChildInfo child = active.next();
+                    mlSet.add(new ParentScopeChannelListener(child.activity.parent) {
+                        private static final long serialVersionUID = -8027205709169238172L;
+
+                        public void completed(FaultData faultData, Set<CompensationHandler> compensations) {
+                            child.completed = true;
+                            _compensations.addAll(compensations);
+
+                            // If we receive a fault, we request termination of all our activities
+                            if (faultData != null && _fault == null) {
+                                for (Iterator<ChildInfo> i = active(); i.hasNext(); )
+                                    replication(i.next().activity.self).terminate();
+                                _fault = faultData;
+                            }
+                            instance(ACTIVE.this);
+                        }
+
+                        public void compensate(OScope scope, SynchChannel ret) {
+                            // Flow does not do compensations, forward these to parent.
+                            _self.parent.compensate(scope, ret);
+                            instance(ACTIVE.this);
+                        }
+
+                        public void cancelled() { completed(null, CompensationHandler.emptySet()); }
+                        public void failure(String reason, Element data) { completed(null, CompensationHandler.emptySet()); }
+                    });
+                }
+                object(false,mlSet);
+            } else /** No More active children. */ {
+                // NOTE: we do not not have to do DPE here because all the children
+                // have been started, and are therefore expected to set the value of
+                // their outgoing links.
+                _self.parent.completed(_fault, _compensations);
+            }
+        }
+    }
+
+    public String toString() {
+        return "<T:Act:Flow:" + _oflow.name + ">";
+    }
+
+    private Iterator<ChildInfo> active() {
+        return new FilterIterator<ChildInfo>(_children.iterator(), new MemberOfFunction<ChildInfo>() {
+            public boolean isMember(ChildInfo childInfo) {
+                return !childInfo.completed;
+            }
+        });
+    }
+
+}

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/FOREACH.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/FOREACH.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/FOREACH.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/FOREACH.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.bpel.rtrep.v1;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.common.FaultException;
+import org.apache.ode.bpel.evt.VariableModificationEvent;
+import org.apache.ode.bpel.rtrep.v1.channels.FaultData;
+import org.apache.ode.bpel.rtrep.v1.channels.ParentScopeChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.ParentScopeChannelListener;
+import org.apache.ode.bpel.rtrep.v1.channels.TerminationChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.TerminationChannelListener;
+import org.apache.ode.jacob.ChannelListener;
+import org.apache.ode.jacob.SynchChannel;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.stl.FilterIterator;
+import org.apache.ode.utils.stl.MemberOfFunction;
+import org.apache.ode.bpel.evar.ExternalVariableModuleException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class FOREACH extends ACTIVITY {
+
+    private static final long serialVersionUID = 1L;
+    private static final Log __log = LogFactory.getLog(FOREACH.class);
+
+    private OForEach _oforEach;
+    private Set<ChildInfo> _children = new HashSet<ChildInfo>();
+    private Set<CompensationHandler> _compHandlers = new HashSet<CompensationHandler>();
+    private int _startCounter = -1;
+    private int _finalCounter = -1;
+    private int _currentCounter = -1;
+    private int _completedCounter = 0;
+    private int _completionCounter = -1;
+
+    public FOREACH(ActivityInfo self, ScopeFrame frame, LinkFrame linkFrame) {
+        super(self,frame, linkFrame);
+        _oforEach = (OForEach) self.o;
+    }
+
+    public void run() {
+        try {
+            _startCounter = evaluateCondition(_oforEach.startCounterValue);
+            _finalCounter = evaluateCondition(_oforEach.finalCounterValue);
+            if (_oforEach.completionCondition != null) {
+                _completionCounter = evaluateCondition(_oforEach.completionCondition.branchCount);
+            }
+            _currentCounter = _startCounter;
+        } catch (FaultException fe) {
+            __log.error(fe);
+            _self.parent.completed(createFault(fe.getQName(), _self.o), _compHandlers);
+            return;
+        }
+
+        // Checking for bpws:invalidBranchCondition when the counter limit is superior
+        // to the maximum number of children
+        if (_completionCounter > 0 && _completionCounter > _finalCounter - _startCounter) {
+            _self.parent.completed(
+                    createFault(_oforEach.getOwner().constants.qnInvalidBranchCondition, _self.o), _compHandlers);
+            return;
+        }
+
+        // There's really nothing to do
+        if (_finalCounter < _startCounter || _completionCounter == 0) {
+            _self.parent.completed(null, _compHandlers);
+        } else {
+            // If we're parrallel, starting all our child copies, otherwise one will suffice.
+            if (_oforEach.parallel) {
+                for (int m = _startCounter; m <= _finalCounter; m++) {
+                    newChild();
+                }
+            } else newChild();
+            instance(new ACTIVE());
+        }
+    }
+
+    private class ACTIVE extends BpelJacobRunnable {
+        private static final long serialVersionUID = -5642862698981385732L;
+
+        private FaultData _fault;
+        private boolean _terminateRequested = false;
+
+        public void run() {
+            Iterator<ChildInfo> active = active();
+            // Continuing as long as a child is active
+            if (active().hasNext()) {
+
+                Set<ChannelListener> mlSet = new HashSet<ChannelListener>();
+                mlSet.add(new TerminationChannelListener(_self.self) {
+                    private static final long serialVersionUID = 2554750257484084466L;
+
+                    public void terminate() {
+                        // Terminating all children before sepuku
+                        for (Iterator<ChildInfo> i = active(); i.hasNext(); )
+                            replication(i.next().activity.self).terminate();
+                        _terminateRequested = true;
+                        instance(ACTIVE.this);
+                    }
+                });
+                for (;active.hasNext();) {
+                    // Checking out our children
+                    final ChildInfo child = active.next();
+                    mlSet.add(new ParentScopeChannelListener(child.activity.parent) {
+                        private static final long serialVersionUID = -8027205709961438172L;
+
+                        public void compensate(OScope scope, SynchChannel ret) {
+                            // Forward compensation to parent
+                            _self.parent.compensate(scope, ret);
+                            instance(ACTIVE.this);
+                        }
+
+                        public void completed(FaultData faultData, Set<CompensationHandler> compensations) {
+                            child.completed = true;
+                            //
+                            if (_completionCounter > 0 && _oforEach.completionCondition.successfulBranchesOnly) {
+                                if (faultData != null) _completedCounter++;
+                            } else _completedCounter++;
+
+                            _compHandlers.addAll(compensations);
+
+                            // Keeping the fault to let everybody know
+                            if (faultData != null && _fault == null) {
+                                _fault = faultData;
+                            }
+                            if (shouldContinue() && _fault == null && !_terminateRequested) {
+                                // Everything fine. If parrallel, just let our children be, otherwise making a new child
+                                if (!_oforEach.parallel) newChild();
+                            } else {
+                                // Work is done or something wrong happened, children shouldn't continue
+                                for (Iterator<ChildInfo> i = active(); i.hasNext(); )
+                                    replication(i.next().activity.self).terminate();
+                            }
+                            instance(ACTIVE.this);
+                        }
+
+                        public void cancelled() { completed(null, CompensationHandler.emptySet()); }
+                        public void failure(String reason, Element data) { completed(null, CompensationHandler.emptySet()); }
+                    });
+                }
+                object(false,mlSet);
+            } else {
+                // No children left, either because they've all been executed or because we
+                // had to make them stop.
+                _self.parent.completed(_fault, _compHandlers);
+            }
+        }
+    }
+
+    private boolean shouldContinue() {
+        boolean stop = false;
+        if (_completionCounter > 0) {
+            stop = (_completedCounter >= _completionCounter) || stop;
+        }
+        stop = (_startCounter + _completedCounter > _finalCounter) || stop;
+        return !stop;
+    }
+
+    private int evaluateCondition(OExpression condition)
+            throws FaultException {
+        return getBpelRuntime().getExpLangRuntime().
+                evaluateAsNumber(condition, getEvaluationContext()).intValue();
+    }
+
+    private void newChild() {
+        ChildInfo child = new ChildInfo(new ActivityInfo(genMonotonic(), _oforEach.innerScope,
+                newChannel(TerminationChannel.class), newChannel(ParentScopeChannel.class)));
+        _children.add(child);
+
+        // Creating the current counter value node
+        Document doc = DOMUtils.newDocument();
+        Node counterNode = doc.createTextNode(""+_currentCounter++);
+
+        // Instantiating the scope directly to keep control of its scope frame, allows
+        // the introduction of the counter variable in there (monkey business that is).
+        ScopeFrame newFrame = new ScopeFrame(
+                _oforEach.innerScope, getBpelRuntime().createScopeInstance(_scopeFrame.scopeInstanceId,
+                _oforEach.innerScope), _scopeFrame, null);
+        VariableInstance vinst = newFrame.resolve(_oforEach.counterVariable);
+
+        try {
+        initializeVariable(vinst, counterNode);
+        } catch (ExternalVariableModuleException e) {
+        	__log.error("Exception while initializing external variable", e);
+            _self.parent.failure(e.toString(), null);
+            return;
+        }
+
+        // Generating event
+        VariableModificationEvent se = new VariableModificationEvent(vinst.declaration.name);
+        se.setNewValue(counterNode);
+        if (_oforEach.debugInfo != null)
+            se.setLineNo(_oforEach.debugInfo.startLine);
+        sendEvent(se);
+
+        instance(new SCOPE(child.activity, newFrame, _linkFrame));
+    }
+
+    public String toString() {
+        return "<T:Act:Flow:" + _oforEach.name + ">";
+    }
+
+    private Iterator<ChildInfo> active() {
+        return new FilterIterator<ChildInfo>(_children.iterator(), new MemberOfFunction<ChildInfo>() {
+            public boolean isMember(ChildInfo childInfo) {
+                return !childInfo.completed;
+            }
+        });
+    }
+
+}

Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/INVOKE.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/INVOKE.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/INVOKE.java (added)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/INVOKE.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,280 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.rtrep.v1;
+
+import java.util.Collection;
+import java.util.Date;
+
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.common.FaultException;
+import org.apache.ode.bpel.evt.ActivityFailureEvent;
+import org.apache.ode.bpel.evt.ActivityRecoveryEvent;
+import org.apache.ode.bpel.evt.VariableModificationEvent;
+import org.apache.ode.bpel.rtrep.v1.OFailureHandling;
+import org.apache.ode.bpel.rtrep.v1.OInvoke;
+import org.apache.ode.bpel.rtrep.v1.OScope;
+import org.apache.ode.bpel.rtrep.v1.channels.ActivityRecoveryChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.ActivityRecoveryChannelListener;
+import org.apache.ode.bpel.rtrep.v1.channels.FaultData;
+import org.apache.ode.bpel.rtrep.v1.channels.InvokeResponseChannel;
+import org.apache.ode.bpel.rtrep.v1.channels.InvokeResponseChannelListener;
+import org.apache.ode.bpel.rtrep.v1.channels.TerminationChannelListener;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.bpel.evar.ExternalVariableModuleException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * JacobRunnable that performs the work of the <code>invoke</code> activity.
+ */
+public class INVOKE extends ACTIVITY {
+    private static final long serialVersionUID = 992248281026821783L;
+    private static final Log __log = LogFactory.getLog(INVOKE.class);
+
+    private OInvoke _oinvoke;
+    // Records number of invocations on the activity.
+    private int     _invoked;
+    // Date/time of last failure.
+    private Date    _lastFailure;
+    // Reason for last failure.
+    private String  _failureReason;
+    // Data associated with failure.
+    private Element _failureData;
+
+    public INVOKE(ActivityInfo self, ScopeFrame scopeFrame, LinkFrame linkFrame) {
+        super(self, scopeFrame, linkFrame);
+        _oinvoke = (OInvoke) _self.o;
+        _invoked = 0;
+    }
+
+    public final void run() {
+        Element outboundMsg;
+        try {
+            outboundMsg = setupOutbound(_oinvoke, _oinvoke.initCorrelationsInput);
+        } catch (FaultException e) {
+            __log.error(e);
+            FaultData fault = createFault(e.getQName(), _oinvoke);
+            _self.parent.completed(fault, CompensationHandler.emptySet());
+            return;
+        } catch (ExternalVariableModuleException e) {
+            __log.error(e);
+            _self.parent.failure(e.toString(), null);
+            return;
+        }
+        ++_invoked;
+
+        // if there is no output variable, then this is a one-way invoke
+        boolean isTwoWay = _oinvoke.outputVar != null;
+
+        try {
+            if (!isTwoWay) {
+                FaultData faultData = null;
+                getBpelRuntime().invoke(null, _scopeFrame.resolve(_oinvoke.partnerLink), _oinvoke.operation, outboundMsg, null);
+                _self.parent.completed(faultData, CompensationHandler.emptySet());
+
+            } else /* two-way */{
+                final VariableInstance outputVar = _scopeFrame.resolve(_oinvoke.outputVar);
+                final InvokeResponseChannel invokeResponseChannel = newChannel(InvokeResponseChannel.class);
+
+                final String mexId = getBpelRuntime().invoke(invokeResponseChannel.export(),
+                    _scopeFrame.resolve(_oinvoke.partnerLink), _oinvoke.operation, outboundMsg, invokeResponseChannel);
+
+                object(false, new InvokeResponseChannelListener(invokeResponseChannel) {
+                    private static final long serialVerstmptmpionUID = 4496880438819196765L;
+
+                    public void onResponse() {
+                        // we don't have to write variable data -> this already
+                        // happened in the nativeAPI impl
+                        FaultData fault = null;
+
+                        Element response;
+                        try {
+                            response = getBpelRuntime().getPartnerResponse(mexId);
+                        } catch (Exception e) {
+                            __log.error("Exception while processing invoke response", e);
+                            throw new RuntimeException(e);
+                        }
+
+                        try {
+                        initializeVariable(outputVar, response);
+                        } catch (ExternalVariableModuleException e) {
+                        	__log.error("Exception while initializing external variable", e);
+                            _self.parent.failure(e.toString(), null);
+                            return;
+                        }
+                        
+                        // Generating event
+                        VariableModificationEvent se = new VariableModificationEvent(outputVar.declaration.name);
+                        se.setNewValue(response);
+                        if (_oinvoke.debugInfo != null)
+                            se.setLineNo(_oinvoke.debugInfo.startLine);
+                        sendEvent(se);
+
+                        try {
+                            for (OScope.CorrelationSet anInitCorrelationsOutput : _oinvoke.initCorrelationsOutput) {
+                                initializeCorrelation(_scopeFrame.resolve(anInitCorrelationsOutput), outputVar);
+                            }
+                            if (_oinvoke.partnerLink.hasPartnerRole()) {
+                                // Trying to initialize partner epr based on a message-provided epr/session.
+                                if (!getBpelRuntime().isPartnerRoleEndpointInitialized(_scopeFrame
+                                        .resolve(_oinvoke.partnerLink)) || !_oinvoke.partnerLink.initializePartnerRole) {
+                    
+                                    Node fromEpr = getBpelRuntime().getSourceEPR(mexId);
+                                    if (fromEpr != null) {
+                                        getBpelRuntime().writeEndpointReference(
+                                            _scopeFrame.resolve(_oinvoke.partnerLink), (Element) fromEpr);
+                                    }
+                                }                    
+                                
+                                String partnersSessionId = getBpelRuntime().getSourceSessionId(mexId);
+                                if (partnersSessionId != null)
+                                    getBpelRuntime().initializePartnersSessionId(_scopeFrame.resolve(_oinvoke.partnerLink),
+                                        partnersSessionId);
+                                
+                            }
+                        } catch (FaultException e) {
+                            fault = createFault(e.getQName(), _oinvoke);
+                        }
+
+                        // TODO update output variable with data from non-initiate correlation sets
+
+                        _self.parent.completed(fault, CompensationHandler.emptySet());
+                        getBpelRuntime().releasePartnerMex(mexId);
+                    }
+
+                    public void onFault() {
+                        QName faultName = getBpelRuntime().getPartnerFault(mexId);
+                        Element msg = getBpelRuntime().getPartnerResponse(mexId);
+                        QName msgType = getBpelRuntime().getPartnerResponseType(mexId);
+                        FaultData fault = createFault(faultName, msg,
+                            _oinvoke.getOwner().messageTypes.get(msgType), _self.o);
+                        _self.parent.completed(fault, CompensationHandler.emptySet());
+                        getBpelRuntime().releasePartnerMex(mexId);
+                    }
+
+                    public void onFailure() {
+                        // This indicates a communication failure. We don't throw a fault,
+                        // because there is no fault, instead we'll re-incarnate the invoke
+                        // and either retry or indicate failure condition.
+                        // admin to resume the process.
+                        String reason = getBpelRuntime().getPartnerFaultExplanation(mexId);
+                        __log.error("Failure during invoke: " + reason);
+                        try {
+                            Element el = DOMUtils.stringToDOM("<invokeFailure><![CDATA["+reason+"]]></invokeFailure>");
+                            _self.parent.failure(reason, el);
+                        } catch (Exception e) {
+                            _self.parent.failure(reason, null);
+                        }
+                        getBpelRuntime().releasePartnerMex(mexId);
+                    }
+
+                }.or(new TerminationChannelListener(_self.self) {
+                    private static final long serialVersionUID = 4219496341785922396L;
+
+                    public void terminate() {
+                    	_self.parent.completed(null, CompensationHandler.emptySet());
+                    	object(new InvokeResponseChannelListener(invokeResponseChannel) {
+                        private static final long serialVersionUID = 688746737897792929L;
+						public void onFailure() {
+							__log.debug("Failure on invoke ignored, the invoke has already been terminated: " + _oinvoke.toString());
+						}
+						public void onFault() {
+                            __log.debug("Fault on invoke ignored, the invoke has already been terminated: " + _oinvoke.toString());
+						}
+						public void onResponse() {
+                            __log.debug("Response on invoke ignored, the invoke has already been terminated: " + _oinvoke.toString());
+						}
+
+                    });
+                    }
+                }));
+                
+            }
+        } catch (FaultException fault) {
+            __log.error(fault);
+            FaultData faultData = createFault(fault.getQName(), _oinvoke, fault.getMessage());
+            _self.parent.completed(faultData, CompensationHandler.emptySet());
+        }
+    }
+
+    private Element setupOutbound(OInvoke oinvoke, Collection<OScope.CorrelationSet> outboundInitiations)
+        throws FaultException, ExternalVariableModuleException {
+        if (outboundInitiations.size() > 0) {
+            for (OScope.CorrelationSet c : outboundInitiations) {
+                initializeCorrelation(_scopeFrame.resolve(c), _scopeFrame.resolve(oinvoke.inputVar));
+            }
+        }
+
+        if (oinvoke.operation.getInput().getMessage().getParts().size() > 0) {
+            sendVariableReadEvent(_scopeFrame.resolve(oinvoke.inputVar));
+            Node outboundMsg = fetchVariableData(_scopeFrame.resolve(oinvoke.inputVar), false);
+            // TODO outbound message should be updated with non-initiate correlation sets
+            assert outboundMsg instanceof Element;
+            return (Element) outboundMsg;
+        } else return null;
+    }
+
+    private void requireRecovery() {
+        if (__log.isDebugEnabled())
+            __log.debug("ActivityRecovery: Invoke activity " + _self.aId + " requires recovery");
+        sendEvent(new ActivityFailureEvent(_failureReason));
+        final ActivityRecoveryChannel recoveryChannel = newChannel(ActivityRecoveryChannel.class);
+        getBpelRuntime().registerActivityForRecovery(recoveryChannel, _self.aId, _failureReason, _lastFailure, _failureData,
+            new String[] { "retry", "cancel", "fault" }, _invoked - 1);
+        object(false, new ActivityRecoveryChannelListener(recoveryChannel) {
+            private static final long serialVersionUID = 8397883882810521685L;
+            public void retry() {
+                if (__log.isDebugEnabled())
+                    __log.debug("ActivityRecovery: Retrying invoke activity " + _self.aId + " (user initiated)");
+                sendEvent(new ActivityRecoveryEvent("retry"));
+                getBpelRuntime().unregisterActivityForRecovery(recoveryChannel);
+                instance(INVOKE.this);
+            }
+            public void cancel() {
+                if (__log.isDebugEnabled())
+                    __log.debug("ActivityRecovery: Cancelling invoke activity " + _self.aId + " (user initiated)");
+                sendEvent(new ActivityRecoveryEvent("cancel"));
+                getBpelRuntime().unregisterActivityForRecovery(recoveryChannel);
+                _self.parent.cancelled();
+            }
+            public void fault(FaultData faultData) {
+                if (__log.isDebugEnabled())
+                    __log.debug("ActivityRecovery: Faulting invoke activity " + _self.aId + " (user initiated)");
+                sendEvent(new ActivityRecoveryEvent("fault"));
+                getBpelRuntime().unregisterActivityForRecovery(recoveryChannel);
+                if (faultData == null)
+                  faultData = createFault(OFailureHandling.FAILURE_FAULT_NAME, _self.o, _failureReason);
+                _self.parent.completed(faultData, CompensationHandler.emptySet());
+            }
+        }.or(new TerminationChannelListener(_self.self) {
+            private static final long serialVersionUID = 2148587381204858397L;
+
+            public void terminate() {
+                if (__log.isDebugEnabled())
+                    __log.debug("ActivityRecovery: Cancelling invoke activity " + _self.aId + " (terminated by scope)");
+                getBpelRuntime().unregisterActivityForRecovery(recoveryChannel);
+                _self.parent.completed(null, CompensationHandler.emptySet());
+            }
+        }));
+    }
+
+}