Author: mszefler
Date: Thu Oct 26 14:47:04 2006
New Revision: 468152

URL: http://svn.apache.org/viewvc?view=rev&rev=468152
Log:
Moved XPath10 compilation code from bpel-el-xpath10

Added:
    
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/
    
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/CompilationExceptionWrapper.java
   (with props)
    
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/Constants.java
   (with props)
    
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/JaxenBpelHandler.java
   (with props)
    
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerBPEL11.java
   (with props)
    
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerBPEL20.java
   (with props)
    
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerImpl.java
   (with props)
    
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPathMessages.java
   (with props)
    
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XslCompilationErrorListener.java
   (with props)
    
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XslCompileUriResolver.java
   (with props)

Added: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/CompilationExceptionWrapper.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/CompilationExceptionWrapper.java?view=auto&rev=468152
==============================================================================
--- 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/CompilationExceptionWrapper.java
 (added)
+++ 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/CompilationExceptionWrapper.java
 Thu Oct 26 14:47:04 2006
@@ -0,0 +1,39 @@
+/*
+ * 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.elang.xpath10.compiler;
+
+import org.apache.ode.bpel.compiler.api.CompilationException;
+
+import org.jaxen.JaxenException;
+
+
+/**
+ * Jaxen-compliant wrapper for [EMAIL PROTECTED] 
org.apache.ode.bpel.compiler.api.CompilationException}.
+ */
+class CompilationExceptionWrapper extends JaxenException {
+
+  public CompilationExceptionWrapper(CompilationException cause) {
+    super(cause);
+    assert getCompilationException() != null;
+  }
+
+  public CompilationException getCompilationException() {
+    return (CompilationException) getCause();
+  }
+}

Propchange: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/CompilationExceptionWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/Constants.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/Constants.java?view=auto&rev=468152
==============================================================================
--- 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/Constants.java
 (added)
+++ 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/Constants.java
 Thu Oct 26 14:47:04 2006
@@ -0,0 +1,52 @@
+/*
+ * 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.elang.xpath10.compiler;
+
+/**
+ * XPath-4-BPEL related constants.
+ */
+class Constants {
+  /**
+   * Extension function bpws:getVariableData('variableName', 'partName'?,
+   * 'locationPath'?)
+   */
+  public static final String EXT_FUNCTION_GETVARIABLEDATA = "getVariableData";
+
+  /**
+   * Extension function
+   * bpws:getVariableProperty('variableName','propertyName')
+   */
+  public static final String EXT_FUNCTION_GETVARIABLEPROPRTY = 
"getVariableProperty";
+
+  /**
+   * Extension function bpws:getLinkStatus('getLinkName')
+   */
+  public static final String EXT_FUNCTION_GETLINKSTATUS = "getLinkStatus";
+
+  /**
+   * Extension function bpws:doXslTransform('xslSheetUri', node-set, 
(xslParamKey, xslParamValue)*)
+   */
+  public static final String EXT_FUNCTION_DOXSLTRANSFORM = "doXslTransform";
+
+  public static final String BPEL20_NS = 
"http://schemas.xmlsoap.org/ws/2004/03/business-process/";;
+  public static final String BPEL11_NS = 
"http://schemas.xmlsoap.org/ws/2003/03/business-process/";;
+
+  public static final String NS_ODE_MESSAGE = 
"http://www.fivesight.com/ode/message";;
+
+}

Propchange: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/Constants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/JaxenBpelHandler.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/JaxenBpelHandler.java?view=auto&rev=468152
==============================================================================
--- 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/JaxenBpelHandler.java
 (added)
+++ 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/JaxenBpelHandler.java
 Thu Oct 26 14:47:04 2006
