|
From: <pm_...@us...> - 2011-05-03 13:24:52
|
Revision: 4308
http://mxquery.svn.sourceforge.net/mxquery/?rev=4308&view=rev
Author: pm_fischer
Date: 2011-05-03 13:24:45 +0000 (Tue, 03 May 2011)
Log Message:
-----------
- only copy anonymous updateable stores. When named, keep a single
instance
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/update/store/llImpl/LLStore.java
trunk/MXQuery_Testing/src/ch/ethz/mxquery/testsuite/TestSuiteUpdate.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/update/store/llImpl/LLStore.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/update/store/llImpl/LLStore.java 2011-05-03 09:46:28 UTC (rev 4307)
+++ trunk/MXQuery/src/ch/ethz/mxquery/update/store/llImpl/LLStore.java 2011-05-03 13:24:45 UTC (rev 4308)
@@ -1188,10 +1188,13 @@
}
public Source copySource(Context ctx, Vector nestedPredCtxStack) throws MXQueryException {
- if (uri == null || uri.startsWith("SimpleStore_"))
+ if (uri == null || uri.startsWith("SimpleStore_")) {
uri = "SimpleStore_"
+ Integer.toString(++storeSet.urilessCounter);
return new LLStore(uri, storeSet,initialSource.copy(ctx, null, false, nestedPredCtxStack));
+ } else {
+ return this;
+ }
}
public boolean isModified() {
Modified: trunk/MXQuery_Testing/src/ch/ethz/mxquery/testsuite/TestSuiteUpdate.java
===================================================================
--- trunk/MXQuery_Testing/src/ch/ethz/mxquery/testsuite/TestSuiteUpdate.java 2011-05-03 09:46:28 UTC (rev 4307)
+++ trunk/MXQuery_Testing/src/ch/ethz/mxquery/testsuite/TestSuiteUpdate.java 2011-05-03 13:24:45 UTC (rev 4308)
@@ -637,7 +637,7 @@
}
}
- boolean resetFiles = false;
+ boolean resetFiles = true;
if (resetFiles) {
SVNWCClient svnClient = new SVNWCClient((ISVNAuthenticationManager)null,null);
try {
@@ -701,7 +701,7 @@
}
}
- boolean resetFiles = false;
+ boolean resetFiles = true;
if (resetFiles) {
SVNWCClient svnClient = new SVNWCClient((ISVNAuthenticationManager)null,null);
try {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tim...@us...> - 2011-05-04 19:41:33
|
Revision: 4310
http://mxquery.svn.sourceforge.net/mxquery/?rev=4310&view=rev
Author: timchurch
Date: 2011-05-04 19:41:26 +0000 (Wed, 04 May 2011)
Log Message:
-----------
Updated ant build file to create jar file for android
Modified Paths:
--------------
trunk/MXQuery/build.xml
Removed Paths:
-------------
trunk/MXQuery/android/src/ch/ethz/mxquery/android/
Modified: trunk/MXQuery/build.xml
===================================================================
--- trunk/MXQuery/build.xml 2011-05-04 14:46:27 UTC (rev 4309)
+++ trunk/MXQuery/build.xml 2011-05-04 19:41:26 UTC (rev 4310)
@@ -1061,6 +1061,8 @@
<!-- Android Build Target START-->
<property name="android.dir" value="${root.dir}/android"/>
+ <property name="androidtmp.dir" value="${customtmp.dir}"/>
+ <property name="androidsrc.dir" value="${android.dir}/src"/>
<!-- define "if" statement used below -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
@@ -1072,13 +1074,114 @@
<!-- import sdk.dir property if not on Jenkins -->
<property file="${android.dir}/local.properties"/>
- <if>
- <isset property="sdk.dir"/>
- <then>
- <import file="${android.dir}/build-android.xml"/>
- </then>
- </if>
+ <!-- build Android version -->
+ <target name="android-prepare">
+
+ <!-- merge branches -->
+ <echo message="Merging source trees"/>
+ <delete>
+ <fileset dir="${androidtmp.dir}/">
+ <include name="**/*"/>
+ </fileset>
+ </delete>
+ <copy todir="${androidtmp.dir}">
+ <fileset dir="${src.dir}"/>
+ </copy>
+ <copy todir="${androidtmp.dir}" overwrite="yes">
+ <fileset dir="${androidsrc.dir}"/>
+ </copy>
+
+ <!-- remove unsupported classes -->
+ <echo message="Removing unsupported classes"/>
+ <delete dir="${androidtmp.dir}/ch/ethz/mxquery/dmcq/"/>
+ <delete>
+ <fileset dir="${androidtmp.dir}/ch/ethz/mxquery/functions/fn/">
+ <include name="NormalizeUnicode.java"/>
+ </fileset>
+ </delete>
+ <delete>
+ <fileset dir="${androidtmp.dir}/ch/ethz/mxquery/query/webservice/">
+ <include name="MultipleXQueryServer.java"/>
+ <include name="SingleXQueryServer.java"/>
+ <include name="XSPMain.java"/>
+ </fileset>
+ </delete>
+ <delete>
+ <fileset dir="${androidtmp.dir}/ch/ethz/mxquery/util/">
+ <include name="MultipleSchemaExposer.java"/>
+ <include name="PerfTools.java"/>
+ <include name="SingleSchemaExposer.java"/>
+ </fileset>
+ </delete>
+ <delete>
+ <fileset dir="${androidtmp.dir}/ch/ethz/mxquery/xdmio/xmlAdapters/">
+ <include name="NonValidatingStaxAdapter.java"/>
+ <include name="Token2StaxAdapter.java"/>
+ </fileset>
+ </delete>
+ <delete>
+ <fileset dir="${androidtmp.dir}/examples/">
+ <include name="InputOutputExample.java"/>
+ <include name="StreamStatsDemo.java"/>
+ <include name="XQJExample.java"/>
+ </fileset>
+ </delete>
+ </target>
+
+ <!-- Android-relevant libraries -->
+ <path id="android.lib.path">
+ <fileset dir="./lib">
+ <include name="**/*.jar" />
+ </fileset>
+ <fileset dir="${android.dir}/lib">
+ <include name="**/*.jar" />
+ </fileset>
+ </path>
+
+ <target name="compile-android" depends="clean,android-prepare">
+ <depend srcdir="${customtmp.dir}"
+ destdir="${build.dir}"
+ cache="depcache"
+ closure="yes"
+ />
+ <javac source="1.5"
+ srcdir="${customtmp.dir}"
+ destdir="${build.dir}"
+ target="1.5"
+ classpathref="project.class.path"
+ debug="${debug}"
+ optimize="${optimize}"
+ extdirs="">
+ <classpath>
+ <path refid="android.lib.path" />
+ </classpath>
+ </javac>
+ </target>
+
+ <target name="jar-android" depends="compile-android">
+ <echo message="Creating jar archive..."/>
+ <unjar src="${resources.dir}/kxml2-min-2.3.0.jar" dest="${build.dir}"></unjar>
+ <unjar src="${resources.dir}/xmlpull_1_1_3_4c.jar" dest="${build.dir}"></unjar>
+ <unjar src="${resources.dir}/jax-1_1-fr-qname-class.jar" dest="${build.dir}"></unjar>
+ <unjar src="${resources.dir}/xercesImpl.jar" dest="${build.dir}"></unjar>
+ <unjar src="${android.dir}/lib/jsr173_1.0_api-repackaged.jar" dest="${build.dir}"></unjar>
+ <unjar src="${resources.dir}/tagsoup-1.2.jar" dest="${build.dir}"></unjar>
+ <unjar src="${android.dir}/lib/xqjapi-repackaged.jar" dest="${build.dir}"></unjar>
+ <unjar src="${resources.dir}/commons-cli-1.2.jar" dest="${build.dir}"></unjar>
+ <jar jarfile="${dist.dir}/mxquery-android.jar">
+ <fileset dir="${build.dir}" excludes="examples/**/*.*"/>
+ <fileset dir="${src.dir}" includes="ch/**/*.xq"/>
+ <fileset dir="${src.dir}" includes="ch/**/*.xml"/>
+ <fileset dir="${src.dir}" includes="ch/**/*.txt"/>
+ <manifest>
+ <attribute name="Built-By" value="Tim und Max"/>
+ </manifest>
+ </jar>
+ </target>
+
+
+
<!-- Android Build Target END -->
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <max...@us...> - 2011-05-04 21:48:49
|
Revision: 4311
http://mxquery.svn.sourceforge.net/mxquery/?rev=4311&view=rev
Author: maxspeicher
Date: 2011-05-04 21:48:40 +0000 (Wed, 04 May 2011)
Log Message:
-----------
- changed to namespace ch.ethz.repackaged for repackaged JARs
- added refactoring of XQJ package to build file
Modified Paths:
--------------
trunk/MXQuery/android/lib/jsr173_1.0_api-repackaged.jar
trunk/MXQuery/android/lib/xqjapi-repackaged.jar
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQDataFactory.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQDynamicContext.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQForwardSequence.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQItem.java
trunk/MXQuery/build.xml
Removed Paths:
-------------
trunk/MXQuery/android/ant-contrib-1.0b3.jar
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/FlatItem.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/Item.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/ItemAccessor.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQConnection.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQDataSource.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQExpression.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQMetaData.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQPreparedExpression.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQSequence.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQStaticContext.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQType.java
trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/TreeItem.java
Deleted: trunk/MXQuery/android/ant-contrib-1.0b3.jar
===================================================================
(Binary files differ)
Modified: trunk/MXQuery/android/lib/jsr173_1.0_api-repackaged.jar
===================================================================
(Binary files differ)
Modified: trunk/MXQuery/android/lib/xqjapi-repackaged.jar
===================================================================
(Binary files differ)
Deleted: trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/FlatItem.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/FlatItem.java 2011-05-04 19:41:26 UTC (rev 4310)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/FlatItem.java 2011-05-04 21:48:40 UTC (rev 4311)
@@ -1,264 +0,0 @@
-/* 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.xqj;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.net.URI;
-import java.util.Properties;
-
-import javax.xml.datatype.DatatypeConfigurationException;
-import javax.xml.datatype.DatatypeFactory;
-
-import org.w3c.dom.Node;
-
-import ch.ethz.mxquery.contextConfig.Context;
-import ch.ethz.mxquery.datamodel.MXQueryDouble;
-import ch.ethz.mxquery.datamodel.MXQueryNumber;
-import ch.ethz.mxquery.datamodel.types.Type;
-import ch.ethz.mxquery.datamodel.types.TypeInfo;
-import ch.ethz.mxquery.datamodel.types.TypeLexicalConstraints;
-import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
-import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.iterators.TokenIterator;
-import ch.ethz.mxquery.model.XDMIterator;
-import ch.ethz.mxquery.util.PlatformDependentUtils;
-import ch.ethz.xquery.XQException;
-
-public class FlatItem implements Item {
-
- TokenInterface tk;
- private boolean closed = false;
-
- public FlatItem(TokenInterface tk){
- this.tk = tk;
- }
-
- public void close() {
- closed = true;
- this.tk = null;
- }
-
- public String getAtomicValue() throws XQException {
- if (Type.isSubTypeOf(tk.getEventType(), Type.ANY_ATOMIC_TYPE, null)) {
- return tk.getValueAsString();
- }
- throw new XQException("Failed to getAtomicValue: item is a node, or is closed");
- }
-
- public boolean getBoolean() throws XQException {
- if (Type.isTypeOrSubTypeOf(tk.getEventType(), Type.BOOLEAN, Context.getDictionary())) {
- return tk.getBoolean();
- }
- throw new XQException("Failed to getBoolean: item is a node, or is closed");
- }
-
- public byte getByte() throws XQException {
- int targetType = Type.BYTE;
- return (byte)checkIntType(targetType);
- }
-
- public double getDouble() throws XQException {
- if (Type.isTypeOrSubTypeOf(tk.getEventType(), Type.DOUBLE, Context.getDictionary())) {
- MXQueryDouble doub = null;
- doub = tk.getDouble();
- return doub.getValue();
- }
- throw new XQException("Failed to getDouble: item is a node, or is closed");
- }
-
- public float getFloat() throws XQException {
- if (Type.isTypeOrSubTypeOf(tk.getEventType(), Type.FLOAT, Context.getDictionary())) {
- MXQueryDouble doub = null;
- doub = tk.getDouble();
- return (float)doub.getValue();
- }
- throw new XQException("Failed to getFloat: item is a node, or is closed");
- }
-
- public int getInt() throws XQException {
- int targetType = Type.INT;
- return (int)checkIntType(targetType);
- }
-
- public String getItemAsString(Properties props) throws XQException {
- if (Type.isTypeOrSubTypeOf(tk.getEventType(), Type.ANY_ATOMIC_TYPE, Context.getDictionary())) {
- return getAtomicValue();
- }
- throw new XQException("Failed to getItemAsString: ");
- }
-
-
- public long getLong() throws XQException {
- int targetType = Type.INTEGER;
- return checkIntType(targetType);
- }
-
- public short getShort() throws XQException {
- int targetType = Type.SHORT;
- return (short)checkIntType(targetType);
- }
-
- private long checkIntType(int targetType) throws XQException {
- if (Type.isTypeOrSubTypeOf(tk.getEventType(), Type.DECIMAL, Context.getDictionary())){
- long res = tk.getLong();
- if (!Type.isTypeOrSubTypeOf(tk.getEventType(), Type.INTEGER, Context.getDictionary())){
- MXQueryNumber num = tk.getNumber();
- try {
- res = num.getLongValue();
- } catch (MXQueryException e) {
- throw new XQException("Invalid value for getXXX() operation");
- }
- if (num.compareTo(res)!= 0) {
- throw new XQException("Invalid value for getXXX() operation");
- }
- }
- try {
- if (!TypeLexicalConstraints.satisfyIntegerRange(targetType, res))
- throw new XQException("Invalid value for getXXX() operation");
- } catch (MXQueryException e) {
- throw new XQException(e.toString());
- }
-
- return res;
- }
- throw new XQException("Failed to getByte: item is a node, or is closed");
- }
-
-
- public boolean isClosed() {
- return this.closed;
- }
-
- public TypeInfo getType() {
- return new TypeInfo(tk.getEventType(),Type.OCCURRENCE_IND_EXACTLY_ONE);
- }
-
- public XDMIterator getAsIterator() throws XQException{
- try {
- return new TokenIterator(null,tk,null, false);
- } catch (MXQueryException me) {
- throw new XQException(me.toString());
- }
- }
-
- public Object getObject() throws XQException {
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.STRING,Context.getDictionary())) {
- return getItemAsString(null);
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.ANY_URI,Context.getDictionary())||
- Type.isTypeOrSubTypeOf(tk.getEventType(),Type.UNTYPED_ATOMIC,Context.getDictionary())) {
- return getItemAsString(null);
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.FLOAT,Context.getDictionary())) {
- return new Float(getFloat());
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.DOUBLE,Context.getDictionary())) {
- return new Double(getDouble());
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.BYTE,Context.getDictionary())) {
- return new Byte(getByte());
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.SHORT,Context.getDictionary())||
- Type.isTypeOrSubTypeOf(tk.getEventType(),Type.UNSIGNED_BYTE,Context.getDictionary())) {
- return new Short(getShort());
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.INT,Context.getDictionary())||
- Type.isTypeOrSubTypeOf(tk.getEventType(),Type.UNSIGNED_SHORT,Context.getDictionary())) {
- return new Integer(getInt());
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.LONG,Context.getDictionary())||
- Type.isTypeOrSubTypeOf(tk.getEventType(),Type.UNSIGNED_INT,Context.getDictionary())) {
- return new Long(getLong());
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.INTEGER,Context.getDictionary())||
- Type.isTypeOrSubTypeOf(tk.getEventType(),Type.UNSIGNED_LONG,Context.getDictionary())) {
- return BigInteger.valueOf(getLong());
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.DECIMAL,Context.getDictionary())) {
- return new BigDecimal(tk.getValueAsString());
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.BOOLEAN,Context.getDictionary())) {
- return new Boolean(tk.getBoolean());
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.BASE64_BINARY,Context.getDictionary())) {
- return tk.getBinary().getValue();
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.HEX_BINARY,Context.getDictionary())) {
- return tk.getBinary().getValue();
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.DATE,Context.getDictionary())||
- Type.isTypeOrSubTypeOf(tk.getEventType(),Type.DATE_TIME,Context.getDictionary())||
- Type.isTypeOrSubTypeOf(tk.getEventType(),Type.TIME,Context.getDictionary())||
- Type.isTypeOrSubTypeOf(tk.getEventType(),Type.G_DAY,Context.getDictionary())||
- Type.isTypeOrSubTypeOf(tk.getEventType(),Type.G_MONTH,Context.getDictionary())||
- Type.isTypeOrSubTypeOf(tk.getEventType(),Type.G_MONTH_DAY,Context.getDictionary())||
- Type.isTypeOrSubTypeOf(tk.getEventType(),Type.G_YEAR,Context.getDictionary())||
- Type.isTypeOrSubTypeOf(tk.getEventType(),Type.G_YEAR_MONTH,Context.getDictionary())) {
- try {
- return DatatypeFactory.newInstance().newXMLGregorianCalendar(getItemAsString(null));
- } catch (DatatypeConfigurationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- //XMLGregorianCalendarImpl.parse(getItemAsString(null));
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(), Type.QNAME, Context.getDictionary())) {
- ch.ethz.mxquery.datamodel.QName qn = tk.getQNameTokenValue();
- return PlatformDependentUtils.getJavaxQName(qn);
- }
-
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.DAY_TIME_DURATION,Context.getDictionary())) {
- try {
- return DatatypeFactory.newInstance().newDurationDayTime(getItemAsString(null));
- } catch (DatatypeConfigurationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.DURATION,Context.getDictionary())) {
- try {
- return DatatypeFactory.newInstance().newDuration(getItemAsString(null));
- } catch (DatatypeConfigurationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if (Type.isTypeOrSubTypeOf(tk.getEventType(),Type.YEAR_MONTH_DURATION,Context.getDictionary())) {
- try {
- return DatatypeFactory.newInstance().newDurationYearMonth(getItemAsString(null));
- } catch (DatatypeConfigurationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
-
- throw new XQException("Unsupported type for getObject");
-
- }
-
- public Node getNode() throws XQException {
- // TODO Auto-generated method stub
- throw new XQException("getNode() not possible on atomic types");
- }
-
- public URI getNodeUri() throws XQException{
- throw new XQException("getNodeUri not possible on atomic types");
- }
-
-}
Deleted: trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/Item.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/Item.java 2011-05-04 19:41:26 UTC (rev 4310)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/Item.java 2011-05-04 21:48:40 UTC (rev 4311)
@@ -1,61 +0,0 @@
-/* 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.xqj;
-
-import java.net.URI;
-import java.util.Properties;
-
-import org.w3c.dom.Node;
-
-import ch.ethz.mxquery.datamodel.types.TypeInfo;
-import ch.ethz.mxquery.model.XDMIterator;
-import ch.ethz.xquery.XQException;
-
-public interface Item {
-
- void close();
-
- String getAtomicValue() throws XQException;
-
- boolean getBoolean() throws XQException;
-
- byte getByte() throws XQException;
-
- double getDouble() throws XQException;
-
- float getFloat() throws XQException;
-
- int getInt() throws XQException;
-
- String getItemAsString(Properties props) throws XQException;
-
- XDMIterator getAsIterator() throws XQException;
-
- long getLong() throws XQException;
-
- short getShort() throws XQException;
-
- boolean isClosed();
-
- TypeInfo getType();
-
- Object getObject() throws XQException;
-
- Node getNode() throws XQException;
-
- URI getNodeUri() throws XQException;
-
-}
Deleted: trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/ItemAccessor.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/ItemAccessor.java 2011-05-04 19:41:26 UTC (rev 4310)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/ItemAccessor.java 2011-05-04 21:48:40 UTC (rev 4311)
@@ -1,122 +0,0 @@
-/* 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.xqj;
-
-import java.io.IOException;
-import java.util.Vector;
-
-import ch.ethz.mxquery.datamodel.types.Type;
-import ch.ethz.mxquery.datamodel.xdm.Token;
-import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
-import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.model.Iterator;
-import ch.ethz.mxquery.model.XDMIterator;
-import ch.ethz.mxquery.query.PreparedStatement;
-import ch.ethz.mxquery.util.PlatformDependentUtils;
-import ch.ethz.xquery.XQException;
-import ch.ethz.xquery.XQQueryException;
-
-public class ItemAccessor {
-
- private XDMIterator iter;
- private PreparedStatement statement;
- //private Iterator retIter;
-
-// private boolean startTagStarted = false;
-// private boolean endTagFound = false;
-
- public ItemAccessor(XDMIterator iter){
- this.iter = iter;
- }
-
- public ItemAccessor(PreparedStatement statement) throws XQException {
- this.statement = statement;
- try {
- this.iter = statement.evaluate();
- } catch (MXQueryException e) {
- throw new XQQueryException(e.toString(),PlatformDependentUtils.getJavaxQName(e.getErrorCode()));
- }
- }
-
-// public boolean hasNext() {
-// // TODO Auto-generated method stub
-// return false;
-// }
-
- public Object next() throws MXQueryException, IOException {
- int depth = 0;
- int curDepth;
- boolean flag = true;
-
-// startTagStarted = false;
-// endTagFound = false;
-
- Vector v = new Vector();
-
- //StringBuffer myBuffer = new StringBuffer();
-
- //this.retIter = this.iter.
-
- TokenInterface tok = iter.next();
- curDepth = depth;
-
- if(Type.isAtomicType(tok.getEventType(), null)){
- return new FlatItem(tok);
- }
-
- if(tok.getEventType() != Type.END_SEQUENCE){
-
- while(tok.getEventType() !=Type.END_SEQUENCE && flag){
-
- if (Type.isStartType(tok.getEventType())){
- depth++;
- } else if (Type.isEndType(tok.getEventType())){
- depth--;
- }
-
-
- v.add(tok);
-
- if(depth != curDepth){
- tok = iter.next();
- } else {
- flag = false;
- }
- }
- return new TreeItem(v);
-
- }
- if (tok == Token.END_SEQUENCE_TOKEN) {
- if (iter.getExpressionCategoryType(false) == Iterator.EXPR_CATEGORY_UPDATING) {
- iter.getPendingUpdateList().apply();
- statement.serializeStores(false);
- }
- }
-
- return null;
-
- }
-
- public XDMIterator getIterator(){
- return iter;
- }
-
- public void remove() {
- // TODO Auto-generated method stub
-
- }
-
-}
Deleted: trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQConnection.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQConnection.java 2011-05-04 19:41:26 UTC (rev 4310)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQConnection.java 2011-05-04 21:48:40 UTC (rev 4311)
@@ -1,218 +0,0 @@
-/* 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.xqj;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.util.Vector;
-
-import ch.ethz.mxquery.query.XQCompiler;
-import ch.ethz.mxquery.query.PreparedStatement;
-import ch.ethz.mxquery.query.impl.CompilerImpl;
-import ch.ethz.mxquery.util.PlatformDependentUtils;
-import ch.ethz.mxquery.contextConfig.CompilerOptions;
-import ch.ethz.mxquery.contextConfig.Context;
-import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.xquery.XQConnection;
-import ch.ethz.xquery.XQException;
-import ch.ethz.xquery.XQExpression;
-import ch.ethz.xquery.XQMetaData;
-import ch.ethz.xquery.XQPreparedExpression;
-import ch.ethz.xquery.XQQueryException;
-import ch.ethz.xquery.XQStaticContext;
-
-public class MXQueryXQConnection extends MXQueryXQDataFactory implements
-XQConnection {
-
- MXQueryXQStaticContext runtime;
- private int languageLevel = 0;
- private Vector expStore = new Vector();
- CompilerOptions co = new CompilerOptions();
-
- public MXQueryXQConnection(MXQueryXQDataSource src) {
- // Query root context (=? static context) per connections
- runtime = new MXQueryXQStaticContext(new Context());
- }
-
- public MXQueryXQConnection(MXQueryXQDataSource src, int mode) {
- // Query root context (=? static context) per connections
- runtime = new MXQueryXQStaticContext(new Context());
- languageLevel = mode;
- }
-
-
- public void clearWarnings() throws XQException {
- checkNotClosed();
- // TODO Auto-generated method stub
-
- }
-
- public void close() throws XQException {
- for(int i = 0; i < this.expStore.size(); i ++){
- if(this.expStore.get(i) instanceof MXQueryXQExpression)
- ((MXQueryXQExpression) this.expStore.get(i)).close();
- else
- ((MXQueryXQPreparedExpression) this.expStore.get(i)).close();
- }
- closed = true;
- }
-
- public void commit() throws XQException {
- checkNotClosed();
- // TODO NoOp
-
- }
-
- public XQExpression createExpression(XQStaticContext properties)
- throws XQException {
- if (properties == null) {
- throw new XQException("Static Context is null");
- }
- checkNotClosed();
- MXQueryXQExpression mxExp = new MXQueryXQExpression(this, (MXQueryXQStaticContext)properties, languageLevel);
- this.expStore.add(mxExp);
- return mxExp;
- }
-
- public XQExpression createExpression() throws XQException {
- checkNotClosed();
- MXQueryXQExpression mxExp = new MXQueryXQExpression(this, new MXQueryXQStaticContext(runtime), languageLevel);
- this.expStore.add(mxExp);
- return mxExp;
- }
-
- public XQMetaData getMetaData() throws XQException {
- checkNotClosed();
- return new MXQueryXQMetaData(this);
- }
-
- public String getMetaDataProperty(String key) throws XQException {
- checkNotClosed();
- throw new UnsupportedOperationException("Metadata is not yet implemented");
- }
-
- public String[] getSupportedMetaDataPropertyNames() throws XQException {
- checkNotClosed();
- throw new UnsupportedOperationException("Metadata is not yet implemented");
- }
-
- public boolean isClosed() {
- return closed;
- }
-
- public XQPreparedExpression prepareExpression(InputStream xquery)
- throws XQException {
- if (xquery == null)
- throw new XQException("Query is null");
- return prepareExpression(xquery, new MXQueryXQStaticContext(runtime));
- }
-
- public XQPreparedExpression prepareExpression(InputStream xquery,
- XQStaticContext properties) throws XQException {
- if (xquery == null)
- throw new XQException("Query is null");
- return prepareExpression(new InputStreamReader(xquery), properties);
- }
-
- public XQPreparedExpression prepareExpression(Reader xquery)
- throws XQException {
- checkNotClosed();
- if (xquery == null)
- throw new XQException("Query is null");
- return prepareExpression(xquery, new MXQueryXQStaticContext(runtime));
- }
-
- public XQPreparedExpression prepareExpression(Reader xquery,
- XQStaticContext properties) throws XQException {
- checkNotClosed();
- if (xquery == null)
- throw new XQException("Input is a null value");
- String expr = "";
- String str;
- try {
- BufferedReader br = new BufferedReader(xquery);
- while((str = br.readLine()) != null){
- expr += str;
- }
- } catch (IOException e) {
- throw new XQQueryException(e.toString());
- }
- return prepareExpression(expr, properties);
-
- }
-
- public XQPreparedExpression prepareExpression(String xquery)
- throws XQException {
- if (xquery == null)
- throw new XQException("Query is null");
- return prepareExpression(xquery, new MXQueryXQStaticContext(runtime));
- }
-
- public XQPreparedExpression prepareExpression(String xquery,
- XQStaticContext properties) throws XQException {
- checkNotClosed();
- if (xquery == null)
- throw new XQException("Query is null");
- MXQueryXQStaticContext ctx = runtime;
- if (properties != null)
- ctx = (MXQueryXQStaticContext)properties;
- else
- throw new XQException("Static context is null");
- try {
- XQCompiler compiler = new CompilerImpl();
- PreparedStatement statement = compiler.compile(ctx.runtime, xquery,co, null, null);
- MXQueryXQPreparedExpression mxPreExp = new MXQueryXQPreparedExpression(this, statement);
- this.expStore.add(mxPreExp);
- return mxPreExp;
- } catch (MXQueryException e) {
- throw new XQQueryException(e.toString(),PlatformDependentUtils.getJavaxQName(e.getErrorCode()));
- }
- }
-
- public void rollback() throws XQException {
- checkNotClosed();
- }
-
-
- public boolean getAutoCommit() throws XQException {
- return true;
- }
-
-
- public XQStaticContext getStaticContext() throws XQException {
- checkNotClosed();
- return new MXQueryXQStaticContext(runtime);
- }
-
-
- public void setAutoCommit(boolean autoCommit) throws XQException {
- if (autoCommit == false)
- throw new XQException("Disabling autocommit not supported");
-
- }
-
-
- public void setStaticContext(XQStaticContext properties) throws XQException {
- checkNotClosed();
- if (properties == null)
- throw new XQException("Static Context is null");
- runtime = ((MXQueryXQStaticContext)properties);
- }
-
-}
Modified: trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQDataFactory.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQDataFactory.java 2011-05-04 19:41:26 UTC (rev 4310)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQDataFactory.java 2011-05-04 21:48:40 UTC (rev 4311)
@@ -75,14 +75,14 @@
import ch.ethz.mxquery.util.StringReader;
import ch.ethz.mxquery.xdmio.XDMInputFactory;
import ch.ethz.mxquery.xdmio.XMLSource;
-import ch.ethz.namespace.QName;
-import ch.ethz.stream.XMLStreamReader;
-import ch.ethz.xquery.XQDataFactory;
-import ch.ethz.xquery.XQException;
-import ch.ethz.xquery.XQItem;
-import ch.ethz.xquery.XQItemType;
-import ch.ethz.xquery.XQSequence;
-import ch.ethz.xquery.XQSequenceType;
+import ch.ethz.repackaged.namespace.QName;
+import ch.ethz.repackaged.stream.XMLStreamReader;
+import ch.ethz.repackaged.xquery.XQDataFactory;
+import ch.ethz.repackaged.xquery.XQException;
+import ch.ethz.repackaged.xquery.XQItem;
+import ch.ethz.repackaged.xquery.XQItemType;
+import ch.ethz.repackaged.xquery.XQSequence;
+import ch.ethz.repackaged.xquery.XQSequenceType;
public class MXQueryXQDataFactory implements XQDataFactory {
Deleted: trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQDataSource.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQDataSource.java 2011-05-04 19:41:26 UTC (rev 4310)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQDataSource.java 2011-05-04 21:48:40 UTC (rev 4311)
@@ -1,92 +0,0 @@
-/* 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.xqj;
-
-import java.io.PrintWriter;
-import java.sql.Connection;
-import java.util.Properties;
-
-import ch.ethz.xquery.XQConnection;
-import ch.ethz.xquery.XQDataSource;
-import ch.ethz.xquery.XQException;
-
-public class MXQueryXQDataSource implements
-XQDataSource {
-
- public static final int XQJ_NORMAL_MODE = 0;
- public static final int XQJ_UPDATE_MODE = 1;
- public static final int XQJ_SCRIPTING_MODE = 2;
-
- private int languageLevel = 0;
-
- PrintWriter logger;
-
- public MXQueryXQDataSource() {
- }
-
- public MXQueryXQDataSource(int mode) {
- languageLevel = mode;
- }
-
- public XQConnection getConnection() throws XQException {
- return new MXQueryXQConnection(this, languageLevel);
- }
-
- public XQConnection getConnection(Connection con) throws XQException {
- throw new XQException("MXQuery cannot connect to a JDBC data source");
- }
-
- public XQConnection getConnection(String username, String password)
- throws XQException {
- return getConnection();
- }
-
- public PrintWriter getLogWriter() {
- return logger;
- }
-
- public int getLoginTimeout() {
- return 0;
- }
-
- public String getProperty(String name) throws XQException {
- throw new XQException("Getting property "+name+" not supported");
- }
-
- public String[] getSupportedPropertyNames() {
- String[] names =
- { };
- return names;
- }
-
- public void setLogWriter(PrintWriter out) throws XQException {
- logger = out;
- }
-
- public void setLoginTimeout(int seconds) throws XQException {
- // No-Op
- }
-
- public void setProperties(Properties props) throws XQException {
- throw new XQException("Setting properties not supported");
- }
-
- public void setProperty(String name, String value) throws XQException {
- throw new XQException("Setting property "+name+" not supported");
-
- }
-
-}
Modified: trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQDynamicContext.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQDynamicContext.java 2011-05-04 19:41:26 UTC (rev 4310)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/xqj/MXQueryXQDynamicContext.java 2011-05-04 21:48:40 UTC (rev 4311)
@@ -68,14 +68,14 @@
import ch.ethz.mxquery.util.StringReader;
import ch.ethz.mxquery.xdmio.XDMInputFactory;
import ch.ethz.mxquery.xdmio.XMLSource;
-import ch.ethz.namespace.QName;
-import ch.ethz.stream.XMLStreamReader;
-import ch.ethz.xquery.XQDynamicContext;
-import ch.ethz.xquery.XQException;
-import ch.ethz.xquery.XQItem;
-import ch.ethz.xquery.XQItemType;
-import ch.ethz.xquery.XQQueryException;
-import ch.ethz.xquery.XQSequence;
+import ch.ethz.repackaged.namespace.QName;
+import ch.ethz.repackaged.stream.XMLStreamReader;
+import ch.ethz.repackage...
[truncated message content] |
|
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/Parse...
[truncated message content] |
|
From: <et...@us...> - 2011-05-06 22:35:18
|
Revision: 4324
http://mxquery.svn.sourceforge.net/mxquery/?rev=4324&view=rev
Author: etterth
Date: 2011-05-06 22:35:11 +0000 (Fri, 06 May 2011)
Log Message:
-----------
- Added Timer
- Fixed Timezone-related bug, which caused a wrong time to be returned in fn:currenttime()
Modified Paths:
--------------
trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryDateTime.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/PlatformDependentUtils.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/Calendar.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/TimeZone.java
Added Paths:
-----------
trunk/MXQuery/xqib_samples/timer.html
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/Timer.java
Added: trunk/MXQuery/xqib_samples/timer.html
===================================================================
--- trunk/MXQuery/xqib_samples/timer.html (rev 0)
+++ trunk/MXQuery/xqib_samples/timer.html 2011-05-06 22:35:11 UTC (rev 4324)
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>XQIB: Sample page</title>
+ <meta charset="UTF-8"/>
+ <link href="style.css" rel="stylesheet" type="text/css">
+ <script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
+ <script type="application/xquery">
+ declare updating function local:listener() {
+ insert node <div>{fn:current-time()}</div> as last into b:dom()//body
+, b:timer(1000, xs:QName('local:listener'))
+ };
+
+ b:timer(1000, xs:QName('local:listener'))
+
+ </script>
+ </head>
+ <body>
+ <h1>timer</h1>
+
+ </body>
+</html>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryDateTime.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryDateTime.java 2011-05-06 10:18:30 UTC (rev 4323)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryDateTime.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -897,7 +897,7 @@
// int offset = new GregorianCalendar().get(Calendar.ZONE_OFFSET);
// int offset = Calendar.getInstance().get(Calendar.ZONE_OFFSET);
// return getNewCalendar(offset);
- return getNewCalendar(0);
+ return getNewCalendar(TimeZone.getDefault().getRawOffset());
}
private static TimeZone getNewTimeZone(int zone_offset) {
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-06 10:18:30 UTC (rev 4323)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -211,6 +211,9 @@
}
};
}
+ else {
+ throw new MXQueryException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "a qname has to be provided in an async expath function", getLoc());
+ }
XDMIterator[] oldsubiters = subIters;
subIters = new XDMIterator[oldsubiters.length - 1];
for (int i = 1; i < oldsubiters.length; i++) {
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java 2011-05-06 10:18:30 UTC (rev 4323)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -454,6 +454,33 @@
qn = new QName(
"http://xqib.org",
"b",
+ "timer");
+ paramTypes = new TypeInfo[2];
+
+ paramTypes[0] = new TypeInfo(getType(
+ "numeric",ctx),getOccur("numeric"),null);
+
+ paramTypes[1] = new TypeInfo(getType(
+ "QName",ctx),getOccur("QName"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.Timer iter = new ch.ethz.mxquery.functions.b.Timer();
+ iter.setContext(context, false);
+
+ type = -1;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
"pageURI");
paramTypes = new TypeInfo[0];
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/Timer.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/Timer.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/Timer.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -0,0 +1,148 @@
+package ch.ethz.mxquery.functions.b;
+
+import java.util.Vector;
+
+import com.google.gwt.user.client.Window;
+
+import ch.ethz.mxqjs.client.Environment;
+import ch.ethz.mxqjs.client.QnameAndArity;
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.MXQueryBigDecimal;
+import ch.ethz.mxquery.datamodel.MXQueryDouble;
+import ch.ethz.mxquery.datamodel.MXQueryFloat;
+import ch.ethz.mxquery.datamodel.MXQueryNumber;
+import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.types.TypeInfo;
+import ch.ethz.mxquery.datamodel.xdm.DecimalToken;
+import ch.ethz.mxquery.datamodel.xdm.DoubleToken;
+import ch.ethz.mxquery.datamodel.xdm.FloatToken;
+import ch.ethz.mxquery.datamodel.xdm.LongToken;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.DynamicException;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.StaticException;
+import ch.ethz.mxquery.exceptions.TypeException;
+import ch.ethz.mxquery.extensionsModules.expathhttp.HttpIO;
+import ch.ethz.mxquery.functions.fn.Abs;
+import ch.ethz.mxquery.model.TokenBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.LogLevel;
+import ch.ethz.mxquery.util.Logger;
+import ch.ethz.mxquery.util.browser.XmlHttpRequestWrappedHandler;
+import ch.ethz.mxquery.util.browser.XmlHttpRequestWrapper;
+
+public class Timer extends TokenBasedIterator {
+
+ protected QName asynchandlername;
+
+ @Override
+ protected void init() throws MXQueryException {
+ // TODO integer and timer
+ currentToken = Token.END_SEQUENCE_TOKEN;
+ if (subIters[0] == null) {
+ throw new IllegalArgumentException();
+ }
+ XDMIterator handleriter = subIters[1];
+ asynchandlername = handleriter.next().getQNameTokenValue();
+ if (asynchandlername == null) {
+ throw new MXQueryException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "a qname has to be provided in b:timer", getLoc());
+ }
+ XDMIterator timeiter = subIters[0];
+ TokenInterface tok;
+ try {
+ tok = timeiter.next();
+ } catch (TypeException de) {
+ if (de.getErrorCode().equals(
+ ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE))
+ throw new DynamicException(
+ ErrorCodes.F0023_INVALID_VALUE_FOR_CAST_CONSTRUCTOR,
+ de.getMessage(), loc);
+ else
+ throw de;
+ }
+
+ int type = Type.getEventTypeSubstituted(tok.getEventType(),
+ Context.getDictionary());
+
+ if (Type.isAttribute(type)) {
+ type = Type.getAttributeValueType(type);
+ }
+
+ if (!Type.isNumericPrimitiveType(type)){
+ throw new MXQueryException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "a numeric value has to be provided in b:timer", getLoc());
+ }
+
+ int time;
+ switch(type){
+ case Type.INTEGER:
+ time = (int) tok.getLong();
+ break;
+ case Type.DOUBLE:
+ case Type.FLOAT:
+ case Type.DECIMAL:
+ time = (int) tok.getNumber().getLongValue();
+ break;
+ case Type.UNTYPED_ATOMIC:
+ case Type.UNTYPED:
+ time = new MXQueryDouble(tok.getValueAsString()).getIntValue();
+ break;
+ default:
+ throw new TypeException(ErrorCodes.F0028_INVALID_ARGUMENT_TYPE, "Invalid argument type "+Type.getTypeQName(type, Context.getDictionary()), loc);
+}//switch
+ if (this.getContext().getRootContext()
+ .getFunction(asynchandlername, 0) == null) {
+ throw new MXQueryException(
+ ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,
+ "the eventhandler with the name "
+ + asynchandlername.toString()
+ + " is not available in a timer call",
+ loc);
+ }
+ final Timer thisobj = this;
+
+ com.google.gwt.user.client.Timer timerobj = new com.google.gwt.user.client.Timer() {
+
+ @Override
+ public void run() {
+
+ Logger log = Logger.getLogger(this.getClass().getName());
+ log.log(LogLevel.FINER, "Invoking the TimerHandler " + thisobj.asynchandlername.toString());
+ QnameAndArity qa = new QnameAndArity(
+ thisobj.asynchandlername, 0, thisobj.getContext()
+ .getRootContext());
+ try {
+ Environment.invokeModule(qa,
+ new XDMIterator[] { });
+ } catch (MXQueryException e) {
+ // TODO Auto-generated catch block
+
+ Environment.displayErrorMessage(new StringBuffer(), null, e,
+ false);
+ e.printStackTrace();
+ }
+ log.log(LogLevel.FINER, "TimerHandler " + thisobj.asynchandlername.toString() + " done");
+ }
+ };
+ timerobj.schedule(time);
+
+
+ }
+
+ @Override
+ public TypeInfo getStaticType() {
+ return new TypeInfo();
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ XDMIterator copy = new Timer();
+ copy.setContext(context, true);
+ copy.setSubIters(subIters);
+ return copy;
+ }
+
+}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/PlatformDependentUtils.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/PlatformDependentUtils.java 2011-05-06 10:18:30 UTC (rev 4323)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/PlatformDependentUtils.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -93,7 +93,7 @@
public static int getCurrentTimezoneOffset(){
Calendar cal = MXQueryDateTime.getNewCalendar();
TimeZone tz = cal.getTimeZone();
- return tz.getStandardOffset() / (1000 * 60);
+ return tz.getRawOffset() / (1000 * 60);
}
/**
* Provide access to the current time
@@ -105,7 +105,7 @@
TimeZone tz = cal.getTimeZone();
return new MXQueryDateTime(cal,
- tz.getStandardOffset() , MXQueryDateTime.VALUE_TYPE_DATE_TIME);
+ tz.getRawOffset() / (1000 * 60) , MXQueryDateTime.VALUE_TYPE_DATE_TIME);
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/Calendar.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/Calendar.java 2011-05-06 10:18:30 UTC (rev 4323)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/Calendar.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -437,7 +437,7 @@
}
else
{
- return timeZone.getStandardOffset();
+ return timeZone.getRawOffset();
}
// case DST_OFFSET:
// //TODO, fix
@@ -805,16 +805,29 @@
// }
- Date date = new Date(
- localDateTime.year,
- localDateTime.month,
- localDateTime.date,
- localDateTime.hourOfDay,
- localDateTime.minutes,
- localDateTime.seconds);
+ Date datewithoutms = new Date(
+ localDateTime.year,
+ localDateTime.month,
+ localDateTime.date,
+ localDateTime.hourOfDay,
+ localDateTime.minutes,
+ localDateTime.seconds);
- // Date class does not have milliseconds manipulation.
- date.setTime(date.getTime() + localDateTime.milliseconds);
+
+ // Date class does not have milliseconds manipulation.
+ Date datewithms = new Date(datewithoutms.getTime() + localDateTime.milliseconds);
+ localDateTime.year = datewithms.getYear();
+ localDateTime.month = datewithms.getMonth();
+ localDateTime.date = datewithms.getDate();
+ localDateTime.hourOfDay = datewithms.getHours();
+ localDateTime.minutes = datewithms.getMinutes();
+ localDateTime.seconds = datewithms.getSeconds();
+ localDateTime.milliseconds = (int) (datewithms.getTime() - datewithoutms.getTime());
+ //milliseconds might have been negative
+ if (localDateTime.milliseconds < 0){
+ localDateTime.milliseconds = - localDateTime.milliseconds;
+ }
+ localDateTime.milliseconds = localDateTime.milliseconds % 1000;
// Store the rolled up fields back in the original LocalDateTime object.
// setValuesFromDate(this.date);
@@ -943,8 +956,8 @@
// Console.log("GWTDate createDate " + d);
- int offsetConversion = d.getTimezoneOffset() - timeZone2.getStandardOffset();
- d.setMinutes(d.getMinutes() - offsetConversion);
+ int offsetConversion = -d.getTimezoneOffset()*60*1000 - timeZone2.getRawOffset();
+ d.setTime(d.getTime() + offsetConversion);
// d.setMinutes(d.getMinutes() - timeZone.timeZoneContainer.getTimeZone().getDaylightAdjustment(d));
return d;
}
@@ -954,7 +967,7 @@
return this.getTime().getTime();
}
public static Calendar getInstance() {
- return getInstance(new Date().getTimezoneOffset());
+ return getInstance(TimeZone.getDefault().getRawOffset());
}
public static Calendar getInstance(int zone_offset) {
// TODO Auto-generated method stub
@@ -968,8 +981,9 @@
}
public void setTimeZone(TimeZone newTimeZone) {
- this.localDateTime.minutes += this.timeZone.getStandardOffset()- newTimeZone.getStandardOffset() ;
+ this.localDateTime.milliseconds -= this.timeZone.getRawOffset()- newTimeZone.getRawOffset() ;
this.timeZone = newTimeZone;
+ this.needsCalculation = true;
}
public TimeZone getTimeZone() {
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/TimeZone.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/TimeZone.java 2011-05-06 10:18:30 UTC (rev 4323)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/util/TimeZone.java 2011-05-06 22:35:11 UTC (rev 4324)
@@ -5,19 +5,19 @@
public class TimeZone {
- private int minutes_offset = 0;
+ private int milliseconds_offset = 0;
public TimeZone(int zone_offset) {
- minutes_offset = zone_offset;
+ milliseconds_offset = zone_offset;
}
public static TimeZone getDefault() {
- return new TimeZone(new Date().getTimezoneOffset());
+ return new TimeZone(-new Date().getTimezoneOffset()*1000*60);
}
/**
- * @return the offset in minutes
+ * @return the offset in milliseconds
*/
- public int getStandardOffset() {
- return minutes_offset;
+ public int getRawOffset() {
+ return milliseconds_offset;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-05-09 02:20:35
|
Revision: 4326
http://mxquery.svn.sourceforge.net/mxquery/?rev=4326&view=rev
Author: etterth
Date: 2011-05-09 02:20:28 +0000 (Mon, 09 May 2011)
Log Message:
-----------
- Cookies added
- Fixed build
- Asynchronous expath now with handler as last parameter
- Fixed a bug with setting the value in input elements
- The setup script no longer destroys the root's .svn
Modified Paths:
--------------
trunk/MXQuery/xqib_setup_env.sh
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/EXPathHTTP.xml
trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Element.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Node.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/HtmlParser.gwt.xml
Added Paths:
-----------
trunk/MXQuery/xqib_samples/cookies.html
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/GetCookie.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/GetCookieNames.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveCookie.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/SetCookie.java
Added: trunk/MXQuery/xqib_samples/cookies.html
===================================================================
--- trunk/MXQuery/xqib_samples/cookies.html (rev 0)
+++ trunk/MXQuery/xqib_samples/cookies.html 2011-05-09 02:20:28 UTC (rev 4326)
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>XQIB: Sample page</title>
+ <meta charset="UTF-8"/>
+ <link href="style.css" rel="stylesheet" type="text/css">
+ <script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
+ <script type="application/xquery">
+ import module namespace http-client = "http://expath.org/ns/http-client";
+
+ declare updating function local:getCookie($loc, $evtObj) {
+ let $name := b:dom()//input[@id='name']/@value
+ let $value := b:getCookie($name)
+ return if ($value) then
+
+ (replace value of node b:dom()//div[@id='status'] with ('the value of', $name, 'is', $value),
+ replace value of node b:dom()//input[@id='value']/@value with $value)
+ else
+ (replace value of node b:dom()//div[@id='status'] with concat('there is no cookie with name "', $name , '"'))
+ };
+
+ declare updating function local:setCookie($loc, $evtObj) {
+ b:setCookie(b:dom()//input[@id='name']/@value, b:dom()//input[@id='value']/@value)
+ };
+
+
+ b:addEventListener(b:dom()//input[@id="getbutton"], "onclick", xs:QName("local:getCookie")),
+ b:addEventListener(b:dom()//input[@id="setbutton"], "onclick", xs:QName("local:setCookie"))
+
+ </script>
+ </head>
+ <body>
+ <h1>Cookies</h1>
+ <p/>
+ <div>Name: <input type="text" value="" style="font-size: 30pt; font-weight: bold" id="name"/></div>
+ <div>Value: <input type="text" value="" style="font-size: 30pt; font-weight: bold" id="value"/></div>
+
+ <input type="button" value="Set" style="font-size: 30pt; font-weight: bold" id="setbutton"/>
+ <input type="button" value="Get" style="font-size: 30pt; font-weight: bold" id="getbutton"/>
+ <div id="status"></div>
+ </body>
+</html>
\ No newline at end of file
Modified: trunk/MXQuery/xqib_setup_env.sh
===================================================================
--- trunk/MXQuery/xqib_setup_env.sh 2011-05-08 16:32:28 UTC (rev 4325)
+++ trunk/MXQuery/xqib_setup_env.sh 2011-05-09 02:20:28 UTC (rev 4326)
@@ -1,5 +1,10 @@
cp .classpath mxquery.classpath
-cp -rf xqib_files/* .
-cp -rf xqib_files/.* .
+#mkdir $(find xqib_files/ -type d | grep -v '.svn' )
+#cp $(find xqib_files/ | grep -v '.svn' ) .
+#cp -rf xqib_files/* .
+#cp -rf xqib_files/.* .
+(cd xqib_files ; tar --exclude='.svn' -c -f - .) | tar xfv -
ant xqib-js_prepare
-cp -rf xqib_samples/* war
+
+#cp -rf xqib_samples/* war
+(cd xqib_samples ; tar --exclude='.svn' -c -f - .) | (cd war ; tar xfv -)
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-05-08 16:32:28 UTC (rev 4325)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-05-09 02:20:28 UTC (rev 4326)
@@ -150,6 +150,7 @@
try {
log.log(LogLevel.FINER, "Calling eventcallback " + functionname.qname.toString());
ListBasedIterator eventiter = new EventIterator(event);
+ eventiter.setContext(new Context(), true);
Iterator[] subiterators = { nodeiter, eventiter };
QName qn = functionname.qname;
qn.setNamespaceURI(functionname.context.getNamespace(
@@ -164,7 +165,7 @@
// TODO Auto-generated catch block
Environment.displayErrorMessage(new StringBuffer(), null, e,
- false);
+ true);
e.printStackTrace();
}
}
@@ -324,6 +325,11 @@
} catch (Exception ex) {
}
}
+ else {//query == nulll
+ queryResult.append(err.getErrorCode() + " "
+ + err.getMessage() + "\n");
+
+ }
for (StackTraceElement trace : err.getStackTrace()) {
queryResult.append("\n");
queryResult.append(trace.toString());
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/EXPathHTTP.xml
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/EXPathHTTP.xml 2011-05-08 16:32:28 UTC (rev 4325)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/EXPathHTTP.xml 2011-05-09 02:20:28 UTC (rev 4326)
@@ -29,27 +29,27 @@
<functionDescription>
<functionName>async-request</functionName>
<parameters>
- <paramType>QName</paramType>
<paramType>element()?</paramType>
<paramType>string?</paramType>
<paramType>item()*</paramType>
+ <paramType>QName</paramType>
</parameters>
<className op="async">HttpIO</className>
</functionDescription>
<functionDescription>
<functionName>async-request</functionName>
<parameters>
- <paramType>QName</paramType>
<paramType>element()?</paramType>
<paramType>string?</paramType>
+ <paramType>QName</paramType>
</parameters>
<className op="async">HttpIO</className>
</functionDescription>
<functionDescription>
<functionName>async-request</functionName>
<parameters>
+ <paramType>element()?</paramType>
<paramType>QName</paramType>
- <paramType>element()?</paramType>
</parameters>
<className op="async">HttpIO</className>
</functionDescription>
@@ -63,10 +63,10 @@
<functionDescription>
<functionName>async-read</functionName>
<parameters>
+ <paramType>xs:string</paramType>
<paramType>QName</paramType>
- <paramType>xs:string</paramType>
</parameters>
<className op="async read">HttpIO</className>
</functionDescription>
</functionGroup>
-</functionGallery>
\ No newline at end of file
+</functionGallery>
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-08 16:32:28 UTC (rev 4325)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-09 02:20:28 UTC (rev 4326)
@@ -172,7 +172,7 @@
private void init() throws MXQueryException {
if (async) {
- XDMIterator handleriter = subIters[0];
+ XDMIterator handleriter = subIters[subIters.length - 1];
this.asynchandlername = handleriter.next().getQNameTokenValue();
if (asynchandlername != null) {
if (this.getContext().getRootContext()
@@ -209,8 +209,8 @@
}
XDMIterator[] oldsubiters = subIters;
subIters = new XDMIterator[oldsubiters.length - 1];
- for (int i = 1; i < oldsubiters.length; i++) {
- subIters[i - 1] = oldsubiters[i];
+ for (int i = 0; i < oldsubiters.length-1; i++) {
+ subIters[i] = oldsubiters[i];
}
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml 2011-05-08 16:32:28 UTC (rev 4325)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml 2011-05-09 02:20:28 UTC (rev 4326)
@@ -2,9 +2,46 @@
<functionGallery basePackage="ch.ethz.mxquery.functions.">
<functionGroup prefix="b" namespace="http://xqib.org">
<functionDescription>
+ <functionName>getCookieNames</functionName>
+ <className>GetCookieNames</className>
+ </functionDescription>
+ <functionDescription>
+ <functionName>getCookie</functionName>
+ <parameters>
+ <paramType>xs:string</paramType>
+ </parameters>
+ <className>GetCookie</className>
+ </functionDescription>
+ <functionDescription>
+ <functionName>removeCookie</functionName>
+ <parameters>
+ <paramType>xs:string</paramType>
+ </parameters>
+ <className>RemoveCookie</className>
+ </functionDescription>
+ <functionDescription>
+ <functionName>setCookie</functionName>
+ <parameters>
+ <paramType>xs:string</paramType>
+ <paramType>xs:string</paramType>
+ </parameters>
+ <className>SetCookie</className>
+ </functionDescription>
+ <functionDescription>
+ <functionName>setCookie</functionName>
+ <parameters>
+ <paramType>xs:string</paramType>
+ <paramType>xs:string</paramType>
+ <paramType>xs:dateTime</paramType>
+ </parameters>
+ <className>SetCookie</className>
+ </functionDescription>
+<!-- TODO: setcookie and removeCookie with more arguments -->
+
+ <functionDescription>
<functionName>pageURI</functionName>
<className>LocUri</className>
- </functionDescription>
+ </functionDescription>/
<functionDescription>
<functionName>getLocation</functionName>
<className>GetLocation</className>
@@ -1645,4 +1682,4 @@
</functionDescription>
</functionGroup>
-</functionGallery>
\ No newline at end of file
+</functionGallery>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java 2011-05-08 16:32:28 UTC (rev 4325)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java 2011-05-09 02:20:28 UTC (rev 4326)
@@ -198,10 +198,9 @@
Function function;
int type;
String classname;
+
+ ctx.addNamespace("expathhttp", "http://expath.org/ns/http-client");
- ctx.addNamespace(XQStaticContext.NS_EXPATH,
- XQStaticContext.URI_EXPATH);
-
qn = new QName(
"http://expath.org/ns/http-client",
"expathhttp",
@@ -290,16 +289,16 @@
paramTypes = new TypeInfo[4];
paramTypes[0] = new TypeInfo(getType(
- "QName",ctx),getOccur("QName"),null);
+ "element()?",ctx),getOccur("element()?"),null);
paramTypes[1] = new TypeInfo(getType(
- "element()?",ctx),getOccur("element()?"),null);
+ "string?",ctx),getOccur("string?"),null);
paramTypes[2] = new TypeInfo(getType(
- "string?",ctx),getOccur("string?"),null);
+ "item()*",ctx),getOccur("item()*"),null);
paramTypes[3] = new TypeInfo(getType(
- "item()*",ctx),getOccur("item()*"),null);
+ "QName",ctx),getOccur("QName"),null);
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
@@ -325,13 +324,13 @@
paramTypes = new TypeInfo[3];
paramTypes[0] = new TypeInfo(getType(
- "QName",ctx),getOccur("QName"),null);
+ "element()?",ctx),getOccur("element()?"),null);
paramTypes[1] = new TypeInfo(getType(
- "element()?",ctx),getOccur("element()?"),null);
+ "string?",ctx),getOccur("string?"),null);
paramTypes[2] = new TypeInfo(getType(
- "string?",ctx),getOccur("string?"),null);
+ "QName",ctx),getOccur("QName"),null);
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
@@ -357,10 +356,10 @@
paramTypes = new TypeInfo[2];
paramTypes[0] = new TypeInfo(getType(
- "QName",ctx),getOccur("QName"),null);
+ "element()?",ctx),getOccur("element()?"),null);
paramTypes[1] = new TypeInfo(getType(
- "element()?",ctx),getOccur("element()?"),null);
+ "QName",ctx),getOccur("QName"),null);
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
@@ -412,10 +411,10 @@
paramTypes = new TypeInfo[2];
paramTypes[0] = new TypeInfo(getType(
- "QName",ctx),getOccur("QName"),null);
+ "xs:string",ctx),getOccur("xs:string"),null);
paramTypes[1] = new TypeInfo(getType(
- "xs:string",ctx),getOccur("xs:string"),null);
+ "QName",ctx),getOccur("QName"),null);
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
@@ -454,20 +453,89 @@
qn = new QName(
"http://xqib.org",
"b",
- "timer");
+ "getCookieNames");
+ paramTypes = new TypeInfo[0];
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.GetCookieNames iter = new ch.ethz.mxquery.functions.b.GetCookieNames();
+ iter.setContext(context, false);
+
+ type = -1;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "getCookie");
+ paramTypes = new TypeInfo[1];
+
+ paramTypes[0] = new TypeInfo(getType(
+ "xs:string",ctx),getOccur("xs:string"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.GetCookie iter = new ch.ethz.mxquery.functions.b.GetCookie();
+ iter.setContext(context, false);
+
+ type = -1;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "removeCookie");
+ paramTypes = new TypeInfo[1];
+
+ paramTypes[0] = new TypeInfo(getType(
+ "xs:string",ctx),getOccur("xs:string"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.RemoveCookie iter = new ch.ethz.mxquery.functions.b.RemoveCookie();
+ iter.setContext(context, false);
+
+ type = -1;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "setCookie");
paramTypes = new TypeInfo[2];
paramTypes[0] = new TypeInfo(getType(
- "numeric",ctx),getOccur("numeric"),null);
+ "xs:string",ctx),getOccur("xs:string"),null);
paramTypes[1] = new TypeInfo(getType(
- "QName",ctx),getOccur("QName"),null);
+ "xs:string",ctx),getOccur("xs:string"),null);
signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
{
- ch.ethz.mxquery.functions.b.Timer iter = new ch.ethz.mxquery.functions.b.Timer();
+ ch.ethz.mxquery.functions.b.SetCookie iter = new ch.ethz.mxquery.functions.b.SetCookie();
iter.setContext(context, false);
type = -1;
@@ -481,6 +549,36 @@
qn = new QName(
"http://xqib.org",
"b",
+ "setCookie");
+ paramTypes = new TypeInfo[3];
+
+ paramTypes[0] = new TypeInfo(getType(
+ "xs:string",ctx),getOccur("xs:string"),null);
+
+ paramTypes[1] = new TypeInfo(getType(
+ "xs:string",ctx),getOccur("xs:string"),null);
+
+ paramTypes[2] = new TypeInfo(getType(
+ "xs:dateTime",ctx),getOccur("xs:dateTime"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.SetCookie iter = new ch.ethz.mxquery.functions.b.SetCookie();
+ iter.setContext(context, false);
+
+ type = -1;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
"pageURI");
paramTypes = new TypeInfo[0];
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/GetCookie.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/GetCookie.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/GetCookie.java 2011-05-09 02:20:28 UTC (rev 4326)
@@ -0,0 +1,43 @@
+package ch.ethz.mxquery.functions.b;
+
+import java.util.Vector;
+
+import com.google.gwt.user.client.Cookies;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.datamodel.xdm.UntypedAtomicToken;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.TypeException;
+import ch.ethz.mxquery.model.TokenBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class GetCookie extends TokenBasedIterator {
+
+ @Override
+ protected void init() throws MXQueryException {
+ TokenInterface tok = subIters[0].next();
+ String name = tok.getValueAsString();
+ if (name == null){
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Invalid argument type", loc);
+ }
+
+ String value = Cookies.getCookie(name);
+ if (value != null)
+ this.currentToken = new UntypedAtomicToken(null, value);
+ else
+ this.currentToken = Token.END_SEQUENCE_TOKEN;
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ GetCookie copy = new GetCookie();
+ copy.setContext(context, true);
+ copy.setSubIters(subIters);
+ return copy;
+ }
+
+}
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/GetCookieNames.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/GetCookieNames.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/GetCookieNames.java 2011-05-09 02:20:28 UTC (rev 4326)
@@ -0,0 +1,36 @@
+package ch.ethz.mxquery.functions.b;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Vector;
+
+import com.google.gwt.user.client.Cookies;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.datamodel.xdm.UntypedAtomicToken;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.iterators.browser.ListBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class GetCookieNames extends ListBasedIterator {
+
+ @Override
+ protected void init() throws MXQueryException {
+ lst = new LinkedList<TokenInterface>();
+ Collection<String> cookies = Cookies.getCookieNames();
+ for (String cookie: cookies){
+ lst.add(new UntypedAtomicToken(null, cookie));
+ }
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ GetCookieNames copy = new GetCookieNames();
+ copy.setContext(context, true);
+ copy.setSubIters(subIters);
+ return copy;
+ }
+
+}
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveCookie.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveCookie.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/RemoveCookie.java 2011-05-09 02:20:28 UTC (rev 4326)
@@ -0,0 +1,38 @@
+package ch.ethz.mxquery.functions.b;
+
+import java.util.Vector;
+
+import com.google.gwt.user.client.Cookies;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.datamodel.xdm.UntypedAtomicToken;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.TypeException;
+import ch.ethz.mxquery.model.TokenBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class RemoveCookie extends TokenBasedIterator {
+
+ @Override
+ protected void init() throws MXQueryException {
+ TokenInterface tok = subIters[0].next();
+ String name = tok.getValueAsString();
+ if (name == null){
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Invalid argument type", loc);
+ }
+
+ Cookies.removeCookie(name);
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ RemoveCookie copy = new RemoveCookie();
+ copy.setContext(context, true);
+ copy.setSubIters(subIters);
+ return copy;
+ }
+
+}
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/SetCookie.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/SetCookie.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/SetCookie.java 2011-05-09 02:20:28 UTC (rev 4326)
@@ -0,0 +1,58 @@
+package ch.ethz.mxquery.functions.b;
+
+import java.util.Vector;
+
+import com.google.gwt.user.client.Cookies;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.MXQueryDateTime;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.TypeException;
+import ch.ethz.mxquery.model.TokenBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class SetCookie extends TokenBasedIterator {
+
+ @Override
+ protected void init() throws MXQueryException {
+ TokenInterface tok = subIters[0].next();
+ String name = tok.getValueAsString();
+ if (name == null) {
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
+ "Invalid argument type", loc);
+ }
+
+ tok = subIters[1].next();
+ String value = tok.getValueAsString();
+ if (value == null) {
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
+ "Invalid argument type", loc);
+ }
+
+ if (subIters.length == 2) {
+ Cookies.setCookie(name, value);
+ return;
+ }
+ MXQueryDateTime expires = tok.getDateTime();
+ if (expires == null) {
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
+ "Invalid argument type", loc);
+ }
+
+ Cookies.setCookie(name, value, expires.createCalendar().getTime());
+ // TODO: more overloads
+
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ SetCookie copy = new SetCookie();
+ copy.setContext(context, true);
+ copy.setSubIters(subIters);
+ return copy;
+ }
+
+}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java 2011-05-08 16:32:28 UTC (rev 4325)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java 2011-05-09 02:20:28 UTC (rev 4326)
@@ -177,7 +177,21 @@
public native Document createDocument() /*-{
return $doc.implementation.createDocument('http://www.w3.org/1999/xhtml', '', null);
}-*/;
+
+ public void nodeSetValue(Node node, String nodeValue) {
+ if (node.getNodeType() == Node.ATTRIBUTE_NODE){
+ ((Attribute)node).getOwnerElement().setAttributeNS(node.getNameSpaceURI(), node.getLocalName(), nodeValue);
+ return;
+ }
+ native_nodeSetValue(node, nodeValue);
+
+ }
+ public native void native_nodeSetValue(Node node, String nodeValue) /*-{
+ node.nodeValue= nodeValue;
+
+ }-*/;
+
// public native Document getIFrameDocument(IFrameElement iframe) /*-{
//// $wnd.ifr = iframe;
// return iframe.contentDocument.document;
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Element.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Element.java 2011-05-08 16:32:28 UTC (rev 4325)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Element.java 2011-05-09 02:20:28 UTC (rev 4326)
@@ -2,7 +2,13 @@
import java.util.List;
+import org.eclipse.jdt.internal.compiler.ast.ThisReference;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.Namespace;
+
import com.google.gwt.core.client.JsArray;
+import com.google.gwt.dom.client.InputElement;
import com.google.gwt.dom.client.Style;
public class Element extends Node {
@@ -25,6 +31,21 @@
};
public final void setAttributeNS (String namespace, String localName, String value) {
+ String thisNameSpaceURI = this.getNameSpaceURI();
+ if ("http://www.w3.org/1999/xhtml".equals(thisNameSpaceURI)){
+ if ("input".equals(this.getLocalName())) {
+ InputElement el = (InputElement) this.getAsGwtElement();
+ if ("value".equals(localName)) {
+ el.setValue(value);
+ return;
+ } else if ("checked".equals(localName)) {
+
+ el.setChecked("true".equals(value));
+ return;
+ }
+ }
+
+ }
DOMImpl.impl.elementSetAttributeNS(this, namespace, localName, value);
};
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Node.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Node.java 2011-05-08 16:32:28 UTC (rev 4325)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Node.java 2011-05-09 02:20:28 UTC (rev 4326)
@@ -366,7 +366,7 @@
* The value of this node, depending on its type; see the table above. When
* it is defined to be null, setting it has no effect.
*/
- public final native void setNodeValue(String nodeValue) /*-{
- this.nodeValue = nodeValue;
- }-*/;
+ public final void setNodeValue(String nodeValue) {
+ DOMImpl.impl.nodeSetValue(this, nodeValue);
+ }
}
Modified: trunk/MXQuery/xqib_src/nu/validator/htmlparser/HtmlParser.gwt.xml
===================================================================
--- trunk/MXQuery/xqib_src/nu/validator/htmlparser/HtmlParser.gwt.xml 2011-05-08 16:32:28 UTC (rev 4325)
+++ trunk/MXQuery/xqib_src/nu/validator/htmlparser/HtmlParser.gwt.xml 2011-05-09 02:20:28 UTC (rev 4326)
@@ -6,6 +6,4 @@
<source path="common"/>
<source path="impl"/>
<source path="gwt"/>
- <entry-point class="nu.validator.htmlparser.gwt.HtmlParserModule"/>
- <add-linker name="sso"/>
</module>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-05-08 16:32:37
|
Revision: 4325
http://mxquery.svn.sourceforge.net/mxquery/?rev=4325&view=rev
Author: etterth
Date: 2011-05-08 16:32:28 +0000 (Sun, 08 May 2011)
Log Message:
-----------
- Tidy support for XQIB
Modified Paths:
--------------
trunk/MXQuery/build.xml
trunk/MXQuery/xqib_NOTICE
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/MXQueryJS.gwt.xml
trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Document.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Element.java
Added Paths:
-----------
trunk/MXQuery/gwt-2.3.0/
trunk/MXQuery/gwt-2.3.0/gwt-dev.jar
trunk/MXQuery/gwt-2.3.0/gwt-user.jar
trunk/MXQuery/xqib_samples/data/
trunk/MXQuery/xqib_samples/data/test.html
trunk/MXQuery/xqib_samples/tidy.html
trunk/MXQuery/xqib_src/nu/
trunk/MXQuery/xqib_src/nu/validator/
trunk/MXQuery/xqib_src/nu/validator/htmlparser/
trunk/MXQuery/xqib_src/nu/validator/htmlparser/HtmlParser.gwt.xml
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/Auto.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/CharacterName.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/Const.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/IdType.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/Inline.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/Literal.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/Local.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/NoLength.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/NsUri.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/Prefix.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/QName.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/Virtual.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/package.html
trunk/MXQuery/xqib_src/nu/validator/htmlparser/common/
trunk/MXQuery/xqib_src/nu/validator/htmlparser/common/ByteReadable.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/common/CharacterHandler.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/common/DoctypeExpectation.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/common/DocumentMode.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/common/DocumentModeHandler.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/common/EncodingDeclarationHandler.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/common/Heuristics.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/common/Interner.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/common/TokenHandler.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/common/TransitionHandler.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/common/XmlViolationPolicy.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/common/package.html
trunk/MXQuery/xqib_src/nu/validator/htmlparser/gwt/
trunk/MXQuery/xqib_src/nu/validator/htmlparser/gwt/BrowserTreeBuilder.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/gwt/HtmlParser.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/gwt/HtmlParserModule.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/gwt/ParseEndListener.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/AttributeName.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/CoalescingTreeBuilder.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/ElementName.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/ErrorReportingTokenizer.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/HotSpotWorkaround.txt
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/HtmlAttributes.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/LocatorImpl.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/MetaScanner.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/NCName.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/NamedCharacters.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/NamedCharactersAccel.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/Portability.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/PushedLocation.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/StackNode.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/StateSnapshot.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/TaintableLocatorImpl.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/Tokenizer.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/Tokenizer.java.orig
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/TreeBuilder.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/TreeBuilderState.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/UTF16Buffer.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/impl/package.html
trunk/MXQuery/xqib_src/nu/validator/htmlparser/public/
trunk/MXQuery/xqib_src/nu/validator/htmlparser/translatable/
trunk/MXQuery/xqib_src/nu/validator/htmlparser/translatable/java/
trunk/MXQuery/xqib_src/nu/validator/htmlparser/translatable/java/io/
trunk/MXQuery/xqib_src/nu/validator/htmlparser/translatable/java/io/IOException.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/translatable/org/
trunk/MXQuery/xqib_src/nu/validator/htmlparser/translatable/org/xml/
trunk/MXQuery/xqib_src/nu/validator/htmlparser/translatable/org/xml/sax/
trunk/MXQuery/xqib_src/nu/validator/htmlparser/translatable/org/xml/sax/Attributes.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/translatable/org/xml/sax/ErrorHandler.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/translatable/org/xml/sax/Locator.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/translatable/org/xml/sax/SAXException.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/translatable/org/xml/sax/SAXParseException.java
trunk/MXQuery/xqib_src/nu/validator/htmlparser/translatable/org/xml/sax/package.html
trunk/MXQuery/xqib_src/nu/validator/saxtree/
trunk/MXQuery/xqib_src/nu/validator/saxtree/CDATA.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/CharBufferNode.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/Characters.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/Comment.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/DTD.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/Document.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/DocumentFragment.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/Element.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/Entity.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/IgnorableWhitespace.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/LocatorImpl.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/Node.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/NodeType.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/NullLexicalHandler.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/ParentNode.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/PrefixMapping.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/ProcessingInstruction.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/SkippedEntity.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/TreeBuilder.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/TreeParser.java
trunk/MXQuery/xqib_src/nu/validator/saxtree/package.html
Removed Paths:
-------------
trunk/MXQuery/gwt-2.1.0/
Modified: trunk/MXQuery/build.xml
===================================================================
--- trunk/MXQuery/build.xml 2011-05-06 22:35:11 UTC (rev 4324)
+++ trunk/MXQuery/build.xml 2011-05-08 16:32:28 UTC (rev 4325)
@@ -522,14 +522,15 @@
<pathelement location="lib/junit.jar"/>
<!--<pathelement location="${ECLIPSE_HOME}/plugins/org.hamcrest.core_1.1.0.v20090501071000.jar"/>-->
</path>
- <path id="GWT SDK [GWT (1) - 2.1.0].libraryclasspath">
- <pathelement location="gwt-2.1.0/gwt-user.jar"/>
- <pathelement location="gwt-2.1.0/gwt-dev.jar"/>
+
+ <path id="GWT SDK.libraryclasspath">
+ <pathelement location="gwt-2.3.0/gwt-user.jar"/>
+ <pathelement location="gwt-2.3.0/gwt-dev.jar"/>
</path>
<path id="MXQueryJS.classpath">
<pathelement location="${gwt_webclasses.dir}"/>
<path refid="JUnit 4.libraryclasspath"/>
- <path refid="GWT SDK [GWT (1) - 2.1.0].libraryclasspath"/>
+ <path refid="GWT SDK.libraryclasspath"/>
</path>
<path id="run.MXQueryJS.classpath">
<pathelement location="${xqibtmp.dir}"/>
@@ -842,7 +843,7 @@
<path id="run.XQTS all.classpath">
<path refid="MXQueryJS.classpath"/>
- <path refid="GWT SDK [GWT (1) - 2.1.0].libraryclasspath"/>
+ <path refid="GWT SDK.libraryclasspath"/>
<pathelement location="${xqibjunit.dir}"/>
<!--<pathelement location="xqib_test"/>-->
<pathelement location="${xqibtmp.dir}"/>
Added: trunk/MXQuery/gwt-2.3.0/gwt-dev.jar
===================================================================
(Binary files differ)
Property changes on: trunk/MXQuery/gwt-2.3.0/gwt-dev.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/MXQuery/gwt-2.3.0/gwt-user.jar
===================================================================
(Binary files differ)
Property changes on: trunk/MXQuery/gwt-2.3.0/gwt-user.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: trunk/MXQuery/xqib_NOTICE
===================================================================
--- trunk/MXQuery/xqib_NOTICE 2011-05-06 22:35:11 UTC (rev 4324)
+++ trunk/MXQuery/xqib_NOTICE 2011-05-08 16:32:28 UTC (rev 4325)
@@ -13,4 +13,103 @@
- Apache Software Foundation (Java helper classes, Xerces)
- Robert Hanson (Regular Expressions from GWT widgets) for XQIB-JS
- GWT calendar project (time and calendar support) for XQIB-JS
+ - Validator.nu HTML Parser for XQIB-JS
+License for Validator.nu HTML Parser:
+
+This is for the HTML parser as a whole except the rewindable input stream,
+the named character classes and the Live DOM Viewer.
+For the copyright notices for individual files, please see individual files.
+
+/*
+ * Copyright (c) 2005, 2006, 2007 Henri Sivonen
+ * Copyright (c) 2007-2011 Mozilla Foundation
+ * Portions of comments Copyright 2004-2007 Apple Computer, Inc., Mozilla
+ * Foundation, and Opera Software ASA.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+The following license is for the WHATWG spec from which the named character
+data was extracted.
+
+/*
+ * Copyright 2004-2010 Apple Computer, Inc., Mozilla Foundation, and Opera
+ * Software ASA.
+ *
+ * You are granted a license to use, reproduce and create derivative works of
+ * this document.
+ */
+
+The following license is for the rewindable input stream.
+
+/*
+ * Copyright (c) 2001-2003 Thai Open Source Software Center Ltd
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of the Thai Open Source Software Center Ltd nor
+ * the names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+The following license applies to the Live DOM Viewer:
+
+Copyright (c) 2000, 2006, 2008 Ian Hickson and various contributors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
Added: trunk/MXQuery/xqib_samples/data/test.html
===================================================================
--- trunk/MXQuery/xqib_samples/data/test.html (rev 0)
+++ trunk/MXQuery/xqib_samples/data/test.html 2011-05-08 16:32:28 UTC (rev 4325)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset='utf-8'>
+<title>Test doc</title>
+</head>
+<body>
+<ul>
+<li>B</li>
+<li>A
+<ul>
+<li>3</li>
+<li>1</li>
+<li>2</li>
+</ul>
+</li>
+<li>C</li>
+</ul>
+</body>
+</html>
Added: trunk/MXQuery/xqib_samples/tidy.html
===================================================================
--- trunk/MXQuery/xqib_samples/tidy.html (rev 0)
+++ trunk/MXQuery/xqib_samples/tidy.html 2011-05-08 16:32:28 UTC (rev 4325)
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>XQIB: Sample page</title>
+ <meta charset="UTF-8"/>
+ <link href="style.css" rel="stylesheet" type="text/css">
+ <script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
+ <script type="application/xquery">
+ import module namespace http-client = "http://expath.org/ns/http-client";
+
+ declare updating function local:getWeather($loc, $evtObj) {
+ let $forecast := http-client:send-request(
+ <http-client:request href="data/test.html" method="get"/>
+ )[2]
+ return
+
+ insert node
+ <div>{$forecast//li/ul}</div>
+ as last into b:dom()//body,
+
+ delete node b:dom()//div
+ };
+
+
+ b:addEventListener(b:dom()//input[@name="button"], "onclick", xs:QName("local:getWeather"))
+
+ </script>
+ </head>
+ <body>
+ <a href="index.html"><< Index</a>
+ <h1>Weather forecast</h1>
+ <a href="WeatherREST.html">Page</a> | <a href="WeatherREST_source.html">Source</a>
+ <p/>
+ <input type="text" value="" style="font-size: 30pt; font-weight: bold" name="city"/>
+ <input type="button" value="Go!" style="font-size: 30pt; font-weight: bold" name="button"/>
+ <div><img src="JupiterZeus.gif"/></div>
+ </body>
+</html>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/MXQueryJS.gwt.xml
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/MXQueryJS.gwt.xml 2011-05-06 22:35:11 UTC (rev 4324)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/MXQueryJS.gwt.xml 2011-05-08 16:32:28 UTC (rev 4325)
@@ -14,7 +14,9 @@
<inherits name="ch.ethz.mxquery"/>
<inherits name="java"/>
-<inherits name="com.google.gwt.xml.XML" />
+ <inherits name="com.google.gwt.xml.XML" />
+<inherits name="nu.validator.htmlparser.HtmlParser" />
+ <!-- <inherits name="nu.validator.htmlparser.HtmlParser" /> -->
<!-- <set-property name="user.agent" value="ie6" /> -->
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-06 22:35:11 UTC (rev 4324)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-08 16:32:28 UTC (rev 4325)
@@ -15,31 +15,27 @@
package ch.ethz.mxquery.extensionsModules.expathhttp;
-import java.io.BufferedInputStream;
-import java.io.DataOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
+import java.util.Vector;
+import org.xml.sax.SAXException;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.IFrameElement;
+
+import nu.validator.htmlparser.gwt.HtmlParser;
+
import ch.ethz.mxqjs.client.Environment;
import ch.ethz.mxqjs.client.QnameAndArity;
-import ch.ethz.mxquery.util.Hashtable;
-import java.util.Vector;
-
import ch.ethz.mxquery.bindings.WindowFactory;
import ch.ethz.mxquery.contextConfig.CompilerOptions;
import ch.ethz.mxquery.contextConfig.Context;
import ch.ethz.mxquery.datamodel.Identifier;
import ch.ethz.mxquery.datamodel.IdentifierFactory;
-import ch.ethz.mxquery.datamodel.MXQueryBinary;
import ch.ethz.mxquery.datamodel.QName;
import ch.ethz.mxquery.datamodel.Source;
import ch.ethz.mxquery.datamodel.XQName;
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
-import ch.ethz.mxquery.datamodel.xdm.BinaryToken;
import ch.ethz.mxquery.datamodel.xdm.ElementToken;
import ch.ethz.mxquery.datamodel.xdm.NamedToken;
import ch.ethz.mxquery.datamodel.xdm.TextToken;
@@ -63,21 +59,18 @@
import ch.ethz.mxquery.query.PreparedStatement;
import ch.ethz.mxquery.query.XQCompiler;
import ch.ethz.mxquery.query.impl.CompilerImpl;
-import ch.ethz.mxquery.update.store.domImpl.NodeStore;
import ch.ethz.mxquery.util.Base64;
-import ch.ethz.mxquery.util.LineReader;
+import ch.ethz.mxquery.util.Hashtable;
import ch.ethz.mxquery.util.LogLevel;
import ch.ethz.mxquery.util.Logger;
-import ch.ethz.mxquery.util.StringReader;
-import ch.ethz.mxquery.util.browser.AsyncXmlHttpRequest;
import ch.ethz.mxquery.util.browser.AsyncXmlHttpRequestWrapper;
import ch.ethz.mxquery.util.browser.CachedDownloader;
-import ch.ethz.mxquery.util.browser.SyncXmlHttpRequest;
import ch.ethz.mxquery.util.browser.SyncXmlHttpRequestWrapper;
-import ch.ethz.mxquery.util.browser.XmlHttpRequest;
import ch.ethz.mxquery.util.browser.XmlHttpRequestWrappedHandler;
import ch.ethz.mxquery.util.browser.XmlHttpRequestWrapper;
-import ch.ethz.mxquery.xdmio.XDMInputFactory;
+import ch.ethz.mxquery.util.browser.dom.DOMImpl;
+import ch.ethz.mxquery.util.browser.dom.Document;
+import ch.ethz.mxquery.util.browser.dom.Node;
import ch.ethz.mxquery.xdmio.XDMSerializer;
import ch.ethz.mxquery.xdmio.XDMSerializerSettings;
@@ -761,19 +754,51 @@
// resIts[resIts.length - 1] = XDMInputFactory.createXMLInput(
// context, new StringReader(result.toString()), false,
// context.getInputValidationMode(), loc);
- } else if (contentType.indexOf("html") >= 0) {
- resIts[resIts.length - 1] = new TokenIterator(context,
- new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC,
- createNextTokenId(3), conn.responseAsString(),
- curNsScope), loc, false);
+ } else {
+ String responseString = conn.responseAsString();
+ if (contentType.indexOf("html") >= 0) {
+// resIts[resIts.length - 1] = new TokenIterator(context,
+// new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC,
+// createNextTokenId(3), conn.responseAsString(),
+// curNsScope), loc, false);
// TODO tidy input
+
+// IFrameElement iframe = com.google.gwt.dom.client.Document.get().createIFrameElement();
+// iframe.setInnerHTML( );
+
+
+
+// Document doc = DOMImpl.impl.getIFrameDocument(iframe);
+// doc.write(conn.responseAsString());
+ Document doc = Document.createDocument();
+// Element el = doc.getAsGwtDocument().getDocumentElement();
+// el.removeFromParent();
+// el = doc.getAsGwtDocument().getDocumentElement();
+ nu.validator.htmlparser.gwt.HtmlParser tidyparser = new HtmlParser(doc);
+ try {
+ tidyparser.parse(conn.responseAsString(), null);
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ resIts[resIts.length - 1] = new NodeStoreIterator(
+ doc);
+// Element el = doc.getAsGwtDocument().getDocumentElement();
+// int crap =0;
+
+// Element el = com.google.gwt.dom.client.Document.get().createDivElement();
+// el.setInnerHTML(responseString);
+// resIts[resIts.length - 1] = new NodeStoreIterator(
+// Node.createFromGwtNode(el));
// resIts[resIts.length - 1] = XDMInputFactory.createTidyInput(
// context, new StringReader(result.toString()), loc);
- } else if (contentType.startsWith("text/")
+ } else if (contentType.startsWith("text/")
|| contentType.equalsIgnoreCase("application/xml-dtd")) {
resIts[resIts.length - 1] = new TokenIterator(context,
new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC,
- createNextTokenId(3), conn.responseAsString(),
+ createNextTokenId(3), responseString,
curNsScope), loc, false);
// TODO
@@ -781,7 +806,7 @@
// new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC,
// createNextTokenId(3), result
// .toString(), curNsScope), loc, false);
- } else { // not identified => binary
+ } else { // not identified => binary
// TODO
// resIts[resIts.length - 1] = new TokenIterator(context,
// new BinaryToken(
@@ -789,6 +814,7 @@
// createNextTokenId(3),
// new MXQueryBinary(data, Type.BASE64_BINARY),
// curNsScope), loc, false);
+ }
}
}
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java 2011-05-06 22:35:11 UTC (rev 4324)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/DOMImpl.java 2011-05-08 16:32:28 UTC (rev 4325)
@@ -7,6 +7,7 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JsArray;
+import com.google.gwt.dom.client.IFrameElement;
import com.google.gwt.dom.client.InputElement;
import com.google.gwt.dom.client.TextAreaElement;
@@ -173,4 +174,13 @@
return document.createElementNS(nameSpaceURI, localName);
}-*/;
+ public native Document createDocument() /*-{
+ return $doc.implementation.createDocument('http://www.w3.org/1999/xhtml', '', null);
+}-*/;
+
+// public native Document getIFrameDocument(IFrameElement iframe) /*-{
+//// $wnd.ifr = iframe;
+// return iframe.contentDocument.document;
+//}-*/;
+
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Document.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Document.java 2011-05-06 22:35:11 UTC (rev 4324)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Document.java 2011-05-08 16:32:28 UTC (rev 4325)
@@ -1,5 +1,6 @@
package ch.ethz.mxquery.util.browser.dom;
+import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.Window;
public class Document extends Node{
@@ -25,4 +26,12 @@
public final native Node createComment(String value) /*-{
return this.createComment(value);
}-*/;
+
+ public static Document createDocument() {
+ return DOMImpl.impl.createDocument();
+ }
+
+ public final native void write(String str)/*-{
+ this.write(str);
+ }-*/;
}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Element.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Element.java 2011-05-06 22:35:11 UTC (rev 4324)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/dom/Element.java 2011-05-08 16:32:28 UTC (rev 4325)
@@ -10,6 +10,9 @@
}
+ public static Element createFromGwtNode(com.google.gwt.dom.client.Node n){
+ return (Element)(Object)n;
+ }
public final com.google.gwt.dom.client.Element getAsGwtElement() {
return (com.google.gwt.dom.client.Element)(Object)this;
Added: trunk/MXQuery/xqib_src/nu/validator/htmlparser/HtmlParser.gwt.xml
===================================================================
--- trunk/MXQuery/xqib_src/nu/validator/htmlparser/HtmlParser.gwt.xml (rev 0)
+++ trunk/MXQuery/xqib_src/nu/validator/htmlparser/HtmlParser.gwt.xml 2011-05-08 16:32:28 UTC (rev 4325)
@@ -0,0 +1,11 @@
+<module>
+ <inherits name="com.google.gwt.core.Core"/>
+ <inherits name="com.google.gwt.user.User"/>
+ <super-source path="translatable"/>
+ <source path="annotation"/>
+ <source path="common"/>
+ <source path="impl"/>
+ <source path="gwt"/>
+ <entry-point class="nu.validator.htmlparser.gwt.HtmlParserModule"/>
+ <add-linker name="sso"/>
+</module>
Added: trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/Auto.java
===================================================================
--- trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/Auto.java (rev 0)
+++ trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/Auto.java 2011-05-08 16:32:28 UTC (rev 4325)
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2010 Mozilla Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package nu.validator.htmlparser.annotation;
+
+public @interface Auto {
+
+}
Added: trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/CharacterName.java
===================================================================
--- trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/CharacterName.java (rev 0)
+++ trunk/MXQuery/xqib_src/nu/validator/htmlparser/annotation/CharacterName.java 2011-05-08 16:32:28 UTC (rev 4325)
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2010 Mozilla Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNE...
[truncated message content] |
|
From: <et...@us...> - 2011-05-09 13:52:42
|
Revision: 4327
http://mxquery.svn.sourceforge.net/mxquery/?rev=4327&view=rev
Author: etterth
Date: 2011-05-09 13:52:36 +0000 (Mon, 09 May 2011)
Log Message:
-----------
- fn:currenttime is now set in invokeModule
- added b:js-eval($script as xs:string)
Modified Paths:
--------------
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java
Added Paths:
-----------
trunk/MXQuery/xqib_samples/js-eval.html
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/JsEval.java
Added: trunk/MXQuery/xqib_samples/js-eval.html
===================================================================
--- trunk/MXQuery/xqib_samples/js-eval.html (rev 0)
+++ trunk/MXQuery/xqib_samples/js-eval.html 2011-05-09 13:52:36 UTC (rev 4327)
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>XQIB: Sample page</title>
+ <meta charset="UTF-8"/>
+ <link href="style.css" rel="stylesheet" type="text/css">
+ <script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
+ <script type="application/xquery">
+
+
+ b:js-eval('window.alert("eval!")')
+
+ </script>
+ </head>
+ <body>
+ <h1>timer</h1>
+
+ </body>
+</html>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-05-09 02:20:28 UTC (rev 4326)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-05-09 13:52:36 UTC (rev 4327)
@@ -186,6 +186,8 @@
}
int arity = subiterators.length;
Function function = functionname.context.getFunction(functionname.qname, arity);
+ //set currenttime
+ functionname.context.setCurrentTime(null);
XDMIterator func = function.getFunctionImplementation(new Context(functionname.context));
func.setSubIters(subiterators);
// func.setContext(getContext(), true);
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml 2011-05-09 02:20:28 UTC (rev 4326)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FG.xml 2011-05-09 13:52:36 UTC (rev 4327)
@@ -2,6 +2,21 @@
<functionGallery basePackage="ch.ethz.mxquery.functions.">
<functionGroup prefix="b" namespace="http://xqib.org">
<functionDescription>
+ <functionName>js-eval</functionName>
+ <parameters>
+ <paramType>xs:string</paramType>
+ </parameters>
+ <className>JsEval</className>
+ </functionDescription>
+ <functionDescription>
+ <functionName>timer</functionName>
+ <parameters>
+ <paramType>xs:integer</paramType>
+ <paramType>QName</paramType>
+ </parameters>
+ <className>Timer</className>
+ </functionDescription>
+ <functionDescription>
<functionName>getCookieNames</functionName>
<className>GetCookieNames</className>
</functionDescription>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java 2011-05-09 02:20:28 UTC (rev 4326)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java 2011-05-09 13:52:36 UTC (rev 4327)
@@ -453,6 +453,57 @@
qn = new QName(
"http://xqib.org",
"b",
+ "js-eval");
+ paramTypes = new TypeInfo[1];
+
+ paramTypes[0] = new TypeInfo(getType(
+ "xs:string",ctx),getOccur("xs:string"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.JsEval iter = new ch.ethz.mxquery.functions.b.JsEval();
+ iter.setContext(context, false);
+
+ type = -1;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "timer");
+ paramTypes = new TypeInfo[2];
+
+ paramTypes[0] = new TypeInfo(getType(
+ "xs:integer",ctx),getOccur("xs:integer"),null);
+
+ paramTypes[1] = new TypeInfo(getType(
+ "QName",ctx),getOccur("QName"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.Timer iter = new ch.ethz.mxquery.functions.b.Timer();
+ iter.setContext(context, false);
+
+ type = -1;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
"getCookieNames");
paramTypes = new TypeInfo[0];
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/JsEval.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/JsEval.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/b/JsEval.java 2011-05-09 13:52:36 UTC (rev 4327)
@@ -0,0 +1,40 @@
+package ch.ethz.mxquery.functions.b;
+
+import java.util.Vector;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.TypeException;
+import ch.ethz.mxquery.model.TokenBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class JsEval extends TokenBasedIterator {
+
+ @Override
+ protected void init() throws MXQueryException {
+ TokenInterface tok = subIters[0].next();
+ String script = tok.getValueAsString();
+ if (script == null){
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Invalid argument type", loc);
+ }
+ eval(script);
+ currentToken = Token.END_SEQUENCE_TOKEN;
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ JsEval copy = new JsEval();
+ copy.setSubIters(subIters);
+ copy.setContext(context, true);
+ return copy;
+ }
+
+ protected native void eval(String script)/*-{
+ eval(script);
+ }-*/;
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-05-09 22:45:27
|
Revision: 4330
http://mxquery.svn.sourceforge.net/mxquery/?rev=4330&view=rev
Author: etterth
Date: 2011-05-09 22:45:21 +0000 (Mon, 09 May 2011)
Log Message:
-----------
- Fixed IE9 XML bug (the IE8 functions were taken )
- Fixed asynchronous WeatherREST samples
Modified Paths:
--------------
trunk/MXQuery/xqib_samples/WeatherRESTasync.html
trunk/MXQuery/xqib_samples/WeatherRESTasyncSlow.html
trunk/MXQuery/xqib_samples/WeatherRESTasyncSlowCached.html
trunk/MXQuery/xqib_samples/WeatherRESTread.html
trunk/MXQuery/xqib_samples/timer.html
trunk/MXQuery/xqib_src/ch/ethz/mxquery.gwt.xml
Modified: trunk/MXQuery/xqib_samples/WeatherRESTasync.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherRESTasync.html 2011-05-09 21:46:10 UTC (rev 4329)
+++ trunk/MXQuery/xqib_samples/WeatherRESTasync.html 2011-05-09 22:45:21 UTC (rev 4330)
@@ -44,8 +44,8 @@
};
declare updating function local:getWeather($loc, $evtObj) {
- http-client:async-request(xs:QName('local:weatherResult'),
- <http-client:request href="forecast2.xml" method="get"/>
+ http-client:async-request(<http-client:request href="forecast2.xml" method="get"/>,
+ xs:QName('local:weatherResult')
)
};
Modified: trunk/MXQuery/xqib_samples/WeatherRESTasyncSlow.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherRESTasyncSlow.html 2011-05-09 21:46:10 UTC (rev 4329)
+++ trunk/MXQuery/xqib_samples/WeatherRESTasyncSlow.html 2011-05-09 22:45:21 UTC (rev 4330)
@@ -45,7 +45,7 @@
declare updating function local:getWeather($loc, $evtObj) {
(
- http-client:async-request(xs:QName('local:weatherResult'), <http-client:request href="http://n.ethz.ch/~etterth/slowserver.php?file=forecast2.xml" method="get"/>),
+ http-client:async-request( <http-client:request href="http://n.ethz.ch/~etterth/slowserver.php?file=forecast2.xml" method="get"/>, xs:QName('local:weatherResult')),
insert node
<div>Loading:
<img src="img/Loading_2_transparent.gif" />
Modified: trunk/MXQuery/xqib_samples/WeatherRESTasyncSlowCached.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherRESTasyncSlowCached.html 2011-05-09 21:46:10 UTC (rev 4329)
+++ trunk/MXQuery/xqib_samples/WeatherRESTasyncSlowCached.html 2011-05-09 22:45:21 UTC (rev 4330)
@@ -45,7 +45,7 @@
declare updating function local:getWeather($loc, $evtObj) {
(
- http-client:async-read(xs:QName('local:weatherResult'), "http://n.ethz.ch/~etterth/slowserver.php?file=forecast2.xml"),
+ http-client:async-read("http://n.ethz.ch/~etterth/slowserver.php?file=forecast2.xml",xs:QName('local:weatherResult')),
insert node
<div>Loading:
<img src="img/Loading_2_transparent.gif" />
Modified: trunk/MXQuery/xqib_samples/WeatherRESTread.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherRESTread.html 2011-05-09 21:46:10 UTC (rev 4329)
+++ trunk/MXQuery/xqib_samples/WeatherRESTread.html 2011-05-09 22:45:21 UTC (rev 4330)
@@ -44,8 +44,8 @@
};
declare updating function local:getWeather($loc, $evtObj) {
- http-client:async-read(xs:QName('local:weatherResult'),
- "forecast2.xml"
+ http-client:async-read("forecast2.xml",
+xs:QName('local:weatherResult')
)
};
Modified: trunk/MXQuery/xqib_samples/timer.html
===================================================================
--- trunk/MXQuery/xqib_samples/timer.html 2011-05-09 21:46:10 UTC (rev 4329)
+++ trunk/MXQuery/xqib_samples/timer.html 2011-05-09 22:45:21 UTC (rev 4330)
@@ -7,8 +7,8 @@
<script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
<script type="application/xquery">
declare updating function local:listener() {
+ b:timer(1000, xs:QName('local:listener')),
insert node <div>{fn:current-time()}</div> as last into b:dom()//body
-, b:timer(1000, xs:QName('local:listener'))
};
b:timer(1000, xs:QName('local:listener'))
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery.gwt.xml
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery.gwt.xml 2011-05-09 21:46:10 UTC (rev 4329)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery.gwt.xml 2011-05-09 22:45:21 UTC (rev 4330)
@@ -51,11 +51,11 @@
<when-property-is name="user.agent" value="opera" />
</replace-with>
- <replace-with class="ch.ethz.mxquery.util.browser.dom.DOMImplIE8">
+ <!-- <replace-with class="ch.ethz.mxquery.util.browser.dom.DOMImplIE8">
<when-type-is class="ch.ethz.mxquery.util.browser.dom.DOMImpl" />
<when-property-is name="user.agent" value="ie8" />
- </replace-with>
+ </replace-with> -->
<replace-with class="ch.ethz.mxquery.util.browser.dom.DOMImplIE">
<when-type-is class="ch.ethz.mxquery.util.browser.dom.DOMImpl" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-05-12 11:10:50
|
Revision: 4331
http://mxquery.svn.sourceforge.net/mxquery/?rev=4331&view=rev
Author: pm_fischer
Date: 2011-05-12 11:10:38 +0000 (Thu, 12 May 2011)
Log Message:
-----------
Merge HOF implementation
Modified Paths:
--------------
trunk/MXQuery/midp_src/ch/ethz/mxquery/query/webservice/WSDLHandler.java
trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/Type.java
trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/TypeInfo.java
trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/NamedToken.java
trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/QNameToken.java
trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/Token.java
trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/TokenInterface.java
trunk/MXQuery/src/ch/ethz/mxquery/exceptions/ErrorCodes.java
trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/FG.xml
trunk/MXQuery/src/ch/ethz/mxquery/functions/Function.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionGallery.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionSignature.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Abs.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DataValuesIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Deep_equal.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/FNString.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Node_Name.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Put.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/SubString.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/SubstringAfter.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/SubstringBefore.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Translate.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/UpperCase.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/SequenceTypeIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/UserdefFuncCall.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/UserdefFuncCallLateBinding.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/VariableIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/XMLContent.java
trunk/MXQuery/src/ch/ethz/mxquery/model/Iterator.java
trunk/MXQuery/src/ch/ethz/mxquery/model/XDMIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/SEParser.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/SchemaParser.java
trunk/MXQuery/src/ch/ethz/mxquery/query/webservice/WSDLGenerator.java
trunk/MXQuery/src/ch/ethz/mxquery/query/webservice/WSDLHandler.java
trunk/MXQuery/src/ch/ethz/mxquery/query/webservice/WSServer.java
trunk/MXQuery/src/ch/ethz/mxquery/sms/MMimpl/StreamStoreInput.java
trunk/MXQuery/src/ch/ethz/mxquery/sms/MMimpl/TokenBufferStore.java
trunk/MXQuery/src/examples/ExternalFunctionExample.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/Function.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/TypeTest.java
Added Paths:
-----------
trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/FunctionItemToken.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Function_arity.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Function_name.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/ClosureIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/FunctionItemWrapperIterator.java
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/query/webservice/WSDLHandler.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/query/webservice/WSDLHandler.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/query/webservice/WSDLHandler.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -201,7 +201,7 @@
params[i] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
}
FunctionSignature signature = new FunctionSignature(functionName,params,FunctionSignature.EXTERNAL_FUNCTION,XDMIterator.EXPR_CATEGORY_SEQUENTIAL,true,false);
- Function function = new Function(null,signature,wf,null,-1);
+ Function function = new Function(null,signature,wf,null,null);
context.addFunction(function, true, true);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/Type.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/Type.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/Type.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -44,6 +44,8 @@
public final static int ITEM = 0;
+ public final static int FUNCTION_ITEM = 1;
+
public final static int NODE = 2; // 0000000000000000000000000000010
/** Token types */
@@ -197,6 +199,9 @@
public static final int TYPE_NK_EMPTY_SEQ_TEST = 64;
/** occurrence indicators consts */
+
+ public final static int OCCURRENCE_IND_EMPTY = 0;
+
public final static int OCCURRENCE_IND_EXACTLY_ONE = 1;
public final static int OCCURRENCE_IND_ZERO_OR_ONE = 2;
@@ -625,7 +630,9 @@
case END_SEQUENCE:
q = new QName(null, "END_SEQUENCE");
break;
-
+ case FUNCTION_ITEM:
+ q = new QName(null, "function(*)");
+ break;
default:
throw new RuntimeException("Incorrect type passed. Type " + type + " is not supported in method getTypeQName");
}
@@ -1093,4 +1100,33 @@
public static boolean isNilled(int type) {
return ((type & MASK_CHECK_NILLABLE) == MASK_CHECK_NILLABLE);
}
+ /**
+ * Check if aocc is covered by bocc, as in XQ 3.0: 2.5.5.1 The SequenceType Subtype Judgement
+ * @param aocc Occurence indicator that needs to be checked
+ * @param bocc Occurence indicator that is provided
+ * @return true if aocc is contained by bocc, false otherwise
+ */
+ public static boolean isOccCompatible(int aocc, int bocc) {
+ if (aocc == bocc)
+ return true;
+ switch (bocc) {
+ case Type.OCCURRENCE_IND_EMPTY:
+ return false;
+ case Type.OCCURRENCE_IND_EXACTLY_ONE:
+ return false;
+ case Type.OCCURRENCE_IND_ZERO_OR_ONE:
+ if (aocc == Type.OCCURRENCE_IND_ZERO_OR_MORE || aocc==Type.OCCURRENCE_IND_ONE_OR_MORE)
+ return false;
+ else return true;
+ case Type.OCCURRENCE_IND_ZERO_OR_MORE:
+ return true;
+ case Type.OCCURRENCE_IND_ONE_OR_MORE:
+ if (aocc == Type.OCCURRENCE_IND_EXACTLY_ONE)
+ return true;
+ else return false;
+ }
+ // TODO: Infinite types
+ return true;
+ }
+
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/TypeInfo.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/TypeInfo.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/TypeInfo.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -31,6 +31,8 @@
private int occurID = UNDEFINED;
private XQName qn = null;
private int typeAnnotation =UNDEFINED;
+ private TypeInfo [] paramTypes = null;
+ private TypeInfo returnType=null;
private final static int MASK_GET_START_TAG = Integer.parseInt("0001100000000000000000000000000", 2);
private final static int MASK_CLEAN_START_TAG = Integer.parseInt("1110011111111111111111111111111", 2);
@@ -56,6 +58,14 @@
this.qn = name;
this.typeAnnotation = typeAn;
}
+
+ public TypeInfo(int type, int occurIndID, TypeInfo[] params,TypeInfo retType) {
+ this.type = type;
+ this.occurID = occurIndID;
+ this.paramTypes = params;
+ this.returnType = retType;
+ }
+
public int getTypeAnnotation() {
int t;
@@ -67,8 +77,9 @@
t = this.type & MASK_CLEAN_START_TAG;
}
- if (t == 0) return -1;
- else return t;
+ if (t == 0) return Type.ANY_TYPE;
+ else
+ return t;
//return typeAnnotation;
}
@@ -145,11 +156,21 @@
return (type == UNDEFINED);
}
+ public TypeInfo [] getParameterTypes() {
+ return paramTypes;
+ }
+
+ public TypeInfo getReturnType() {
+ return returnType;
+ }
+
public TypeInfo copy() {
if (typeAnnotation != UNDEFINED)
return new TypeInfo(type,occurID,qn,typeAnnotation);
+ else if (type ==Type.FUNCTION_ITEM)
+ return new TypeInfo(type, occurID, paramTypes, returnType);
else
- return new TypeInfo(type, occurID,qn);
+ return new TypeInfo(type, occurID,qn);
}
public String toString() {
Added: trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/FunctionItemToken.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/FunctionItemToken.java (rev 0)
+++ trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/FunctionItemToken.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -0,0 +1,54 @@
+package ch.ethz.mxquery.datamodel.xdm;
+
+import java.util.Enumeration;
+
+import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.functions.Function;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
+
+public class FunctionItemToken extends Token{
+ Function func;
+ Hashtable closure;
+ public FunctionItemToken(Function fun) {
+ super(Type.FUNCTION_ITEM,null,null);
+ func = fun;
+ }
+ public FunctionItemToken(Function fun, Hashtable closure) {
+ super(Type.FUNCTION_ITEM,null,null);
+ func = fun;
+ this.closure = closure;
+ }
+
+ public long getLong() {
+ return func.getFunctionSignature().getArity();
+ }
+ public QName getQNameTokenValue() {
+ return (QName)func.getFunctionSignature().getName();
+ }
+ public Function getFunction() {
+ return func;
+ }
+ public TokenInterface copy() {
+ return new FunctionItemToken(func,closure);
+ }
+ public QName [] getClosureVarNames() {
+ if (closure != null) {
+ QName [] res = new QName[closure.size()];
+ Enumeration varNames = closure.keys();
+ int i=0;
+ while (varNames.hasMoreElements())
+ res[i++] = (QName) varNames.nextElement();
+ return res;
+ } else return new QName[]{};
+ }
+
+ public XDMIterator getClosureValue(QName qn) {
+ return (XDMIterator) closure.get(qn);
+ }
+
+ public FunctionItemToken coerce(Function fun) {
+ return new FunctionItemToken(fun, closure);
+ }
+}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/NamedToken.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/NamedToken.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/NamedToken.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -32,8 +32,6 @@
public String [] getIDREFS();
- public String getPrefix();
-
public NamedToken copy(XQName newName) throws MXQueryException;
public NamedToken copyStrip();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/QNameToken.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/QNameToken.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/QNameToken.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -19,7 +19,7 @@
import ch.ethz.mxquery.datamodel.QName;
import ch.ethz.mxquery.datamodel.types.Type;
-public final class QNameToken extends Token {
+public class QNameToken extends Token {
private final QName value;
public QNameToken(Identifier id, QName value) {
@@ -29,25 +29,15 @@
public QNameToken(QNameToken token) {
super(token);
- this.value = token.getQName();
+ this.value = token.getQNameTokenValue();
}
-
- public QName getQName() {
- return this.value;
- }
-
-
+
/* (non-Javadoc)
* @see ch.ethz.mxquery.util.tokens.Token#getNS()
*/
public String getNS() {
return value.getNamespaceURI();
}
-
- public void setNS(String uri) {
- value.setNamespaceURI(uri);
- }
-
public QName getQNameTokenValue() {
return this.value;
Modified: trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/Token.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/Token.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/Token.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -153,6 +153,14 @@
}
/* (non-Javadoc)
+ * @see ch.ethz.mxquery.datamodel.xdm.TokenInterface#getLocal()
+ */
+ public String getPrefix() {
+ return null;
+ }
+
+
+ /* (non-Javadoc)
* @see ch.ethz.mxquery.datamodel.xdm.TokenInterface#setId(ch.ethz.mxquery.datamodel.Identifier)
*/
public void setNodeId(Identifier id) throws MXQueryException{
Modified: trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/TokenInterface.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/TokenInterface.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/TokenInterface.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -30,6 +30,8 @@
public abstract String getNS();
public abstract String getLocal();
+
+ public abstract String getPrefix();
/**
* Assigns a node ID to this node
* While tokens are meant to be immutable, we make an exception
Modified: trunk/MXQuery/src/ch/ethz/mxquery/exceptions/ErrorCodes.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/exceptions/ErrorCodes.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/exceptions/ErrorCodes.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -230,6 +230,9 @@
public final static QName F0033_REGULAR_EXPRESSION_MATCHES_EMPTY = new QName(XQStaticContext.URI_ERR,"err","FORX0003");
public final static QName F0034_INVALID_REPLACEMENT_STRING = new QName(XQStaticContext.URI_ERR,"err","FORX0004");
public final static QName F0035_AGUMENT_NOD_NO_TYPED_VALUE = new QName(XQStaticContext.URI_ERR,"err","FOTY0012");
+ public final static QName F0036_FUNCTION_ITEM_AT_FN_DATA = new QName(XQStaticContext.URI_ERR,"err","FOTY0013");
+ public final static QName F0037_FUNCTION_ITEM_AT_FN_STRING = new QName(XQStaticContext.URI_ERR,"err","FOTY0014");
+ public final static QName F0038_FUNCTION_ITEM_AT_DEEP_EQUAL = new QName(XQStaticContext.URI_ERR,"err","FOTY0015");
// Serializer error codes
public final static QName S0001_ATTRIBUTE_OR_NAMESPACE_NOT_ALLOWED_HERE = new QName(XQStaticContext.URI_ERR,"err","SENR0001");
Modified: trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -175,7 +175,7 @@
TypeInfo requestElement = new TypeInfo(Type.START_TAG, Type.OCCURRENCE_IND_EXACTLY_ONE,requestName);
- SequenceTypeIterator sq = new SequenceTypeIterator(requestElement, true, false, childContext, loc);
+ SequenceTypeIterator sq = new SequenceTypeIterator(requestElement, true, false, childContext, loc, false);
sq.setSubIters(subIters[0]);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/FG.xml
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/FG.xml 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/FG.xml 2011-05-12 11:10:38 UTC (rev 4331)
@@ -388,6 +388,20 @@
<className>Floor</className>
</functionDescription>
<functionDescription>
+ <functionName>function-name</functionName>
+ <parameters>
+ <paramType>function(*)</paramType>
+ </parameters>
+ <className>Function_name</className>
+ </functionDescription>
+ <functionDescription>
+ <functionName>function-arity</functionName>
+ <parameters>
+ <paramType>function(*)</paramType>
+ </parameters>
+ <className>Function_arity</className>
+ </functionDescription>
+ <functionDescription>
<functionName>generate-id</functionName>
<parameters>
<paramType>node()</paramType>
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/Function.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/Function.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/Function.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -19,6 +19,7 @@
import ch.ethz.mxquery.contextConfig.Context;
import ch.ethz.mxquery.datamodel.QName;
+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;
@@ -38,20 +39,20 @@
protected String className;
- protected FunctionSignature signature;
+ FunctionSignature signature;
protected XDMIterator iter;
- int returnType = -1;
+ TypeInfo returnType = null;
String operation = null;
public Function(String className, FunctionSignature signature,
- XDMIterator iter, String op, int dataType) {
+ XDMIterator iter, String op, TypeInfo retDataType) {
this.className = className;
this.iter = iter;
this.signature = signature;
this.operation = op;
- this.returnType = dataType;
+ this.returnType = retDataType;
if (iter != null)
return;
@@ -78,8 +79,8 @@
public Function getAsExternalFunction(String prefix) {
QName fName = new QName(signature.getName().getNamespaceURI(), prefix,
signature.getName().getLocalPart());
- FunctionSignature newSig = new FunctionSignature(fName, signature
- .getParameterTypes(), FunctionSignature.EXTERNAL_FUNCTION,
+ FunctionSignature newSig = new FunctionSignature(fName, signature.paramTypes
+ , FunctionSignature.EXTERNAL_FUNCTION,
signature.getExpressionCategory(), false, true);
Function func = new Function(className, newSig, iter, operation, returnType);
return func;
@@ -116,9 +117,8 @@
* Get the signature of this function
*
* @return a copy of the signature
- * @throws MXQueryException
*/
- public FunctionSignature getFunctionSignature() throws MXQueryException {
+ public FunctionSignature getFunctionSignature() {
if (signature != null) {
return signature.copy();
} else {
@@ -151,12 +151,12 @@
try {
XDMIterator function = (XDMIterator) (Class.forName(className)
.newInstance());
- if (operation != null || returnType != -1) {
+ if (operation != null || returnType != null) {
RequestTypeMulti mult = (RequestTypeMulti)function;
if (operation != null)
mult.setOperation(operation);
- if (returnType != -1)
- mult.setReturnType(returnType);
+ if (returnType != null)
+ mult.setReturnType(returnType.getType());
}
return function;
} catch (ClassNotFoundException e) {
@@ -182,4 +182,25 @@
null, false, nestedPredCtxStack), operation, returnType);
return func;
}
+
+
+ public TypeInfo getReturnType() throws MXQueryException {
+ if (returnType != null)
+ return returnType;
+ if (iter!=null)
+ return iter.getStaticType();
+ else {
+ XDMIterator it = loadClass();
+ return it.getStaticType();
+ }
+
+ }
+
+ public QName[] getClosure() {
+ if (iter!=null && iter instanceof UserdefFuncCall) {
+ UserdefFuncCall ud = (UserdefFuncCall)iter;
+ return ud.getClosure();
+ } else
+ return null;
+ }
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionGallery.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionGallery.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionGallery.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -122,16 +122,21 @@
public Function get(QName name, int arity) throws MXQueryException{
// fix for fn:contains - any arity > 2 possible
// TODO: refine to also include in the prefix/namespace
- if (name.getLocalPart().equals("concat") && arity > 2)
- arity = 2;
+ int localArity = arity;
+ if (name.getLocalPart().equals("concat") && name.getNamespaceURI().equals(Context.URI_FN)&& arity > 2)
+ localArity = 2;
// TODO: More elegant way. For now, create dummy signature with empty types
- TypeInfo [] typePlaceholder = new TypeInfo[arity];
+ TypeInfo [] typePlaceholder = new TypeInfo[localArity];
for (int i=0;i<typePlaceholder.length;i++) {
typePlaceholder[i] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
}
FunctionSignature signature = new FunctionSignature(name,typePlaceholder);
Function function = (Function)functions.get(signature);
if(function != null){
+ if (name.getLocalPart().equals("concat") &&
+ name.getNamespaceURI().equals(Context.URI_FN)&& arity > 2) {
+ function.signature.arity = arity;
+ }
return function;
}else{
return null;
@@ -233,7 +238,7 @@
xpp.require(XmlPullParser.START_TAG, null, "functionDescription");
xpp.nextTag();
String operation = null;
- int type = -1;
+ TypeInfo type = null;
while (!xpp.getName().equals("functionDescription") && xpp.getEventType() != XmlPullParser.END_TAG) {
String elementName = xpp.getName();
if (elementName.equals("functionName")) {
@@ -254,8 +259,9 @@
operation = xpp.getAttributeValue("", "op");
String rawType = xpp.getAttributeValue("", "type");
funcDesc[2] = xpp.nextText();
- if (rawType != null)
- type = getType(rawType,ctx);
+ if (rawType != null) {
+ type = new TypeInfo(getType(rawType,ctx),getOccur(rawType));
+ }
} else {
// element ignored
System.out.println("element ignored!");
@@ -303,9 +309,12 @@
}else if (rawType.equals("node()")){
return Type.NODE;
}else if (rawType.equals("element()")){
- return Type.ITEM;//TODO: fix it!
+ return Type.START_TAG;
+ }else if (rawType.startsWith("function(")){
+ return Type.FUNCTION_ITEM;
}else{
XQName qname = new QName(rawType);
+
if (qname.getNamespacePrefix()==null){
if (qname.getLocalPart().equals("numeric")){
qname = new QName(Context.URI_MXQ,Context.NS_MXQ,"number");
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionSignature.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionSignature.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionSignature.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -15,8 +15,10 @@
package ch.ethz.mxquery.functions;
+import ch.ethz.mxquery.contextConfig.XQStaticContext;
import ch.ethz.mxquery.datamodel.QName;
import ch.ethz.mxquery.datamodel.XQName;
+import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.model.XDMIterator;
@@ -32,6 +34,8 @@
TypeInfo [] paramTypes;
+ int arity = 0;
+
protected int type;
protected int expressionType;
@@ -59,6 +63,8 @@
expressionType = exprType;
nondet = nondeterministic;
privateScope = isPrivate;
+ if (this.paramTypes != null)
+ arity = paramTypes.length;
}
/**
* Checks the equality of Function Signatures.
@@ -80,7 +86,7 @@
* since the type of parameters is irrelevant
*/
public int hashCode() {
- return (qname.hashCode() << 3) | paramTypes.length;
+ return (qname.hashCode() << 3) | arity;
}
/**
* Returns the name of this function as qualified QName
@@ -94,20 +100,20 @@
* @return The number of parameters
*/
public int getArity() {
- if (paramTypes != null)
- return this.paramTypes.length;
- else
- return 0;
+ return arity;
}
/**
* Returns the type information for each of the parameters
* @return A type information for each parameter, an empty TypeInfo[] if no parameters in the function
*/
- public TypeInfo [] getParameterTypes() {
- if (paramTypes != null)
- return paramTypes;
+ public TypeInfo getParameterTypes(int pos) {
+ if (paramTypes != null && pos < paramTypes.length)
+ return paramTypes[pos];
else
- return new TypeInfo[]{};
+ if (qname.getLocalPart().equals("concat") && qname.getNamespaceURI().equals(XQStaticContext.URI_FN))
+ return new TypeInfo(Type.ANY_ATOMIC_TYPE,Type.OCCURRENCE_IND_ZERO_OR_ONE);
+ else
+ throw new RuntimeException("Trying to access an invalid parameter specification");
}
/**
* Get the type of function: built-in/system, user-defined, external
@@ -140,7 +146,12 @@
}
public FunctionSignature copy() {
- return new FunctionSignature(qname.copy(), paramTypes, type, expressionType, nondet, privateScope);
+ QName qn = null;
+ if (qname != null)
+ qn = qname.copy();
+ FunctionSignature fs = new FunctionSignature(qn, paramTypes, type, expressionType, nondet, privateScope);
+ fs.arity = arity;
+ return fs;
}
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -156,7 +156,7 @@
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);
+ 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, null);
ctx.addFunction(fn);
}
} catch (ClassNotFoundException e) {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Abs.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Abs.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Abs.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -96,7 +96,7 @@
}
double valU = Math.abs(db.getValue());
currentToken = new DoubleToken(null,new MXQueryDouble(valU));
-
+ break;
default:
throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Invalid argument type", loc);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DataValuesIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DataValuesIterator.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DataValuesIterator.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -31,6 +31,7 @@
import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.datamodel.xdm.UntypedAtomicToken;
import ch.ethz.mxquery.datamodel.xdm.XDMScope;
+import ch.ethz.mxquery.exceptions.DynamicException;
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
@@ -460,6 +461,8 @@
case Type.END_DOCUMENT:
level--;
break;
+ case Type.FUNCTION_ITEM:
+ throw new DynamicException(ErrorCodes.F0036_FUNCTION_ITEM_AT_FN_DATA, "Function Items do not have a typed value, thus cannot be atomized", loc);
case Type.END_SEQUENCE:
return new EmptySequenceIterator(context, loc);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Deep_equal.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Deep_equal.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Deep_equal.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -100,6 +100,9 @@
if (Type.isTextNode(t2Ev))
t2Ev = Type.getTextNodeValueType(t2Ev);
+ if (t1Ev == Type.FUNCTION_ITEM || t2Ev == Type.FUNCTION_ITEM)
+ throw new TypeException(ErrorCodes.F0038_FUNCTION_ITEM_AT_DEEP_EQUAL, "Function items not allow in fn:deep-equal()",loc);
+
if ((Type.isAtomicType(t1Ev, null)||t1Ev == Type.UNTYPED) && (Type.isAtomicType(t2Ev, null)||t2Ev == Type.UNTYPED)) {
try {
// TODO: support NaN
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/FNString.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/FNString.java 2011-05-09 22:45:21 UTC (rev 4330)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/FNString.java 2011-05-12 11:10:38 UTC (rev 4331)
@@ -21,6 +21,7 @@
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.datamodel.xdm.TextToken;
import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.DynamicException;
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.TypeException;
@@ -35,7 +36,15 @@
// fn:string always atomizes!
input = DataValuesIterator.getDataIterator(it,context);
StringBuffer res = new StringBuffer();
- TokenInterface tok = input.next();
+ TokenInterface tok;
+ try {
+ tok = input.next();
+ } catch (DynamicException de) {
+ if (de.getErrorCode().equals(ErrorCodes.F0036_FUNCTION_ITEM_AT_FN_DATA))
+ throw new Dy...
[truncated message content] |
|
From: <max...@us...> - 2011-05-13 18:16:54
|
Revision: 4335
http://mxquery.svn.sourceforge.net/mxquery/?rev=4335&view=rev
Author: maxspeicher
Date: 2011-05-13 18:16:48 +0000 (Fri, 13 May 2011)
Log Message:
-----------
- added java.lang.CharSequence to Java/XQuery type mapping
- added helper class (MXQuery.java) for passing the Android application context to the library
- changed IOLib.java to use Android-specific IO (not working yet)
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
Added Paths:
-----------
trunk/MXQuery/android/src/ch/ethz/mxquery/android/
trunk/MXQuery/android/src/ch/ethz/mxquery/android/MXQuery.java
trunk/MXQuery/android/src/ch/ethz/mxquery/util/
trunk/MXQuery/android/src/ch/ethz/mxquery/util/IOLib.java
Added: trunk/MXQuery/android/src/ch/ethz/mxquery/android/MXQuery.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/android/MXQuery.java (rev 0)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/android/MXQuery.java 2011-05-13 18:16:48 UTC (rev 4335)
@@ -0,0 +1,59 @@
+package ch.ethz.mxquery.android;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import android.app.Activity;
+import android.content.Context;
+import android.widget.Button;
+import android.widget.TextView;
+
+public class MXQuery {
+
+ private static Context ctx;
+ private static Activity act;
+
+ public static void init(Activity act) {
+ MXQuery.ctx = act.getApplicationContext();
+ MXQuery.act = act;
+ }
+
+ public static Context getContext() {
+ return ctx;
+ }
+
+ public static Activity getActivity() {
+ return act;
+ }
+
+ public static String doc(String fileName) {
+ String result = "";
+
+ try {
+ BufferedReader in = new BufferedReader(new InputStreamReader(
+ ctx.openFileInput(fileName)));
+ String line;
+
+ while ((line = in.readLine()) != null) {
+ result += line;
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+
+ public static Button getButton(int id) {
+ return (Button) act.findViewById(id);
+ }
+
+ public static TextView getTextView(int id) {
+ return (TextView) act.findViewById(id);
+ }
+
+}
Added: trunk/MXQuery/android/src/ch/ethz/mxquery/util/IOLib.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/util/IOLib.java (rev 0)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/util/IOLib.java 2011-05-13 18:16:48 UTC (rev 4335)
@@ -0,0 +1,263 @@
+/* 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.util;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+
+import android.content.Context;
+import ch.ethz.mxquery.android.MXQuery;
+import ch.ethz.mxquery.exceptions.DynamicException;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.QueryLocation;
+
+public class IOLib {
+
+ private static Context ctx = MXQuery.getContext();
+
+ public static void copyFile(String source, String destination) throws MXQueryException{
+ FileInputStream in = null;
+ FileOutputStream out = null;
+ try {
+ File src = new File(new URI(source));
+ File dst = new File(new URI(destination));
+ if (src.exists()) {
+ // create a copy of the file, possibly overwriting previous copies
+ in = new FileInputStream(src);
+ out = new FileOutputStream(dst, false);
+ byte[] buf = new byte[4096];
+ int len;
+ while ((len = in.read(buf)) > 0){
+ out.write(buf, 0, len);
+ }
+ }
+
+ } catch (IOException io) {
+ throw new DynamicException(ErrorCodes.A0007_EC_IO,"I/O Error copying file "+io.toString(),QueryLocation.OUTSIDE_QUERY_LOC);
+ } catch (URISyntaxException e) {
+ throw new DynamicException(ErrorCodes.A0007_EC_IO,"I/O Error copying file "+e.toString(),QueryLocation.OUTSIDE_QUERY_LOC);
+ }
+ finally {
+ if (in != null)
+ try {
+ in.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if (out != null)
+ try {
+ out.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Check the file encoding using a 8bit representation
+ * @param ins Input stream to check
+ * @param xquery snoop an xquery file, not an XML file
+ * @return Encoding String if detected, otherwise null
+ * @throws UnsupportedEncodingException
+ * @throws IOException
+ */
+
+ public static final String snoopEncoding8bit(InputStream ins, boolean xquery) throws UnsupportedEncodingException, IOException {
+ String encoding = null;
+ String typeToSearch = "?xml";
+ if (xquery)
+ typeToSearch = "xquery";
+
+ // Check all the encoding that are 8bit-oriented for the normal characters
+ InputStreamReader rs = new InputStreamReader(ins, "us-ascii");
+ char [] cbuf = new char[1025];
+ int bytes = rs.read(cbuf, 0, 1024);
+ if (bytes > 0 ) {
+ String startLine = new String(cbuf);
+ if (startLine.indexOf(typeToSearch) >= 0) {
+ int encodingPos;
+ if (!xquery) {
+ encodingPos = startLine.indexOf("encoding=\"");
+ if (encodingPos > 0) {
+ String tempEncoding = startLine.substring(encodingPos + 10);
+ int endEncoding = tempEncoding.indexOf('"');
+ encoding = tempEncoding.substring(0, endEncoding);
+ }
+ }
+ else {
+ int xqPos = startLine.indexOf("xquery");
+ if (xqPos >= 0 ) {
+ encodingPos = startLine.indexOf("encoding", xqPos+1);
+ if (encodingPos > 0) {
+ int sep = startLine.indexOf(";", encodingPos + 8);
+ if (sep > 0) {
+ String tempEncoding = startLine.substring(encodingPos + 8, sep);
+ char delim = '"';
+ int startDelim = tempEncoding.indexOf(delim);
+ int endDelim = tempEncoding.indexOf(delim,startDelim+1);
+ if (endDelim >=0 && endDelim > startDelim+1)
+ encoding = tempEncoding.substring(startDelim+1, endDelim);
+ }
+ }
+ }
+ }
+ }
+ }
+ return encoding;
+ }
+
+ /**
+ * Check the file encoding using a 16bit representation
+ * @param ins Input stream to check
+ * @param xquery TODO
+ * @return Encoding String if detected, otherwise null
+ * @throws UnsupportedEncodingException
+ * @throws IOException
+ */
+
+ public static final String snoopEncoding16bit(InputStream ins, boolean xquery) throws UnsupportedEncodingException, IOException {
+
+ String encoding = null;
+ String typeToSearch = "?xml";
+ if (xquery)
+ typeToSearch = "xquery";
+
+ InputStreamReader rs = new InputStreamReader(ins, "utf-16");
+ char [] cbuf = new char[1025];
+ int bytes = rs.read(cbuf, 0, 1024);
+ if (bytes > 0 ) {
+ String startLine = new String(cbuf);
+ if (startLine.indexOf(typeToSearch) >= 0) {
+ encoding = "utf-16";
+ }
+ }
+ return encoding;
+ }
+
+ public static Reader getInput (String toOpen, boolean xquery, QueryLocation loc) throws MXQueryException {
+ String encoding = "utf-8";
+ InputStream ins = null;
+ URI uri;
+ try {
+ uri = new URI(toOpen);
+ } catch (URISyntaxException e) {
+ throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC, "Invalid URI given to fn:doc", loc);
+ }
+ if (uri.isAbsolute()) {
+ try {
+ URL url = uri.toURL();
+ URLConnection conn = url.openConnection();
+ conn.setRequestProperty("User-Agent", "MXQuery");
+ ins = conn.getInputStream();
+ // try to use content-type specific
+ String contentType = conn.getContentType();
+ int encPos = contentType.indexOf("charset=");
+ if (encPos > 0)
+ encoding = contentType.substring(encPos+8); //lenght of "charset="
+ //encoding = "iso-8859-1";
+ BufferedInputStream bufs = new BufferedInputStream(ins);
+ bufs.mark(16384);
+ String tempEncoding = IOLib.snoopEncoding8bit(bufs, xquery);
+ if (tempEncoding != null) {
+ encoding = tempEncoding;
+ } else {
+ bufs.reset();
+ bufs.mark(16384);
+ tempEncoding = IOLib.snoopEncoding16bit(bufs, xquery);
+ if (tempEncoding != null) {
+ encoding = tempEncoding;
+ }
+ }
+ bufs.reset();
+ return new BufferedReader(new UnicodeReader(bufs, encoding));
+ } catch (IOException e) {
+ throw new DynamicException(ErrorCodes.F0014_ERROR_RETRIEVING_RESOURCE, "I/O Error - Remote Data cannot be accessed: " + e, loc);
+ }
+ } else {
+ try {
+ ins = ctx.openFileInput(toOpen);
+
+ // snoop encoding
+ encoding = "utf-8";
+ String tempEncoding = IOLib.snoopEncoding8bit(ins, xquery);
+ if (tempEncoding != null) {
+ encoding = tempEncoding;
+ } else {
+ ins.close();
+ ins = ctx.openFileInput(toOpen);
+ tempEncoding = IOLib.snoopEncoding16bit(ins, xquery);
+ if (tempEncoding != null) {
+ encoding = tempEncoding;
+ }
+ }
+ ins.close();
+ ins = ctx.openFileInput(toOpen);
+ return new BufferedReader(new UnicodeReader(ins, encoding));
+ } catch (FileNotFoundException e1) {
+ throw new DynamicException(ErrorCodes.F0014_ERROR_RETRIEVING_RESOURCE, "File '" + uri + "' does not exist!", loc);
+ } catch (UnsupportedEncodingException e) {
+ try {
+ ins.close();
+ } catch (IOException ie) {
+ //
+ }
+ throw new DynamicException(ErrorCodes.A0007_EC_IO, "Unsupported encoding '" + encoding + "' in File '" + uri, loc);
+ } catch (Exception e) {
+ try {
+ if (ins != null)
+ ins.close();
+ } catch (IOException ie) {
+ //
+ }
+ throw new DynamicException(ErrorCodes.F0014_ERROR_RETRIEVING_RESOURCE, "File '" + uri + "' could not be openend " + e.toString(), loc);
+ }
+ }
+ }
+
+ public static PrintStream getOutput(String url, boolean append, String encoding) throws IOException, MXQueryException {
+ URI uri = null;
+ try {
+ uri = new URI(url);
+ } catch (URISyntaxException e) {
+ throw new DynamicException(ErrorCodes.A0007_EC_IO,"Error Creating output file - invalid file name/URI: "+url,QueryLocation.OUTSIDE_QUERY_LOC);
+ }
+ OutputStream outw = new FileOutputStream(new File(uri), append);
+ return new PrintStream(outw,false,encoding);
+ }
+
+ public static String getSystemBaseUri() {
+ String curDir = System.getProperty("user.dir");
+ File fl = new File(curDir);
+ return fl.toURI().toString();
+ }
+}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-12 16:21:56 UTC (rev 4334)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-13 18:16:48 UTC (rev 4335)
@@ -1,6 +1,7 @@
package ch.ethz.mxquery.functions;
import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashMap;
@@ -73,6 +74,7 @@
public static Context getNativeMethods(String className) throws MXQueryException{
Context ctx = new Context();
+
try {
Class toImport = Class.forName(className);
@@ -151,6 +153,29 @@
}
}
+
+ Field [] fields = toImport.getFields();
+
+ for (int i=0;i<fields.length;i++) {
+ Field cur = fields[i];
+ int mod = cur.getModifiers();
+ if (Modifier.isPublic(mod)) {
+ String name = cur.getName();
+ TypeInfo[] params;
+ if (Modifier.isStatic(mod)) {
+ params = new TypeInfo[0];
+ }
+ else {
+ params = new TypeInfo[1];
+ params[0] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ }
+ TypeInfo resultType = getXQueryType(cur.getType());
+ MethodData md = new MethodData(toImport, name, params, resultType);
+ if (!functions.containsKey(md))
+ functions.put(md,md);
+ }
+ }
+
java.util.Iterator allFuncts = functions.values().iterator();
while (allFuncts.hasNext()) {
MethodData md = (MethodData)allFuncts.next();
@@ -181,7 +206,9 @@
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);
+ return new TypeInfo(Type.STRING,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ if (class1.getName().equals("java.lang.CharSequence"))
+ 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"))
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-05-12 16:21:56 UTC (rev 4334)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-05-13 18:16:48 UTC (rev 4335)
@@ -15,6 +15,7 @@
package ch.ethz.mxquery.iterators;
import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Vector;
@@ -54,7 +55,6 @@
this.native_function = function;
this.resultSeqTypeIt = returnSeqTypeIt;
//this.paramNames = paramNames;
- this.native_function = function;
this.methodName = methodName;
this.returnType = returnType;
this.paramTypes = paramTypes;
@@ -114,14 +114,20 @@
try {
Method meth = null;
+ Field field = null;
Object res;
if (methodName.equals("new")) {
Constructor con = native_function.getConstructor(invocationParamsTypes);
res = con.newInstance(invocationParams);
}
else {
- meth = native_function.getMethod(methodName, invocationParamsTypes);
- res = meth.invoke(instanceToCall, invocationParams);
+ try {
+ meth = native_function.getMethod(methodName, invocationParamsTypes);
+ res = meth.invoke(instanceToCall, invocationParams);
+ } catch (NoSuchMethodException e) {
+ field = native_function.getField(methodName);
+ res = field.get(instanceToCall);
+ }
}
try {
@@ -135,22 +141,18 @@
this.current = new TokenIterator(context, wrap, loc, false);
}
} catch (SecurityException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
+ } catch (NoSuchFieldException e) {
+ 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 was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-05-14 13:30:06
|
Revision: 4338
http://mxquery.svn.sourceforge.net/mxquery/?rev=4338&view=rev
Author: pm_fischer
Date: 2011-05-14 13:29:59 +0000 (Sat, 14 May 2011)
Log Message:
-----------
do not use complete subtype substitution in native function calls,
extend with Integer and byte types
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/JavaImportTests.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-05-13 21:42:26 UTC (rev 4337)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-05-14 13:29:59 UTC (rev 4338)
@@ -29,7 +29,6 @@
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.EmptySequenceIterator;
import ch.ethz.mxquery.model.Iterator;
@@ -77,12 +76,21 @@
// 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());
+ int type = tok.getEventType();//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.INTEGER:
+ case Type.INT:
+ invocationParams[i] = new Integer((int)tok.getLong());
+ invocationParamsTypes[i] = Integer.TYPE;
+ break;
+ case Type.BYTE:
+ invocationParams[i] = new Byte((byte)tok.getLong());
+ invocationParamsTypes[i] = Byte.TYPE;
+ break;
case Type.STRING:
case Type.ANY_URI:
invocationParams[i] = new String(tok.getText());
Modified: trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/JavaImportTests.java
===================================================================
--- trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/JavaImportTests.java 2011-05-13 21:42:26 UTC (rev 4337)
+++ trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/JavaImportTests.java 2011-05-14 13:29:59 UTC (rev 4338)
@@ -46,5 +46,17 @@
assertEquals("false", resultBuffer.toString().trim() );
};
+ public void test_int_arg() throws Exception{
+ String query = "declare namespace jint ='java:java.lang.Integer'; jint:bitCount(42)";
+ doQuery(prepareQuery(query, false,false, false, false, false));
+ System.out.println(resultBuffer.toString());
+ assertEquals("3", resultBuffer.toString().trim() );
+ };
+ public void test_byte_arg() throws Exception{
+ String query = "declare namespace jint ='java:java.lang.Byte'; jint:toString(xs:byte(42))";
+ doQuery(prepareQuery(query, false,false, false, false, false));
+ System.out.println(resultBuffer.toString());
+ assertEquals("42", resultBuffer.toString().trim() );
+ };
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-05-14 15:31:41
|
Revision: 4340
http://mxquery.svn.sourceforge.net/mxquery/?rev=4340&view=rev
Author: pm_fischer
Date: 2011-05-14 15:31:32 +0000 (Sat, 14 May 2011)
Log Message:
-----------
Merge branch 'XQ3.0-functions'
Modified Paths:
--------------
trunk/MXQuery/build.xml
trunk/MXQuery/midp_src/ch/ethz/mxquery/util/IOLib.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/XDMInputFactory.java
trunk/MXQuery/src/ch/ethz/mxquery/cmdline/MXQuery.java
trunk/MXQuery/src/ch/ethz/mxquery/datamodel/MXQueryDouble.java
trunk/MXQuery/src/ch/ethz/mxquery/exceptions/MXQueryException.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/FG.xml
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DataValuesIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Doc.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DocumentUri.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Node_Name.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/SubSequenceIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/math/TransMath.java
trunk/MXQuery/src/ch/ethz/mxquery/model/Iterator.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
trunk/MXQuery/src/ch/ethz/mxquery/util/FileReader.java
trunk/MXQuery/src/ch/ethz/mxquery/util/IOLib.java
trunk/MXQuery_Testing/XQTests/Queries/inserttest.xml
trunk/MXQuery_Testing/XQTests/Sources/doc.xml
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/XQ11FunctionsTest.java
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/scripting/ScriptingUseCases.java
trunk/MXQuery_Testing/src/ch/ethz/mxquery/testsuite/TestSuite.java
trunk/MXQuery_Testing/src/ch/ethz/mxquery/testsuite/internal/DictionaryBasedStemmer.java
Added Paths:
-----------
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/AvailEnvVars.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EnvVar.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Head.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Tail.java
trunk/MXQuery_Testing/XQTests/Sources/iso.txt
Modified: trunk/MXQuery/build.xml
===================================================================
--- trunk/MXQuery/build.xml 2011-05-14 13:30:29 UTC (rev 4339)
+++ trunk/MXQuery/build.xml 2011-05-14 15:31:32 UTC (rev 4340)
@@ -184,7 +184,7 @@
<delete file="${customtmp.dir}/ch/ethz/mxquery/sms/activeStore/ReadDataThread.java" />
<delete file="${customtmp.dir}/ch/ethz/mxquery/functions/fn/NormalizeUnicode.java" />
-
+ <delete file="${customtmp.dir}/ch/ethz/mxquery/functions/fn/AvailEnvVars.java"/>
<delete file="${customtmp.dir}/ch/ethz/mxquery/iterators/PFFLWORIterator.java" />
<delete file="${customtmp.dir}/ch/ethz/mxquery/iterators/PGFLWORIterator.java"/>
<delete file="${customtmp.dir}/ch/ethz/mxquery/iterators/PGroupBy.java"/>
@@ -444,6 +444,8 @@
<delete file="${midptmp.dir}/ch/ethz/mxquery/functions/fn/Round.java"/>
<delete file="${midptmp.dir}/ch/ethz/mxquery/functions/fn/Put.java"/>
<delete file="${midptmp.dir}/ch/ethz/mxquery/functions/fn/Matches.java"/>
+ <delete file="${midptmp.dir}/ch/ethz/mxquery/functions/fn/AvailEnvVars.java"/>
+ <delete file="${midptmp.dir}/ch/ethz/mxquery/functions/fn/EnvVar.java"/>
<delete file="${midptmp.dir}/ch/ethz/mxquery/functions/fn/IRItoURI.java"/>
<delete file="${midptmp.dir}/ch/ethz/mxquery/functions/fn/DocAvailable.java"/>
<delete file="${midptmp.dir}/ch/ethz/mxquery/functions/fn/NormalizeUnicode.java"/>
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/util/IOLib.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/util/IOLib.java 2011-05-14 13:30:29 UTC (rev 4339)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/util/IOLib.java 2011-05-14 15:31:32 UTC (rev 4340)
@@ -137,15 +137,16 @@
return encoding;
}
- public static Reader getInput (String uri, boolean xquery, QueryLocation loc) throws MXQueryException {
- String encoding = "utf-8";
+ public static Reader getInput (String uri, boolean xquery, String encoding, QueryLocation loc) throws MXQueryException {
+ if (encoding == null)
+ encoding = "utf-8";
InputStream ins = null;
try {
ins = Connector.openInputStream(uri);
- encoding = "iso-8859-1";
+ //encoding = "iso-8859-1";
String tempEncoding = IOLib.snoopEncoding8bit(ins, xquery);
if (tempEncoding != null) {
encoding = tempEncoding;
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/XDMInputFactory.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/XDMInputFactory.java 2011-05-14 13:30:29 UTC (rev 4339)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/xdmio/XDMInputFactory.java 2011-05-14 15:31:32 UTC (rev 4340)
@@ -49,7 +49,7 @@
public static XMLSource createXMLInput(Context ctx, String uri, boolean doc, int valMode, QueryLocation location) throws MXQueryException {
if (valMode == Context.NO_VALIDATION || valMode == Context.IGNORE_DTD)
- return new XPPImportAdapter(ctx,IOLib.getInput(uri, false, location),doc,location);
+ return new XPPImportAdapter(ctx,IOLib.getInput(uri, false, null,location),doc,location);
else {
throw new MXQueryException(ErrorCodes.A0002_EC_NOT_SUPPORTED,"XML Input validation not supported on CLDC",location);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/cmdline/MXQuery.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/cmdline/MXQuery.java 2011-05-14 13:30:29 UTC (rev 4339)
+++ trunk/MXQuery/src/ch/ethz/mxquery/cmdline/MXQuery.java 2011-05-14 15:31:32 UTC (rev 4340)
@@ -536,7 +536,7 @@
throw new Exception(errorMsg+compString[j]);
QName varName = getVar(ctx, argValPair);
String uri = URIUtils.resolveURI(ctx.getBaseURI(),argValPair[1],QueryLocation.OUTSIDE_QUERY_LOC);
- Reader rd = IOLib.getInput(uri, false, QueryLocation.OUTSIDE_QUERY_LOC);
+ Reader rd = IOLib.getInput(uri, false, null, QueryLocation.OUTSIDE_QUERY_LOC);
VariableHolder vh = ctx.getVariable(varName);
XDMIterator xmlIt;
if (vh != null && vh.getType() != null && Type.isAtomicType(vh.getType().getType(),Context.getDictionary())) {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/datamodel/MXQueryDouble.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/datamodel/MXQueryDouble.java 2011-05-14 13:30:29 UTC (rev 4339)
+++ trunk/MXQuery/src/ch/ethz/mxquery/datamodel/MXQueryDouble.java 2011-05-14 15:31:32 UTC (rev 4340)
@@ -108,6 +108,8 @@
public MXQueryDouble(double d) {
val = d;
+ if ((new Float(d)).equals(new Float(-0.0)))
+ negativeZero = true;
}
/** Methods: */
Modified: trunk/MXQuery/src/ch/ethz/mxquery/exceptions/MXQueryException.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/exceptions/MXQueryException.java 2011-05-14 13:30:29 UTC (rev 4339)
+++ trunk/MXQuery/src/ch/ethz/mxquery/exceptions/MXQueryException.java 2011-05-14 15:31:32 UTC (rev 4340)
@@ -93,7 +93,7 @@
if (loc.getFile()!=null) {
str.append("Error was not caused in main query module, but in the imported query module ").append(loc.getFile()).append("\n");
try {
- query = FileReader.getContents(IOLib.getInput(loc.getFile(), true, QueryLocation.OUTSIDE_QUERY_LOC));
+ query = FileReader.getContents(IOLib.getInput(loc.getFile(), true, null, QueryLocation.OUTSIDE_QUERY_LOC));
} catch (MXQueryException e) {
str.append("Could not retrieve module contents, bailing out");
return str.toString();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/FG.xml
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/FG.xml 2011-05-14 13:30:29 UTC (rev 4339)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/FG.xml 2011-05-14 15:31:32 UTC (rev 4340)
@@ -62,6 +62,11 @@
<className type="xs:time">DateTimeAdjustTimezone</className>
</functionDescription>
<functionDescription>
+ <functionName>available-environment-variables</functionName>
+ <parameters/>
+ <className>AvailEnvVars</className>
+ </functionDescription>
+ <functionDescription>
<functionName>avg</functionName>
<parameters>
<paramType>xs:anyAtomicType*</paramType>
@@ -185,6 +190,11 @@
<parameters> </parameters>
<className>CurrentTime</className>
</functionDescription>
+ <functionDescription>
+ <functionName>data</functionName>
+ <parameters/>
+ <className>DataValuesIterator</className>
+ </functionDescription>
<functionDescription>
<functionName>data</functionName>
<parameters>
@@ -272,6 +282,11 @@
</parameters>
<className>DocAvailable</className>
</functionDescription>
+ <functionDescription>
+ <functionName>document-uri</functionName>
+ <parameters/>
+ <className>DocumentUri</className>
+ </functionDescription>
<functionDescription>
<functionName>document-uri</functionName>
<parameters>
@@ -326,6 +341,13 @@
<className>EndsWith</className>
</functionDescription>
<functionDescription>
+ <functionName>environment-variable</functionName>
+ <parameters>
+ <paramType>xs:string</paramType>
+ </parameters>
+ <className>EnvVar</className>
+ </functionDescription>
+ <functionDescription>
<functionName>error</functionName>
<parameters>
<paramType>xs:QName?</paramType>
@@ -414,6 +436,13 @@
<className>GenerateId</className>
</functionDescription>
<functionDescription>
+ <functionName>head</functionName>
+ <parameters>
+ <paramType>item()?</paramType>
+ </parameters>
+ <className>Head</className>
+ </functionDescription>
+ <functionDescription>
<functionName>hours-from-dateTime</functionName>
<parameters>
<paramType>xs:dateTime?</paramType>
@@ -692,6 +721,11 @@
</functionDescription>
<functionDescription>
<functionName>node-name</functionName>
+ <parameters/>
+ <className>Node_Name</className>
+ </functionDescription>
+ <functionDescription>
+ <functionName>node-name</functionName>
<parameters>
<paramType>node()?</paramType>
</parameters>
@@ -751,14 +785,14 @@
<className>One_or_more</className>
</functionDescription>
<functionDescription>
- <functionName>parse</functionName>
+ <functionName>parse-xml</functionName>
<parameters>
<paramType>string</paramType>
</parameters>
<className>Parse</className>
</functionDescription>
<functionDescription>
- <functionName>parse</functionName>
+ <functionName>parse-xml</functionName>
<parameters>
<paramType>string</paramType>
<paramType>string</paramType>
@@ -1081,6 +1115,13 @@
</parameters>
<className>Sum</className>
</functionDescription>
+ <functionDescription>
+ <functionName>tail</functionName>
+ <parameters>
+ <paramType>item()*</paramType>
+ </parameters>
+ <className>Tail</className>
+ </functionDescription>
<functionDescription>
<functionName>timezone-from-date</functionName>
<parameters>
@@ -1149,6 +1190,44 @@
<className>Unordered</className>
</functionDescription>
<functionDescription>
+ <functionName>unparsed-text</functionName>
+ <parameters>
+ <paramType>xs:string?</paramType>
+ </parameters>
+ <className op="unparsed-text">Doc</className>
+ </functionDescription>
+ <functionDescription>
+ <functionName>unparsed-text</functionName>
+ <parameters>
+ <paramType>xs:string?</paramType>
+ <paramType>xs:string</paramType>
+ </parameters>
+ <className op="unparsed-text">Doc</className>
+ </functionDescription>
+ <functionDescription>
+ <functionName>unparsed-text-lines</functionName>
+ <parameters>
+ <paramType>xs:string?</paramType>
+ </parameters>
+ <className op="unparsed-text-lines">Doc</className>
+ </functionDescription>
+ <functionDescription>
+ <functionName>unparsed-text-lines</functionName>
+ <parameters>
+ <paramType>xs:string?</paramType>
+ <paramType>xs:string</paramType>
+ </parameters>
+ <className op="unparsed-text-lines">Doc</className>
+ </functionDescription>
+ <functionDescription>
+ <functionName>unparsed-text-available</functionName>
+ <parameters>
+ <paramType>xs:string?</paramType>
+ </parameters>
+ <className>DocAvailable</className>
+ </functionDescription>
+
+ <functionDescription>
<functionName>upper-case</functionName>
<parameters>
<paramType>xs:string?</paramType>
@@ -1512,7 +1591,8 @@
<functionDescription>
<functionName>atan2</functionName>
<parameters>
- <paramType>xs:double?</paramType>
+ <paramType>xs:double</paramType>
+ <paramType>xs:double</paramType>
</parameters>
<className op="atan2">TransMath</className>
</functionDescription>
@@ -1635,4 +1715,4 @@
<className>SubFiles2</className>
</functionDescription>
</functionGroup>
-</functionGallery>
\ No newline at end of file
+</functionGallery>
Added: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/AvailEnvVars.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/AvailEnvVars.java (rev 0)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/AvailEnvVars.java 2011-05-14 15:31:32 UTC (rev 4340)
@@ -0,0 +1,38 @@
+package ch.ethz.mxquery.functions.fn;
+
+import java.util.Vector;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.xdm.TextToken;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.model.CurrentBasedIterator;
+import ch.ethz.mxquery.model.TokenSequenceIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class AvailEnvVars extends CurrentBasedIterator {
+
+ public TokenInterface next() throws MXQueryException {
+ if (called == 0) {
+ called++;
+ Vector vars = new Vector();
+ java.util.Iterator envVars = System.getenv().keySet().iterator();
+ // create a snapshot of the environment variables
+ while (envVars.hasNext()) {
+ TokenInterface tok = new TextToken(null,(String)envVars.next());
+ vars.add(tok);
+ }
+ current = new TokenSequenceIterator(vars);
+ }
+ return current.next();
+ }
+
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ AvailEnvVars copy = new AvailEnvVars();
+ copy.setContext(context, true);
+ copy.setSubIters(subIters);
+ return copy;
+ }
+
+}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DataValuesIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DataValuesIterator.java 2011-05-14 13:30:29 UTC (rev 4339)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DataValuesIterator.java 2011-05-14 15:31:32 UTC (rev 4340)
@@ -64,9 +64,6 @@
DataValuesIterator(Context ctx, XDMIterator iter, QueryLocation location) {
super(ctx, location);
- if (iter == null) {
- throw new IllegalArgumentException();
- }
this.subIters = new XDMIterator[] { iter };
}
@@ -74,10 +71,8 @@
super(null, location);
this.fnData = true;
- if (iter == null) {
- throw new IllegalArgumentException();
- }
- this.subIters = new XDMIterator[] { iter };
+ if (iter != null)
+ this.subIters = new XDMIterator[] { iter };
}
public DataValuesIterator() {
@@ -89,7 +84,7 @@
if (!evalComplete) {
if (!(current instanceof SequenceIterator))
- current = getValue(subIters[0]);
+ current = getValue(getNodeIteratorOrContext(subIters, 1,context, loc));
TokenInterface e = current.next();
if (e.getEventType() == Type.END_SEQUENCE) {
evalComplete = true;
@@ -740,7 +735,11 @@
protected XDMIterator copy(Context context, XDMIterator[] subIters,
Vector nestedPredCtxStack) throws MXQueryException {
- XDMIterator copy = new DataValuesIterator(subIters[0], loc);
+ XDMIterator copy ;
+ if (subIters != null && subIters.length > 0)
+ copy = new DataValuesIterator(subIters[0], loc);
+ else
+ copy = new DataValuesIterator(null,loc);
copy.setContext(context, false);
return copy;
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Doc.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Doc.java 2011-05-14 13:30:29 UTC (rev 4339)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Doc.java 2011-05-14 15:31:32 UTC (rev 4340)
@@ -22,17 +22,20 @@
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.TextToken;
import ch.ethz.mxquery.datamodel.xdm.Token;
import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.DynamicException;
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.functions.RequestTypeMulti;
+import ch.ethz.mxquery.iterators.TokenIterator;
import ch.ethz.mxquery.model.CurrentBasedIterator;
import ch.ethz.mxquery.model.EmptySequenceIterator;
+import ch.ethz.mxquery.model.TokenSequenceIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.IOLib;
+import ch.ethz.mxquery.util.LineReader;
import ch.ethz.mxquery.util.URIUtils;
import ch.ethz.mxquery.xdmio.XDMInputFactory;
import ch.ethz.mxquery.xdmio.XMLSource;
@@ -43,8 +46,12 @@
*
*/
public class Doc extends CurrentBasedIterator implements RequestTypeMulti{
- private boolean inValidateExpression = false;
- private boolean tidyInput = false;
+ private final int OPERATION_DOC = 0;
+ private final int OPERATION_TIDY =1;
+ private final int OPERATION_UNPARSED=2;
+ private final int OPERATION_UNPARSED_LINES=3;
+private boolean inValidateExpression = false;
+ private int operation = OPERATION_DOC;
private String docURI = null;
private Reader rd = null; // keep around to close
@@ -60,10 +67,6 @@
public void setInValidateExpression(boolean inValidateExpression) {
this.inValidateExpression = inValidateExpression;
}
-
- public void setTidyInput (boolean tidyInput) {
- this.tidyInput = tidyInput;
- }
public TokenInterface next() throws MXQueryException {
if (called == 0) {
@@ -93,54 +96,90 @@
protected void init() throws MXQueryException {
- XDMIterator parameter = subIters[0];
- if (parameter == null) {
- // this should never happen!!!
- throw new IllegalArgumentException("No parameter for fn:doc() function given!");
- }
- TokenInterface tok = parameter.next();
- int type = Type.getEventTypeSubstituted(tok.getEventType(), Context.getDictionary());
+
+ String add = getStringValueOrEmpty(subIters[0]);
+
- if (type == Type.END_SEQUENCE) {
+ if (add == null) {
current = new EmptySequenceIterator(context, loc);
return;
}
- if (Type.typePromoteableTo(type, Type.STRING,Context.getDictionary())|| type == Type.UNTYPED_ATOMIC) {
-
- String add = tok.getText();
- String uri = null;
- try {
- uri = URIUtils.resolveURI(context.getBaseURI(),add,loc);
- } catch (DynamicException de) {
- if (de.getErrorCode().equals(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE)) {
- throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC, "Invalid URI given to fn:doc(): "+add, loc);
- }
- else
- throw de;
- }
- if (tidyInput)
- rd = IOLib.getInput(uri, false, loc);
- XMLSource cur;
- try {
+
+ String encoding = null;
+
+ if (subIters.length > 1) {
+ encoding = getStringValue(subIters[1]);
+ }
+
+ String uri = null;
+ try {
+ uri = URIUtils.resolveURI(context.getBaseURI(),add,loc);
+ } catch (DynamicException de) {
+ if (de.getErrorCode().equals(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE)) {
+ throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC, "Invalid URI given to fn:doc(): "+add, loc);
+ }
+ else
+ throw de;
+ }
+ if (operation!=OPERATION_DOC)
+ rd = IOLib.getInput(uri, false, encoding, loc);
+ XDMIterator cur = null;
+ try {
+ switch(operation) {
+ case OPERATION_DOC:
if (isInValidateExpression())
- cur = XDMInputFactory.createXMLInput(context, rd, true, Context.SCHEMA_VALIDATION_STRICT, loc);
- else if (tidyInput)
- cur = XDMInputFactory.createTidyInput(context, rd, loc);
- else cur = XDMInputFactory.createXMLInput(context, uri, true, context.getInputValidationMode(), loc);
- cur.setURI(uri);
- docURI = uri;
- current = cur;
- } catch (MXQueryException me) {
- try {
- rd.close();
- } catch (IOException ie) {
- //
- }
- throw me;
+ cur = XDMInputFactory.createXMLInput(context, rd, true, Context.SCHEMA_VALIDATION_STRICT, loc);
+ else
+ cur = XDMInputFactory.createXMLInput(context, uri, true, context.getInputValidationMode(), loc);
+ ((XMLSource)cur).setURI(uri);
+ break;
+ case OPERATION_TIDY:
+ cur = XDMInputFactory.createTidyInput(context, rd, loc);
+ ((XMLSource)cur).setURI(uri);
+ break;
+ case OPERATION_UNPARSED:
+ StringBuffer sb = new StringBuffer();
+ LineReader lr = new LineReader(rd);
+ String line = lr.readLine();
+ boolean first = true;
+ while(line!=null) {
+ if (first)
+ first=false;
+ else
+ sb.append('\n');
+ sb.append(line);
+ line = lr.readLine();
}
+ cur = new TokenIterator(context,sb.toString(),loc);
+ break;
+ case OPERATION_UNPARSED_LINES:
+ Vector lines = new Vector();
+ lr = new LineReader(rd);
+ line = lr.readLine();
+ while(line!=null) {
+ lines.addElement(new TextToken(null, line));
+ line = lr.readLine();
+ }
+ cur = new TokenSequenceIterator(lines);
+ break;
- } else {
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Invalid argument given to fn:doc", loc);
+ }
+ docURI = uri;
+ current = cur;
+ } catch (MXQueryException me) {
+ try {
+ rd.close();
+ } catch (IOException ie) {
+ //
+ }
+ throw me;
+ } catch (IOException e) {
+ try {
+ rd.close();
+ } catch (IOException ie) {
+ //
+ }
+ throw new MXQueryException(ErrorCodes.F0014_ERROR_RETRIEVING_RESOURCE, e.toString(), loc);
}
}
@@ -152,7 +191,7 @@
Doc copy = new Doc();
copy.setContext(context, true);
copy.setInValidateExpression(inValidateExpression);
- copy.setTidyInput(this.tidyInput);
+ copy.operation = operation;
copy.setConstModePreserve(this.constModePreserve);
copy.setSubIters(subIters);
return copy;
@@ -182,7 +221,11 @@
public void setOperation(String type) throws MXQueryException {
if (type.equals("tidy"))
- tidyInput = true;
+ operation = OPERATION_TIDY;
+ else if (type.equals("unparsed-text"))
+ operation = OPERATION_UNPARSED;
+ else if (type.equals("unparsed-text-lines"))
+ operation = OPERATION_UNPARSED_LINES;
else throw new MXQueryException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Incorrect operation for Doc", loc);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DocumentUri.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DocumentUri.java 2011-05-14 13:30:29 UTC (rev 4339)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DocumentUri.java 2011-05-14 15:31:32 UTC (rev 4340)
@@ -31,7 +31,8 @@
public class DocumentUri extends TokenBasedIterator {
protected void init() throws MXQueryException {
- TokenInterface tok = subIters[0].next();
+ XDMIterator iter = getNodeIteratorOrContext(subIters, 1, context, loc);
+ TokenInterface tok = iter.next();
if (tok.getEventType() == Type.START_DOCUMENT) {
// Take advantage of our Node ID implementation -
// each node ID has a reference to the store it comes from,
Added: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EnvVar.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EnvVar.java (rev 0)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EnvVar.java 2011-05-14 15:31:32 UTC (rev 4340)
@@ -0,0 +1,32 @@
+package ch.ethz.mxquery.functions.fn;
+
+import java.util.Vector;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.xdm.TextToken;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.model.TokenBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class EnvVar extends TokenBasedIterator {
+
+ protected void init() throws MXQueryException {
+ String varName = getStringValue(subIters[0]);
+ String varValue = System.getenv(varName);
+ if (varValue != null)
+ currentToken = new TextToken(null,varValue);
+ else
+ currentToken = Token.END_SEQUENCE_TOKEN;
+
+ }
+
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ EnvVar copy = new EnvVar();
+ copy.setContext(context, true);
+ copy.setSubIters(subIters);
+ return copy;
+ }
+
+}
Added: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Head.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Head.java (rev 0)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Head.java 2011-05-14 15:31:32 UTC (rev 4340)
@@ -0,0 +1,60 @@
+package ch.ethz.mxquery.functions.fn;
+
+import java.util.Vector;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.model.CurrentBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class Head extends CurrentBasedIterator {
+ int position = 0;
+ public TokenInterface next() throws MXQueryException {
+ TokenInterface retToken;
+
+ if (endOfSeq)
+ return Token.END_SEQUENCE_TOKEN;
+
+ if (called == 0) {
+ called++;
+ current = subIters[0];
+ }
+ retToken = sub0Next();
+
+ if(position <=1) {
+ if (retToken.getEventType() == Type.END_SEQUENCE){
+ }
+ return retToken;
+ }
+ else {
+ //current = null;
+ endOfSeq = true;
+ return Token.END_SEQUENCE_TOKEN;
+ }
+ }
+
+ protected void resetImpl() throws MXQueryException {
+ super.resetImpl();
+ position = 0;
+ }
+
+
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ XDMIterator copy = new Head();
+ copy.setContext(context, true);
+ copy.setSubIters(subIters);
+ return copy;
+ }
+
+ private TokenInterface sub0Next() throws MXQueryException {
+ if (depth == 0) {
+ position++;
+ }
+ return super.getNext();
+ }
+
+}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Node_Name.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Node_Name.java 2011-05-14 13:30:29 UTC (rev 4339)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Node_Name.java 2011-05-14 15:31:32 UTC (rev 4340)
@@ -32,12 +32,8 @@
public class Node_Name extends TokenBasedIterator {
protected void init() throws MXQueryException {
- if (subIters == null || subIters.length == 0) {
- currentToken = Token.END_SEQUENCE_TOKEN;
- return;
- }
- XDMIterator input = subIters[0];
+ XDMIterator input = getNodeIteratorOrContext(subIters, 1,context, loc);
TokenInterface inputToken = input.next();
int i = inputToken.getEventType();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/SubSequenceIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/SubSequenceIterator.java 2011-05-14 13:30:29 UTC (rev 4339)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/SubSequenceIterator.java 2011-05-14 15:31:32 UTC (rev 4340)
@@ -19,7 +19,6 @@
import ch.ethz.mxquery.contextConfig.Context;
import ch.ethz.mxquery.datamodel.MXQueryDouble;
import ch.ethz.mxquery.datamodel.types.Type;
-import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.datamodel.xdm.Token;
import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.ErrorCodes;
@@ -161,9 +160,6 @@
startPos = -1;
len = -1;
position = 0;
- }
- public TypeInfo getStaticType() {
- return new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
}
protected XDMIterator copy(Context context, XD...
[truncated message content] |
|
From: <pm_...@us...> - 2011-05-17 10:21:14
|
Revision: 4350
http://mxquery.svn.sourceforge.net/mxquery/?rev=4350&view=rev
Author: pm_fischer
Date: 2011-05-17 10:21:05 +0000 (Tue, 17 May 2011)
Log Message:
-----------
refactoring/simplification of string parameter handling
Modified Paths:
--------------
trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/math/TransMath.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Replace.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/StringToCodepoints.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/String_Length.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/SubString.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Tokenize.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Translate.java
trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/crypto/SignString.java
trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/zorbaRest/HttpIO.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DocAvailable.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EncodeForURI.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EscapeHTMLURI.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/FNQName.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/IRItoURI.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/LowerCase.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Matches.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Namespace_uri_for_prefix.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/NormalizeSpace.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/NormalizeUnicode.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Parse.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Replace.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/ResolveQName.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/StringJoin.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/StringToCodepoints.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/String_Length.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Tokenize.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Trace.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/UpperCase.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/ComputedPIConstrIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/model/Iterator.java
trunk/MXQuery/src/ch/ethz/mxquery/util/Utils.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/fn/IRItoURI.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/fn/Matches.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/fn/Replace.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/fn/Tokenize.java
Modified: trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/math/TransMath.java
===================================================================
--- trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/math/TransMath.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/math/TransMath.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -146,7 +146,7 @@
break;
case TRANSMATH_ATAN2:
MXQueryDouble y = null;
- XDMIterator input2 = subIters[0];
+ XDMIterator input2 = subIters[1];
TokenInterface inputToken2 = input2.next();
int type2 = Type.getEventTypeSubstituted(inputToken2.getEventType(), Context.getDictionary());
@@ -155,16 +155,16 @@
currentToken = Token.END_SEQUENCE_TOKEN;
return;
case Type.INTEGER:
- y = new MXQueryDouble(inputToken.getLong());
+ y = new MXQueryDouble(inputToken2.getLong());
break;
case Type.UNTYPED_ATOMIC:
case Type.UNTYPED:
- y = new MXQueryDouble(inputToken.getText());
+ y = new MXQueryDouble(inputToken2.getText());
break;
case Type.DOUBLE:
case Type.FLOAT:
case Type.DECIMAL:
- y = inputToken.getDouble();
+ y = inputToken2.getDouble();
break;
default:
throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type"+Type.getTypeQName(type, Context.getDictionary()), loc);
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Replace.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Replace.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Replace.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -31,25 +31,13 @@
public class Replace extends TokenBasedIterator {
protected void init() throws MXQueryException {
- XDMIterator input = DataValuesIterator.getDataIterator(subIters[0],context);
- TokenInterface tok = input.next();
-
- int type = tok.getEventType();
-
- if (type == Type.END_SEQUENCE) {
- currentToken = new TextToken(null,"");
+ String res = getStringValueOrEmpty(subIters[0]);
+ if (res == null){
+ currentToken = new TextToken(null, "");
return;
- }
- if (type != Type.STRING)
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type"+type,loc);
- String res = tok.getText();
- TokenInterface tok1 = subIters[1].next();
-
- String pattern = tok1.getText();
-
- TokenInterface tok2 = subIters[2].next();
-
- String replacement = tok2.getText();
+ }
+ String pattern = getStringValue(subIters[1]);
+ String replacement = getStringValue(subIters[2]);
//currentToken.setText(res.replaceAll(pattern, replacement));
//FIXME: Dummy implementation
currentToken = new TextToken(null,res);
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/StringToCodepoints.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/StringToCodepoints.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/StringToCodepoints.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -36,23 +36,11 @@
String toTranslate = null;
protected void init() throws MXQueryException {
- XDMIterator input = DataValuesIterator.getDataIterator(subIters[0],context);
- TokenInterface inputToken =input.next();
- int type = Type.getEventTypeSubstituted( inputToken.getEventType(),null );
-
- switch (type) {
- case(Type.END_SEQUENCE):
- currentToken = new TextToken(null, "");
- break;
- case(Type.STRING):
- case(Type.UNTYPED_ATOMIC):
- case Type.UNTYPED:
- String res = inputToken.getText();
- toTranslate = res;
- break;
- default:
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type"+Type.getTypeQName(type,null),loc);
- }
+ toTranslate = getStringValueOrEmpty(subIters[0]);
+ if (toTranslate==null||toTranslate.equals("")) {
+ currentToken = new TextToken(null, "");
+ return;
+ }
}
public TokenInterface next() throws MXQueryException {
if (called == 0)
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/String_Length.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/String_Length.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/String_Length.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -20,6 +20,7 @@
import ch.ethz.mxquery.exceptions.DynamicException;
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.functions.fn.FNString;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.datamodel.types.Type;
@@ -36,40 +37,22 @@
public class String_Length extends TokenBasedIterator {
protected void init() throws MXQueryException {
- XDMIterator input;
- if (subIters != null && subIters.length == 1) {
- input = DataValuesIterator.getDataIterator(subIters[0], context);
- } else {
- VariableHolder contextVarHolder = context.getContextItem();
- if (contextVarHolder != null) {
- input = contextVarHolder.getIter();
- if (input == null) {
- throw new DynamicException(ErrorCodes.E0002_DYNAMIC_NO_VALUE_ASSIGNED, "Context Item Iterator not set", loc);
- } else {
- input = DataValuesIterator.getDataIterator(input, context);
- }
- } else {
- throw new RuntimeException("Context Item not set");
- }
- }
+ XDMIterator input;
+ if (subIters.length > 0 )
+ input = subIters[0];
+ else {
+ input = new FNString();
+ input.setContext(context, false);
+ }
+ String content = getStringValueOrEmpty(input);
+
+ if (content == null){
+ currentToken = new LongToken(Type.INTEGER, null,0);
+ } else {
+ int charCount = content.length();
+ currentToken = new LongToken(Type.INTEGER, null, charCount );
+ }
- TokenInterface inputToken = input.next();
- int type = inputToken.getEventType();
- if (type == Type.START_DOCUMENT) {
- inputToken = input.next();
- type = inputToken.getEventType();
- }
-
- if ( Type.isAttribute(type) )
- type = Type.getAttributeValueType(type);
-
- if ( Type.isAtomicType(type, null) ){
- String content = inputToken.getValueAsString();
- int charCount = content.length();
- currentToken = new LongToken(Type.INTEGER, null, charCount );
- } else if (type == Type.END_SEQUENCE){
- currentToken = new LongToken(Type.INTEGER, null,0);
- }
}
public TypeInfo getStaticType() {
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/SubString.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/SubString.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/SubString.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -29,16 +29,12 @@
public class SubString extends TokenBasedIterator {
protected void init() throws MXQueryException {
- XDMIterator input = DataValuesIterator.getDataIterator(subIters[0], context);
- TokenInterface inputToken = input.next();
- int type = inputToken.getEventType();
+ String res = getStringValueOrEmpty(subIters[0]);
- if (type == Type.END_SEQUENCE) {
+ if (res == null) {
currentToken = new TextToken(null, "");
return;
}
-
- String res = inputToken.getText();
TokenInterface inputToken1 = subIters[1].next();
int type1 = Type.getEventTypeSubstituted(inputToken1.getEventType(), Context.getDictionary());
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Tokenize.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Tokenize.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Tokenize.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -41,34 +41,19 @@
}
private void init() throws MXQueryException {
- XDMIterator input = DataValuesIterator.getDataIterator(subIters[0],context);
- TokenInterface tok1 = input.next();
- int type = tok1.getEventType();
- String res = tok1.getText();
- XDMIterator input2 = DataValuesIterator.getDataIterator(subIters[1],context);
- TokenInterface tok2 = input2.next();
- int type2 = tok2.getEventType();
- String delimiter = tok2.getText();
- if (type2 != Type.STRING || delimiter.length() == 0)
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type"+Type.getTypeQName(type,null),loc);
- switch (type) {
- case(Type.END_SEQUENCE):
+ String res = getStringValueOrEmpty(subIters[0]);
+ String delimiter = getStringValue(subIters[1]);
+ if (delimiter.length() == 0)
+ throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Separator must not be empty", loc);
+
+ if (res==null || res.length() == 0)
current = new TokenIterator(context, "", loc);
- break;
-
- case(Type.STRING):
- if (res.length() == 0)
- current = new TokenIterator(context, "",loc);
- else {
- String [] splitted = Utils.split(res,delimiter,true);
- TokenIterator [] toks = new TokenIterator[splitted.length];
- for (int i =0;i<toks.length;i++)
- toks[i] = new TokenIterator(context, splitted[i],loc);
- current = new SequenceIterator(null, toks,loc);
- }
- break;
- default:
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type"+type,loc);
+ else {
+ String [] splitted = Utils.split(res,delimiter,true);
+ TokenIterator [] toks = new TokenIterator[splitted.length];
+ for (int i =0;i<toks.length;i++)
+ toks[i] = new TokenIterator(context, splitted[i],loc);
+ current = new SequenceIterator(null, toks,loc);
}
}
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Translate.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Translate.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/fn/Translate.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -34,25 +34,16 @@
private Vector remove = new Vector();
protected void init() throws MXQueryException {
- TokenInterface arg = subIters[0].next();
- TokenInterface mapString = subIters[1].next();
- TokenInterface transString = subIters[2].next();
+ String sArg = getStringValueOrEmpty(subIters[0]);
- if (arg.getEventType() == Type.END_SEQUENCE) {
+ if (sArg == null || sArg.equals("")) {
currentToken = new TextToken(null, "");
return;
}
+
+ String sMap = getStringValue(subIters[1]);
+ String sTrans = getStringValue(subIters[2]);
- if (arg.getEventType() != Type.STRING ||
- mapString.getEventType() != Type.STRING ||
- transString.getEventType() != Type.STRING) {
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type for fn:translate!", loc);
- }
-
- String sArg = arg.getText();
- String sMap = mapString.getText();
- String sTrans = transString.getText();
-
int transPos = 0;
for (int i=0; i<sMap.length(); i++) {
int sMapChar = sMap.charAt(i);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/crypto/SignString.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/crypto/SignString.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/crypto/SignString.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -14,8 +14,6 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.datamodel.xdm.BinaryToken;
-import ch.ethz.mxquery.datamodel.xdm.Token;
-import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.DynamicException;
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
@@ -26,19 +24,12 @@
public class SignString extends TokenBasedIterator {
protected void init() throws MXQueryException {
- TokenInterface method = subIters[0].next();
- if (method == Token.END_SEQUENCE_TOKEN || !(method.getEventType() == Type.UNTYPED_ATOMIC || Type.isTypeOrSubTypeOf(method.getEventType(), Type.STRING, Context.getDictionary())))
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Single Element of Type String Expected",loc);
- String macMethod = method.getText();
- TokenInterface key = subIters[1].next();
- if (key == Token.END_SEQUENCE_TOKEN || !(key.getEventType() == Type.UNTYPED_ATOMIC || Type.isTypeOrSubTypeOf(key.getEventType(), Type.STRING, Context.getDictionary())))
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Single Element of Type String Expected",loc);
- String keyChars = key.getText();
- TokenInterface content = subIters[2].next();
- if (content == Token.END_SEQUENCE_TOKEN || !(content.getEventType() == Type.UNTYPED_ATOMIC || Type.isTypeOrSubTypeOf(content.getEventType(), Type.STRING, Context.getDictionary())))
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Single Element of Type String Expected",loc);
- String contentChars = content.getText();
+ String macMethod = getStringValue(subIters[0]);
+ String keyChars = getStringValue(subIters[1]);
+
+ String contentChars = getStringValue(subIters[2]);
+
Mac mac;
try {
mac = Mac.getInstance(macMethod);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -241,27 +241,7 @@
if (username!=null && (password==null||authmethod==null))
throw new DynamicException(EHC005_DYNAMIC_INVALID_REQUEST_ELEM, "If username is given, password and method also need to be provided", loc);
if (subIters.length > 1) {
- String urlParam = null;
- TokenInterface urlToken = subIters[1].next();
-
- switch (urlToken.getEventType()) {
- case Type.UNTYPED_ATOMIC:
- urlParam = urlToken.getText();
- break;
- case Type.END_SEQUENCE:
- break;
- default:
- if (Type.isTypeOrSubTypeOf(urlToken.getEventType(), Type.STRING,
- Context.getDictionary()))
- urlParam = urlToken.getText();
- else
- throw new DynamicException(
- ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
- "Expected String type for URL", loc);
- break;
- }
- if (urlParam != null)
- url = urlParam;
+ url = getStringValueOrEmpty(subIters[1]);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/zorbaRest/HttpIO.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/zorbaRest/HttpIO.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/extensionsModules/zorbaRest/HttpIO.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -148,25 +148,7 @@
private void init() throws MXQueryException {
TokenInterface urlToken = subIters[0].next();
- String url;
- switch (urlToken.getEventType()) {
- case Type.END_SEQUENCE:
- throw new DynamicException(
- ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
- "Emtpy sequence not allowed for URL", loc);
- case Type.UNTYPED_ATOMIC:
- url = urlToken.getText();
- break;
- default:
- if (Type.isTypeOrSubTypeOf(urlToken.getEventType(), Type.STRING,
- Context.getDictionary()))
- url = urlToken.getText();
- else
- throw new DynamicException(
- ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
- "Expected String type for URL", loc);
- break;
- }
+ String url = getStringValue(subIters[0]);
if (request_type != REQUEST_TYPE_GET && url.indexOf('?') >= 0) {
throw new DynamicException(
ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DocAvailable.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DocAvailable.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/DocAvailable.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -29,89 +29,76 @@
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.datamodel.types.TypeLexicalConstraints;
import ch.ethz.mxquery.datamodel.xdm.BooleanToken;
-import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.DynamicException;
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
public class DocAvailable extends TokenBasedIterator {
protected void init() throws MXQueryException {
- XDMIterator parameter = subIters[0];
- if (parameter == null) {
- // this should never happen!!!
- throw new IllegalArgumentException("No parameter for fn:doc-available() function given!");
+ String add = getStringValueOrEmpty(subIters[0]);
+
+ if (add == null) {
+ currentToken = BooleanToken.FALSE_TOKEN;
+ return;
}
- TokenInterface tok = parameter.next();
- int type = Type.getEventTypeSubstituted(tok.getEventType(), Context.getDictionary());
+ URI uri;
- if (type == Type.END_SEQUENCE) {
+ if (!TypeLexicalConstraints.isValidURI(add))
+ throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
+ try {
+ if (TypeLexicalConstraints.isAbsoluteURI(add)) {
+ uri = new URI(add);
+ } else {
+ String base = context.getBaseURI();
+ String add1 = add;
+ if (add1.startsWith("/"))
+ add1 = add1.substring(1);
+ uri = new URI(base + add1);
+ }
+ } catch (URISyntaxException se) {
+ throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
+ }
+ if(add.startsWith("http://")){
+
+ URL url;
+ try {
+ url = uri.toURL();
+ } catch (MalformedURLException e) {
+ throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
+ }
+ try {
+ InputStream in = url.openStream();
+ in.close();
+ } catch (IOException e) {
currentToken = BooleanToken.FALSE_TOKEN;
return;
+ }
+ currentToken = BooleanToken.TRUE_TOKEN;
+ // }
+ // catch(Exception e){
+ // throw new DynamicException(ErrorCodes.A0006_EC_URI_NOT_FOUND, "Remote Data cannot be accessed: " + e);
+ // }
}
- if (Type.typePromoteableTo(type, Type.STRING,Context.getDictionary()) || type == Type.UNTYPED_ATOMIC) {
- String add=tok.getText();
- URI uri;
-
- if (!TypeLexicalConstraints.isValidURI(add))
- throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
+ else {
+ File xml;
+ try {
+ xml = new File(uri);
+ }catch(IllegalArgumentException ia) {
try {
- if (TypeLexicalConstraints.isAbsoluteURI(add)) {
- uri = new URI(add);
- } else {
- String base = context.getBaseURI();
- String add1 = add;
- if (add1.startsWith("/"))
- add1 = add1.substring(1);
- uri = new URI(base + add1);
- }
- } catch (URISyntaxException se) {
- throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
- }
- if(add.startsWith("http://")){
-
- URL url;
- try {
- url = uri.toURL();
- } catch (MalformedURLException e) {
- throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
- }
- try {
- InputStream in = url.openStream();
- in.close();
- } catch (IOException e) {
- currentToken = BooleanToken.FALSE_TOKEN;
- return;
- }
- currentToken = BooleanToken.TRUE_TOKEN;
-// }
-// catch(Exception e){
-// throw new DynamicException(ErrorCodes.A0006_EC_URI_NOT_FOUND, "Remote Data cannot be accessed: " + e);
-// }
+ xml = new File(add);
+ } catch (IllegalArgumentException ia2) {
+ throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
}
- else {
- File xml;
- try {
- xml = new File(uri);
- }catch(IllegalArgumentException ia) {
- try {
- xml = new File(add);
- } catch (IllegalArgumentException ia2) {
- throw new DynamicException(ErrorCodes.F0017_INVALID_ARGUMENT_TO_FN_DOC,"Invalid URI given to fn:doc-available", loc);
- }
- }
- if (xml.exists()) {
- currentToken = BooleanToken.TRUE_TOKEN;
- } else {
- currentToken = BooleanToken.FALSE_TOKEN;
- }
- }
- }
- else
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Invalid argument given to fn:doc-available", loc);
+ }
+ if (xml.exists()) {
+ currentToken = BooleanToken.TRUE_TOKEN;
+ } else {
+ currentToken = BooleanToken.FALSE_TOKEN;
+ }
+ }
}
public TypeInfo getStaticType() {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EncodeForURI.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EncodeForURI.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EncodeForURI.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -21,10 +21,7 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.datamodel.xdm.TextToken;
-import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
-import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.BitSet;
@@ -44,19 +41,13 @@
}
protected void init() throws MXQueryException {
- XDMIterator input = subIters[0];
- TokenInterface uri = input.next();
+ String uri = getStringValueOrEmpty(subIters[0]);
- if (uri.getEventType() == Type.END_SEQUENCE) {
+ if (uri == null || uri.equals("")) {
currentToken = new TextToken(null, "");
return;
- }
-
- if (!(Type.isTypeOrSubTypeOf(uri.getEventType(), Type.STRING,Context.getDictionary()) || uri.getEventType()==Type.UNTYPED_ATOMIC)) {
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type for fn:encode-for-uri!", loc);
- }
-
- currentToken = new TextToken(null, encode(uri.getText()));
+ }
+ currentToken = new TextToken(null, encode(uri));
}
public TypeInfo getStaticType() {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EscapeHTMLURI.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EscapeHTMLURI.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/EscapeHTMLURI.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -21,10 +21,7 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.datamodel.xdm.TextToken;
-import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
-import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.Utils;
@@ -34,19 +31,13 @@
private int eRange = 126;
protected void init() throws MXQueryException {
- XDMIterator input = subIters[0];
- TokenInterface uri = input.next();
+ String uri = getStringValueOrEmpty(subIters[0]);
- if (uri.getEventType() == Type.END_SEQUENCE) {
+ if (uri == null || uri.equals("")) {
currentToken = new TextToken(null, "");
return;
- }
-
- if (!(Type.isTypeOrSubTypeOf(uri.getEventType(), Type.STRING,Context.getDictionary()) || uri.getEventType()==Type.UNTYPED_ATOMIC)) {
- throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Invalid argument type for fn:encode-for-uri!", loc);
- }
-
- currentToken = new TextToken(null, encode(uri.getText()));
+ }
+ currentToken = new TextToken(null, encode(uri));
}
private String encode(String input) {
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/FNQName.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/FNQName.java 2011-05-16 19:04:44 UTC (rev 4349)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/FNQName.java 2011-05-17 10:21:05 UTC (rev 4350)
@@ -22,73 +22,31 @@
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.datamodel.xdm.QNameToken;
-import ch.ethz.mxquery.datamodel.xdm.Token;
-import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
import ch.ethz.mxquery.exceptions.DynamicException;
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.exceptions.TypeException;
import ch.ethz.mxquery.model.TokenBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
public class FNQName extends TokenBasedIterator {
protected void init() throws MXQueryException {
- if (subIters[0] == null) {
- throw new IllegalArgumentException();
- }
- XDMIterator paramQNameIt;
- TokenInterface nsToken = subIters[0].next();
- paramQNameIt = subIters[1];
- String nsString = null;
- if (!(nsToken.getText() == null || nsToken.getText().equals("")))
- nsString = nsToken.getText();
- if (!(Type.getEventTypeSubstituted(nsToken.getEventType(), Context
- .getDictionary()) == Type.STRING
- || nsToken.getEventType() == Type.UNTYPED_ATOMIC
- || nsToken.getEventType() == Type.UNTYPED || nsToken
- .getEventType() == Type.END_SEQUENCE))
- throw new DynamicException(
- ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
- "Wrong data type for fn:QName", loc);
- TokenInterface paramToken = paramQNameIt.next();
- int type = Type.getEventTypeSubstituted(paramToken.getEventType(),
- Context.getDictionary());
+ String nsString = getStringValueOrEmpty(subIters[0]);
- switch (type) {
- case Type.END_SEQUENCE:
- throw new DynamicException(
- ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,
- "QName expected", loc);
- case Type.STRING:
- case Type.UNTYPED_ATOMIC:
- case Type.UNTYPED:
- String qNameText = paramToken.getText();
+ String qNameText = getStringValue(subIters[1]);
+
if (qNameText.equals(""))
throw new DynamicException(
ErrorCodes.F0005_INVALID_LEXICAL_VALUE,
"Empty QName not possible", loc);
QName qToGen = new QName(qNameText);
if (qToGen.getNamespacePrefix() != null
- && (nsToken.getEventType() == Type.END_SEQUENCE || nsToken
- .getText().equals("")))
+ && (nsString == null || nsString.equals("")))
throw new DynamicException(
E...
[truncated message content] |
|
From: <pm_...@us...> - 2011-05-17 10:24:22
|
Revision: 4351
http://mxquery.svn.sourceforge.net/mxquery/?rev=4351&view=rev
Author: pm_fischer
Date: 2011-05-17 10:24:14 +0000 (Tue, 17 May 2011)
Log Message:
-----------
Refactor Function Gallery to have same code on all platforms
Introduced FGPopulator to handle FG platform-specific loading
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/cmdline/MXQuery.java
trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionGallery.java
Added Paths:
-----------
trunk/MXQuery/src/ch/ethz/mxquery/functions/FGPopulator.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java
Removed Paths:
-------------
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/cmdline/MXQuery.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/cmdline/MXQuery.java 2011-05-17 10:21:05 UTC (rev 4350)
+++ trunk/MXQuery/src/ch/ethz/mxquery/cmdline/MXQuery.java 2011-05-17 10:24:14 UTC (rev 4351)
@@ -54,7 +54,6 @@
import ch.ethz.mxquery.contextConfig.CompilerOptions;
import ch.ethz.mxquery.contextConfig.Context;
import ch.ethz.mxquery.datamodel.QName;
-import ch.ethz.mxquery.datamodel.XQName;
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
@@ -71,7 +70,6 @@
import ch.ethz.mxquery.xdmio.XDMInputFactory;
import ch.ethz.mxquery.xdmio.XDMSerializer;
import ch.ethz.mxquery.xdmio.XDMSerializerSettings;
-import ch.ethz.mxquery.xdmio.XMLSource;
public class MXQuery {
@@ -360,8 +358,7 @@
protected static void setUpExtension(String funcFile)
throws FileNotFoundException {
try {
- File file = new File(funcFile);
- Hashtable builtInExtensions = FunctionGallery.getModules(new InputStreamReader(new FileInputStream(file)));
+ Hashtable builtInExtensions = FunctionGallery.getModulesFile(funcFile);
Enumeration mods = builtInExtensions.keys();
while (mods.hasMoreElements()) {
String ns = (String) mods.nextElement();
Modified: trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java 2011-05-17 10:21:05 UTC (rev 4350)
+++ trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java 2011-05-17 10:24:14 UTC (rev 4351)
@@ -1554,7 +1554,7 @@
globalContext.setParserType(NONVALIDATED_INPUT_MODE_SAX);
globalContext.setScoringImplementation(new MXQSimpleScoring());
for (int i=0;i<extensions.length;i++) {
- Hashtable builtInExtensions = FunctionGallery.getModules(extensions[i]);
+ Hashtable builtInExtensions = FunctionGallery.getModulesRes(extensions[i]);
Enumeration mods = builtInExtensions.keys();
while (mods.hasMoreElements()) {
String ns = (String) mods.nextElement();
Added: trunk/MXQuery/src/ch/ethz/mxquery/functions/FGPopulator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/FGPopulator.java (rev 0)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/FGPopulator.java 2011-05-17 10:24:14 UTC (rev 4351)
@@ -0,0 +1,151 @@
+package ch.ethz.mxquery.functions;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.kxml2.io.KXmlParser;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.contextConfig.XQStaticContext;
+import ch.ethz.mxquery.datamodel.Namespace;
+import ch.ethz.mxquery.datamodel.QName;
+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.model.XDMIterator;
+import ch.ethz.mxquery.util.IOLib;
+
+class FGPopulator {
+
+ private static Reader getRessource(FunctionGallery fg, String name, String type) throws IOException, MXQueryException {
+ if (type.equals("fg"))
+ return new InputStreamReader(fg.getClass().getResourceAsStream(name));
+ if (type.equals("ctx"))
+ return new InputStreamReader(Context.getGlobalContext().getClass().getResourceAsStream(name));
+ if (type.equals("file")) {
+ return IOLib.getInput(name, false, null, QueryLocation.OUTSIDE_QUERY_LOC);
+ }
+ return null;
+ }
+ public static void populateFunctionGallery(XQStaticContext ctx,
+ FunctionGallery fg, String id, String type) throws MXQueryException {
+ Reader is = null;
+ try {
+ is = getRessource(fg, id,type);
+
+ populateFunctionGallery(ctx, fg, is);
+ is.close();
+ } catch (IOException e) {
+ throw new MXQueryException(ErrorCodes.A0007_EC_IO, e, "Function Gallery could not be loaded, IO Error",null);
+ } finally {
+ if (is!=null)
+ try {
+ is.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static void populateFunctionGallery(XQStaticContext ctx,
+ FunctionGallery fg, Reader is) throws MXQueryException {
+ KXmlParser xpp = new KXmlParser();
+ try {
+ xpp.setInput(is);
+
+ xpp.nextTag();
+ xpp.require(XmlPullParser.START_TAG, null, "functionGallery");
+ String baseLoc = xpp.getAttributeValue("","basePackage");
+ if (baseLoc==null)
+ throw new MXQueryException(ErrorCodes.A0007_EC_IO,"Invalid Function Gallery, basePackage missing",QueryLocation.OUTSIDE_QUERY_LOC);
+ xpp.nextTag();
+ while (!xpp.getName().equals("functionGallery") && xpp.getEventType() != XmlPullParser.END_TAG) {
+
+ xpp.require(XmlPullParser.START_TAG, null, "functionGroup");
+ //Function prefix, name, and class
+ String[] funcDesc = new String[3];
+ funcDesc[0] = xpp.getAttributeValue("", "namespace");
+ String prefix = xpp.getAttributeValue("", "prefix");
+ String loc = xpp.getAttributeValue("", "loc");
+ if (loc==null)
+ loc=prefix;
+ String[] parameters = new String[10];
+ int currArity = 0;
+
+ Namespace ns = ctx.getNamespace(prefix);
+ if (ns == null)
+ ctx.addNamespace(prefix, funcDesc[0]);
+ else if (!ns.getURI().equals(funcDesc[0]))
+ throw new MXQueryException(ErrorCodes.E0033_STATIC_MODULE_MULTIPLE_BINDINGS_FOR_SAME_PREFIX, "Inconsisten namespace for function/module import: "+prefix, QueryLocation.OUTSIDE_QUERY_LOC);
+ xpp.nextTag();
+ while (!xpp.getName().equals("functionGroup") && xpp.getEventType() != XmlPullParser.END_TAG) {
+ xpp.require(XmlPullParser.START_TAG, null, "functionDescription");
+ xpp.nextTag();
+ String operation = null;
+ TypeInfo type = null;
+ while (!xpp.getName().equals("functionDescription") && xpp.getEventType() != XmlPullParser.END_TAG) {
+ String elementName = xpp.getName();
+ if (elementName.equals("functionName")) {
+ funcDesc[1] = xpp.nextText();
+ } else if (elementName.equals("parameters")) {
+ xpp.nextTag();
+ int i = 0;
+ while (!xpp.getName().equals("parameters") && xpp.getEventType() != XmlPullParser.END_TAG){
+ xpp.require(XmlPullParser.START_TAG, null, "paramType");
+ elementName = xpp.getName();
+ if (elementName.equals("paramType")){
+ parameters[i++] = xpp.nextText();
+ }
+ xpp.nextTag();
+ }
+ currArity = i;
+ } else if (elementName.equals("className")) {
+ operation = xpp.getAttributeValue("", "op");
+ String rawType = xpp.getAttributeValue("", "type");
+ funcDesc[2] = xpp.nextText();
+ if (rawType != null) {
+ type = new TypeInfo(FunctionGallery.getType(rawType,ctx),FunctionGallery.getOccur(rawType));
+ }
+ } else {
+ // element ignored
+ System.out.println("element ignored!");
+ }
+
+ xpp.nextTag();
+ }
+
+ for (int i = 0; i < funcDesc.length; i++) {
+ if (funcDesc[i] == null) {
+ throw new IllegalArgumentException("The function description is not complete:" + funcDesc[0]
+ + ":" + funcDesc[1] + ":" + funcDesc[2]);
+ }
+ }
+
+ QName qn = new QName(funcDesc[0],prefix, funcDesc[1]);
+
+ TypeInfo [] paramTypes = new TypeInfo[currArity];
+ //TODO: What about the prefix and URI?
+ for (int i=0;i<paramTypes.length;i++)
+ paramTypes[i] = new TypeInfo(FunctionGallery.getType(parameters[i],ctx),FunctionGallery.getOccur(parameters[i]));
+
+ FunctionSignature signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+ Function function = new Function(baseLoc+loc+"."+funcDesc[2],signature, null, operation, type );
+ fg.add(function);
+
+ xpp.nextTag();
+ }
+ xpp.nextTag();
+ }
+ } catch (XmlPullParserException e) {
+ throw new MXQueryException(ErrorCodes.A0007_EC_IO, e, "Function Gallery could not be loaded, Parse Error",null);
+ } catch (IOException e) {
+ throw new MXQueryException(ErrorCodes.A0007_EC_IO, e, "Function Gallery could not be loaded, Parse Error",null);
+ }
+
+}
+}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionGallery.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionGallery.java 2011-05-17 10:21:05 UTC (rev 4350)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionGallery.java 2011-05-17 10:24:14 UTC (rev 4351)
@@ -16,22 +16,15 @@
package ch.ethz.mxquery.functions;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
import java.util.Enumeration;
import ch.ethz.mxquery.util.Hashtable;
import java.util.Vector;
-import org.kxml2.io.KXmlParser;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
+//import org.xmlpull.v1.XmlPullParserException;
-import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.contextConfig.Context;
import ch.ethz.mxquery.contextConfig.XQStaticContext;
-import ch.ethz.mxquery.datamodel.Namespace;
import ch.ethz.mxquery.datamodel.QName;
import ch.ethz.mxquery.datamodel.XQName;
import ch.ethz.mxquery.datamodel.types.Type;
@@ -155,35 +148,28 @@
public static FunctionGallery createFunctionGallery(XQStaticContext ctx, String resName) throws MXQueryException {
FunctionGallery fg = new FunctionGallery(ctx);
- try {
- Reader is = new InputStreamReader(fg.getClass().getResourceAsStream(resName));
- populateFunctionGallery(ctx, fg, is);
- is.close();
+ FGPopulator.populateFunctionGallery(ctx, fg, resName,"fg");
return fg;
- } catch (IOException e) {
- throw new MXQueryException(ErrorCodes.A0007_EC_IO, e, "Function Gallery could not be loaded, IO Error",null);
- } catch (XmlPullParserException e) {
- throw new MXQueryException(ErrorCodes.A0007_EC_IO, e, "Function Gallery could not be loaded, Parse Error",null);
- }
}
- public static Hashtable getModules(String id) throws MXQueryException {
- InputStreamReader is = new InputStreamReader(Context.getGlobalContext().getClass().getResourceAsStream(id));
- return getModules(is);
+ public static Hashtable getModulesRes(String id) throws MXQueryException {
+ Context temp = new Context();
+ FunctionGallery fg = new FunctionGallery(temp);
+ FGPopulator.populateFunctionGallery(temp, fg, id,"ctx");
+ return setUpModules(fg);
}
- public static Hashtable getModules(InputStreamReader is)
+ public static Hashtable getModulesFile(String fn)
throws MXQueryException {
Context temp = new Context();
FunctionGallery fg = new FunctionGallery(temp);
- try {
- populateFunctionGallery(temp, fg, is);
- } catch (XmlPullParserException e) {
- throw new MXQueryException(ErrorCodes.A0007_EC_IO, e, "Function Gallery could not be loaded, Parse Error",null);
- } catch (IOException e) {
- throw new MXQueryException(ErrorCodes.A0007_EC_IO, e, "Function Gallery could not be loaded, Parse Error",null);
- }
+ FGPopulator.populateFunctionGallery(temp, fg, fn,"file");
+ return setUpModules(fg);
+ }
+
+ static Hashtable setUpModules(FunctionGallery fg)
+ throws MXQueryException {
Hashtable mods = new Hashtable();
Enumeration elements = fg.functions.elements();
while(elements.hasMoreElements()) {
@@ -203,97 +189,7 @@
return mods;
}
- public static void populateFunctionGallery(XQStaticContext ctx,
- FunctionGallery fg, Reader is) throws XmlPullParserException,
- IOException, MXQueryException {
- KXmlParser xpp = new KXmlParser();
- xpp.setInput(is);
-
- xpp.nextTag();
- xpp.require(XmlPullParser.START_TAG, null, "functionGallery");
- String baseLoc = xpp.getAttributeValue("","basePackage");
- if (baseLoc==null)
- throw new MXQueryException(ErrorCodes.A0007_EC_IO,"Invalid Function Gallery, basePackage missing",QueryLocation.OUTSIDE_QUERY_LOC);
- xpp.nextTag();
- while (!xpp.getName().equals("functionGallery") && xpp.getEventType() != XmlPullParser.END_TAG) {
-
- xpp.require(XmlPullParser.START_TAG, null, "functionGroup");
- //Function prefix, name, and class
- String[] funcDesc = new String[3];
- funcDesc[0] = xpp.getAttributeValue("", "namespace");
- String prefix = xpp.getAttributeValue("", "prefix");
- String loc = xpp.getAttributeValue("", "loc");
- if (loc==null)
- loc=prefix;
- String[] parameters = new String[10];
- int currArity = 0;
-
- Namespace ns = ctx.getNamespace(prefix);
- if (ns == null)
- ctx.addNamespace(prefix, funcDesc[0]);
- else if (!ns.getURI().equals(funcDesc[0]))
- throw new MXQueryException(ErrorCodes.E0033_STATIC_MODULE_MULTIPLE_BINDINGS_FOR_SAME_PREFIX, "Inconsisten namespace for function/module import: "+prefix, QueryLocation.OUTSIDE_QUERY_LOC);
- xpp.nextTag();
- while (!xpp.getName().equals("functionGroup") && xpp.getEventType() != XmlPullParser.END_TAG) {
- xpp.require(XmlPullParser.START_TAG, null, "functionDescription");
- xpp.nextTag();
- String operation = null;
- TypeInfo type = null;
- while (!xpp.getName().equals("functionDescription") && xpp.getEventType() != XmlPullParser.END_TAG) {
- String elementName = xpp.getName();
- if (elementName.equals("functionName")) {
- funcDesc[1] = xpp.nextText();
- } else if (elementName.equals("parameters")) {
- xpp.nextTag();
- int i = 0;
- while (!xpp.getName().equals("parameters") && xpp.getEventType() != XmlPullParser.END_TAG){
- xpp.require(XmlPullParser.START_TAG, null, "paramType");
- elementName = xpp.getName();
- if (elementName.equals("paramType")){
- parameters[i++] = xpp.nextText();
- }
- xpp.nextTag();
- }
- currArity = i;
- } else if (elementName.equals("className")) {
- operation = xpp.getAttributeValue("", "op");
- String rawType = xpp.getAttributeValue("", "type");
- funcDesc[2] = xpp.nextText();
- if (rawType != null) {
- type = new TypeInfo(getType(rawType,ctx),getOccur(rawType));
- }
- } else {
- // element ignored
- System.out.println("element ignored!");
- }
-
- xpp.nextTag();
- }
-
- for (int i = 0; i < funcDesc.length; i++) {
- if (funcDesc[i] == null) {
- throw new IllegalArgumentException("The function description is not complete:" + funcDesc[0]
- + ":" + funcDesc[1] + ":" + funcDesc[2]);
- }
- }
-
- QName qn = new QName(funcDesc[0],prefix, funcDesc[1]);
-
- TypeInfo [] paramTypes = new TypeInfo[currArity];
- //TODO: What about the prefix and URI?
- for (int i=0;i<paramTypes.length;i++)
- paramTypes[i] = new TypeInfo(getType(parameters[i],ctx),getOccur(parameters[i]));
-
- FunctionSignature signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
- Function function = new Function(baseLoc+loc+"."+funcDesc[2],signature, null, operation, type );
- fg.add(function);
-
- xpp.nextTag();
- }
- xpp.nextTag();
- }
- }
- private static int getType(String rawType, XQStaticContext ctx) throws MXQueryException{
+ static int getType(String rawType, XQStaticContext ctx) throws MXQueryException{
//Removing the occurrence indicators
if (rawType.indexOf('*') > -1){
rawType = rawType.substring(0,rawType.indexOf("*")).trim();
@@ -329,7 +225,7 @@
}
- private static int getOccur(String rawType){
+ static int getOccur(String rawType){
if (rawType.indexOf("*") > -1){
return Type.getOccurID('*');
}else if (rawType.indexOf("+")>-1){
Copied: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java (from rev 4350, trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FunctionGallery.java)
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java 2011-05-17 10:24:14 UTC (rev 4351)
@@ -0,0 +1,6097 @@
+package ch.ethz.mxquery.functions;
+
+import java.io.IOException;
+import java.io.Reader;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.contextConfig.XQStaticContext;
+import ch.ethz.mxquery.datamodel.Namespace;
+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.model.XDMIterator;
+
+class FGPopulator {
+ public static void populateFunctionGallery(XQStaticContext ctx,
+ FunctionGallery fg, String id, String resType) throws MXQueryException {
+
+ if (resType.equals("ctx")) {
+ populateExPath(ctx, fg);
+ return;
+ }
+
+
+
+ Context context = (Context)ctx;
+ QName qn;
+ TypeInfo [] paramTypes;
+ FunctionSignature signature;
+ Function function;
+ TypeInfo type;
+ String classname;
+
+ ctx.addNamespace(XQStaticContext.NS_BROWSER,
+ XQStaticContext.URI_BROWSER);
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "js-eval");
+ paramTypes = new TypeInfo[1];
+
+ paramTypes[0] = new TypeInfo(FunctionGallery.getType(
+ "xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.JsEval iter = new ch.ethz.mxquery.functions.b.JsEval();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "timer");
+ paramTypes = new TypeInfo[2];
+
+ paramTypes[0] = new TypeInfo(FunctionGallery.getType(
+ "xs:integer",ctx),FunctionGallery.getOccur("xs:integer"),null);
+
+ paramTypes[1] = new TypeInfo(FunctionGallery.getType(
+ "QName",ctx),FunctionGallery.getOccur("QName"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.Timer iter = new ch.ethz.mxquery.functions.b.Timer();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "getCookieNames");
+ paramTypes = new TypeInfo[0];
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.GetCookieNames iter = new ch.ethz.mxquery.functions.b.GetCookieNames();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "getCookie");
+ paramTypes = new TypeInfo[1];
+
+ paramTypes[0] = new TypeInfo(FunctionGallery.getType(
+ "xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.GetCookie iter = new ch.ethz.mxquery.functions.b.GetCookie();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "removeCookie");
+ paramTypes = new TypeInfo[1];
+
+ paramTypes[0] = new TypeInfo(FunctionGallery.getType(
+ "xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.RemoveCookie iter = new ch.ethz.mxquery.functions.b.RemoveCookie();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "setCookie");
+ paramTypes = new TypeInfo[2];
+
+ paramTypes[0] = new TypeInfo(FunctionGallery.getType(
+ "xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
+
+ paramTypes[1] = new TypeInfo(FunctionGallery.getType(
+ "xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.SetCookie iter = new ch.ethz.mxquery.functions.b.SetCookie();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "setCookie");
+ paramTypes = new TypeInfo[3];
+
+ paramTypes[0] = new TypeInfo(FunctionGallery.getType(
+ "xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
+
+ paramTypes[1] = new TypeInfo(FunctionGallery.getType(
+ "xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
+
+ paramTypes[2] = new TypeInfo(FunctionGallery.getType(
+ "xs:dateTime",ctx),FunctionGallery.getOccur("xs:dateTime"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.SetCookie iter = new ch.ethz.mxquery.functions.b.SetCookie();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "pageURI");
+ paramTypes = new TypeInfo[0];
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.LocUri iter = new ch.ethz.mxquery.functions.b.LocUri();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "getLocation");
+ paramTypes = new TypeInfo[0];
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.GetLocation iter = new ch.ethz.mxquery.functions.b.GetLocation();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "log");
+ paramTypes = new TypeInfo[1];
+
+ paramTypes[0] = new TypeInfo(FunctionGallery.getType(
+ "xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.Log iter = new ch.ethz.mxquery.functions.b.Log();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "alert");
+ paramTypes = new TypeInfo[1];
+
+ paramTypes[0] = new TypeInfo(FunctionGallery.getType(
+ "xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.Alert iter = new ch.ethz.mxquery.functions.b.Alert();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "removeClass");
+ paramTypes = new TypeInfo[2];
+
+ paramTypes[0] = new TypeInfo(FunctionGallery.getType(
+ "node()+",ctx),FunctionGallery.getOccur("node()+"),null);
+
+ paramTypes[1] = new TypeInfo(FunctionGallery.getType(
+ "xs:string",ctx),FunctionGallery.getOccur("xs:string"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.RemoveClassName iter = new ch.ethz.mxquery.functions.b.RemoveClassName();
+ iter.setContext(context, false);
+
+ type = null;
+
+ function = new Function(
+ null,signature,
+ iter, null, type );
+ fg.add(function);
+ }
+
+ qn = new QName(
+ "http://xqib.org",
+ "b",
+ "getClasses");
+ paramTypes = new TypeInfo[1];
+
+ paramTypes[0] = new TypeInfo(FunctionGallery.getType(
+ "node()+",ctx),FunctionGallery.getOccur("node()+"),null);
+
+ signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+
+
+ {
+ ch.ethz.mxquery.functions.b.GetClasses iter = new ch.ethz.mxquery.functions.b.GetClasses();
+ ...
[truncated message content] |
|
From: <pm_...@us...> - 2011-05-18 10:11:51
|
Revision: 4353
http://mxquery.svn.sourceforge.net/mxquery/?rev=4353&view=rev
Author: pm_fischer
Date: 2011-05-18 10:11:44 +0000 (Wed, 18 May 2011)
Log Message:
-----------
For SAX parsing, disable namespace-prefixes-mode
1) Not available on Android
2) Cleaner namespace scope handling by using SAX callbacks
Android IOLib now works
Modified Paths:
--------------
trunk/MXQuery/android/src/ch/ethz/mxquery/util/IOLib.java
trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/NonSchemaValidatingSaxImportAdapter.java
trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/XDMImportAdapter.java
Modified: trunk/MXQuery/android/src/ch/ethz/mxquery/util/IOLib.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/util/IOLib.java 2011-05-17 10:42:00 UTC (rev 4352)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/util/IOLib.java 2011-05-18 10:11:44 UTC (rev 4353)
@@ -38,6 +38,7 @@
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
+import ch.ethz.mxquery.util.Utils;
public class IOLib {
@@ -166,6 +167,12 @@
if (encoding == null)
encoding = "utf-8";
InputStream ins = null;
+ //android-specific treatment of local/file URIs:
+ //Strip all but the the last part
+ if (toOpen.startsWith("file:/")||toOpen.indexOf(":") < 0) {
+ String [] parts = Utils.split(toOpen, "/", true);
+ toOpen = parts[parts.length-1];
+ }
URI uri;
try {
uri = new URI(toOpen);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/NonSchemaValidatingSaxImportAdapter.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/NonSchemaValidatingSaxImportAdapter.java 2011-05-17 10:42:00 UTC (rev 4352)
+++ trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/NonSchemaValidatingSaxImportAdapter.java 2011-05-18 10:11:44 UTC (rev 4353)
@@ -1,521 +1,547 @@
-/* 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.xmlAdapters;
-
-import java.io.IOException;
-import java.util.Properties;
-import java.util.Vector;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.ext.DeclHandler;
-import org.xml.sax.ext.LexicalHandler;
-import org.xml.sax.helpers.DefaultHandler;
-
-import ch.ethz.mxquery.contextConfig.Context;
-import ch.ethz.mxquery.datamodel.QName;
-import ch.ethz.mxquery.datamodel.XQName;
-import ch.ethz.mxquery.datamodel.types.Type;
-import ch.ethz.mxquery.datamodel.xdm.CommentToken;
-import ch.ethz.mxquery.datamodel.xdm.ElementToken;
-import ch.ethz.mxquery.datamodel.xdm.NamedToken;
-import ch.ethz.mxquery.datamodel.xdm.ProcessingInstrToken;
-import ch.ethz.mxquery.datamodel.xdm.TextToken;
-import ch.ethz.mxquery.datamodel.xdm.Token;
-import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
-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.model.XDMIterator;
-import ch.ethz.mxquery.util.Utils;
-
-public class NonSchemaValidatingSaxImportAdapter extends XDMImportAdapter {
-
-
- SaxAdapter adapter;
- ParseWorker worker;
- MXQueryException parseException = null;
- protected InputSource tobeParsed;
-
- Vector tokens;
- TokenInterface [] currBulk;
- int bulkPos = 0;
- private static final int TOKENBLOCKSIZE = 100;
- private static final int PARSED_BLOCKS_WAITING = 10;
- int validationMode;
- boolean tidyInput;
- private boolean done = false;
-
-
- class SaxAdapter extends DefaultHandler implements LexicalHandler, DeclHandler{
-
- private boolean startCData;
-
- private XMLReader reader;
-
- private boolean inDTD = false;
-
- private StringBuffer pendingTextContent = new StringBuffer();
- TokenInterface [] currToPush = new TokenInterface[TOKENBLOCKSIZE];
- int blockPos = 0;
-
- public SaxAdapter(XMLReader source) {
- reader = source;
- }
-
- public void parse() throws SAXException, IOException,MXQueryException {
- try {
- if (reader == null) {
- String saxParser = System.getProperty("javax.xml.parsers.SAXParserFactory");
- if (tidyInput) {
- System.setProperty("javax.xml.parsers.SAXParserFactory", "org.ccil.cowan.tagsoup.jaxp.SAXFactoryImpl");
- } else
- System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
-
- SAXParserFactory spf = SAXParserFactory.newInstance();
- if (saxParser != null)
- System.setProperty("javax.xml.parsers.SAXParserFactory", saxParser);
- else {
- // use indirect way, since clearProperties is not available in 1.4
- Properties sysProps = System.getProperties();
- sysProps.remove("javax.xml.parsers.SAXParserFactory");
- }
-
- //if (!tidyInput) {
- spf.setNamespaceAware(true);
- spf.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
- //} else {
- // spf.setFeature("http://xml.org/sax/features/namespaces",false);
- //}
- if (validationMode == Context.DTD_VALIDATION) {
- spf.setFeature("http://xml.org/sax/features/validation", true);
- spf.setFeature("http://apache.org/xml/features/validation/dynamic", true);
- } else if (validationMode == Context.IGNORE_DTD){
- spf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar",false);
- spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false);
- }
-
- SAXParser parser = spf.newSAXParser();
- reader = parser.getXMLReader();
- }
- reader.setErrorHandler(this);
- reader.setProperty("http://xml.org/sax/properties/lexical-handler", this);
- if (validationMode == Context.DTD_VALIDATION) {
- reader.setProperty("http://xml.org/sax/properties/declaration-handler", this);
- }
- // reader.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", context.initDictionary().getSchemaLocations());
- reader.setContentHandler(this);
- if (tobeParsed != null)
- reader.parse(tobeParsed);
- else
- reader.parse((String)null);
- } catch (SAXException e) {
- throw new DynamicException(ErrorCodes.A0007_EC_IO,"Error creating validating input: "+e.toString(),loc);
- } catch (ParserConfigurationException e) {
- throw new MXQueryException(ErrorCodes.A0002_EC_NOT_SUPPORTED,"Error creating validating input - parser configuration error",loc);
- }
- }
-
- private void addToken(TokenInterface tok) throws SAXException{
- currToPush[blockPos++] = tok;
- if (blockPos == currToPush.length || tok == Token.END_SEQUENCE_TOKEN) {
- synchronized(tokens) {
- while (tokens.size() > PARSED_BLOCKS_WAITING)
- try {
- tokens.wait();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- throw new SAXException("Stop worker thread");
- }
- tokens.add(currToPush);
- tokens.notify();
- }
- currToPush = new TokenInterface[TOKENBLOCKSIZE];
- blockPos = 0;
- }
- }
-
- public void processingInstruction(String target, String data) throws SAXException {
- emitPendingTextContent();
- try {
- addToken(new ProcessingInstrToken(createNextTokenId(Type.PROCESSING_INSTRUCTION,null), data, target,curNsScope));
- } catch (MXQueryException e) {
- e.printStackTrace();
- }
- }
-
- public void startDocument() throws SAXException {
- emitPendingTextContent();
- addToken(new Token(Type.START_DOCUMENT, createNextTokenId(Type.START_DOCUMENT,null),curNsScope));
- if (getURI() != null)
- curNsScope.setBaseURI(getURI());
- //level++;
- }
-
- public void endDocument() throws SAXException {
- emitPendingTextContent();
- addToken(new Token(Type.END_DOCUMENT, null,curNsScope));
- addToken(Token.END_SEQUENCE_TOKEN);
- level--;
- }
-
- /** Start element. */
- public void startElement(String uri, String localName, String qname, Attributes attributes) throws SAXException {
- emitPendingTextContent();
- level++;
- Vector myToks = new Vector();
- boolean foundId = false;
- boolean foundIdREFS = false;
-
- String xmlId = null;
- String [] xmlIdREFS = null;
-
- String prefix = null;
- String localPart;
- boolean createdNSScope = false;
- int splitPos = qname.indexOf(':');
- if (splitPos > 0) {
- prefix = qname.substring(0,splitPos);
- localPart = qname.substring(splitPos+1);
- } else
- localPart = qname;
- XQName qName = new QName(uri, prefix, localPart);
- NamedToken token = new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG,qName.toString()), qName, curNsScope);
- myToks.add(token);
-
- for (int i = 0; i < attributes.getLength(); i++) {
- int type;
- boolean setID = false;
- type = Type.UNTYPED_ATOMIC; //TODO: DTD types annotation, e.g. ID?
-
- try {
- QName attQname = new QName(attributes.getQName(i));
- String attVal = attributes.getValue(i);
-
- if (!foundId && (type == Type.ID || isXMLId(attQname,qName))) {
- foundId = true;
- xmlId = attVal;
- }
- if (!foundIdREFS && (type == Type.IDREF || isIDREF(attQname,qName))) {
- foundIdREFS = true;
- xmlIdREFS = new String[]{attVal};
- }
-
- if (!foundIdREFS && (type == Type.IDREFS || isIDREFS(attQname,qName))) {
- foundIdREFS = true;
- xmlIdREFS = Utils.split(attVal," ", false);
- }
-
-
- boolean newOpened = checkOpenNsScopeAddNs(createdNSScope, attQname, attVal);
- if (newOpened && !createdNSScope)
- myToks.setElementAt(new ElementToken(Type.START_TAG, token.getNodeId(), qName, curNsScope), 0);
-
- if (attQname.getNamespacePrefix() == null || attQname.getNamespacePrefix().equals("")) {
- if (attQname.getLocalPart().equals("xmlns"))
- continue;
- } else if (attQname.getNamespacePrefix().equals("xmlns"))
- continue;
-
- attQname.setNamespaceURI(attributes.getURI(i));
- NamedToken attToken = createAttributeToken(type, attributes.getValue(i), attQname, curNsScope);
- if (foundId && !setID){
- attToken.setID(xmlId);
- setID = true;
- }
- if (foundIdREFS){
- attToken.setIDREFS(xmlIdREFS);
- foundIdREFS = false;
- }
- myToks.add(attToken);
- } catch (MXQueryException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if (level < 2 && uri != null && localName.equals(qname)&& !createdNSScope) {
- try {
- checkOpenNsScopeAddNs(createdNSScope, new QName(Context.NS_XMLNS), uri);
- myToks.setElementAt(new ElementToken(Type.START_TAG, token.getNodeId(), qName, curNsScope), 0);
- } catch (MXQueryException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
-
- if (foundId) {
- NamedToken nmToken = (NamedToken)myToks.elementAt(0);
- nmToken.setID(xmlId);
- }
- for (int i=0;i<myToks.size();i++) {
- addToken((TokenInterface)myToks.elementAt(i));
- }
- } // startElement(String,String,String,Attributes)
-
-
- /** End element. */
- public void endElement(String uri, String localName, String qname) throws SAXException {
- emitPendingTextContent();
- String prefix = null;
- String localPart;
- //String[] qNameParts = qname.split(":");
- int splitPos = qname.indexOf(':');
- if (splitPos > 0) {
- prefix = qname.substring(0,splitPos);
- localPart = qname.substring(splitPos+1);
- } else
- localPart = qname;
-
- XQName qName = new QName(uri, prefix, localPart);
- NamedToken token = new ElementToken(Type.END_TAG, null, qName, curNsScope);
- addToken(token);
- checkCloseNsScope();
- level--;
- } // endElement(String,String,String)
-
- public void ignorableWhitespace(char[] ch, int start, int length)
- throws SAXException {
- characters(ch, start, length);
- }
-
- private void emitPendingTextContent() throws SAXException{
- if (pendingTextContent.length() > 0) {
- int type = Type.TEXT_NODE_UNTYPED_ATOMIC;
- try {
- addToken(new TextToken(type,createNextTokenId(type,null), pendingTextContent.toString(), curNsScope));
- } catch (MXQueryException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- pendingTextContent = new StringBuffer();
- }
-
- }
- public void characters(char[] ch, int start, int length) throws SAXException {
-
-// for (int i = start; i < start + length; i++) {
-// text.append(ch[i]);
-// }
- int type = Type.TEXT_NODE_UNTYPED_ATOMIC;
- if (startCData) {
- emitPendingTextContent();
- try {
- addToken(new TextToken(type,createNextTokenId(type,null), new String(ch,start,length), curNsScope));
- }catch (MXQueryException e) {
- throw new SAXException(e.toString());
- }
-
- } else {
- pendingTextContent.append(ch,start,length);
- }
- }
-
- public void error(SAXParseException e) throws SAXException {
- throw e;
- }
-
- public void fatalError(SAXParseException e) throws SAXException {
- throw e;
- }
-
- public void warning(SAXParseException e) throws SAXException {
- System.out.println("Warning: " + e.getMessage());
- }
-
- public void comment(char[] ch, int start, int end) throws SAXException {
- emitPendingTextContent();
- if (!inDTD) {
- // only take comments from the main file, not from the DTD
- String text = new String(ch, start, end);
- try {
- addToken(new CommentToken(createNextTokenId(Type.COMMENT,null), text,curNsScope));
- } catch (DynamicException e) {
- throw new SAXException(e);
- }
- }
- }
-
- public void endCDATA() throws SAXException {
- startCData = false;
- }
-
- public void endDTD() throws SAXException {
- inDTD = false;
- }
-
- public void endEntity(String arg0) throws SAXException {
- //System.out.println("Entity ended");
- }
-
- public void startCDATA() throws SAXException {
- startCData = true;
- }
-
- public void startDTD(String name, String publicID, String systemID) throws SAXException {
- systemid = systemID;
- publicid = publicID;
- dtdRootElem = name;
- inDTD = true;
- }
-
- public void startEntity(String arg0) throws SAXException {
- //System.out.println("Entitiy started "+arg0);
- }
-
- public void attributeDecl(String name, String name2, String type,String mode, String value) throws SAXException {
- if (type.equals("ID"))idsVector.add(name+"#"+name2);
- if (type.equals("IDREF")) idRefVector.add(name+"#"+name2);
- if (type.equals("IDREFS")) idRefsVector.add(name+"#"+name2);
- }
-
- public void elementDecl(String name, String model) throws SAXException {
- //System.out.println("element decl"+model);
- }
-
- public void externalEntityDecl(String name, String publicId,
- String systemId) throws SAXException {
-// System.out.println("external decl");
-
- }
-
- public void internalEntityDecl(String name, String value)
- throws SAXException {
- // System.out.println("internal decl");
-
- }
- }
-
-
- class ParseWorker extends Thread {
- Vector tokens;
- SaxAdapter adapter;
-
- public ParseWorker(Vector tokens, SaxAdapter adapter) {
- super();
- this.tokens = tokens;
- this.adapter = adapter;
- }
-
- public void run() {
- try {
- adapter.parse();
- }
- catch (SAXException e) {
- String message = e.getMessage();
- parseException = new DynamicException(ErrorCodes.E0027_DYNAMIC_VALIDATE_UNEXPECTED_VALIDITY, message, loc);
- synchronized(tokens) {
- tokens.notify();
- }
-
- } catch (IOException e) {
- parseException = new MXQueryException(ErrorCodes.A0007_EC_IO,"I/O Error while parsing: "+e.toString(),loc);
- synchronized(tokens) {
- tokens.notify();
- }
- } catch (MXQueryException e) {
- parseException = e;
- synchronized(tokens) {
- tokens.notify();
- }
- }
- }
- }
-
- public NonSchemaValidatingSaxImportAdapter(Context ctx, QueryLocation loc,InputSource xml, int validationMode, boolean tidyInput) {
- super(ctx,loc);
- adapter= new SaxAdapter(null);
- this.tokens = new Vector();
- tobeParsed = xml;
- this.tidyInput = tidyInput;
- this.validationMode= validationMode;
- }
-
- public NonSchemaValidatingSaxImportAdapter(Context ctx, QueryLocation loc,XMLReader source) {
- super(ctx,loc);
- adapter= new SaxAdapter(source);
- this.tokens = new Vector();
- }
-
- protected void init() throws MXQueryException {
- worker = new ParseWorker(tokens, adapter);
- worker.start();
- }
-
- protected XDMIterator copy(Context context, XDMIterator[] subIters, Vector nestedPredCtxStack) throws MXQueryException {
- XDMImportAdapter res = new NonSchemaValidatingSaxImportAdapter(this.context, loc,tobeParsed, validationMode, false);
- res.uri = uri;
- return res;
- }
- public TokenInterface next() throws MXQueryException {
- if (called == 0) {
- init();
- called++;
- getBulkFromQueue();
- }
- if (done)
- return Token.END_SEQUENCE_TOKEN;
- if (bulkPos == currBulk.length)
- getBulkFromQueue();
- TokenInterface tok = currBulk[bulkPos++];
- if (tok == Token.END_SEQUENCE_TOKEN)
- done = true;
- return tok;
- }
-
- private void getBulkFromQueue() throws MXQueryException {
- synchronized(tokens) {
- while (tokens.isEmpty() && parseException == null) {
- try {
- tokens.wait();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if (parseException != null)
- throw parseException;
- currBulk = (TokenInterface[])tokens.remove(0);
- bulkPos = 0;
- tokens.notify();
- }
- }
-
-
- protected void resetImpl() throws MXQueryException {
- super.resetImpl();
- done = false;
- worker.interrupt();
- }
-
- protected void freeResources(boolean restartable)
- throws MXQueryException {
- // TODO Auto-generated method stub
- super.freeResources(restartable);
- if (worker != null)
- worker.interrupt();
- }
-
-
-}
+/* 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.xmlAdapters;
+
+import java.io.IOException;
+import java.util.Properties;
+import java.util.Vector;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.ext.DeclHandler;
+import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.helpers.DefaultHandler;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.Namespace;
+import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.datamodel.XQName;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.xdm.CommentToken;
+import ch.ethz.mxquery.datamodel.xdm.ElementToken;
+import ch.ethz.mxquery.datamodel.xdm.NamedToken;
+import ch.ethz.mxquery.datamodel.xdm.ProcessingInstrToken;
+import ch.ethz.mxquery.datamodel.xdm.TextToken;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.datamodel.xdm.XDMScope;
+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.model.XDMIterator;
+import ch.ethz.mxquery.util.Utils;
+
+public class NonSchemaValidatingSaxImportAdapter extends XDMImportAdapter {
+
+
+ SaxAdapter adapter;
+ ParseWorker worker;
+ MXQueryException parseException = null;
+ protected InputSource tobeParsed;
+
+ Vector tokens;
+ TokenInterface [] currBulk;
+ int bulkPos = 0;
+ private static final int TOKENBLOCKSIZE = 100;
+ private static final int PARSED_BLOCKS_WAITING = 10;
+ int validationMode;
+ boolean tidyInput;
+ private boolean done = false;
+
+
+ class SaxAdapter extends DefaultHandler implements LexicalHandler, DeclHandler{
+
+ private boolean startCData;
+
+ private XMLReader reader;
+
+ private boolean inDTD = false;
+
+ private StringBuffer pendingTextContent = new StringBuffer();
+ TokenInterface [] currToPush = new TokenInterface[TOKENBLOCKSIZE];
+ int blockPos = 0;
+
+ public SaxAdapter(XMLReader source) {
+ reader = source;
+ }
+
+ public void parse() throws SAXException, IOException,MXQueryException {
+ try {
+ if (reader == null) {
+ String saxParser = System.getProperty("javax.xml.parsers.SAXParserFactory");
+ if (tidyInput) {
+ System.setProperty("javax.xml.parsers.SAXParserFactory", "org.ccil.cowan.tagsoup.jaxp.SAXFactoryImpl");
+ } else
+ System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
+
+ SAXParserFactory spf = SAXParserFactory.newInstance();
+ if (saxParser != null)
+ System.setProperty("javax.xml.parsers.SAXParserFactory", saxParser);
+ else {
+ // use indirect way, since clearProperties is not available in 1.4
+ Properties sysProps = System.getProperties();
+ sysProps.remove("javax.xml.parsers.SAXParserFactory");
+ }
+
+ //if (!tidyInput) {
+ spf.setNamespaceAware(true);
+ //spf.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
+ //} else {
+ // spf.setFeature("http://xml.org/sax/features/namespaces",false);
+ //}
+ if (validationMode == Context.DTD_VALIDATION) {
+ spf.setFeature("http://xml.org/sax/features/validation", true);
+ spf.setFeature("http://apache.org/xml/features/validation/dynamic", true);
+ } else if (validationMode == Context.IGNORE_DTD){
+ spf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar",false);
+ spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false);
+ }
+
+ SAXParser parser = spf.newSAXParser();
+ reader = parser.getXMLReader();
+ }
+ reader.setErrorHandler(this);
+ reader.setProperty("http://xml.org/sax/properties/lexical-handler", this);
+ if (validationMode == Context.DTD_VALIDATION) {
+ reader.setProperty("http://xml.org/sax/properties/declaration-handler", this);
+ }
+ // reader.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", context.initDictionary().getSchemaLocations());
+ reader.setContentHandler(this);
+ if (tobeParsed != null)
+ reader.parse(tobeParsed);
+ else
+ reader.parse((String)null);
+ } catch (SAXException e) {
+ throw new DynamicException(ErrorCodes.A0007_EC_IO,"Error creating validating input: "+e.toString(),loc);
+ } catch (ParserConfigurationException e) {
+ throw new MXQueryException(ErrorCodes.A0002_EC_NOT_SUPPORTED,"Error creating validating input - parser configuration error",loc);
+ }
+ }
+
+ private void addToken(TokenInterface tok) throws SAXException{
+ currToPush[blockPos++] = tok;
+ if (blockPos == currToPush.length || tok == Token.END_SEQUENCE_TOKEN) {
+ synchronized(tokens) {
+ while (tokens.size() > PARSED_BLOCKS_WAITING)
+ try {
+ tokens.wait();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ throw new SAXException("Stop worker thread");
+ }
+ tokens.add(currToPush);
+ tokens.notify();
+ }
+ currToPush = new TokenInterface[TOKENBLOCKSIZE];
+ blockPos = 0;
+ }
+ }
+
+ public void processingInstruction(String target, String data) throws SAXException {
+ emitPendingTextContent();
+ try {
+ addToken(new ProcessingInstrToken(createNextTokenId(Type.PROCESSING_INSTRUCTION,null), data, target,curNsScope));
+ } catch (MXQueryException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void startDocument() throws SAXException {
+ emitPendingTextContent();
+ addToken(new Token(Type.START_DOCUMENT, createNextTokenId(Type.START_DOCUMENT,null),curNsScope));
+ if (getURI() != null)
+ curNsScope.setBaseURI(getURI());
+ //level++;
+ }
+
+ public void endDocument() throws SAXException {
+ emitPendingTextContent();
+ addToken(new Token(Type.END_DOCUMENT, null,curNsScope));
+ addToken(Token.END_SEQUENCE_TOKEN);
+ level--;
+ }
+
+ /** Start element. */
+ public void startElement(String uri, String localName, String qname, Attributes attributes) throws SAXException {
+ emitPendingTextContent();
+ level++;
+ Vector myToks = new Vector();
+ boolean foundId = false;
+ boolean foundIdREFS = false;
+
+ String xmlId = null;
+ String [] xmlIdREFS = null;
+
+ String prefix = null;
+ String localPart;
+ boolean createdNSScope = false;
+ int splitPos = qname.indexOf(':');
+ if (splitPos > 0) {
+ prefix = qname.substring(0,splitPos);
+ localPart = qname.substring(splitPos+1);
+ } else
+ localPart = qname;
+ XQName qName = new QName(uri, prefix, localPart);
+ NamedToken token = new ElementToken(Type.START_TAG, createNextTokenId(Type.START_TAG,qName.toString()), qName, curNsScope);
+ myToks.add(token);
+
+ for (int i = 0; i < attributes.getLength(); i++) {
+ int type;
+ boolean setID = false;
+ type = Type.UNTYPED_ATOMIC; //TODO: DTD types annotation, e.g. ID?
+
+ try {
+ QName attQname = new QName(attributes.getQName(i));
+ String attVal = attributes.getValue(i);
+
+ if (!foundId && (type == Type.ID || isXMLId(attQname,qName))) {
+ foundId = true;
+ xmlId = attVal;
+ }
+ if (!foundIdREFS && (type == Type.IDREF || isIDREF(attQname,qName))) {
+ foundIdREFS = true;
+ xmlIdREFS = new String[]{attVal};
+ }
+
+ if (!foundIdREFS && (type == Type.IDREFS || isIDREFS(attQname,qName))) {
+ foundIdREFS = true;
+ xmlIdREFS = Utils.split(attVal," ", false);
+ }
+
+
+ boolean newOpened = checkOpenNsScopeAddNs(createdNSScope, attQname, attVal);
+ //boolean newOpened = false;
+ if (newOpened && !createdNSScope)
+ myToks.setElementAt(new ElementToken(Type.START_TAG, token.getNodeId(), qName, curNsScope), 0);
+
+ if (attQname.getNamespacePrefix() == null || attQname.getNamespacePrefix().equals("")) {
+ if (attQname.getLocalPart().equals("xmlns"))
+ continue;
+ } else if (attQname.getNamespacePrefix().equals("xmlns"))
+ continue;
+
+ attQname.setNamespaceURI(attributes.getURI(i));
+ NamedToken attToken = createAttributeToken(type, attributes.getValue(i), attQname, curNsScope);
+ if (foundId && !setID){
+ attToken.setID(xmlId);
+ setID = true;
+ }
+ if (foundIdREFS){
+ attToken.setIDREFS(xmlIdREFS);
+ foundIdREFS = false;
+ }
+ myToks.add(attToken);
+ } catch (MXQueryException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+// if (level < 2 && uri != null && localName.equals(qname)&& !createdNSScope) {
+// try {
+// //checkOpenNsScopeAddNs(createdNSScope, new QName(Context.NS_XMLNS), uri);
+// //myToks.setElementAt(new ElementToken(Type.START_TAG, token.getNodeId(), qName, curNsScope), 0);
+// } catch (MXQueryException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+// }
+
+
+ if (foundId) {
+ NamedToken nmToken = (NamedToken)myToks.elementAt(0);
+ nmToken.setID(xmlId);
+ }
+ for (int i=0;i<myToks.size();i++) {
+ addToken((TokenInterface)myToks.elementAt(i));
+ }
+ } // startElement(String,String,String,Attributes)
+
+
+ /** End element. */
+ public void endElement(String uri, String localName, String qname) throws SAXException {
+ emitPendingTextContent();
+ String prefix = null;
+ String localPart;
+ //String[] qNameParts = qname.split(":");
+ int splitPos = qname.indexOf(':');
+ if (splitPos > 0) {
+ prefix = qname.substring(0,splitPos);
+ localPart = qname.substring(splitPos+1);
+ } else
+ localPart = qname;
+
+ XQName qName = new QName(uri, prefix, localPart);
+ NamedToken token = new ElementToken(Type.END_TAG, null, qName, curNsScope);
+ addToken(token);
+ checkCloseNsScope();
+ level--;
+ } // endElement(String,String,String)
+
+ public void ignorableWhitespace(char[] ch, int start, int length)
+ throws SAXException {
+ characters(ch, start, length);
+ }
+
+ private void emitPendingTextContent() throws SAXException{
+ if (pendingTextContent.length() > 0) {
+ int type = Type.TEXT_NODE_UNTYPE...
[truncated message content] |
|
From: <et...@us...> - 2011-05-19 20:58:30
|
Revision: 4358
http://mxquery.svn.sourceforge.net/mxquery/?rev=4358&view=rev
Author: etterth
Date: 2011-05-19 20:58:22 +0000 (Thu, 19 May 2011)
Log Message:
-----------
- Removed dependency on third party tidy library.
- New tidy function uses iframes with document.write to use the browser's integrated parser (drawback: js code in the document will be executed)
Modified Paths:
--------------
trunk/MXQuery/xqib_NOTICE
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/MXQueryJS.gwt.xml
trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
Added Paths:
-----------
trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HtmlParser.java
Removed Paths:
-------------
trunk/MXQuery/xqib_src/nu/
Modified: trunk/MXQuery/xqib_NOTICE
===================================================================
--- trunk/MXQuery/xqib_NOTICE 2011-05-19 18:41:47 UTC (rev 4357)
+++ trunk/MXQuery/xqib_NOTICE 2011-05-19 20:58:22 UTC (rev 4358)
@@ -13,103 +13,4 @@
- Apache Software Foundation (Java helper classes, Xerces)
- Robert Hanson (Regular Expressions from GWT widgets) for XQIB-JS
- GWT calendar project (time and calendar support) for XQIB-JS
- - Validator.nu HTML Parser for XQIB-JS
-License for Validator.nu HTML Parser:
-
-This is for the HTML parser as a whole except the rewindable input stream,
-the named character classes and the Live DOM Viewer.
-For the copyright notices for individual files, please see individual files.
-
-/*
- * Copyright (c) 2005, 2006, 2007 Henri Sivonen
- * Copyright (c) 2007-2011 Mozilla Foundation
- * Portions of comments Copyright 2004-2007 Apple Computer, Inc., Mozilla
- * Foundation, and Opera Software ASA.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-The following license is for the WHATWG spec from which the named character
-data was extracted.
-
-/*
- * Copyright 2004-2010 Apple Computer, Inc., Mozilla Foundation, and Opera
- * Software ASA.
- *
- * You are granted a license to use, reproduce and create derivative works of
- * this document.
- */
-
-The following license is for the rewindable input stream.
-
-/*
- * Copyright (c) 2001-2003 Thai Open Source Software Center Ltd
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * * Neither the name of the Thai Open Source Software Center Ltd nor
- * the names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-The following license applies to the Live DOM Viewer:
-
-Copyright (c) 2000, 2006, 2008 Ian Hickson and various contributors
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/MXQueryJS.gwt.xml
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/MXQueryJS.gwt.xml 2011-05-19 18:41:47 UTC (rev 4357)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/MXQueryJS.gwt.xml 2011-05-19 20:58:22 UTC (rev 4358)
@@ -15,7 +15,6 @@
<inherits name="ch.ethz.mxquery"/>
<inherits name="java"/>
<inherits name="com.google.gwt.xml.XML" />
-<inherits name="nu.validator.htmlparser.HtmlParser" />
<!-- <inherits name="nu.validator.htmlparser.HtmlParser" /> -->
<!-- <set-property name="user.agent" value="ie6" /> -->
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HtmlParser.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HtmlParser.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HtmlParser.java 2011-05-19 20:58:22 UTC (rev 4358)
@@ -0,0 +1,20 @@
+package ch.ethz.mxquery.extensionsModules.expathhttp;
+
+import ch.ethz.mxquery.util.browser.dom.Document;
+
+public class HtmlParser {
+ public static Document tidyAndParse(String html){
+ return nativeTidyAndParse(html);
+ }
+
+ static protected native Document nativeTidyAndParse(String html)/*-{
+ var a = $doc.createElement('iframe');
+ a.style.visibility = 'hidden';
+ $doc.documentElement.appendChild(a);
+ a.contentWindow.document.write(html);
+ var doc = a.contentWindow.document;
+ a.parentNode.removeChild(a);
+ return doc;
+ }-*/;
+
+}
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-19 18:41:47 UTC (rev 4357)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java 2011-05-19 20:58:22 UTC (rev 4358)
@@ -22,8 +22,6 @@
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.IFrameElement;
-import nu.validator.htmlparser.gwt.HtmlParser;
-
import ch.ethz.mxqjs.client.Environment;
import ch.ethz.mxqjs.client.QnameAndArity;
import ch.ethz.mxquery.bindings.WindowFactory;
@@ -770,19 +768,14 @@
// Document doc = DOMImpl.impl.getIFrameDocument(iframe);
// doc.write(conn.responseAsString());
- Document doc = Document.createDocument();
+// Document doc = Document.createDocument();
// Element el = doc.getAsGwtDocument().getDocumentElement();
// el.removeFromParent();
// el = doc.getAsGwtDocument().getDocumentElement();
- nu.validator.htmlparser.gwt.HtmlParser tidyparser = new HtmlParser(doc);
- try {
- tidyparser.parse(conn.responseAsString(), null);
- } catch (SAXException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+// HtmlParser tidyparser = new HtmlParser(doc);
+ Document doc = HtmlParser.tidyAndParse(conn.responseAsString());
+
-
resIts[resIts.length - 1] = new NodeStoreIterator(
doc);
// Element el = doc.getAsGwtDocument().getDocumentElement();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-05-22 11:10:28
|
Revision: 4361
http://mxquery.svn.sourceforge.net/mxquery/?rev=4361&view=rev
Author: etterth
Date: 2011-05-22 11:10:21 +0000 (Sun, 22 May 2011)
Log Message:
-----------
- Refactored NativeFunctionImporter to allow support for different languages
Modified Paths:
--------------
trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
Added Paths:
-----------
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-19 21:50:35 UTC (rev 4360)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-22 11:10:21 UTC (rev 4361)
@@ -9,8 +9,13 @@
public class NativeFunctionImporter {
- public static Context getNativeMethods(String className) throws MXQueryException{
+ public static Context getNativeMethods(String uri) throws MXQueryException{
+ String className = uri.substring(5);
Context ctx = new Context();
throw new MXQueryException(ErrorCodes.A0002_EC_NOT_SUPPORTED, "Import of native methods not supported", QueryLocation.OUTSIDE_QUERY_LOC);
}
+
+ public static boolean isNativeUri(String uri) {
+ return uri.startsWith("java:");
+ }
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-19 21:50:35 UTC (rev 4360)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-22 11:10:21 UTC (rev 4361)
@@ -1,219 +1,21 @@
package ch.ethz.mxquery.functions;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-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{
+ public static Context getNativeMethods(String uri) throws MXQueryException{
+ String className = uri.substring(5);
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);
- }
- }
- }
-
- }
- }
-
- Field [] fields = toImport.getFields();
-
- for (int i=0;i<fields.length;i++) {
- Field cur = fields[i];
- int mod = cur.getModifiers();
- if (Modifier.isPublic(mod)) {
- String name = cur.getName();
- TypeInfo[] params;
- if (Modifier.isStatic(mod)) {
- params = new TypeInfo[0];
- }
- else {
- params = new TypeInfo[1];
- params[0] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
- }
- TypeInfo resultType = getXQueryType(cur.getType());
- MethodData md = new MethodData(toImport, name, params, resultType);
- if (!functions.containsKey(md))
- functions.put(md,md);
- }
- }
-
- 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, null);
- 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;
+ throw new MXQueryException(ErrorCodes.A0002_EC_NOT_SUPPORTED, "Import of native methods not supported", QueryLocation.OUTSIDE_QUERY_LOC);
}
- 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.CharSequence"))
- 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);
- }
+ public static boolean isNativeUri(String uri) {
+ return uri.startsWith("java:");
+ }
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-05-19 21:50:35 UTC (rev 4360)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-05-22 11:10:21 UTC (rev 4361)
@@ -940,8 +940,8 @@
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));
+ if (NativeFunctionImporter.isNativeUri(uri)) {
+ Context javamod = NativeFunctionImporter.getNativeMethods(uri);
importModuleFunctionsVariables(uri, name, javamod);
}
declaredNamespaces.add(name);
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/NativeFunctionImporter.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-22 11:10:21 UTC (rev 4361)
@@ -0,0 +1,21 @@
+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 uri) throws MXQueryException{
+ String className = uri.substring(5);
+ Context ctx = new Context();
+ throw new MXQueryException(ErrorCodes.A0002_EC_NOT_SUPPORTED, "Import of native methods not supported", QueryLocation.OUTSIDE_QUERY_LOC);
+ }
+
+ public static boolean isNativeUri(String uri) {
+ return uri.startsWith("java:");
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-05-24 13:32:31
|
Revision: 4366
http://mxquery.svn.sourceforge.net/mxquery/?rev=4366&view=rev
Author: pm_fischer
Date: 2011-05-24 13:32:19 +0000 (Tue, 24 May 2011)
Log Message:
-----------
annotation (e..g, %private, %updating) support: definitions, tests and helper structures
Modified Paths:
--------------
trunk/MXQuery/android/src/ch/ethz/mxquery/query/parser/SchemaParser.java
trunk/MXQuery/midp_src/ch/ethz/mxquery/query/webservice/WSDLHandler.java
trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java
trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/XQStaticContext.java
trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/TypeInfo.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/FGPopulator.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/Function.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionSignature.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Filter.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Fold.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Map.java
trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/MapPairs.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/SequenceTypeIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/model/VariableHolder.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/SchemaParser.java
trunk/MXQuery/src/ch/ethz/mxquery/query/webservice/WSDLHandler.java
trunk/MXQuery/src/examples/ExternalFunctionExample.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/Function.java
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/xq11streaming/MiscTests.java
Added Paths:
-----------
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-func.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-import-default.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-import-defaultvar.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-import-private.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-import-privatevar.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-import-public.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-import-publicvar.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-missing-literal.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-module.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-nondet-UDT.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-nondet-func.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-nondet-sequential-func.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-privateprivatefunc.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-privatepublicfunc.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-publicpublicfunc.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-unknown-namespace.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/annotations-var.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/functest-deterministic-builtin.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/functest-deterministic-external-nondet-coercion.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/functest-deterministic-external-nondet-partial.xq
trunk/MXQuery_Testing/XQTests/Queries/xquery11/functest-deterministic-external-nondet.xq
Modified: trunk/MXQuery/android/src/ch/ethz/mxquery/query/parser/SchemaParser.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/query/parser/SchemaParser.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/query/parser/SchemaParser.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -48,6 +48,7 @@
import ch.ethz.mxquery.functions.xs.XSConstructorIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.URIUtils;
+import ch.ethz.mxquery.util.Hashtable;
public class SchemaParser implements DOMErrorHandler {
/**
@@ -287,7 +288,7 @@
Type.OCCURRENCE_IND_ZERO_OR_MORE);
FunctionSignature signature = new FunctionSignature(qn, paramTypes,
FunctionSignature.SYSTEM_FUNCTION,
- XDMIterator.EXPR_CATEGORY_SIMPLE, false, true);
+ new Hashtable());
XDMIterator it = XSConstructorIterator.getBaseTypeConstructor(ctx, Type.getTypeFootprint(
qn, dict), dict);
if (it != null) {
Modified: trunk/MXQuery/midp_src/ch/ethz/mxquery/query/webservice/WSDLHandler.java
===================================================================
--- trunk/MXQuery/midp_src/ch/ethz/mxquery/query/webservice/WSDLHandler.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/midp_src/ch/ethz/mxquery/query/webservice/WSDLHandler.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -200,7 +200,9 @@
// only function name and arity
params[i] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
}
- FunctionSignature signature = new FunctionSignature(functionName,params,FunctionSignature.EXTERNAL_FUNCTION,XDMIterator.EXPR_CATEGORY_SEQUENTIAL,true,false);
+ Hashtable annotations = new Hashtable();
+ annotations.put(FunctionSignature.NONDETERMINISTIC_ANNOTATION, new XDMIterator[]{});
+ FunctionSignature signature = new FunctionSignature(functionName,params,FunctionSignature.EXTERNAL_FUNCTION,annotations);
Function function = new Function(null,signature,wf,null,null);
context.addFunction(function, true, true);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/Context.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -395,33 +395,33 @@
public void registerVariable(QName qname, boolean isFFLWOR)
throws MXQueryException {
- registerVariable(qname, false, isFFLWOR, null, false);
+ registerVariable(qname, false, isFFLWOR, null, new Hashtable());
}
public void registerVariable(QName qname, boolean isFFLWOR,
- XDMIterator seqTypeIter, boolean assignable)
+ XDMIterator seqTypeIter, Hashtable annotations)
throws MXQueryException {
- registerVariable(qname, false, isFFLWOR, seqTypeIter, assignable);
+ registerVariable(qname, false, isFFLWOR, seqTypeIter, annotations);
}
public void registerNewContextItem() throws MXQueryException {
- registerVariable(CONTEXT_ITEM, false, null, false);
+ registerVariable(CONTEXT_ITEM, false, null, new Hashtable());
}
public void registerNewContextItem(XDMIterator seqTypeIter) throws MXQueryException {
- registerVariable(CONTEXT_ITEM, false, seqTypeIter, false);
+ registerVariable(CONTEXT_ITEM, false, seqTypeIter, new Hashtable());
}
public void registerVariable(QName qname, boolean external,
- boolean isFFLWOR, XDMIterator seqTypeIter, boolean assignable)
+ boolean isFFLWOR, XDMIterator seqTypeIter, Hashtable annotations)
throws MXQueryException {
registerVariable(qname, external, isFFLWOR, seqTypeIter, true,
- assignable, true);
+ annotations, true);
}
public void registerVariable(QName qname, boolean external,
boolean isFFLWOR, XDMIterator seqTypeIter, boolean resolve,
- boolean assignable, boolean declared) throws MXQueryException {
+ Hashtable annotations, boolean declared) throws MXQueryException {
XQName resolvedQName = qname;
if (resolve && qname.getNamespaceURI() == null)
resolvedQName = qname.resolveQNameNamespace(this, false);
@@ -442,18 +442,17 @@
holder.setDeclared(declared);
}
} else {
- holder = new VariableHolder(this, external,variableMap.size());
+ holder = new VariableHolder(this, external,variableMap.size(),annotations);
holder.setDeclared(declared);
variableMap.put(resolvedQName, holder);
}
holder.setSeqTypeIt(seqTypeIter);
- holder.setAssignable(assignable);
}
public QName registerAnonymousVariable() {
QName qname = new QName(ANONYM_VARIABLE_PREFIX, ANONYM_VARIABLE_PREFIX
+ ++anonymVariableCounter);
- variableMap.put(qname, new VariableHolder(this, false,variableMap.size()));
+ variableMap.put(qname, new VariableHolder(this, false,variableMap.size(),new Hashtable()));
return qname;
}
@@ -522,7 +521,7 @@
throws MXQueryException {
VariableHolder holder = getVariable(qname);
if (holder == null) {
- registerVariable(qname, true,false,null,true,false,false);
+ registerVariable(qname, true,false,null,true,new Hashtable(),false);
holder = getVariable(qname);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/XQStaticContext.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/XQStaticContext.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/contextConfig/XQStaticContext.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -458,11 +458,11 @@
* @param qname
* @param isFFLWOR
* @param seqTypeIter
- * @param assignable
+ * @param annotations
* @throws MXQueryException
*/
public void registerVariable(QName qname, boolean isFFLWOR, XDMIterator seqTypeIter,
- boolean assignable) throws MXQueryException;
+ Hashtable annotations) throws MXQueryException;
/**
* Registers a new context item in this scope
* @throws MXQueryException
@@ -483,11 +483,11 @@
* @param external
* @param isFFLWOR
* @param seqTypeIter
- * @param assignable
+ * @param annotations
* @throws MXQueryException
*/
public void registerVariable(QName qname, boolean external, boolean isFFLWOR,
- XDMIterator seqTypeIter, boolean assignable) throws MXQueryException;
+ XDMIterator seqTypeIter, Hashtable annotations) throws MXQueryException;
/**
* Registers a new variable. If the variable already exists, an error is thrown.
@@ -496,12 +496,12 @@
* @param isFFLWOR
* @param seqTypeIter
* @param resolve
- * @param assignable
+ * @param annotations
* @param declared TODO
* @throws MXQueryException
*/
public void registerVariable(QName qname, boolean external, boolean isFFLWOR,
- XDMIterator seqTypeIter, boolean resolve, boolean assignable, boolean declared) throws MXQueryException;
+ XDMIterator seqTypeIter, boolean resolve, Hashtable annotations, boolean declared) throws MXQueryException;
/**
* Registers a new "anonymous" (=internal) variable
* @return the QName of the registered variable
Modified: trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/TypeInfo.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/TypeInfo.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/datamodel/types/TypeInfo.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -20,6 +20,7 @@
package ch.ethz.mxquery.datamodel.types;
import ch.ethz.mxquery.datamodel.XQName;
+import ch.ethz.mxquery.util.Hashtable;
/** Some of node kind types (e.g. element, attribute, PI) might have name part in the type definition.
* It's not possible to represent type with integer number in these cases.
@@ -33,6 +34,7 @@
private int typeAnnotation =UNDEFINED;
private TypeInfo [] paramTypes = null;
private TypeInfo returnType=null;
+ private Hashtable annotations=null;
private final static int MASK_GET_START_TAG = Integer.parseInt("0001100000000000000000000000000", 2);
private final static int MASK_CLEAN_START_TAG = Integer.parseInt("1110011111111111111111111111111", 2);
@@ -59,11 +61,12 @@
this.typeAnnotation = typeAn;
}
- public TypeInfo(int type, int occurIndID, TypeInfo[] params,TypeInfo retType) {
+ public TypeInfo(int type, int occurIndID, TypeInfo[] params,TypeInfo retType, Hashtable annotations) {
this.type = type;
this.occurID = occurIndID;
this.paramTypes = params;
this.returnType = retType;
+ this.annotations = annotations;
}
@@ -164,11 +167,15 @@
return returnType;
}
+ public Hashtable getAnnotations() {
+ return annotations;
+ }
+
public TypeInfo copy() {
if (typeAnnotation != UNDEFINED)
return new TypeInfo(type,occurID,qn,typeAnnotation);
else if (type ==Type.FUNCTION_ITEM)
- return new TypeInfo(type, occurID, paramTypes, returnType);
+ return new TypeInfo(type, occurID, paramTypes, returnType,annotations);
else
return new TypeInfo(type, occurID,qn);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/FGPopulator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/FGPopulator.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/FGPopulator.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -16,7 +16,7 @@
import ch.ethz.mxquery.exceptions.ErrorCodes;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
-import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
import ch.ethz.mxquery.util.IOLib;
class FGPopulator {
@@ -133,7 +133,7 @@
for (int i=0;i<paramTypes.length;i++)
paramTypes[i] = new TypeInfo(FunctionGallery.getType(parameters[i],ctx),FunctionGallery.getOccur(parameters[i]));
- FunctionSignature signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+ FunctionSignature signature = new FunctionSignature(qn, paramTypes, FunctionSignature.SYSTEM_FUNCTION, new Hashtable());
Function function = new Function(baseLoc+loc+"."+funcDesc[2],signature, null, operation, type );
fg.add(function);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/Function.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/Function.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/Function.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -26,6 +26,7 @@
import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.iterators.UserdefFuncCall;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
/**
* Holds information on the function metadata and methods to retrieve the
@@ -79,9 +80,10 @@
public Function getAsExternalFunction(String prefix) {
QName fName = new QName(signature.getName().getNamespaceURI(), prefix,
signature.getName().getLocalPart());
+ Hashtable annotations = signature.getAllAnnotations();
+ annotations.put(FunctionSignature.PRIVATE_ANNOTATION,new XDMIterator[]{});
FunctionSignature newSig = new FunctionSignature(fName, signature.paramTypes
- , FunctionSignature.EXTERNAL_FUNCTION,
- signature.getExpressionCategory(), false, true);
+ , FunctionSignature.EXTERNAL_FUNCTION,annotations);
Function func = new Function(className, newSig, iter, operation, returnType);
return func;
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionSignature.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionSignature.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/FunctionSignature.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -15,12 +15,15 @@
package ch.ethz.mxquery.functions;
+import java.util.Enumeration;
+
import ch.ethz.mxquery.contextConfig.XQStaticContext;
import ch.ethz.mxquery.datamodel.QName;
import ch.ethz.mxquery.datamodel.XQName;
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
/**
* Holds information on the signature (Name, parameters, classification) of an XQuery function
@@ -30,6 +33,14 @@
public class FunctionSignature {
+ public static final QName PRIVATE_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","private");
+ public static final QName PUBLIC_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","public");
+ public static final QName DETERMINISTIC_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","deterministic");
+ public static final QName NONDETERMINISTIC_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","nondeterministic");
+ public static final QName SIMPLE_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","simple");
+ public static final QName UPDATING_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","updating");
+ public static final QName SEQUENTIAL_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","sequential");
+
protected QName qname;
TypeInfo [] paramTypes;
@@ -37,13 +48,9 @@
int arity = 0;
protected int type;
-
- protected int expressionType;
-
- protected boolean nondet;
-
- protected boolean privateScope;
-
+
+ Hashtable annotations;
+
//Undefined is just for locking up values
private static final int UNDEFINED_TYPE=0;
@@ -53,18 +60,16 @@
//public static final int LOCAL_SCOPE_FUNCTION=4;
FunctionSignature(QName qname, TypeInfo [] parameterType){
- this(qname, parameterType, UNDEFINED_TYPE, XDMIterator.EXPR_CATEGORY_SIMPLE, false, false);
+ this(qname, parameterType, UNDEFINED_TYPE, new Hashtable());
}
- public FunctionSignature(QName qname, TypeInfo[] parameterType, int type, int exprType, boolean nondeterministic, boolean isPrivate){
+ public FunctionSignature(QName qname, TypeInfo[] parameterType, int type, Hashtable annotations){
this.qname = qname;
this.paramTypes = parameterType;
this.type = type;
- expressionType = exprType;
- nondet = nondeterministic;
- privateScope = isPrivate;
if (this.paramTypes != null)
arity = paramTypes.length;
+ this.annotations = annotations;
}
/**
* Checks the equality of Function Signatures.
@@ -128,28 +133,43 @@
* @return The expression type of this function: SIMPLE, UPDATING, SCRIPTING
*/
public int getExpressionCategory() {
- return expressionType;
+ if (annotations.containsKey(UPDATING_ANNOTATION))
+ return XDMIterator.EXPR_CATEGORY_UPDATING;
+ if (annotations.containsKey(SEQUENTIAL_ANNOTATION))
+ return XDMIterator.EXPR_CATEGORY_SEQUENTIAL;
+ return XDMIterator.EXPR_CATEGORY_SIMPLE;
}
/**
* Is this a deterministic or non-deterministic functions (as defined in XQuery 1.1)
* @return true if the function is non-deterministic
*/
public boolean isNonDeterministic() {
- return nondet;
+ return annotations.containsKey(NONDETERMINISTIC_ANNOTATION);
}
/**
* Is this a private function (XQuery 1.1, exempt from module import)
* @return true if this is a private function
*/
public boolean isPrivateFunction() {
- return privateScope;
+ return annotations.containsKey(PRIVATE_ANNOTATION);
}
+ public Hashtable getAllAnnotations() {
+ Hashtable ht = new Hashtable();
+ Enumeration keys = annotations.keys();
+ while (keys.hasMoreElements()) {
+ Object key = keys.nextElement();
+ Object val = annotations.get(key);
+ ht.put(key, val);
+ }
+ return ht;
+ }
+
public FunctionSignature copy() {
QName qn = null;
if (qname != null)
qn = qname.copy();
- FunctionSignature fs = new FunctionSignature(qn, paramTypes, type, expressionType, nondet, privateScope);
+ FunctionSignature fs = new FunctionSignature(qn, paramTypes, type, annotations);
fs.arity = arity;
return fs;
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/NativeFunctionImporter.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -17,6 +17,7 @@
import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.iterators.NativeFuncCall;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
public class NativeFunctionImporter {
@@ -181,7 +182,10 @@
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);
+ Hashtable annotations = new Hashtable();
+ annotations.put(FunctionSignature.SEQUENTIAL_ANNOTATION,new XDMIterator[]{});
+ annotations.put(FunctionSignature.NONDETERMINISTIC_ANNOTATION,new XDMIterator[]{});
+ FunctionSignature fs = new FunctionSignature(qn, md.paramTypes,FunctionSignature.EXTERNAL_FUNCTION,annotations);
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, null);
ctx.addFunction(fn);
}
@@ -220,4 +224,4 @@
public static boolean isNativeUri(String uri) {
return uri.startsWith("java:");
}
-}
\ No newline at end of file
+}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Filter.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Filter.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Filter.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -15,6 +15,7 @@
import ch.ethz.mxquery.model.CurrentBasedIterator;
import ch.ethz.mxquery.model.Iterator;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
public class Filter extends CurrentBasedIterator {
@@ -31,7 +32,7 @@
// if (!(predicate instanceof FFLWORIterator))
TypeInfo [] params = new TypeInfo[1];
params[0] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
- TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.BOOLEAN,Type.OCCURRENCE_IND_EXACTLY_ONE));
+ TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.BOOLEAN,Type.OCCURRENCE_IND_EXACTLY_ONE), new Hashtable());
SequenceTypeIterator st = new SequenceTypeIterator(tInfo, true, true, context, loc, true);
st.setSubIters(subIters[0]);
Iterator[] its = null;
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Fold.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Fold.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Fold.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -20,6 +20,7 @@
import ch.ethz.mxquery.model.VariableHolder;
import ch.ethz.mxquery.model.Window;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
public class Fold extends CurrentBasedIterator implements RequestTypeMulti{
@@ -38,7 +39,7 @@
TypeInfo [] params = new TypeInfo[2];
params[0] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
params[1] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
- TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE));
+ TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE), new Hashtable());
SequenceTypeIterator st = new SequenceTypeIterator(tInfo, true, true, context, loc, true);
st.setSubIters(subIters[0]);
st.setResettable(true);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Map.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Map.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/Map.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -15,6 +15,7 @@
import ch.ethz.mxquery.model.CurrentBasedIterator;
import ch.ethz.mxquery.model.Iterator;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
public class Map extends CurrentBasedIterator {
@@ -31,7 +32,7 @@
// if (!(predicate instanceof FFLWORIterator))
TypeInfo [] params = new TypeInfo[1];
params[0] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE);
- TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE));
+ TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE), new Hashtable());
SequenceTypeIterator st = new SequenceTypeIterator(tInfo, true, true, context, loc, true);
st.setSubIters(subIters[0]);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/MapPairs.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/MapPairs.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/functions/fn/MapPairs.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -18,6 +18,7 @@
import ch.ethz.mxquery.model.VariableHolder;
import ch.ethz.mxquery.model.Window;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
public class MapPairs extends CurrentBasedIterator {
Window wnd1, wnd2;
@@ -34,7 +35,7 @@
params[0] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
params[1] = new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_EXACTLY_ONE);
- TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE));
+ TypeInfo tInfo = new TypeInfo(Type.FUNCTION_ITEM, Type.OCCURRENCE_IND_EXACTLY_ONE, params, new TypeInfo(Type.ITEM,Type.OCCURRENCE_IND_ZERO_OR_MORE), new Hashtable());
st = new SequenceTypeIterator(tInfo, true, true, context, loc, true);
st.setSubIters(subIters[0]);
st.setResettable(true);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/SequenceTypeIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/SequenceTypeIterator.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/SequenceTypeIterator.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -39,6 +39,7 @@
import ch.ethz.mxquery.model.CurrentBasedIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.util.KXmlSerializer;
+import ch.ethz.mxquery.util.Hashtable;
public class SequenceTypeIterator extends CurrentBasedIterator {
@@ -343,8 +344,8 @@
if (tok.getEventType()!=Type.FUNCTION_ITEM)
return false;
TypeInfo [] params = tInfo.getParameterTypes();
+ FunctionSignature fs = ((FunctionItemToken)tok).getFunction().getFunctionSignature();
if (params != null) {
- FunctionSignature fs = ((FunctionItemToken)tok).getFunction().getFunctionSignature();
if (fs.getArity() != params.length)
return false;
for (int i=0;i<params.length;i++) {
@@ -359,6 +360,21 @@
!Type.isOccCompatible(retType.getOccurID(),tInfo.getReturnType().getOccurID()))
return false;
}
+ if (tInfo.getAnnotations().size() > 0) {
+ Hashtable annToCheck = tInfo.getAnnotations();
+ if (annToCheck.containsKey(FunctionSignature.DETERMINISTIC_ANNOTATION) &&
+ fs.isNonDeterministic())
+ return false;
+ if (annToCheck.containsKey(FunctionSignature.SIMPLE_ANNOTATION) &&
+ fs.getExpressionCategory() != XDMIterator.EXPR_CATEGORY_SIMPLE)
+ return false;
+ if (annToCheck.contains(FunctionSignature.UPDATING_ANNOTATION) &&
+ fs.getExpressionCategory() != XDMIterator.EXPR_CATEGORY_SEQUENTIAL)
+ return false;
+ if (annToCheck.contains(FunctionSignature.SEQUENTIAL_ANNOTATION) &&
+ fs.getExpressionCategory() != XDMIterator.EXPR_CATEGORY_UPDATING)
+ return false;
+ }
return true;
}
@@ -391,7 +407,7 @@
FunctionSignature origSig = tok.getFunction().getFunctionSignature();
if (origSig.getArity() != targetType.getParameterTypes().length)
throw new TypeException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE,"Wrong arity for function item",loc);
- FunctionSignature fs = new FunctionSignature(tok.getQNameTokenValue(), targetType.getParameterTypes(), FunctionSignature.USER_DEFINED_FUNCTION, origSig.getExpressionCategory(), origSig.isNonDeterministic(), origSig.isPrivateFunction());
+ FunctionSignature fs = new FunctionSignature(tok.getQNameTokenValue(), targetType.getParameterTypes(), FunctionSignature.USER_DEFINED_FUNCTION, origSig.getAllAnnotations());
Function fun = new Function(null,fs,tok.getFunction().getFunctionImplementation(getContext()),null,targetType.getReturnType());
return tok.coerce(fun);
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/model/VariableHolder.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/model/VariableHolder.java 2011-05-23 09:59:07 UTC (rev 4365)
+++ trunk/MXQuery/src/ch/ethz/mxquery/model/VariableHolder.java 2011-05-24 13:32:19 UTC (rev 4366)
@@ -21,6 +21,7 @@
import ch.ethz.mxquery.bindings.WindowFactory;
import ch.ethz.mxquery.contextConfig.Context;
import ch.ethz.mxquery.contextConfig.XQStaticContext;
+import ch.ethz.mxquery.datamodel.QName;
import ch.ethz.mxquery.datamodel.Source;
import ch.ethz.mxquery.datamodel.types.Type;
import ch.ethz.mxquery.datamodel.types.TypeInfo;
@@ -29,14 +30,19 @@
import ch.ethz.mxquery.exceptions.QueryLocation;
import ch.ethz.mxquery.exceptions.StaticException;
import ch.ethz.mxquery.iterators.VariableIterator;
+import ch.ethz.mxquery.util.Hashtable;
public class VariableHolder {
+
+ public static final QName ASSIGNABLE_ANNOTATION = new QName(XQStaticContext.URI_FN,"fn","as...
[truncated message content] |
|
From: <pm_...@us...> - 2011-05-24 13:34:15
|
Revision: 4367
http://mxquery.svn.sourceforge.net/mxquery/?rev=4367&view=rev
Author: pm_fischer
Date: 2011-05-24 13:34:09 +0000 (Tue, 24 May 2011)
Log Message:
-----------
- fn:matches should work on Java 1.4 again
- all errors are thrown (and not just logged) for NativeFunctionCalls
- use string, not URI for file I/O
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
trunk/MXQuery/src/ch/ethz/mxquery/util/IOLib.java
Added Paths:
-----------
trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/fn/
trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/fn/Matches.java
Added: trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/fn/Matches.java
===================================================================
--- trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/fn/Matches.java (rev 0)
+++ trunk/MXQuery/altsrc/ch/ethz/mxquery/functions/fn/Matches.java 2011-05-24 13:34:09 UTC (rev 4367)
@@ -0,0 +1,148 @@
+/* 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.functions.fn;
+
+import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.thaiopensource.datatype.xsd.regex.jdk1_4.Translator;
+
+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.BooleanToken;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+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.exceptions.StaticException;
+import ch.ethz.mxquery.model.TokenBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+
+public class Matches extends TokenBasedIterator {
+
+ protected void init() throws MXQueryException {
+ String text = getStringValueOrEmpty(subIters[0]);
+ if (text == null)
+ text = "";
+
+ int f = computeFlags(subIters, 3, loc);
+
+ String pat = getStringValue(subIters[1]);
+
+ if (pat.equals("")) {
+ throw new DynamicException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Pattern must be a String value!", loc);
+ }
+
+
+ if ((f & Pattern.COMMENTS) != 0) {
+ pat = removeWsFromPattern(pat);
+ f = f ^ Pattern.COMMENTS;
+ }
+
+ Pattern p = null;
+ try {
+ String toMatch = pat;
+// if ((f & Pattern.LITERAL) == 0)
+ toMatch = Translator.translate(pat);
+ p = Pattern.compile(toMatch, f);
+ } catch (Exception e) {
+ throw new DynamicException(ErrorCodes.F0032_INVALID_REGULAR_EXPRESSION, "Invalid regular expression!", loc);
+ }
+
+ if ((f & Pattern.CASE_INSENSITIVE) != 0)
+ text = text.toLowerCase();
+ Matcher m = p.matcher(text);
+ if (m.find())
+ currentToken = BooleanToken.TRUE_TOKEN;
+ else
+ currentToken = BooleanToken.FALSE_TOKEN;
+ }
+
+ private static String removeWsFromPattern(String pattern) {
+ StringBuffer res = new StringBuffer(pattern.length());
+ boolean inCharClass = false;
+ // Simplified version of WS stripping, does not take [] into account
+ for (int i=0;i<pattern.length();i++) {
+ char chr = pattern.charAt(i);
+ if (!Character.isWhitespace(chr) || inCharClass)
+ res.append(chr);
+ if (chr == '[')
+ inCharClass = true;
+ if (chr == ']')
+ inCharClass = false;
+ }
+ return res.toString();
+ }
+
+ /**
+ * Extract and compute the flags for the regexp-based functions
+ * @param subIters
+ * @param pos: Position of the flags parameter, counting as in XQuery (1...)
+ * @param loc: QueryLocation for error reporting
+ * @return
+ * @throws MXQueryException
+ */
+
+ static int computeFlags(XDMIterator [] subIters, int pos, QueryLocation loc) throws MXQueryException {
+ int f = 0;
+ if (subIters.length == pos) {
+
+ TokenInterface flags = subIters[pos-1].next();
+ String theFlags = flags.getText();
+
+ if (theFlags == null) {
+ throw new DynamicException(ErrorCodes.E0004_TYPE_INAPPROPRIATE_TYPE, "Regex Flags must be a String value!", loc);
+ }
+
+ if (!theFlags.equals("")) { // if flags are empty, skip
+ if (!theFlags.matches("[smixq]+")) {
+ throw new DynamicException(ErrorCodes.F0031_INVALID_REGULAR_EXPRESSION_FLAGS, "Invalid regular expression flags!", loc);
+ }
+
+ if (theFlags.indexOf("s") >= 0) {
+ f += Pattern.DOTALL;
+ }
+ if (theFlags.indexOf('m') >= 0) {
+ f += Pattern.MULTILINE;
+ }
+ if (theFlags.indexOf("i") >= 0) {
+ f += Pattern.CASE_INSENSITIVE;
+ }
+ if (theFlags.indexOf("x") >= 0) {
+ f += Pattern.COMMENTS;
+ }
+ if (theFlags.indexOf("q") >= 0) {
+ throw new StaticException(ErrorCodes.A0002_EC_NOT_SUPPORTED, "'q' flag/literal matches not supported on Java 1.4", loc);
+ }
+
+ }
+ }
+ return f;
+ }
+
+ public TypeInfo getStaticType() {
+ return new TypeInfo(Type.BOOLEAN,Type.OCCURRENCE_IND_EXACTLY_ONE);
+ }
+
+ protected XDMIterator copy(Context context, XDMIterator[] subIters, Vector nestedPredCtxStack) throws MXQueryException {
+ XDMIterator copy = new Matches();
+ copy.setContext(context, true);
+ copy.setSubIters(subIters);
+ return copy;
+ }
+}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-05-24 13:32:19 UTC (rev 4366)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-05-24 13:34:09 UTC (rev 4367)
@@ -149,19 +149,19 @@
this.current = new TokenIterator(context, wrap, loc, false);
}
} catch (SecurityException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
} catch (NoSuchFieldException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
} catch (NoSuchMethodException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
} catch (IllegalArgumentException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
} catch (IllegalAccessException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
} catch (InvocationTargetException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
} catch (InstantiationException e) {
- e.printStackTrace();
+ throw new DynamicException(ErrorCodes.A0009_EC_EVALUATION_NOT_POSSIBLE, "Native call failed: "+e.getMessage(), loc);
}
//this.current = new TokenIterator(context, 42,Type.INT, loc);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/util/IOLib.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/util/IOLib.java 2011-05-24 13:32:19 UTC (rev 4366)
+++ trunk/MXQuery/src/ch/ethz/mxquery/util/IOLib.java 2011-05-24 13:34:09 UTC (rev 4367)
@@ -201,7 +201,7 @@
throw new DynamicException(ErrorCodes.F0014_ERROR_RETRIEVING_RESOURCE, "I/O Error - Remote Data cannot be accessed: " + e, loc);
}
} else {
- File xml = new File(uri);
+ File xml = new File(toOpen);
if (xml.exists()) {
try {
ins = new FileInputStream(xml);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-05-25 18:40:42
|
Revision: 4369
http://mxquery.svn.sourceforge.net/mxquery/?rev=4369&view=rev
Author: pm_fischer
Date: 2011-05-25 18:40:36 +0000 (Wed, 25 May 2011)
Log Message:
-----------
- fix nested module import problem on XQIB
- reStore building on Java 1.4
Modified Paths:
--------------
trunk/MXQuery/build.xml
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/Function.java
Modified: trunk/MXQuery/build.xml
===================================================================
--- trunk/MXQuery/build.xml 2011-05-24 13:54:45 UTC (rev 4368)
+++ trunk/MXQuery/build.xml 2011-05-25 18:40:36 UTC (rev 4369)
@@ -217,7 +217,7 @@
<copy file="${altsrc.dir}/ch/ethz/mxquery/query/impl/CompilerImpl.java" todir="${customtmp.dir}/ch/ethz/mxquery/query/impl" overwrite="yes" />
<copy file="${altsrc.dir}/ch/ethz/mxquery/xdmio/xmlAdapters/NonValidatingDOMAdapter.java" todir="${customtmp.dir}/ch/ethz/mxquery/xdmio/xmlAdapters/" overwrite="yes" />
<copy file="${altsrc.dir}/ch/ethz/mxquery/functions/math/TransMath.java" todir="${customtmp.dir}/ch/ethz/mxquery/functions/math" overwrite="yes" />
- <copy file="${altsrc.dir}/ch/ethz/mxquery/functions/Matches.java" todir="${customtmp.dir}/ch/ethz/mxquery/functions/" overwrite="yes" />
+ <copy file="${altsrc.dir}/ch/ethz/mxquery/functions/fn/Matches.java" todir="${customtmp.dir}/ch/ethz/mxquery/functions/fn/" overwrite="yes" />
<depend srcdir="${customtmp.dir}"
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/Function.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/Function.java 2011-05-24 13:54:45 UTC (rev 4368)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/Function.java 2011-05-25 18:40:36 UTC (rev 4369)
@@ -27,6 +27,7 @@
import ch.ethz.mxquery.functions.FunctionSignature;
import ch.ethz.mxquery.iterators.UserdefFuncCall;
import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.Hashtable;
/**
* Holds information on the function metadata and methods to retrieve the
@@ -80,9 +81,10 @@
public Function getAsExternalFunction(String prefix) {
QName fName = new QName(signature.getName().getNamespaceURI(), prefix,
signature.getName().getLocalPart());
+ Hashtable annotations = signature.getAllAnnotations();
+ annotations.put(FunctionSignature.PRIVATE_ANNOTATION,new XDMIterator[]{});
FunctionSignature newSig = new FunctionSignature(fName, signature.paramTypes
- , FunctionSignature.EXTERNAL_FUNCTION,
- signature.getAllAnnotations());
+ , FunctionSignature.EXTERNAL_FUNCTION,annotations);
Function func = new Function(className, newSig, iter, operation, returnType);
return func;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-05-26 08:04:22
|
Revision: 4370
http://mxquery.svn.sourceforge.net/mxquery/?rev=4370&view=rev
Author: pm_fischer
Date: 2011-05-26 08:04:15 +0000 (Thu, 26 May 2011)
Log Message:
-----------
- fixes on detection of sequential annotation
- cleanup on namespace scope processing
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/XDMScope.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/NSScopeChange.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/update/StripTypeIterator.java
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
trunk/MXQuery_Testing/XQTests/Queries/try_zorba_3.xq
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/WebService/WSMXQImportTest.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/XDMScope.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/XDMScope.java 2011-05-25 18:40:36 UTC (rev 4369)
+++ trunk/MXQuery/src/ch/ethz/mxquery/datamodel/xdm/XDMScope.java 2011-05-26 08:04:15 UTC (rev 4370)
@@ -144,7 +144,7 @@
uri = (Namespace) c.prefixNamespaceMap.get(prefix);
else
uri = (Namespace) prefixNamespaceMap.get(prefix);
- if (uri!= null)
+ if (uri!= null && !"".equals(uri.getURI()))
return uri.getURI();
else return null;
}
@@ -226,7 +226,7 @@
}
}
// Undeclare default NS if construction around uses it, but inner content does not
- if ((ns.getNamespace("") == null || ns.getNamespace("").getURI() == null) && curScope.getNamespace("")!=null) {
+ if ((ns.getNamespace("") == null || ns.getNamespace("").getURI() == null) && requiredNS.contains(new Namespace("", ""))) {
nsNew.addNamespace("", "");
newNamespaces++;
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/NSScopeChange.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/NSScopeChange.java 2011-05-25 18:40:36 UTC (rev 4369)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/NSScopeChange.java 2011-05-26 08:04:15 UTC (rev 4370)
@@ -131,9 +131,10 @@
}
if (ev == Type.END_TAG) {
if (next instanceof NamedToken
- && !scopeDepth.empty() && depth == scopeDepth.peek()) {
+ && !scopeDepth.empty() && depth == scopeDepth.peek()-1) {
curNsScope = curNsScope.getParent();
scopeDepth.pop();
+ oldParentNs = null;
}
}
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/update/StripTypeIterator.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/update/StripTypeIterator.java 2011-05-25 18:40:36 UTC (rev 4369)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/update/StripTypeIterator.java 2011-05-26 08:04:15 UTC (rev 4370)
@@ -55,7 +55,7 @@
seenAttrPos++;
}
else
- cur = current.next();
+ cur = getNext();
if (Type.isAttribute(cur.getEventType())) {
NamedToken nm = ((NamedToken)cur).copyStrip();
nm.setIDREFS(null);
@@ -64,7 +64,7 @@
if (cur.getEventType() == Type.START_TAG) {
NamedToken nm = ((NamedToken)cur).copyStrip();
boolean hasNamedIDAttribute = false;
- TokenInterface nextTok = current.next();
+ TokenInterface nextTok = getNext();
if (collectedAttributes.size() > 0)
collectedAttributes = new Vector();
collectedAttributes.addElement(nextTok);
@@ -80,7 +80,7 @@
requiredNS.add(new Namespace(nm.getPrefix(), nm.getNS()));
}
// if attribute, check if id
- nextTok = current.next();
+ nextTok = getNext();
collectedAttributes.addElement(nextTok);
}
nm.setIDREFS(null);
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-05-25 18:40:36 UTC (rev 4369)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-05-26 08:04:15 UTC (rev 4370)
@@ -635,7 +635,7 @@
throw new StaticException(
ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,
"Function named " + funcToCheck.funcName.toString()
- + " not available", getCurrentLoc());
+ + " with arity "+funcToCheck.arity+" not available", getCurrentLoc());
}
}
// Check if the expression type is consistent
@@ -1957,7 +1957,7 @@
paramAnnotations.put(VariableHolder.ASSIGNABLE_ANNOTATION, new XDMIterator[]{});
getCurrentContext().registerVariable(
(QName) paramNames.elementAt(i), false,
- seqTypeIt, annotations);
+ seqTypeIt, paramAnnotations);
}
Iterator body;
@@ -2040,9 +2040,10 @@
annotations.put(FunctionSignature.UPDATING_ANNOTATION, new XDMIterator[]{});
} else if (co.isScripting() && parseKeyword("sequential")) {
checkExprTypeAnnotation(annotations);
+ annotations.put(FunctionSignature.SEQUENTIAL_ANNOTATION, new XDMIterator[]{});
} else if (parseKeyword("simple")) {
checkExprTypeAnnotation(annotations);
- annotations.put(FunctionSignature.SEQUENTIAL_ANNOTATION, new XDMIterator[]{});
+ annotations.put(FunctionSignature.SIMPLE_ANNOTATION, new XDMIterator[]{});
} else if (co.isXquery11() && parseKeyword("private")) {
checkVisibilityAnnotation(annotations);
annotations.put(FunctionSignature.PRIVATE_ANNOTATION, new XDMIterator[]{});
Modified: trunk/MXQuery_Testing/XQTests/Queries/try_zorba_3.xq
===================================================================
--- trunk/MXQuery_Testing/XQTests/Queries/try_zorba_3.xq 2011-05-25 18:40:36 UTC (rev 4369)
+++ trunk/MXQuery_Testing/XQTests/Queries/try_zorba_3.xq 2011-05-26 08:04:15 UTC (rev 4370)
@@ -2,5 +2,5 @@
try {
2 + "3"
} catch * ($ecode, $desc) {
- string-join(($ecode, $desc), " ")
+ string-join((xs:string($ecode), $desc), " ")
}
Modified: trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/WebService/WSMXQImportTest.java
===================================================================
--- trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/WebService/WSMXQImportTest.java 2011-05-25 18:40:36 UTC (rev 4369)
+++ trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/WebService/WSMXQImportTest.java 2011-05-26 08:04:15 UTC (rev 4370)
@@ -36,7 +36,7 @@
String query = UriToString(queries + "Q13_MXQuery_Node_Sequence_Result_Function.xq");
PreparedStatement expr = prepareQuery(query, false, true, false, false, false);
doQuery(expr);
- assertEquals(UriToString(expected_results+"Q13_MXQuery_Node_Sequence_Result_Function.xml"),resultBuffer.toString().trim());
+ assertXMLEqual(UriToString(expected_results+"Q13_MXQuery_Node_Sequence_Result_Function.xml"),resultBuffer.toString().trim());
}
public void test_14() throws Exception{
String query = UriToString(queries + "Q14_MXQuery_Atomic_Sequence_Result_Function.xq");
@@ -72,7 +72,7 @@
String query = UriToString(queries + "Q19_MXQuery_Element_Mapping_Function.xq");
PreparedStatement expr = prepareQuery(query, false, true, false, false, false);
doQuery(expr);
- assertEquals(UriToString(expected_results+"Q19_MXQuery_Element_Mapping_Function.xml"),resultBuffer.toString().trim());
+ assertXMLEqual(UriToString(expected_results+"Q19_MXQuery_Element_Mapping_Function.xml"),resultBuffer.toString().trim());
}
// public void test_multi() throws Exception {
// String query = UriToString(queries + "Q20_Import_Multiple_WSDL.xq");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <et...@us...> - 2011-05-31 00:30:51
|
Revision: 4374
http://mxquery.svn.sourceforge.net/mxquery/?rev=4374&view=rev
Author: etterth
Date: 2011-05-31 00:30:44 +0000 (Tue, 31 May 2011)
Log Message:
-----------
- Basic (incomplete) API for calling an XQIB function from JS added
Modified Paths:
--------------
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/MXQueryJS.java
Added Paths:
-----------
trunk/MXQuery/xqib_samples/jsapi1.html
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/JsApi.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/JavaScriptArrayIterator.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/JsToMxQuery.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/MxQueryToJs.java
Removed Paths:
-------------
trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleElementIterator.java
Added: trunk/MXQuery/xqib_samples/jsapi1.html
===================================================================
--- trunk/MXQuery/xqib_samples/jsapi1.html (rev 0)
+++ trunk/MXQuery/xqib_samples/jsapi1.html 2011-05-31 00:30:44 UTC (rev 4374)
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>XQIB: Sample page</title>
+ <meta charset="UTF-8"/>
+ <link href="style.css" rel="stylesheet" type="text/css">
+ <script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
+ <script type="application/xquery" >
+ module namespace m = "http://www.XQIB.org/module";
+
+ declare function m:generateDiv($node as node()+) {
+ for $x in $node/text()
+ return
+ <div>{concat('div generated by XQIB with "',$x,'" which was passed from JS')}</div>
+ };
+ </script>
+ <script type="text/javascript" >
+ handle = function () {
+ var output = xqib.call('http://www.XQIB.org/module','generateDiv',document.getElementsByTagName('h1'))
+ for (i=0;i<output.length;i++){
+ document.getElementById('output').appendChild(output[i]);
+ }
+ };
+ </script>
+ </head>
+ <body>
+ <a href="index.html"><< Index</a>
+ <h1>Some Text</h1>
+ <h1>Some more text</h1>
+ <div><a href="ModuleImport_new.html">Page</a> | <a href="ModuleImport_new_source.html">Source</a></div>
+ <input type='button' value='Test calling XQIB' onclick='handle()' />
+<div id='output' />
+ </body>
+</html>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-05-30 13:49:59 UTC (rev 4373)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -12,7 +12,7 @@
import ch.ethz.mxquery.functions.Function;
import ch.ethz.mxquery.iterators.browser.EventIterator;
import ch.ethz.mxquery.iterators.browser.ListBasedIterator;
-import ch.ethz.mxquery.iterators.browser.SingleElementIterator;
+import ch.ethz.mxquery.iterators.browser.SingleNodeIterator;
import ch.ethz.mxquery.model.Iterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.query.PreparedStatement;
@@ -145,7 +145,7 @@
test.node = test.node.getParentElement();
}
for (QnameAndArity functionname : handlers.get(test)) {
- SingleElementIterator nodeiter = new SingleElementIterator(
+ SingleNodeIterator nodeiter = new SingleNodeIterator(
test.node);
try {
log.log(LogLevel.FINER, "Calling eventcallback " + functionname.qname.toString());
@@ -219,7 +219,6 @@
// }
NodeStoreSet.resetStoreSet();
-
// prep = null;
// ip = null;
// function = null;
Added: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/JsApi.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/JsApi.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/JsApi.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -0,0 +1,112 @@
+package ch.ethz.mxqjs.client;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.functions.Function;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.query.PreparedStatement;
+import ch.ethz.mxquery.query.impl.PreparedStatementImpl;
+import ch.ethz.mxquery.util.LogLevel;
+import ch.ethz.mxquery.util.Logger;
+import ch.ethz.mxquery.util.browser.JsToMxQuery;
+import ch.ethz.mxquery.util.browser.MxQueryToJs;
+import ch.ethz.mxquery.xdmio.XDMSerializer;
+import ch.ethz.mxquery.xdmio.XDMSerializerSettings;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+
+public class JsApi {
+ public static Logger lg = Logger.getLogger(JsApi.class.getName());
+ //this does not work
+// static {
+// register();
+// }
+ public static native void register()/*-{
+ if ($wnd.xqib == undefined){
+ $wnd.xqib = {};
+ }
+ $wnd.xqib.__executeWithArray = @ch.ethz.mxqjs.client.JsApi::n_ExecuteFunction(Lcom/google/gwt/core/client/JsArray;);
+ $wnd.eval ('xqib.call = function () {return xqib.__executeWithArray(arguments);}');
+ }-*/;
+
+ public static JsArray<JavaScriptObject> call(JsArray<JavaScriptObject> args){
+ int arity = args.length() -2;
+ if (arity < 0){
+ lg.log(LogLevel.WARNING, "You need at least a namespace and a function name to call an XQuery function");
+ return null;
+ }
+
+ String nsUri = asString(args,0);
+ String local = asString(args,1);
+ QName qname = new QName(nsUri, null, local);
+ QnameAndArity functionname;
+ try {
+ Context context = Environment.createContext().getModule(nsUri);
+ if (context == null) {
+ context = Environment.createContext();
+ }
+ functionname = new QnameAndArity(qname, arity, context);
+
+
+
+ XDMIterator[] subiterators = new XDMIterator[arity];
+ for (int i=0;i<arity;i++){
+ subiterators[i] = JsToMxQuery.getIterator(args.get(i + 2));
+ }
+
+
+ //XDMIterator result = Environment.invokeModule(nameAndArity, subiterators);
+ Environment.preProcessDocument();
+ // try {
+ if (subiterators == null) {
+ subiterators = new XDMIterator[0];
+ }
+ for (XDMIterator iter : subiterators) {
+ iter.staticInit();
+ }
+ Function function = functionname.context.getFunction(functionname.qname, arity);
+ //set currenttime
+ functionname.context.setCurrentTime(null);
+ XDMIterator func = function.getFunctionImplementation(new Context(functionname.context));
+ func.setSubIters(subiterators);
+ // func.setContext(getContext(), true);
+
+ PreparedStatement prep = new PreparedStatementImpl(
+ context, func,
+ Environment.getCompilerOptions(), null);
+ // NodeStore nodestore = new NodeStore(Document.get());
+ // prep.addExternalResource(Context.CONTEXT_ITEM,
+ // nodestore.getIterator(Environment.getContext()));
+
+ XDMIterator result = prep.evaluate();
+ result.staticInit();
+ // result.setContext(getContext(), true);
+ // TODO is this right
+ // ((UserdefFuncCall)result).getFunction().setContext(getContext(),
+ // true);
+
+ final JsArray<JavaScriptObject> ret = MxQueryToJs.getAsJavaScriptObject(result);
+ prep.applyPUL();
+ Environment.postProcessDocument();
+
+ lg.log(LogLevel.FINER, "got " + args.length() + " arguments");
+ return ret;
+ } catch (MXQueryException e) {
+ Environment.displayErrorMessage(null, null, e, true);
+ return null;
+ }
+
+ }
+
+ private static native JsArray<JavaScriptObject> n_ExecuteFunction(JsArray<JavaScriptObject> arguments)/*-{
+
+ return @ch.ethz.mxqjs.client.JsApi::call(Lcom/google/gwt/core/client/JsArray;)(arguments);
+ }-*/;
+
+ private static native String asString(JsArray<JavaScriptObject> arr, int i)/*-{
+ return arr[i];
+ }-*/;
+
+}
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/MXQueryJS.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/MXQueryJS.java 2011-05-30 13:49:59 UTC (rev 4373)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/MXQueryJS.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -62,6 +62,7 @@
* This is the entry point method.
*/
public void onModuleLoad() {
+ JsApi.register();
NodeList<Element> scripts = Document.get().getElementsByTagName(
"script");
int scriptlen = scripts.getLength();
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/JavaScriptArrayIterator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/JavaScriptArrayIterator.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/JavaScriptArrayIterator.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -0,0 +1,59 @@
+package ch.ethz.mxquery.iterators.browser;
+
+import java.util.Vector;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.model.CurrentBasedIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.browser.JsToMxQuery;
+
+public class JavaScriptArrayIterator extends CurrentBasedIterator {
+
+ JsArray<JavaScriptObject> arr;
+ int index;
+
+ public JavaScriptArrayIterator(JsArray<JavaScriptObject> arr) {
+ this.arr = arr;
+ }
+
+ @Override
+ public TokenInterface next() throws MXQueryException {
+ if (current == null) {
+ if (arr.length() == 0)
+ return Token.END_SEQUENCE_TOKEN;
+ current = JsToMxQuery.getIterator(arr.get(0));
+ }
+ TokenInterface ret = current.next();
+ if (ret.getEventType() == Type.END_SEQUENCE) {
+ index++;
+ if (index >= arr.length())
+ return Token.END_SEQUENCE_TOKEN;
+ current = JsToMxQuery.getIterator(arr.get(index));
+ ret = current.next();
+ }
+ return ret;
+ }
+
+ @Override
+ protected void resetImpl() throws MXQueryException {
+ super.resetImpl();
+ index = 0;
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ JavaScriptArrayIterator iter = new JavaScriptArrayIterator(arr);
+ iter.setContext(context, true);
+ iter.setSubIters(subIters);
+ return iter;
+ }
+
+}
Deleted: trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleElementIterator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleElementIterator.java 2011-05-30 13:49:59 UTC (rev 4373)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleElementIterator.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -1,65 +0,0 @@
-package ch.ethz.mxquery.iterators.browser;
-
-
-
-import java.util.Vector;
-
-import ch.ethz.mxquery.contextConfig.Context;
-import ch.ethz.mxquery.datamodel.types.Type;
-import ch.ethz.mxquery.datamodel.xdm.Token;
-import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
-import ch.ethz.mxquery.exceptions.MXQueryException;
-import ch.ethz.mxquery.model.Window;
-import ch.ethz.mxquery.model.XDMIterator;
-import ch.ethz.mxquery.update.store.domImpl.NodeToken;
-import ch.ethz.mxquery.util.browser.dom.Node;
-
-
-public class SingleElementIterator extends NodeStoreIterator {
- boolean finished = false;
- public SingleElementIterator(Node store) {
- super(store);
- }
-
- @Override
- public TokenInterface next() throws MXQueryException {
- if (finished)
- return Token.END_SEQUENCE_TOKEN;
- TokenInterface tok = super.next();
-
- if (tok.getEventType() == Type.END_TAG){
- NodeToken nt = (NodeToken) tok;
- finished = nt.getNode() == this.store;
- }
- return tok;
- }
-
- @Override
- protected void resetImpl() throws MXQueryException {
- super.resetImpl();
- finished = false;
- }
-
- @Override
- public Window getNewWindow(int startPosition, int endPosition)
- throws MXQueryException {
- if (startPosition == 1
- && endPosition == Window.END_OF_STREAM_POSITION) {
- Window ret = new SingleElementIterator(store);
- ret.setContext(context,false);
- return ret;
- } else {
- throw new MXQueryException("dont use window with integer parameters", "", null);
- }
- }
-
- @Override
- protected XDMIterator copy(Context context, XDMIterator[] subIters,
- Vector nestedPredCtxStack) throws MXQueryException {
- SingleElementIterator ret = new SingleElementIterator(this.store);
- ret.setContext(context, true);
- ret.setContext(context, true);
- ret.setSubIters(subIters);
- return ret;
- }
-}
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/iterators/browser/SingleNodeIterator.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -0,0 +1,72 @@
+package ch.ethz.mxquery.iterators.browser;
+
+
+
+import java.util.Vector;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.xdm.Token;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.model.Window;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.update.store.domImpl.NodeToken;
+import ch.ethz.mxquery.util.browser.dom.Node;
+
+
+public class SingleNodeIterator extends NodeStoreIterator {
+ boolean finished = false;
+ boolean multipletokens;
+ public SingleNodeIterator(Node store) {
+ super(store);
+ short nt = store.getNodeType();
+ multipletokens = nt == Node.ELEMENT_NODE
+ || nt == Node.DOCUMENT_NODE;
+ }
+
+ @Override
+ public TokenInterface next() throws MXQueryException {
+ if (finished)
+ return Token.END_SEQUENCE_TOKEN;
+
+ if (!multipletokens && called >= 1)
+ return Token.END_SEQUENCE_TOKEN;
+ TokenInterface tok = super.next();
+
+ if (tok.getEventType() == Type.END_TAG){
+ NodeToken nt = (NodeToken) tok;
+ finished = nt.getNode() == this.store;
+ }
+ return tok;
+ }
+
+ @Override
+ protected void resetImpl() throws MXQueryException {
+ super.resetImpl();
+ finished = false;
+
+ }
+
+ @Override
+ public Window getNewWindow(int startPosition, int endPosition)
+ throws MXQueryException {
+ if (startPosition == 1
+ && endPosition == Window.END_OF_STREAM_POSITION) {
+ Window ret = new SingleNodeIterator(store);
+ ret.setContext(context,false);
+ return ret;
+ } else {
+ throw new MXQueryException("dont use window with integer parameters", "", null);
+ }
+ }
+
+ @Override
+ protected XDMIterator copy(Context context, XDMIterator[] subIters,
+ Vector nestedPredCtxStack) throws MXQueryException {
+ SingleNodeIterator ret = new SingleNodeIterator(this.store);
+ ret.setContext(context, true);
+ ret.setSubIters(subIters);
+ return ret;
+ }
+}
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/JsToMxQuery.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/JsToMxQuery.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/JsToMxQuery.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -0,0 +1,129 @@
+package ch.ethz.mxquery.util.browser;
+
+import ch.ethz.mxquery.datamodel.MXQueryDouble;
+import ch.ethz.mxquery.datamodel.xdm.BooleanToken;
+import ch.ethz.mxquery.datamodel.xdm.DoubleToken;
+import ch.ethz.mxquery.datamodel.xdm.TextToken;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.iterators.browser.JavaScriptArrayIterator;
+import ch.ethz.mxquery.iterators.browser.SingleNodeIterator;
+import ch.ethz.mxquery.model.EmptySequenceIterator;
+import ch.ethz.mxquery.model.Iterator;
+import ch.ethz.mxquery.model.TokenSequenceIterator;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.util.browser.dom.Node;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+
+public class JsToMxQuery {
+
+ public static XDMIterator getIterator(JavaScriptObject obj) {
+ TokenInterface tok = convertSingleValue(obj);
+ if (tok != null) {
+ return new TokenSequenceIterator(new TokenInterface[] { tok });
+ }
+ XDMIterator iter = convertArray(obj);
+ if (iter != null) {
+ return iter;
+ }
+ iter = convertNode(obj);
+ if (iter != null) {
+ return iter;
+ }
+ return new EmptySequenceIterator(null, null);
+ }
+
+ private static XDMIterator convertNode(JavaScriptObject obj) {
+ if (!isNode(obj))
+ return null;
+ return new SingleNodeIterator((Node) obj);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static XDMIterator convertArray(JavaScriptObject obj) {
+ if (!isNonEmptyArrayLike(obj))
+ return null;
+ return new JavaScriptArrayIterator((JsArray<JavaScriptObject>) obj);
+ }
+
+ private static TokenInterface convertSingleValue(JavaScriptObject obj) {
+ if (isBoolean(obj)) {
+ TokenInterface valuetoken;
+ if (booleanValue(obj)) {
+ valuetoken = BooleanToken.TRUE_TOKEN;
+ } else {
+ valuetoken = BooleanToken.FALSE_TOKEN;
+ }
+ return valuetoken;
+ }
+
+ if (isNumber(obj)) {
+ TokenInterface valuetoken = new DoubleToken(null,
+ new MXQueryDouble(numberValue(obj)));
+ return valuetoken;
+ }
+ if (isString(obj)) {
+ TokenInterface valuetoken = new TextToken(null, stringValue(obj));
+ return valuetoken;
+ }
+ return null;
+ }
+
+ private static boolean isBoolean(JavaScriptObject obj) {
+ return typeOf(obj).equals("boolean");
+ };
+
+ private static native boolean booleanValue(JavaScriptObject obj) /*-{
+ return obj == true;
+ }-*/;
+
+ private static native double numberValue(JavaScriptObject obj) /*-{
+ return obj;
+ }-*/;
+
+ private static native boolean hasNodeType(JavaScriptObject obj) /*-{
+ return 'nodeType' in obj;
+ }-*/;
+
+ private static boolean isNode(JavaScriptObject obj) {
+ if (!isObject(obj))
+ return false;
+ return hasNodeType(obj);
+ };
+
+ private static boolean isNumber(JavaScriptObject obj) {
+ return typeOf(obj).equals("number");
+ };
+
+ private static boolean isString(JavaScriptObject obj) {
+ return typeOf(obj).equals("string");
+ };
+
+ private static native String stringValue(JavaScriptObject obj) /*-{
+ return obj;
+ }-*/;
+
+ private static boolean isObject(JavaScriptObject obj) {
+ return typeOf(obj).equals("object");
+ };
+
+ private static native boolean isNonEmptyArrayLike(JavaScriptObject obj) /*-{
+ try { // don't bother with `typeof` - just access `length` and `catch`
+ return obj.length > 0 && '0' in Object(obj);
+ } catch (e) {
+ return false;
+ }
+ }-*/;
+
+ private static native String typeOf(JavaScriptObject obj) /*-{
+ return typeof obj;
+ }-*/;
+
+ private static native Node node(JavaScriptObject obj) /*-{
+ if (obj != null && obj.nodeType)
+ return obj;
+ return null;
+ }-*/;
+
+}
Added: trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/MxQueryToJs.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/MxQueryToJs.java (rev 0)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/util/browser/MxQueryToJs.java 2011-05-31 00:30:44 UTC (rev 4374)
@@ -0,0 +1,150 @@
+package ch.ethz.mxquery.util.browser;
+
+import java.util.ArrayList;
+
+import ch.ethz.mxquery.contextConfig.Context;
+import ch.ethz.mxquery.datamodel.Identifier;
+import ch.ethz.mxquery.datamodel.types.Type;
+import ch.ethz.mxquery.datamodel.xdm.TokenInterface;
+import ch.ethz.mxquery.exceptions.DynamicException;
+import ch.ethz.mxquery.exceptions.ErrorCodes;
+import ch.ethz.mxquery.exceptions.MXQueryException;
+import ch.ethz.mxquery.exceptions.TypeException;
+import ch.ethz.mxquery.model.XDMIterator;
+import ch.ethz.mxquery.update.store.domImpl.NodeToken;
+import ch.ethz.mxquery.util.browser.dom.Document;
+import ch.ethz.mxquery.util.browser.dom.Element;
+import ch.ethz.mxquery.util.browser.dom.Node;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+
+public class MxQueryToJs {
+ public static JsArray<JavaScriptObject> getAsJavaScriptObject(
+ XDMIterator iter) {
+ @SuppressWarnings("unchecked")
+ JsArray<JavaScriptObject> ret = (JsArray<JavaScriptObject>) JsArray
+ .createArray();
+
+ try {
+ TokenInterface tok = iter.next();
+ for (; tok.getEventType() != Type.END_SEQUENCE; tok = iter.next()) {
+ if (Type.isNode(tok.getEventType())) {
+ ret.push(consumeAndProduceNode(tok, iter));
+ } else {
+ ret.push(convertToken(tok));
+ }
+ }
+ } catch (MXQueryException e) {
+ // TODO: handle exception
+ }
+ return ret;
+ }
+
+ /**
+ *
+ * @param tok
+ * @param iter
+ * @return a node that is equal to the input (if it already is a
+ * materialized node, the node itself will be given
+ * @throws MXQueryException
+ */
+ private static JavaScriptObject consumeAndProduceNode(TokenInterface tok,
+ XDMIterator iter) throws MXQueryException {
+ final Document theDocument = Document
+ .createFromGwtNode(com.google.gwt.dom.client.Document.get());
+ int type = tok.getEventType();
+ if (Type.isStartType(type)) {// we have to consume
+ // ArrayList<TokenInterface> tokens = new
+ // ArrayList<TokenInterface>();
+ // tokens.add(tok);
+ Identifier startid = tok.getNodeId();
+ if (tok instanceof NodeToken) {
+ NodeToken nt = (NodeToken) tok;
+ Node node = nt.getNode();
+
+ int level = 1;
+ do {
+ tok = iter.next();
+
+ type = Type.getEventTypeSubstituted(tok.getEventType(),
+ Context.getDictionary());
+
+ switch (type) {
+ case Type.END_SEQUENCE:
+ break;
+ case Type.START_TAG:
+ level++;
+ break;
+ case Type.END_TAG:
+ level--;
+ break;
+ default:
+
+ }
+ } while (level != 0 && type != Type.END_SEQUENCE);
+ return node;
+ }
+
+ // we need to create a new node
+ Element ret = theDocument.createElementNS(tok.getNS(),
+ tok.getLocal());
+ tok = iter.next();
+ while (Type.isAttribute(tok.getEventType())) {
+ ret.setAttributeNS(tok.getNS(), tok.getLocal(),
+ tok.getValueAsString());
+ tok = iter.next();
+ }
+ while (!Type.isEndType(tok.getEventType())) {
+ if (Type.isTextNode(tok.getEventType())) {
+ ret.appendChild(Node.createFromGwtNode(theDocument
+ .getAsGwtDocument().createTextNode(tok.getText())));
+ } else if (Type.isStartType(tok.getEventType())) {
+ ret.appendChild((Node) consumeAndProduceNode(tok, iter));
+ } else {
+ // TODO: does this happen?
+ }
+ tok = iter.next();
+
+ }
+
+ // tok must be END_TAG
+ return ret;
+
+ } else {
+ if (tok instanceof NodeToken) {
+ NodeToken nt = (NodeToken) tok;
+ return nt.getNode();
+ }
+ return createJavaScriptString(tok.getValueAsString());
+ }
+
+ }
+
+ private static JavaScriptObject convertToken(TokenInterface tok) {
+ int type = tok.getTypeAnnotation();
+ if (type == Type.BOOLEAN) {
+ return createJavaScriptBoolean(tok.getBoolean());
+ } else if (Type.isNumericPrimitiveType(type)) {
+ return createJavaScriptNumber(tok.getDouble().getValue());
+ }
+ // TODO more distinctions
+ else {
+ return createJavaScriptString(tok.getValueAsString());
+ }
+ }
+
+ private static native JavaScriptObject createJavaScriptBoolean(
+ boolean boolean1) /*-{
+ return boolean1;
+ }-*/;
+
+ private static native JavaScriptObject createJavaScriptNumber(double d) /*-{
+ return d;
+ }-*/;
+
+ private static native JavaScriptObject createJavaScriptString(String str) /*-{
+ return str;
+ }-*/;
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pm_...@us...> - 2011-06-01 15:42:33
|
Revision: 4379
http://mxquery.svn.sourceforge.net/mxquery/?rev=4379&view=rev
Author: pm_fischer
Date: 2011-06-01 15:42:25 +0000 (Wed, 01 Jun 2011)
Log Message:
-----------
- HOF can now contain forward references
- XQIB uses HOF for callback functions
- updated XQIB samples
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
trunk/MXQuery/xqib_samples/BGColors.html
trunk/MXQuery/xqib_samples/Delete.html
trunk/MXQuery/xqib_samples/DeleteInsert.html
trunk/MXQuery/xqib_samples/DragAndDrop.html
trunk/MXQuery/xqib_samples/EventLocation.html
trunk/MXQuery/xqib_samples/MouseButton.html
trunk/MXQuery/xqib_samples/MultiplicationTable.html
trunk/MXQuery/xqib_samples/OnClickEvent.html
trunk/MXQuery/xqib_samples/OnmouseoverEvent.html
trunk/MXQuery/xqib_samples/OnmouseoverEvent_source.html
trunk/MXQuery/xqib_samples/RESTCallCourses.html
trunk/MXQuery/xqib_samples/RESTCallCourses_source.html
trunk/MXQuery/xqib_samples/SetStyle.html
trunk/MXQuery/xqib_samples/SetStyle_source.html
trunk/MXQuery/xqib_samples/Update.html
trunk/MXQuery/xqib_samples/Update_source.html
trunk/MXQuery/xqib_samples/WeatherREST.html
trunk/MXQuery/xqib_samples/WeatherREST_source.html
trunk/MXQuery/xqib_samples/WeatherRESTasync.html
trunk/MXQuery/xqib_samples/WeatherRESTasyncSlow.html
trunk/MXQuery/xqib_samples/WeatherRESTasyncSlowCached.html
trunk/MXQuery/xqib_samples/WeatherRESTread.html
trunk/MXQuery/xqib_samples/cookies.html
trunk/MXQuery/xqib_samples/log.htm
trunk/MXQuery/xqib_samples/removeEventListener.html
trunk/MXQuery/xqib_samples/textarea.htm
trunk/MXQuery/xqib_samples/tidy.html
trunk/MXQuery/xqib_samples/timer.html
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/extensionsModules/expathhttp/HttpIO.java
trunk/MXQuery/xqib_src/ch/ethz/mxquery/functions/FGPopulator.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/xqib_src/ch/ethz/mxquery/functions/b/Timer.java
trunk/MXQuery_Testing/src/ch/ethz/mxquery/test/xq11streaming/MiscTests.java
Added Paths:
-----------
trunk/MXQuery_Testing/XQTests/Queries/xquery11/hof-forward-samefunc.xq
Modified: trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/src/ch/ethz/mxquery/query/parser/Parser.java 2011-06-01 15:42:25 UTC (rev 4379)
@@ -71,6 +71,7 @@
import ch.ethz.mxquery.iterators.ComputedCommentConstrIterator;
import ch.ethz.mxquery.iterators.ComputedPIConstrIterator;
import ch.ethz.mxquery.iterators.ComputedTextConstrIterator;
+import ch.ethz.mxquery.iterators.DelayedLiteralFunctionItemIterator;
import ch.ethz.mxquery.iterators.DescendantOrSelfIterator;
import ch.ethz.mxquery.iterators.DocOrderIterator;
import ch.ethz.mxquery.iterators.ExceptIterator;
@@ -642,6 +643,8 @@
// This is only possible once all "forward/late" functions are available
for (int i = 0; i < addedFunctions.size(); i++) {
XDMIterator funcToCheck = (XDMIterator) addedFunctions.elementAt(i);
+ funcToCheck.staticInit();
+ funcToCheck.require(0);
funcToCheck.getExpressionCategoryType(co.isScripting());
}
@@ -1983,13 +1986,15 @@
funcCallIter = new UserdefFuncCall(getCurrentContext(),
qname, paramArr, arrParamTypes, body, returnType,
seqTypeIt, exprCategory, getCurrentLoc());
- funcCallIter.staticInit();
- funcCallIter = (UserdefFuncCall)funcCallIter.require(0);
+// funcCallIter.staticInit();
+// funcCallIter = (UserdefFuncCall)funcCallIter.require(0);
if (!allowExternal) {
// if inline function
// compute the closure
// all variable references which are not resolved within the
// context
+ funcCallIter.staticInit();
+ funcCallIter = (UserdefFuncCall)funcCallIter.require(0);
Vector subs = funcCallIter.getAllSubItersRecursive();
Vector closure = new Vector();
for (int i=0;i<subs.size();i++) {
@@ -6618,7 +6623,10 @@
Function f = getCurrentContext().getFunction(qn, arity);
if (f==null)
- throw new StaticException(ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,"Function "+qn+" with arity"+arity+" not available",getCurrentLoc());
+ if (!inProlog)
+ throw new StaticException(ErrorCodes.E0017_STATIC_DOESNT_MATCH_FUNCTION_SIGNATURE,"Function "+qn+" with arity"+arity+" not available",getCurrentLoc());
+ else
+ return new DelayedLiteralFunctionItemIterator(getCurrentContext(), qn, arity);
FunctionItemToken lit = new FunctionItemToken(f);
return new TokenIterator(getCurrentContext(), lit, getCurrentLoc(),false);
Modified: trunk/MXQuery/xqib_samples/BGColors.html
===================================================================
--- trunk/MXQuery/xqib_samples/BGColors.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/BGColors.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -12,7 +12,7 @@
for $button in b:dom()//input[@type="button"]
return
- b:addEventListener($button, "onclick", xs:QName("local:set"))
+ b:addEventListener($button, "onclick", local:set#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/Delete.html
===================================================================
--- trunk/MXQuery/xqib_samples/Delete.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/Delete.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -10,7 +10,7 @@
delete node b:dom()//input
};
- b:addEventListener(b:dom()//input, "onclick", xs:QName("local:onclick"))
+ b:addEventListener(b:dom()//input, "onclick", local:onclick#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/DeleteInsert.html
===================================================================
--- trunk/MXQuery/xqib_samples/DeleteInsert.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/DeleteInsert.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -10,7 +10,7 @@
delete node b:dom()//input, insert node <hr color="red"/> as last into b:dom()//body
};
- b:addEventListener(b:dom()//input, "onclick", xs:QName("local:onclick"))
+ b:addEventListener(b:dom()//input, "onclick", local:onclick#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/DragAndDrop.html
===================================================================
--- trunk/MXQuery/xqib_samples/DragAndDrop.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/DragAndDrop.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -25,9 +25,9 @@
declare sequential function local:onmousedown($loc, $evt) {
- b:addEventListener(b:dom()//body, "onmousemove", xs:QName("local:onmousemove"));
+ b:addEventListener(b:dom()//body, "onmousemove", local:onmousemove#2);
- b:addEventListener(b:dom()//body, "onmouseup", xs:QName("local:onmouseup"));
+ b:addEventListener(b:dom()//body, "onmouseup", local:onmouseup#2);
replace node b:dom()//div[@name="offsetx"] with <div name="offsetx">{$evt/clientX - local:getValuePx(b:getStyle($loc, "left"))}</div>;
@@ -48,16 +48,16 @@
declare sequential function local:onmouseup($loc, $evt) {
- b:removeEventListener(b:dom()//body, "onmouseup", xs:QName("local:onmouseup"));
+ b:removeEventListener(b:dom()//body, "onmouseup", local:onmouseup#2);
- b:removeEventListener(b:dom()//body, "onmousemove", xs:QName("local:onmousemove"));
+ b:removeEventListener(b:dom()//body, "onmousemove", local:onmousemove#2);
replace value of node b:dom()//div[@id="up_counter"] with xs:int(b:dom()//div[@id="up_counter"]) + 1;
};
- b:addEventListener(b:dom()//div[@id="mydiv"], "onmousedown", xs:QName("local:onmousedown"));
+ b:addEventListener(b:dom()//div[@id="mydiv"], "onmousedown", local:onmousedown#2);
Modified: trunk/MXQuery/xqib_samples/EventLocation.html
===================================================================
--- trunk/MXQuery/xqib_samples/EventLocation.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/EventLocation.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -11,7 +11,7 @@
};
for $d in b:dom()//div
- return b:addEventListener($d, "onclick", xs:QName("local:listener"))
+ return b:addEventListener($d, "onclick", local:listener#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/MouseButton.html
===================================================================
--- trunk/MXQuery/xqib_samples/MouseButton.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/MouseButton.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -17,7 +17,7 @@
b:alert("Unknown button")
};
- b:addEventListener(b:dom()//div[@id = "clickHere"], "onmouseup", xs:QName("local:listener"))
+ b:addEventListener(b:dom()//div[@id = "clickHere"], "onmouseup", local:listener#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/MultiplicationTable.html
===================================================================
--- trunk/MXQuery/xqib_samples/MultiplicationTable.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/MultiplicationTable.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -29,7 +29,7 @@
for $i in b:dom()//input[@type='button']
return
- b:addEventListener($i, "onclick", xs:QName("local:generateTable"));
+ b:addEventListener($i, "onclick", local:generateTable#2);
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/OnClickEvent.html
===================================================================
--- trunk/MXQuery/xqib_samples/OnClickEvent.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/OnClickEvent.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -10,7 +10,7 @@
b:alert("Hello, World")
};
- b:addEventListener(b:dom()//input[@id = "myButton"], "onclick", xs:QName ('local:listener'))
+ b:addEventListener(b:dom()//input[@id = "myButton"], "onclick", local:listener#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/OnmouseoverEvent.html
===================================================================
--- trunk/MXQuery/xqib_samples/OnmouseoverEvent.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/OnmouseoverEvent.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -10,7 +10,7 @@
b:alert("Mouse Over!")
};
- b:addEventListener(b:dom()//h1, "onmouseover", xs:QName("local:listener"))
+ b:addEventListener(b:dom()//h1, "onmouseover", local:listener#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/OnmouseoverEvent_source.html
===================================================================
--- trunk/MXQuery/xqib_samples/OnmouseoverEvent_source.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/OnmouseoverEvent_source.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -19,7 +19,7 @@
<span class="functiondeclare">};</span>
<span class="browserfunction">b:addEventListener</span>
- (<span class="browserfunction">b:dom()</span><span class="enhance1">//h1</span>, "onmouseover", "local:listener")
+ (<span class="browserfunction">b:dom()</span><span class="enhance1">//h1</span>, "onmouseover", local:listener#2)
<span class="scripttag"></script></span>
</head>
<body>
Modified: trunk/MXQuery/xqib_samples/RESTCallCourses.html
===================================================================
--- trunk/MXQuery/xqib_samples/RESTCallCourses.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/RESTCallCourses.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -18,7 +18,7 @@
}</p> as last into b:dom()//body
};
- b:addEventListener(b:dom()//input[@name="click"], "onclick", xs:QName("local:clickListener"))
+ b:addEventListener(b:dom()//input[@name="click"], "onclick", local:clickListener#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/RESTCallCourses_source.html
===================================================================
--- trunk/MXQuery/xqib_samples/RESTCallCourses_source.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/RESTCallCourses_source.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -31,7 +31,7 @@
<span class="functiondeclare">};</span>
<span class="browserfunction">b:addEventListener</span>
- (<span class="enhance2">b:dom()//input[@name="click"]</span>, "onclick", "<span class="enhance1">local:clickListener</span>")
+ (<span class="enhance2">b:dom()//input[@name="click"]</span>, "onclick", "<span class="enhance1">local:clickListener#2</span>")
<span class="scripttag"></script></span>
</head>
<body>
Modified: trunk/MXQuery/xqib_samples/SetStyle.html
===================================================================
--- trunk/MXQuery/xqib_samples/SetStyle.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/SetStyle.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -14,7 +14,7 @@
b:setStyle(b:dom()//body, "color", "blue")
};
- b:addEventListener(b:dom()//input, "onclick", xs:QName("local:listener"))
+ b:addEventListener(b:dom()//input, "onclick", local:listener#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/SetStyle_source.html
===================================================================
--- trunk/MXQuery/xqib_samples/SetStyle_source.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/SetStyle_source.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -24,7 +24,7 @@
<span class="functiondeclare">};</span>
<span class="browserfunction">b:addEventListener</span>
- (<span class="enhance2"><span class="browserfunction">b:dom()</span><span class="enhance1">//input</span>, "onclick", "local:listener")
+ (<span class="enhance2"><span class="browserfunction">b:dom()</span><span class="enhance1">//input</span>, "onclick", local:listener#2)
<span class="scripttag"></script></span>
</head>
<span class="enhance1"><body style="color: red"></span>
Modified: trunk/MXQuery/xqib_samples/Update.html
===================================================================
--- trunk/MXQuery/xqib_samples/Update.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/Update.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -10,7 +10,7 @@
insert node <hr color="red"/> as last into b:dom()//body
};
- b:addEventListener(b:dom()//input, "onclick", xs:QName("local:onclick"))
+ b:addEventListener(b:dom()//input, "onclick", local:onclick#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/Update_source.html
===================================================================
--- trunk/MXQuery/xqib_samples/Update_source.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/Update_source.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -21,7 +21,7 @@
<span class="functiondeclare">};</span>
<span class="browserfunction">b:addEventListener</span>
- (<span class="browserfunction">b:dom()</span><span class="enhance2">//input</span>, "onclick", "<span class="enhance3">local:onclick</span>")
+ (<span class="browserfunction">b:dom()</span><span class="enhance2">//input</span>, "onclick", "<span class="enhance3">local:onclick#2</span>")
<span class="scripttag"></script></span>
</head>
<span class="enhance1"><body></span>
Modified: trunk/MXQuery/xqib_samples/WeatherREST.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherREST.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/WeatherREST.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -46,7 +46,7 @@
};
- b:addEventListener(b:dom()//input[@name="button"], "onclick", xs:QName("local:getWeather"))
+ b:addEventListener(b:dom()//input[@name="button"], "onclick", local:getWeather#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/WeatherREST_source.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherREST_source.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/WeatherREST_source.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -53,7 +53,7 @@
<span class="functiondeclare">};</span>
<span class="browserfunction">b:addEventListener</span>
- (<span class="enhance4">b:dom()//input[@name="button"]</span>, "onclick", "<span class="enhance1">local:getWeather</span>")
+ (<span class="enhance4">b:dom()//input[@name="button"]</span>, "onclick", "<span class="enhance1">local:getWeather#2</span>")
<span class="scripttag"></script></span>
</head>
<span class="enhance3"><body></span>
Modified: trunk/MXQuery/xqib_samples/WeatherRESTasync.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherRESTasync.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/WeatherRESTasync.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -45,12 +45,12 @@
declare updating function local:getWeather($loc, $evtObj) {
http-client:async-request(<http-client:request href="forecast2.xml" method="get"/>,
- xs:QName('local:weatherResult')
+ local:weatherResult#1
)
};
- b:addEventListener(b:dom()//input[@name="button"], "onclick", xs:QName("local:getWeather"))
+ b:addEventListener(b:dom()//input[@name="button"], "onclick", local:getWeather#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/WeatherRESTasyncSlow.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherRESTasyncSlow.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/WeatherRESTasyncSlow.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -45,7 +45,7 @@
declare updating function local:getWeather($loc, $evtObj) {
(
- http-client:async-request( <http-client:request href="http://n.ethz.ch/~etterth/slowserver.php?file=forecast2.xml" method="get"/>, xs:QName('local:weatherResult')),
+ http-client:async-request( <http-client:request href="http://n.ethz.ch/~etterth/slowserver.php?file=forecast2.xml" method="get"/>, local:weatherResult#1),
insert node
<div>Loading:
<img src="img/Loading_2_transparent.gif" />
@@ -56,7 +56,7 @@
};
- b:addEventListener(b:dom()//input[@name="button"], "onclick", xs:QName("local:getWeather"))
+ b:addEventListener(b:dom()//input[@name="button"], "onclick", local:getWeather#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/WeatherRESTasyncSlowCached.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherRESTasyncSlowCached.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/WeatherRESTasyncSlowCached.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -45,7 +45,7 @@
declare updating function local:getWeather($loc, $evtObj) {
(
- http-client:async-read("http://n.ethz.ch/~etterth/slowserver.php?file=forecast2.xml",xs:QName('local:weatherResult')),
+ http-client:async-read("http://n.ethz.ch/~etterth/slowserver.php?file=forecast2.xml",local:weatherResult#1),
insert node
<div>Loading:
<img src="img/Loading_2_transparent.gif" />
@@ -56,7 +56,7 @@
};
- b:addEventListener(b:dom()//input[@name="button"], "onclick", xs:QName("local:getWeather"))
+ b:addEventListener(b:dom()//input[@name="button"], "onclick", local:getWeather#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/WeatherRESTread.html
===================================================================
--- trunk/MXQuery/xqib_samples/WeatherRESTread.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/WeatherRESTread.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -44,13 +44,12 @@
};
declare updating function local:getWeather($loc, $evtObj) {
- http-client:async-read("forecast2.xml",
-xs:QName('local:weatherResult')
+ http-client:async-read("forecast2.xml",local:weatherResult#1)
)
};
- b:addEventListener(b:dom()//input[@name="button"], "onclick", xs:QName("local:getWeather"))
+ b:addEventListener(b:dom()//input[@name="button"], "onclick", local:getWeather#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/cookies.html
===================================================================
--- trunk/MXQuery/xqib_samples/cookies.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/cookies.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -24,8 +24,8 @@
};
- b:addEventListener(b:dom()//input[@id="getbutton"], "onclick", xs:QName("local:getCookie")),
- b:addEventListener(b:dom()//input[@id="setbutton"], "onclick", xs:QName("local:setCookie"))
+ b:addEventListener(b:dom()//input[@id="getbutton"], "onclick", local:getCookie#2),
+ b:addEventListener(b:dom()//input[@id="setbutton"], "onclick", local:setCookie#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/log.htm
===================================================================
--- trunk/MXQuery/xqib_samples/log.htm 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/log.htm 2011-06-01 15:42:25 UTC (rev 4379)
@@ -7,7 +7,7 @@
<script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
<script type="application/xquery">
- b:log(b:getStyle(b:dom()//body, "color"))
+ trace(b:getStyle(b:dom()//body, "color"))
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/removeEventListener.html
===================================================================
--- trunk/MXQuery/xqib_samples/removeEventListener.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/removeEventListener.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -26,7 +26,7 @@
<script type="application/xquery">
declare sequential function local:listener($loc, $evtObj) {
- b:removeEventListener($loc, "onclick", xs:QName("local:listener")),
+ b:removeEventListener($loc, "onclick", local:listener#2),
b:alert($loc);
};
Modified: trunk/MXQuery/xqib_samples/textarea.htm
===================================================================
--- trunk/MXQuery/xqib_samples/textarea.htm 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/textarea.htm 2011-06-01 15:42:25 UTC (rev 4379)
@@ -1,28 +1,28 @@
-<!DOCTYPE html>
-<html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>XQIB: Sample page</title>
- <meta charset="UTF-8"/>
- <link href="style.css" rel="stylesheet" type="text/css">
- <script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
- <script type="application/xquery">
- declare updating function local:onclick($loc, $evtObj) {
- let $textarea := b:dom()//textarea[@id='ta1']
-return (
- insert node ' appended text' as last into $textarea,
- insert node <div>{fn:concat('The value in ta1 was "', $textarea/text(),'"')}</div> after $textarea
-)
- };
-
- b:addEventListener(b:dom()//input, "onclick", xs:QName("local:onclick"))
-
- </script>
- </head>
- <body>
- <a href="index.html"><< Index</a>
- <h1>Insert</h1>
- <div><a href="Update.html">Page</a> | <a href="Update_source.html">Source</a></div>
- <p><textarea id="ta1"></textarea></p>
- <input type="button" value="test textarea"/>
- </body>
-</html>
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>XQIB: Sample page</title>
+ <meta charset="UTF-8"/>
+ <link href="style.css" rel="stylesheet" type="text/css">
+ <script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
+ <script type="application/xquery">
+ declare updating function local:onclick($loc, $evtObj) {
+ let $textarea := b:dom()//textarea[@id='ta1']
+return (
+ insert node ' appended text' as last into $textarea,
+ insert node <div>{fn:concat('The value in ta1 was "', $textarea/text(),'"')}</div> after $textarea
+)
+ };
+
+ b:addEventListener(b:dom()//input, "onclick", local:onclick#2)
+
+ </script>
+ </head>
+ <body>
+ <a href="index.html"><< Index</a>
+ <h1>Insert</h1>
+ <div><a href="Update.html">Page</a> | <a href="Update_source.html">Source</a></div>
+ <p><textarea id="ta1"></textarea></p>
+ <input type="button" value="test textarea"/>
+ </body>
+</html>
Modified: trunk/MXQuery/xqib_samples/tidy.html
===================================================================
--- trunk/MXQuery/xqib_samples/tidy.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/tidy.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -22,7 +22,7 @@
};
- b:addEventListener(b:dom()//input[@name="button"], "onclick", xs:QName("local:getWeather"))
+ b:addEventListener(b:dom()//input[@name="button"], "onclick", local:getWeather#2)
</script>
</head>
Modified: trunk/MXQuery/xqib_samples/timer.html
===================================================================
--- trunk/MXQuery/xqib_samples/timer.html 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_samples/timer.html 2011-06-01 15:42:25 UTC (rev 4379)
@@ -7,11 +7,11 @@
<script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
<script type="application/xquery">
declare updating function local:listener() {
- b:timer(1000, xs:QName('local:listener')),
+ (:b:timer(1000, local:listener#0),:)
insert node <div>{fn:current-time()}</div> as last into b:dom()//body
};
- b:timer(1000, xs:QName('local:listener'))
+ b:timer(1000, local:listener#0)
</script>
</head>
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-05-31 12:53:45 UTC (rev 4378)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/client/Environment.java 2011-06-01 15:42:25 UTC (rev 4379)
@@ -7,9 +7,11 @@
import ch.ethz.mxquery.contextConfig.CompilerOptions;
import ch.ethz.mxquery.contextConfig.Context;
import ch.ethz.mxquery.datamodel.QName;
+import ch.ethz.mxquery.datamodel.xdm.FunctionItemToken;
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
import ch.ethz.mxquery.functions.Function;
+import ch.ethz.mxquery.functions.FunctionGallery;
import ch.ethz.mxquery.iterators.browser.EventIterator;
import ch.ethz.mxquery.iterators.browser.ListBasedIterator;
import ch.ethz.mxquery.iterators.browser.SingleNodeIterator;
@@ -35,9 +37,9 @@
public class Environment {
- static Hashtable<NodeAndEventName, List<QnameAndArity>> handlers;
+ static Hashtable<NodeAndEventName, List<FunctionItemToken>> handlers;
static Hashtable<String, Context> modules = new Hashtable<String, Context>();
- static Context modCtx;
+ static Context modCtx = new Context();
static CompilerOptions co;
static int contextcounter = 0;
@@ -90,41 +92,41 @@
}
public static void reset() {
- modCtx = null;
+ //modCtx = null;
co = null;
handlers = null;
}
public static void addEventListener(Element el, String eventName,
- QName functionname, int arity, Context ctx) {
+ FunctionItemToken fi, Context ctx) {
if (eventName.startsWith("on"))
eventName = eventName.substring(2);
if (handlers == null)
- handlers = new Hashtable<NodeAndEventName, List<QnameAndArity>>();
+ handlers = new Hashtable<NodeAndEventName, List<FunctionItemToken>>();
NodeAndEventName test = new NodeAndEventName(el, eventName);
- List<QnameAndArity> lst = handlers.get(test);
+ List<FunctionItemToken> lst = handlers.get(test);
if (lst == null) {
- lst = new ArrayList<QnameAndArity>();
+ lst = new ArrayList<FunctionItemToken>();
handlers.put(test, lst);
}
- lst.add(new QnameAndArity(functionname, arity, ctx));
+ lst.add(fi);
nativeAddEventListener(el, eventName);
}
public static void removeEventListener(Element el, String eventName,
- QName functionname, int arity, Context ctx) throws MXQueryException {
+ FunctionItemToken fi, Context ctx) throws MXQueryException {
if (eventName.startsWith("on"))
eventName = eventName.substring(2);
if (handlers == null)
throw new MXQueryException("Eventlistener cannot be removed",
"handler to remove cannot be found", null);
NodeAndEventName test = new NodeAndEventName(el, eventName);
- List<QnameAndArity> lst = handlers.get(test);
+ List<FunctionItemToken> lst = handlers.get(test);
if (lst == null) {
throw new MXQueryException("Eventlistener cannot be removed",
"handler to remove cannot be found", null);
}
- lst.remove(new QnameAndArity(functionname, arity, ctx));
+ lst.remove(fi);
if (lst.isEmpty()) {
handlers.put(test, null);
nativeRemoveEventListener(el, eventName);
@@ -144,22 +146,20 @@
while (test....
[truncated message content] |
|
From: <max...@us...> - 2011-06-07 14:50:19
|
Revision: 4390
http://mxquery.svn.sourceforge.net/mxquery/?rev=4390&view=rev
Author: maxspeicher
Date: 2011-06-07 14:50:09 +0000 (Tue, 07 Jun 2011)
Log Message:
-----------
Extended NativeFuncCall so that a method is also recognized if the signature contains interfaces/superclasses of the actual parameter objects.
Modified Paths:
--------------
trunk/MXQuery/android/src/ch/ethz/mxquery/android/MXQuery.java
trunk/MXQuery/android/src/ch/ethz/mxquery/functions/fn/Doc.java
trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
Added Paths:
-----------
trunk/MXQuery/android/src/ch/ethz/mxquery/android/UiListener.java
Modified: trunk/MXQuery/android/src/ch/ethz/mxquery/android/MXQuery.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/android/MXQuery.java 2011-06-07 08:33:26 UTC (rev 4389)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/android/MXQuery.java 2011-06-07 14:50:09 UTC (rev 4390)
@@ -4,9 +4,18 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.StringWriter;
+import ch.ethz.mxquery.xqj.MXQueryXQDataSource;
+import ch.ethz.repackaged.xquery.XQConnection;
+import ch.ethz.repackaged.xquery.XQDataSource;
+import ch.ethz.repackaged.xquery.XQException;
+import ch.ethz.repackaged.xquery.XQExpression;
+import ch.ethz.repackaged.xquery.XQSequence;
+
import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.widget.Button;
@@ -14,8 +23,10 @@
public class MXQuery {
+ private static Activity act;
private static Context ctx;
- private static Activity act;
+ private static String xQueryFile;
+ private static XQDataSource xqjd = new MXQueryXQDataSource(MXQueryXQDataSource.XQJ_UPDATE_MODE);
public static void init(Activity act) {
MXQuery.ctx = act.getApplicationContext();
@@ -30,26 +41,18 @@
return act;
}
- public static String doc(String fileName) {
- String result = "";
-
- try {
- BufferedReader in = new BufferedReader(new InputStreamReader(
- ctx.openFileInput(fileName)));
- String line;
-
- while ((line = in.readLine()) != null) {
- result += line;
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- return result;
+ public static void startActivity(Class<?> next) {
+ act.startActivity(new Intent(act, next));
}
+ public static String getXQueryFile() {
+ return xQueryFile;
+ }
+
+ public static void setXQueryFile(int rawResourceId) {
+ xQueryFile = readXQueryFile(rawResourceId);
+ }
+
public static Button getButton(int id) {
return (Button) act.findViewById(id);
}
@@ -58,6 +61,40 @@
return (TextView) act.findViewById(id);
}
+ public static String doQuery(String query) {
+ StringWriter result = new StringWriter();
+
+ try {
+ XQConnection xqjc = xqjd.getConnection();
+ XQExpression xqje = xqjc.createExpression();
+ XQSequence xqjs = xqje.executeQuery(query);
+
+ xqjs.writeSequence(result, null);
+ xqjc.close();
+ } catch (XQException xqe) {
+ xqe.printStackTrace();
+ return xqe.getMessage();
+ }
+ return result.toString();
+ }
+
+ public static String readXQueryFile(int rawResourceId) {
+ BufferedReader in = new BufferedReader(new InputStreamReader(
+ act.getResources().openRawResource(rawResourceId)));
+ String query = "";
+ String line;
+
+ try {
+ while ((line = in.readLine()) != null) {
+ query += line;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return query;
+ }
+
public static Location getLocation() {
Location lastKnownLocation = null;
LocationManager locationManager = (LocationManager) act.getSystemService(Context.LOCATION_SERVICE);
Added: trunk/MXQuery/android/src/ch/ethz/mxquery/android/UiListener.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/android/UiListener.java (rev 0)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/android/UiListener.java 2011-06-07 14:50:09 UTC (rev 4390)
@@ -0,0 +1,26 @@
+package ch.ethz.mxquery.android;
+
+import android.view.View;
+import android.view.View.OnClickListener;
+import ch.ethz.mxquery.android.MXQuery;
+
+public class UiListener implements OnClickListener {
+
+ public String methodName;
+ public static View view;
+
+ public UiListener(String methodName) {
+ this.methodName = methodName;
+ }
+
+ public void onClick(View v) {
+ view = v;
+
+ MXQuery.doQuery(
+ MXQuery.getXQueryFile() +
+ methodName +
+ "(uil:view())"
+ );
+ }
+
+}
Modified: trunk/MXQuery/android/src/ch/ethz/mxquery/functions/fn/Doc.java
===================================================================
--- trunk/MXQuery/android/src/ch/ethz/mxquery/functions/fn/Doc.java 2011-06-07 08:33:26 UTC (rev 4389)
+++ trunk/MXQuery/android/src/ch/ethz/mxquery/functions/fn/Doc.java 2011-06-07 14:50:09 UTC (rev 4390)
@@ -121,13 +121,19 @@
else
throw de;
}
- //if (operation!=OPERATION_DOC)
+
+ /*
+ * Next five commented-out lines: quick workaround to get
+ * fn:doc(...) working on Android.
+ */
+
+// if (operation!=OPERATION_DOC)
rd = IOLib.getInput(uri, false, encoding, loc);
XDMIterator cur = null;
try {
switch(operation) {
case OPERATION_DOC:
- cur = XDMInputFactory.createXMLInput(context, rd, true, Context.NO_VALIDATION, loc);
+ cur = XDMInputFactory.createXMLInput(context, rd, true, context.getInputValidationMode(), loc);
// if (isInValidateExpression())
// cur = XDMInputFactory.createXMLInput(context, rd, true, Context.SCHEMA_VALIDATION_STRICT, loc);
// else
Modified: trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-06-07 08:33:26 UTC (rev 4389)
+++ trunk/MXQuery/src/ch/ethz/mxquery/iterators/NativeFuncCall.java 2011-06-07 14:50:09 UTC (rev 4390)
@@ -19,6 +19,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.util.ArrayList;
import java.util.Vector;
import ch.ethz.mxquery.contextConfig.Context;
@@ -132,17 +133,56 @@
Method meth = null;
Field field = null;
Object res;
+
if (methodName.equals("new")) {
Constructor con = native_function.getConstructor(invocationParamsTypes);
res = con.newInstance(invocationParams);
- }
- else {
+ } else {
+ ArrayList candidates = new ArrayList();
+ Method[] methods = native_function.getMethods();
+
+ /*
+ * This retrieves a correct method even if the parameter
+ * types of the method signature are interfaces or abstract
+ * classes, which are not the actual types of the objects
+ * passed.
+ */
+ for (int i=0; i<methods.length; ++i) {
+ if (methodName.equals(methods[i].getName())) {
+ Class[] params = methods[i].getParameterTypes();
+ boolean add = true;
+
+ if (params.length == invocationParams.length) {
+ for (int j=0; j<params.length; ++j) {
+ if (!params[j].isInstance(invocationParams[j])) {
+ add = false;
+ }
+ }
+
+ if (add) {
+ candidates.add(methods[i]);
+ }
+ }
+ }
+ }
+
try {
meth = native_function.getMethod(methodName, invocationParamsTypes);
res = meth.invoke(instanceToCall, invocationParams);
} catch (NoSuchMethodException e) {
- field = native_function.getField(methodName);
- res = field.get(instanceToCall);
+ /*
+ * The method name provided by XQuery is either the
+ * name of a field, or the method could not be
+ * retrieved b/c the parameter types of the signature
+ * are interfaces or abstract classes.
+ */
+ if (candidates.size() == 1) {
+ meth = (Method) candidates.get(0);
+ res = meth.invoke(instanceToCall, invocationParams);
+ } else {
+ field = native_function.getField(methodName);
+ res = field.get(instanceToCall);
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|