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 2008/09/10 21:07:05 UTC
svn commit: r693931 [4/12] - in /ode/trunk:
bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/
bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/
bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/
runtimes/...
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WSDLRegistry.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WSDLRegistry.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WSDLRegistry.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WSDLRegistry.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,294 @@
+/*
+ * 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.compiler.v1;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.compiler.CommonCompilationMessages;
+import org.apache.ode.bpel.compiler.ResourceFinder;
+import org.apache.ode.bpel.compiler.WsdlFinderXMLEntityResolver;
+import org.apache.ode.bpel.compiler.SourceLocation;
+import org.apache.ode.bpel.compiler.bom.PropertyAlias;
+import org.apache.ode.bpel.compiler.bom.Property;
+import org.apache.ode.bpel.compiler.bom.PartnerLinkType;
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.compiler.wsdl.Definition4BPEL;
+import org.apache.ode.bpel.compiler.wsdl.XMLSchemaType;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.Namespaces;
+import org.apache.ode.utils.StreamUtils;
+import org.apache.ode.utils.msg.MessageBundle;
+import org.apache.ode.utils.xsd.SchemaModel;
+import org.apache.ode.utils.xsd.SchemaModelImpl;
+import org.apache.ode.utils.xsd.XSUtils;
+import org.apache.ode.utils.xsd.XsdException;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+import javax.wsdl.*;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.xml.namespace.QName;
+import java.io.StringReader;
+import java.io.IOException;
+import java.net.URI;
+import java.util.*;
+
+
+/**
+ * A parsed collection of WSDL definitions, including BPEL-specific extensions.
+ */
+class WSDLRegistry {
+ private static final Log __log = LogFactory.getLog(WSDLRegistry.class);
+
+ private static final CommonCompilationMessages __cmsgs =
+ MessageBundle.getMessages(CommonCompilationMessages.class);
+
+ private final HashMap<String, ArrayList<Definition4BPEL>> _definitions = new HashMap<String, ArrayList<Definition4BPEL>>();
+
+ private final Map<URI, byte[]> _schemas = new HashMap<URI,byte[]>();
+ private final Map<URI, String> _internalSchemas = new HashMap<URI, String>();
+
+ private SchemaModel _model;
+
+ private CompilerContext _ctx;
+
+
+ WSDLRegistry(CompilerContext cc) {
+ // bogus schema to force schema creation
+ _schemas.put(URI.create("http://fivesight.com/bogus/namespace"),
+ ("<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
+ + " targetNamespace=\"http://fivesight.com/bogus/namespace\">"
+ + "<xsd:simpleType name=\"__bogusType__\">"
+ + "<xsd:restriction base=\"xsd:normalizedString\"/>"
+ + "</xsd:simpleType>" + "</xsd:schema>").getBytes());
+ try {
+ _schemas.put(URI.create(Namespaces.WSDL_11), StreamUtils.read(getClass().getResource("/wsdl.xsd")));
+ _schemas.put(URI.create("http://www.w3.org/2001/xml.xsd"), StreamUtils.read(getClass().getResource("/xml.xsd")));
+ } catch (IOException e) {
+ throw new RuntimeException("Couldn't load default schemas.", e);
+ }
+
+ _ctx = cc;
+ }
+
+ public Definition4BPEL[] getDefinitions(){
+ ArrayList<Definition4BPEL> result = new ArrayList<Definition4BPEL>();
+ for (ArrayList<Definition4BPEL> definition4BPELs : _definitions.values()) {
+ for (Definition4BPEL definition4BPEL : definition4BPELs) {
+ result.add(definition4BPEL);
+ }
+ }
+ return result.toArray(new Definition4BPEL[result.size()]);
+ }
+
+ /**
+ * Get the schema model (XML Schema).
+ *
+ * @return schema model
+ */
+ public SchemaModel getSchemaModel() {
+ if (_model == null) {
+ _model = SchemaModelImpl.newModel(_schemas);
+ }
+ assert _model != null;
+ return _model;
+ }
+
+ /**
+ * Adds a WSDL definition for use in resolving MessageType, PortType,
+ * Operation and BPEL properties and property aliases
+ *
+ * @param def WSDL definition
+ */
+ @SuppressWarnings("unchecked")
+ public void addDefinition(Definition4BPEL def, ResourceFinder rf, URI defuri) throws CompilationException {
+ if (def == null)
+ throw new NullPointerException("def=null");
+
+ if (__log.isDebugEnabled()) {
+ __log.debug("addDefinition(" + def.getTargetNamespace() + " from " + def.getDocumentBaseURI() + ")");
+ }
+
+ if (_definitions.containsKey(def.getTargetNamespace())) {
+ // This indicates that we imported a WSDL with the same namespace from
+ // two different locations. This is not an error, but should be a warning.
+ if (__log.isInfoEnabled()) {
+ __log.info("WSDL at " + defuri + " is a duplicate import, your documents " +
+ "should all be in different namespaces (its's not nice but will still work).");
+ }
+ }
+
+ ArrayList<Definition4BPEL> defs = null;
+ if (_definitions.get(def.getTargetNamespace()) == null) defs = new ArrayList<Definition4BPEL>();
+ else defs = _definitions.get(def.getTargetNamespace());
+
+ defs.add(def);
+ _definitions.put(def.getTargetNamespace(), defs);
+
+ captureSchemas(def, rf, defuri);
+
+ if (__log.isDebugEnabled())
+ __log.debug("Processing <imports> in " + def.getDocumentBaseURI());
+
+ for (List<Import> imports : ((Map<String, List<Import>>)def.getImports()).values()) {
+ HashSet<String> imported = new HashSet<String>();
+
+ for (Import im : imports) {
+ // If there are several imports in the same WSDL all importing the same namespace
+ // that is a sure sign of programmer error.
+ if (imported.contains(im.getNamespaceURI())) {
+ if (__log.isInfoEnabled()) {
+ __log.info("WSDL at " + im.getLocationURI() + " imports several documents in the same " +
+ "namespace (" + im.getNamespaceURI() + "), your documents should all be in different " +
+ "namespaces (its's not nice but will still work).");
+ }
+ }
+
+ Definition4BPEL importDef = (Definition4BPEL) im.getDefinition();
+
+ // The assumption here is that if the definition is not set on the
+ // import object then there was some problem parsing the thing,
+ // although it would have been nice to actually get the parse
+ // error.
+ if (importDef == null) {
+ CompilationException ce = new CompilationException(
+ __cmsgs.errWsdlImportNotFound(im.getNamespaceURI(),
+ im.getLocationURI()).setSource(new SourceLocation(defuri)));
+ if (_ctx == null)
+ throw ce;
+
+ _ctx.recoveredFromError(new SourceLocation(defuri), ce);
+ continue;
+ }
+
+ imported.add(im.getNamespaceURI());
+ addDefinition((Definition4BPEL) im.getDefinition(), rf, defuri.resolve(im.getLocationURI()));
+ }
+ }
+ }
+
+ public void addSchemas(Map<URI, byte[]> capture) {
+ _schemas.putAll(capture);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void captureSchemas(Definition def, ResourceFinder rf, URI defuri) throws CompilationException {
+ assert def != null;
+
+ if (__log.isDebugEnabled())
+ __log.debug("Processing XSD schemas in " + def.getDocumentBaseURI());
+
+ Types types = def.getTypes();
+
+ if (types != null) {
+ for (ExtensibilityElement ee : ((List<ExtensibilityElement>) def.getTypes().getExtensibilityElements())) {
+ if (ee instanceof XMLSchemaType) {
+ String schema = ((XMLSchemaType) ee).getXMLSchema();
+ WsdlFinderXMLEntityResolver resolver = new WsdlFinderXMLEntityResolver(rf, defuri, _internalSchemas, false);
+ try {
+ Map<URI, byte[]> capture = XSUtils.captureSchema(defuri, schema, resolver);
+ _schemas.putAll(capture);
+
+ try {
+ Document doc = DOMUtils.parse(new InputSource(new StringReader(schema)));
+ String schemaTargetNS = doc.getDocumentElement().getAttribute("targetNamespace");
+ if (schemaTargetNS != null && schemaTargetNS.length() > 0)
+ _internalSchemas.put(new URI(schemaTargetNS), schema);
+ } catch (Exception e) {
+ throw new RuntimeException("Couldn't parse schema in " + def.getTargetNamespace(), e);
+ }
+ } catch (XsdException xsde) {
+ __log.debug("captureSchemas: capture failed for " + defuri, xsde);
+
+ LinkedList<XsdException> exceptions = new LinkedList<XsdException>();
+ while (xsde != null) {
+ exceptions.addFirst(xsde);
+ xsde = xsde.getPrevious();
+ }
+
+ for (XsdException ex : exceptions) {
+ // TODO: the line number here is going to be wrong for the in-line schema.
+ // String location = ex.getSystemId() + ":" + ex.getLineNumber();
+ CompilationException ce = new CompilationException(
+ __cmsgs.errSchemaError(ex.getDetailMessage()).setSource(new SourceLocation(defuri)));
+ if (_ctx != null)
+ _ctx.recoveredFromError(new SourceLocation(defuri), ce);
+ else
+ throw ce;
+ }
+ }
+ // invalidate model
+ _model = null;
+
+ }
+ }
+ }
+ }
+
+ public Property getProperty(QName name) {
+ ArrayList<Definition4BPEL> defs = _definitions.get(name.getNamespaceURI());
+ if (defs == null) return null;
+ for (Definition4BPEL definition4BPEL : defs) {
+ if (definition4BPEL != null && definition4BPEL.getProperty(name) != null)
+ return definition4BPEL.getProperty(name);
+ }
+ return null;
+ }
+
+ public PropertyAlias getPropertyAlias(QName propertyName, QName messageType) {
+ ArrayList<Definition4BPEL> defs = _definitions.get(propertyName.getNamespaceURI());
+ if (defs == null) return null;
+ for (Definition4BPEL definition4BPEL : defs) {
+ if (definition4BPEL != null && definition4BPEL.getPropertyAlias(propertyName, messageType) != null)
+ return definition4BPEL.getPropertyAlias(propertyName, messageType);
+ }
+ return null;
+ }
+
+ public PartnerLinkType getPartnerLinkType(QName partnerLinkType) {
+ ArrayList<Definition4BPEL> defs = _definitions.get(partnerLinkType.getNamespaceURI());
+ if (defs == null) return null;
+ for (Definition4BPEL definition4BPEL : defs) {
+ if (definition4BPEL != null && definition4BPEL.getPartnerLinkType(partnerLinkType) != null)
+ return definition4BPEL.getPartnerLinkType(partnerLinkType);
+ }
+ return null;
+ }
+
+ public PortType getPortType(QName portType) {
+ ArrayList<Definition4BPEL> defs = _definitions.get(portType.getNamespaceURI());
+ if (defs == null) return null;
+ for (Definition4BPEL definition4BPEL : defs) {
+ if (definition4BPEL != null && definition4BPEL.getPortType(portType) != null)
+ return definition4BPEL.getPortType(portType);
+ }
+ return null;
+ }
+
+ public Message getMessage(QName msgType) {
+ ArrayList<Definition4BPEL> defs = _definitions.get(msgType.getNamespaceURI());
+ if (defs == null) return null;
+ for (Definition4BPEL definition4BPEL : defs) {
+ if (definition4BPEL != null && definition4BPEL.getMessage(msgType) != null)
+ return definition4BPEL.getMessage(msgType);
+ }
+ return null;
+ }
+
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WaitGenerator.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WaitGenerator.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WaitGenerator.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WaitGenerator.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,53 @@
+/*
+ * 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.compiler.v1;
+
+import org.apache.ode.bpel.compiler.bom.WaitActivity;
+import org.apache.ode.bpel.compiler.bom.Activity;
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.rtrep.v1.OWait;
+import org.apache.ode.bpel.rtrep.v1.OActivity;
+import org.apache.ode.utils.msg.MessageBundle;
+
+/**
+ * Generates code for the <code><wait></code> activities.
+ */
+class WaitGenerator extends DefaultActivityGenerator {
+
+ private WaitGeneratorMessages _msgs = MessageBundle.getMessages(WaitGeneratorMessages.class);
+
+ public OActivity newInstance(Activity src) {
+ return new OWait(_context.getOProcess(), _context.getCurrent());
+ }
+
+ public void compile(OActivity output, Activity src) {
+ WaitActivity waitDef = (WaitActivity)src;
+ OWait owait = (OWait)output;
+ if (waitDef.getFor() != null && waitDef.getUntil() == null) {
+ owait.forExpression = _context.compileExpr(waitDef.getFor());
+ }
+ else if (waitDef.getFor() == null && waitDef.getUntil() != null) {
+ owait.untilExpression = _context.compileExpr(waitDef.getUntil());
+ }
+ else {
+ throw new CompilationException(_msgs.errWaitMustDefineForOrUntilDuration().setSource(waitDef));
+ }
+ }
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WaitGeneratorMessages.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WaitGeneratorMessages.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WaitGeneratorMessages.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WaitGeneratorMessages.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,32 @@
+/*
+ * 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.compiler.v1;
+
+import org.apache.ode.bpel.compiler.api.CompilationMessageBundle;
+import org.apache.ode.bpel.compiler.api.CompilationMessage;
+
+public class WaitGeneratorMessages extends CompilationMessageBundle {
+
+ /** Must specify exactly one "for" or "until" expression. */
+ public CompilationMessage errWaitMustDefineForOrUntilDuration() {
+ return this.formatCompilationMessage("Must specify exactly one \"for\" or \"until\" expression.");
+ }
+
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WhileGenerator.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WhileGenerator.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WhileGenerator.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/WhileGenerator.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,41 @@
+/*
+ * 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.compiler.v1;
+
+import org.apache.ode.bpel.compiler.bom.WhileActivity;
+import org.apache.ode.bpel.compiler.bom.Activity;
+import org.apache.ode.bpel.rtrep.v1.OWhile;
+import org.apache.ode.bpel.rtrep.v1.OActivity;
+
+
+/**
+ * Generates code for <code><while></code> activities.
+ */
+class WhileGenerator extends DefaultActivityGenerator {
+ public OActivity newInstance(Activity src) {
+ return new OWhile(_context.getOProcess(), _context.getCurrent());
+ }
+
+ public void compile(OActivity output, Activity srcx) {
+ OWhile owhile = (OWhile) output;
+ WhileActivity src = (WhileActivity)srcx;
+ owhile.whileCondition = _context.compileExpr(src.getCondition());
+ owhile.activity = _context.compile(src.getActivity());
+ }
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/JaxenBpelHandler.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/JaxenBpelHandler.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/JaxenBpelHandler.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/JaxenBpelHandler.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,246 @@
+/*
+ * 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.compiler.v1.xpath10;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ode.utils.NSContext;
+import org.apache.ode.utils.msg.MessageBundle;
+import org.apache.ode.utils.xsl.XslTransformHandler;
+import org.apache.ode.bpel.rtrep.v1.xpath10.*;
+import org.apache.ode.bpel.rtrep.v1.*;
+import org.apache.ode.bpel.rtrep.common.Constants;
+import org.apache.ode.bpel.compiler.XPathMessages;
+import org.apache.ode.bpel.compiler.CompilationExceptionWrapper;
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.compiler.v1.CompilerContext;
+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() {
+ 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 RuntimeException(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 {@link 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()));
+ }
+
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerBPEL11.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerBPEL11.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerBPEL11.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerBPEL11.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,61 @@
+/*
+ * 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.compiler.v1.xpath10;
+
+import org.apache.ode.bpel.rtrep.v1.OExpression;
+import org.apache.ode.bpel.rtrep.v1.OLValueExpression;
+import org.apache.ode.bpel.rtrep.v1.xpath10.OXPath10Expression;
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.compiler.bom.Expression;
+import org.apache.ode.utils.Namespaces;
+
+/**
+ * XPath 1.0 expression compiler for BPEL v1.1.
+ */
+public class XPath10ExpressionCompilerBPEL11 extends XPath10ExpressionCompilerImpl {
+ public XPath10ExpressionCompilerBPEL11() {
+ super(Namespaces.BPEL11_NS);
+ }
+
+ /**
+ * @see org.apache.ode.bpel.compiler.v1.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.v1.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;
+ }
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerBPEL20.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerBPEL20.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerBPEL20.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerBPEL20.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,93 @@
+/*
+ * 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.compiler.v1.xpath10;
+
+import org.apache.ode.bpel.compiler.v1.CompilerContext;
+import org.apache.ode.bpel.compiler.bom.Expression;
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.rtrep.v1.OLValueExpression;
+import org.apache.ode.bpel.rtrep.v1.OExpression;
+import org.apache.ode.bpel.rtrep.v1.xpath10.OXPath10Expression;
+import org.apache.ode.bpel.rtrep.v1.xpath10.OXPath10ExpressionBPEL20;
+import org.apache.ode.utils.Namespaces;
+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() {
+ this(Namespaces.WSBPEL2_0_FINAL_EXEC);
+ }
+
+ public XPath10ExpressionCompilerBPEL20(String bpelNS) {
+ super(bpelNS);
+ TransformerFactory trsf = new net.sf.saxon.TransformerFactoryImpl();
+ XslTransformHandler.getInstance().setTransformerFactory(trsf);
+
+ _qnDoXslTransform = new QName(bpelNS, "doXslTransform");
+ }
+
+ /**
+ * @see org.apache.ode.bpel.compiler.v1.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.v1.api.ExpressionCompiler#compile(java.lang.Object)
+ */
+ public OExpression compile(Object source) throws CompilationException {
+ return _compile((Expression)source, false);
+ }
+ /**
+ * @see org.apache.ode.bpel.compiler.v1.api.ExpressionCompiler#compileLValue(java.lang.Object)
+ */
+ public OLValueExpression compileLValue(Object source) throws CompilationException {
+ return (OLValueExpression)_compile((Expression)source, false);
+ }
+
+ 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;
+ }
+
+
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerBPEL20Draft.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerBPEL20Draft.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerBPEL20Draft.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerBPEL20Draft.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.compiler.v1.xpath10;
+
+import org.apache.ode.utils.Namespaces;
+
+/**
+ * @author Matthieu Riou <mriou at apache dot org>
+ */
+public class XPath10ExpressionCompilerBPEL20Draft extends XPath10ExpressionCompilerBPEL20 {
+
+ public XPath10ExpressionCompilerBPEL20Draft() {
+ super(Namespaces.WS_BPEL_20_NS);
+ }
+
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerImpl.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerImpl.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XPath10ExpressionCompilerImpl.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,139 @@
+/*
+ * 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.compiler.v1.xpath10;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ode.bpel.compiler.v1.ExpressionCompiler;
+import org.apache.ode.bpel.compiler.v1.CompilerContext;
+import org.apache.ode.bpel.compiler.XPathMessages;
+import org.apache.ode.bpel.compiler.CompilationExceptionWrapper;
+import org.apache.ode.bpel.compiler.bom.Expression;
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.rtrep.v1.xpath10.OXPath10Expression;
+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.v1.api.ExpressionCompiler#setCompilerContext(org.apache.ode.bpel.compiler.v1.api.CompilerContext)
+ */
+ public void setCompilerContext(CompilerContext compilerContext) {
+ _compilerContext = compilerContext;
+ }
+
+ /**
+ * @see org.apache.ode.bpel.compiler.v1.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");
+ }
+
+ xpathStr = node.getNodeValue();
+ xpathStr = xpathStr.trim();
+ if (xpathStr.length() == 0) {
+ throw new CompilationException(__msgs.errXPathSyntax(xpathStr));
+ }
+
+ 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));
+ }
+ }
+
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XslCompilationErrorListener.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XslCompilationErrorListener.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XslCompilationErrorListener.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XslCompilationErrorListener.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,86 @@
+/*
+ * 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.compiler.v1.xpath10;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.compiler.v1.CompilerContext;
+import org.apache.ode.bpel.compiler.SourceLocatorWrapper;
+import org.apache.ode.bpel.compiler.SourceLocation;
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.compiler.api.CompilationMessage;
+
+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);
+ SourceLocation loc = exception.getLocator() != null ? new SourceLocatorWrapper(exception.getLocator()) : null;
+ if (_cc != null)
+ _cc.recoveredFromError(loc,ce);
+ else
+ __log.error("XSL stylesheet parsing error! ", exception);
+ }
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XslCompileUriResolver.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XslCompileUriResolver.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XslCompileUriResolver.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath10/XslCompileUriResolver.java Wed Sep 10 12:06:59 2008
@@ -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.compiler.v1.xpath10;
+
+import org.apache.ode.bpel.compiler.v1.CompilerContext;
+import org.apache.ode.bpel.rtrep.v1.xpath10.OXPath10Expression;
+import org.apache.ode.bpel.rtrep.v1.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));
+ }
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/JaxpFunctionResolver.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/JaxpFunctionResolver.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/JaxpFunctionResolver.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/JaxpFunctionResolver.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,265 @@
+/*
+ * 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.compiler.v1.xpath20;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathFunction;
+import javax.xml.xpath.XPathFunctionException;
+import javax.xml.xpath.XPathFunctionResolver;
+
+import org.apache.ode.bpel.compiler.v1.CompilerContext;
+import org.apache.ode.bpel.compiler.v1.xpath10.XslCompileUriResolver;
+import org.apache.ode.bpel.compiler.XPathMessages;
+import org.apache.ode.bpel.compiler.WrappedResolverException;
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.rtrep.common.Constants;
+import org.apache.ode.bpel.rtrep.v1.xpath20.OXPath20ExpressionBPEL20;
+import org.apache.ode.bpel.rtrep.v1.OScope;
+import org.apache.ode.bpel.rtrep.v1.OProcess;
+import org.apache.ode.bpel.rtrep.v1.OXslSheet;
+import org.apache.ode.utils.NSContext;
+import org.apache.ode.utils.Namespaces;
+import org.apache.ode.utils.msg.MessageBundle;
+import org.apache.ode.utils.xsl.XslTransformHandler;
+
+/**
+ * @author mriou <mriou at apache dot org>
+ */
+public class JaxpFunctionResolver implements XPathFunctionResolver {
+
+ private static final XPathMessages __msgs = MessageBundle.getMessages(XPathMessages.class);
+
+ private CompilerContext _cctx;
+ private OXPath20ExpressionBPEL20 _out;
+ private NSContext _nsContext;
+ private String _bpelNS;
+
+ public JaxpFunctionResolver(CompilerContext cctx, OXPath20ExpressionBPEL20 out,
+ NSContext nsContext, String bpelNS) {
+ _cctx = cctx;
+ _bpelNS = bpelNS;
+ _nsContext = nsContext;
+ _bpelNS = bpelNS;
+ _out = out;
+ }
+
+ public XPathFunction resolveFunction(QName functionName, int arity) {
+ if (functionName.getNamespaceURI() == null) {
+ throw new WrappedResolverException("Undeclared namespace for " + functionName);
+ } else if (functionName.getNamespaceURI().equals(_bpelNS)) {
+ String localName = functionName.getLocalPart();
+ if (Constants.EXT_FUNCTION_GETVARIABLEPROPRTY.equals(localName)) {
+ return new GetVariableProperty();
+ } else if (Constants.EXT_FUNCTION_DOXSLTRANSFORM.equals(localName)) {
+ return new DoXslTransform();
+ } else {
+ throw new WrappedResolverException(__msgs.errUnknownBpelFunction(localName));
+ }
+ } else if (functionName.getNamespaceURI().equals(Namespaces.ODE_EXTENSION_NS)) {
+ String localName = functionName.getLocalPart();
+ if (Constants.NON_STDRD_FUNCTION_SPLIT_TO_ELEMENTS.equals(localName) ||
+ Constants.NON_STDRD_FUNCTION_DEPRECATED_SPLIT_TO_ELEMENTS.equals(localName)) {
+ return new SplitToElements();
+ } else if (Constants.NON_STDRD_FUNCTION_COMBINE_URL.equals(localName) ||
+ Constants.NON_STDRD_FUNCTION_DEPRECATED_COMBINE_URL.equals(localName)) {
+ return new CombineUrl();
+ } else if (Constants.NON_STDRD_FUNCTION_COMPOSE_URL.equals(localName) ||
+ Constants.NON_STDRD_FUNCTION_EXPAND_TEMPLATE.equals(localName) ||
+ Constants.NON_STDRD_FUNCTION_DEPRECATED_COMPOSE_URL.equals(localName) ||
+ Constants.NON_STDRD_FUNCTION_DEPRECATED_EXPAND_TEMPLATE.equals(localName)) {
+ return new ComposeUrl();
+ } else if (Constants.NON_STDRD_FUNCTION_DOM_TO_STRING.equals(localName) ||
+ Constants.NON_STDRD_FUNCTION_DEPRECATED_DOM_TO_STRING.equals(localName)) {
+ return new DomToString();
+ } else if (Constants.NON_STDRD_FUNCTION_INSERT_AFTER.equals(localName)) {
+ return new InsertAfter();
+ } else if (Constants.NON_STDRD_FUNCTION_INSERT_AS_FIRST_INTO.equals(localName)) {
+ return new InsertAsFirstInto();
+ } else if (Constants.NON_STDRD_FUNCTION_INSERT_AS_LAST_INTO.equals(localName)) {
+ return new InsertAsLastInto();
+ } else if (Constants.NON_STDRD_FUNCTION_INSERT_BEFORE.equals(localName)) {
+ return new InsertBefore();
+ } else if (Constants.NON_STDRD_FUNCTION_DELETE.equals(localName)) {
+ return new Delete();
+ } else if (Constants.NON_STDRD_FUNCTION_RENAME.equals(localName)) {
+ return new Rename();
+ }
+ }
+
+ return null;
+ }
+
+
+ public class GetVariableProperty implements XPathFunction {
+ public Object evaluate(List params) throws XPathFunctionException {
+ if (params.size() != 2) {
+ throw new CompilationException(
+ __msgs.errInvalidNumberOfArguments(Constants.EXT_FUNCTION_GETVARIABLEPROPRTY));
+ }
+ String varName = (String) params.get(0);
+ OScope.Variable v = _cctx.resolveVariable(varName);
+ _out.vars.put(varName, v);
+
+ String propName = (String) 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);
+ return "";
+ }
+ }
+
+ public class DoXslTransform implements XPathFunction {
+ public Object evaluate(List params) throws XPathFunctionException {
+ if (params.size() < 2 || params.size() % 2 != 0) {
+ throw new CompilationException(
+ __msgs.errInvalidNumberOfArguments(Constants.EXT_FUNCTION_DOXSLTRANSFORM));
+ }
+
+ String xslUri = (String) 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.errXslCompilation(xslUri, e.toString()));
+ }
+
+ _out.xslSheets.put(xslSheet.uri, xslSheet);
+ return "";
+ }
+ }
+
+ /**
+ * Compile time checking for the non standard ode:splitToElements function.
+ */
+ public class SplitToElements implements XPathFunction {
+ public Object evaluate(List params) throws XPathFunctionException {
+ if (params.size() < 3 || params.size() > 4) {
+ throw new CompilationException(
+ __msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_SPLIT_TO_ELEMENTS));
+ }
+ return "";
+ }
+ }
+
+ public static class CombineUrl implements XPathFunction {
+ public Object evaluate(List args) throws XPathFunctionException {
+ if (args.size() != 2) {
+ throw new CompilationException(__msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_COMBINE_URL));
+ }
+ return "";
+ }
+ }
+
+ public static class DomToString implements XPathFunction {
+ public Object evaluate(List args) throws XPathFunctionException {
+ if (args.size() != 1) {
+ throw new CompilationException(__msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_DOM_TO_STRING));
+ }
+ return "";
+ }
+ }
+
+ public static class ComposeUrl implements XPathFunction {
+ public Object evaluate(List args) throws XPathFunctionException {
+ boolean separareParameteters;
+ if (args.size() != 2 && (args.size() <= 2 || args.size() % 2 != 1)) {
+ throw new CompilationException(__msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_COMPOSE_URL));
+ }
+ return "";
+ }
+ }
+
+ public class InsertInto implements XPathFunction {
+ public Object evaluate(List args) throws XPathFunctionException {
+ if (args.size() != 3) {
+ throw new CompilationException(__msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_INSERT_AFTER));
+ }
+ return "";
+ }
+ }
+
+ public class InsertAfter implements XPathFunction {
+ public Object evaluate(List args) throws XPathFunctionException {
+ if (args.size() < 2 || args.size() > 3) {
+ throw new CompilationException(__msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_INSERT_AFTER));
+ }
+ return "";
+ }
+ }
+
+ public class InsertBefore implements XPathFunction {
+ public Object evaluate(List args) throws XPathFunctionException {
+ if (args.size() < 2 || args.size() > 3) {
+ throw new CompilationException(__msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_INSERT_BEFORE));
+ }
+ return "";
+ }
+ }
+
+ public class InsertAsFirstInto implements XPathFunction {
+ public Object evaluate(List args) throws XPathFunctionException {
+ if (args.size() != 2) {
+ throw new CompilationException(__msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_INSERT_AS_FIRST_INTO));
+ }
+ return "";
+ }
+ }
+
+ public class InsertAsLastInto implements XPathFunction {
+ public Object evaluate(List args) throws XPathFunctionException {
+ if (args.size() != 2) {
+ throw new CompilationException(__msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_INSERT_AS_LAST_INTO));
+ }
+ return "";
+ }
+ }
+
+ public class Delete implements XPathFunction {
+ public Object evaluate(List args) throws XPathFunctionException {
+ if (args.size() < 1 || args.size() > 2) {
+ throw new CompilationException(__msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_DELETE));
+ }
+ return "";
+ }
+ }
+
+ public class Rename implements XPathFunction {
+ public Object evaluate(List args) throws XPathFunctionException {
+ if (args.size() < 2) {
+ throw new CompilationException(__msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_RENAME));
+ }
+ return "";
+ }
+ }
+
+
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/JaxpVariableResolver.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/JaxpVariableResolver.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/JaxpVariableResolver.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/JaxpVariableResolver.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,122 @@
+/*
+ * 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.compiler.v1.xpath20;
+
+import org.apache.ode.bpel.compiler.v1.CompilerContext;
+import org.apache.ode.bpel.compiler.XPathMessages;
+import org.apache.ode.bpel.compiler.WrappedResolverException;
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.rtrep.v1.*;
+import org.apache.ode.bpel.rtrep.v1.xpath10.OXPath10ExpressionBPEL20;
+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;
+import javax.xml.xpath.XPathVariableResolver;
+
+/**
+ * This is a mock implementation of the XPathVariableResolver for compilation. It
+ * always returns an empty string which allows execution of XPath expressions even
+ * if we don't have any values yet. This way we can easily rule out invalid variables
+ * and isolate properly BPEL variables.
+ * @author mriou <mriou at apache dot org>
+ */
+public class JaxpVariableResolver implements XPathVariableResolver {
+
+ private static final XPathMessages __msgs = MessageBundle.getMessages(XPathMessages.class);
+
+ private CompilerContext _cctx;
+ private OXPath10ExpressionBPEL20 _oxpath;
+
+ public JaxpVariableResolver(CompilerContext cctx, OXPath10ExpressionBPEL20 oxpath) {
+ _cctx = cctx;
+ _oxpath = oxpath;
+ }
+
+ public Object resolveVariable(QName variableName) {
+ // Custom variables
+ if ("ode".equals(variableName.getPrefix())
+ || Namespaces.ODE_EXTENSION_NS.equals(variableName.getNamespaceURI())) {
+ if ("pid".equals(variableName.getLocalPart())) return "";
+ }
+
+ try {
+ String name = variableName.getLocalPart();
+ if(_oxpath.isJoinExpression) {
+ // these resolve to links
+ OLink olink = _cctx.resolveLink(name);
+ _oxpath.links.put(name, olink);
+ return Boolean.TRUE;
+ } else {
+ int dot = name.indexOf('.');
+ if (dot != -1)
+ name = name.substring(0,dot);
+ OScope.Variable var = _cctx.resolveVariable(name);
+ _oxpath.vars.put(name, var);
+ return extractValue(var, var.type);
+ }
+ } catch (CompilationException e) {
+ throw new WrappedResolverException(e);
+ }
+ }
+
+ 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
+ if (((OMessageVarType)varType).parts.size() == 0)
+ throw new WrappedResolverException(__msgs.errExpressionMessageNoPart(var.name));
+ return extractValue(var, ((OMessageVarType)varType).parts.values().iterator().next().type);
+ }
+ return "";
+ }
+
+ private Object generateFromType(QName typeName) {
+ if (typeName.getNamespaceURI().equals(Namespaces.XML_SCHEMA)) {
+ if (typeName.getLocalPart().equals("int") ||
+ typeName.getLocalPart().equals("integer") ||
+ typeName.getLocalPart().equals("short") ||
+ typeName.getLocalPart().equals("long") ||
+ typeName.getLocalPart().equals("byte") ||
+ typeName.getLocalPart().equals("float") ||
+ typeName.getLocalPart().equals("double") ||
+ typeName.getLocalPart().equals("nonPositiveInteger") ||
+ typeName.getLocalPart().equals("nonNegativeInteger") ||
+ typeName.getLocalPart().equals("negativeInteger") ||
+ typeName.getLocalPart().equals("unsignedLong") ||
+ typeName.getLocalPart().equals("unsignedInt") ||
+ typeName.getLocalPart().equals("unsignedShort") ||
+ typeName.getLocalPart().equals("unsignedByte"))
+ return 0;
+ if (typeName.getLocalPart().equals("boolean"))
+ return Boolean.TRUE;
+ if (typeName.getLocalPart().equals("string"))
+ return "";
+ }
+ Document doc = DOMUtils.newDocument();
+ doc.appendChild(doc.createElement("empty"));
+ return doc.getDocumentElement();
+ }
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/OdeXPathFunctionLibrary.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/OdeXPathFunctionLibrary.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/OdeXPathFunctionLibrary.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/OdeXPathFunctionLibrary.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,72 @@
+/*
+ * 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.compiler.v1.xpath20;
+
+import net.sf.saxon.expr.Expression;
+import net.sf.saxon.trans.XPathException;
+import net.sf.saxon.trans.StaticError;
+import net.sf.saxon.xpath.XPathFunctionCall;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathFunction;
+import javax.xml.xpath.XPathFunctionException;
+import java.util.ArrayList;
+
+/**
+ * Overloading the XPathFunctionLibrary to force it to initialize our functions giving
+ * the provided parameters. Otherwise the Saxon implemetation just never gives you
+ * any parameter before runtime.
+ * @author mriou <mriou at apache dot org>
+ */
+public class OdeXPathFunctionLibrary extends net.sf.saxon.xpath.XPathFunctionLibrary {
+ private static final long serialVersionUID = -8885396864277163797L;
+
+ private JaxpFunctionResolver _funcResolver;
+
+ public OdeXPathFunctionLibrary(JaxpFunctionResolver funcResolver) {
+ _funcResolver = funcResolver;
+ }
+
+ public Expression bind(int nameCode, String uri, String local, Expression[] staticArgs) throws XPathException {
+ QName name = new QName(uri, local);
+ XPathFunction function = _funcResolver.resolveFunction(name, staticArgs.length);
+ if (function == null) {
+ return null;
+ }
+
+ // Converting the expression array to the simple string
+ ArrayList args = new ArrayList(staticArgs.length);
+ for (Expression expression : staticArgs) {
+ String exprStr = expression.toString();
+ if (exprStr.startsWith("\"")) exprStr = exprStr.substring(1);
+ if (exprStr.endsWith("\"")) exprStr = exprStr.substring(0, exprStr.length() - 1);
+ args.add(exprStr);
+ }
+
+ try {
+ function.evaluate(args);
+ } catch (XPathFunctionException e) {
+ throw new StaticError(e);
+ }
+ XPathFunctionCall fc = new XPathFunctionCall(function);
+ fc.setArguments(staticArgs);
+ return fc;
+ }
+
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/SaxonContext.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/SaxonContext.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/SaxonContext.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/SaxonContext.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,111 @@
+/*
+ * 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.compiler.v1.xpath20;
+
+import net.sf.saxon.xpath.StandaloneContext;
+import net.sf.saxon.xpath.XPathFunctionLibrary;
+import net.sf.saxon.trans.Variable;
+import net.sf.saxon.trans.XPathException;
+import net.sf.saxon.trans.StaticError;
+import net.sf.saxon.om.QNameException;
+import net.sf.saxon.om.NameChecker;
+import net.sf.saxon.Configuration;
+import net.sf.saxon.functions.FunctionLibraryList;
+import net.sf.saxon.functions.FunctionLibrary;
+import net.sf.saxon.expr.VariableReference;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ode.utils.Namespaces;
+
+import java.util.List;
+
+/**
+ * Hooks on Saxon StandaloneContext to be notified when the compilation
+ * finds some variables and functions. This allows us to prepare the
+ * OXpathExpression with variable references and all the things needed
+ * at runtime.
+ * @author mriou <mriou at apache dot org>
+ */
+public class SaxonContext extends StandaloneContext {
+
+ private JaxpVariableResolver _varResolver;
+ private JaxpFunctionResolver _funcResolver;
+
+ public SaxonContext(Configuration config, JaxpVariableResolver varResolver,
+ JaxpFunctionResolver funcResolver) {
+ super(config);
+
+ // We need to remove the default XPathFunctionLibrary to replace it
+ // with our own
+ List libList = ((FunctionLibraryList)getFunctionLibrary()).libraryList;
+ XPathFunctionLibrary xpathLib = null;
+ for (Object lib : libList) {
+ FunctionLibrary flib = (FunctionLibrary) lib;
+ if (flib instanceof XPathFunctionLibrary) xpathLib = (XPathFunctionLibrary) flib;
+ }
+ if (xpathLib != null) libList.remove(xpathLib);
+ OdeXPathFunctionLibrary oxpfl = new OdeXPathFunctionLibrary(funcResolver);
+ oxpfl.setXPathFunctionResolver(funcResolver);
+
+ oxpfl.setXPathFunctionResolver(_funcResolver);
+ ((FunctionLibraryList)getFunctionLibrary()).addFunctionLibrary(oxpfl);
+
+ _varResolver = varResolver;
+ _funcResolver = funcResolver;
+ }
+
+ public Variable declareVariable(String qname, Object initialValue) throws XPathException {
+ String prefix;
+ String localName;
+ final NameChecker checker = getConfiguration().getNameChecker();
+ try {
+ String[] parts = checker.getQNameParts(qname);
+ prefix = parts[0];
+ localName = parts[1];
+ } catch (QNameException err) {
+ throw new StaticError("Invalid QName for variable: " + qname);
+ }
+ String uri = "";
+ if (!("".equals(prefix))) {
+ uri = getURIForPrefix(prefix);
+ }
+
+ _varResolver.resolveVariable(new QName(uri, localName, prefix));
+
+ return super.declareVariable(qname, initialValue);
+ }
+
+ public VariableReference bindVariable(int fingerprint) throws StaticError {
+ String localName = getNamePool().getLocalName(fingerprint);
+ String prefix = getNamePool().getPrefix(fingerprint);
+ String ns = getNamePool().getURI(fingerprint);
+ // The prefix is lost by compilation, hardcoding it from the ns.
+ if (Namespaces.ODE_EXTENSION_NS.equals(ns)) prefix = "ode";
+ if (prefix != null && prefix.length() > 0) prefix = prefix + ":";
+ try {
+ declareVariable(prefix + localName, null);
+ } catch (XPathException e) {
+ throw new StaticError(e);
+ }
+ return super.bindVariable(fingerprint);
+ }
+
+
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/XPath20ExpressionCompilerBPEL20.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/XPath20ExpressionCompilerBPEL20.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/XPath20ExpressionCompilerBPEL20.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/XPath20ExpressionCompilerBPEL20.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.compiler.v1.xpath20;
+
+import org.apache.ode.utils.Namespaces;
+
+
+/**
+ * XPath 2.0 compiler for the BPEL 2.0 final spec.
+ * @author mriou <mriou at apache dot org>
+ */
+public class XPath20ExpressionCompilerBPEL20 extends XPath20ExpressionCompilerImpl {
+
+ public XPath20ExpressionCompilerBPEL20() {
+ super(Namespaces.WSBPEL2_0_FINAL_EXEC);
+ }
+}
Added: ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/XPath20ExpressionCompilerBPEL20Draft.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/XPath20ExpressionCompilerBPEL20Draft.java?rev=693931&view=auto
==============================================================================
--- ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/XPath20ExpressionCompilerBPEL20Draft.java (added)
+++ ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v1/xpath20/XPath20ExpressionCompilerBPEL20Draft.java Wed Sep 10 12:06:59 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.compiler.v1.xpath20;
+
+import org.apache.ode.utils.Namespaces;
+
+/**
+ * @author Matthieu Riou <mriou at apache dot org>
+ */
+public class XPath20ExpressionCompilerBPEL20Draft extends XPath20ExpressionCompilerImpl {
+
+ public XPath20ExpressionCompilerBPEL20Draft() {
+ super(Namespaces.WS_BPEL_20_NS);
+ }
+
+}