@@ -0,0 +1,250 @@
+/*
+ * 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.elang.xpath10.compiler;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.compiler.api.CompilerContext;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10ExpressionBPEL20;
+import org.apache.ode.bpel.o.OExpression;
+import org.apache.ode.bpel.o.OLink;
+import org.apache.ode.bpel.o.OMessageVarType;
+import org.apache.ode.bpel.o.OProcess;
+import org.apache.ode.bpel.o.OScope;
+import org.apache.ode.bpel.o.OXslSheet;
+import org.apache.ode.utils.NSContext;
+import org.apache.ode.utils.msg.MessageBundle;
+import org.apache.ode.utils.xsl.XslTransformHandler;
+import org.jaxen.JaxenException;
+import org.jaxen.JaxenHandler;
+import org.jaxen.expr.Expr;
+import org.jaxen.expr.FunctionCallExpr;
+import org.jaxen.expr.LiteralExpr;
+
+
+/**
+ * Verifies validity of bpel extensions for xpath expressions
+ */
+class JaxenBpelHandler extends JaxenHandler {
+  private static final XPathMessages __msgs = 
MessageBundle.getMessages(XPathMessages.class);
+
+  private CompilerContext _cctx;
+  private OXPath10Expression _out;
+  private NSContext _nsContext;
+  private String _bpelNsUril;
+
+  JaxenBpelHandler(String bpelNsUri, OXPath10Expression out, NSContext 
nsContext, CompilerContext cctx) {
+    _bpelNsUril = bpelNsUri;
+    _cctx = cctx;
+    _nsContext = nsContext;
+    _out = out;
+
+    assert nsContext != null;
+    assert cctx != null;
+    assert out != null;
+  }
+
+       public void variableReference(String prefix, String variableName)
+                       throws JaxenException {
+               super.variableReference(prefix, variableName);
+
+    // Custom variables
+    if ("ode".equals(prefix)) {
+      if ("pid".equals(variableName)) return;
+    }
+
+    if(_out instanceof OXPath10ExpressionBPEL20){
+                       OXPath10ExpressionBPEL20 out = 
(OXPath10ExpressionBPEL20)_out;
+                       try{
+                               if(out.isJoinExpression){
+                                       // these resolve to links
+                                       OLink olink = 
_cctx.resolveLink(variableName);
+                                       _out.links.put(variableName, olink);
+                               }else{
+                                       int dot = variableName.indexOf('.');
+                                       if (dot != -1)
+                                               variableName = 
variableName.substring(0,dot);
+                                       OScope.Variable var = 
_cctx.resolveVariable(variableName);
+                                       _out.vars.put(variableName, var);
+                               }
+                       }catch(CompilationException ce){
+                               throw new CompilationExceptionWrapper(ce);
+                       }
+               }
+       }
+  
+  public void endXPath() throws JaxenException {
+    super.endXPath();
+  }
+
+  /**
+   */
+  public void endFunction()
+                   throws JaxenException {
+    super.endFunction();
+
+    FunctionCallExpr c = (FunctionCallExpr)peekFrame()
+                                             .getLast();
+
+    String prefix = c.getPrefix();
+
+    // empty string prefix should resolve to xpath namespace, NOT bpel
+    if ((prefix == null) || "".equals(prefix)) {
+      return;
+    }
+
+    String ns = _nsContext.getNamespaceURI(prefix);
+
+    if (ns == null) {
+      throw new CompilationException(
+          __msgs.errUndeclaredFunctionPrefix(prefix,c.getFunctionName()));
+    } else if (isBpelNamespace(ns)) {
+      try {
+        if 
(Constants.EXT_FUNCTION_GETVARIABLEDATA.equals(c.getFunctionName())) {
+          compileGetVariableData(c);
+        } else if (Constants.EXT_FUNCTION_GETVARIABLEPROPRTY.equals(c
+                .getFunctionName())) {
+          compileGetVariableProperty(c);
+        } else if 
(Constants.EXT_FUNCTION_GETLINKSTATUS.equals(c.getFunctionName())) {
+          compileGetLinkStatus(c);
+        } else if 
(Constants.EXT_FUNCTION_DOXSLTRANSFORM.equals(c.getFunctionName())) {
+          compileDoXslTransform(c);
+        } else {
+          throw new 
CompilationException(__msgs.errUnknownBpelFunction(c.getFunctionName()));
+        }
+      } catch (CompilationException ce) {
+        throw new CompilationExceptionWrapper(ce);
+      }
+    }
+  }
+
+  private boolean isBpelNamespace(String ns) {
+    return ns.equals(_bpelNsUril);
+  }
+
+  private void compileGetLinkStatus(FunctionCallExpr c)
+                           throws CompilationException {
+    List params = c.getParameters();
+
+    if (params.size() != 1) {
+      throw  new 
CompilationException(__msgs.errInvalidNumberOfArguments(c.getFunctionName()));
+    }
+
+    String linkName = getLiteralFromExpression((Expr)params.get(0));
+
+    OLink olink = _cctx.resolveLink(linkName);
+    _out.links.put(linkName, olink);
+  }
+
+  /**
+   * Compile a <code>bpws:getVariableData(...)</em> function call. Note that 
all arguments
+   * to this call <em>must</em> be literal values. Therefore, we are able to 
"pre-compile"
+   * all possible invocations of this call, and save ourselves the problem of 
compiling
+   * query expressions at runtime.
+   * @param c [EMAIL PROTECTED] FunctionCallExpr} for this invocation
+   * @throws CompilationException
+   */
+  private void compileGetVariableData(FunctionCallExpr c)
+                                     throws CompilationException {
+    List params = c.getParameters();
+
+    if (params.size() < 1 || params.size() > 3) {
+      throw new CompilationException(
+                                
__msgs.errInvalidNumberOfArguments(c.getFunctionName()));
+
+    }
+    String varname = getLiteralFromExpression((Expr)params.get(0));
+    String partname = params.size() > 1 ? 
getLiteralFromExpression((Expr)params.get(1)) : null;
+    String locationstr = params.size() > 2 ? 
getLiteralFromExpression((Expr)params.get(2)) : null;
+
+    OScope.Variable var = _cctx.resolveVariable(varname);
+    OMessageVarType.Part part = partname != null ? 
_cctx.resolvePart(var,partname) : null;
+    OExpression location = null;
+    if (locationstr != null) {
+      location = _cctx.compileExpr(locationstr,_nsContext);
+    }
+
+    _out.addGetVariableDataSig(varname, partname, locationstr,
+            new 
OXPath10Expression.OSigGetVariableData(_cctx.getOProcess(),var, part,location));
+
+  }
+
+  private void compileGetVariableProperty(FunctionCallExpr c)
+                                 throws CompilationException{
+    List params = c.getParameters();
+
+    if (params.size() != 2) {
+      throw new CompilationException(
+                          
__msgs.errInvalidNumberOfArguments(Constants.EXT_FUNCTION_GETVARIABLEPROPRTY));
+    }
+
+    String varName = getLiteralFromExpression((Expr)params.get(0));
+    OScope.Variable v = _cctx.resolveVariable(varName);
+    _out.vars.put(varName, v);
+
+    String propName = getLiteralFromExpression((Expr)params.get(1));
+    QName qname = _nsContext.derefQName(propName);
+
+    if (qname == null)
+      throw new CompilationException(
+                                __msgs.errInvalidQName(propName));
+
+    OProcess.OProperty property = _cctx.resolveProperty(qname);
+    // Make sure we can...
+    _cctx.resolvePropertyAlias(v, qname);
+
+    _out.properties.put(propName, property);
+    _out.vars.put(varName, v);
+  }
+
+  private void compileDoXslTransform(FunctionCallExpr c) throws 
CompilationException {
+    List params = c.getParameters();
+    if (params.size() < 2 || params.size() % 2 != 0) {
+      throw new CompilationException(
+          
__msgs.errInvalidNumberOfArguments(Constants.EXT_FUNCTION_DOXSLTRANSFORM));
+    }
+
+    String xslUri = getLiteralFromExpression((Expr)params.get(0));
+    OXslSheet xslSheet = _cctx.compileXslt(xslUri);
+    try {
+      XslTransformHandler.getInstance().parseXSLSheet(xslSheet.uri, 
xslSheet.sheetBody,
+                      new XslCompileUriResolver(_cctx, _out));
+    } catch (Exception e) {
+      throw new CompilationException(
+          __msgs.errInvalidNumberOfArguments(xslUri));
+    }
+
+    _out.xslSheets.put(xslSheet.uri, xslSheet);
+  }
+
+  private String getLiteralFromExpression(Expr expr)
+      throws CompilationException {
+    expr = expr.simplify();
+
+    if (expr instanceof LiteralExpr)
+      return ((LiteralExpr)expr).getLiteral();
+
+    throw new CompilationException(__msgs.errLiteralExpected(expr.getText()));
+  }
+
+}

