Author: mriou Date: Thu May 17 12:04:20 2007 New Revision: 539082 URL: http://svn.apache.org/viewvc?view=rev&rev=539082 Log: Reporting a sensible message when a varibale based on an inexistant message or a message with no part is used in an XPath expression.
Modified: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPathMessages.java incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpVariableResolver.java Modified: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPathMessages.java URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPathMessages.java?view=diff&rev=539082&r1=539081&r2=539082 ============================================================================== --- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPathMessages.java (original) +++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPathMessages.java Thu May 17 12:04:20 2007 @@ -32,74 +32,80 @@ return super.formatCompilationMessage("Couldn't configure XPath factory"); } + /** Invalid number of argument to function "{0}". */ + public CompilationMessage errInvalidNumberOfArguments(String functionName) { + return super.formatCompilationMessage("Invalid number of argument to function \"{0}\".", + functionName); + } + + /** Error compiling XSL Sheet "{0}" : {1}. */ + public CompilationMessage errXslCompilation(String xslName, String error) { + return super.formatCompilationMessage("Error compiling XSL Sheet \"{0}\" : {1}", + xslName, error); + } + + /** Attempt to use an unrecognized BPEL function "{0}". */ + public CompilationMessage errUnknownBpelFunction(String functionName) { + return super.formatCompilationMessage( + "Attempt to use an unrecognized BPEL function \"{0}\".", functionName); + } + + /** The expression "{0}" must be a literal string. */ + public CompilationMessage errLiteralExpected(String text) { + return super.formatCompilationMessage("The expression \"{0}\" must be a literal string.", + text); + } + + /** The prefix "{0}" on the XPath function "{1}" is not bound to a URI. */ + public CompilationMessage errUndeclaredFunctionPrefix(String prefix, String functionName) { + return super.formatCompilationMessage("The prefix \"{0}\" on the XPath function \"{1}\"" + + " is not bound to a URI.", prefix, functionName); + } + + /** + * The prefixed name "{0}" could not be dereferenced in this namespace + * context. + */ + public CompilationMessage errInvalidQName(String qnameStr) { + return super.formatCompilationMessage( + "The prefixed name \"{0}\" could not be dereferenced in this namespace context.", + qnameStr); + } + + /** The string "{0}" is not a valid XPath 1.0 expression. */ + public CompilationMessage errXPathSyntax(String xPathString) { + return super.formatCompilationMessage( + "The string \"{0}\" is not a valid XPath 1.0 expression.", xPathString); + } + + /** The string "{0}" is not a valid XPath 1.0 expression. */ + public CompilationMessage warnXPath20Syntax(String xPathString, String message) { + return super.formatCompilationMessage( + "The string \"{0}\" is not a valid XPath 2.0 expression: {1}", xPathString, message); + } + + /** The XPath node with value "{0}" was not a text node. */ + public CompilationMessage errUnexpectedNodeTypeForXPath(String string) { + return super.formatCompilationMessage( + "The XPath node with value \"{0}\" was not a text node.", string); + } + + /** Unexpected compilator error: {0} */ + public CompilationMessage errUnexpectedCompilationError(String string) { + return super.formatCompilationMessage( + "Unexpected compilation error: {0}", string); + } + + /** bpws:xsltStylesheetNotFound the declared stylesheet could not be found: {0} */ + public CompilationMessage errXsltStylesheetNotFound(String string) { + return super.formatCompilationMessage( + "bpws:xsltStylesheetNotFound the declared stylesheet could not be found: {0}", string); + } + + /** Invalid number of argument to function "{0}". */ + public CompilationMessage errExpressionMessageNoPart(String message) { + return super.formatCompilationMessage("Attempt to use the messageType variable {0} in an expression " + + " even though the associated message is undefined or has no part.", message); + } - /** Invalid number of argument to function "{0}". */ - public CompilationMessage errInvalidNumberOfArguments(String functionName) { - return super.formatCompilationMessage("Invalid number of argument to function \"{0}\".", - functionName); - } - - /** Error compiling XSL Sheet "{0}" : {1}. */ - public CompilationMessage errXslCompilation(String xslName, String error) { - return super.formatCompilationMessage("Error compiling XSL Sheet \"{0}\" : {1}", - xslName, error); - } - - /** Attempt to use an unrecognized BPEL function "{0}". */ - public CompilationMessage errUnknownBpelFunction(String functionName) { - return super.formatCompilationMessage( - "Attempt to use an unrecognized BPEL function \"{0}\".", functionName); - } - - /** The expression "{0}" must be a literal string. */ - public CompilationMessage errLiteralExpected(String text) { - return super.formatCompilationMessage("The expression \"{0}\" must be a literal string.", - text); - } - - /** The prefix "{0}" on the XPath function "{1}" is not bound to a URI. */ - public CompilationMessage errUndeclaredFunctionPrefix(String prefix, String functionName) { - return super.formatCompilationMessage("The prefix \"{0}\" on the XPath function \"{1}\"" - + " is not bound to a URI.", prefix, functionName); - } - - /** - * The prefixed name "{0}" could not be dereferenced in this namespace - * context. - */ - public CompilationMessage errInvalidQName(String qnameStr) { - return super.formatCompilationMessage( - "The prefixed name \"{0}\" could not be dereferenced in this namespace context.", - qnameStr); - } - - /** The string "{0}" is not a valid XPath 1.0 expression. */ - public CompilationMessage errXPathSyntax(String xPathString) { - return super.formatCompilationMessage( - "The string \"{0}\" is not a valid XPath 1.0 expression.", xPathString); - } - - /** The string "{0}" is not a valid XPath 1.0 expression. */ - public CompilationMessage warnXPath20Syntax(String xPathString, String message) { - return super.formatCompilationMessage( - "The string \"{0}\" is not a valid XPath 2.0 expression: {1}", xPathString, message); - } - - /** The XPath node with value "{0}" was not a text node. */ - public CompilationMessage errUnexpectedNodeTypeForXPath(String string) { - return super.formatCompilationMessage( - "The XPath node with value \"{0}\" was not a text node.", string); - } - - /** Unexpected compilator error: {0} */ - public CompilationMessage errUnexpectedCompilationError(String string) { - return super.formatCompilationMessage( - "Unexpected compilation error: {0}", string); - } - - /** bpws:xsltStylesheetNotFound the declared stylesheet could not be found: {0} */ - public CompilationMessage errXsltStylesheetNotFound(String string) { - return super.formatCompilationMessage( - "bpws:xsltStylesheetNotFound the declared stylesheet could not be found: {0}", string); - } } Modified: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpVariableResolver.java URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpVariableResolver.java?view=diff&rev=539082&r1=539081&r2=539082 ============================================================================== --- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpVariableResolver.java (original) +++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpVariableResolver.java Thu May 17 12:04:20 2007 @@ -21,6 +21,7 @@ import org.apache.ode.bpel.compiler.api.CompilationException; import org.apache.ode.bpel.compiler.api.CompilerContext; +import org.apache.ode.bpel.elang.xpath10.compiler.XPathMessages; import org.apache.ode.bpel.elang.xpath10.o.OXPath10ExpressionBPEL20; import org.apache.ode.bpel.o.OElementVarType; import org.apache.ode.bpel.o.OLink; @@ -28,8 +29,9 @@ import org.apache.ode.bpel.o.OScope; import org.apache.ode.bpel.o.OVarType; import org.apache.ode.bpel.o.OXsdTypeVarType; -import org.apache.ode.utils.Namespaces; import org.apache.ode.utils.DOMUtils; +import org.apache.ode.utils.Namespaces; +import org.apache.ode.utils.msg.MessageBundle; import org.w3c.dom.Document; import javax.xml.namespace.QName; @@ -44,6 +46,8 @@ */ public class JaxpVariableResolver implements XPathVariableResolver { + private static final XPathMessages __msgs = MessageBundle.getMessages(XPathMessages.class); + private CompilerContext _cctx; private OXPath10ExpressionBPEL20 _oxpath; @@ -72,21 +76,23 @@ name = name.substring(0,dot); OScope.Variable var = _cctx.resolveVariable(name); _oxpath.vars.put(name, var); - return extractValue(var.type); + return extractValue(var, var.type); } } catch (CompilationException e) { throw new WrappedResolverException(e); } } - private Object extractValue(OVarType varType) { + private Object extractValue(OScope.Variable var, OVarType varType) { if (varType instanceof OXsdTypeVarType) { return generateFromType(((OXsdTypeVarType)varType).xsdType); } else if (varType instanceof OElementVarType) { return generateFromType(((OElementVarType)varType).elementType); } else if (varType instanceof OMessageVarType) { // MR That's an ugly hack but otherwise, xpath compilation doesn't work - return extractValue( ((OMessageVarType.Part) ((OMessageVarType)varType).parts.values().iterator().next()).type); + if (((OMessageVarType)varType).parts.size() == 0) + throw new WrappedResolverException(__msgs.errExpressionMessageNoPart(var.name)); + return extractValue(var, ((OMessageVarType)varType).parts.values().iterator().next().type); } return ""; }