You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by ka...@apache.org on 2008/12/05 20:17:52 UTC

svn commit: r723825 - in /ode/branches/APACHE_ODE_1.X: bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/ bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/

Author: karthick
Date: Fri Dec  5 11:17:52 2008
New Revision: 723825

URL: http://svn.apache.org/viewvc?rev=723825&view=rev
Log:
Re-introduce xdt functions for backward compabibility

Modified:
    ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.java
    ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java
    ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java

Modified: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.java?rev=723825&r1=723824&r2=723825&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.java Fri Dec  5 11:17:52 2008
@@ -67,6 +67,12 @@
     public static final String NON_STDRD_FUNCTION_RENAME = "rename";
     public static final String NON_STDRD_FUNCTION_PROCESS_PROPERTY = "process-property";
     
+    /**
+     * Non standard extension functions in the deprecated "xdt" namespace
+     */
+    public static final String NON_STDRD_FUNCTION_DAY_TIME_DURATION = "dayTimeDuration";
+    public static final String NON_STDRD_FUNCTION_YEAR_MONTH_DURATION = "yearMonthDuration";
+    
     public static final String XQUERY_FUNCTION_HANDLER_COMPILER = "org.apache.ode.bpel.elang.xquery10.compiler.XQuery10BpelFunctions";
     public static final String XQUERY_FUNCTION_HANDLER_RUNTIME = "org.apache.ode.bpel.elang.xquery10.runtime.XQuery10BpelFunctions";
 

Modified: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java?rev=723825&r1=723824&r2=723825&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java Fri Dec  5 11:17:52 2008
@@ -103,6 +103,13 @@
             } else if (Constants.NON_STDRD_FUNCTION_PROCESS_PROPERTY.equals(localName)) {
             	return new ProcessProperty();
             }
+        } else if (functionName.getNamespaceURI().equals(Namespaces.DEPRECATED_XDT_NS)) {
+            String localName = functionName.getLocalPart();
+            if (Constants.NON_STDRD_FUNCTION_DAY_TIME_DURATION.equals(localName)) {
+                return new DayTimeDuration();
+            } else if (Constants.NON_STDRD_FUNCTION_YEAR_MONTH_DURATION.equals(localName)) {
+                return new YearMonthDuration();
+            }
         }
 
         return null;
@@ -270,4 +277,22 @@
     	}
     }
 
+    public class DayTimeDuration implements XPathFunction {
+    	public Object evaluate(List args) throws XPathFunctionException {
+            if (args.size() != 1) {
+                throw new CompilationException(__msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_DAY_TIME_DURATION));
+            }
+            return "";
+    	}
+    }
+
+    public class YearMonthDuration implements XPathFunction {
+    	public Object evaluate(List args) throws XPathFunctionException {
+            if (args.size() != 1) {
+                throw new CompilationException(__msgs.errInvalidNumberOfArguments(Constants.NON_STDRD_FUNCTION_YEAR_MONTH_DURATION));
+            }
+            return "";
+    	}
+    }
+
 }

Modified: ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java?rev=723825&r1=723824&r2=723825&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java Fri Dec  5 11:17:52 2008
@@ -19,7 +19,6 @@
 
 package org.apache.ode.bpel.elang.xpath20.runtime;
 
-import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -38,8 +37,10 @@
 
 import net.sf.saxon.dom.NodeWrapper;
 import net.sf.saxon.trans.XPathException;
+import net.sf.saxon.value.DayTimeDurationValue;
 import net.sf.saxon.value.IntegerValue;
 import net.sf.saxon.value.QNameValue;
+import net.sf.saxon.value.YearMonthDurationValue;
 
 import org.apache.commons.httpclient.URIException;
 import org.apache.commons.logging.Log;