Propchange: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/JaxenBpelHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerBPEL11.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerBPEL11.java?view=auto&rev=468152
==============================================================================
--- 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerBPEL11.java
 (added)
+++ 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerBPEL11.java
 Thu Oct 26 14:47:04 2006
@@ -0,0 +1,60 @@
+/*
+ * 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.elang.xpath10.compiler;
+
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.compiler.bom.Expression;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
+import org.apache.ode.bpel.o.OExpression;
+import org.apache.ode.bpel.o.OLValueExpression;
+
+/**
+ * XPath 1.0 expression compiler for BPEL v1.1.
+ */
+public class XPath10ExpressionCompilerBPEL11 extends 
XPath10ExpressionCompilerImpl {
+  public XPath10ExpressionCompilerBPEL11() {
+    super(Constants.BPEL11_NS);
+  }
+  
+  /**
+   * @see 
org.apache.ode.bpel.compiler.api.ExpressionCompiler#compileJoinCondition(java.lang.Object)
+   */
+  public OExpression compileJoinCondition(Object source) throws 
CompilationException {
+       return compile(source);
+  }
+  
+  public OLValueExpression compileLValue(Object source) throws 
CompilationException {
+       throw new UnsupportedOperationException("Not supported for bpel 1.1");
+  }
+
+  /**
+   * @see 
org.apache.ode.bpel.compiler.api.ExpressionCompiler#compile(java.lang.Object)
+   */
+  public OExpression compile(Object source) throws CompilationException {
+    Expression xpath = (Expression)source;
+    OXPath10Expression oexp = new OXPath10Expression(
+            _compilerContext.getOProcess(),
+            _qnFnGetVariableData,
+            _qnFnGetVariableProperty,
+            _qnFnGetLinkStatus);
+    oexp.namespaceCtx = xpath.getNamespaceContext();
+    doJaxenCompile(oexp, xpath);
+    return oexp;
+  }
+}

