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 2009/01/21 02:31:48 UTC
svn commit: r736189 - in /ode/sandbox/simpel/src:
main/antlr/org/apache/ode/simpel/antlr/ main/java/org/apache/ode/embed/
main/java/org/apache/ode/simpel/ main/java/org/apache/ode/simpel/omodel/
main/java/org/apache/ode/simpel/util/ test/java/org/apach...
Author: mriou
Date: Tue Jan 20 17:31:47 2009
New Revision: 736189
URL: http://svn.apache.org/viewvc?rev=736189&view=rev
Log:
Cleaned up error reporting during semantic analysis using the same facilities as the parser.
Modified:
ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g
ode/sandbox/simpel/src/main/java/org/apache/ode/embed/EmbeddedStore.java
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/ErrorListener.java
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java
ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java
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=736189&r1=736188&r2=736189&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 Jan 20 17:31:47 2009
@@ -110,7 +110,7 @@
param_block
scope Parent;
: ^(SEQUENCE ID+
- { OBuilder.StructuredActivity seq = builder.build(OSequence.class, $BPELScope::oscope, $Parent[-1]::activity);
+ { OBuilder.StructuredActivity seq = builder.build($ID, OSequence.class, $BPELScope::oscope, $Parent[-1]::activity);
$Parent::activity = seq;
builder.setBlockParam($BPELScope::oscope, (OSequence)seq.getOActivity(), $ID.text);
}
@@ -136,7 +136,8 @@
}
e=(expr) {
$ExprContext::expr.setExpr(deepText($e));
- OBuilder.StructuredActivity<OSwitch> oswitch = builder.build(OSwitch.class, $BPELScope::oscope, $Parent[-1]::activity, $ExprContext::expr);
+ OBuilder.StructuredActivity<OSwitch> oswitch = builder.build($e, OSwitch.class,
+ $BPELScope::oscope, $Parent[-1]::activity, $ExprContext::expr);
$Parent::activity = oswitch;
} b1=(body)
(^(ELSE b2=(body)))?);
@@ -148,7 +149,8 @@
}
e=(expr) {
$ExprContext::expr.setExpr(deepText($e));
- OBuilder.StructuredActivity<OWhile> owhile = builder.build(OWhile.class, $BPELScope::oscope, $Parent[-1]::activity, $ExprContext::expr);
+ OBuilder.StructuredActivity<OWhile> owhile = builder.build($e, OWhile.class,
+ $BPELScope::oscope, $Parent[-1]::activity, $ExprContext::expr);
$Parent::activity = owhile;
}
body);
@@ -187,8 +189,8 @@
onquery
scope ReceiveBlock Parent;
: ^(ONQUERY ID {
- OBuilder.StructuredActivity<OEventHandler.OEvent> on = builder
- .build(OEventHandler.OEvent.class, $BPELScope::oscope, $Parent[-1]::activity, deepText($ID), "GET");
+ OBuilder.StructuredActivity<OEventHandler.OEvent> on = builder.build($ID, OEventHandler.OEvent.class,
+ $BPELScope::oscope, $Parent[-1]::activity, deepText($ID), "GET");
$ReceiveBlock::activity = (OComm) on.getOActivity();
$Parent::activity = on;
}
@@ -196,8 +198,8 @@
onrec
scope ReceiveBlock Parent;
: ^(ONRECEIVE ID {
- OBuilder.StructuredActivity<OEventHandler.OEvent> on = builder
- .build(OEventHandler.OEvent.class, $BPELScope::oscope, $Parent[-1]::activity, deepText($ID), "POST");
+ OBuilder.StructuredActivity<OEventHandler.OEvent> on = builder.build($ID, OEventHandler.OEvent.class,
+ $BPELScope::oscope, $Parent[-1]::activity, deepText($ID), "POST");
$ReceiveBlock::activity = (OComm) on.getOActivity();
$Parent::activity = on;
}
@@ -205,8 +207,8 @@
onupd
scope ReceiveBlock Parent;
: ^(ONUPDATE ID {
- OBuilder.StructuredActivity<OEventHandler.OEvent> on = builder
- .build(OEventHandler.OEvent.class, $BPELScope::oscope, $Parent[-1]::activity, deepText($ID), "PUT");
+ OBuilder.StructuredActivity<OEventHandler.OEvent> on = builder.build($ID, OEventHandler.OEvent.class,
+ $BPELScope::oscope, $Parent[-1]::activity, deepText($ID), "PUT");
$ReceiveBlock::activity = (OComm) on.getOActivity();
$Parent::activity = on;
}
@@ -227,7 +229,7 @@
invoke
scope ReceiveBlock;
: ^(INVOKE ^(p=ID o=ID in=ID?)) {
- OBuilder.StructuredActivity<OInvoke> inv = builder.build(OInvoke.class, $BPELScope::oscope,
+ OBuilder.StructuredActivity<OInvoke> inv = builder.build($p, OInvoke.class, $BPELScope::oscope,
$Parent::activity, text($p), text($o), text($in), null);
$ReceiveBlock::activity = inv.getOActivity();
}
@@ -236,10 +238,10 @@
reply
: ^(REPLY msg=ID (pl=ID (op=ID)?)?) {
if (ReceiveBlock_stack.size() > 0)
- builder.build(OReply.class, $BPELScope::oscope, $Parent::activity,
+ builder.build($msg, OReply.class, $BPELScope::oscope, $Parent::activity,
$ReceiveBlock::activity, text($msg), text($pl), text($op));
else
- builder.build(OReply.class, $BPELScope::oscope, $Parent::activity,
+ builder.build($msg, OReply.class, $BPELScope::oscope, $Parent::activity,
null, text($msg), text($pl), text($op));
};
receive
@@ -248,10 +250,10 @@
// The receive input is the lvalue of the assignment expression in which this receive is enclosed (if it is)
OBuilder.StructuredActivity<OPickReceive> rec;
if (ExprContext_stack.size() > 0)
- rec = builder.build(OPickReceive.class, $BPELScope::oscope,
+ rec = builder.build($p, OPickReceive.class, $BPELScope::oscope,
$Parent::activity, text($p), text($o), $ExprContext::expr);
else
- rec = builder.build(OPickReceive.class, $BPELScope::oscope,
+ rec = builder.build($p, OPickReceive.class, $BPELScope::oscope,
$Parent::activity, text($p), text($o), null);
$ReceiveBlock::activity = rec.getOActivity().onMessages.get(0);
@@ -270,10 +272,10 @@
// The request output is the lvalue of the assignment expression in which this request is enclosed (if it is)
OBuilder.StructuredActivity<OInvoke> inv;
if (ExprContext_stack.size() > 1)
- inv = builder.build(OInvoke.class, $BPELScope::oscope,
+ inv = builder.build($e, OInvoke.class, $BPELScope::oscope,
$Parent::activity, $ExprContext::expr, text($meth), text($msg), $ExprContext[-1]::expr);
else
- inv = builder.build(OInvoke.class, $BPELScope::oscope,
+ inv = builder.build($e, OInvoke.class, $BPELScope::oscope,
$Parent::activity, $ExprContext::expr, text($meth), text($msg), null);
$ReceiveBlock::activity = inv.getOActivity();
@@ -292,7 +294,7 @@
$ExprContext::expr.setExpr(deepText($rv));
if (!"RESOURCE".equals($rv.getText()) && !"RECEIVE".equals($rv.getText()) && !"REQUEST".equals($rv.getText())) {
OBuilder.StructuredActivity<OAssign> assign =
- builder.build(OAssign.class, $BPELScope::oscope, $Parent::activity, $ExprContext::expr);
+ builder.build($rv, OAssign.class, $BPELScope::oscope, $Parent::activity, $ExprContext::expr);
// The long, winding road of abstraction
$ExprContext::expr = (SimPELExpr) ((OAssign.Expression)((OAssign.Copy)assign.
getOActivity().operations.get(0)).from).expression;
@@ -310,13 +312,13 @@
e=(expr)) {
$ExprContext::expr.setExpr(deepText($e));
OBuilder.StructuredActivity<OWait> wait =
- builder.build(OWait.class, $BPELScope::oscope, $Parent::activity, $ExprContext::expr);
+ builder.build($e, OWait.class, $BPELScope::oscope, $Parent::activity, $ExprContext::expr);
};
exit : EXIT;
// Other
-variable: ^(VARIABLE ID VAR_MODS*) { builder.addVariableDecl(text($ID), text($VAR_MODS)); };
+variable: ^(VARIABLE ID VAR_MODS*) { builder.addVariableDecl($ID, text($ID), text($VAR_MODS)); };
resource
scope ExprContext;
@@ -326,7 +328,7 @@
e=(expr)? ID?) {
$ExprContext::expr.setExpr(deepText($e));
// The resource name is the lvalue of the assignment expression in which this resource def is enclosed
- builder.addResourceDecl($BPELScope::oscope, $ExprContext[-1]::expr.getLValue(), $ExprContext::expr, text($ID));
+ builder.addResourceDecl($e, $BPELScope::oscope, $ExprContext[-1]::expr.getLValue(), $ExprContext::expr, text($ID));
};
partner_link
Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/embed/EmbeddedStore.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/embed/EmbeddedStore.java?rev=736189&r1=736188&r2=736189&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/embed/EmbeddedStore.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/embed/EmbeddedStore.java Tue Jan 20 17:31:47 2009
@@ -27,6 +27,7 @@
import org.apache.ode.bpel.rapi.Serializer;
import org.apache.ode.bpel.rapi.ProcessModel;
import org.apache.ode.simpel.SimPELCompiler;
+import org.apache.ode.simpel.CompilationException;
import org.apache.ode.Descriptor;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
@@ -51,7 +52,12 @@
private ArrayList<ProcessStoreListener> _listeners = new ArrayList<ProcessStoreListener>();
public Collection<QName> deploy(String processStr, Descriptor desc) {
- OProcess op = _compiler.compileProcess(processStr, desc);
+ OProcess op = null;
+ try {
+ op = _compiler.compileProcess(processStr, desc);
+ } catch (CompilationException e) {
+ System.err.println("There were errors during the compilation of a SimPEL process:\n" + e.toString());
+ }
_processes.put(op.getQName(), op);
fireEvent(new ProcessStoreEvent(ProcessStoreEvent.Type.DEPLOYED, op.getQName(), null));
Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/ErrorListener.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/ErrorListener.java?rev=736189&r1=736188&r2=736189&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/ErrorListener.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/ErrorListener.java Tue Jan 20 17:31:47 2009
@@ -1,7 +1,5 @@
package org.apache.ode.simpel;
-import org.antlr.runtime.RecognitionException;
-
import java.util.List;
/**
@@ -11,5 +9,5 @@
List<CompilationException.Error> getErrors();
- void reportRecognitionError(int line, int column, String message, RecognitionException e);
+ void reportRecognitionError(int line, int column, String message, Exception e);
}
Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java?rev=736189&r1=736188&r2=736189&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java Tue Jan 20 17:31:47 2009
@@ -114,7 +114,7 @@
// Pass the tree to the walker for compilation
CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
SimPELWalker walker = new SimPELWalker(nodes);
- OBuilder obuilder = new OBuilder(desc);
+ OBuilder obuilder = new OBuilder(desc, errListener);
walker.setBuilder(obuilder);
walker.setErrorListener(errListener);
HashMap<Integer, Integer> tokenMapping = buildTokenMap(E4XParser.tokenNames, E4XLexer.class, SimPELWalker.class);
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=736189&r1=736188&r2=736189&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 Jan 20 17:31:47 2009
@@ -11,8 +11,11 @@
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.simpel.CompilationException;
+import org.apache.ode.simpel.ErrorListener;
import org.apache.ode.utils.GUID;
import org.apache.ode.Descriptor;
+import org.antlr.runtime.tree.Tree;
import javax.wsdl.PortType;
import javax.xml.namespace.QName;
@@ -28,6 +31,8 @@
private static final String SIMPEL_NS = "http://ode.apache.org/simpel/1.0/definition";
private Descriptor _desc;
+ private ErrorListener errors;
+
private OExpressionLanguage _exprLang;
private OExpressionLanguage _konstExprLang;
private String _processNS;
@@ -37,15 +42,20 @@
private HashMap<String,ResourceDesc> webResources = new HashMap<String,ResourceDesc>();
private HashSet<String> typedVariables = new HashSet<String>();
- public OBuilder(Descriptor desc) {
+ public OBuilder(Descriptor desc, ErrorListener errors) {
HashMap<String, String> exprRuntime = new HashMap<String, String>();
exprRuntime.put("runtime-class", "org.apache.ode.simpel.expr.E4XExprRuntime");
_exprLang = new OExpressionLanguage(_oprocess, exprRuntime);
_exprLang.expressionLanguageUri = SIMPEL_NS + "/exprLang";
_desc = desc;
+ this.errors = errors;
}
public StructuredActivity build(Class oclass, OScope oscope, StructuredActivity parent, Object... params) {
+ return build(null, oclass, oscope, parent, params);
+ }
+
+ public StructuredActivity build(Tree t, Class oclass, OScope oscope, StructuredActivity parent, Object... params) {
try {
OActivity oactivity = (OActivity) oclass
.getConstructor(OProcess.class, OActivity.class).newInstance(_oprocess, parent.getOActivity());
@@ -62,8 +72,19 @@
StructuredActivity result = (StructuredActivity) buildMethod.invoke(this, buildParams);
if (result != null) parent.run((OActivity) result.getOActivity());
return result;
+ } catch (BuilderException e) {
+ // Report an error and try to recover from it to get further down in the tree
+ errors.reportRecognitionError(t != null ? t.getLine() : -1, t != null ? t.getCharPositionInLine() : -1, e.getMessage(), e);
+ return new SimpleActivity<OEmpty>(new OEmpty(_oprocess, (OActivity) parent.getOActivity()));
} catch (Exception e) {
- throw new RuntimeException("Couldn't build activity of type " + oclass, e);
+ // Unrecoverable error, trying to report as much as possible
+ errors.reportRecognitionError(t != null ? t.getLine() : -1, t != null ? t.getCharPositionInLine() : -1,
+ "Unrecoverable error, couldn't build activity of type " + oclass +
+ (t != null ? (" near " + t.getText()) : ""), e);
+
+ CompilationException ce = new CompilationException(e);
+ ce.errors = errors.getErrors();
+ throw ce;
}
}
@@ -77,6 +98,7 @@
}
public abstract void run(OActivity child);
}
+
public static class SimpleActivity<T> extends StructuredActivity<T> {
public SimpleActivity(T oact) {
super(oact);
@@ -111,7 +133,7 @@
if (_desc.isRestful()) {
SimPELExpr expr = new SimPELExpr(_oprocess);
expr.setExpr(_desc.getAddress() != null ? ("\""+_desc.getAddress()+"\"") : "\"/\"");
- addResourceDecl(processScope, "self", expr, null);
+ addResourceDecl(null, processScope, "self", expr, null);
}
return buildScope(processScope, null);
@@ -166,8 +188,9 @@
if (operation == null) {
onMessage.resource = copyResource(webResources.get(partnerLinkOrResource), "POST");
onMessage.resource.setInbound(true);
- if (onMessage.resource == null)
- throw new RuntimeException("Unknown resource declared in receive: " + partnerLinkOrResource);
+ if (onMessage.resource == null) {
+ throw new BuilderException("Unknown resource declared in receive: " + partnerLinkOrResource);
+ }
_oprocess.providedResources.add(onMessage.resource);
} else {
onMessage.partnerLink = buildPartnerLink(oscope, partnerLinkOrResource, operation, true, true);
@@ -197,6 +220,8 @@
}
public StructuredActivity buildEvent(final OEventHandler.OEvent oevent, OScope oscope, String resource, String method) {
+ if (webResources.get(resource) == null) throw new BuilderException("Unknown resource in event: " + resource);
+
oevent.resource = copyResource(webResources.get(resource), method);
_oprocess.providedResources.add(oevent.resource);
OScope eventScope = new OScope(_oprocess, oevent);
@@ -217,7 +242,7 @@
public SimpleActivity buildRequest(OInvoke invoke, OScope oscope, SimPELExpr expr, String method, String outgoingMsg, SimPELExpr responseMsg) {
if (method != null && (!method.equalsIgnoreCase("\"get\"") && !method.equalsIgnoreCase("\"put\"")
&& !method.equalsIgnoreCase("\"post\"") && !method.equalsIgnoreCase("\"delete\"")))
- throw new RuntimeException("Invalid HTTP method: " + method);
+ throw new BuilderException("Invalid HTTP method in request declaration: " + method);
expr.setExpr(expr.getExpr());
expr.expressionLanguage = _exprLang;
@@ -284,7 +309,7 @@
String var, String plinkOrRes, String operation) {
oreply.variable = resolveVariable(oscope, var, operation, false);
if (plinkOrRes == null) {
- if (ocomm == null) throw new RuntimeException("No parent receive but reply with var " + var +
+ if (ocomm == null) throw new BuilderException("No parent receive but reply with var " + var +
" has no plinkOrRes/operation or resource information.");
if (ocomm.isRestful()) {
oreply.resource = ocomm.getResource();
@@ -296,7 +321,7 @@
} else {
if (operation == null) {
ResourceDesc res = webResources.get(plinkOrRes);
- if (res == null) throw new RuntimeException("Couldn't resolve the reply using partner link " +
+ if (res == null) throw new BuilderException("Couldn't resolve the reply using partner link " +
"or resource " + plinkOrRes +". Either an operation is missing or the resource isn't recognized.");
oreply.resource = res.latest;
} else {
@@ -347,9 +372,13 @@
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);
+ public void addVariableDecl(Tree t, String varName, String modifiers) {
+ if (variables.get(varName) != null) {
+ errors.reportRecognitionError(t.getLine(), t.getCharPositionInLine(), "Variable " +
+ varName + " has already been declared.", null);
+ return;
+ }
+
if (modifiers == null) return;
if (modifiers.indexOf("unique") >= 0) {
@@ -373,7 +402,7 @@
}
}
- public void addResourceDecl(OScope scope, String resourceName, SimPELExpr pathExpr, String resourceRef) {
+ public void addResourceDecl(Tree t, OScope scope, String resourceName, SimPELExpr pathExpr, String resourceRef) {
ResourceDesc res = new ResourceDesc();
res.name = resourceName;
res.declaringScope = scope;
@@ -385,8 +414,11 @@
if (resourceRef != null) {
ResourceDesc reference = webResources.get(resourceRef);
- if (reference == null) throw new RuntimeException("Unknown resource reference " + resourceRef +
- " in the definition of resource " + resourceName);
+ if (reference == null) {
+ errors.reportRecognitionError(t != null ? t.getLine() : -1, t != null ? t.getCharPositionInLine() : -1,
+ "Unknown resource reference " + resourceRef + " in the definition of resource " + resourceName, null);
+ return;
+ }
res.reference = reference;
}
@@ -549,4 +581,10 @@
}
}
}
+
+ private static class BuilderException extends RuntimeException {
+ private BuilderException(String message) {
+ super(message);
+ }
+ }
}
Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java?rev=736189&r1=736188&r2=736189&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java Tue Jan 20 17:31:47 2009
@@ -18,7 +18,7 @@
return _errors;
}
- public void reportRecognitionError(int line, int column, String message, RecognitionException e) {
+ public void reportRecognitionError(int line, int column, String message, Exception e) {
_errors.add(new CompilationException.Error(line, column, message, e));
System.err.println(line + ":" + column + " " + message);
}
Modified: ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java?rev=736189&r1=736188&r2=736189&view=diff
==============================================================================
--- ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java (original)
+++ ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java Tue Jan 20 17:31:47 2009
@@ -142,7 +142,7 @@
return null;
}
- public void reportRecognitionError(int line, int column, String message, RecognitionException e) {
+ public void reportRecognitionError(int line, int column, String message, Exception e) {
messages.append(" - line ").append(line).append(": ").append(message).append("\n");
}
}