You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2012/08/01 20:15:23 UTC

svn commit: r1368152 [1/2] - in /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery: functions/ runtime/functions/cast/

Author: prestonc
Date: Wed Aug  1 18:15:22 2012
New Revision: 1368152

URL: http://svn.apache.org/viewvc?rev=1368152&view=rev
Log:
The cast framework is now in place. All the functions have been stubbed out, but not completely debugged. Since the framework is done, I have adding all the different type functions. As testing is completed updates will be made to work out the bugs.

Added:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/AbstractCastToOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastScalarEvaluatorFactory.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToAnyURIOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBase64BinaryOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBooleanOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDTDurationOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateTimeOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDecimalOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDoubleOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDurationOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToFloatOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGDayOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGMonthDayOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGMonthOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGYearMonthOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGYearOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToHexBinaryOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToIntegerOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToNotationOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToQNameOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToStringOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToTimeOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToUntypedAtomicOperation.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToYMDurationOperation.java   (with props)
Modified:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml?rev=1368152&r1=1368151&r2=1368152&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml Wed Aug  1 18:15:22 2012
@@ -864,6 +864,7 @@
         <param name="arg" type="item()*"/>
         <param name="type" type="xs:int"/>
         <return type="item()*"/>
+        <runtime type="scalar" class="org.apache.vxquery.runtime.functions.cast.CastScalarEvaluatorFactory"/>
     </operator>
 
     <!-- opext:castable($arg as item()*, $type as xsext:type) as xs:boolean -->

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/AbstractCastToOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/AbstractCastToOperation.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/AbstractCastToOperation.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/AbstractCastToOperation.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,115 @@
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.atomic.XSBinaryPointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDatePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSQNamePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSTimePointable;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+
+import edu.uci.ics.hyracks.data.std.primitive.BooleanPointable;
+import edu.uci.ics.hyracks.data.std.primitive.DoublePointable;
+import edu.uci.ics.hyracks.data.std.primitive.FloatPointable;
+import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
+import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public abstract class AbstractCastToOperation {
+    public void convertAnyURI(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertBase64Binary(XSBinaryPointable binaryp, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertBoolean(BooleanPointable boolp, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertDate(XSDatePointable datep, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertDatetime(XSDateTimePointable datetimep, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertDecimal(XSDecimalPointable decp, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertDouble(DoublePointable doublep, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertDTDuration(IntegerPointable intp, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertDuration(XSDurationPointable durationp, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertFloat(FloatPointable floatp, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertGDay(XSDatePointable datep, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertGMonth(XSDatePointable datep, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertGMonthDay(XSDatePointable datep, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertGYear(XSDatePointable datep, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertGYearMonth(XSDatePointable datep, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertHexBinary(XSBinaryPointable binaryp, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertInteger(LongPointable longp, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertNotation(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertQName(XSQNamePointable qnamep, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertTime(XSTimePointable timep, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertUntypedAtomic(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public void convertYMDuration(IntegerPointable intp, DataOutput dOut) throws SystemException, IOException {
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+}

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/AbstractCastToOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastScalarEvaluatorFactory.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastScalarEvaluatorFactory.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastScalarEvaluatorFactory.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,331 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSBinaryPointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDatePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSQNamePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSTimePointable;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.type.AbstractTypeScalarEvaluatorFactory;
+import org.apache.vxquery.types.BuiltinTypeRegistry;
+import org.apache.vxquery.types.SequenceType;
+
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
+import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.primitive.BooleanPointable;
+import edu.uci.ics.hyracks.data.std.primitive.DoublePointable;
+import edu.uci.ics.hyracks.data.std.primitive.FloatPointable;
+import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
+import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+
+public class CastScalarEvaluatorFactory extends AbstractTypeScalarEvaluatorFactory {
+    private static final long serialVersionUID = 1L;
+
+    public CastScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
+        super(args);
+    }
+
+    @Override
+    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
+            throws AlgebricksException {
+        return new AbstractTypeScalarEvaluator(args, ctx) {
+            final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
+            final DataOutput dOut = abvs.getDataOutput();
+            final TypedPointables tp = new TypedPointables();
+            AbstractCastToOperation aOp = new CastToStringOperation();
+
+            @Override
+            protected void evaluate(TaggedValuePointable tvp, IPointable result) throws SystemException {
+                int tid = getBaseTypeForCasts(tvp.getTag());
+                if (tid == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
+                    // TODO Convert to double
+                    tid = ValueTag.XS_DOUBLE_TAG;
+                    throw new UnsupportedOperationException();
+                }
+
+                abvs.reset();
+                try {
+                    switch (tid) {
+                        case ValueTag.XS_ANY_URI_TAG:
+                            tvp.getValue(tp.utf8sp);
+                            aOp.convertString(tp.utf8sp, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_BASE64_BINARY_TAG:
+                            tvp.getValue(tp.binaryp);
+                            aOp.convertBase64Binary(tp.binaryp, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_BOOLEAN_TAG:
+                            tvp.getValue(tp.boolp);
+                            aOp.convertBoolean(tp.boolp, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_DATE_TAG:
+                            tvp.getValue(tp.datep);
+                            aOp.convertDate(tp.datep, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_DATETIME_TAG:
+                            tvp.getValue(tp.datetimep);
+                            aOp.convertDatetime(tp.datetimep, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                            tvp.getValue(tp.intp);
+                            aOp.convertDTDuration(tp.intp, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp.getValue(tp.decp);
+                            aOp.convertDecimal(tp.decp, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_DOUBLE_TAG:
+                            tvp.getValue(tp.doublep);
+                            aOp.convertDouble(tp.doublep, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_DURATION_TAG:
+                            tvp.getValue(tp.durationp);
+                            aOp.convertDuration(tp.durationp, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp.getValue(tp.floatp);
+                            aOp.convertFloat(tp.floatp, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_G_DAY_TAG:
+                            tvp.getValue(tp.datep);
+                            aOp.convertGDay(tp.datep, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_G_MONTH_TAG:
+                            tvp.getValue(tp.datep);
+                            aOp.convertGMonth(tp.datep, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_G_MONTH_DAY_TAG:
+                            tvp.getValue(tp.datep);
+                            aOp.convertGMonthDay(tp.datep, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_G_YEAR_TAG:
+                            tvp.getValue(tp.datep);
+                            aOp.convertGYear(tp.datep, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_G_YEAR_MONTH_TAG:
+                            tvp.getValue(tp.datep);
+                            aOp.convertGYearMonth(tp.datep, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_HEX_BINARY_TAG:
+                            tvp.getValue(tp.binaryp);
+                            aOp.convertHexBinary(tp.binaryp, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_INTEGER_TAG:
+                            tvp.getValue(tp.longp);
+                            aOp.convertInteger(tp.longp, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_NOTATION_TAG:
+                            tvp.getValue(tp.utf8sp);
+                            aOp.convertNotation(tp.utf8sp, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_QNAME_TAG:
+                            tvp.getValue(tp.qnamep);
+                            aOp.convertQName(tp.qnamep, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_STRING_TAG:
+                            tvp.getValue(tp.utf8sp);
+                            aOp.convertString(tp.utf8sp, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_TIME_TAG:
+                            tvp.getValue(tp.timep);
+                            aOp.convertTime(tp.timep, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_UNTYPED_ATOMIC_TAG:
+                            tvp.getValue(tp.utf8sp);
+                            aOp.convertUntypedAtomic(tp.utf8sp, dOut);
+                            result.set(abvs);
+                            return;
+
+                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                            tvp.getValue(tp.intp);
+                            aOp.convertYMDuration(tp.intp, dOut);
+                            result.set(abvs);
+                            return;
+
+                    }
+                } catch (SystemException se) {
+                    throw se;
+                } catch (Exception e) {
+                    throw new SystemException(ErrorCode.SYSE0001, e);
+                }
+                throw new SystemException(ErrorCode.XPTY0004);
+            }
+
+            @Override
+            protected void setSequenceType(SequenceType sType) {
+                if (sType.getItemType() == BuiltinTypeRegistry.XS_ANY_URI) {
+                    aOp = new CastToAnyURIOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_BASE64_BINARY) {
+                    aOp = new CastToBase64BinaryOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_BOOLEAN) {
+                    aOp = new CastToBooleanOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_DATE) {
+                    aOp = new CastToDateOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_DATETIME) {
+                    aOp = new CastToDateTimeOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_DAY_TIME_DURATION) {
+                    aOp = new CastToDTDurationOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_DECIMAL) {
+                    aOp = new CastToDecimalOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_DOUBLE) {
+                    aOp = new CastToDoubleOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_DURATION) {
+                    aOp = new CastToDurationOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_FLOAT) {
+                    aOp = new CastToFloatOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_G_DAY) {
+                    aOp = new CastToGDayOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_G_MONTH) {
+                    aOp = new CastToGMonthOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_G_MONTH_DAY) {
+                    aOp = new CastToGMonthDayOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_G_YEAR) {
+                    aOp = new CastToGYearOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_G_YEAR_MONTH) {
+                    aOp = new CastToGYearMonthOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_INTEGER) {
+                    aOp = new CastToIntegerOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_HEX_BINARY) {
+                    aOp = new CastToHexBinaryOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_NOTATION) {
+                    aOp = new CastToNotationOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_QNAME) {
+                    aOp = new CastToQNameOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_STRING) {
+                    aOp = new CastToStringOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_TIME) {
+                    aOp = new CastToTimeOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_UNTYPED_ATOMIC) {
+                    aOp = new CastToUntypedAtomicOperation();
+                } else if (sType.getItemType() == BuiltinTypeRegistry.XS_YEAR_MONTH_DURATION) {
+                    aOp = new CastToYMDurationOperation();
+                } else {
+                    aOp = new CastToUntypedAtomicOperation();
+                }
+            }
+
+            private int getBaseTypeForCasts(int tid) throws SystemException {
+                while (true) {
+                    switch (tid) {
+                        case ValueTag.XS_STRING_TAG:
+                        case ValueTag.XS_DECIMAL_TAG:
+                        case ValueTag.XS_INTEGER_TAG:
+                        case ValueTag.XS_FLOAT_TAG:
+                        case ValueTag.XS_DOUBLE_TAG:
+                        case ValueTag.XS_ANY_URI_TAG:
+                        case ValueTag.XS_BOOLEAN_TAG:
+                        case ValueTag.XS_DATE_TAG:
+                        case ValueTag.XS_DATETIME_TAG:
+                        case ValueTag.XS_TIME_TAG:
+                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                        case ValueTag.XS_BASE64_BINARY_TAG:
+                        case ValueTag.XS_HEX_BINARY_TAG:
+                        case ValueTag.XS_QNAME_TAG:
+                        case ValueTag.XS_G_DAY_TAG:
+                        case ValueTag.XS_G_MONTH_DAY_TAG:
+                        case ValueTag.XS_G_MONTH_TAG:
+                        case ValueTag.XS_G_YEAR_MONTH_TAG:
+                        case ValueTag.XS_G_YEAR_TAG:
+                        case ValueTag.XS_UNTYPED_ATOMIC_TAG:
+                            return tid;
+
+                        case ValueTag.XS_ANY_ATOMIC_TAG:
+                            throw new SystemException(ErrorCode.XPTY0004);
+
+                        default:
+                            tid = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tid).getBaseType().getTypeId();
+                    }
+                }
+            }
+
+        };
+    }
+
+    private static class TypedPointables {
+        BooleanPointable boolp = (BooleanPointable) BooleanPointable.FACTORY.createPointable();
+        IntegerPointable intp = (IntegerPointable) IntegerPointable.FACTORY.createPointable();
+        LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
+        FloatPointable floatp = (FloatPointable) FloatPointable.FACTORY.createPointable();
+        DoublePointable doublep = (DoublePointable) DoublePointable.FACTORY.createPointable();
+        UTF8StringPointable utf8sp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
+        XSBinaryPointable binaryp = (XSBinaryPointable) XSBinaryPointable.FACTORY.createPointable();
+        XSDecimalPointable decp = (XSDecimalPointable) XSDecimalPointable.FACTORY.createPointable();
+        XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
+        XSDatePointable datep = (XSDatePointable) XSDatePointable.FACTORY.createPointable();
+        XSDurationPointable durationp = (XSDurationPointable) XSDurationPointable.FACTORY.createPointable();
+        XSTimePointable timep = (XSTimePointable) XSTimePointable.FACTORY.createPointable();
+        XSQNamePointable qnamep = (XSQNamePointable) XSQNamePointable.FACTORY.createPointable();
+    }
+
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastScalarEvaluatorFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastScalarEvaluatorFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToAnyURIOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToAnyURIOperation.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToAnyURIOperation.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToAnyURIOperation.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,30 @@
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.SystemException;
+
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class CastToAnyURIOperation extends AbstractCastToOperation {
+
+    @Override
+    public void convertAnyURI(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_ANY_URI_TAG);
+        dOut.write(stringp.getByteArray(), stringp.getStartOffset(), stringp.getLength());
+    }
+
+    @Override
+    public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_ANY_URI_TAG);
+        dOut.write(stringp.getByteArray(), stringp.getStartOffset(), stringp.getLength());
+    }
+
+    @Override
+    public void convertUntypedAtomic(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        convertString(stringp, dOut);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToAnyURIOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBase64BinaryOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBase64BinaryOperation.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBase64BinaryOperation.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBase64BinaryOperation.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,44 @@
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.commons.codec.binary.Base64OutputStream;
+import org.apache.vxquery.datamodel.accessors.atomic.XSBinaryPointable;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.SystemException;
+
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
+
+public class CastToBase64BinaryOperation extends AbstractCastToOperation {
+
+    @Override
+    public void convertBase64Binary(XSBinaryPointable binaryp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_BASE64_BINARY_TAG);
+        dOut.write(binaryp.getByteArray(), binaryp.getStartOffset(), binaryp.getLength());
+    }
+
+    @Override
+    public void convertHexBinary(XSBinaryPointable binaryp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_BASE64_BINARY_TAG);
+        dOut.write(binaryp.getByteArray(), binaryp.getStartOffset(), binaryp.getLength());
+    }
+
+    @Override
+    public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        ByteArrayAccessibleOutputStream baaos = new ByteArrayAccessibleOutputStream();
+        Base64OutputStream b64os = new Base64OutputStream(baaos, true);
+        b64os.write(stringp.getByteArray(), stringp.getStartOffset() + 2, stringp.getUTFLength());
+
+        dOut.write(ValueTag.XS_STRING_TAG);
+        dOut.write((byte) ((baaos.size() >>> 8) & 0xFF));
+        dOut.write((byte) ((baaos.size() >>> 0) & 0xFF));
+        dOut.write(baaos.getByteArray());
+    }
+
+    @Override
+    public void convertUntypedAtomic(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        convertString(stringp, dOut);
+    }
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBase64BinaryOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBooleanOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBooleanOperation.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBooleanOperation.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBooleanOperation.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,110 @@
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.strings.ICharacterIterator;
+import org.apache.vxquery.runtime.functions.strings.LowerCaseCharacterIterator;
+import org.apache.vxquery.runtime.functions.strings.UTF8StringCharacterIterator;
+
+import edu.uci.ics.hyracks.data.std.primitive.BooleanPointable;
+import edu.uci.ics.hyracks.data.std.primitive.DoublePointable;
+import edu.uci.ics.hyracks.data.std.primitive.FloatPointable;
+import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class CastToBooleanOperation extends AbstractCastToOperation {
+
+    @Override
+    public void convertBoolean(BooleanPointable boolp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_BOOLEAN_TAG);
+        dOut.write(boolp.getByteArray(), boolp.getStartOffset(), boolp.getLength());
+    }
+
+    @Override
+    public void convertDecimal(XSDecimalPointable decp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_BOOLEAN_TAG);
+        if (decp.getDecimalValue() == 1 && decp.getBeforeDecimalPlace() == 0) {
+            dOut.write(1);
+        } else {
+            dOut.write(0);
+        }
+    }
+
+    @Override
+    public void convertDouble(DoublePointable doublep, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_BOOLEAN_TAG);
+        if (doublep.getDouble() == 1) {
+            dOut.write(1);
+        } else {
+            dOut.write(0);
+        }
+    }
+
+    @Override
+    public void convertFloat(FloatPointable floatp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_BOOLEAN_TAG);
+        if (floatp.getFloat() == 1) {
+            dOut.write(1);
+        } else {
+            dOut.write(0);
+        }
+    }
+
+    @Override
+    public void convertInteger(LongPointable longp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_BOOLEAN_TAG);
+        if (longp.getLong() == 1) {
+            dOut.write(1);
+        } else {
+            dOut.write(0);
+        }
+    }
+
+    @Override
+    public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        byte result = 0;
+        ICharacterIterator charIterator = new LowerCaseCharacterIterator(new UTF8StringCharacterIterator(stringp));
+        charIterator.reset();
+        int c;
+        search: for (int index = 0; (c = charIterator.next()) != ICharacterIterator.EOS_CHAR; ++index) {
+            switch (index) {
+                case 0:
+                    if (c == Character.valueOf('1')) {
+                        result = 1;
+                    } else if (c != Character.valueOf('t')) {
+                        break search;
+                    }
+                    break;
+                case 1:
+                    if (c != Character.valueOf('r')) {
+                        break search;
+                    }
+                    break;
+                case 2:
+                    if (c != Character.valueOf('u')) {
+                        break search;
+                    }
+                    break;
+                case 3:
+                    if (c == Character.valueOf('e')) {
+                        result = 1;
+                    }
+                    break;
+                default:
+                    result = 0;
+                    break search;
+            }
+        }
+        dOut.write(ValueTag.XS_BOOLEAN_TAG);
+        dOut.write(result);
+    }
+
+    @Override
+    public void convertUntypedAtomic(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        convertString(stringp, dOut);
+    }
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToBooleanOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDTDurationOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDTDurationOperation.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDTDurationOperation.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDTDurationOperation.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,102 @@
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
+import org.apache.vxquery.datamodel.util.DateTime;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.strings.ICharacterIterator;
+import org.apache.vxquery.runtime.functions.strings.UTF8StringCharacterIterator;
+
+import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class CastToDTDurationOperation extends AbstractCastToOperation {
+
+    @Override
+    public void convertDTDuration(IntegerPointable intp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_DAY_TIME_DURATION_TAG);
+        dOut.write(intp.getByteArray(), intp.getStartOffset(), intp.getLength());
+    }
+
+    @Override
+    public void convertDuration(XSDurationPointable durationp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_DAY_TIME_DURATION_TAG);
+        dOut.writeInt(durationp.getDayTime());
+    }
+
+    @Override
+    public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
+        charIterator.reset();
+        boolean pastDecimal = false, timeSection = false;
+        byte decimalPlace = 3;
+
+        int value = 0;
+        long day = 0, hour = 0, minute = 0, millisecond = 0;
+        long negativeResult = 1;
+
+        // First character 
+        int c = charIterator.next();
+        if (c == Character.valueOf('-')) {
+            negativeResult = -1;
+            c = charIterator.next();
+        }
+        if (c != Character.valueOf('P')) {
+            // Invalid duration format.
+            throw new SystemException(ErrorCode.FORG0001);
+        }
+
+        while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
+            if (Character.isDigit(c)) {
+                value = value * 10 + Character.getNumericValue(c);
+                if (pastDecimal) {
+                    --decimalPlace;
+                }
+            } else if (c == Character.valueOf('T')) {
+                timeSection = true;
+            } else if (c == Character.valueOf('.')) {
+                pastDecimal = true;
+            } else if (c == Character.valueOf('D') && !timeSection) {
+                day = value;
+                value = 0;
+                pastDecimal = false;
+            } else if (c == Character.valueOf('H') && timeSection) {
+                hour = value;
+                value = 0;
+                pastDecimal = false;
+            } else if (c == Character.valueOf('M') && timeSection) {
+                minute = value;
+                value = 0;
+                pastDecimal = false;
+            } else if (c == Character.valueOf('S') && timeSection) {
+                millisecond = (long) (value * Math.pow(10, decimalPlace));
+                value = 0;
+                pastDecimal = false;
+            } else {
+                // Invalid duration format.
+                throw new SystemException(ErrorCode.FORG0001);
+            }
+        }
+
+        long dayTime = day * DateTime.CHRONON_OF_DAY + hour * DateTime.CHRONON_OF_HOUR + minute
+                * DateTime.CHRONON_OF_MINUTE + millisecond;
+        dOut.write(ValueTag.XS_DAY_TIME_DURATION_TAG);
+        dOut.writeInt((int) (negativeResult * dayTime));
+    }
+
+    @Override
+    public void convertYMDuration(IntegerPointable intp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_DAY_TIME_DURATION_TAG);
+        dOut.writeInt(0);
+    }
+
+    @Override
+    public void convertUntypedAtomic(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        convertString(stringp, dOut);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDTDurationOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateOperation.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateOperation.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateOperation.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,85 @@
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.atomic.XSDatePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
+import org.apache.vxquery.datamodel.util.DateTime;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.strings.ICharacterIterator;
+import org.apache.vxquery.runtime.functions.strings.UTF8StringCharacterIterator;
+
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class CastToDateOperation extends AbstractCastToOperation {
+
+    @Override
+    public void convertDate(XSDatePointable datep, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_DATE_TAG);
+        dOut.write(datep.getByteArray(), datep.getStartOffset(), datep.getLength());
+    }
+
+    @Override
+    public void convertDatetime(XSDateTimePointable datetimep, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_DATE_TAG);
+        dOut.writeShort((short) datetimep.getYear());
+        dOut.write((byte) datetimep.getMonth());
+        dOut.write((byte) datetimep.getDay());
+        dOut.write((byte) datetimep.getTimezoneHour());
+        dOut.write((byte) datetimep.getTimezoneMinute());
+    }
+
+    @Override
+    public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
+        charIterator.reset();
+        int c;
+        int index = 0;
+        long[] date = new long[5];
+        boolean positiveTimezone = false;
+
+        // Set defaults
+        date[3] = DateTime.TIMEZONE_HOUR_NULL;
+        date[4] = DateTime.TIMEZONE_MINUTE_NULL;
+
+        while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
+            if (Character.isDigit(c)) {
+                date[index] = date[index] * 10 + Character.getNumericValue(c);
+            } else if (c == Character.valueOf('-') || c == Character.valueOf(':')) {
+                ++index;
+            } else if (c == Character.valueOf('+')) {
+                positiveTimezone = true;
+                ++index;
+            } else {
+                // Invalid date format.
+                throw new SystemException(ErrorCode.FORG0001);
+            }
+        }
+        // Final touches on timezone.
+        if (!positiveTimezone && date[3] != DateTime.TIMEZONE_HOUR_NULL) {
+            date[3] *= -1;
+        }
+        if (!positiveTimezone && date[4] != DateTime.TIMEZONE_MINUTE_NULL) {
+            date[4] *= -1;
+        }
+        // Double check for a valid date
+        if (!DateTime.valid(date[0], date[1], date[2], 0, 0, 0, date[3], date[4])) {
+            throw new SystemException(ErrorCode.FODT0001);
+        }
+
+        dOut.write(ValueTag.XS_DATE_TAG);
+        dOut.writeShort((short) date[0]);
+        dOut.write((byte) date[1]);
+        dOut.write((byte) date[2]);
+        dOut.write((byte) date[3]);
+        dOut.write((byte) date[4]);
+    }
+
+    @Override
+    public void convertUntypedAtomic(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        convertString(stringp, dOut);
+    }
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateTimeOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateTimeOperation.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateTimeOperation.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateTimeOperation.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,102 @@
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.atomic.XSDatePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
+import org.apache.vxquery.datamodel.util.DateTime;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.strings.ICharacterIterator;
+import org.apache.vxquery.runtime.functions.strings.UTF8StringCharacterIterator;
+
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class CastToDateTimeOperation extends AbstractCastToOperation {
+
+    @Override
+    public void convertDate(XSDatePointable datep, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_DATETIME_TAG);
+        dOut.writeShort((short) datep.getYear());
+        dOut.write((byte) datep.getMonth());
+        dOut.write((byte) datep.getDay());
+        dOut.write((byte) 0); // Hour
+        dOut.write((byte) 0); // Minute
+        dOut.writeInt(0); // Millisecond
+        dOut.write((byte) datep.getTimezoneHour());
+        dOut.write((byte) datep.getTimezoneMinute());
+    }
+
+    @Override
+    public void convertDatetime(XSDateTimePointable datetimep, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_DATETIME_TAG);
+        dOut.write(datetimep.getByteArray(), datetimep.getStartOffset(), datetimep.getLength());
+    }
+
+    @Override
+    public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
+        charIterator.reset();
+        int c;
+        int index = 0;
+        long[] date = new long[8];
+        boolean positiveTimezone = false;
+        boolean pastDecimal = false;
+        byte decimalPlace = 3;
+
+        // Set defaults
+        date[6] = DateTime.TIMEZONE_HOUR_NULL;
+        date[7] = DateTime.TIMEZONE_MINUTE_NULL;
+
+        while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
+            if (Character.isDigit(c)) {
+                date[index] = date[index] * 10 + Character.getNumericValue(c);
+                if (pastDecimal) {
+                    --decimalPlace;
+                }
+            } else if (c == Character.valueOf('-') || c == Character.valueOf(':') || c == Character.valueOf('T')) {
+                ++index;
+                pastDecimal = false;
+            } else if (c == Character.valueOf('+')) {
+                pastDecimal = false;
+                positiveTimezone = true;
+                ++index;
+            } else if (c == Character.valueOf('.')) {
+                pastDecimal = true;
+            } else {
+                // Invalid date format.
+                throw new SystemException(ErrorCode.FORG0001);
+            }
+        }
+        // Final touches on seconds and timezone.
+        date[5] = (long) (date[5] * Math.pow(10, decimalPlace));
+        if (!positiveTimezone && date[6] != DateTime.TIMEZONE_HOUR_NULL) {
+            date[6] *= -1;
+        }
+        if (!positiveTimezone && date[7] != DateTime.TIMEZONE_MINUTE_NULL) {
+            date[7] *= -1;
+        }
+        // Double check for a valid datetime
+        if (!DateTime.valid(date[0], date[1], date[2], date[3], date[4], date[5], date[6], date[7])) {
+            throw new SystemException(ErrorCode.FODT0001);
+        }
+        
+        dOut.write(ValueTag.XS_DATETIME_TAG);
+        dOut.writeShort((short) date[0]);
+        dOut.write((byte) date[1]);
+        dOut.write((byte) date[2]);
+        dOut.write((byte) date[3]);
+        dOut.write((byte) date[4]);
+        dOut.writeInt((int) date[5]);
+        dOut.write((byte) date[6]);
+        dOut.write((byte) date[7]);
+    }
+
+    @Override
+    public void convertUntypedAtomic(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        convertString(stringp, dOut);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateTimeOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDecimalOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDecimalOperation.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDecimalOperation.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDecimalOperation.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,132 @@
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.strings.ICharacterIterator;
+import org.apache.vxquery.runtime.functions.strings.UTF8StringCharacterIterator;
+
+import edu.uci.ics.hyracks.data.std.primitive.BooleanPointable;
+import edu.uci.ics.hyracks.data.std.primitive.DoublePointable;
+import edu.uci.ics.hyracks.data.std.primitive.FloatPointable;
+import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class CastToDecimalOperation extends AbstractCastToOperation {
+
+    @Override
+    public void convertBoolean(BooleanPointable boolp, DataOutput dOut) throws SystemException, IOException {
+        long value = (boolp.getBoolean() ? 1 : 0);
+        dOut.write(ValueTag.XS_DECIMAL_TAG);
+        dOut.writeByte(0);
+        dOut.writeLong(value);
+    }
+
+    @Override
+    public void convertDecimal(XSDecimalPointable decp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_DECIMAL_TAG);
+        dOut.write(decp.getByteArray(), decp.getStartOffset(), decp.getLength());
+    }
+
+    @Override
+    public void convertDouble(DoublePointable doublep, DataOutput dOut) throws SystemException, IOException {
+        double doubleValue = doublep.getDouble();
+        byte decimalPlace = 0;
+        // Move the decimal
+        while (doubleValue % 1 != 0) {
+            if (decimalPlace + 1 > XSDecimalPointable.PRECISION) {
+                throw new SystemException(ErrorCode.FOCA0001);
+            }
+            decimalPlace++;
+            doubleValue *= 10;
+        }
+        // Remove extra zeros
+        while (doubleValue != 0 && doubleValue % 10 == 0) {
+            doubleValue /= 10;
+            --decimalPlace;
+        }
+        dOut.write(ValueTag.XS_DECIMAL_TAG);
+        dOut.write(decimalPlace);
+        dOut.writeLong((long) doubleValue);
+    }
+
+    @Override
+    public void convertFloat(FloatPointable floatp, DataOutput dOut) throws SystemException, IOException {
+        float floatValue = floatp.getFloat();
+        byte decimalPlace = 0;
+        // Move the decimal
+        while (floatValue % 1 != 0) {
+            if (decimalPlace + 1 > XSDecimalPointable.PRECISION) {
+                throw new SystemException(ErrorCode.FOCA0001);
+            }
+            decimalPlace++;
+            floatValue *= 10;
+        }
+        // Remove extra zeros
+        while (floatValue != 0 && floatValue % 10 == 0) {
+            floatValue /= 10;
+            --decimalPlace;
+        }
+        dOut.write(ValueTag.XS_DECIMAL_TAG);
+        dOut.write(decimalPlace);
+        dOut.writeLong((long) floatValue);
+    }
+
+    @Override
+    public void convertInteger(LongPointable longp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_DECIMAL_TAG);
+        dOut.write((byte) 0);
+        dOut.writeLong(longp.getLong());
+    }
+
+    @Override
+    public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
+        charIterator.reset();
+        byte decimalPlace = 0;
+        long value = 0;
+        boolean pastDecimal = false, negativeValue = false;
+        int count = 0;
+        int c = 0;
+
+        while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
+            if (count + 1 > XSDecimalPointable.PRECISION) {
+                throw new SystemException(ErrorCode.FOCA0001);
+            } else if (Character.isDigit(c)) {
+                value = value * 10 + Character.getNumericValue(c);
+                if (pastDecimal) {
+                    decimalPlace++;
+                }
+                count++;
+            } else if (c == Character.valueOf('-')) {
+                negativeValue = true;
+            } else if (c == Character.valueOf('.')) {
+                pastDecimal = true;
+            } else {
+                throw new SystemException(ErrorCode.FORG0001);
+            }
+        }
+        if (negativeValue) {
+            value *= -1;
+        }
+
+        // Normalize the value and take off trailing zeros.
+        while (value != 0 && value % 10 == 0) {
+            value -= 10;
+            --decimalPlace;
+        }
+        dOut.write(ValueTag.XS_DECIMAL_TAG);
+        dOut.write(decimalPlace);
+        dOut.writeLong(value);
+    }
+
+    @Override
+    public void convertUntypedAtomic(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        convertString(stringp, dOut);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDecimalOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDoubleOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDoubleOperation.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDoubleOperation.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDoubleOperation.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,103 @@
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.strings.ICharacterIterator;
+import org.apache.vxquery.runtime.functions.strings.UTF8StringCharacterIterator;
+
+import edu.uci.ics.hyracks.data.std.primitive.BooleanPointable;
+import edu.uci.ics.hyracks.data.std.primitive.DoublePointable;
+import edu.uci.ics.hyracks.data.std.primitive.FloatPointable;
+import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class CastToDoubleOperation extends AbstractCastToOperation {
+
+    @Override
+    public void convertBoolean(BooleanPointable boolp, DataOutput dOut) throws SystemException, IOException {
+        double value = (boolp.getBoolean() ? 1 : 0);
+        dOut.write(ValueTag.XS_DOUBLE_TAG);
+        dOut.writeDouble(value);
+    }
+
+    @Override
+    public void convertDecimal(XSDecimalPointable decp, DataOutput dOut) throws SystemException, IOException {
+        double value = decp.doubleValue();
+        dOut.write(ValueTag.XS_DOUBLE_TAG);
+        dOut.writeDouble(value);
+    }
+
+    @Override
+    public void convertDouble(DoublePointable doublep, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_DOUBLE_TAG);
+        dOut.write(doublep.getByteArray(), doublep.getStartOffset(), doublep.getLength());
+    }
+
+    @Override
+    public void convertFloat(FloatPointable floatp, DataOutput dOut) throws SystemException, IOException {
+        double value = floatp.doubleValue();
+        dOut.write(ValueTag.XS_DOUBLE_TAG);
+        dOut.writeDouble(value);
+    }
+
+    @Override
+    public void convertInteger(LongPointable longp, DataOutput dOut) throws SystemException, IOException {
+        double value = longp.doubleValue();
+        dOut.write(ValueTag.XS_DOUBLE_TAG);
+        dOut.writeDouble(value);
+    }
+
+    @Override
+    public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
+        charIterator.reset();
+        byte decimalPlace = 0;
+        long value = 0;
+        boolean pastDecimal = false, negativeValue = false;
+        int c = 0;
+        while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
+            if (Character.isDigit(c)) {
+                value = value * 10 + Character.getNumericValue(c);
+                if (pastDecimal) {
+                    decimalPlace--;
+                }
+            } else if (c == Character.valueOf('-')) {
+                negativeValue = true;
+            } else if (c == Character.valueOf('E')) {
+                break;
+            } else {
+                pastDecimal = true;
+            }
+        }
+        if (c == Character.valueOf('E')) {
+            int moveOffset = 0;
+            while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
+                if (Character.isDigit(c)) {
+                    moveOffset = moveOffset * 10 + Character.getNumericValue(c);
+                } else if (c == Character.valueOf('-')) {
+                    moveOffset = moveOffset * -1;
+                } else {
+                    break;
+                }
+            }
+            decimalPlace += moveOffset;
+        }
+        if (negativeValue) {
+            value *= -1;
+        }
+        double valueDouble = value * Math.pow(10, decimalPlace);
+
+        dOut.write(ValueTag.XS_DOUBLE_TAG);
+        dOut.writeDouble(valueDouble);
+    }
+
+    @Override
+    public void convertUntypedAtomic(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        convertString(stringp, dOut);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDoubleOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDurationOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDurationOperation.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDurationOperation.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDurationOperation.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,114 @@
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
+import org.apache.vxquery.datamodel.util.DateTime;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.strings.ICharacterIterator;
+import org.apache.vxquery.runtime.functions.strings.UTF8StringCharacterIterator;
+
+import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class CastToDurationOperation extends AbstractCastToOperation {
+
+    @Override
+    public void convertDTDuration(IntegerPointable intp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_DURATION_TAG);
+        dOut.writeInt(0);
+        dOut.writeInt(intp.getInteger());
+    }
+
+    @Override
+    public void convertDuration(XSDurationPointable durationp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_DURATION_TAG);
+        dOut.write(durationp.getByteArray(), durationp.getStartOffset(), durationp.getLength());
+    }
+
+    @Override
+    public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
+        charIterator.reset();
+        boolean pastDecimal = false, timeSection = false;
+        byte decimalPlace = 3;
+
+        int value = 0;
+        long year = 0, month = 0, day = 0, hour = 0, minute = 0, millisecond = 0;
+        long negativeResult = 1;
+
+        // First character 
+        int c = charIterator.next();
+        if (c == Character.valueOf('-')) {
+            negativeResult = -1;
+            c = charIterator.next();
+        }
+        if (c != Character.valueOf('P')) {
+            // Invalid duration format.
+            throw new SystemException(ErrorCode.FORG0001);
+        }
+
+        while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
+            if (Character.isDigit(c)) {
+                value = value * 10 + Character.getNumericValue(c);
+                if (pastDecimal) {
+                    --decimalPlace;
+                }
+            } else if (c == Character.valueOf('T')) {
+                timeSection = true;
+            } else if (c == Character.valueOf('.')) {
+                pastDecimal = true;
+            } else if (c == Character.valueOf('Y') && !timeSection) {
+                year = value;
+                value = 0;
+                pastDecimal = false;
+            } else if (c == Character.valueOf('M') && !timeSection) {
+                month = value;
+                value = 0;
+                pastDecimal = false;
+            } else if (c == Character.valueOf('D') && !timeSection) {
+                day = value;
+                value = 0;
+                pastDecimal = false;
+            } else if (c == Character.valueOf('H') && timeSection) {
+                hour = value;
+                value = 0;
+                pastDecimal = false;
+            } else if (c == Character.valueOf('M') && timeSection) {
+                minute = value;
+                value = 0;
+                pastDecimal = false;
+            } else if (c == Character.valueOf('S') && timeSection) {
+                millisecond = (long) (value * Math.pow(10, decimalPlace));
+                value = 0;
+                pastDecimal = false;
+            } else {
+                // Invalid duration format.
+                throw new SystemException(ErrorCode.FORG0001);
+            }
+        }
+
+        long yearMonth = year * 12 + month;
+        long dayTime = day * DateTime.CHRONON_OF_DAY + hour * DateTime.CHRONON_OF_HOUR + minute
+                * DateTime.CHRONON_OF_MINUTE + millisecond;
+        dOut.write(ValueTag.XS_DURATION_TAG);
+        dOut.writeInt((int) (negativeResult * yearMonth));
+        dOut.writeInt((int) (negativeResult * dayTime));
+    }
+
+    @Override
+    public void convertYMDuration(IntegerPointable intp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_DURATION_TAG);
+        dOut.writeInt(intp.getInteger());
+        dOut.writeInt(0);
+    }
+
+    @Override
+    public void convertUntypedAtomic(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        convertString(stringp, dOut);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDurationOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToFloatOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToFloatOperation.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToFloatOperation.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToFloatOperation.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,103 @@
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.strings.ICharacterIterator;
+import org.apache.vxquery.runtime.functions.strings.UTF8StringCharacterIterator;
+
+import edu.uci.ics.hyracks.data.std.primitive.BooleanPointable;
+import edu.uci.ics.hyracks.data.std.primitive.DoublePointable;
+import edu.uci.ics.hyracks.data.std.primitive.FloatPointable;
+import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class CastToFloatOperation extends AbstractCastToOperation {
+
+    @Override
+    public void convertBoolean(BooleanPointable boolp, DataOutput dOut) throws SystemException, IOException {
+        float value = (boolp.getBoolean() ? 1 : 0);
+        dOut.write(ValueTag.XS_FLOAT_TAG);
+        dOut.writeFloat(value);
+    }
+
+    @Override
+    public void convertDecimal(XSDecimalPointable decp, DataOutput dOut) throws SystemException, IOException {
+        float value = decp.floatValue();
+        dOut.write(ValueTag.XS_FLOAT_TAG);
+        dOut.writeFloat(value);
+    }
+
+    @Override
+    public void convertDouble(DoublePointable doublep, DataOutput dOut) throws SystemException, IOException {
+        float value = doublep.floatValue();
+        dOut.write(ValueTag.XS_FLOAT_TAG);
+        dOut.writeFloat(value);
+    }
+
+    @Override
+    public void convertFloat(FloatPointable floatp, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_FLOAT_TAG);
+        dOut.write(floatp.getByteArray(), floatp.getStartOffset(), floatp.getLength());
+    }
+
+    @Override
+    public void convertInteger(LongPointable longp, DataOutput dOut) throws SystemException, IOException {
+        float value = longp.floatValue();
+        dOut.write(ValueTag.XS_FLOAT_TAG);
+        dOut.writeFloat(value);
+    }
+
+    @Override
+    public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
+        charIterator.reset();
+        byte decimalPlace = 0;
+        long value = 0;
+        boolean pastDecimal = false, negativeValue = false;
+        int c = ICharacterIterator.EOS_CHAR;
+        while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
+            if (Character.isDigit(c)) {
+                value = value * 10 + Character.getNumericValue(c);
+                if (pastDecimal) {
+                    decimalPlace--;
+                }
+            } else if (c == Character.valueOf('-')) {
+                negativeValue = true;
+            } else if (c == Character.valueOf('E')) {
+                break;
+            } else {
+                pastDecimal = true;
+            }
+        }
+        if (c == Character.valueOf('E')) {
+            int moveOffset = 0;
+            while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
+                if (Character.isDigit(c)) {
+                    moveOffset = moveOffset * 10 + Character.getNumericValue(c);
+                } else if (c == Character.valueOf('-')) {
+                    moveOffset = moveOffset * -1;
+                } else {
+                    break;
+                }
+            }
+            decimalPlace += moveOffset;
+        }
+        if (negativeValue) {
+            value *= -1;
+        }
+        float valueFloat = (float) (value * Math.pow(10, decimalPlace));
+
+        dOut.write(ValueTag.XS_FLOAT_TAG);
+        dOut.writeFloat(valueFloat);
+    }
+
+    @Override
+    public void convertUntypedAtomic(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        convertString(stringp, dOut);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToFloatOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGDayOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGDayOperation.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGDayOperation.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGDayOperation.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,91 @@
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.atomic.XSDatePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
+import org.apache.vxquery.datamodel.util.DateTime;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.strings.ICharacterIterator;
+import org.apache.vxquery.runtime.functions.strings.UTF8StringCharacterIterator;
+
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class CastToGDayOperation extends AbstractCastToOperation {
+
+    @Override
+    public void convertDate(XSDatePointable datep, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_G_DAY_TAG);
+        dOut.writeShort((short) 1972);
+        dOut.write((byte) 12);
+        dOut.write((byte) datep.getDay());
+        dOut.write((byte) DateTime.TIMEZONE_HOUR_NULL);
+        dOut.write((byte) DateTime.TIMEZONE_MINUTE_NULL);
+    }
+
+    @Override
+    public void convertDatetime(XSDateTimePointable datetimep, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_G_DAY_TAG);
+        dOut.writeShort((short) 1972);
+        dOut.write((byte) 12);
+        dOut.write((byte) datetimep.getDay());
+        dOut.write((byte) 0);
+        dOut.write((byte) 0);
+        dOut.writeInt((int) 0);
+        dOut.write((byte) DateTime.TIMEZONE_HOUR_NULL);
+        dOut.write((byte) DateTime.TIMEZONE_MINUTE_NULL);
+    }
+
+    @Override
+    public void convertGDay(XSDatePointable datep, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_G_DAY_TAG);
+        dOut.write(datep.getByteArray(), datep.getStartOffset(), datep.getLength());
+    }
+
+    @Override
+    public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
+        charIterator.reset();
+        int c;
+        int index = 0;
+        long[] date = new long[6];
+        boolean positiveTimezone = false;
+
+        // Set defaults
+        date[4] = DateTime.TIMEZONE_HOUR_NULL;
+        date[5] = DateTime.TIMEZONE_MINUTE_NULL;
+
+        while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
+            if (Character.isDigit(c)) {
+                date[index] = date[index] * 10 + Character.getNumericValue(c);
+            } else if (c == Character.valueOf('-') || c == Character.valueOf(':')) {
+                ++index;
+            } else if (c == Character.valueOf('+')) {
+                positiveTimezone = true;
+                ++index;
+            } else {
+                // Invalid date format.
+                throw new SystemException(ErrorCode.FORG0001);
+            }
+        }
+        if (!DateTime.valid(1972, 12, date[3], 0, 0, 0, date[4], date[5])) {
+            throw new SystemException(ErrorCode.FODT0001);
+        }
+
+        dOut.write(ValueTag.XS_G_DAY_TAG);
+        dOut.writeShort((short) 1972);
+        dOut.write((byte) 12);
+        dOut.write((byte) date[3]);
+        dOut.write((byte) ((positiveTimezone ? 1 : -1) * date[4]));
+        dOut.write((byte) ((positiveTimezone ? 1 : -1) * date[5]));
+    }
+
+    @Override
+    public void convertUntypedAtomic(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        convertString(stringp, dOut);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGDayOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGMonthDayOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGMonthDayOperation.java?rev=1368152&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGMonthDayOperation.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGMonthDayOperation.java Wed Aug  1 18:15:22 2012
@@ -0,0 +1,91 @@
+package org.apache.vxquery.runtime.functions.cast;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.atomic.XSDatePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
+import org.apache.vxquery.datamodel.util.DateTime;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.strings.ICharacterIterator;
+import org.apache.vxquery.runtime.functions.strings.UTF8StringCharacterIterator;
+
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class CastToGMonthDayOperation extends AbstractCastToOperation {
+
+    @Override
+    public void convertDate(XSDatePointable datep, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_G_MONTH_DAY_TAG);
+        dOut.writeShort((short) 1972);
+        dOut.write((byte) datep.getMonth());
+        dOut.write((byte) datep.getDay());
+        dOut.write((byte) DateTime.TIMEZONE_HOUR_NULL);
+        dOut.write((byte) DateTime.TIMEZONE_MINUTE_NULL);
+    }
+
+    @Override
+    public void convertDatetime(XSDateTimePointable datetimep, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_G_MONTH_DAY_TAG);
+        dOut.writeShort((short) 1972);
+        dOut.write((byte) datetimep.getMonth());
+        dOut.write((byte) datetimep.getDay());
+        dOut.write((byte) 0);
+        dOut.write((byte) 0);
+        dOut.writeInt((int) 0);
+        dOut.write((byte) DateTime.TIMEZONE_HOUR_NULL);
+        dOut.write((byte) DateTime.TIMEZONE_MINUTE_NULL);
+    }
+
+    @Override
+    public void convertGMonthDay(XSDatePointable datep, DataOutput dOut) throws SystemException, IOException {
+        dOut.write(ValueTag.XS_G_MONTH_DAY_TAG);
+        dOut.write(datep.getByteArray(), datep.getStartOffset(), datep.getLength());
+    }
+
+    @Override
+    public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
+        charIterator.reset();
+        int c;
+        int index = 0;
+        long[] date = new long[6];
+        boolean positiveTimezone = false;
+
+        // Set defaults
+        date[4] = DateTime.TIMEZONE_HOUR_NULL;
+        date[5] = DateTime.TIMEZONE_MINUTE_NULL;
+
+        while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
+            if (Character.isDigit(c)) {
+                date[index] = date[index] * 10 + Character.getNumericValue(c);
+            } else if (c == Character.valueOf('-') || c == Character.valueOf(':')) {
+                ++index;
+            } else if (c == Character.valueOf('+')) {
+                positiveTimezone = true;
+                ++index;
+            } else {
+                // Invalid date format.
+                throw new SystemException(ErrorCode.FORG0001);
+            }
+        }
+        if (!DateTime.valid(1972, date[2], date[3], 0, 0, 0, date[4], date[5])) {
+            throw new SystemException(ErrorCode.FODT0001);
+        }
+
+        dOut.write(ValueTag.XS_G_MONTH_DAY_TAG);
+        dOut.writeShort((short) 1972);
+        dOut.write((byte) date[2]);
+        dOut.write((byte) date[3]);
+        dOut.write((byte) ((positiveTimezone ? 1 : -1) * date[4]));
+        dOut.write((byte) ((positiveTimezone ? 1 : -1) * date[5]));
+    }
+
+    @Override
+    public void convertUntypedAtomic(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
+        convertString(stringp, dOut);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToGMonthDayOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native