Propchange: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerBPEL11.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerBPEL20.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerBPEL20.java?view=auto&rev=468152
==============================================================================
--- 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerBPEL20.java
 (added)
+++ 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerBPEL20.java
 Thu Oct 26 14:47:04 2006
@@ -0,0 +1,91 @@
+/*
+ * 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.elang.xpath10.compiler;
+
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.compiler.api.CompilerContext;
+import org.apache.ode.bpel.compiler.bom.Expression;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10ExpressionBPEL20;
+import org.apache.ode.bpel.o.OExpression;
+import org.apache.ode.bpel.o.OLValueExpression;
+import org.apache.ode.utils.xsl.XslTransformHandler;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.TransformerFactory;
+
+/**
+ * XPath 1.0 expression compiler for BPEL 2.0
+ */
+public class XPath10ExpressionCompilerBPEL20 extends 
XPath10ExpressionCompilerImpl {
+
+  protected QName _qnDoXslTransform;
+
+  public XPath10ExpressionCompilerBPEL20() {
+    super(Constants.BPEL20_NS);
+    TransformerFactory trsf = new net.sf.saxon.TransformerFactoryImpl();
+    XslTransformHandler.getInstance().setTransformerFactory(trsf);
+
+    _qnDoXslTransform = new QName(Constants.BPEL20_NS, "doXslTransform");
+  }
+
+  /**
+   * @see 
org.apache.ode.bpel.compiler.api.ExpressionCompiler#compileJoinCondition(java.lang.Object)
+   */
+  public OExpression compileJoinCondition(Object source) throws 
CompilationException {
+    return _compile((Expression)source, true);
+  }
+
+  @Override
+  public void setCompilerContext(CompilerContext ctx) {
+      super.setCompilerContext(ctx);
+      XslCompilationErrorListener xe = new XslCompilationErrorListener(ctx);
+      XslTransformHandler.getInstance().setErrorListener(xe);
+  }
+  /**
+   * @see 
org.apache.ode.bpel.compiler.api.ExpressionCompiler#compile(java.lang.Object)
+   */
+  public OExpression compile(Object source) throws CompilationException {
+    return _compile((Expression)source, false);
+  }
+  /**
+   * @see 
org.apache.ode.bpel.compiler.api.ExpressionCompiler#compileLValue(java.lang.Object)
+   */
+  public OLValueExpression compileLValue(Object source) throws 
CompilationException {
+    return (OLValueExpression)_compile((Expression)source, false);
+  }
+
+  /**
+   * @see org.apache.ode.bpel.capi.ExpressionCompiler#compile(java.lang.Object)
+   */
+  private OExpression _compile(Expression xpath, boolean isJoinCondition) 
throws CompilationException {
+    OXPath10Expression oexp = new OXPath10ExpressionBPEL20(
+            _compilerContext.getOProcess(),
+            _qnFnGetVariableData,
+            _qnFnGetVariableProperty,
+            _qnFnGetLinkStatus,
+            _qnDoXslTransform,
+            isJoinCondition);
+    oexp.namespaceCtx = xpath.getNamespaceContext();
+    doJaxenCompile(oexp, xpath);
+    return oexp;
+  }
+
+
+}

