You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by ms...@apache.org on 2006/10/26 23:48:43 UTC
svn commit: r468155 - in
/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang:
./ xpath10/ xpath10/runtime/
Author: mszefler
Date: Thu Oct 26 14:48:42 2006
New Revision: 468155
URL: http://svn.apache.org/viewvc?view=rev&rev=468155
Log:
Added bpel-el-xpath10 runtime classes.
Added:
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/BpelDocumentNavigator.java (with props)
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java (with props)
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenNamespaceContextAdapter.java (with props)
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/WrappedFaultException.java (with props)
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/XPath10ExpressionRuntime.java (with props)
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/XslRuntimeUriResolver.java (with props)
Added: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/BpelDocumentNavigator.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/BpelDocumentNavigator.java?view=auto&rev=468155
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/BpelDocumentNavigator.java (added)
+++ incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/BpelDocumentNavigator.java Thu Oct 26 14:48:42 2006
@@ -0,0 +1,34 @@
+/*
+ * 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.runtime;
+
+import org.jaxen.dom.DocumentNavigator;
+import org.w3c.dom.Node;
+
+class BpelDocumentNavigator extends DocumentNavigator {
+
+ private Node _documentRoot;
+ BpelDocumentNavigator(Node docRoot) {
+ _documentRoot = docRoot;
+ }
+
+ public Object getDocumentNode(Object contextNode) {
+ return _documentRoot;
+ }
+}
Propchange: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/BpelDocumentNavigator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java?view=auto&rev=468155
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java (added)
+++ incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java Thu Oct 26 14:48:42 2006
@@ -0,0 +1,369 @@
+/*
+ * 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.runtime;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.common.FaultException;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10ExpressionBPEL20;
+import org.apache.ode.bpel.explang.EvaluationContext;
+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.OXsdTypeVarType;
+import org.apache.ode.bpel.o.OXslSheet;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.xsd.XSTypes;
+import org.apache.ode.utils.xsl.XslTransformHandler;
+import org.jaxen.Context;
+import org.jaxen.Function;
+import org.jaxen.FunctionCallException;
+import org.jaxen.FunctionContext;
+import org.jaxen.UnresolvableException;
+import org.jaxen.VariableContext;
+import org.jaxen.XPathFunctionContext;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * Implementation of the various JAXEN evaluation contexts in terms of the
+ * {@link EvaluationContext}.
+ */
+class JaxenContexts implements FunctionContext, VariableContext {
+ private static final Log __log = LogFactory.getLog(JaxenContexts.class);
+
+ /** Static, thread-safe singleton implementing default XPath functions */
+ private static final FunctionContext __defaultXPathFunctions = XPathFunctionContext.getInstance();
+
+ private OXPath10Expression _oxpath;
+ private EvaluationContext _xpathEvalCtx;
+ private Function _getVariableProperty;
+ private Function _getVariableData;
+ private Function _getLinkStatus;
+ private Function _doXslTransform;
+ private Map _extensionFunctions;
+
+ public JaxenContexts(OXPath10Expression oxpath,
+ Map extensionFunctions,
+ EvaluationContext xpathEvalCtx) {
+ _oxpath = oxpath;
+ _xpathEvalCtx = xpathEvalCtx;
+ _extensionFunctions = extensionFunctions;
+ _getVariableProperty = new BpelVariablePropertyFunction();
+ _getVariableData = new BpelVariableDataFunction();
+ _getLinkStatus = new GetLinkStatusFunction();
+ _doXslTransform = new DoXslTransformFunction();
+ }
+
+ /**
+ * @see org.jaxen.FunctionContext#getFunction(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ public Function getFunction(String namespaceURI, String prefix,
+ String localName)
+ throws UnresolvableException {
+ if (__log.isDebugEnabled()) {
+ __log.debug("getFunction(" + namespaceURI + "," + prefix + ","
+ + localName);
+ }
+
+ if ((namespaceURI != null)) {
+ QName fnQName = new QName(namespaceURI, localName);
+
+ if (fnQName.equals(_oxpath.qname_getVariableProperty))
+ return _getVariableProperty;
+ if (fnQName.equals(_oxpath.qname_getVariableData))
+ return _getVariableData;
+ if (fnQName.equals(_oxpath.qname_getLinkStatus))
+ return _getLinkStatus;
+ if (_oxpath instanceof OXPath10ExpressionBPEL20) {
+ OXPath10ExpressionBPEL20 oxpath20 = (OXPath10ExpressionBPEL20) _oxpath;
+ if (fnQName.equals(oxpath20.qname_doXslTransform)) {
+ return _doXslTransform;
+ }
+ }
+ Function f = (Function)_extensionFunctions.get(localName);
+
+ if (f != null) {
+ return f;
+ }
+ }
+
+ // Defer to the default XPath context.
+ return __defaultXPathFunctions.getFunction(null, prefix, localName);
+ }
+
+ /**
+ * @see org.jaxen.VariableContext#getVariableValue(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ public Object getVariableValue(String namespaceURI, String prefix,
+ String localName)
+ throws UnresolvableException {
+ if(!(_oxpath instanceof OXPath10ExpressionBPEL20)){
+ throw new IllegalStateException("XPath variables not supported for bpel 1.1");
+ }
+
+ // Custom variables
+ if ("ode".equals(prefix)) {
+ if ("pid".equals(localName)) {
+ return _xpathEvalCtx.getProcessId();
+ }
+ }
+
+ OXPath10ExpressionBPEL20 expr = (OXPath10ExpressionBPEL20)_oxpath;
+ if(expr.isJoinExpression){
+ OLink olink = _oxpath.links.get(localName);
+
+ try {
+ return _xpathEvalCtx.isLinkActive(olink) ? Boolean.TRUE : Boolean.FALSE;
+ } catch (FaultException e) {
+ throw new WrappedFaultException.JaxenUnresolvableException(e);
+ }
+ }else{
+ String varName;
+ String partName;
+ int dotloc = localName.indexOf('.');
+ if (dotloc == -1) {
+ varName = localName;
+ partName = null;
+ } else {
+ varName = localName.substring(0, dotloc);
+ partName = localName.substring(dotloc + 1);
+ }
+ OScope.Variable variable = _oxpath.vars.get(varName);
+ OMessageVarType.Part part = partName == null ? null : ((OMessageVarType)variable.type).parts.get(partName);
+
+ try{
+ Node variableNode = _xpathEvalCtx.readVariable(variable, part);
+ if (variableNode == null)
+ throw new WrappedFaultException.JaxenUnresolvableException(
+ new FaultException(variable.getOwner().constants.qnSelectionFailure, "Unknown variable " + localName));
+ if (variable.type instanceof OXsdTypeVarType && ((OXsdTypeVarType)variable.type).simple) {
+ String text = variableNode.getTextContent();
+ try {
+ return XSTypes.toJavaObject(((OXsdTypeVarType)variable.type).xsdType,
+ text);
+ } catch (Exception e) { }
+ // Elegant way failed, trying brute force
+ try {
+ return Integer.valueOf(text);
+ } catch (NumberFormatException e) { }
+ try {
+ return Double.valueOf(text);
+ } catch (NumberFormatException e) { }
+ return text;
+ } else {
+ return variableNode;
+ }
+ }catch(FaultException e){
+ throw new WrappedFaultException.JaxenUnresolvableException(e);
+ }
+ }
+ }
+
+ /**
+ * bpws:getVariableData()
+ */
+ class BpelVariableDataFunction implements Function {
+ public Object call(Context context, List args)
+ throws FunctionCallException {
+ if (__log.isDebugEnabled()) {
+ __log.debug("call(context=" + context + " args=" + args + ")");
+ }
+
+ String varname = (String) args.get(0);
+ String partname = args.size() > 1 ? (String) args.get(1) : null;
+ String xpathStr = args.size() > 2 ? (String)args.get(2) : null;
+
+ OXPath10Expression.OSigGetVariableData sig = _oxpath.resolveGetVariableDataSig(varname,partname,xpathStr);
+ if (sig == null) {
+ String msg = "InternalError: Attempt to use an unknown getVariableData signature: " + args;
+ if (__log.isFatalEnabled())
+ __log.fatal(msg);
+ throw new FunctionCallException(msg);
+ }
+
+ try {
+ Node ret = _xpathEvalCtx.readVariable(sig.variable, sig.part);
+ if (sig.location != null)
+ ret = _xpathEvalCtx.evaluateQuery(ret, sig.location);
+
+ if (__log.isDebugEnabled()) {
+ __log.debug("bpws:getVariableData(" + args + ")' = " + ret);
+ }
+
+ return ret;
+ } catch (FaultException e) {
+ __log.error("bpws:getVariableData(" + args + ") threw FaultException");
+
+ throw new WrappedFaultException.JaxenFunctionException(e);
+ }
+ }
+ }
+
+ /**
+ * bpws:getVariableProperty()
+ */
+ class BpelVariablePropertyFunction implements Function {
+ public Object call(Context context, List args)
+ throws FunctionCallException {
+ if (args.size() != 2) {
+ throw new FunctionCallException("missing required arguments");
+ }
+
+ OScope.Variable var = _oxpath.vars.get(args.get(0));
+ OProcess.OProperty property = _oxpath.properties.get(args.get(1));
+
+ if (__log.isDebugEnabled()) {
+ __log.debug("function call:'bpws:getVariableProperty(" + var + ","
+ + property + ")'");
+ }
+
+ try {
+ return _xpathEvalCtx.readMessageProperty(var, property);
+ } catch (FaultException e) {
+ throw new WrappedFaultException.JaxenFunctionException(e);
+ }
+ }
+ }
+
+ class GetLinkStatusFunction implements Function {
+ public Object call(Context context, List args)
+ throws FunctionCallException {
+ assert args.size() == 1;
+
+ OLink olink = _oxpath.links.get(args.get(0));
+
+ try {
+ return _xpathEvalCtx.isLinkActive(olink) ? Boolean.TRUE : Boolean.FALSE;
+ } catch (FaultException e) {
+ throw new WrappedFaultException.JaxenFunctionException(e);
+ }
+ }
+ }
+
+ class DoXslTransformFunction implements Function {
+ public Object call(Context context, List args) throws FunctionCallException {
+ assert args.size() >= 2;
+ assert args.size() % 2 == 0;
+ if (__log.isDebugEnabled()) {
+ __log.debug("call(context=" + context + " args=" + args + ")");
+ }
+ if(!(_oxpath instanceof OXPath10ExpressionBPEL20)) {
+ throw new IllegalStateException("XPath function bpws:doXslTransform not supported in " +
+ "BPEL 1.1!");
+ }
+
+ Element varElmt;
+ try {
+ if (args.get(1) instanceof List) {
+ List elmts = (List)args.get(1);
+ if (elmts.size() != 1) throw new WrappedFaultException.JaxenFunctionException(
+ new FaultException(_oxpath.getOwner().constants.qnXsltInvalidSource,
+ "Second parameter of the bpws:doXslTransform function MUST point to a single " +
+ "element node."));
+ varElmt = (Element) elmts.get(0);
+ } else {
+ varElmt = (Element) args.get(1);
+ }
+ } catch (ClassCastException e) {
+ throw new WrappedFaultException.JaxenFunctionException(
+ new FaultException(_oxpath.getOwner().constants.qnXsltInvalidSource,
+ "Second parameter of the bpws:doXslTransform function MUST point to a single " +
+ "element node."));
+ }
+
+ URI xslUri;
+ try {
+ xslUri = new URI((String) args.get(0));
+ } catch (URISyntaxException use) {
+ // Shouldn't happen, checked at compilation time
+ throw new FunctionCallException("First parameter of the bpws:doXslTransform isn't a valid URI!", use);
+ }
+ OXslSheet xslSheet = _oxpath.xslSheets.get(xslUri);
+ // Shouldn't happen, checked at compilation time
+ if (xslSheet == null) throw new FunctionCallException("Couldn't find the XSL sheet " + args.get(0)
+ + ", process compilation or deployment was probably incomplete!");
+
+ if (!(varElmt instanceof Element)) {
+ throw new WrappedFaultException.JaxenFunctionException(
+ new FaultException(_oxpath.getOwner().constants.qnXsltInvalidSource,
+ "Second parameter of the bpws:doXslTransform function MUST point to a single " +
+ "element node."));
+ }
+
+ HashMap<QName, Object> parametersMap = null;
+ if (args.size() > 2) {
+ parametersMap = new HashMap<QName, Object>();
+ for (int idx = 2; idx < args.size(); idx+=2) {
+ QName keyQName = _oxpath.namespaceCtx.derefQName((String) args.get(idx));
+ parametersMap.put(keyQName, args.get(idx + 1));
+ }
+ }
+
+ DOMSource source = new DOMSource(varElmt);
+ // Using a StreamResult as a DOMResult doesn't behaves properly when the result
+ // of the transformation is just a string.
+ StringWriter writerResult = new StringWriter();
+ StreamResult result = new StreamResult(writerResult);
+ XslRuntimeUriResolver resolver = new XslRuntimeUriResolver(_oxpath);
+ XslTransformHandler.getInstance().cacheXSLSheet(xslUri, xslSheet.sheetBody, resolver);
+ try {
+ XslTransformHandler.getInstance().transform(xslUri, source, result, parametersMap, resolver);
+ } catch (Exception e) {
+ throw new WrappedFaultException.JaxenFunctionException(
+ new FaultException(_oxpath.getOwner().constants.qnSubLanguageExecutionFault,
+ e.toString()));
+ }
+ writerResult.flush();
+
+ String output = writerResult.toString();
+ // I'm not really proud of that but hey, it does the job and I don't think there's
+ // any other easy way.
+ if (output.startsWith("<?xml")) {
+ try {
+ return DOMUtils.stringToDOM(writerResult.toString());
+ } catch (SAXException e) {
+ throw new FunctionCallException(e);
+ } catch (IOException e) {
+ throw new FunctionCallException(e);
+ }
+ } else {
+ return output;
+ }
+ }
+ }
+
+}
Propchange: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenNamespaceContextAdapter.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenNamespaceContextAdapter.java?view=auto&rev=468155
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenNamespaceContextAdapter.java (added)
+++ incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenNamespaceContextAdapter.java Thu Oct 26 14:48:42 2006
@@ -0,0 +1,46 @@
+/*
+ * 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.runtime;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.NamespaceContext;
+
+/**
+ * Class adapting the {@link javax.xml.namespace.NamespaceContext} interface to the
+ * JAXEN {@link NamespaceContext} interface.
+ * @pattern Adapter
+ */
+class JaxenNamespaceContextAdapter implements NamespaceContext {
+ private static final Log __log = LogFactory.getLog(JaxenNamespaceContextAdapter.class);
+
+ private javax.xml.namespace.NamespaceContext _namespaceContext;
+
+ JaxenNamespaceContextAdapter(javax.xml.namespace.NamespaceContext ctx) {
+ _namespaceContext = ctx;
+ }
+
+ public String translateNamespacePrefixToUri(String prefix) {
+ String namespaceURI = _namespaceContext.getNamespaceURI(prefix);
+ if (__log.isDebugEnabled()) {
+ __log.debug("translateNamespacePrefixToUri(" + prefix + ")=" + namespaceURI);
+ }
+ return namespaceURI;
+ }
+}
Propchange: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenNamespaceContextAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/WrappedFaultException.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/WrappedFaultException.java?view=auto&rev=468155
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/WrappedFaultException.java (added)
+++ incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/WrappedFaultException.java Thu Oct 26 14:48:42 2006
@@ -0,0 +1,67 @@
+/*
+ * 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.runtime;
+
+import org.apache.ode.bpel.common.FaultException;
+
+import org.jaxen.FunctionCallException;
+import org.jaxen.UnresolvableException;
+
+/**
+ * Wrap a fault in a jaxen exception
+ */
+public interface WrappedFaultException {
+ public FaultException getFaultException();
+
+ /**
+ * Jaxenized {@link FaultException}; Jaxen requires us to throw only exceptions
+ * extending its {@link UnresolvableVariableException} so we comply.
+ */
+ static class JaxenUnresolvableException extends UnresolvableException implements WrappedFaultException{
+ FaultException _cause;
+ public JaxenUnresolvableException(FaultException e) {
+ super("var");
+ assert e != null;
+ initCause(e);
+ _cause = e;
+ }
+
+ public FaultException getFaultException() {
+ return _cause;
+ }
+ }
+
+ /**
+ * Jaxenized {@link FaultException}; Jaxen requires us to throw only exceptions
+ * extending its {@link FunctionCallException} so we comply.
+ */
+ static class JaxenFunctionException extends FunctionCallException implements WrappedFaultException{
+ FaultException _cause;
+ public JaxenFunctionException(FaultException e) {
+ super(e);
+ assert e != null;
+ initCause(e);
+ _cause = e;
+ }
+
+ public FaultException getFaultException() {
+ return _cause;
+ }
+ }
+}
Propchange: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/WrappedFaultException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/XPath10ExpressionRuntime.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/XPath10ExpressionRuntime.java?view=auto&rev=468155
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/XPath10ExpressionRuntime.java (added)
+++ incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/XPath10ExpressionRuntime.java Thu Oct 26 14:48:42 2006
@@ -0,0 +1,181 @@
+/*
+ * 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.runtime;
+
+import org.apache.ode.bpel.common.FaultException;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
+import org.apache.ode.bpel.explang.ConfigurationException;
+import org.apache.ode.bpel.explang.EvaluationContext;
+import org.apache.ode.bpel.explang.EvaluationException;
+import org.apache.ode.bpel.explang.ExpressionLanguageRuntime;
+import org.apache.ode.bpel.o.OExpression;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.xsd.Duration;
+import org.apache.ode.utils.xsd.XMLCalendar;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.Context;
+import org.jaxen.ContextSupport;
+import org.jaxen.JaxenException;
+import org.jaxen.XPath;
+import org.jaxen.dom.DOMXPath;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+import java.util.*;
+
+/**
+ * XPath 1.0 Expression Language run-time subsytem.
+ */
+public class XPath10ExpressionRuntime implements ExpressionLanguageRuntime {
+ /** Class-level logger. */
+ private static final Log __log = LogFactory.getLog(XPath10ExpressionRuntime.class);
+
+ /** Compiled expression cache. */
+ private final Map<String, XPath> _compiledExpressions = new HashMap<String, XPath>();
+
+ /** Registered extension functions. */
+ private final Map _extensionFunctions = new HashMap();
+
+ public void initialize(Map properties) throws ConfigurationException {
+ }
+
+ public String evaluateAsString(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException {
+ try {
+ return compile((OXPath10Expression) cexp).stringValueOf(createContext((OXPath10Expression) cexp, ctx));
+ } catch (JaxenException e) {
+ handleJaxenException(e);
+ }
+ throw new AssertionError("UNREACHABLE");
+ }
+
+ public boolean evaluateAsBoolean(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException {
+ try {
+ return compile((OXPath10Expression) cexp).booleanValueOf(createContext((OXPath10Expression) cexp, ctx));
+ } catch (JaxenException e) {
+ handleJaxenException(e);
+ }
+ throw new AssertionError("UNREACHABLE");
+ }
+
+ public Number evaluateAsNumber(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException {
+ try {
+ return compile((OXPath10Expression) cexp).numberValueOf(createContext((OXPath10Expression) cexp, ctx));
+ } catch (JaxenException e) {
+ handleJaxenException(e);
+ }
+ throw new AssertionError("UNREACHABLE");
+ }
+
+ public List evaluate(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException {
+ try {
+ XPath compiledXPath = compile((OXPath10Expression) cexp);
+ Context context = createContext((OXPath10Expression) cexp, ctx);
+
+ List retVal = compiledXPath.selectNodes(context);
+
+ if ((retVal.size() == 1) && !(retVal.get(0) instanceof Node)) {
+ Document d = DOMUtils.newDocument();
+ // Giving our node a parent just in case it's an LValue expression
+ Element wrapper = d.createElement("wrapper");
+ Text text = d.createTextNode(retVal.get(0).toString());
+ wrapper.appendChild(text);
+ d.appendChild(wrapper);
+ retVal = Collections.singletonList(text);
+ }
+
+ return retVal;
+
+ } catch (JaxenException je) {
+ handleJaxenException(je);
+ }
+ throw new AssertionError("UNREACHABLE");
+ }
+
+ public Node evaluateNode(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException {
+ List retVal = evaluate(cexp, ctx);
+ if (retVal.size() == 0)
+ throw new FaultException(cexp.getOwner().constants.qnSelectionFailure, "No results for expression: " + cexp);
+ if (retVal.size() > 1)
+ throw new FaultException(cexp.getOwner().constants.qnSelectionFailure, "Multiple results for expression: " + cexp);
+ return (Node) retVal.get(0);
+ }
+
+ public Calendar evaluateAsDate(OExpression cexp, EvaluationContext context) throws FaultException, EvaluationException {
+
+ String literal = evaluateAsString(cexp, context);
+
+ try {
+ return new XMLCalendar(literal);
+ } catch (Exception ex) {
+ __log.error("Date conversion error." ,ex);
+ throw new EvaluationException("Date conversion errror.", ex);
+ }
+ }
+
+ public Duration evaluateAsDuration(OExpression cexp, EvaluationContext context) throws FaultException, EvaluationException {
+ String literal = this.evaluateAsString(cexp, context);
+ try {
+ Duration duration = new org.apache.ode.utils.xsd.Duration(literal);
+ return duration;
+ } catch (Exception ex) {
+ __log.error("Date conversion error.", ex);
+ throw new EvaluationException("Duration conversion error." ,ex);
+ }
+ }
+
+ private Context createContext(OXPath10Expression oxpath, EvaluationContext ctx) {
+ JaxenContexts bpelSupport = new JaxenContexts(oxpath, _extensionFunctions, ctx);
+ ContextSupport support = new ContextSupport(new JaxenNamespaceContextAdapter(oxpath.namespaceCtx),
+ bpelSupport, bpelSupport,
+ new BpelDocumentNavigator(ctx.getRootNode()));
+ Context jctx = new Context(support);
+
+ if (ctx.getRootNode() != null)
+ jctx.setNodeSet(Collections.singletonList(ctx.getRootNode()));
+
+ return jctx;
+ }
+
+
+ private XPath compile(OXPath10Expression exp) throws JaxenException {
+ XPath xpath = _compiledExpressions.get(exp.xpath);
+ if (xpath == null) {
+ xpath = new DOMXPath(exp.xpath);
+ synchronized(_compiledExpressions) {
+ _compiledExpressions.put(exp.xpath, xpath);
+ }
+ }
+ return xpath;
+ }
+
+ private void handleJaxenException(JaxenException je) throws EvaluationException,FaultException {
+ if (je instanceof WrappedFaultException) {
+ throw ((WrappedFaultException)je).getFaultException();
+ } else if (je.getCause() instanceof WrappedFaultException) {
+ throw ((WrappedFaultException)je.getCause())
+ .getFaultException();
+ } else {
+ throw new EvaluationException(je.getMessage(),je);
+ }
+
+ }
+}
Propchange: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/XPath10ExpressionRuntime.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/XslRuntimeUriResolver.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/XslRuntimeUriResolver.java?view=auto&rev=468155
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/XslRuntimeUriResolver.java (added)
+++ incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/XslRuntimeUriResolver.java Thu Oct 26 14:48:42 2006
@@ -0,0 +1,50 @@
+/*
+ * 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.runtime;
+
+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.net.URI;
+import java.io.StringReader;
+
+/**
+ * Used to give the Xsl processor a way to access included XSL sheets
+ * by using the maps of sheets pre-processed at compilation time and
+ * stored in the OXPath10Expression.
+ */
+public class XslRuntimeUriResolver implements URIResolver {
+
+ private OXPath10Expression _expr;
+
+ public XslRuntimeUriResolver(OXPath10Expression expr) {
+ _expr = expr;
+ }
+
+ public Source resolve(String href, String base) throws TransformerException {
+ URI uri = URI.create(href);
+ OXslSheet sheet = _expr.xslSheets.get(uri);
+ return new StreamSource(new StringReader(sheet.sheetBody));
+ }
+}
Propchange: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/XslRuntimeUriResolver.java
------------------------------------------------------------------------------
svn:eol-style = native