Author: mriou
Date: Tue Sep 30 18:08:32 2008
New Revision: 700653
URL: http://svn.apache.org/viewvc?rev=700653&view=rev
Log:
First test using correlation passing. Properties can be written as any simple
type variable (when marked unique). Properties read still missing.
Modified:
ode/sandbox/simpel/Rakefile
ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPEL.g
ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/expr/E4XExprRuntime.java
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/SimPELExpr.java
ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELRuntimeTest.java
Modified: ode/sandbox/simpel/Rakefile
URL:
http://svn.apache.org/viewvc/ode/sandbox/simpel/Rakefile?rev=700653&r1=700652&r2=700653&view=diff
==============================================================================
--- ode/sandbox/simpel/Rakefile (original)
+++ ode/sandbox/simpel/Rakefile Tue Sep 30 18:08:32 2008
@@ -43,7 +43,7 @@
"ode-engine", "ode-il-common", "ode-jacob",
"ode-scheduler-simple",
"ode-utils", :under=>"org.apache.ode",
:version=>"1.3-SNAPSHOT")
WSDL4J = "wsdl4j:wsdl4j:jar:1.6.2"
-XERCES = "xerces:xercesImpl:jar:2.9.0"
+XERCES = "xerces:xercesImpl:jar:2.8.1"
repositories.remote << "http://repo1.maven.org/maven2"
repositories.remote << "http://people.apache.org/~mriou/ode-1.2RC1/"
Modified: ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPEL.g
URL:
http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPEL.g?rev=700653&r1=700652&r2=700653&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPEL.g
(original)
+++ ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPEL.g Tue
Sep 30 18:08:32 2008
@@ -182,7 +182,7 @@
correlation
: '{' corr_mapping (',' corr_mapping)* '}' -> ^(CORRELATION
corr_mapping*);
corr_mapping
- : f1=ID ':' expr -> ^(CORR_MAP $f1 expr);
+ : fn=ID ':' var=ID -> ^(CORR_MAP $fn $var);
funct : 'function'^ f=ID '(' ID? (','! ID)* ')' js_block;
Modified:
ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g
URL:
http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g?rev=700653&r1=700652&r2=700653&view=diff
==============================================================================
---
ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g
(original)
+++
ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g
Tue Sep 30 18:08:32 2008
@@ -190,12 +190,12 @@
invoke
scope ReceiveBlock;
- : ^(INVOKE ^(p=ID o=ID in=ID?)) {
- OBuilder.StructuredActivity<OInvoke> inv =
builder.build(OInvoke.class, $BPELScope::oscope,
- $Parent::activity, text($p), text($o), text($in));
- $ReceiveBlock::activity = inv.getOActivity();
- }
- (prb=(param_block))?;
+ : ^(INVOKE ^(p=ID o=ID in=ID?)) {
+ OBuilder.StructuredActivity<OInvoke> inv =
builder.build(OInvoke.class, $BPELScope::oscope,
+ $Parent::activity, text($p), text($o), text($in));
+ $ReceiveBlock::activity = inv.getOActivity();
+ }
+ (prb=(param_block))?;
reply
: ^(REPLY msg=ID (pl=ID var=ID)?) {
@@ -208,11 +208,11 @@
};
receive
scope ReceiveBlock;
- : ^(RECEIVE ^(p=ID o=ID correlation?)) {
+ : ^(RECEIVE ^(p=ID o=ID {
OBuilder.StructuredActivity<OPickReceive> rec =
builder.build(OPickReceive.class, $BPELScope::oscope,
$Parent::activity, text($p), text($o));
$ReceiveBlock::activity = rec.getOActivity();
- }
+ } correlation?))
(prb=(param_block))?;
assign
@@ -237,19 +237,22 @@
exit : EXIT;
// Other
-variable: ^(VARIABLE ID VAR_MODS*);
+variable: ^(VARIABLE ID VAR_MODS*) { builder.addVariableDecl(text($ID),
text($VAR_MODS)); };
partner_link
: ^(PARTNERLINK ID*);
correlation
-scope ExprContext;
- : ^(CORRELATION {
- $ExprContext::expr = new SimPELExpr(builder.getProcess());
- }
- corr_mapping*);
+ : ^(CORRELATION (corr_mapping {
+ builder.addCorrelationMatch($ReceiveBlock::activity,
$corr_mapping.corr);
+ } )*);
corr_mapping
- : ^(CORR_MAP ID expr);
+returns [List corr]
+ : ^(CORR_MAP fn=ID var=ID) {
+ corr = new ArrayList(2);
+ corr.add(deepText($fn));
+ corr.add(deepText($var));
+ };
// XML
xmlElement
Modified:
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/expr/E4XExprRuntime.java
URL:
http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/expr/E4XExprRuntime.java?rev=700653&r1=700652&r2=700653&view=diff
==============================================================================
---
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/expr/E4XExprRuntime.java
(original)
+++
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/expr/E4XExprRuntime.java
Tue Sep 30 18:08:32 2008
@@ -83,11 +83,14 @@
// First evaluating the assignment
SimPELExpr expr = (SimPELExpr) oexpr;
- String forged = expr.getLValue() + " = " + expr.getExpr();
+ String forged = expr.getExpr();
+ if (expr.getLValue() != null)
+ forged = expr.getLValue() + " = " + expr.getExpr();
- cx.evaluateString(scope, forged, "<expr>", 0, null);
+ Object res = cx.evaluateString(scope, forged, "<expr>", 0, null);
// Second extracting the resulting variable value
- Object res = scope.getEnv().get(expr.getLVariable());
+ if (expr.getLValue() != null)
+ res = scope.getEnv().get(expr.getLVariable());
ArrayList<Node> resList = new ArrayList<Node>(1);
if (res instanceof String || res instanceof Number) {
@@ -119,7 +122,7 @@
}
public Node evaluateNode(OExpression oExpression, EvaluationContext
evaluationContext) throws FaultException {
- return null;
+ return (Node) evaluate(oExpression, evaluationContext).get(0);
}
private class ODEDelegator extends Delegator {
@@ -145,11 +148,19 @@
OScope.Variable v = _expr.getReferencedVariable(name);
if (v == null) return super.get(name, start);
+ // Handling of variables pointing to property values
+ if (v.type instanceof OPropertyVarType) {
+ System.out.println("Property value access.");
+ }
+
if (_env.get(name) != null) return _env.get(name);
// TODO this assumes message type with a single part for all
variables, valid?
Node node;
try {
- node =
_evaluationContext.readVariable(v,((OMessageVarType)v.type).parts.values().iterator().next());
+ if (v.type instanceof OMessageVarType)
+ node =
_evaluationContext.readVariable(v,((OMessageVarType)v.type).parts.values().iterator().next());
+ else
+ node = _evaluationContext.readVariable(v, null);
} catch (FaultException e) {
if
(e.getQName().getLocalPart().equals("uninitializedVariable")) return
super.get(name, start);
else throw e;
@@ -182,7 +193,10 @@
Node node;
try {
- node =
_evaluationContext.readVariable(v,((OMessageVarType)v.type).parts.values().iterator().next());
+ if (v.type instanceof OMessageVarType)
+ node =
_evaluationContext.readVariable(v,((OMessageVarType)v.type).parts.values().iterator().next());
+ else
+ node = _evaluationContext.readVariable(v, null);
} catch (FaultException e) {
return false;
}
Modified:
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java
URL:
http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java?rev=700653&r1=700652&r2=700653&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java
(original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java
Tue Sep 30 18:08:32 2008
@@ -6,11 +6,14 @@
import org.apache.ode.bpel.rtrep.v2.*;
import org.apache.ode.bpel.compiler.bom.Bpel20QNames;
+import org.apache.ode.bpel.rapi.PropertyExtractor;
import org.apache.ode.simpel.wsdl.SimPELInput;
import org.apache.ode.simpel.wsdl.SimPELOperation;
import org.apache.ode.simpel.wsdl.SimPELOutput;
import org.apache.ode.simpel.wsdl.SimPELPortType;
import org.apache.ode.utils.GUID;
+import org.w3c.dom.Node;
+import org.w3c.dom.Document;
import javax.wsdl.PortType;
import javax.wsdl.Part;
@@ -24,6 +27,7 @@
* TODO allow javascript blocks instead of just hooking on equal, otherwise
you can't do stuff like
* operations.appendChild(<operand>2</operand>);
* operations.appendChild(<operand>3</operand>);
+ * TODO support generic variable declarations that aren't mapped to a property
(unique)
*/
public class OBuilder extends BaseCompiler {
private static final Logger __log = Logger.getLogger(OBuilder.class);
@@ -104,7 +108,7 @@
final OScope processScope = new OScope(_oprocess, null);
processScope.name = "__PROCESS_SCOPE:" + name;
- _oprocess.procesScope = processScope;
+ _oprocess.processScope = processScope;
return buildScope(processScope, null);
}
@@ -177,7 +181,8 @@
String lvar = lexpr.split("\\.")[0];
vref.variable = resolveVariable(oscope, lvar);
// Don't worry, it's all type safe, therefore it's correct
- vref.part =
((OMessageVarType)vref.variable.type).parts.values().iterator().next();
+ if (vref.variable.type instanceof OMessageVarType)
+ vref.part =
((OMessageVarType)vref.variable.type).parts.values().iterator().next();
ocopy.to = vref;
rexpr.setLValue(lexpr);
@@ -188,7 +193,7 @@
}
public SimpleActivity buildReply(OReply oreply, OScope oscope,
OPickReceive oreceive,
- String var, String partnerLink, String operation)
{
+ String var, String partnerLink, String
operation) {
oreply.variable = resolveVariable(oscope, var, operation, false);
if (partnerLink == null) {
if (oreceive == null) throw new RuntimeException("No parent
receive but reply with var " + var +
@@ -198,7 +203,7 @@
buildPartnerLink(oscope, oreply.partnerLink.name,
oreply.operation.getName(), true, false);
} else {
oreply.partnerLink = buildPartnerLink(oscope, partnerLink,
operation, true, false);
- oreply.operation =
oreply.partnerLink.myRolePortType.getOperation(operation, null, null);
+ oreply.operation =
oreply.partnerLink.myRolePortType.getOperation(operation, null, null);
}
// Adding partner role
return new SimpleActivity<OReply>(oreply);
@@ -208,7 +213,7 @@
// The AST for block activities is something like:
// (SEQUENCE (activity) (SEQUENCE varIds otherActivities))
// The blockActivity here is the second sequence so we just set the
varIds on the previous activity
- if (blockActivity == null || !(blockActivity instanceof OSequence)) {
+ if (blockActivity == null) {
__log.warn("Can't set block parameter with block parent activity "
+ blockActivity);
return;
}
@@ -217,6 +222,12 @@
if (oact instanceof OPickReceive) {
OPickReceive.OnMessage rec =
((OPickReceive)oact).onMessages.get(0);
rec.variable = resolveVariable(oscope, varName,
rec.operation.getName(), true);
+ if (rec.matchCorrelation != null) {
+ // Setting the message variable type associated with the
correlation expression
+ for (PropertyExtractor extractor :
rec.matchCorrelation.getExtractors()) {
+
((SimPELExpr)extractor).getReferencedVariable(extractor.getMessageVariableName()).type
= rec.variable.type;
+ }
+ }
} else if (oact instanceof OInvoke) {
OInvoke inv = (OInvoke)oact;
inv.outputVar = resolveVariable(oscope, varName,
inv.operation.getName(), false);
@@ -233,6 +244,50 @@
expr.addVariable(resolveVariable(oscope, varName));
}
+ public void addVariableDecl(String varName, String modifiers) {
+ if (variables.get(varName) != null)
+ throw new RuntimeException("Duplicate definition of variable " +
varName);
+
+ if (modifiers.indexOf("unique") >= 0) {
+ OProcess.OProperty oproperty = new OProcess.OProperty(_oprocess);
+ oproperty.name = new QName(varName);
+ _oprocess.properties.add(oproperty);
+
+ OPropertyVarType propType = new OPropertyVarType(_oprocess);
+ OScope.Variable propVar = new OScope.Variable(_oprocess, propType);
+ propVar.name = varName;
+ propVar.declaringScope = _oprocess.processScope;
+ variables.put(varName, propVar);
+
+ // TODO get rid of this dummy correlation set, we should be able
to access properties directly
+ OScope.CorrelationSet set = new OScope.CorrelationSet(_oprocess);
+ set.name = varName;
+ set.properties.add(oproperty);
+ set.declaringScope = _oprocess.processScope;
+ _oprocess.processScope.addCorrelationSet(set);
+ }
+ }
+
+ public void addCorrelationMatch(OActivity receive, List match) {
+ // TODO multiple values match
+ OScope.CorrelationSet cset =
_oprocess.processScope.getCorrelationSet((String) match.get(1));
+ OPickReceive.OnMessage rec = ((OPickReceive)receive).onMessages.get(0);
+
+ // Creating an expression that will return the correlation value by
applying the correlation
+ // function to the input variable (bound to __msg__)
+ OScope.Variable msgVar = new OScope.Variable(_oprocess, null);
+ msgVar.name = "__msg" + rec.getId() + "__";
+ msgVar.declaringScope = _oprocess.processScope;
+ SimPELExpr expr = new SimPELExpr(_oprocess);
+ expr.setExpr(match.get(0) + "(" + msgVar.name + ")");
+ expr.addVariable(msgVar);
+ expr.expressionLanguage = _exprLang;
+ cset.extractors.add(expr);
+
+ rec.matchCorrelation = cset;
+ rec.partnerLink.addCorrelationSetForOperation(rec.operation, cset);
+ }
+
public OProcess getProcess() {
return _oprocess;
}
@@ -309,11 +364,6 @@
part.type = new OElementVarType(_oprocess, new QName(_processNS,
elmtName));
varType.parts.clear();
varType.parts.put(part.name, part);
-//
-// LinkedList<OMessageVarType.Part> parts = new
LinkedList<OMessageVarType.Part>();
-// parts.add(new OMessageVarType.Part(_oprocess, elmtName,
-// new OElementVarType(_oprocess, new QName(_processNS,
elmtName))));
-// resolved.type = new OMessageVarType(_oprocess, new
QName(_processNS, operation), parts);
typedVariables.add(name);
}
return resolved;
Modified:
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/SimPELExpr.java
URL:
http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/SimPELExpr.java?rev=700653&r1=700652&r2=700653&view=diff
==============================================================================
---
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/SimPELExpr.java
(original)
+++
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/SimPELExpr.java
Tue Sep 30 18:08:32 2008
@@ -1,13 +1,14 @@
package org.apache.ode.simpel.omodel;
import org.apache.ode.bpel.rtrep.v2.*;
+import org.apache.ode.bpel.rapi.PropertyExtractor;
import java.util.HashMap;
/**
* @author Matthieu Riou <[EMAIL PROTECTED]>
*/
-public class SimPELExpr extends OExpression {
+public class SimPELExpr extends OExpression implements PropertyExtractor {
private String expr;
private String lvalue;
private String lvariable;
@@ -52,4 +53,10 @@
public String toString() {
return expr;
}
+
+ public String getMessageVariableName() {
+ // Special case of a correlation match expression, the expression only
references
+ // a single variable bound to the incoming message.
+ return _referencedVariables.keySet().iterator().next();
+ }
}
Modified:
ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELRuntimeTest.java
URL:
http://svn.apache.org/viewvc/ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELRuntimeTest.java?rev=700653&r1=700652&r2=700653&view=diff
==============================================================================
---
ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELRuntimeTest.java
(original)
+++
ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELRuntimeTest.java
Tue Sep 30 18:08:32 2008
@@ -209,15 +209,43 @@
}
private static final String SIMPLE_CORRELATION =
- "var append = \" Yeeha!\"; \n" +
- "function getCounterId(msg) { return msg.counterId; }; \n" +
+ "function getExchangeId(msg) { return msg.id; }; \n" +
"\n" +
- "process SimpleCorrelation {\n" +
+ "process SimpleCorrelation { \n" +
" var cid unique; \n" +
- " receive(myPl, helloOp) { |msgIn|\n" +
- " msgOut = helloPrepend(msgIn) + append;\n" +
- " reply(msgOut);\n" +
+ " receive(myPl, firstOp) { |msgIn| \n" +
+ " cid = msgIn.id; \n" +
+ " text = msgIn.text; \n" +
+ " }\n" +
+ " receive(myPl, secondOp, {getExchangeId: cid}) { |secMsgIn| \n"
+
+ " text = text + secMsgIn.text; \n" +
+ " reply(text); \n" +
" }\n" +
"}";
+ public void testSimpleCorrelation() throws Exception {
+ EmbeddedServer server = new EmbeddedServer();
+ server.start();
+ server.deploy(SIMPLE_CORRELATION);
+
+ Element wrapper = DOMUtils.stringToDOM(
+ "<xd:firstOpRequest
xmlns:xd=\"http://ode.apache.org/simpel/1.0/definition/SimpleCorrelation\">" +
+ "<exchange>" +
+ "<id>XYZ1</id>" +
+ "<text>foo</text>" +
+ "</exchange>" +
+ "</xd:firstOpRequest>");
+ server.sendMessage("myPl", "firstOp", wrapper);
+
+ wrapper = DOMUtils.stringToDOM(
+ "<xd:secondOpRequest
xmlns:xd=\"http://ode.apache.org/simpel/1.0/definition/SimpleCorrelation\">" +
+ "<exchange>" +
+ "<id>XYZ1</id>" +
+ "<text>bar</text>" +
+ "</exchange>" +
+ "</xd:secondOpRequest>");
+ Element result = server.sendMessage("myPl", "secondOp", wrapper);
+ assertTrue(DOMUtils.domToString(result).indexOf("foobar") > 0);
+ }
+
}