Propchange: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerBPEL20.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerImpl.java?view=auto&rev=468152
==============================================================================
--- 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerImpl.java
 (added)
+++ 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerImpl.java
 Thu Oct 26 14:47:04 2006
@@ -0,0 +1,137 @@
+/*
+ * 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.elang.xpath10.compiler;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.compiler.api.CompilerContext;
+import org.apache.ode.bpel.compiler.api.ExpressionCompiler;
+import org.apache.ode.bpel.compiler.bom.Expression;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.msg.MessageBundle;
+import org.jaxen.saxpath.SAXPathException;
+import org.jaxen.saxpath.XPathReader;
+import org.jaxen.saxpath.helpers.XPathReaderFactory;
+import org.w3c.dom.Node;
+
+/**
+ * XPath compiler based on the JAXEN implementation. Supports both 2.0 and 1.1
+ * BPEL.
+ */
+public abstract class XPath10ExpressionCompilerImpl implements 
ExpressionCompiler {
+
+    private static final XPathMessages __msgs = 
MessageBundle.getMessages(XPathMessages.class);
+
+    // private HashMap<String,Function> _extensionFunctions = new
+    // HashMap<String,Function>();
+    protected CompilerContext _compilerContext;
+
+    /** Namespace of the BPEL functions (for v2 to v1 compatibility) . */
+    private String _bpelNsURI;
+
+    protected QName _qnFnGetVariableData;
+
+    protected QName _qnFnGetVariableProperty;
+
+    protected QName _qnFnGetLinkStatus;
+
+    protected Map<String, String> _properties = new HashMap<String, String>();
+
+    /**
+     * Construtor.
+     * 
+     * @param bpelNsURI
+     *            the BPEL extension function namespace; varies depending on
+     *            BPEL version.
+     */
+    public XPath10ExpressionCompilerImpl(String bpelNsURI) {
+        _bpelNsURI = bpelNsURI;
+        _qnFnGetVariableData = new QName(_bpelNsURI, "getVariableData");
+        _qnFnGetVariableProperty = new QName(_bpelNsURI, 
"getVariableProperty");
+        _qnFnGetLinkStatus = new QName(_bpelNsURI, "getLinkStatus");
+        _properties.put("runtime-class", 
"org.apache.ode.bpel.elang.xpath10.runtime.XPath10ExpressionRuntime");        
+    }
+
+    /**
+     * @see 
org.apache.ode.bpel.compiler.api.ExpressionCompiler#setCompilerContext(org.apache.ode.bpel.compiler.api.CompilerContext)
+     */
+    public void setCompilerContext(CompilerContext compilerContext) {
+        _compilerContext = compilerContext;
+    }
+
+    /**
+     * @see org.apache.ode.bpel.compiler.api.ExpressionCompiler#getProperties()
+     */
+    public Map<String, String> getProperties() {
+        return _properties;
+    }
+
+    // Dead code
+    /*
+     * private void registerExtensionFunction(String name, Class function) { 
try {
+     * Function jaxenFunction = (Function)function.newInstance();
+     * _extensionFunctions.put(name, jaxenFunction); } catch
+     * (InstantiationException e) { throw new RuntimeException("unexpected 
error
+     * creating extension function: " + name, e); } catch
+     * (IllegalAccessException e) { throw new RuntimeException("unexpected 
error
+     * creating extension function: " + name, e); } catch (ClassCastException 
e) {
+     * throw new RuntimeException("expected extension function of type " +
+     * Function.class.getName()); } }
+     */
+
+    /**
+     * Verifies validity of a xpath expression.
+     */
+    protected void doJaxenCompile(OXPath10Expression out, Expression source) 
throws CompilationException {
+        String xpathStr;
+        Node node = source.getExpression();
+        if (node == null) {
+            throw new IllegalStateException("XPath string and xpath node are 
both null");
+        }
+        if (node.getNodeType() != Node.TEXT_NODE) {
+            throw new 
CompilationException(__msgs.errUnexpectedNodeTypeForXPath(DOMUtils.domToString(node)));
+        }
+        xpathStr = node.getNodeValue();
+        xpathStr = xpathStr.trim();
+
+        try {
+            XPathReader reader = XPathReaderFactory.createReader();
+            JaxenBpelHandler handler = new JaxenBpelHandler(_bpelNsURI, out, 
source.getNamespaceContext(),
+                    _compilerContext);
+            reader.setXPathHandler(handler);
+
+            reader.parse(xpathStr);
+            out.xpath = xpathStr;
+        } catch (CompilationExceptionWrapper e) {
+            CompilationException ce = e.getCompilationException();
+            if (ce == null) {
+                ce = new 
CompilationException(__msgs.errUnexpectedCompilationError(e.getMessage()), e);
+            }
+            throw ce;
+        } catch (SAXPathException e) {
+            throw new CompilationException(__msgs.errXPathSyntax(xpathStr));
+        }
+    }
+
+}

Propchange: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPath10ExpressionCompilerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
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=auto&rev=468152
==============================================================================
--- 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPathMessages.java
 (added)
+++ 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPathMessages.java
 Thu Oct 26 14:47:04 2006
@@ -0,0 +1,105 @@
+/*
+ * 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.elang.xpath10.compiler;
+
+import org.apache.ode.bpel.compiler.api.CompilationMessage;
+import org.apache.ode.bpel.compiler.api.CompilationMessageBundle;
+
+/**
+ * Compilation messages related to XPath 1.0 expressions.
+ * @author mriou <mriou at apache dot org>
+ */
+public class XPathMessages extends CompilationMessageBundle {
+
+    public CompilationMessage errUnconfigurableXPathFactory() {
+        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);
+  }
+}