@@ -63,7 +64,6 @@
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Text;
-import org.xml.sax.SAXException;
 
 /**
  * @author mriou <mriou at apache dot org>
@@ -130,6 +130,13 @@
             } else if (Constants.NON_STDRD_FUNCTION_PROCESS_PROPERTY.equals(localName)) {
             	return new ProcessProperty();
             }
+        } else if (functionName.getNamespaceURI().equals(Namespaces.DEPRECATED_XDT_NS)) {
+            String localName = functionName.getLocalPart();
+            if (Constants.NON_STDRD_FUNCTION_DAY_TIME_DURATION.equals(localName)) {
+                return new DayTimeDuration();
+            } else if (Constants.NON_STDRD_FUNCTION_YEAR_MONTH_DURATION.equals(localName)) {
+                return new YearMonthDuration();
+            }
         }
 
         return null;
@@ -1132,6 +1139,108 @@
     	}
     }
     
+    public class DayTimeDuration implements XPathFunction {
+    	public Object evaluate(List args) throws XPathFunctionException {
+            if (args.size() != 1)
+                throw new XPathFunctionException(new FaultException(new QName(Namespaces.ODE_EXTENSION_NS, "dayTimeDurationPropertyInvalidSource"), "Invalid arguments"));
+
+            if (__log.isDebugEnabled()) {
+                __log.debug("dayTimeDuration call(context=" + _ectx + " args=" + args + ")");
+            }
+
+            String argument = null;
+            Element targetElmt = null;
+            try {
+                if (args.get(0) instanceof List) {
+                    List elmts = (List) args.get(0);
+                    if (elmts.size() != 1) throw new XPathFunctionException(
+                            new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
+                                    "The bpws:dayTimeDuration function MUST be passed a single " +
+                                            "element node."));
+                    if (elmts.get(0) instanceof Element) {
+                        targetElmt = (Element) elmts.get(0);
+                    } else if (elmts.get(0) instanceof String) {
+                    	argument = (String) elmts.get(0);
+                    }
+                } else if (args.get(0) instanceof NodeWrapper) {
+                    targetElmt = (Element) ((NodeWrapper) args.get(0)).getUnderlyingNode();
+                } else if (args.get(0) instanceof Element) {
+                    targetElmt = (Element) args.get(0);
+                } else if (args.get(0) instanceof String)	{
+                	argument = (String) args.get(0);
+                } else {
+                    throw new XPathFunctionException("Unexpected argument type: "+args.get(0).getClass());
+                }
+                if (argument == null) {
+                	if (targetElmt != null) {
+                		argument = targetElmt.getTextContent();
+                	}
+                }
+            } catch (IllegalArgumentException e) {
+                throw new XPathFunctionException(
+                		new FaultException(_oxpath.getOwner().constants.qnInvalidExpressionValue,
+                				"Invalid argument: URI Template expected. " + args.get(0), e));
+            } catch (ClassCastException e) {
+                throw new XPathFunctionException(
+                        new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
+                                "The bpws:dayTimeDuration function MUST be passed a single " +
+                                        "element node."));
+            }
+            return DayTimeDurationValue.makeDayTimeDurationValue(argument);
+    	}
+    }
+    
+    public class YearMonthDuration implements XPathFunction {
+    	public Object evaluate(List args) throws XPathFunctionException {
+            if (args.size() != 1)
+                throw new XPathFunctionException(new FaultException(new QName(Namespaces.ODE_EXTENSION_NS, "yearMonthDurationPropertyInvalidSource"), "Invalid arguments"));
+
+            if (__log.isDebugEnabled()) {
+                __log.debug("yearMonthDuration call(context=" + _ectx + " args=" + args + ")");
+            }
+
+            String argument = null;
+            Element targetElmt = null;
+            try {
+                if (args.get(0) instanceof List) {
+                    List elmts = (List) args.get(0);
+                    if (elmts.size() != 1) throw new XPathFunctionException(
+                            new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
+                                    "The bpws:yearMonthDuration function MUST be passed a single " +
+                                            "element node."));
+                    if (elmts.get(0) instanceof Element) {
+                        targetElmt = (Element) elmts.get(0);
+                    } else if (elmts.get(0) instanceof String) {
+                    	argument = (String) elmts.get(0);
+                    }
+                } else if (args.get(0) instanceof NodeWrapper) {
+                    targetElmt = (Element) ((NodeWrapper) args.get(0)).getUnderlyingNode();
+                } else if (args.get(0) instanceof Element) {
+                    targetElmt = (Element) args.get(0);
+                } else if (args.get(0) instanceof String)	{
+                	argument = (String) args.get(0);
+                } else {
+                    throw new XPathFunctionException("Unexpected argument type: "+args.get(0).getClass());
+                }
+                if (argument == null) {
+                	if (targetElmt != null) {
+                		argument = targetElmt.getTextContent();
+                	}
+                }
+            } catch (IllegalArgumentException e) {
+                throw new XPathFunctionException(
+                		new FaultException(_oxpath.getOwner().constants.qnInvalidExpressionValue,
+                				"Invalid argument: URI Template expected. " + args.get(0), e));
+            } catch (ClassCastException e) {
+                throw new XPathFunctionException(
+                        new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
+                                "The bpws:yearMonthDuration function MUST be passed a single " +
+                                        "element node."));
+            }
+            return YearMonthDurationValue.makeYearMonthDurationValue(argument);
+    	}
+    }
+    
     public static class Helper {
         /**
          * Extract a string from the given parameter.<br/>