Author: mriou
Date: Tue Oct 14 11:49:06 2008
New Revision: 704611
URL: http://svn.apache.org/viewvc?rev=704611&view=rev
Log:
SimPEL is now Turing complete, we have names bound to an unlimited memory space
(practically large enough), conditions and loops. From now on, everything is
sugar coating. The problem is just that we got used to very thick sugar coating.
Modified:
ode/sandbox/simpel/Rakefile
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/test/java/org/apache/ode/simpel/SimPELRuntimeTest.java
Modified: ode/sandbox/simpel/Rakefile
URL:
http://svn.apache.org/viewvc/ode/sandbox/simpel/Rakefile?rev=704611&r1=704610&r2=704611&view=diff
==============================================================================
--- ode/sandbox/simpel/Rakefile (original)
+++ ode/sandbox/simpel/Rakefile Tue Oct 14 11:49:06 2008
@@ -70,8 +70,10 @@
walker_txt = File.read(walker)
patch_walker = lambda do |regx, offset, txt|
- insrt_idx = walker_txt.index(regx)
- walker_txt.insert(insrt_idx + offset, txt)
+ insrt_idx = 0
+ while (insrt_idx = walker_txt.index(regx, insrt_idx+1)) do
+ walker_txt.insert(insrt_idx + offset, txt)
+ end
end
patch_walker[/SimPELWalker.g(.*)ns_id$/, 51, "ids =
(LinkedListTree)input.LT(1);"]
patch_walker[/SimPELWalker.g(.*) \( path_expr \)$/, 37, "lv =
(LinkedListTree)input.LT(1);"]
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=704611&r1=704610&r2=704611&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 Oct 14 11:49:06 2008
@@ -139,11 +139,16 @@
(^(ELSE b2=(body)))?);
while_ex
-scope ExprContext;
+scope ExprContext Parent;
: ^(WHILE {
$ExprContext::expr = new SimPELExpr(builder.getProcess());
}
- expr body);
+ e=(expr) {
+ $ExprContext::expr.setExpr(deepText($e));
+ OBuilder.StructuredActivity<OWhile> owhile =
builder.build(OWhile.class, $BPELScope::oscope, $Parent[-1]::activity,
$ExprContext::expr);
+ $Parent::activity = owhile;
+ }
+ body);
until_ex
scope ExprContext;
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=704611&r1=704610&r2=704611&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 Oct 14 11:49:06 2008
@@ -42,7 +42,10 @@
public boolean evaluateAsBoolean(OExpression oexpr, EvaluationContext
evaluationContext) throws FaultException {
// TODO context caching
Context cx = ContextFactory.getGlobal().enterContext();
- ODEDelegator scope = new ODEDelegator(cx.initStandardObjects(),
evaluationContext, (SimPELExpr)oexpr, cx);
+ cx.setOptimizationLevel(-1);
+
+ Scriptable parentScope = getScope(cx, oexpr);
+ ODEDelegator scope = new ODEDelegator(parentScope, evaluationContext,
(SimPELExpr)oexpr, cx);
// First evaluating the assignment
SimPELExpr expr = (SimPELExpr) oexpr;
@@ -61,24 +64,7 @@
Context cx = ContextFactory.getGlobal().enterContext();
cx.setOptimizationLevel(-1);
- Scriptable parentScope;
- if (oexpr.getOwner().globalState != null) {
- parentScope = globalStateCache.get(oexpr.getOwner().getGuid());
- if (parentScope == null) {
- Scriptable sharedScope = cx.initStandardObjects();
- try {
- ObjectInputStream in = new ScriptableInputStream(new
ByteArrayInputStream(oexpr.getOwner().globalState), sharedScope);
- parentScope = (Scriptable) in.readObject();
- in.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- globalStateCache.put(oexpr.getOwner().getGuid(), parentScope);
- }
- } else {
- parentScope = cx.initStandardObjects();
- }
-
+ Scriptable parentScope = getScope(cx, oexpr);
ODEDelegator scope = new ODEDelegator(parentScope, evaluationContext,
(SimPELExpr)oexpr, cx);
// First evaluating the assignment
@@ -89,8 +75,13 @@
Object res = cx.evaluateString(scope, forged, "<expr>", 0, null);
// Second extracting the resulting variable value
- if (expr.getLValue() != null)
+ if (expr.getLValue() != null) {
res = scope.getEnv().get(expr.getLVariable());
+ OVarType varType =
expr.getReferencedVariable(expr.getLVariable()).type;
+ // Setting variables runtime type
+ if (res instanceof String) varType.underlyingType =
OVarType.STRING_TYPE;
+ if (res instanceof Number) varType.underlyingType =
OVarType.NUMBER_TYPE;
+ }
ArrayList<Node> resList = new ArrayList<Node>(1);
if (res instanceof String || res instanceof Number) {
@@ -150,9 +141,9 @@
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 {
+ // This assumes message type with a single part
if (v.type instanceof OMessageVarType)
node =
_evaluationContext.readVariable(v,((OMessageVarType)v.type).parts.values().iterator().next());
else
@@ -162,10 +153,19 @@
else throw e;
}
// Simple types
- if (node.getNodeValue() != null) return node.getNodeValue();
- else if (node.getNodeType() == Node.ELEMENT_NODE) {
+ // TODO I think the sumple type case never exists anymore
(stuff get wrapped), remove this
+ if (node.getNodeValue() != null) {
+ String rawValue = node.getNodeValue();
+ if (v.type.underlyingType == OVarType.SCHEMA_TYPE ||
v.type.underlyingType == OVarType.STRING_TYPE)
+ return rawValue;
+ if (v.type.underlyingType == OVarType.NUMBER_TYPE) return
Double.valueOf(rawValue);
+ } else if (node.getNodeType() == Node.ELEMENT_NODE) {
Element nodeElmt = (Element) node;
- if (DOMUtils.getFirstChildElement(nodeElmt) == null)
return nodeElmt.getTextContent();
+ if (DOMUtils.getFirstChildElement(nodeElmt) == null) {
+ String rawValue = nodeElmt.getTextContent();
+ if (v.type.underlyingType == OVarType.NUMBER_TYPE)
return Double.valueOf(rawValue);
+ else return rawValue;
+ }
else node = DOMUtils.getFirstChildElement((Element)node);
}
@@ -213,6 +213,27 @@
}
}
+ public Scriptable getScope(Context cx, OExpression oexpr) {
+ Scriptable parentScope;
+ if (oexpr.getOwner().globalState != null) {
+ parentScope = globalStateCache.get(oexpr.getOwner().getGuid());
+ if (parentScope == null) {
+ Scriptable sharedScope = cx.initStandardObjects();
+ try {
+ ObjectInputStream in = new ScriptableInputStream(new
ByteArrayInputStream(oexpr.getOwner().globalState), sharedScope);
+ parentScope = (Scriptable) in.readObject();
+ in.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ globalStateCache.put(oexpr.getOwner().getGuid(), parentScope);
+ }
+ } else {
+ parentScope = cx.initStandardObjects();
+ }
+ return parentScope;
+ }
+
// Can someone tell me why I have to implement this? The Java API just
sucks.
public static String join(String[] ss) {
StringBuffer buffer = new StringBuffer();
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=704611&r1=704610&r2=704611&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 Oct 14 11:49:06 2008
@@ -139,6 +139,16 @@
};
}
+ public StructuredActivity<OWhile> buildWhile(final OWhile owhile, OScope
parentScope, SimPELExpr whileExpr) {
+ owhile.whileCondition = whileExpr;
+ owhile.whileCondition.expressionLanguage = _exprLang;
+ return new StructuredActivity<OWhile>(owhile) {
+ public void run(OActivity child) {
+ owhile.activity = child;
+ }
+ };
+ }
+
public SimpleActivity buildPickReceive(OPickReceive receive, OScope
oscope, String partnerLink, String operation) {
OPickReceive.OnMessage onMessage = new
OPickReceive.OnMessage(_oprocess);
onMessage.partnerLink = buildPartnerLink(oscope, partnerLink,
operation, true, true);
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=704611&r1=704610&r2=704611&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 Oct 14 11:49:06 2008
@@ -248,4 +248,29 @@
assertTrue(DOMUtils.domToString(result).indexOf("foobar") > 0);
}
+ private static final String WHILE_LOOP =
+ "process WhileLoop { \n" +
+ " receive(myPl, firstOp) { |counter| \n" +
+ " i = 0; j = 1; cur = 1; \n" +
+ " while (cur <= counter) { \n" +
+ " k = i; i = j; j = k+j; cur = cur+1; \n" +
+ " } \n" +
+ " reply(i); \n" +
+ " }\n" +
+ "}";
+
+ public void testWhile() throws Exception {
+ EmbeddedServer server = new EmbeddedServer();
+ server.start();
+ server.deploy(WHILE_LOOP);
+
+ Document doc = DOMUtils.newDocument();
+ Element wrapper =
doc.createElementNS("http://ode.apache.org/simpel/1.0/definition/WhileLoop",
"firstOpRequest");
+ wrapper.setTextContent("20");
+
+ Element result = server.sendMessage("myPl", "firstOp", wrapper);
+ System.out.println(":: " + DOMUtils.domToString(result));
+ assertTrue(DOMUtils.domToString(result).indexOf("6765") > 0);
+ }
+
}