Propchange: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XPathMessages.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XslCompilationErrorListener.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XslCompilationErrorListener.java?view=auto&rev=468152
==============================================================================
--- 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XslCompilationErrorListener.java
 (added)
+++ 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XslCompilationErrorListener.java
 Thu Oct 26 14:47:04 2006
@@ -0,0 +1,81 @@
+/*
+ * 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.elang.xpath10.compiler;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.compiler.api.CompilationMessage;
+import org.apache.ode.bpel.compiler.api.CompilerContext;
+import org.apache.ode.utils.xsl.XslTransformHandler;
+
+import javax.xml.transform.ErrorListener;
+import javax.xml.transform.TransformerException;
+
+
+/**
+ * Reports errors that occured during Xsl sheets processing. This 
implementation isn't
+ * built to be thread safe in case multiple compilations occur parrallely, 
however
+ * this shouldn't occur.
+ */
+public class XslCompilationErrorListener implements ErrorListener {
+
+  private static final Log __log = 
LogFactory.getLog(XslCompilationErrorListener.class);
+  private CompilerContext _cc;
+
+  public XslCompilationErrorListener(CompilerContext cc) {
+    _cc = cc;
+  }
+
+  public void warning(TransformerException exception) throws 
TransformerException {
+    if (__log.isWarnEnabled()) {
+      __log.warn(exception);
+    }
+    recover(CompilationMessage.WARN, exception);
+  }
+
+  public void error(TransformerException exception) throws 
TransformerException {
+    if (__log.isErrorEnabled()) {
+      __log.error(exception);
+    }
+    recover(CompilationMessage.ERROR, exception);
+    throw exception;
+  }
+
+  public void fatalError(TransformerException exception) throws 
TransformerException {
+    if (__log.isFatalEnabled()) {
+      __log.fatal(exception);
+    }
+    recover(CompilationMessage.ERROR, exception);
+    throw exception;
+  }
+
+  // If somebody has a better idea to handle errors thrown by the XSL engine 
I'm
+  // really, really, REALLY open to suggestions.
+  private void recover(short severity, TransformerException exception) {
+    CompilationMessage cmsg = new CompilationMessage();
+    cmsg.severity = severity;
+    cmsg.code = "parseXsl";
+    cmsg.phase = 0;
+    cmsg.messageText = exception.getMessageAndLocation();
+    CompilationException ce = new CompilationException(cmsg, exception);
+    _cc.recoveredFromError(XslTransformHandler.getInstance(), ce);
+  }
+}

