|
From: <pm_...@us...> - 2011-05-05 07:23:49
|
Revision: 4313
http://mxquery.svn.sourceforge.net/mxquery/?rev=4313&view=rev
Author: pm_fischer
Date: 2011-05-05 07:23:40 +0000 (Thu, 05 May 2011)
Log Message:
-----------
Import functionality for Java methods/objects (initial version)
- same syntax and semantics as Saxon-PE/EE, BaseX, eXist, Qizx
- added "wrapped object" to XDM implementation
- currently limited support for data types, needs to be extended
- partial tests for import
Cleanup up wrong use of error codes in XQIB (E0017, not A0017)
AtomicItemFactory
- now has a method to take any Java object
- split into common part (all platforms) and platform-specific part
for more data types
Modified Paths:
--------------
trunk/MXQuery/build.xml
trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/Type.java
trunk/MXQuery/src/ch/ethz/mxquery/exceptions/ErrorCodes.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/PatternDataHelper.java
trunk/MXQuery/src/ch/ethz/mxquery/sms/MMimpl/StreamStoreInput.java
trunk/MXQuery/src/ch/ethz/mxquery/sms/MMimpl/TokenBufferStore.java
trunk/MXQuery/src/ch/ethz/mxquery/xdmio/XDMAtomicItemFactory.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddEventListener.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveEventListener.java
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/JavaImportTests.java
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/pattern/PatternClauseTests.java
Added Paths:
-----------
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/XDMAtomicItemFactory.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/xdmio/XDMAtomicItemFactory.java
Modified: trunk/MXQuery/build.xml
===================================================================
--- trunk/MXQuery/build.xml 2011-05-05 07:18:53 UTC (rev 4312)
+++ trunk/MXQuery/build.xml 2011-05-05 07:23:40 UTC (rev 4313)
@@ -426,6 +426,7 @@
<delete file="${midptmp.dir}/ch/ethz/mxquery/iterators/PGFLWORIterator.java"/>
<delete file="${midptmp.dir}/ch/ethz/mxquery/iterators/PGroupBy.java"/>
<delete file="${midptmp.dir}/ch/ethz/mxquery/iterators/CommandLineInIterator.java"/>
+ <delete file="${xqibtmp.dir}/ch/ethz/mxquery/iterators/NativeFuncCall.java"/>
<delete file="${midptmp.dir}/ch/ethz/mxquery/iterators/forseq/ForseqWindowIndexIterator.java"/>
<delete file="${midptmp.dir}/ch/ethz/mxquery/iterators/forseq/ForseqWindowEarlyBinding.java"/>
<delete file="${midptmp.dir}/ch/ethz/mxquery/iterators/forseq/ForseqWindowEarlyBindingParallel.java"/>
@@ -607,6 +608,7 @@
<delete file="${xqibtmp.dir}/ch/ethz/mxquery/iterators/forseq/ForseqWindowIndexIterator.java"/>
<delete file="${xqibtmp.dir}/ch/ethz/mxquery/iterators/forseq/ForseqWindowEarlyBinding.java"/>
<delete file="${xqibtmp.dir}/ch/ethz/mxquery/iterators/forseq/ForseqWindowEarlyBindingParallel.java"/>
+ <delete file="${xqibtmp.dir}/ch/ethz/mxquery/iterators/NativeFuncCall.java"/>
<delete file="${xqibtmp.dir}/ch/ethz/mxquery/util/UnicodeInputStream.java"/>
<delete file="${xqibtmp.dir}/ch/ethz/mxquery/util/UnicodeReader.java"/>
<delete file="${xqibtmp.dir}/ch/ethz/mxquery/functions/mxq/DirectXMLWrapperIterator.java"/>
@@ -675,9 +677,9 @@
<copy todir="${xqibtmp.dir}" overwrite="yes"><fileset dir="${xqibsrc.dir}"/></copy>
+ <copy file="${midpsrc.dir}/ch/ethz/mxquery/functions/NativeFunctionImporter.java" todir="${customtmp.dir}/ch/ethz/mxquery/functions/" overwrite="yes" />
<copy file="${midpsrc.dir}/ch/ethz/mxquery/sms/MMimpl/TokenBufferStore.java" todir="${customtmp.dir}/ch/ethz/mxquery/sms/MMimpl/" overwrite="yes" />
- <copy file="${midpsrc.dir}/ch/ethz/mxquery/bindings/WindowBuffer.java" todir="${customtmp.dir}/ch/ethz/mxquery/bindings/" overwrite="yes" />
-
+ <copy file="${midpsrc.dir}/ch/ethz/mxquery/bindings/WindowBuffer.java" todir="${customtmp.dir}/ch/ethz/mxquery/bindings/" overwrite="yes" />
</target>
Added: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/NativeFunctionImporter.java (rev 0)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-05 07:23:40 UTC (rev 4313)
@@ -0,0 +1,16 @@
+package ch.ethz.mxquery.functions;
+
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.QueryLocation;
+
+public class NativeFunctionImporter {
+
+
+ public static Context getNativeMethods(String className) throws MXQueryException{
+ Context ctx = new Context();
+ throw new MXQueryException(ErrorCodes.A0002_EC_NOT_SUPPORTED, "Import of native methods not supported", QueryLocation.OUTSIDE_QUERY_LOC);
+ }
+}
Added: trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/XDMAtomicItemFactory.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/XDMAtomicItemFactory.java (rev 0)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/XDMAtomicItemFactory.java 2011-05-05 07:23:40 UTC (rev 4313)
@@ -0,0 +1,51 @@
+/* Copyright 2006 - 2009 ETH Zurich
+ *
+ * Licensed 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 ch.ethz.mxquery.xdmio;
+
+
+import ch.ethz.mxquery.datamodel.MXQueryBigDecimal;
+import ch.ethz.mxquery.datamodel.MXQueryDate;
+import ch.ethz.mxquery.datamodel.MXQueryDateTime;
+import ch.ethz.mxquery.datamodel.MXQueryDayTimeDuration;
+import ch.ethz.mxquery.datamodel.MXQueryDouble;
+import ch.ethz.mxquery.datamodel.MXQueryDuration;
+import ch.ethz.mxquery.datamodel.MXQueryFloat;
+import ch.ethz.mxquery.datamodel.MXQueryGregorian;
+import ch.ethz.mxquery.datamodel.MXQueryTime;
+import ch.ethz.mxquery.datamodel.MXQueryYearMonthDuration;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.xdm.DateTimeToken;
+import ch.ethz.mxquery.datamodel.xdm.DateToken;
+import ch.ethz.mxquery.datamodel.xdm.DayTimeDurToken;
+import ch.ethz.mxquery.datamodel.xdm.DurationToken;
+import ch.ethz.mxquery.datamodel.xdm.GregorianToken;
+import ch.ethz.mxquery.datamodel.xdm.TimeToken;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.datamodel.xdm.YearMonthDurToken;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.iterators.TokenIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+/**
+ * Factory to create items of all atomic types in XDM
+ * @author Peter Fischer
+ *
+ */
+public class XDMAtomicItemFactory extends SharedAtomicItemFactory{
+
+}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/Type.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/Type.java 2011-05-05 07:18:53 UTC (rev 4312)
+++ trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/Type.java 2011-05-05 07:23:40 UTC (rev 4313)
@@ -799,7 +799,7 @@
public static boolean isNumericPrimitiveType(int type) {
// clean additional info bits
type = type & MASK_CLEAN_ADDITIONAL_INFO;
- return isSubTypeOf(type, DECIMAL, null) || type == DOUBLE || type == FLOAT || type == DECIMAL;
+ return isSubTypeOf(type, DECIMAL, null) || type == DOUBLE || type == FLOAT || type == DECIMAL || type == NUMBER;
// return isSubTypeOf(type, NUMBER);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/exceptions/ErrorCodes.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/exceptions/ErrorCodes.java 2011-05-05 07:18:53 UTC (rev 4312)
+++ trunk/MXQuery/src/ch/ethz/mxquery/exceptions/ErrorCodes.java 2011-05-05 07:23:40 UTC (rev 4313)
@@ -141,8 +141,10 @@
public final static QName A0014_Unspecified_Service_Name = new QName(XQStaticContext.URI_ERR,"err","XQST0096");
public final static QName A0015_Unspecified_Endpoint = new QName(XQStaticContext.URI_ERR,"err","XQST0097");
public final static QName A0016_Endpoint_Does_Not_Exist = new QName(XQStaticContext.URI_ERR,"err","XQST0098");
- public final static QName A0017_Duplicate_Pattern_Var = new QName(URI_MXQ_ERR,"app","MXQE0013");
- public final static QName A0017_Missing_Pattern_Var_Decl = new QName(URI_MXQ_ERR,"app","MXQE0013");
+ public final static QName A0017_Duplicate_Pattern_Var = new QName(URI_MXQ_ERR,"app","MXQE0017");
+ public final static QName A0018_Missing_Pattern_Var_Decl = new QName(URI_MXQ_ERR,"app","MXQE0018");
+ public final static QName A0019_Unknown_Class = new QName(URI_MXQ_ERR,"app","MXQE0019");
+ public final static QName A0020_Incompatible_Overload = new QName(URI_MXQ_ERR,"app","MXQE0020");
/* Error codes from Update Facility, version 28.08.2007 */
public final static QName U0001_UPDATE_STATIC_UPDATING_EXPRESSION_NOT_ALLOWED_HERE = new QName(XQStaticContext.URI_ERR,"err","XUST0001");
Added: trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java (rev 0)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-05 07:23:40 UTC (rev 4313)
@@ -0,0 +1,192 @@
+package ch.ethz.mxquery.functions;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.types.TypeInfo;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.exceptions.StaticException;
+import ch.ethz.mxquery.iterators.NativeFuncCall;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class NativeFunctionImporter {
+
+ static class MethodData {
+ Class baseClass;
+ String methodName;
+ TypeInfo [] paramTypes;
+ TypeInfo returnType;
+
+ public MethodData(Class baseClass, String methodName,
+ TypeInfo[] paramTypes, TypeInfo returnType) {
+ super();
+ this.baseClass = baseClass;
+ this.methodName = methodName;
+ this.paramTypes = paramTypes;
+ this.returnType = returnType;
+ }
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((baseClass == null) ? 0 : baseClass.hashCode());
+ result = prime * result
+ + ((methodName == null) ? 0 : methodName.hashCode());
+ result = prime * result + paramTypes.length;
+ return result;
+ }
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ MethodData other = (MethodData) obj;
+ if (baseClass == null) {
+ if (other.baseClass != null)
+ return false;
+ } else if (!baseClass.equals(other.baseClass))
+ return false;
+ if (methodName == null) {
+ if (other.methodName != null)
+ return false;
+ } else if (!methodName.equals(other.methodName))
+ return false;
+ if (paramTypes == null) {
+ if (other.paramTypes != null)
+ return false;
+ }else if (paramTypes.length != other.paramTypes.length)
+ return false;
+ return true;
+ }
+
+ }
+
+ public static Context getNativeMethods(String className) throws MXQueryException{
+ Context ctx = new Context();
+ try {
+ Class toImport = Class.forName(className);
+
+ Map functions = new HashMap();
+
+ Constructor [] constructors = toImport.getConstructors();
+ for (int i=0;i<constructors.length;i++) {
+ Constructor cur = constructors[i];
+ int mod = cur.getModifiers();
+ if (Modifier.isPublic(mod)) {
+ TypeInfo [] params;
+ Class [] paramTypes = cur.getParameterTypes();
+ params = new TypeInfo[paramTypes.length];
+ for (int j=0;j<params.length;j++) {
+ params[j] = getXQueryType(paramTypes[j]);
+ }
+ MethodData md = new MethodData(toImport, "new", params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE));
+ if (!functions.containsKey(md))
+ functions.put(md,md);
+ else {
+ MethodData existingMd = (MethodData)functions.get(md);
+ for (int j=0;j<existingMd.paramTypes.length;j++) {
+ if (!params[j].equals(existingMd.paramTypes [j])) {
+ if (Type.isNumericPrimitiveType(params[j].getType()) && Type.isNumericPrimitiveType(existingMd.paramTypes[j].getType()))
+ existingMd.paramTypes[j] = new TypeInfo(Type.NUMBER,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ else
+ if (Type.isAtomicType(params[j].getType(), Context.getDictionary()) && Type.isAtomicType(existingMd.paramTypes[j].getType(),Context.getDictionary()))
+ existingMd.paramTypes[j] = new TypeInfo(Type.ANY_ATOMIC_TYPE,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ else
+ existingMd.paramTypes[j] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ }
+ }
+ }
+
+ }
+ }
+
+ Method [] methods = toImport.getMethods();
+
+ for (int i=0;i<methods.length;i++) {
+ Method cur = methods[i];
+ int mod = cur.getModifiers();
+ if (Modifier.isPublic(mod)) {
+ String name = cur.getName();
+ Class [] paramTypes = cur.getParameterTypes();
+ TypeInfo [] params = new TypeInfo[paramTypes.length];
+ if (Modifier.isStatic(mod)) {
+ params = new TypeInfo[paramTypes.length];
+ for (int j=0;j<params.length;j++) {
+ params[j] = getXQueryType(paramTypes[j]);
+ }
+ }
+ else {
+ params = new TypeInfo[paramTypes.length+1];
+ params[0] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ for (int j=1;j<params.length;j++) {
+ params[j] = getXQueryType(paramTypes[j-1]);
+ }
+ }
+ TypeInfo resultType = getXQueryType(cur.getReturnType());
+ MethodData md = new MethodData(toImport, name, params, resultType);
+ if (!functions.containsKey(md))
+ functions.put(md,md);
+ else {
+ MethodData existingMd = (MethodData)functions.get(md);
+ for (int j=0;j<existingMd.paramTypes.length;j++) {
+ if (!params[j].equals(existingMd.paramTypes [j])) {
+ if (Type.isNumericPrimitiveType(params[j].getType()) && Type.isNumericPrimitiveType(existingMd.paramTypes[j].getType()))
+ existingMd.paramTypes[j] = new TypeInfo(Type.NUMBER,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ else
+ existingMd.paramTypes[j] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ //throw new StaticException(ErrorCodes.A0020_Incompatible_Overload, "Overloaded Java Function "+className+"."+name+" could not be mapped", QueryLocation.OUTSIDE_QUERY_LOC);
+ }
+ }
+ }
+
+ }
+ }
+ java.util.Iterator allFuncts = functions.values().iterator();
+ while (allFuncts.hasNext()) {
+ MethodData md = (MethodData)allFuncts.next();
+ QName qn = new QName("java:"+className,"javamethod",md.methodName);
+ FunctionSignature fs = new FunctionSignature(qn, md.paramTypes,FunctionSignature.EXTERNAL_FUNCTION,XDMIterator.EXPR_CATEGORY_SEQUENTIAL,true,false);
+ Function fn = new Function(null, fs, new NativeFuncCall(ctx, md.paramTypes, toImport, md.methodName, md.returnType, null, XDMIterator.EXPR_CATEGORY_SIMPLE, QueryLocation.OUTSIDE_QUERY_LOC), null, 0);
+ ctx.addFunction(fn);
+ }
+ } catch (ClassNotFoundException e) {
+ throw new StaticException(ErrorCodes.A0019_Unknown_Class, "Class "+className+" could not be found", QueryLocation.OUTSIDE_QUERY_LOC);
+ }
+ return ctx;
+ }
+ private static TypeInfo getXQueryType(Class class1) {
+
+ if (class1.isPrimitive()) {
+ if (class1.getName().equals("long"))
+ return new TypeInfo(Type.LONG,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("double"))
+ return new TypeInfo(Type.DOUBLE,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("float"))
+ return new TypeInfo(Type.FLOAT,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("int"))
+ return new TypeInfo(Type.INT,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("boolean"))
+ return new TypeInfo(Type.BOOLEAN,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ System.out.println(class1.getPackage()+" "+class1.getName());
+ return new TypeInfo(Type.UNTYPED_ATOMIC,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ }
+ if (class1.getName().equals("java.lang.String"))
+ return new TypeInfo(Type.STRING,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("java.lang.Double"))
+ return new TypeInfo(Type.DOUBLE,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("java.lang.Float"))
+ return new TypeInfo(Type.FLOAT,Type.OCCURRENCE_IND_EXACTLY_ONE);
+
+ return new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
+ }
+}
Added: trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java (rev 0)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-05-05 07:23:40 UTC (rev 4313)
@@ -0,0 +1,312 @@
+/* Copyright 2006 - 2009 ETH Zurich
+ *
+ * Licensed 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 ch.ethz.mxquery.iterators;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Vector;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.types.TypeInfo;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.datamodel.xdm.WrappedObjectToken;
+import ch.ethz.mxquery.exceptions.DynamicException;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.functions.fn.DataValuesIterator;
+import ch.ethz.mxquery.model.CurrentBasedIterator;
+import ch.ethz.mxquery.model.Iterator;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.xdmio.XDMAtomicItemFactory;
+
+public class NativeFuncCall extends CurrentBasedIterator {
+ //protected QName[] paramNames;
+
+ Class native_function;
+ String methodName;
+ protected XDMIterator resultSeqTypeIt;
+
+ protected TypeInfo[] paramTypes;
+
+ protected TypeInfo returnType;
+
+ private int sigExpressionCategory = EXPR_CATEGORY_SIMPLE;
+
+ public NativeFuncCall(Context ctx, TypeInfo[] paramTypes,
+ Class function, String methodName, TypeInfo returnType, XDMIterator returnSeqTypeIt, int exprCategory, QueryLocation location) throws MXQueryException {
+ super(ctx, location);
+ this.native_function = function;
+ this.resultSeqTypeIt = returnSeqTypeIt;
+ //this.paramNames = paramNames;
+ this.native_function = function;
+ this.methodName = methodName;
+ this.returnType = returnType;
+ this.paramTypes = paramTypes;
+ this.sigExpressionCategory = exprCategory;
+ //function.setResettable(true);
+ }
+
+ protected void init() throws MXQueryException {
+
+ if (resultSeqTypeIt != null) {
+ resultSeqTypeIt.setResettable(true);
+ resultSeqTypeIt.reset();
+ }
+ //function.setResettable(true);
+ Object [] invocationParams = new Object[subIters.length];
+ Class [] invocationParamsTypes = new Class[subIters.length];
+ Object instanceToCall = null;
+ for (int i = 0; i < this.subIters.length; i++) {
+ TokenInterface tok = subIters[i].next();
+ // For now, just take exactly a single value
+ if (tok.getEventType()==Type.END_SEQUENCE || subIters[i].next().getEventType() != Type.END_SEQUENCE)
+ throw new DynamicException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Expected a single item", loc);
+ int type = Type.getEventTypeSubstituted(tok.getEventType(), Context.getDictionary());
+ switch (type) {
+ case Type.DOUBLE:
+ invocationParams[i] = new Double(tok.getDouble().getValue());
+ invocationParamsTypes[i] = Double.TYPE;
+ break;
+ case Type.STRING:
+ case Type.ANY_URI:
+ invocationParams[i] = new String(tok.getText());
+ invocationParamsTypes[i] = invocationParams[i].getClass();
+ break;
+ case Type.ITEM:
+ if (i==0 && tok instanceof WrappedObjectToken) {
+ WrappedObjectToken wrap = (WrappedObjectToken) tok;
+ instanceToCall = wrap.getWrappedObject();
+ } else
+ throw new DynamicException(ErrorCodes.A0002_EC_NOT_SUPPORTED, "Type "+Type.getTypeQName(tok.getEventType(), Context.getDictionary())+" not implemented in Java calls", loc);
+ break;
+ default:
+ throw new DynamicException(ErrorCodes.A0002_EC_NOT_SUPPORTED, "Type "+Type.getTypeQName(tok.getEventType(), Context.getDictionary())+" not implemented in Java calls", loc);
+ }
+
+
+ }
+ // On instance methods, take away the first parameter, since it is the instance reference
+ if (instanceToCall != null) {
+ Class [] allTypes = invocationParamsTypes;
+ Object [] allParams = invocationParams;
+ invocationParamsTypes = new Class[allTypes.length-1];
+ invocationParams = new Object[allParams.length-1];
+ System.arraycopy(allTypes, 1, invocationParamsTypes, 0, invocationParamsTypes.length);
+ System.arraycopy(allParams, 1, invocationParams, 0, invocationParams.length);
+
+ }
+
+ try {
+ Object res;
+ if (methodName.equals("new")) {
+ Constructor con = native_function.getConstructor(invocationParamsTypes);
+ res = con.newInstance(invocationParams);
+ }
+ else {
+ Method meth = native_function.getMethod(methodName, invocationParamsTypes);
+ res = meth.invoke(instanceToCall, invocationParams);
+ }
+
+ try {
+ this.current = XDMAtomicItemFactory.createAtomicItemType(res);
+ }catch (MXQueryException me) {
+ WrappedObjectToken wrap = new WrappedObjectToken(res);
+ this.current = new TokenIterator(context, wrap, loc, false);
+ }
+ } catch (SecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InstantiationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ //this.current = new TokenIterator(context, 42,Type.INT, loc);
+ }
+
+ public TokenInterface next() throws MXQueryException {
+ if (this.called == 0) {
+ this.init();
+ }
+ this.called++;
+ return this.current.next();
+ }
+
+ public void setContext(Context context, boolean recursive) throws MXQueryException {
+ if (subIters != null && recursive) {
+ for (int i=0;i<subIters.length;i++)
+ subIters[i].setContext(context, recursive);
+ }
+
+ }
+
+ public void setResettable(boolean r) throws MXQueryException {
+ for (int i = 0; i < this.subIters.length; i++) {
+ this.subIters[i].setResettable(r);
+ }
+ resettable = r;
+ }
+
+ public XDMIterator staticInit() throws MXQueryException {
+ super.staticInit();
+ //function.staticInit();
+ return this;
+ }
+
+
+ protected void resetImpl() throws MXQueryException {
+ for (int i = 0; i < this.subIters.length; i++) {
+ this.subIters[i].reset();
+ }
+ super.resetImpl();
+ }
+
+ public void setSubIters(XDMIterator[] subIt) throws MXQueryException {
+ if (subIt == null) {
+ return;
+ }
+ if (paramTypes != null) {
+ // Insert fn:data if input is expected to be atomic
+ for (int i = 0;i<subIt.length;i++) {
+ subIt[i] = insertAtomizationCast(paramTypes[i], subIt[i]);
+ }
+
+ }
+ subIters = subIt;
+ }
+
+ private XDMIterator insertAtomizationCast(TypeInfo parType, XDMIterator toAdapt) {
+ if (parType != null && parType.getType() != TypeInfo.UNDEFINED
+ && Type.isAtomicType(parType.getType(), Context.getDictionary()))
+ toAdapt = DataValuesIterator.getDataIterator(toAdapt, toAdapt.getContext());
+
+ if (parType != null && parType.getType() != TypeInfo.UNDEFINED &&
+ (parType.getType() != Type.END_SEQUENCE) &&
+ parType.getType() != Type.ANY_ATOMIC_TYPE && !Type.isNode(parType.getType())
+ && !Type.isTypeOrSubTypeOf(toAdapt.getStaticType().getType(),parType.getType(), Context.getDictionary()) && parType.getType() != Type.ITEM)
+ toAdapt = new CastAsIterator(toAdapt.getContext(), toAdapt, parType, false, true,loc);
+ return toAdapt;
+ }
+
+ protected XDMIterator copy(Context context, XDMIterator[] subIters, Vector nestedPredCtxStack) throws MXQueryException {
+ NativeFuncCall copy = new NativeFuncCall(
+ context,
+ Iterator.copyTypeInfos(paramTypes),
+ native_function,
+ methodName,
+ returnType.copy(),
+ resultSeqTypeIt==null?null:resultSeqTypeIt.copy(context, null, false, nestedPredCtxStack), exprCategory,loc);
+
+ copy.exprCategory = exprCategory;
+ copy.sigExpressionCategory = sigExpressionCategory;
+ copy.subIters = subIters;
+
+ return copy;
+ }
+
+// public int getExprTypeShallow() throws MXQueryException {
+// boolean hasUpdates = false;
+// if (subIters != null) {
+// hasUpdates = checkArguments(hasUpdates,isScripting);
+// }
+//
+// if (hasUpdates)
+// exprCategory = EXPR_CATEGORY_UPDATING;
+// else
+// exprCategory = sigExpressionCategory;
+// return exprCategory;
+// }
+
+// protected void checkExpressionTypes() throws MXQueryException {
+// boolean hasUpdates = false;
+// if (subIters != null) {
+// hasUpdates = checkArguments(hasUpdates,isScripting);
+// }
+//
+// if (exprCategory == EXPR_CATEGORY_UNDETERMINED) {
+// try {
+// int funcCat = function.getExpressionCategoryType(isScripting);
+// if (funcCat != sigExpressionCategory && funcCat != EXPR_CATEGORY_UNDETERMINED)
+// if(!isScripting) {
+// if (funcCat != XDMIterator.EXPR_CATEGORY_VACUOUS)
+// switch (sigExpressionCategory) {
+// case XDMIterator.EXPR_CATEGORY_UPDATING:
+// throw new StaticException(ErrorCodes.U0002_UPDATE_STATIC_NONUPDATING_EXPRESSION_NOT_ALLOWED_HERE,"Simple body not allowed in updating/sequential function", loc);
+// case XDMIterator.EXPR_CATEGORY_SIMPLE:
+// throw new StaticException(ErrorCodes.U0001_UPDATE_STATIC_UPDATING_EXPRESSION_NOT_ALLOWED_HERE,"Updating body not allowed in non-updating function", loc);
+// }
+// } else {
+// switch (sigExpressionCategory) {
+// case EXPR_CATEGORY_SIMPLE:
+// if (funcCat != EXPR_CATEGORY_VACUOUS)
+// throw new StaticException(ErrorCodes.SX0008_FUNCTION_BODY_CATEGORY_INCONSITENT,"Updating/Sequential body not allowed in non-updating function", loc);
+// break;
+// case EXPR_CATEGORY_UPDATING:
+// if (funcCat == EXPR_CATEGORY_SEQUENTIAL)
+// throw new StaticException(ErrorCodes.SX0008_FUNCTION_BODY_CATEGORY_INCONSITENT,"Sequential body not allowed in non-updating function", loc);
+// break;
+// case EXPR_CATEGORY_SEQUENTIAL:
+// if (funcCat == EXPR_CATEGORY_UPDATING)
+// throw new StaticException(ErrorCodes.SX0008_FUNCTION_BODY_CATEGORY_INCONSITENT,"Updating body not allowed in sequential function", loc);
+// }
+// }
+// }catch (NullPointerException ne) {
+// // could not look up the function
+// }
+// }
+// if (hasUpdates && sigExpressionCategory != EXPR_CATEGORY_UPDATING)
+// exprCategory = EXPR_CATEGORY_UPDATING;
+// else
+// exprCategory = sigExpressionCategory;
+// }
+//
+// private boolean checkArguments(boolean hasUpdates,boolean isScripting) throws MXQueryException {
+// if (!isScripting)
+// checkExprSimpleOnly(subIters,isScripting);
+// else {
+// switch (sigExpressionCategory) {
+// case EXPR_CATEGORY_SIMPLE:
+// case EXPR_CATEGORY_UPDATING:
+// hasUpdates = checkExprNoSequential(subIters,isScripting);
+// break;
+// case EXPR_CATEGORY_SEQUENTIAL:
+// checkExprSimpleOnly(subIters,isScripting);
+// }
+// }
+// return hasUpdates;
+// }
+
+
+ //It was not overwritten!
+ public TypeInfo getStaticType(){
+ return returnType;
+ }
+
+}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-05-05 07:18:53 UTC (rev 4312)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-05-05 07:23:40 UTC (rev 4313)
@@ -48,6 +48,7 @@
import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.functions.Function;
import ch.ethz.mxquery.functions.FunctionSignature;
+import ch.ethz.mxquery.functions.NativeFunctionImporter;
import ch.ethz.mxquery.functions.fn.BooleanIterator;
import ch.ethz.mxquery.functions.fn.Collection;
import ch.ethz.mxquery.functions.fn.CountIterator;
@@ -897,14 +898,8 @@
"Error while parsing: '=' expected!");
}
- String uri = null;
+ String uri = StringLiteralAsString(true);
- XDMIterator it = StringLiteral();
- if (it != null) {
- TokenInterface tok = it.next();
- uri = tok.getText();
- }
-
if (uri == null) {
generateStaticError(
ErrorCodes.E0003_STATIC_NOT_A_VALID_GRAMMAR_ELEMENT,
@@ -941,6 +936,10 @@
ErrorCodes.E0033_STATIC_MODULE_MULTIPLE_BINDINGS_FOR_SAME_PREFIX,
"Multiple declarations of Namespace " + name);
ctx.addNamespace(new Namespace(name, uri));
+ if (uri.startsWith("java:")) {
+ Context javamod = NativeFunctionImporter.getNativeMethods(uri.substring(5));
+ importModuleFunctionsVariables(uri, name, javamod);
+ }
declaredNamespaces.add(name);
return true;
@@ -2543,7 +2542,7 @@
if (varData == null)
generateStaticError(
- ErrorCodes.A0017_Missing_Pattern_Var_Decl,
+ ErrorCodes.A0018_Missing_Pattern_Var_Decl,
"Variable declaration '"
+ varQName1
+ "' is spurious, not needed by the pattern definition");
@@ -2591,7 +2590,7 @@
if (patVar.size() != declVar.size()) {
generateStaticError(
- ErrorCodes.A0017_Missing_Pattern_Var_Decl,
+ ErrorCodes.A0018_Missing_Pattern_Var_Decl,
"Not all variables used in the pattern have been declared");
}
// with all variable information present, we can now check
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/parser/PatternDataHelper.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/parser/PatternDataHelper.java 2011-05-05 07:18:53 UTC (rev 4312)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/parser/PatternDataHelper.java 2011-05-05 07:23:40 UTC (rev 4313)
@@ -303,7 +303,7 @@
if (!var.contains(v1))
var.add(v1);
else
- throw new StaticException(ErrorCodes.A0017_Missing_Pattern_Var_Decl, "Variable "+v1+" is used multiple times in the pattern", QueryLocation.OUTSIDE_QUERY_LOC);
+ throw new StaticException(ErrorCodes.A0018_Missing_Pattern_Var_Decl, "Variable "+v1+" is used multiple times in the pattern", QueryLocation.OUTSIDE_QUERY_LOC);
}
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/sms/MMimpl/StreamStoreInput.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/sms/MMimpl/StreamStoreInput.java 2011-05-05 07:18:53 UTC (rev 4312)
+++ trunk/MXQuery/src/ch/ethz/mxquery/sms/MMimpl/StreamStoreInput.java 2011-05-05 07:23:40 UTC (rev 4313)
@@ -135,7 +135,7 @@
break;
}
- if ( Type.isAtomicType(type, null) || Type.isTextNode(type)) {
+ if ( Type.isAtomicType(type, null) || Type.isTextNode(type) || type == Type.ITEM) {
event = 1;
if (level == 0) {
buffer.newItem();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/sms/MMimpl/TokenBufferStore.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/sms/MMimpl/TokenBufferStore.java 2011-05-05 07:18:53 UTC (rev 4312)
+++ trunk/MXQuery/src/ch/ethz/mxquery/sms/MMimpl/TokenBufferStore.java 2011-05-05 07:23:40 UTC (rev 4313)
@@ -308,7 +308,7 @@
break;
}
- if ( Type.isAtomicType(type, Context.getDictionary()) || type == Type.UNTYPED) {
+ if ( Type.isAtomicType(type, Context.getDictionary()) || type == Type.UNTYPED || type == Type.ITEM) {
if (level == 0) {
indexNewNode();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/xdmio/XDMAtomicItemFactory.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/xdmio/XDMAtomicItemFactory.java 2011-05-05 07:18:53 UTC (rev 4312)
+++ trunk/MXQuery/src/ch/ethz/mxquery/xdmio/XDMAtomicItemFactory.java 2011-05-05 07:23:40 UTC (rev 4313)
@@ -15,37 +15,34 @@
package ch.ethz.mxquery.xdmio;
-import ch.ethz.mxquery.contextConfig.Context;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import javax.xml.datatype.DatatypeConstants;
+import javax.xml.datatype.Duration;
+import javax.xml.datatype.XMLGregorianCalendar;
+
import ch.ethz.mxquery.datamodel.MXQueryBigDecimal;
-import ch.ethz.mxquery.datamodel.MXQueryBinary;
import ch.ethz.mxquery.datamodel.MXQueryDate;
import ch.ethz.mxquery.datamodel.MXQueryDateTime;
+import ch.ethz.mxquery.datamodel.MXQueryDayTimeDuration;
import ch.ethz.mxquery.datamodel.MXQueryDouble;
import ch.ethz.mxquery.datamodel.MXQueryDuration;
import ch.ethz.mxquery.datamodel.MXQueryFloat;
import ch.ethz.mxquery.datamodel.MXQueryGregorian;
import ch.ethz.mxquery.datamodel.MXQueryTime;
-import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.datamodel.MXQueryYearMonthDuration;
import ch.ethz.mxquery.datamodel.types.Type;
-import ch.ethz.mxquery.datamodel.xdm.AnyURIToken;
-import ch.ethz.mxquery.datamodel.xdm.BooleanToken;
import ch.ethz.mxquery.datamodel.xdm.DateTimeToken;
import ch.ethz.mxquery.datamodel.xdm.DateToken;
-import ch.ethz.mxquery.datamodel.xdm.DecimalToken;
-import ch.ethz.mxquery.datamodel.xdm.DoubleToken;
+import ch.ethz.mxquery.datamodel.xdm.DayTimeDurToken;
import ch.ethz.mxquery.datamodel.xdm.DurationToken;
-import ch.ethz.mxquery.datamodel.xdm.FloatToken;
import ch.ethz.mxquery.datamodel.xdm.GregorianToken;
-import ch.ethz.mxquery.datamodel.xdm.LongToken;
-import ch.ethz.mxquery.datamodel.xdm.QNameToken;
-import ch.ethz.mxquery.datamodel.xdm.TextToken;
import ch.ethz.mxquery.datamodel.xdm.TimeToken;
import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
-import ch.ethz.mxquery.datamodel.xdm.UntypedAtomicToken;
-import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.datamodel.xdm.YearMonthDurToken;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
-import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.iterators.TokenIterator;
import ch.ethz.mxquery.model.XDMIterator;
@@ -54,395 +51,101 @@
* @author Peter Fischer
*
*/
-public class XDMAtomicItemFactory {
- /**
- * Creates an AnyURI Item
- * @param uri the String to be represented as anyURI item
- * @return an XDM Iterator representing the constructed AnyURI Item
- * @throws MXQueryException
- */
- public static XDMIterator createAnyURI(final String uri) throws MXQueryException{
- return createTextTypeItem(null, uri, Type.ANY_URI);
- }
+public class XDMAtomicItemFactory extends SharedAtomicItemFactory{
/**
- * Creates a Base 64 Binary Item
- * @param base64Val String representation of a Base 64 value
- * @return an XDM Iterator representing the constructed Base 64 Binary Item
+ * Create an atomic type item from the given Java object
+ * An error is raised there is no matching atomic type or if values are incorrect
+ * @param val A Java object to be converted into a XDM atomic type
+ * @return an XDMIterator producing this atomic type
* @throws MXQueryException
*/
- public static XDMIterator createBase64Binary(String base64Val) throws MXQueryException {
- MXQueryBinary bin = new MXQueryBinary(base64Val,Type.BASE64_BINARY);
- return new TokenIterator(null,bin,QueryLocation.OUTSIDE_QUERY_LOC);
- }
- /**
- * Creates a Base 64 Binary Item
- * @param binValue binary values to be represented as Base 64
- * @return an XDM Iterator representing the constructed Base 64 Binary Item
- * @throws MXQueryException
- */
- public static XDMIterator createBase64Binary(byte [] binValue) throws MXQueryException {
- MXQueryBinary bin = new MXQueryBinary(binValue,Type.BASE64_BINARY);
- return new TokenIterator(null,bin,QueryLocation.OUTSIDE_QUERY_LOC);
- }
+ public static XDMIterator createAtomicItemType(Object val) throws MXQueryException{
+ if(val.getClass() == Float.class)
+ return createFloat(new MXQueryFloat(((Float)val).floatValue()));
+ if(val.getClass() == Double.class)
+ return createDouble(new MXQueryDouble(((Double)val).doubleValue()));
+ if(val.getClass() == BigDecimal.class)
+ return createDecimal(new MXQueryBigDecimal((BigDecimal)val));
+ if(val.getClass() == BigInteger.class) {
+ return createInteger(((BigInteger)val).longValue());
+ }
+ if(val instanceof Duration) {
+ Duration dur = (Duration)val;
+ TokenInterface tok;
+ if (dur.getYears() == 0 && dur.getMonths() == 0) {
+ MXQueryDayTimeDuration durDay = new MXQueryDayTimeDuration(dur.getSign(),dur.getDays(),dur.getHours(),dur.getMinutes(),dur.getSeconds(),0);
+ tok = new DayTimeDurToken(null,durDay);
+ } else if (dur.getDays() == 0 && dur.getHours() == 0 && dur.getMinutes() == 0 && dur.getSeconds() == 0) {
+ MXQueryYearMonthDuration durYear = new MXQueryYearMonthDuration(dur.getSign(),dur.getYears(),dur.getMonths());
+ tok = new YearMonthDurToken(null,durYear);
+ } else {
+ MXQueryDayTimeDuration durDay = new MXQueryDayTimeDuration(dur.getSign(),dur.getDays(),dur.getHours(),dur.getMinutes(),dur.getSeconds(),0);
+ MXQueryYearMonthDuration durYear = new MXQueryYearMonthDuration(dur.getSign(),dur.getYears(),dur.getMonths());
+ MXQueryDuration durMX = new MXQueryDuration(durYear,durDay);
+ tok = new DurationToken(null,durMX);
+ }
+ return new TokenIterator(null,tok,QueryLocation.OUTSIDE_QUERY_LOC,false);
+ }
+ if (val instanceof XMLGregorianCalendar) {
+ XMLGregorianCalendar greg = (XMLGregorianCalendar)val;
+ TokenInterface tok = null;
+ if (greg.getYear() != DatatypeConstants.FIELD_UNDEFINED) {
+ if (greg.getMonth() != DatatypeConstants.FIELD_UNDEFINED) {
+ if (greg.getDay() != DatatypeConstants.FIELD_UNDEFINED) {
+ if (greg.getHour() != DatatypeConstants.FIELD_UNDEFINED) {
+ // Year, Month, Day, Hour = dateTime
- /**
- * Creates a Boolean Item
- * @param val the boolean value for the item
- * @return an XDM Iterator representing the constructed Boolean Item
- * @throws MXQueryException
- */
- public static XDMIterator createBoolean(boolean val) throws MXQueryException{
- BooleanToken myToken;
- if (val)
- myToken = BooleanToken.TRUE_TOKEN;
- else
- myToken = BooleanToken.FALSE_TOKEN;
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Byte Item
- * @param bVal the byte value for the item
- * @return an XDM Iterator representing the constructed Byte Item
- * @throws MXQueryException
- */
- public static XDMIterator createByte(byte bVal) throws MXQueryException {
- LongToken myToken = new LongToken(Type.BYTE,null,bVal);
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Date Item
- * @param dVal a String expressing the date for this item (XML Schema/XQuery format)
- * @return an XDM Iterator representing the constructed Date Item
- * @throws MXQueryException
- */
- public static XDMIterator createDate(String dVal) throws MXQueryException{
- MXQueryDate date = new MXQueryDate(dVal);
- return new TokenIterator(null,new DateToken(null,date),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a DateTime Item
- * @param dTimeVal a String expressing the dateTime for this item (XML Schema/XQuery format)
- * @return an XDM Iterator representing the constructed DateTim Item
- * @throws MXQueryException
- */
- public static XDMIterator createDateTime(String dTimeVal) throws MXQueryException{
- MXQueryDateTime dateTime = new MXQueryDateTime(dTimeVal);
- return new TokenIterator(null,new DateTimeToken(null,dateTime),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Duration Item
- * @param durVal a String expressing the duration for this item (XML Schema/XQuery format)
- * @return an XDM Iterator representing the constructed Duration Item
- * @throws MXQueryException
- */
- public static XDMIterator createDuration(String durVal) throws MXQueryException{
- MXQueryDuration dur = new MXQueryDuration(durVal);
- return new TokenIterator(null,new DurationToken(null,dur),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Decimal Item
- * @param dVal a MXQueryBigDecimal expressing the decimal value for this item
- * @return an XDM Iterator representing the constructed Decimal Item
- * @throws MXQueryException
- */
- public static XDMIterator createDecimal(MXQueryBigDecimal dVal) throws MXQueryException{
- return new TokenIterator(null, new DecimalToken(null,dVal),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Double Item
- * @param dVal a MXQueryDouble expressing the double value for this item
- * @return an XDM Iterator representing the constructed Double Item
- * @throws MXQueryException
- */
- public static XDMIterator createDouble(MXQueryDouble dVal) throws MXQueryException{
- return new TokenIterator(null,new DoubleToken(null,dVal),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Float Item
- * @param fVal a MXQueryFloat expressing the float value for this item
- * @return an XDM Iterator representing the constructed Float Item
- * @throws MXQueryException
- */
- public static XDMIterator createFloat(MXQueryFloat fVal) throws MXQueryException{
- return new TokenIterator(null,new FloatToken(null,fVal),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Gregorian Day Item
- * @param gDayVal the day number (1-31) expressing the Gregorian Day for this item
- * @return an XDM Iterator representing the constructed Gregorian Day Item
- * @throws MXQueryException
- */
- public static XDMIterator createGDay(int gDayVal) throws MXQueryException{
- MXQueryGregorian gDay = new MXQueryGregorian(0,0,gDayVal,0,Type.G_DAY);
- return new TokenIterator(null,new GregorianToken(null,gDay),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Gregorian Month Item
- * @param gMonthVal the month number (1-12) expressing the Gregorian Month for this item
- * @return an XDM Iterator representing the constructed Gregorian Month Item
- * @throws MXQueryException
- */
- public static XDMIterator createGMonth(int gMonthVal) throws MXQueryException{
- MXQueryGregorian gMonth = new MXQueryGregorian(0,gMonthVal,0,0,Type.G_MONTH);
- return new TokenIterator(null,new GregorianToken(null,gMonth),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Gregorian MonthDay Item
- * @param gMonthVal gMonthVal the month number (1-12) expressing the Gregorian Month for this item
- * @param gDayVal the day number (1-31) expressing the Gregorian Day for this item
- * @return an XDM Iterator representing the constructed Gregorian MonthDay Item
- * @throws MXQueryException
- */
- public static XDMIterator createGMonthDay(int gMonthVal, int gDayVal) throws MXQueryException {
- MXQueryGregorian gMonthDay = new MXQueryGregorian(0,gMonthVal,gDayVal,0,Type.G_MONTH_DAY);
- return new TokenIterator(null,new GregorianToken(null,gMonthDay),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Gregorian Year Item
- * @param gYearVal the year number expressing the Gregorian Year for this item
- * @return an XDM Iterator representing the constructed Gregorian Year Item
- * @throws MXQueryException
- */
- public static XDMIterator createGYear(int gYearVal) throws MXQueryException {
- MXQueryGregorian gYear = new MXQueryGregorian(gYearVal,0,0,0,Type.G_YEAR);
- return new TokenIterator(null,new GregorianToken(null,gYear),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Gregorian YearMonth Item
- * @param gYearVal gYearVal the year number expressing the Gregorian Year for this item
- * @param gMonthVal gMonthVal the month number (1-12) expressing the Gregorian Month for this item
- * @return an XDM Iterator representing the constructed Gregorian YearMonth Item
- * @throws MXQueryException
- */
- public static XDMIterator createGYearMonth(int gYearVal,int gMonthVal) throws MXQueryException {
- MXQueryGregorian gYearMonth = new MXQueryGregorian(gYearVal,gMonthVal,0,0,Type.G_YEAR_MONTH);
- return new TokenIterator(null,new GregorianToken(null,gYearMonth),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Hex Binary Item from a string representation
- * @param hexVal a string expressing the hex binary value for this item
- * @return an XDM Iterator representing the constructed HexBinary Item
- * @throws MXQueryException
- */
- public static XDMIterator createHexBinary(String hexVal) throws MXQueryException {
- MXQueryBinary bin = new MXQueryBinary(hexVal,Type.HEX_BINARY);
- return new TokenIterator(null,bin,QueryLocation.OUTSIDE_QUERY_LOC);
- }
- /**
- * Creates a Hex Binary Item from a binary representation
- * @param binValue a byte array expressing the hex binary value for this item
- * @return an XDM Iterator representing the constructed HexBinary Item
- * @throws MXQueryException
- */
- public static XDMIterator createHexBinary(byte [] binValue) throws MXQueryException {
- MXQueryBinary bin = new MXQueryBinary(binValue,Type.HEX_BINARY);
- return new TokenIterator(null,bin,QueryLocation.OUTSIDE_QUERY_LOC);
- }
- /**
- * Creates an Int Item
- * @param intVal an integer expressing the int value for this item
- * @return an XDM Iterator representing the constructed Int Item
- * @throws MXQueryException
- */
- public static XDMIterator createInt(int intVal) throws MXQueryException {
- LongToken myToken = new LongToken(Type.INT,null,intVal);
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates an Integer Item
- * @param intVal an integer expressing the integer value for this item
- * @return an XDM Iterator representing the constructed Integer Item
- * @throws MXQueryException
- */
- public static XDMIterator createInteger(long intVal) throws MXQueryException {
- LongToken myToken = new LongToken(Type.INTEGER,null,intVal);
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Long Item
- * @param longVal a long expressing the long value for this item
- * @return an XDM Iterator representing the constructed Long Item
- * @throws MXQueryException
- */
- public static XDMIterator createLong(long longVal) throws MXQueryException{
- LongToken myToken = new LongToken(Type.LONG,null,longVal);
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a NCName Item
- * @param ncname a String expressing the NCNAME value for this item
- * @return an XDM Iterator representing the constructed NCNAME Item
- * @throws MXQueryException
- */
- public static XDMIterator createNCName(final String ncname) throws MXQueryException{
- return createTextTypeItem(null, ncname, Type.NCNAME);
- }
- /**
- * Creates a Negative Integer Item
- * @param longVal a long expressing the negative integer value for this item
- * @return an XDM Iterator representing the constructed Negative Integer Item
- * @throws MXQueryException
- */
- public static XDMIterator createNegativeInteger(long longVal) throws MXQueryException{
- LongToken myToken = new LongToken(Type.NEGATIVE_INTEGER,null,longVal);
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Non-Negative Integer Item
- * @param longVal a long expressing the non-negative integer value for this item
- * @return an XDM Iterator representing the constructed Non-Negative Integer Item
- * @throws MXQueryException
- */
- public static XDMIterator createNonNegativeInteger(long longVal) throws MXQueryException{
- LongToken myToken = new LongToken(Type.NON_NEGATIVE_INTEGER,null,longVal);
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Non-Positive Integer Item
- * @param longVal a long expressing the non-positive integer value for this item
- * @return an XDM Iterator representing the constructed Non-Positive Integer Item
- * @throws MXQueryException
- */
- public static XDMIterator createNonPositiveInteger(long longVal) throws MXQueryException{
- LongToken myToken = new LongToken(Type.NON_POSITIVE_INTEGER,null,longVal);
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Positive Integer Item
- * @param longVal a long expressing the positive integer value for this item
- * @return an XDM Iterator representing the constructed Positive Integer Item
- * @throws MXQueryException
- */
- public static XDMIterator createPositiveInteger(long longVal) throws MXQueryException{
- LongToken myToken = new LongToken(Type.POSITIVE_INTEGER,null,longVal);
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a QName Item
- * @param prefix a string representing the namespace prefix
- * @param localName a string representing the local name
- * @return an XDM Iterator representing the constructed QName Item
- * @throws MXQueryException
- */
- public static XDMIterator createQName(String prefix, String localName) throws MXQueryException{
- QName qn = new QName(prefix,localName);
- return new TokenIterator(null,new QNameToken(null,qn),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a qualified QName Item
- * @param namespace a string representing the namespace URI
- * @param prefix a string representing the namespace prefix
- * @param localName a string representing the local name
- * @return an XDM Iterator representing the constructed QName Item
- * @throws MXQueryException
- */
- public static XDMIterator createQName(String namespace, String prefix, String localName) throws MXQueryException{
- QName qn = new QName(namespace, prefix,localName);
- return new TokenIterator(null,new QNameToken(null,qn),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a Short Item
- * @param shortVal a short expressing the short value for this item
- * @return an XDM Iterator representing the constructed Short Item
- * @throws MXQueryException
- */
- public static XDMIterator createShort(short shortVal) throws MXQueryException{
- LongToken myToken = new LongToken(Type.SHORT,null,shortVal);
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates a String Item
- * @param str a String expressing the string value for this item
- * @return an XDM Iterator representing the constructed String Item
- * @throws MXQueryException
- */
- public static XDMIterator createString(final String str) throws MXQueryException{
- return createTextTypeItem(null, str, Type.STRING);
- }
- /**
- * Creates a Time Item
- * @param timeVal a string expressing the time value for this item (XML Schema/XQuery format)
- * @return an XDM Iterator representing the constructed Time Item
- * @throws MXQueryException
- */
- public static XDMIterator createTime(String timeVal) throws MXQueryException{
- MXQueryTime time = new MXQueryTime(timeVal);
- return new TokenIterator(null, new TimeToken(null,time),QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates an Unsigned Byte Item
- * @param ubVal a short expressing the unsigned byte value for this item
- * @return an XDM Iterator representing the constructed Unsigned Byte Item
- * @throws MXQueryException
- */
- public static XDMIterator createUnsignedByte(short ubVal) throws MXQueryException{
- LongToken myToken = new LongToken(Type.UNSIGNED_BYTE,null,ubVal);
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates an Unsigned Int Item
- * @param usVal a long expressing the unsigned int value for this item
- * @return an XDM Iterator representing the constructed Unsigned Int Item
- * @throws MXQueryException
- */
- public static XDMIterator createUnsignedInt(long usVal) throws MXQueryException{
- LongToken myToken = new LongToken(Type.UNSIGNED_INT,null,usVal);
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates an Unsigned Long Item. Note: Unsigned Long is limited to the signed long space in MXQuery
- * @param ulVal a long expressing the unsigned long value for this item
- * @return an XDM Iterator representing the constructed Unsigned Long Item
- * @throws MXQueryException
- */
- public static XDMIterator createUnsignedLong(long ulVal) throws MXQueryException {
- LongToken myToken = new LongToken(Type.UNSIGNED_LONG,null,ulVal);
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
- /**
- * Creates an Unsigned Short Item
- * @param uiVal an integer expressing the unsigned short value for this item
- * @return an XDM Iterator representing the constructed Unsigned Short Item
- * @throws MXQueryException
- */
- public static XDMIterator createUnsignedShort(int uiVal) throws MXQueryException{
- LongToken myToken = new LongToken(Type.UNSIGNED_SHORT,null,uiVal);
- return new TokenIterator(null,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
- }
+ MXQueryDateTime dat = new MXQueryDateTime(greg.toXMLFormat());
+ tok = new DateTimeToken(null,dat);
- /**
- * Creates a untyped atomic Item
- * @param str a String expressing the string value for this item
- * @return an XDM Iterator representing the constructed String Item
- * @throws MXQueryException
- */
- public static XDMIterator createUntypedAtomic(final String str) throws MXQueryException{
- return createTextTypeItem(null, str, Type.UNTYPED_ATOMIC);
- }
-
- private static XDMIterator createTextTypeItem (Context ctx, String value, int type) throws MXQueryException {
-
- TokenInterface myToken;
-
- int checkType = Type.getEventTypeSubstituted(type, Context.getDictionary());
-
- switch (checkType) {
- case Type.STRING:
- case Type.UNTYPED:
- myToken = new TextToken(type, null, value,null);
- break;
+ } else {
+ MXQueryDate dat = new MXQueryDate(greg.toXMLFormat());
+ tok = new DateToken(null,dat);
+ }
+ } else {
+ // Year, Month, no Day = gYearMonth
+ MXQueryGregorian mxqG = new MXQueryGregorian(greg.getYear(),greg.getMonth(),0,0,Type.G_YEAR_MONTH);
+ tok = new GregorianToken(null,mxqG);
- case Type.UNTYPED_ATOMIC:
- myToken = new UntypedAtomicToken(null, value);
- break;
-
- case Type.ANY_URI:
- myToken = new AnyURIToken(null, value);
- break;
- default:
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Incorrect type passed: " + Type.getTypeQName(type, Context.getDictionary()),QueryLocation.OUTSIDE_QUERY_LOC );
+ }
+ } else {
+ // Year, no month = gYear
+ MXQueryGregorian mxqG = new MXQueryGregorian(greg.getYear(),0,0,0,Type.G_YEAR);
+ tok = new GregorianToken(null,mxqG);
}
- return new TokenIterator(ctx,myToken,QueryLocation.OUTSIDE_QUERY_LOC, false);
+ } else {
+ if (greg.getMonth() != DatatypeConstants.FIELD_UNDEFINED) {
+ if (greg.getDay() != DatatypeConstants.FIELD_UNDEFINED) {
+ // no year, month+day present: gMonthDay
+ MXQueryGregorian mxqG = new MXQueryGregorian(0,greg.getMonth(),greg.getDay(),0,Type.G_MONTH_DAY);
+ tok = new GregorianToken(null,mxqG);
+ } else {
+ // no year, month present, no day: gMonthDay
+ MXQueryGregorian mxqG = new MXQueryGregorian(0,greg.getMonth(),0,0,Type.G_MONTH);
+ tok = new GregorianToken(null,mxqG);
+ }
+ } else {
+ if (greg.getDay() != DatatypeConstants.FIELD_UNDEFINED) {
+ // no year, no month, but day: gDay
+ MXQueryGregorian mxqG = new MXQueryGregorian(0,0,greg.getDay(),0,Type.G_DAY);
+ tok = new GregorianToken(null,mxqG);
+
+ } else {
+ // time
+ MXQueryTime dat = new MXQueryTime(greg.toXMLFormat());
+ tok = new TimeToken(null,dat);
+
+ }
+ }
+ }
+ return new TokenIterator(null,tok,QueryLocation.OUTSIDE_QUERY_LOC,false);
}
-
+
+ // if (val instanceof QName) {
+ // QName qn = (QName) val;
+ // QNameToken qnt = new QNameToken(null, new ch.ethz.mxquery.datamodel.QName(qn.getNamespaceURI(),qn.getLocalPart(),qn.getPrefix()));
+ // return new TokenIterator(null,qnt,QueryLocation.OUTSIDE_QUERY_LOC,false);
+ // }
+ return SharedAtomicItemFactory.createAtomicItemType(val);
+ }
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-05 07:18:53 UTC (rev 4312)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-05 07:23:40 UTC (rev 4313)
@@ -185,7 +185,7 @@
if (this.getContext().getRootContext()
.getFunction(asynchandlername, 1) == null) {
throw new MXQueryException(
- ErrorCodes.A0017_Missing_Pattern_Var_Decl,
+ ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,
"the eventhandler with the name "
+ asynchandlername.toString()
+ " is not available in an asynchronous expath call",
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddEventListener.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddEventListener.java 2011-05-05 07:18:53 UTC (rev 4312)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/AddEventListener.java 2011-05-05 07:23:40 UTC (rev 4313)
@@ -98,7 +98,7 @@
// qfunctionname.setNamespaceURI(this.getContext().getNamespace(qfunctionname.getNamespacePrefix()...
[truncated message content] |