Propchange: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XslCompilationErrorListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XslCompileUriResolver.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XslCompileUriResolver.java?view=auto&rev=468152
==============================================================================
--- 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XslCompileUriResolver.java
 (added)
+++ 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XslCompileUriResolver.java
 Thu Oct 26 14:47:04 2006
@@ -0,0 +1,51 @@
+/*
+ * 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.elang.xpath10.compiler;
+
+import org.apache.ode.bpel.compiler.api.CompilerContext;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
+import org.apache.ode.bpel.o.OXslSheet;
+
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.stream.StreamSource;
+import java.io.StringReader;
+
+/**
+ * Used to give the Xsl processor a way to access included XSL sheets
+ * by using the CompilerContext (which uses RR behind the scene).
+ */
+public class XslCompileUriResolver implements URIResolver {
+
+  private CompilerContext _cc;
+  private OXPath10Expression _expr;
+
+  public XslCompileUriResolver(CompilerContext cc, OXPath10Expression expr) {
+    _cc = cc;
+    _expr = expr;
+  }
+
+  public Source resolve(String href, String base) throws TransformerException {
+    OXslSheet xslSheet = _cc.compileXslt(href);
+    _expr.xslSheets.put(xslSheet.uri, xslSheet);
+    return new StreamSource(new StringReader(xslSheet.sheetBody));
+  }
+}

Propchange: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath10/compiler/XslCompileUriResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to