[saxonhe] 02/03: Align upstream branch source with tarball
Eugene Zhukov
eugene at moszumanska.debian.org
Fri Oct 21 19:31:59 UTC 2016
This is an automated email from the git hooks/post-receive script.
eugene pushed a commit to branch stretch
in repository saxonhe.
commit 0043dc7a35df524471b4d31e684f24eabe67cce1
Author: Eugene Zhukov <eugene at debian.org>
Date: Fri Oct 21 20:17:50 2016 +0300
Align upstream branch source with tarball
---
sf/saxon/xqj/Closable.java | 63 --
sf/saxon/xqj/ObjectConverter.java | 54 --
sf/saxon/xqj/SaxonDuration.java | 333 ---------
sf/saxon/xqj/SaxonXMLGregorianCalendar.java | 759 -------------------
sf/saxon/xqj/SaxonXQConnection.java | 207 ------
sf/saxon/xqj/SaxonXQDataFactory.java | 1042 ---------------------------
sf/saxon/xqj/SaxonXQDataSource.java | 539 --------------
sf/saxon/xqj/SaxonXQDynamicContext.java | 270 -------
sf/saxon/xqj/SaxonXQExpression.java | 132 ----
sf/saxon/xqj/SaxonXQForwardSequence.java | 359 ---------
sf/saxon/xqj/SaxonXQItem.java | 327 ---------
sf/saxon/xqj/SaxonXQItemAccessor.java | 28 -
sf/saxon/xqj/SaxonXQItemType.java | 260 -------
sf/saxon/xqj/SaxonXQMetaData.java | 163 -----
sf/saxon/xqj/SaxonXQPreparedExpression.java | 197 -----
sf/saxon/xqj/SaxonXQSequence.java | 426 -----------
sf/saxon/xqj/SaxonXQSequenceType.java | 71 --
sf/saxon/xqj/SaxonXQStaticContext.java | 368 ----------
sf/saxon/xqj/StandardObjectConverter.java | 284 --------
sf/saxon/xqj/package.html | 38 -
20 files changed, 5920 deletions(-)
diff --git a/sf/saxon/xqj/Closable.java b/sf/saxon/xqj/Closable.java
deleted file mode 100644
index 04cd8bc..0000000
--- a/sf/saxon/xqj/Closable.java
+++ /dev/null
@@ -1,63 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import javax.xml.xquery.XQException;
-
-/**
- * This class represents the common ability of many XQJ classes to be closed. Note that closing an object
- * serves no useful purpose in the Saxon implementation; this complex machinery is provided merely to satisfy
- * the XQJ interface, which is designed to accommodate a client-server implementation.
- */
-public abstract class Closable {
-
- /*@Nullable*/ private Closable container = null;
- private boolean closed = false;
-
- /**
- * Set the container of this closable object. Closing the container causes this object to be
- * treated as closed itself
- * @param container the container of this closable object
- */
-
- public final void setClosableContainer(Closable container) {
- this.container = container;
- }
-
- /**
- * Close this object
- */
-
- public final void close() {
- closed = true;
- }
-
- /**
- * Ask whether this object has been closed.
- * @return true if either the object itself or its container has been closed
- */
-
- public final boolean isClosed() {
- if (container != null && container.isClosed()) {
- close();
- }
- return closed;
- }
-
- /**
- * Check whether this object has been closed (either directly, or by closing its container)
- * @throws XQException if the object has been closed
- */
-
- final void checkNotClosed() throws XQException {
- if (isClosed()) {
- throw new XQException("The XQJ object has been closed");
- }
- }
-}
-
diff --git a/sf/saxon/xqj/ObjectConverter.java b/sf/saxon/xqj/ObjectConverter.java
deleted file mode 100644
index 6112483..0000000
--- a/sf/saxon/xqj/ObjectConverter.java
+++ /dev/null
@@ -1,54 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.om.Item;
-
-import javax.xml.xquery.XQException;
-import javax.xml.xquery.XQItemAccessor;
-import javax.xml.xquery.XQItemType;
-
-/**
- * This interface is based on the "CommonHandler" concept defined in early drafts of XQJ. It defines the data
- * conversion routines used by the Saxon XQJ implementation to convert between native Java objects and XDM values.
- * Most applications will use the Saxon-supplied implementation {@link StandardObjectConverter}, but it is possible
- * to supply an alternative implementation using the method {@link SaxonXQDataFactory#setObjectConverter}
- */
-public interface ObjectConverter {
-
- /**
- * Convert an Item to a Java object
- * @param xqItemAccessor the XQJ object representing the item to be converted
- * @return the Java object that results from the conversion
- * @throws XQException
- */
-
- Object toObject(XQItemAccessor xqItemAccessor) throws XQException;
-
- /**
- * Convert a Java object to an Item, when no information is available about the required type
- * @param value the supplied Java object. If null is supplied, null is returned.
- * @return the Item that results from the conversion
- * @throws XQException if the Java object cannot be converted to an XQItem
- */
-
- Item convertToItem(Object value) throws XQException;
-
- /**
- * Convert a Java object to an Item, when a required type has been specified. Note that Saxon only calls
- * this method when none of the standard conversions defined in the XQJ specification is able to handle
- * the object.
- * @param value the supplied Java object. If null is supplied, null is returned.
- * @param type the required XPath data type
- * @return the Item that results from the conversion
- * @throws XQException if the Java object cannot be converted to an XQItem
- */
-
- public Item convertToItem(Object value, XQItemType type) throws XQException;
-}
-
diff --git a/sf/saxon/xqj/SaxonDuration.java b/sf/saxon/xqj/SaxonDuration.java
deleted file mode 100644
index 45834f0..0000000
--- a/sf/saxon/xqj/SaxonDuration.java
+++ /dev/null
@@ -1,333 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.functions.Component;
-import net.sf.saxon.lib.NamespaceConstant;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.value.*;
-
-import javax.xml.datatype.DatatypeConstants;
-import javax.xml.datatype.Duration;
-import javax.xml.namespace.QName;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Calendar;
-
-/**
- * Saxon implementation of the JAXP class javax.xml.datatype.Duration. This is currently used only by the XQJ
- * interface for XQuery: the normal representation of a duration in Saxon is the class {@link DurationValue}.
- * <p>
- * The JAXP specification for this class defines it in terms of XML Schema 1.0 semantics. This defines a structure
- * with six independent components (year, month, day, hour, minute, second). This implementation is more aligned
- * to the XPath 2.0 semantics of the data type, which essentially defines duration as an integer number of months plus
- * a decimal number of seconds.
- */
-public class SaxonDuration extends Duration {
-
- private DurationValue duration;
-
- /**
- * Create a SaxonDuration that wraps a supplied DurationValue
- * @param duration the value to be wrapped.
- */
-
- public SaxonDuration(DurationValue duration) {
- this.duration = duration;
- }
-
- /**
- * Get the underlying DurationValue
- * @return the underlying DurationValue
- */
-
- public DurationValue getDurationValue() {
- return duration;
- }
-
- /**
- * Get the type of this duration, as one of the values xs:duration, xs:dayTimeDuration, or
- * xs:yearMonthDuration. (Note that the XML Schema namespace URI is used, whereas the current
- * implementation of the superclass uses a provisional URI allocated in a 2003 W3C working draft)
- * @return the type of this duration, as one of the values xs:duration, xs:dayTimeDuration, or
- * xs:yearMonthDuration
- */
-
- public QName getXMLSchemaType() {
- if (duration instanceof DayTimeDurationValue) {
- return new QName(NamespaceConstant.SCHEMA, "dayTimeDuration");
- } else if (duration instanceof YearMonthDurationValue) {
- return new QName(NamespaceConstant.SCHEMA, "yearMonthDuration");
- } else {
- return new QName(NamespaceConstant.SCHEMA, "duration");
- }
- }
-
- /**
- * Returns the sign of this duration in -1,0, or 1.
- *
- * @return -1 if this duration is negative, 0 if the duration is zero,
- * and 1 if the duration is positive.
- */
- public int getSign() {
- return duration.signum();
- }
-
- /**
- * Gets the value of a field.
- * <p/>
- * Fields of a duration object may contain arbitrary large value.
- * Therefore this method is designed to return a {@link Number} object.
- * <p/>
- * In case of YEARS, MONTHS, DAYS, HOURS, and MINUTES, the returned
- * number will be a non-negative integer. In case of seconds,
- * the returned number may be a non-negative decimal value.
- * <p/>
- * The Saxon implementation of duration uses normalized values. This means
- * that the YEARS and DAYS fields may be arbitrarily large, but other
- * components will be limited in size: for example MINUTES will never
- * exceed 60 and MONTHS will never exceed 12.
- *
- * @param field one of the six Field constants (YEARS, MONTHS, DAYS, HOURS,
- * MINUTES, or SECONDS.)
- * @return If the specified field is present, this method returns
- * a non-null non-negative {@link Number} object that
- * represents its value. If it is not present, return null.
- * For YEARS, MONTHS, DAYS, HOURS, and MINUTES, this method
- * returns a {@link java.math.BigInteger} object. For SECONDS, this
- * method returns a {@link java.math.BigDecimal}.
- * @throws NullPointerException If the <code>field</code> is <code>null</code>.
- */
- public Number getField(DatatypeConstants.Field field) {
- try {
- if (field == DatatypeConstants.YEARS) {
- return BigInteger.valueOf(((Int64Value)duration.getComponent(Component.YEAR)).longValue());
- } else if (field == DatatypeConstants.MONTHS) {
- return BigInteger.valueOf(((Int64Value)duration.getComponent(Component.MONTH)).longValue());
- } else if (field == DatatypeConstants.DAYS) {
- return BigInteger.valueOf(((Int64Value)duration.getComponent(Component.DAY)).longValue());
- } else if (field == DatatypeConstants.HOURS) {
- return BigInteger.valueOf(((Int64Value)duration.getComponent(Component.HOURS)).longValue());
- } else if (field == DatatypeConstants.MINUTES) {
- return BigInteger.valueOf(((Int64Value)duration.getComponent(Component.MINUTES)).longValue());
- } else if (field == DatatypeConstants.SECONDS) {
- return (((DecimalValue)duration.getComponent(Component.SECONDS)).getDecimalValue());
- } else {
- throw new IllegalArgumentException("Invalid field");
- }
- } catch (XPathException e) {
- throw new AssertionError("Component extraction on duration failed");
- }
- }
-
- /**
- * Checks if a field is set. In this implementation, all fields are always set.
- * @param field one of the six Field constants (YEARS, MONTHS, DAYS, HOURS,
- * MINUTES, or SECONDS.)
- * @return This implementation always returns true.
- */
- public boolean isSet(DatatypeConstants.Field field) {
- return true;
- }
-
- /**
- * <p>Computes a new duration whose value is <code>this+rhs</code>.</p>
- * <p>This implementation follows the XPath semantics. This means that the operation will fail
- * if the duration is not a yearMonthDuration or a dayTimeDuration.
- * @param rhs <code>Duration</code> to add to this <code>Duration</code>
- * @return non-null valid Duration object.
- * @throws NullPointerException If the rhs parameter is null.
- * @throws IllegalStateException If the durations are not both dayTimeDurations, or
- * both yearMonthDurations.
- * @see #subtract(javax.xml.datatype.Duration)
- */
- public Duration add(Duration rhs) {
- try {
- return new SaxonDuration(duration.add(((SaxonDuration)rhs).duration));
- } catch (XPathException e) {
- throw new IllegalStateException(e.getMessage());
- }
- }
-
- /**
- * <p>Computes a new duration whose value is <code>this-rhs</code>.</p>
- * <p>This implementation follows the XPath semantics. This means that the operation will fail
- * if the duration is not a yearMonthDuration or a dayTimeDuration.
- * @param rhs <code>Duration</code> to subtract from this <code>Duration</code>
- * @return non-null valid Duration object.
- * @throws NullPointerException If the rhs parameter is null.
- * @throws IllegalStateException If the durations are not both dayTimeDurations, or
- * both yearMonthDurations.
- * @see #add(javax.xml.datatype.Duration)
- */
- public Duration subtract(Duration rhs) {
- try {
- return new SaxonDuration(duration.subtract(((SaxonDuration)rhs).duration));
- } catch (XPathException e) {
- throw new IllegalStateException(e.getMessage());
- }
- }
-
- /**
- * Adds this duration to a {@link java.util.Calendar} object.
- * <p/>
- * <p/>
- * Calls {@link java.util.Calendar#add(int,int)} in the
- * order of YEARS, MONTHS, DAYS, HOURS, MINUTES, SECONDS, and MILLISECONDS
- * if those fields are present. Because the {@link java.util.Calendar} class
- * uses int to hold values, there are cases where this method
- * won't work correctly (for example if values of fields
- * exceed the range of int.)
- * </p>
- * <p/>
- * <p/>
- * Also, since this duration class is a Gregorian duration, this
- * method will not work correctly if the given {@link java.util.Calendar}
- * object is based on some other calendar systems.
- * </p>
- * <p/>
- * <p/>
- * Any fractional parts of this <code>Duration</code> object
- * beyond milliseconds will be simply ignored. For example, if
- * this duration is "P1.23456S", then 1 is added to SECONDS,
- * 234 is added to MILLISECONDS, and the rest will be unused.
- * </p>
- * <p/>
- * <p/>
- * Note that because {@link java.util.Calendar#add(int, int)} is using
- * <tt>int</tt>, <code>Duration</code> with values beyond the
- * range of <tt>int</tt> in its fields
- * will cause overflow/underflow to the given {@link java.util.Calendar}.
- * {@link javax.xml.datatype.XMLGregorianCalendar#add(javax.xml.datatype.Duration)} provides the same
- * basic operation as this method while avoiding
- * the overflow/underflow issues.
- *
- * @param calendar A calendar object whose value will be modified.
- * @throws NullPointerException if the calendar parameter is null.
- */
- public void addTo(Calendar calendar) {
- int sign = getSign();
- if (sign == 0) {
- return;
- }
- try {
- calendar.add(getYears()*sign, Calendar.YEAR);
- calendar.add(getMonths()*sign, Calendar.MONTH);
- calendar.add(getDays()*sign, Calendar.DAY_OF_MONTH);
- calendar.add(getHours()*sign, Calendar.HOUR_OF_DAY);
- calendar.add(getMinutes()*sign, Calendar.MINUTE);
- calendar.add((int)((Int64Value)duration.getComponent(Component.WHOLE_SECONDS)).longValue()*sign,
- Calendar.SECOND);
- calendar.add((int)((Int64Value)duration.getComponent(Component.MICROSECONDS)).longValue()*sign/1000,
- Calendar.MILLISECOND);
- } catch (XPathException e) {
- throw new IllegalStateException(e.getMessage());
- }
- }
-
- /**
- * Computes a new duration whose value is <code>factor</code> times
- * longer than the value of this duration.
- * <p/>
- * This implementation follows the XPath semantics. This means that it is defined
- * only on yearMonthDuration and dayTimeDuration. Other cases produce an IllegalStateException.
- *
- * @param factor to multiply by
- * @return returns a non-null valid <code>Duration</code> object
- * @throws IllegalStateException if operation produces fraction in
- * the months field.
- * @throws NullPointerException if the <code>factor</code> parameter is
- * <code>null</code>.
- */
- public Duration multiply(BigDecimal factor) {
- try {
- return new SaxonDuration(duration.multiply(factor.doubleValue()));
- } catch (XPathException e) {
- throw new IllegalStateException(e.getMessage());
- }
- }
-
- /**
- * Returns a new <code>Duration</code> object whose
- * value is <code>-this</code>.
- * <p/>
- * <p/>
- * Since the <code>Duration</code> class is immutable, this method
- * doesn't change the value of this object. It simply computes
- * a new Duration object and returns it.
- *
- * @return always return a non-null valid <code>Duration</code> object.
- */
- public Duration negate() {
- return new SaxonDuration(duration.negate());
- }
-
- /**
- * <p>Converts the years and months fields into the days field
- * by using a specific time instant as the reference point.</p>
- * <p/>
- * This implementation does not support this method
- * @param startTimeInstant <code>Calendar</code> reference point.
- * @return <code>Duration</code> of years and months of this <code>Duration</code> as days.
- * @throws NullPointerException If the startTimeInstant parameter is null.
- * @throws UnsupportedOperationException Always thrown by this implementation.
- */
- public Duration normalizeWith(Calendar startTimeInstant) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * <p>Partial order relation comparison with this <code>Duration</code> instance.</p>
- * <p>This implementation follows the XPath semantics. This means that the result is defined only
- * for dayTimeDuration and yearMonthDuration values, and the result is never indeterminate.
- * <p/>
- * <p>Return:</p>
- * <ul>
- * <li>{@link javax.xml.datatype.DatatypeConstants#LESSER}
- * if this <code>Duration</code> is shorter than <code>duration</code> parameter</li>
- * <li>{@link javax.xml.datatype.DatatypeConstants#EQUAL}
- * if this <code>Duration</code> is equal to <code>duration</code> parameter</li>
- * <li>{@link javax.xml.datatype.DatatypeConstants#GREATER}
- * if this <code>Duration</code> is longer than <code>duration</code> parameter</li>
- * <li>{@link javax.xml.datatype.DatatypeConstants#INDETERMINATE}
- * if a conclusive partial order relation cannot be determined</li>
- * </ul>
- *
- * @param rhs duration to compare
- * @return the relationship between <code>this</code> <code>Duration</code>and <code>duration</code> parameter as
- * {@link javax.xml.datatype.DatatypeConstants#LESSER},
- * {@link javax.xml.datatype.DatatypeConstants#EQUAL},
- * {@link javax.xml.datatype.DatatypeConstants#GREATER}
- * or {@link javax.xml.datatype.DatatypeConstants#INDETERMINATE}.
- * @throws UnsupportedOperationException If the underlying implementation
- * cannot reasonably process the request, e.g. W3C XML Schema allows for
- * arbitrarily large/small/precise values, the request may be beyond the
- * implementations capability.
- * @throws NullPointerException if <code>duration</code> is <code>null</code>.
- * @throws IllegalArgumentException if the operands are not dayTimeDuration or yearMonthDuration values.
- * @see #isShorterThan(javax.xml.datatype.Duration)
- * @see #isLongerThan(javax.xml.datatype.Duration)
- */
- public int compare(/*@NotNull*/ Duration rhs) {
- if (!(rhs instanceof SaxonDuration)) {
- throw new IllegalArgumentException("Supplied duration is not a SaxonDuration");
- }
- Comparable c0 = duration.getSchemaComparable();
- Comparable c1 = ((SaxonDuration)rhs).duration.getSchemaComparable();
- return c0.compareTo(c1);
- }
-
- /**
- * Returns a hash code consistent with the definition of the equals method.
- *
- * @see Object#hashCode()
- */
- public int hashCode() {
- return duration.hashCode();
- }
-}
\ No newline at end of file
diff --git a/sf/saxon/xqj/SaxonXMLGregorianCalendar.java b/sf/saxon/xqj/SaxonXMLGregorianCalendar.java
deleted file mode 100644
index 6ec3ffb..0000000
--- a/sf/saxon/xqj/SaxonXMLGregorianCalendar.java
+++ /dev/null
@@ -1,759 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.functions.Component;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.value.*;
-
-import javax.xml.datatype.DatatypeConstants;
-import javax.xml.datatype.Duration;
-import javax.xml.datatype.XMLGregorianCalendar;
-import javax.xml.namespace.QName;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.*;
-
-/**
- * Saxon implementation of the JAXP class javax.xml.datatype.XMLGregorianCalendar.
- * This is currently used only by the XQJ interface for XQuery: the normal representation of a
- * date, time, or dateTime value in Saxon is with a subclass of {@link CalendarValue}
- * <p>
- * The JAXP specification for this class defines it in terms of XML Schema 1.0 semantics.
- * This implementation is more aligned to the XPath 2.0 semantics of the data types.
- * <p>
- * Note that this class, unlike the representations of all other data types, is mutable.
- */
-public class SaxonXMLGregorianCalendar extends XMLGregorianCalendar {
-
- /*@Nullable*/ private CalendarValue calendarValue;
- /*@Nullable*/ private BigInteger year;
- private int month = DatatypeConstants.FIELD_UNDEFINED;
- private int day = DatatypeConstants.FIELD_UNDEFINED;
- private int hour = DatatypeConstants.FIELD_UNDEFINED;
- private int minute = DatatypeConstants.FIELD_UNDEFINED;
- private int second = DatatypeConstants.FIELD_UNDEFINED;
- private int microsecond = DatatypeConstants.FIELD_UNDEFINED;
- private int tzOffset = DatatypeConstants.FIELD_UNDEFINED;
-
- /**
- * Create a SaxonXMLGregorianCalendar from a Saxon CalendarValue object
- * @param value the CalendarValue
- */
-
- public SaxonXMLGregorianCalendar(/*@NotNull*/ CalendarValue value) {
- clear();
- setCalendarValue(value);
- }
-
- private SaxonXMLGregorianCalendar() {
- }
-
- /**
- * Set the calendar value of this object
- * @param value the calendar value
- */
-
- public void setCalendarValue(/*@NotNull*/ CalendarValue value) {
- calendarValue = value;
- try {
- if (value instanceof GYearValue) {
- year = BigInteger.valueOf(((Int64Value)value.getComponent(Component.YEAR)).longValue());
- } else if (value instanceof GYearMonthValue) {
- year = BigInteger.valueOf(((Int64Value)value.getComponent(Component.YEAR)).longValue());
- month = (int)((Int64Value)value.getComponent(Component.MONTH)).longValue();
- } else if (value instanceof GMonthValue) {
- month = (int)((Int64Value)value.getComponent(Component.MONTH)).longValue();
- } else if (value instanceof GMonthDayValue) {
- month = (int)((Int64Value)value.getComponent(Component.MONTH)).longValue();
- day = (int)((Int64Value)value.getComponent(Component.DAY)).longValue();
- } else if (value instanceof GDayValue) {
- day = (int)((Int64Value)value.getComponent(Component.DAY)).longValue();
- } else if (value instanceof DateValue) {
- year = BigInteger.valueOf(((Int64Value)value.getComponent(Component.YEAR)).longValue());
- month = (int)((Int64Value)value.getComponent(Component.MONTH)).longValue();
- day = (int)((Int64Value)value.getComponent(Component.DAY)).longValue();
- } else if (value instanceof TimeValue) {
- hour = (int)((Int64Value)value.getComponent(Component.HOURS)).longValue();
- minute = (int)((Int64Value)value.getComponent(Component.MINUTES)).longValue();
- second = (int)((Int64Value)value.getComponent(Component.WHOLE_SECONDS)).longValue();
- microsecond = (int)((Int64Value)value.getComponent(Component.MICROSECONDS)).longValue();
- } else {
- year = BigInteger.valueOf(((Int64Value)value.getComponent(Component.YEAR)).longValue());
- month = (int)((Int64Value)value.getComponent(Component.MONTH)).longValue();
- day = (int)((Int64Value)value.getComponent(Component.DAY)).longValue();
- hour = (int)((Int64Value)value.getComponent(Component.HOURS)).longValue();
- minute = (int)((Int64Value)value.getComponent(Component.MINUTES)).longValue();
- second = (int)((Int64Value)value.getComponent(Component.WHOLE_SECONDS)).longValue();
- microsecond = (int)((Int64Value)value.getComponent(Component.MICROSECONDS)).longValue();
- }
- } catch (XPathException e) {
- throw new IllegalArgumentException(e.getMessage());
- }
- }
-
- /**
- * <p>Unset all fields to undefined.</p>
- * <p/>
- * <p>Set all int fields to {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED} and reference fields
- * to null.</p>
- */
- public void clear() {
- year = null;
- month = DatatypeConstants.FIELD_UNDEFINED;
- day = DatatypeConstants.FIELD_UNDEFINED;
- hour = DatatypeConstants.FIELD_UNDEFINED;
- minute = DatatypeConstants.FIELD_UNDEFINED;
- second = DatatypeConstants.FIELD_UNDEFINED;
- microsecond = DatatypeConstants.FIELD_UNDEFINED;
- tzOffset = DatatypeConstants.FIELD_UNDEFINED;
- }
-
- /**
- * <p>Reset this <code>XMLGregorianCalendar</code> to its original values.</p>
- *
- * <p>Saxon does not attempt to reset to the initial value as defined in the specification of
- * the superclass, because it cannot distinguish the initial setting from subsequent changes.
- * This method is therefore synonymous with {@link #clear()}</p>
- */
- public void reset() {
- clear();
- }
-
- /**
- * <p>Set low and high order component of XSD <code>dateTime</code> year field.</p>
- * <p/>
- * <p>Unset this field by invoking the setter with a parameter value of <code>null</code>.</p>
- *
- * @param year value constraints summarized in <a href="#datetimefield-year">year field of date/time field mapping table</a>.
- * @throws IllegalArgumentException if <code>year</code> parameter is
- * outside value constraints for the field as specified in
- * <a href="#datetimefieldmapping">date/time field mapping table</a>.
- */
- public void setYear(BigInteger year) {
- calendarValue = null;
- this.year = year;
- }
-
- /**
- * <p>Set year of XSD <code>dateTime</code> year field.</p>
- * <p/>
- * <p>Unset this field by invoking the setter with a parameter value of
- * {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- * <p/>
- * <p>Note: if the absolute value of the <code>year</code> parameter
- * is less than 10^9, the eon component of the XSD year field is set to
- * <code>null</code> by this method.</p>
- *
- * @param year value constraints are summarized in <a href="#datetimefield-year">year field of date/time field mapping table</a>.
- * If year is {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}, then eon is set to <code>null</code>.
- */
- public void setYear(int year) {
- calendarValue = null;
- this.year = BigInteger.valueOf(year);
- }
-
- /**
- * <p>Set month.</p>
- * <p/>
- * <p>Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- *
- * @param month value constraints summarized in <a href="#datetimefield-month">month field of date/time field mapping table</a>.
- * @throws IllegalArgumentException if <code>month</code> parameter is
- * outside value constraints for the field as specified in
- * <a href="#datetimefieldmapping">date/time field mapping table</a>.
- */
- public void setMonth(int month) {
- calendarValue = null;
- this.month = month;
- }
-
- /**
- * <p>Set days in month.</p>
- * <p/>
- * <p>Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- *
- * @param day value constraints summarized in <a href="#datetimefield-day">day field of date/time field mapping table</a>.
- * @throws IllegalArgumentException if <code>day</code> parameter is
- * outside value constraints for the field as specified in
- * <a href="#datetimefieldmapping">date/time field mapping table</a>.
- */
- public void setDay(int day) {
- calendarValue = null;
- this.day = day;
- }
-
- /**
- * <p>Set the number of minutes in the timezone offset.</p>
- * <p/>
- * <p>Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- *
- * @param offset value constraints summarized in <a href="#datetimefield-timezone">
- * timezone field of date/time field mapping table</a>.
- * @throws IllegalArgumentException if <code>offset</code> parameter is
- * outside value constraints for the field as specified in
- * <a href="#datetimefieldmapping">date/time field mapping table</a>.
- */
- public void setTimezone(int offset) {
- calendarValue = null;
- tzOffset = offset;
- }
-
- /**
- * <p>Set hours.</p>
- * <p/>
- * <p>Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- *
- * @param hour value constraints summarized in <a href="#datetimefield-hour">hour field of date/time field mapping table</a>.
- * @throws IllegalArgumentException if <code>hour</code> parameter is outside value constraints for the field as specified in
- * <a href="#datetimefieldmapping">date/time field mapping table</a>.
- */
- public void setHour(int hour) {
- calendarValue = null;
- this.hour = hour;
- }
-
- /**
- * <p>Set minutes.</p>
- * <p/>
- * <p>Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- *
- * @param minute value constraints summarized in <a href="#datetimefield-minute">minute field of date/time field mapping table</a>.
- * @throws IllegalArgumentException if <code>minute</code> parameter is outside value constraints for the field as specified in
- * <a href="#datetimefieldmapping">date/time field mapping table</a>.
- */
- public void setMinute(int minute) {
- calendarValue = null;
- this.minute = minute;
- }
-
- /**
- * <p>Set seconds.</p>
- * <p/>
- * <p>Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- *
- * @param second value constraints summarized in <a href="#datetimefield-second">second field of date/time field mapping table</a>.
- * @throws IllegalArgumentException if <code>second</code> parameter is outside value constraints for the field as specified in
- * <a href="#datetimefieldmapping">date/time field mapping table</a>.
- */
- public void setSecond(int second) {
- calendarValue = null;
- this.second = second;
- }
-
- /**
- * <p>Set milliseconds.</p>
- * <p/>
- * <p>Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- *
- * @param millisecond value constraints summarized in
- * <a href="#datetimefield-millisecond">millisecond field of date/time field mapping table</a>.
- * @throws IllegalArgumentException if <code>millisecond</code> parameter is outside value constraints for the field as specified
- * in <a href="#datetimefieldmapping">date/time field mapping table</a>.
- */
- public void setMillisecond(int millisecond) {
- calendarValue = null;
- microsecond = millisecond*1000;
- }
-
- /**
- * <p>Set fractional seconds.</p>
- * <p/>
- * <p>Unset this field by invoking the setter with a parameter value of <code>null</code>.</p>
- *
- * @param fractional value constraints summarized in
- * <a href="#datetimefield-fractional">fractional field of date/time field mapping table</a>.
- * @throws IllegalArgumentException if <code>fractional</code> parameter is outside value constraints for the field as specified
- * in <a href="#datetimefieldmapping">date/time field mapping table</a>.
- */
- public void setFractionalSecond(/*@NotNull*/ BigDecimal fractional) {
- calendarValue = null;
- second = fractional.intValue();
- BigInteger micros = fractional.movePointRight(6).toBigInteger();
- micros = micros.remainder(BigInteger.valueOf(1000000));
- microsecond = micros.intValue();
- }
-
- /**
- * <p>Return high order component for XML Schema 1.0 dateTime datatype field for
- * <code>year</code>.
- * <code>null</code> if this optional part of the year field is not defined.</p>
- * <p/>
- * <p>Value constraints for this value are summarized in
- * <a href="#datetimefield-year">year field of date/time field mapping table</a>.</p>
- *
- * @return eon of this <code>XMLGregorianCalendar</code>. The value
- * returned is an integer multiple of 10^9.
- * @see #getYear()
- * @see #getEonAndYear()
- */
- public BigInteger getEon() {
- return year.divide(BigInteger.valueOf(1000000000));
- }
-
- /**
- * <p>Return low order component for XML Schema 1.0 dateTime datatype field for
- * <code>year</code> or {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- * <p/>
- * <p>Value constraints for this value are summarized in
- * <a href="#datetimefield-year">year field of date/time field mapping table</a>.</p>
- *
- * @return year of this <code>XMLGregorianCalendar</code>.
- * @see #getEon()
- * @see #getEonAndYear()
- */
- public int getYear() {
- return year.intValue();
- }
-
- /**
- * <p>Return XML Schema 1.0 dateTime datatype field for
- * <code>year</code>.</p>
- * <p/>
- * <p>Value constraints for this value are summarized in
- * <a href="#datetimefield-year">year field of date/time field mapping table</a>.</p>
- *
- * @return sum of <code>eon</code> and <code>BigInteger.valueOf(year)</code>
- * when both fields are defined. When only <code>year</code> is defined,
- * return it. When both <code>eon</code> and <code>year</code> are not
- * defined, return <code>null</code>.
- * @see #getEon()
- * @see #getYear()
- */
- /*@Nullable*/ public BigInteger getEonAndYear() {
- return year;
- }
-
- /**
- * <p>Return number of month or {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- * <p/>
- * <p>Value constraints for this value are summarized in
- * <a href="#datetimefield-month">month field of date/time field mapping table</a>.</p>
- *
- * @return year of this <code>XMLGregorianCalendar</code>.
- */
- public int getMonth() {
- return month;
- }
-
- /**
- * Return day in month or {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- * <p/>
- * <p>Value constraints for this value are summarized in
- * <a href="#datetimefield-day">day field of date/time field mapping table</a>.</p>
- *
- * @see #setDay(int)
- */
- public int getDay() {
- return day;
- }
-
- /**
- * Return timezone offset in minutes or
- * {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED} if this optional field is not defined.
- * <p/>
- * <p>Value constraints for this value are summarized in
- * <a href="#datetimefield-timezone">timezone field of date/time field mapping table</a>.</p>
- *
- * @see #setTimezone(int)
- */
- public int getTimezone() {
- return tzOffset;
- }
-
- /**
- * Return hours or {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
- * Returns {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED} if this field is not defined.
- * <p/>
- * <p>Value constraints for this value are summarized in
- * <a href="#datetimefield-hour">hour field of date/time field mapping table</a>.</p>
- *
- * @see #setTime(int, int, int)
- */
- public int getHour() {
- return hour;
- }
-
- /**
- * Return minutes or {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- * Returns {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED} if this field is not defined.
- * <p/>
- * <p>Value constraints for this value are summarized in
- * <a href="#datetimefield-minute">minute field of date/time field mapping table</a>.</p>
- *
- * @see #setTime(int, int, int)
- */
- public int getMinute() {
- return minute;
- }
-
- /**
- * <p>Return seconds or {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- * <p/>
- * <p>Returns {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED} if this field is not defined.
- * When this field is not defined, the optional xs:dateTime
- * fractional seconds field, represented by
- * {@link #getFractionalSecond()} and {@link #getMillisecond()},
- * must not be defined.</p>
- * <p/>
- * <p>Value constraints for this value are summarized in
- * <a href="#datetimefield-second">second field of date/time field mapping table</a>.</p>
- *
- * @return Second of this <code>XMLGregorianCalendar</code>.
- * @see #getFractionalSecond()
- * @see #getMillisecond()
- * @see #setTime(int, int, int)
- */
- public int getSecond() {
- return second;
- }
-
- /**
- * <p>Return microsecond precision of {@link #getFractionalSecond()}.</p>
- *
- * <p>This method represents a convenience accessor to infinite
- * precision fractional second value returned by
- * {@link #getFractionalSecond()}. The returned value is the rounded
- * down to microseconds value of
- * {@link #getFractionalSecond()}. When {@link #getFractionalSecond()}
- * returns <code>null</code>, this method must return
- * {@link DatatypeConstants#FIELD_UNDEFINED}.</p>
- *
- * <p>Value constraints for this value are summarized in
- * <a href="#datetimefield-second">second field of date/time field mapping table</a>.</p>
- *
- * @return Millisecond of this <code>XMLGregorianCalendar</code>.
- *
- * @see #getFractionalSecond()
- * @see #setTime(int, int, int)
- */
- public int getMicrosecond() {
-
- BigDecimal fractionalSeconds = getFractionalSecond();
-
- // is field undefined?
- if (fractionalSeconds == null) {
- return DatatypeConstants.FIELD_UNDEFINED;
- }
-
- return getFractionalSecond().movePointRight(6).intValue();
- }
-
-
- /**
- * <p>Return fractional seconds.</p>
- * <p/>
- * <p><code>null</code> is returned when this optional field is not defined.</p>
- * <p/>
- * <p>Value constraints are detailed in
- * <a href="#datetimefield-second">second field of date/time field mapping table</a>.</p>
- * <p/>
- * <p>This optional field can only have a defined value when the
- * xs:dateTime second field, represented by {@link #getSecond()},
- * does not return {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.</p>
- *
- * @return fractional seconds of this <code>XMLGregorianCalendar</code>.
- * @see #getSecond()
- * @see #setTime(int, int, int, java.math.BigDecimal)
- */
- /*@Nullable*/ public BigDecimal getFractionalSecond() {
- if (second == DatatypeConstants.FIELD_UNDEFINED) {
- return null;
- }
- return BigDecimal.valueOf(microsecond).movePointLeft(6);
- }
-
- /**
- * <p>Compare two instances of W3C XML Schema 1.0 date/time datatypes
- * according to partial order relation defined in
- * <a href="http://www.w3.org/TR/xmlschema-2/#dateTime-order">W3C XML Schema 1.0 Part 2, Section 3.2.7.3,
- * <i>Order relation on dateTime</i></a>.</p>
- * <p/>
- * <p><code>xsd:dateTime</code> datatype field mapping to accessors of
- * this class are defined in
- * <a href="#datetimefieldmapping">date/time field mapping table</a>.</p>
- *
- * @param xmlGregorianCalendar Instance of <code>XMLGregorianCalendar</code> to compare
- * @return The relationship between <code>this</code> <code>XMLGregorianCalendar</code> and
- * the specified <code>xmlGregorianCalendar</code> as
- * {@link javax.xml.datatype.DatatypeConstants#LESSER},
- * {@link javax.xml.datatype.DatatypeConstants#EQUAL},
- * {@link javax.xml.datatype.DatatypeConstants#GREATER} or
- * {@link javax.xml.datatype.DatatypeConstants#INDETERMINATE}.
- * @throws NullPointerException if <code>xmlGregorianCalendar</code> is null.
- */
- public int compare(/*@NotNull*/ XMLGregorianCalendar xmlGregorianCalendar) {
- return toCalendarValue().getSchemaComparable().compareTo(
- ((SaxonXMLGregorianCalendar)xmlGregorianCalendar).toCalendarValue().getSchemaComparable());
- }
-
- /**
- * <p>Normalize this instance to UTC.</p>
- * <p/>
- * <p>2000-03-04T23:00:00+03:00 normalizes to 2000-03-04T20:00:00Z</p>
- * <p>Implements W3C XML Schema Part 2, Section 3.2.7.3 (A).</p>
- *
- * @return a copy of this <code>XMLGregorianCalendar</code> normalized to UTC.
- */
- /*@NotNull*/ public XMLGregorianCalendar normalize() {
- return new SaxonXMLGregorianCalendar(toCalendarValue().adjustTimezone(0));
- }
-
- /**
- * <p>Return the lexical representation of <code>this</code> instance.
- * The format is specified in
- * <a href="http://www.w3.org/TR/xmlschema-2/#dateTime-order">XML Schema 1.0 Part 2, Section 3.2.[7-14].1,
- * <i>Lexical Representation</i>".</a></p>
- * <p/>
- * <p>Specific target lexical representation format is determined by
- * {@link #getXMLSchemaType()}.</p>
- *
- * @return XML, as <code>String</code>, representation of this <code>XMLGregorianCalendar</code>
- * @throws IllegalStateException if the combination of set fields
- * does not match one of the eight defined XML Schema builtin date/time datatypes.
- */
- public String toXMLFormat() {
- return toCalendarValue().getStringValue();
- }
-
- /**
- * <p>Return the name of the XML Schema date/time type that this instance
- * maps to. Type is computed based on fields that are set.</p>
- * @return One of the following class constants:
- * {@link javax.xml.datatype.DatatypeConstants#DATETIME},
- * {@link javax.xml.datatype.DatatypeConstants#TIME},
- * {@link javax.xml.datatype.DatatypeConstants#DATE},
- * {@link javax.xml.datatype.DatatypeConstants#GYEARMONTH},
- * {@link javax.xml.datatype.DatatypeConstants#GMONTHDAY},
- * {@link javax.xml.datatype.DatatypeConstants#GYEAR},
- * {@link javax.xml.datatype.DatatypeConstants#GMONTH} or
- * {@link javax.xml.datatype.DatatypeConstants#GDAY}.
- * @throws IllegalStateException if the combination of set fields
- * does not match one of the eight defined XML Schema builtin
- * date/time datatypes.
- */
- public QName getXMLSchemaType() {
- if (second == DatatypeConstants.FIELD_UNDEFINED) {
- if (year == null) {
- if (month == DatatypeConstants.FIELD_UNDEFINED) {
- return DatatypeConstants.GDAY;
- } else if (day == DatatypeConstants.FIELD_UNDEFINED) {
- return DatatypeConstants.GMONTH;
- } else {
- return DatatypeConstants.GMONTHDAY;
- }
- } else if (day == DatatypeConstants.FIELD_UNDEFINED) {
- if (month == DatatypeConstants.FIELD_UNDEFINED) {
- return DatatypeConstants.GYEAR;
- } else {
- return DatatypeConstants.GYEARMONTH;
- }
- }
- return DatatypeConstants.DATE;
- } else if (year == null) {
- return DatatypeConstants.TIME;
- } else {
- return DatatypeConstants.DATETIME;
- }
- }
-
- /**
- * Validate instance by <code>getXMLSchemaType()</code> constraints.
- *
- * @return true if data values are valid.
- */
- public boolean isValid() {
- return true;
- }
-
- /**
- * <p>Add <code>duration</code> to this instance.</p>
- * <p/>
- * <p>The computation is specified in
- * <a href="http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes">XML Schema 1.0 Part 2, Appendix E,
- * <i>Adding durations to dateTimes</i>></a>.
- * <a href="#datetimefieldsmapping">date/time field mapping table</a>
- * defines the mapping from XML Schema 1.0 <code>dateTime</code> fields
- * to this class' representation of those fields.</p>
- *
- * @param duration Duration to add to this <code>XMLGregorianCalendar</code>.
- * @throws NullPointerException when <code>duration</code> parameter is <code>null</code>.
- */
- public void add(/*@NotNull*/ Duration duration) {
- try {
- CalendarValue cv = toCalendarValue().add(((SaxonDuration)duration).getDurationValue());
- setCalendarValue(cv);
- } catch (XPathException err) {
- throw new IllegalArgumentException(err.getMessage());
- }
- }
-
- /**
- * <p>Convert this <code>XMLGregorianCalendar</code> to a {@link java.util.GregorianCalendar}.</p>
- * <p/>
- * <p>When <code>this</code> instance has an undefined field, this
- * conversion relies on the <code>java.util.GregorianCalendar</code> default
- * for its corresponding field. A notable difference between
- * XML Schema 1.0 date/time datatypes and <code>java.util.GregorianCalendar</code>
- * is that Timezone value is optional for date/time datatypes and it is
- * a required field for <code>java.util.GregorianCalendar</code>. See javadoc
- * for <code>java.util.TimeZone.getDefault()</code> on how the default
- * is determined. To explicitly specify the <code>TimeZone</code>
- * instance, see
- * {@link #toGregorianCalendar(java.util.TimeZone, Locale, javax.xml.datatype.XMLGregorianCalendar)}.</p>
- * @see #toGregorianCalendar(java.util.TimeZone, java.util.Locale, javax.xml.datatype.XMLGregorianCalendar)
- */
- public GregorianCalendar toGregorianCalendar() {
- return toCalendarValue().getCalendar();
- }
-
- /**
- * <p>Convert this <code>XMLGregorianCalendar</code> along with provided parameters
- * to a {@link java.util.GregorianCalendar} instance.</p>
- * <p/>
- * <p> Since XML Schema 1.0 date/time datetypes has no concept of
- * timezone ids or daylight savings timezone ids, this conversion operation
- * allows the user to explicitly specify one with
- * <code>timezone</code> parameter.</p>
- * <p/>
- * <p>To compute the return value's <code>TimeZone</code> field,
- * <ul>
- * <li>when parameter <code>timeZone</code> is non-null,
- * it is the timezone field.</li>
- * <li>else when <code>this.getTimezone() != FIELD_UNDEFINED</code>,
- * create a <code>java.util.TimeZone</code> with a custom timezone id
- * using the <code>this.getTimezone()</code>.</li>
- * <li>else when <code>defaults.getTimezone() != FIELD_UNDEFINED</code>,
- * create a <code>java.util.TimeZone</code> with a custom timezone id
- * using <code>defaults.getTimezone()</code>.</li>
- * <li>else use the <code>GregorianCalendar</code> default timezone value
- * for the host is defined as specified by
- * <code>java.util.TimeZone.getDefault()</code>.</li></p>
- * <p/>
- * <p>To ensure consistency in conversion implementations, the new
- * <code>GregorianCalendar</code> should be instantiated in following
- * manner.
- * <ul>
- * <li>Create a new <code>java.util.GregorianCalendar(TimeZone,
- * Locale)</code> with TimeZone set as specified above and the
- * <code>Locale</code> parameter.
- * </li>
- * <li>Initialize all GregorianCalendar fields by calling {@link java.util.GregorianCalendar#clear()}</li>
- * <li>Obtain a pure Gregorian Calendar by invoking
- * <code>GregorianCalendar.setGregorianChange(
- * new Date(Long.MIN_VALUE))</code>.</li>
- * <li>Its fields ERA, YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY,
- * MINUTE, SECOND and MILLISECOND are set using the method
- * <code>Calendar.set(int,int)</code></li>
- * </ul>
- *
- * @param timezone provide Timezone. <code>null</code> is a legal value.
- * @param aLocale provide explicit Locale. Use default GregorianCalendar locale if
- * value is <code>null</code>.
- * @param defaults provide default field values to use when corresponding
- * field for this instance is FIELD_UNDEFINED or null.
- * If <code>defaults</code>is <code>null</code> or a field
- * within the specified <code>defaults</code> is undefined,
- * just use <code>java.util.GregorianCalendar</code> defaults.
- * @return a java.util.GregorianCalendar conversion of this instance.
- */
- /*@NotNull*/ public GregorianCalendar toGregorianCalendar(TimeZone timezone, Locale aLocale, /*@NotNull*/ XMLGregorianCalendar defaults) {
- GregorianCalendar gc = new GregorianCalendar(timezone, aLocale);
- gc.setGregorianChange(new Date(Long.MIN_VALUE));
- gc.set(Calendar.ERA, (year==null ? (defaults.getYear()>0 ? +1 : -1) : year.signum()));
- gc.set(Calendar.YEAR, (year==null ? defaults.getYear() : year.abs().intValue()));
- gc.set(Calendar.MONTH, (month==DatatypeConstants.FIELD_UNDEFINED ? defaults.getMonth() : month));
- gc.set(Calendar.DAY_OF_MONTH, day==DatatypeConstants.FIELD_UNDEFINED ? defaults.getDay() : day);
- gc.set(Calendar.HOUR, hour==DatatypeConstants.FIELD_UNDEFINED ? defaults.getHour() : hour);
- gc.set(Calendar.MINUTE, minute==DatatypeConstants.FIELD_UNDEFINED ? defaults.getMinute() : minute);
- gc.set(Calendar.SECOND, second==DatatypeConstants.FIELD_UNDEFINED ? defaults.getSecond() : second );
- gc.set(Calendar.MILLISECOND, microsecond==DatatypeConstants.FIELD_UNDEFINED
- ? defaults.getMillisecond() : microsecond /1000);
- return gc;
- }
-
- /**
- * <p>Returns a <code>java.util.TimeZone</code> for this class.</p>
- * <p/>
- * <p>If timezone field is defined for this instance,
- * returns TimeZone initialized with custom timezone id
- * of zoneoffset. If timezone field is undefined,
- * try the defaultZoneoffset that was passed in.
- * If defaultZoneoffset is FIELD_UNDEFINED, return
- * default timezone for this host.
- * (Same default as java.util.GregorianCalendar).</p>
- *
- * @param defaultZoneoffset default zoneoffset if this zoneoffset is
- * {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
- * @return TimeZone for this.
- */
- public TimeZone getTimeZone(int defaultZoneoffset) {
- if (tzOffset == DatatypeConstants.FIELD_UNDEFINED) {
- if (defaultZoneoffset == DatatypeConstants.FIELD_UNDEFINED) {
- return new GregorianCalendar().getTimeZone();
- } else {
- return new SimpleTimeZone(defaultZoneoffset*60000, "XXX");
- }
- } else {
- return new SimpleTimeZone(tzOffset*60000, "XXX");
- }
- }
-
- /**
- * <p>Creates and returns a copy of this object.</p>
- *
- * @return copy of this <code>Object</code>
- */
- /*@NotNull*/@SuppressWarnings({"CloneDoesntCallSuperClone"})
- public Object clone() {
- SaxonXMLGregorianCalendar s = new SaxonXMLGregorianCalendar();
- s.setYear(year);
- s.setMonth(month);
- s.setDay(day);
- s.setHour(hour);
- s.setMinute(minute);
- s.setSecond(second);
- s.setMillisecond(microsecond/1000);
- s.setTimezone(tzOffset);
- return s;
- }
-
- /**
- * Convert this SaxonXMLGregorianCalendar to a Saxon CalendarValue object
- * @return the corresponding CalendarValue
- */
-
- /*@Nullable*/ public CalendarValue toCalendarValue() {
- if (calendarValue != null) {
- return calendarValue;
- }
- if (second == DatatypeConstants.FIELD_UNDEFINED) {
- if (year == null) {
- if (month == DatatypeConstants.FIELD_UNDEFINED) {
- return new GDayValue((byte)day, tzOffset);
- } else if (day == DatatypeConstants.FIELD_UNDEFINED) {
- return new GMonthValue((byte)month, tzOffset);
- } else {
- return new GMonthDayValue((byte)month, (byte)day, tzOffset);
- }
- } else if (day == DatatypeConstants.FIELD_UNDEFINED) {
- if (month == DatatypeConstants.FIELD_UNDEFINED) {
- return new GYearValue(year.intValue(), tzOffset, true);
- } else {
- return new GYearMonthValue(year.intValue(), (byte)month, tzOffset, true);
- }
- }
- return new DateValue(year.intValue(), (byte)month, (byte)day, tzOffset,true);
- } else if (year == null) {
- return new TimeValue((byte)hour, (byte)minute, (byte)second, getMicrosecond(), tzOffset);
- } else {
- return new DateTimeValue(year.intValue(), (byte)month, (byte)day,
- (byte)hour, (byte)minute, (byte)second, getMicrosecond(), tzOffset, true);
- }
- }
-}
\ No newline at end of file
diff --git a/sf/saxon/xqj/SaxonXQConnection.java b/sf/saxon/xqj/SaxonXQConnection.java
deleted file mode 100644
index 9e87683..0000000
--- a/sf/saxon/xqj/SaxonXQConnection.java
+++ /dev/null
@@ -1,207 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.Configuration;
-import net.sf.saxon.query.DynamicQueryContext;
-import net.sf.saxon.query.StaticQueryContext;
-import net.sf.saxon.query.XQueryExpression;
-import net.sf.saxon.trans.XPathException;
-
-import javax.xml.xquery.*;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-
-/**
- * Saxon implementation of the XQL interface XQConnection. This interface represents a
- * "connection" between an XQuery application and an XQuery server. In Saxon the client
- * and server run in the same process so the concept of a connection is rather notional,
- * and some of the properties have little meaning. However, the connection is the factory
- * object used to compile queries.
- * <p>
- * For Javadoc descriptions of the public methors, see the XQJ documentation.
- */
-public class SaxonXQConnection extends SaxonXQDataFactory implements XQConnection {
-
- private Configuration config;
- private SaxonXQStaticContext staticContext;
-
- /**
- * Create an SaxonXQConnection from a SaxonXQDataSource
- * @param dataSource the data source.
- */
- SaxonXQConnection(SaxonXQDataSource dataSource) {
- config = dataSource.getConfiguration();
- staticContext = new SaxonXQStaticContext(config);
- init();
- }
-
- /**
- * Get the Saxon Configuration in use. Changes made to this Configuration will affect this
- * data source and XQJ connections created from it (either before or afterwards).
- * @return the configuration in use.
- */
-
- public Configuration getConfiguration() {
- return config;
- }
-
- public void commit() throws XQException {
- checkNotClosed();
- }
-
- public XQExpression createExpression() throws XQException {
- checkNotClosed();
- return new SaxonXQExpression(this);
- }
-
- public XQExpression createExpression(XQStaticContext properties) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(properties, "properties");
- return new SaxonXQExpression(this, (SaxonXQStaticContext)properties);
- }
-
-
- public boolean getAutoCommit() throws XQException {
- return false;
- }
-
- public XQMetaData getMetaData() throws XQException {
- checkNotClosed();
- return new SaxonXQMetaData(this);
- }
-
-
- public XQStaticContext getStaticContext() throws XQException {
- checkNotClosed();
- return new SaxonXQStaticContext(staticContext);
- }
-
- public XQPreparedExpression prepareExpression(InputStream xquery) throws XQException {
- return prepareExpression(xquery, staticContext);
- }
-
- public XQPreparedExpression prepareExpression(InputStream xquery, XQStaticContext properties) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(xquery, "xquery");
- SaxonXQDataSource.checkNotNull(properties, "properties");
- try {
- SaxonXQStaticContext xqStaticContext = ((SaxonXQStaticContext)properties);
- StaticQueryContext sqc = xqStaticContext.getSaxonStaticQueryContext();
- XQueryExpression exp = sqc.compileQuery(xquery, null);
- DynamicQueryContext dqc = new DynamicQueryContext(config);
- dqc.setApplyFunctionConversionRulesToExternalVariables(false);
- return new SaxonXQPreparedExpression(this, exp, xqStaticContext, dqc);
- } catch (XPathException e) {
- throw newXQException(e);
- } catch (IOException e) {
- throw newXQException(e);
- } catch (NullPointerException e) {
- throw newXQException(e);
- }
- }
-
- public XQPreparedExpression prepareExpression(Reader xquery) throws XQException {
- return prepareExpression(xquery, staticContext);
- }
-
- public XQPreparedExpression prepareExpression(Reader xquery, XQStaticContext properties) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(xquery, "xquery");
- SaxonXQDataSource.checkNotNull(properties, "properties");
- try {
- SaxonXQStaticContext xqStaticContext = ((SaxonXQStaticContext)properties);
- StaticQueryContext sqc = xqStaticContext.getSaxonStaticQueryContext();
- XQueryExpression exp = sqc.compileQuery(xquery);
- DynamicQueryContext dqc = new DynamicQueryContext(config);
- dqc.setApplyFunctionConversionRulesToExternalVariables(false);
- return new SaxonXQPreparedExpression(this, exp, xqStaticContext, dqc);
- } catch (XPathException e) {
- throw newXQException(e);
- } catch (IOException e) {
- throw newXQException(e);
- } catch (NullPointerException e) {
- throw newXQException(e);
- }
- }
-
- public XQPreparedExpression prepareExpression(String xquery) throws XQException {
- return prepareExpression(xquery, staticContext);
- }
-
- public XQPreparedExpression prepareExpression(String xquery, XQStaticContext properties) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(xquery, "xquery");
- SaxonXQDataSource.checkNotNull(properties, "properties");
- try {
- SaxonXQStaticContext xqStaticContext = ((SaxonXQStaticContext)properties);
- StaticQueryContext sqc = xqStaticContext.getSaxonStaticQueryContext();
- XQueryExpression exp = sqc.compileQuery(xquery);
- DynamicQueryContext dqc = new DynamicQueryContext(config);
- dqc.setApplyFunctionConversionRulesToExternalVariables(false);
- return new SaxonXQPreparedExpression(this, exp, xqStaticContext, dqc);
- } catch (XPathException e) {
- throw newXQException(e);
- } catch (NullPointerException e) {
- throw newXQException(e);
- }
- }
-
- /**
- * Copy a prepared expression to create a new prepared expression. The prepared expression to be copied
- * may belong to a different connection. This method (which is a Saxon extension to the XQJ interface) allows
- * a query to be compiled once, and reused concurrently under multiple connections in multiple threads. The
- * compiled code of the existing query and its static context are shared with the original query, but a new
- * dynamic context is established, so that the two expressions can safely be used in parallel.
- * @param expression the XQPreparedExpression to be copied. This must have been created using Saxon, and it
- * must have been created with an XQConnection derived from the same XQDataSource as this connection.
- * @return a copy of the supplied expression, that can be used in a different connection or thread with its
- * own dynamic context. The new copy of the expression belongs to this connection, and can be used in the same
- * way as an expression created using any of the prepareExpression() methods on this class.
- * @throws XQException, for example if either of the connections has been closed
- */
-
- public XQPreparedExpression copyPreparedExpression(XQPreparedExpression expression) throws XQException {
- checkNotClosed();
- if (!(expression instanceof SaxonXQPreparedExpression)) {
- throw new IllegalArgumentException("Supplied expression must be compiled using Saxon");
- }
- XQueryExpression xqe = ((SaxonXQPreparedExpression)expression).getXQueryExpression();
- if (xqe.getExecutable().getConfiguration() != config) {
- throw new IllegalArgumentException("Supplied expression must derive from the same XQDataSource");
- }
- SaxonXQStaticContext sqc = ((SaxonXQPreparedExpression)expression).getSaxonXQStaticContext();
- DynamicQueryContext dqc = new DynamicQueryContext(config);
- return new SaxonXQPreparedExpression(this, xqe, sqc, dqc);
- }
-
- public void rollback() throws XQException {
- checkNotClosed();
- // no-op
- }
-
-
- public void setAutoCommit(boolean autoCommit) throws XQException {
- checkNotClosed();
- // no-op
- }
-
- public void setStaticContext(XQStaticContext properties) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(properties, "properties");
- staticContext = new SaxonXQStaticContext((SaxonXQStaticContext)properties);
- }
-
- /*@NotNull*/ private XQException newXQException(Exception err) {
- XQException xqe = new XQException(err.getMessage());
- xqe.initCause(err);
- return xqe;
- }
-}
-
diff --git a/sf/saxon/xqj/SaxonXQDataFactory.java b/sf/saxon/xqj/SaxonXQDataFactory.java
deleted file mode 100644
index 8c41d07..0000000
--- a/sf/saxon/xqj/SaxonXQDataFactory.java
+++ /dev/null
@@ -1,1042 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.Configuration;
-import net.sf.saxon.dom.DOMObjectModel;
-import net.sf.saxon.evpull.EventIterator;
-import net.sf.saxon.evpull.EventToStaxBridge;
-import net.sf.saxon.evpull.PullEventSource;
-import net.sf.saxon.evpull.StaxToEventBridge;
-import net.sf.saxon.expr.EarlyEvaluationContext;
-import net.sf.saxon.expr.JPConverter;
-import net.sf.saxon.expr.StaticProperty;
-import net.sf.saxon.expr.parser.Token;
-import net.sf.saxon.lib.AugmentedSource;
-import net.sf.saxon.lib.NamespaceConstant;
-import net.sf.saxon.lib.Validation;
-import net.sf.saxon.om.DocumentInfo;
-import net.sf.saxon.om.NodeInfo;
-import net.sf.saxon.om.StandardNames;
-import net.sf.saxon.pattern.*;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.type.*;
-import net.sf.saxon.value.*;
-import net.sf.saxon.value.StringValue;
-import net.sf.saxon.z.IntToIntHashMap;
-import net.sf.saxon.z.IntToIntMap;
-import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-
-import javax.xml.datatype.Duration;
-import javax.xml.datatype.XMLGregorianCalendar;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.Source;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.xquery.*;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.lang.Boolean;
-import java.lang.Byte;
-import java.lang.Double;
-import java.lang.Exception;
-import java.lang.Float;
-import java.lang.Integer;
-import java.lang.Long;
-import java.lang.Object;
-import java.lang.Short;
-import java.lang.String;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Saxon implementation of the XQJ interface XQDataFactory. This is an abstract superclass for SaxonXQDataSource
- * and SaxonXQConnection, both of which provide the factory methods in this interface.
- * <p>
- * For Javadoc specifications of the public methods in this class, see the XQJ documentation.
- */
-
-public abstract class SaxonXQDataFactory extends Closable implements XQDataFactory {
-
- private ObjectConverter objectConverter;
-
- abstract Configuration getConfiguration();
-
- // Two-way mapping between XQJ integer codes for built-in types and the Saxon equivalents
-
- /*@NotNull*/ private static IntToIntMap XQJtoSaxonTypeTranslation = new IntToIntHashMap(80);
- /*@NotNull*/ private static IntToIntMap saxonToXQJTypeTranslation = new IntToIntHashMap(80);
-
- private static void map(int x, int y) {
- XQJtoSaxonTypeTranslation.put(x, y);
- saxonToXQJTypeTranslation.put(y, x);
- }
-
- static {
- map(XQItemType.XQBASETYPE_ANYSIMPLETYPE, StandardNames.XS_ANY_SIMPLE_TYPE);
- map(XQItemType.XQBASETYPE_ANYTYPE, StandardNames.XS_ANY_TYPE);
- map(XQItemType.XQBASETYPE_ANYURI, StandardNames.XS_ANY_URI);
- map(XQItemType.XQBASETYPE_BASE64BINARY, StandardNames.XS_BASE64_BINARY);
- map(XQItemType.XQBASETYPE_BOOLEAN, StandardNames.XS_BOOLEAN);
- map(XQItemType.XQBASETYPE_BYTE, StandardNames.XS_BYTE);
- map(XQItemType.XQBASETYPE_DATE, StandardNames.XS_DATE);
- map(XQItemType.XQBASETYPE_DATETIME, StandardNames.XS_DATE_TIME);
- map(XQItemType.XQBASETYPE_DECIMAL, StandardNames.XS_DECIMAL);
- map(XQItemType.XQBASETYPE_DOUBLE, StandardNames.XS_DOUBLE);
- map(XQItemType.XQBASETYPE_DURATION, StandardNames.XS_DURATION);
- map(XQItemType.XQBASETYPE_ENTITIES, StandardNames.XS_ENTITIES);
- map(XQItemType.XQBASETYPE_ENTITY, StandardNames.XS_ENTITY);
- map(XQItemType.XQBASETYPE_FLOAT, StandardNames.XS_FLOAT);
- map(XQItemType.XQBASETYPE_GDAY, StandardNames.XS_G_DAY);
- map(XQItemType.XQBASETYPE_GMONTH, StandardNames.XS_G_MONTH);
- map(XQItemType.XQBASETYPE_GMONTHDAY, StandardNames.XS_G_MONTH_DAY);
- map(XQItemType.XQBASETYPE_GYEAR, StandardNames.XS_G_YEAR);
- map(XQItemType.XQBASETYPE_GYEARMONTH, StandardNames.XS_G_YEAR_MONTH);
- map(XQItemType.XQBASETYPE_HEXBINARY, StandardNames.XS_HEX_BINARY);
- map(XQItemType.XQBASETYPE_ID, StandardNames.XS_ID);
- map(XQItemType.XQBASETYPE_IDREF, StandardNames.XS_IDREF);
- map(XQItemType.XQBASETYPE_IDREFS, StandardNames.XS_IDREFS);
- map(XQItemType.XQBASETYPE_INT, StandardNames.XS_INT);
- map(XQItemType.XQBASETYPE_INTEGER, StandardNames.XS_INTEGER);
- map(XQItemType.XQBASETYPE_LANGUAGE, StandardNames.XS_LANGUAGE);
- map(XQItemType.XQBASETYPE_LONG, StandardNames.XS_LONG);
- map(XQItemType.XQBASETYPE_NAME, StandardNames.XS_NAME);
- map(XQItemType.XQBASETYPE_NCNAME, StandardNames.XS_NCNAME);
- map(XQItemType.XQBASETYPE_NEGATIVE_INTEGER, StandardNames.XS_NEGATIVE_INTEGER);
- map(XQItemType.XQBASETYPE_NMTOKEN, StandardNames.XS_NMTOKEN);
- map(XQItemType.XQBASETYPE_NMTOKENS, StandardNames.XS_NMTOKENS);
- map(XQItemType.XQBASETYPE_NONNEGATIVE_INTEGER, StandardNames.XS_NON_NEGATIVE_INTEGER);
- map(XQItemType.XQBASETYPE_NONPOSITIVE_INTEGER, StandardNames.XS_NON_POSITIVE_INTEGER);
- map(XQItemType.XQBASETYPE_NORMALIZED_STRING, StandardNames.XS_NORMALIZED_STRING);
- map(XQItemType.XQBASETYPE_NOTATION, StandardNames.XS_NOTATION);
- map(XQItemType.XQBASETYPE_POSITIVE_INTEGER, StandardNames.XS_POSITIVE_INTEGER);
- map(XQItemType.XQBASETYPE_QNAME, StandardNames.XS_QNAME);
- map(XQItemType.XQBASETYPE_SHORT, StandardNames.XS_SHORT);
- map(XQItemType.XQBASETYPE_STRING, StandardNames.XS_STRING);
- map(XQItemType.XQBASETYPE_TIME, StandardNames.XS_TIME);
- map(XQItemType.XQBASETYPE_TOKEN, StandardNames.XS_TOKEN);
- map(XQItemType.XQBASETYPE_UNSIGNED_BYTE, StandardNames.XS_UNSIGNED_BYTE);
- map(XQItemType.XQBASETYPE_UNSIGNED_INT, StandardNames.XS_UNSIGNED_INT);
- map(XQItemType.XQBASETYPE_UNSIGNED_LONG, StandardNames.XS_UNSIGNED_LONG);
- map(XQItemType.XQBASETYPE_UNSIGNED_SHORT, StandardNames.XS_UNSIGNED_SHORT);
- map(XQItemType.XQBASETYPE_ANYATOMICTYPE, StandardNames.XS_ANY_ATOMIC_TYPE);
- map(XQItemType.XQBASETYPE_DAYTIMEDURATION, StandardNames.XS_DAY_TIME_DURATION);
- map(XQItemType.XQBASETYPE_UNTYPED, StandardNames.XS_UNTYPED);
- map(XQItemType.XQBASETYPE_UNTYPEDATOMIC, StandardNames.XS_UNTYPED_ATOMIC);
- map(XQItemType.XQBASETYPE_YEARMONTHDURATION, StandardNames.XS_YEAR_MONTH_DURATION);
- }
-
- /**
- * Get the XQJ type code corresponding to a given Saxon type code
- * @param type the Saxon type code
- * @return the corresponding XQJ type code
- */
-
- static int mapSaxonTypeToXQJ(int type) {
- return saxonToXQJTypeTranslation.get(type);
- }
-
-
- protected void init() {
- objectConverter = new StandardObjectConverter(this);
- }
-
- /**
- * Set the ObjectConverter to be used. This allows user-defined object conversions to override
- * or supplement the standard conversions
- * @param converter the user-supplied ObjectConverter
- */
-
- public void setObjectConverter(ObjectConverter converter) {
- objectConverter = converter;
- }
-
- /**
- * Get the ObjectConverter in use. This will either be the default object converter supplied by Saxon,
- * or a user-supplied ObjectConverter if one has been set.
- * @return the ObjectConverter in use.
- */
-
- public ObjectConverter getObjectConverter() {
- return objectConverter;
- }
-
- /**
- * Create an atomic item type object representing a particular built-in atomic type
- *
- * @param baseType the built-in atomic type, typically a constant such as
- * XQItemType.XQBASETYPE_BOOLEAN
- * @return the corresponding XQItemType
- * @throws XQException if the supplied baseType parameter is not an atomic type
- */
-
- /*@NotNull*/ public XQItemType createAtomicType(int baseType) throws XQException {
- checkNotClosed();
- int saxonType = XQJtoSaxonTypeTranslation.get(baseType);
- if (saxonType == XQJtoSaxonTypeTranslation.getDefaultValue()) {
- throw new XQException("Unknown base type " + baseType);
- }
- SchemaType st = BuiltInType.getSchemaType(saxonType);
- if (st instanceof AtomicType) {
- return new SaxonXQItemType((AtomicType)st, getConfiguration());
- } else {
- throw new XQException("baseType " + baseType + " is not atomic");
- }
- }
-
- /**
- * See interface definition, and description of Saxon extensions below.
- *
- * <p>In addition to the actions described in the XQJ interface definitions, Saxon allows the
- * typename to be a name representing a Java external type. In this case the URI part of the QName
- * must be {@link net.sf.saxon.lib.NamespaceConstant#JAVA_TYPE}, and the local part of the name must be the Java class
- * name (qualified with its package name)
- * @param baseType the "baseType" (in XQJ terminology)
- * @param typename the qualified name of the type
- * @param schemaURI the location of a schema document in which the type is defined (may be null)
- * @return the item type definition
- * @throws XQException
- */
-
-
- /*@NotNull*/ public XQItemType createAtomicType(int baseType, /*@Nullable*/ QName typename, URI schemaURI) throws XQException {
- checkNotClosed();
- if (typename == null) {
- return createAtomicType(baseType);
- }
- if (typename.getNamespaceURI().equals(NamespaceConstant.JAVA_TYPE)) {
- String className = typename.getLocalPart();
- Configuration config = getConfiguration();
- try {
- Class javaClass = config.getClass(className, false, null);
- return new SaxonXQItemType(new ExternalObjectType(javaClass, config), config);
- } catch (XPathException e) {
- throw new XQException(e.getMessage());
- }
- }
- SchemaType st = getConfiguration().getSchemaType(getFingerprint(typename));
- if (st == null) {
- loadSchema(schemaURI);
- st = getConfiguration().getSchemaType(getFingerprint(typename));
- }
- if (st == null) {
- throw new XQException("Type " + typename + " not found in schema");
- } else if (st instanceof AtomicType) {
- return new SaxonXQItemType((AtomicType)st, getConfiguration());
- } else {
- throw new XQException("Type " + typename + " is not atomic");
- }
- }
-
-
- /*@NotNull*/ public XQItemType createAttributeType(/*@Nullable*/ QName nodename, int basetype) throws XQException {
- checkNotClosed();
- Configuration config = getConfiguration();
-
- int saxonType = XQJtoSaxonTypeTranslation.get(basetype);
- if (saxonType == XQJtoSaxonTypeTranslation.getDefaultValue()) {
- throw new XQException("Unknown base type " + basetype);
- }
- SchemaType st = BuiltInType.getSchemaType(saxonType);
- if (!(st.isSimpleType())) {
- throw new XQException("baseType " + basetype + " is not a simple type");
- }
- ContentTypeTest contentTest = new ContentTypeTest(Type.ATTRIBUTE, st, config, false);
- if (nodename == null) {
- return new SaxonXQItemType(contentTest, config);
- } else {
- NameTest nameTest = new NameTest(
- Type.ATTRIBUTE, nodename.getNamespaceURI(), nodename.getLocalPart(), config.getNamePool());
- CombinedNodeTest combined = new CombinedNodeTest(nameTest, Token.INTERSECT, contentTest);
- return new SaxonXQItemType(combined, config);
- }
-
- }
-
- /*@NotNull*/ public XQItemType createAttributeType(/*@Nullable*/ QName nodename, int basetype, /*@Nullable*/ QName typename, URI schemaURI) throws XQException {
- checkNotClosed();
- if (typename == null) {
- return createAttributeType(nodename, basetype);
- }
- Configuration config = getConfiguration();
-
- SchemaType st = BuiltInType.getSchemaType(getFingerprint(typename));
- if (st == null) {
- loadSchema(schemaURI);
- st = getConfiguration().getSchemaType(getFingerprint(typename));
- }
- if (st == null) {
- throw new XQException("Type " + typename + " not found in schema");
- } else if (!(st.isSimpleType())) {
- throw new XQException("Type " + typename + " is not a simple type");
- }
- ContentTypeTest contentTest = new ContentTypeTest(Type.ATTRIBUTE, st, config, false);
- if (nodename == null) {
- return new SaxonXQItemType(contentTest, config);
- } else {
- NameTest nameTest = new NameTest(
- Type.ATTRIBUTE, nodename.getNamespaceURI(), nodename.getLocalPart(), config.getNamePool());
- CombinedNodeTest combined = new CombinedNodeTest(nameTest, Token.INTERSECT, contentTest);
- return new SaxonXQItemType(combined, config);
- }
- }
-
- /*@NotNull*/ public XQItemType createCommentType() throws XQException {
- checkNotClosed();
- return new SaxonXQItemType(NodeKindTest.COMMENT, getConfiguration());
- }
-
- /*@NotNull*/ public XQItemType createDocumentElementType(XQItemType elementType) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(elementType, "elementType");
- ItemType itemType = ((SaxonXQItemType)elementType).getSaxonItemType();
- if (itemType instanceof NodeTest && (((NodeTest)itemType).getNodeKindMask() & (1<<Type.ELEMENT)) != 0) {
- return new SaxonXQItemType(new DocumentNodeTest((NodeTest)itemType), getConfiguration());
- } else {
- throw new XQException("elementType is of wrong kind");
- }
- }
-
- /*@NotNull*/ public XQItemType createDocumentSchemaElementType(XQItemType type) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(type, "type");
- ItemType itemType = ((SaxonXQItemType)type).getSaxonItemType();
- if (itemType instanceof NodeTest && (((NodeTest)itemType).getNodeKindMask() & (1<<Type.ELEMENT)) != 0) {
- return new SaxonXQItemType(new DocumentNodeTest((NodeTest)itemType), getConfiguration());
- } else {
- throw new XQException("elementType is of wrong kind");
- }
- }
-
- /*@NotNull*/ public XQItemType createDocumentType() throws XQException {
- checkNotClosed();
- return new SaxonXQItemType(NodeKindTest.DOCUMENT, getConfiguration());
- }
-
- /*@NotNull*/ public XQItemType createElementType(/*@Nullable*/ QName nodename, int basetype) throws XQException {
- checkNotClosed();
- Configuration config = getConfiguration();
-
- if (basetype == XQItemType.XQBASETYPE_ANYTYPE) {
- if (nodename == null) {
- return new SaxonXQItemType(NodeKindTest.ELEMENT, config);
- } else {
- return new SaxonXQItemType(
- new NameTest(Type.ELEMENT, getFingerprint(nodename), config.getNamePool()),
- config);
- }
- }
-
- int saxonType = XQJtoSaxonTypeTranslation.get(basetype);
- if (saxonType == XQJtoSaxonTypeTranslation.getDefaultValue()) {
- throw new XQException("Unknown base type " + basetype);
- }
- SchemaType st = BuiltInType.getSchemaType(saxonType);
- ContentTypeTest contentTest = new ContentTypeTest(Type.ELEMENT, st, config, false);
- if (nodename == null) {
- return new SaxonXQItemType(contentTest, config);
- } else {
- NameTest nameTest = new NameTest(
- Type.ELEMENT, nodename.getNamespaceURI(), nodename.getLocalPart(), config.getNamePool());
- CombinedNodeTest combined = new CombinedNodeTest(nameTest, Token.INTERSECT, contentTest);
- return new SaxonXQItemType(combined, config);
- }
-
- }
-
- /*@NotNull*/ public XQItemType createElementType(/*@Nullable*/ QName nodename, int basetype, /*@Nullable*/ QName typename, URI schemaURI, boolean allowNill)
- throws XQException {
- checkNotClosed();
- if (typename == null) {
- return createElementType(nodename, basetype);
- }
- Configuration config = getConfiguration();
-
- SchemaType st = BuiltInType.getSchemaType(getFingerprint(typename));
- if (st == null) {
- loadSchema(schemaURI);
- st = getConfiguration().getSchemaType(getFingerprint(typename));
- }
- if (st == null) {
- throw new XQException("Type " + typename + " not found in schema");
- }
-
- ContentTypeTest contentTest = new ContentTypeTest(Type.ELEMENT, st, config, allowNill);
- if (nodename == null) {
- return new SaxonXQItemType(contentTest, config);
- } else {
- NameTest nameTest = new NameTest(
- Type.ELEMENT, nodename.getNamespaceURI(), nodename.getLocalPart(), config.getNamePool());
- CombinedNodeTest combined = new CombinedNodeTest(nameTest, Token.INTERSECT, contentTest);
- return new SaxonXQItemType(combined, config);
- }
- }
-
- /*@NotNull*/ public XQItem createItem(XQItem item) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(item, "item");
- ((SaxonXQItem)item).checkNotClosed();
- return new SaxonXQItem(((SaxonXQItem)item).getSaxonItem(), this);
- }
-
- /*@NotNull*/ public XQItem createItemFromAtomicValue(String value, XQItemType type) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(value, "value");
- SaxonXQDataSource.checkNotNull(type, "type");
- AtomicType at = testAtomic(type);
- StringValue sv = new StringValue(value);
- Converter converter = getConfiguration().getConversionRules().getConverter(BuiltInAtomicType.STRING, at);
- ConversionResult result = converter.convert(sv);
- if (result instanceof ValidationFailure) {
- throw new XQException(((ValidationFailure)result).getMessage());
- }
- return new SaxonXQItem((AtomicValue)result, this);
- }
-
- /*@NotNull*/ public XQItem createItemFromBoolean(boolean value, /*@Nullable*/ XQItemType type) throws XQException {
- checkNotClosed();
- if (type == null) {
- return new SaxonXQItem(BooleanValue.get(value), this);
- } else {
- AtomicType at = testAtomic(type);
- if (at.getPrimitiveType() == StandardNames.XS_BOOLEAN) {
- try {
- ConversionResult result =
- Converter.convert(BooleanValue.get(value), at, getConfiguration().getConversionRules());
- if (result instanceof ValidationFailure) {
- throw new XQException(((ValidationFailure)result).getMessage());
- }
- return new SaxonXQItem((AtomicValue)result, this);
- } catch (Exception e) {
- throw new XQException("Failed to convert boolean value to required type: " + e.getMessage());
- }
- } else {
- throw new XQException("Target type for a boolean must be xs:boolean or a subtype");
- }
- }
- }
-
- /*@NotNull*/ public XQItem createItemFromByte(byte value, /*@Nullable*/ XQItemType type) throws XQException {
- checkNotClosed();
- if (type == null) {
- try {
- return new SaxonXQItem(new Int64Value(value, BuiltInAtomicType.BYTE, false), this);
- } catch (XPathException de) {
- throw newXQException(de);
- }
- } else {
- return createItemFromLong(value, type);
- }
- }
-
- /*@NotNull*/ public XQItem createItemFromDocument(InputStream value, String baseURI, XQItemType type) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(value, "value");
- try {
- Source ss = new SAXSource(new InputSource(value));
- ss.setSystemId(baseURI);
- ss = augmentSource(ss, type);
- DocumentInfo doc = getConfiguration().buildDocument(ss);
- checkDocumentType(doc, (SaxonXQItemType)type);
- return new SaxonXQItem(doc, this);
- } catch (XPathException de) {
- throw newXQException(de);
- }
- }
-
- /*@NotNull*/ public XQItem createItemFromDocument(Reader value, String baseURI, XQItemType type) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(value, "value");
- try {
- Source ss = new SAXSource(new InputSource(value));
- ss.setSystemId(baseURI);
- ss = augmentSource(ss, type);
- DocumentInfo doc = getConfiguration().buildDocument(ss);
- checkDocumentType(doc, (SaxonXQItemType)type);
- return new SaxonXQItem(doc, this);
- } catch (XPathException de) {
- throw newXQException(de);
- }
- }
-
- /*@NotNull*/ public XQItem createItemFromDocument(Source value, XQItemType type) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(value, "value");
- try {
- Source ss = augmentSource(value, type);
- DocumentInfo doc = getConfiguration().buildDocument(ss);
- checkDocumentType(doc, (SaxonXQItemType)type);
- return new SaxonXQItem(doc, this);
- } catch (XPathException de) {
- throw newXQException(de);
- }
- }
-
- /*@NotNull*/ public XQItem createItemFromDocument(String value, String baseURI, XQItemType type) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(value, "value");
- try {
- Source ss = new SAXSource(new InputSource(new StringReader(value)));
- ss.setSystemId(baseURI);
- ss = augmentSource(ss, type);
- DocumentInfo doc = getConfiguration().buildDocument(ss);
- checkDocumentType(doc, (SaxonXQItemType)type);
- return new SaxonXQItem(doc, this);
- } catch (XPathException de) {
- throw newXQException(de);
- }
- }
-
- /*@NotNull*/ public XQItem createItemFromDocument(XMLStreamReader value, XQItemType type) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(value, "value");
- try {
- EventIterator provider;
- if (value instanceof EventToStaxBridge) {
- // Rather than converting Saxon events to StAX events and back again, use the original
- // event stream directly
- provider = ((EventToStaxBridge)value).getProvider();
- } else {
- StaxToEventBridge bridge = new StaxToEventBridge();
- bridge.setXMLStreamReader(value);
- bridge.setPipelineConfiguration(getConfiguration().makePipelineConfiguration());
- provider = bridge;
- }
- Source ss = new PullEventSource(provider);
- ss = augmentSource(ss, type);
- DocumentInfo doc = getConfiguration().buildDocument(ss);
- checkDocumentType(doc, (SaxonXQItemType)type);
- return new SaxonXQItem(doc, this);
- } catch (XPathException de) {
- throw newXQException(de);
- }
- }
-
- private Source augmentSource(Source in, /*@Nullable*/ XQItemType required) throws XQException {
- if (required == null) {
- return in;
- } else {
- int kind = required.getItemKind();
- switch (kind) {
- case XQItemType.XQITEMKIND_DOCUMENT:
- case XQItemType.XQITEMKIND_NODE:
- case XQItemType.XQITEMKIND_ITEM:
- // no validation required
- return in;
- case XQItemType.XQITEMKIND_DOCUMENT_ELEMENT:
- // no validation required unless a type is specified
- ItemType it = ((SaxonXQItemType)required).getSaxonItemType();
- it = ((DocumentNodeTest)it).getElementTest();
- SchemaType contentType = ((NodeTest)it).getContentType();
- int fp = contentType.getFingerprint();
- if (fp == StandardNames.XS_ANY_TYPE || fp == StandardNames.XS_UNTYPED) {
- return in;
- }
- break;
- case XQItemType.XQITEMKIND_DOCUMENT_SCHEMA_ELEMENT:
- break;
- default:
- throw new XQException("Required item type for document node is incorrect");
- }
- }
- AugmentedSource out = AugmentedSource.makeAugmentedSource(in);
- out.setSchemaValidationMode(Validation.STRICT);
- return out;
- }
-
- private void checkDocumentType(DocumentInfo doc, /*@Nullable*/ SaxonXQItemType required) throws XQException {
- checkNotClosed();
- if (required != null &&
- !required.getSaxonItemType().matchesItem(doc, false, getConfiguration())) {
- throw new XQException("Document was successfully built but has the wrong type");
- }
- }
-
- /*@NotNull*/ public XQItem createItemFromDouble(double value, /*@Nullable*/ XQItemType type) throws XQException {
- checkNotClosed();
- if (type == null) {
- return new SaxonXQItem(new DoubleValue(value), this);
- } else {
- AtomicType at = testAtomic(type);
- if (at.getPrimitiveType() == StandardNames.XS_DOUBLE) {
- try {
- ConversionResult result = Converter.convert(new DoubleValue(value), at, getConfiguration().getConversionRules());
- if (result instanceof ValidationFailure) {
- throw new XQException(((ValidationFailure)result).getMessage());
- }
- return new SaxonXQItem((AtomicValue)result, this);
- } catch (Exception e) {
- throw new XQException("Failed to convert double value to required type: " + e.getMessage());
- }
- } else {
- throw new XQException("Target type for a double must be xs:double or a subtype");
- }
- }
- }
-
- /*@NotNull*/ public XQItem createItemFromFloat(float value, /*@Nullable*/ XQItemType type) throws XQException {
- checkNotClosed();
- if (type == null) {
- return new SaxonXQItem(new FloatValue(value), this);
- } else {
- AtomicType at = testAtomic(type);
- if (at.getPrimitiveType() == StandardNames.XS_FLOAT) {
- try {
- ConversionResult result = Converter.convert(new FloatValue(value), at, getConfiguration().getConversionRules());
- if (result instanceof ValidationFailure) {
- throw new XQException(((ValidationFailure)result).getMessage());
- }
- return new SaxonXQItem((AtomicValue)result, this);
- } catch (Exception e) {
- throw new XQException("Failed to convert float value to required type: " + e.getMessage());
- }
- } else {
- throw new XQException("Target type for a float must be xs:float or a subtype");
- }
- }
- }
-
- /*@NotNull*/ public XQItem createItemFromInt(int value, /*@Nullable*/ XQItemType type) throws XQException {
- checkNotClosed();
- if (type == null) {
- try {
- return new SaxonXQItem(new Int64Value(value, BuiltInAtomicType.INT, false), this);
- } catch (XPathException de) {
- throw newXQException(de);
- }
- } else {
- return createItemFromLong(value, type);
- }
- }
-
- /*@NotNull*/ public XQItem createItemFromLong(long value, /*@Nullable*/ XQItemType type) throws XQException {
- checkNotClosed();
- if (type == null) {
- try {
- return new SaxonXQItem(new Int64Value(value, BuiltInAtomicType.LONG, false), this);
- } catch (XPathException de) {
- throw newXQException(de);
- }
- } else {
- AtomicType at = testAtomic(type);
- int prim = at.getPrimitiveType();
- if (prim == StandardNames.XS_INTEGER || prim == StandardNames.XS_DECIMAL) {
- try {
- ConversionResult result = Converter.convert(Int64Value.makeIntegerValue(value), at, getConfiguration().getConversionRules());
- if (result instanceof ValidationFailure) {
- throw new XQException(((ValidationFailure)result).getMessage());
- }
- return new SaxonXQItem((AtomicValue)result, this);
- } catch (Exception e) {
- throw new XQException("Failed to convert long|int|short|byte value to required type: " + e.getMessage());
- }
- } else {
- throw new XQException("Target type for a long|int|short|byte must be xs:decimal or a subtype");
- }
- }
- }
-
- /*@NotNull*/ public XQItem createItemFromNode(Node value, /*@Nullable*/ XQItemType type) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(value, "value");
- try {
- JPConverter jp = DOMObjectModel.getInstance().getJPConverter(Node.class, getConfiguration());
- NodeInfo n = (NodeInfo)jp.convert(value, new EarlyEvaluationContext(getConfiguration(), null));
- XQItem result = new SaxonXQItem(n, this);
- if (type != null && !result.instanceOf(type)) {
- throw new XQException("The node is not a valid instance of the required type");
- }
- return result;
- } catch (XPathException de) {
- throw newXQException(de);
- }
- }
-
- /*@NotNull*/ public XQItem createItemFromObject(Object value, /*@Nullable*/ XQItemType type) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(value, "value");
- if (type == null) {
- return new SaxonXQItem(getObjectConverter().convertToItem(value), this);
- } else {
- return convertToXQItem(value, type);
- }
- }
-
-
- /*@NotNull*/ public XQItem createItemFromString(String value, /*@Nullable*/ XQItemType type) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(value, "value");
- if (type == null) {
- return new SaxonXQItem(new StringValue(value), this);
- } else {
- AtomicType at = testAtomic(type);
- int prim = at.getPrimitiveType();
- if (prim == StandardNames.XS_STRING) {
- try {
- ConversionResult result = Converter.convert(new net.sf.saxon.value.StringValue(value), at, getConfiguration().getConversionRules());
- if (result instanceof ValidationFailure) {
- throw new XQException(((ValidationFailure)result).getMessage());
- }
- return new SaxonXQItem((AtomicValue)result, this);
- } catch (Exception e) {
- throw new XQException("Failed to convert string value to required type: " + e.getMessage());
- }
- } else {
- throw new XQException("Target type for a string must be xs:string or a subtype");
- }
- }
- }
-
- /*@NotNull*/ public XQItemType createItemType() throws XQException {
- checkNotClosed();
- return new SaxonXQItemType(AnyItemType.getInstance(), getConfiguration());
- }
-
- /**
- * Convert a Java object to an XQItem of a given type
- * @param value the supplied Java object
- * @param type the required type
- * @return an XQItem of the required type
- * @throws XQException if the value cannot be converted
- */
-
- /*@NotNull*/ private XQItem convertToXQItem(Object value, /*@NotNull*/ XQItemType type) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(value, "value");
- if (value instanceof Boolean) {
- return createItemFromBoolean(((Boolean) value).booleanValue(), type);
- } else if (value instanceof byte[]) {
- AtomicType at = testAtomic(type);
- int prim = at.getPrimitiveType();
- ConversionResult result;
- if (prim == StandardNames.XS_HEX_BINARY) {
- Converter converter = getConfiguration().getConversionRules().getConverter(BuiltInAtomicType.HEX_BINARY, at);
- result = converter.convert(new HexBinaryValue((byte[]) value));
- } else if (prim == StandardNames.XS_BASE64_BINARY) {
- Converter converter = getConfiguration().getConversionRules().getConverter(BuiltInAtomicType.BASE64_BINARY, at);
- result = converter.convert(new Base64BinaryValue((byte[]) value));
- } else {
- throw new XQException("Target type must be xs:hexBinary, xs:base64Binary, or a subtype");
- }
- if (result instanceof ValidationFailure) {
- throw new XQException(((ValidationFailure)result).getMessage());
- }
- return new SaxonXQItem((AtomicValue)result, this);
- } else if (value instanceof Byte) {
- return createItemFromByte(((Byte) value).byteValue(), type);
- } else if (value instanceof Float) {
- return createItemFromFloat(((Float) value).floatValue(), type);
- } else if (value instanceof Double) {
- return createItemFromDouble(((Double) value).doubleValue(), type);
- } else if (value instanceof Integer) {
- return createItemFromInt(((Integer) value).intValue(), type);
- } else if (value instanceof Long) {
- return createItemFromLong(((Long) value).longValue(), type);
- } else if (value instanceof Short) {
- return createItemFromShort(((Short) value).shortValue(), type);
- } else if (value instanceof String) {
- AtomicType at = testAtomic(type);
- int prim = at.getPrimitiveType();
- ConversionResult result;
- if (prim == StandardNames.XS_UNTYPED_ATOMIC) {
- result = new UntypedAtomicValue((String) value);
- } else if (prim == StandardNames.XS_STRING) {
- Converter converter = getConfiguration().getConversionRules().getConverter(BuiltInAtomicType.STRING, at);
- result = converter.convert(new StringValue((String)value));
- } else if (prim == StandardNames.XS_ANY_URI) {
- Converter converter = getConfiguration().getConversionRules().getConverter(BuiltInAtomicType.ANY_URI, at);
- result = converter.convert(new StringValue((String)value));
- } else {
- // Note: the spec also allow NOTATION, but string->notation conversion doesn't work
- throw new XQException("Target type must be string, untypedAtomic, or anyURI");
- }
- if (result instanceof ValidationFailure) {
- throw new XQException(((ValidationFailure)result).getMessage());
- }
- return new SaxonXQItem((AtomicValue)result, this);
- } else if (value instanceof BigDecimal) {
- AtomicType at = testAtomic(type);
- int prim = at.getPrimitiveType();
- if (prim == StandardNames.XS_DECIMAL || prim == StandardNames.XS_INTEGER) {
- Converter converter = getConfiguration().getConversionRules().getConverter(BuiltInAtomicType.DECIMAL, at);
- ConversionResult result = converter.convert(new DecimalValue((BigDecimal) value));
- if (result instanceof ValidationFailure) {
- throw new XQException(((ValidationFailure)result).getMessage());
- }
- return new SaxonXQItem((AtomicValue)result, this);
- } else {
- throw new XQException("Target type must be xs:decimal or a subtype");
- }
- } else if (value instanceof BigInteger) {
- AtomicType at = testAtomic(type);
- int prim = at.getPrimitiveType();
- if (prim == StandardNames.XS_DECIMAL || prim == StandardNames.XS_INTEGER) {
- Converter converter = getConfiguration().getConversionRules().getConverter(BuiltInAtomicType.DECIMAL, at);
- ConversionResult result = converter.convert(new DecimalValue(new BigDecimal((BigInteger) value)));
- if (result instanceof ValidationFailure) {
- throw new XQException(((ValidationFailure)result).getMessage());
- }
- return new SaxonXQItem((AtomicValue)result, this);
- } else {
- throw new XQException("Target type must be xs:decimal or a subtype");
- }
- } else if (value instanceof Duration) {
- AtomicType at = testAtomic(type);
- int prim = at.getPrimitiveType();
- if (prim == StandardNames.XS_DURATION || prim == StandardNames.XS_DAY_TIME_DURATION || prim == StandardNames.XS_YEAR_MONTH_DURATION) {
- DurationValue dv = (DurationValue) getObjectConverter().convertToItem(value);
- Converter converter = getConfiguration().getConversionRules().getConverter(dv.getPrimitiveType(), at);
- ConversionResult result = converter.convert(dv);
- if (result instanceof ValidationFailure) {
- throw new XQException(((ValidationFailure)result).getMessage());
- }
- return new SaxonXQItem((AtomicValue)result, this);
- } else {
- throw new XQException("Target type must be xs:duration or a subtype");
- }
-
- } else if (value instanceof XMLGregorianCalendar) {
- AtomicType at = testAtomic(type);
- int prim = at.getPrimitiveType();
- switch (prim) {
- case StandardNames.XS_DATE_TIME:
- case StandardNames.XS_DATE:
- case StandardNames.XS_TIME:
- case StandardNames.XS_G_YEAR:
- case StandardNames.XS_G_YEAR_MONTH:
- case StandardNames.XS_G_MONTH:
- case StandardNames.XS_G_MONTH_DAY:
- case StandardNames.XS_G_DAY:
- AtomicValue dv = (AtomicValue) getObjectConverter().convertToItem(value);
- Converter converter = getConfiguration().getConversionRules().getConverter(dv.getPrimitiveType(), at);
- ConversionResult result = converter.convert(dv);
- if (result instanceof ValidationFailure) {
- throw new XQException(((ValidationFailure)result).getMessage());
- }
- return new SaxonXQItem((AtomicValue)result, this);
- default:
- throw new XQException("Target type must be a date/time type");
- }
- } else if (value instanceof QName) {
- AtomicType at = testAtomic(type);
- int prim = at.getPrimitiveType();
- if (prim == StandardNames.XS_QNAME) {
- QualifiedNameValue dv = (QualifiedNameValue) getObjectConverter().convertToItem(value);
- Converter converter = getConfiguration().getConversionRules().getConverter(dv.getPrimitiveType(), at);
- ConversionResult result = converter.convert(dv);
- if (result instanceof ValidationFailure) {
- throw new XQException(((ValidationFailure)result).getMessage());
- }
- return new SaxonXQItem((AtomicValue)result, this);
- } else {
- throw new XQException("Target type must be xs:QName or a subtype");
- }
- } else if (value instanceof Node) {
- NodeInfo result = (NodeInfo) getObjectConverter().convertToItem(value);
- XQItem item = new SaxonXQItem(result, this);
- if (!item.instanceOf(type)) {
- throw new XQException("Supplied node does not match the requested XQItemType");
- }
- return item;
- } else {
- return new SaxonXQItem(getObjectConverter().convertToItem(value, type), this);
- }
- }
-
-
- /*@NotNull*/ public XQItem createItemFromShort(short value, /*@Nullable*/ XQItemType type) throws XQException {
- checkNotClosed();
- if (type == null) {
- try {
- return new SaxonXQItem(new Int64Value(value, BuiltInAtomicType.SHORT, false), this);
- } catch (XPathException de) {
- throw newXQException(de);
- }
- } else {
- return createItemFromLong(value, type);
- }
- }
-
-
-
- /*@NotNull*/ public XQItemType createNodeType() throws XQException {
- checkNotClosed();
- return new SaxonXQItemType(AnyNodeTest.getInstance(), getConfiguration());
- }
-
- /*@NotNull*/ public XQItemType createProcessingInstructionType(/*@Nullable*/ String piTarget) throws XQException {
- checkNotClosed();
- if (piTarget == null) {
- return new SaxonXQItemType(NodeKindTest.PROCESSING_INSTRUCTION, getConfiguration());
- } else {
- return new SaxonXQItemType(
- new NameTest(Type.PROCESSING_INSTRUCTION, "", piTarget, getConfiguration().getNamePool()),
- getConfiguration());
- }
- }
-
- /*@NotNull*/ public XQItemType createSchemaAttributeType(/*@NotNull*/ QName nodename, int basetype, /*@Nullable*/ URI schemaURI) throws XQException {
- checkNotClosed();
- Configuration config = getConfiguration();
- int fp = getFingerprint(nodename);
- SchemaDeclaration attributeDecl = config.getAttributeDeclaration(fp);
- if (attributeDecl == null && schemaURI != null) {
- loadSchema(schemaURI);
- attributeDecl = config.getAttributeDeclaration(fp);
- }
- if (attributeDecl == null) {
- throw new XQException("Attribute declaration " + nodename + " not found in schema");
- }
- NodeTest nameTest = attributeDecl.makeSchemaNodeTest();
- return new SaxonXQItemType(nameTest, config);
- }
-
- /*@NotNull*/ public XQItemType createSchemaElementType(/*@NotNull*/ QName nodename, int basetype, /*@Nullable*/ URI schemaURI) throws XQException {
- checkNotClosed();
- Configuration config = getConfiguration();
- int fp = getFingerprint(nodename);
- SchemaDeclaration elementDecl = config.getElementDeclaration(fp);
- if (elementDecl == null && schemaURI != null) {
- loadSchema(schemaURI);
- elementDecl = config.getElementDeclaration(fp);
- }
- if (elementDecl == null) {
- throw new XQException("Element declaration " + nodename + " not found in schema");
- }
- NodeTest nameTest = elementDecl.makeSchemaNodeTest();
- return new SaxonXQItemType(nameTest, config);
-
- }
-
- /*@NotNull*/ public XQSequence createSequence(/*@Nullable*/ Iterator i) throws XQException {
- checkNotClosed();
- if (i == null) {
- throw new XQException("createSequence(): argument is null");
- }
- List list = new ArrayList(50);
- while (i.hasNext()) {
- Object object = i.next();
- XQItem item;
- if (object instanceof XQItem) {
- item = (XQItem)object;
- } else {
- item = createItemFromObject(object, null);
- }
- list.add(((SaxonXQItem)item).getSaxonItem());
- }
- SequenceExtent extent = new SequenceExtent(list);
- return new SaxonXQSequence(extent, this);
- }
-
- /*@NotNull*/ public XQSequence createSequence(/*@Nullable*/ XQSequence s) throws XQException {
- checkNotClosed();
- if (s == null) {
- throw new XQException("createSequence(): argument is null");
- }
- ((Closable)s).checkNotClosed();
- if (s instanceof SaxonXQSequence) {
- return new SaxonXQSequence(((SaxonXQSequence) s).getValue(), this);
- } else if (s instanceof SaxonXQForwardSequence) {
- try {
- SequenceExtent extent = new SequenceExtent(((SaxonXQForwardSequence) s).getCleanIterator());
- return new SaxonXQSequence(extent, this);
- } catch (XPathException de) {
- throw newXQException(de);
- }
- } else {
- throw new XQException("Supplied sequence is not a Saxon implementation");
- }
- }
-
- /*@NotNull*/ public XQSequenceType createSequenceType(XQItemType item, int occurrence) throws XQException {
- checkNotClosed();
- if (item instanceof SaxonXQItemType) {
- ItemType itemType = ((SaxonXQItemType) item).getSaxonItemType();
- int cardinality;
- switch (occurrence) {
- case XQSequenceType.OCC_EXACTLY_ONE:
- cardinality = StaticProperty.EXACTLY_ONE;
- break;
- case XQSequenceType.OCC_ONE_OR_MORE:
- cardinality = StaticProperty.ALLOWS_ONE_OR_MORE;
- break;
- case XQSequenceType.OCC_ZERO_OR_ONE:
- cardinality = StaticProperty.ALLOWS_ZERO_OR_ONE;
- break;
- case XQSequenceType.OCC_ZERO_OR_MORE:
- cardinality = StaticProperty.ALLOWS_ZERO_OR_MORE;
- break;
- default:
- throw new XQException("Invalid occurrence value");
- }
- SequenceType st = SequenceType.makeSequenceType(itemType, cardinality);
- return new SaxonXQSequenceType(st, getConfiguration());
- } else {
- throw new XQException("Supplied XQItemType is not a Saxon-created object");
- }
- }
-
- /*@NotNull*/ public XQItemType createTextType() throws XQException {
- checkNotClosed();
- return new SaxonXQItemType(NodeKindTest.TEXT, getConfiguration());
- }
-
- private AtomicType testAtomic(/*@NotNull*/ XQItemType type) throws XQException {
- if (type instanceof SaxonXQItemType) {
- AtomicType at = ((SaxonXQItemType) type).getAtomicType();
- if (at == null) {
- throw new XQException("Requested type is not atomic");
- }
- return at;
- } else {
- throw new XQException("Supplied XQItemType is not a Saxon-created object");
- }
- }
-
- /*@NotNull*/ private static XQException newXQException(/*@NotNull*/ Exception err) {
- XQException e = new XQException(err.getMessage());
- e.initCause(err);
- return e;
- }
-
- private int getFingerprint(/*@NotNull*/ QName name) {
- return getConfiguration().getNamePool().allocate(
- name.getPrefix(), name.getNamespaceURI(), name.getLocalPart());
- }
-
- /**
- * Attempt to load the schema document at a given location into the Configuration
- * @param schemaURI the absolute URI of the location of the schema document. If null is supplied,
- * the method is a no-op.
- * @throws XQException if the URI is not absolute, or if no schema is found at the location,
- * or if the schema is invalid, or if it is inconsistent with existing schema components present
- * in the Configuration.
- */
-
- private void loadSchema(/*@Nullable*/ URI schemaURI) throws XQException {
- if (schemaURI == null) {
- return;
- }
- if (!schemaURI.isAbsolute()) {
- throw new XQException("Schema URI must be an absolute URI");
- }
- try {
- getConfiguration().loadSchema(schemaURI.toString());
- } catch (SchemaException err) {
- throw newXQException(err);
- }
- }
-
-}
-
diff --git a/sf/saxon/xqj/SaxonXQDataSource.java b/sf/saxon/xqj/SaxonXQDataSource.java
deleted file mode 100644
index 5b6786a..0000000
--- a/sf/saxon/xqj/SaxonXQDataSource.java
+++ /dev/null
@@ -1,539 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.Configuration;
-import net.sf.saxon.lib.ExtensionFunctionDefinition;
-import net.sf.saxon.lib.FeatureKeys;
-import net.sf.saxon.lib.Validation;
-import net.sf.saxon.value.BooleanValue;
-import net.sf.saxon.value.Whitespace;
-
-import javax.xml.xquery.XQConnection;
-import javax.xml.xquery.XQDataSource;
-import javax.xml.xquery.XQException;
-import java.io.PrintWriter;
-import java.sql.Connection;
-import java.util.Enumeration;
-import java.util.Properties;
-
-/**
- * Saxon implementation of the XQJ XQDataSource interface. The first action of a client application
- * is to instantiate a SaxonXQDataSource. This is done directly: there is no factory class as with JAXP.
- * An application that does not want compile-time references to the Saxon XQJ implementation can instantiate
- * this class dynamically using the reflection API (class.newInstance()).
- * <p>
- * For full Javadoc descriptions of the public methods, see the XQJ specification.
- */
-public class SaxonXQDataSource implements XQDataSource {
-
- private Configuration config;
- private PrintWriter logger;
-
- /**
- * Create a SaxonXQDataSource using a default configuration.
- * The Configuration will be an EE, PE, or HE configuration depending on the
- * what is found on the classpath
- */
-
- public SaxonXQDataSource() {
- config = Configuration.newConfiguration();
- config.setProcessor(this);
- }
-
- /**
- * Create a Saxon XQDataSource with a specific configuration
- * @param config The Saxon configuration to be used
- */
-
- public SaxonXQDataSource(Configuration config) {
- this.config = config;
- }
-
- /**
- * Get the Saxon Configuration in use. Changes made to this Configuration will affect this
- * data source and XQJ connections created from it (either before or afterwards). Equally,
- * changes made to this SaxonXQDataSource are reflected in the Configuration object (which means
- * they also impact any other SaxonXQDataSource objects that share the same Configuration).
- * @return the configuration in use.
- */
-
- public Configuration getConfiguration() {
- return config;
- }
-
- /*@NotNull*/ public XQConnection getConnection() throws XQException {
- return new SaxonXQConnection(this);
- }
-
- /**
- * Get a connection based on an underlying JDBC connection
- * @param con the JDBC connection
- * @return a connection based on an underlying JDBC connection
- * @throws XQException The Saxon implementation of this method always throws
- * an XQException, indicating that Saxon does not support connection to a JDBC data source.
- */
-
- /*@NotNull*/ public XQConnection getConnection(Connection con) throws XQException {
- throw new XQException("Saxon cannot connect to a SQL data source");
- }
-
- /**
- * Get a connection, by supplying a username and password. The Saxon implementation of this is equivalent
- * to the default constructor: the username and password are ignored.
- * @param username the user name
- * @param password the password
- * @return a connection
- * @throws XQException
- */
-
- /*@NotNull*/ public XQConnection getConnection(String username, String password) throws XQException {
- return getConnection();
- }
-
- public int getLoginTimeout() {
- return 0;
- }
-
- public PrintWriter getLogWriter() {
- return logger;
- }
-
- /**
- * Get a configuration property setting. The properties that are supported, and their meanings, are the
- * same as the properties that can be obtained using "get" methods; for example
- * <code>getProperty("dtdValidation")</code> returns the same result as <code>getDtdValidation()</code>.
- *
- * <p>Further Saxon configuration properties are available using the URIs defined as constants in
- * {@link net.sf.saxon.lib.FeatureKeys}</p>
- *
- * @param name the name of the configuration property
- * @return the value of the configuration property. Note that in the case of on/off properties this
- * will be returned as the string true/false
- * @throws XQException
- */
-
- /*@Nullable*/ public String getProperty(String name) throws XQException {
- checkNotNull(name, "name");
- if ("allowExternalFunctions".equals(name)) {
- return getAllowExternalFunctions();
- } else if ("dtdValidation".equals(name)) {
- return getDtdValidation();
- } else if ("expandAttributeDefaults".equals(name)) {
- return getExpandAttributeDefaults();
- } else if ("expandXInclude".equals(name)) {
- return getExpandXInclude();
- } else if ("retainLineNumbers".equals(name)) {
- return getRetainLineNumbers();
- } else if ("schemaValidationMode".equals(name)) {
- return getSchemaValidationMode();
- } else if ("stripWhitespace".equals(name)) {
- return getStripWhitespace();
- } else if ("useXsiSchemaLocation".equals(name)) {
- return getUseXsiSchemaLocation();
- } else if ("xmlVersion".equals(name)) {
- return getXmlVersion();
- } else if ("xsdVersion".equals(name)) {
- return getXsdVersion();
- } else {
- try {
- return config.getConfigurationProperty(name).toString();
- } catch (IllegalArgumentException e) {
- throw new XQException("Property " + name + " is not recognized");
- } catch (NullPointerException err) {
- throw new XQException("Null property name or value");
- }
- }
-
- }
-
- /*@NotNull*/ private static String[] supportedPropertyNames = {
- "allowExternalFunctions",
- "dtdValidation",
- "expandAttributeDefaults",
- "expandXInclude",
- "retainLineNumbers",
- "schemaValidationMode",
- "stripWhitespace",
- "useXsiSchemaLocation",
- "xmlVersion",
- "xsdVersion"
- };
-
- /*@NotNull*/ public String[] getSupportedPropertyNames() {
- return supportedPropertyNames;
- }
-
- public void setLoginTimeout(int seconds) throws XQException {
- // no-op
- }
-
- public void setLogWriter(PrintWriter out) throws XQException {
- logger = out;
- }
-
- public void setProperties(Properties props) throws XQException {
- checkNotNull(props, "props");
- Enumeration iter = props.keys();
- while (iter.hasMoreElements()) {
- String name = (String)iter.nextElement();
- String value = props.getProperty(name);
- setProperty(name, value);
- }
- }
-
- /**
- * Set a configuration property. The properties that are supported, and their meanings, are the
- * same as the properties that can be obtained using "set" methods; for example
- * <code>setProperty("dtdValidation", "true")</code> has the same effect as
- * <code>setDtdValidation("true")</code>.
- *
- * <p>Further Saxon configuration properties are available using the URIs defined as constants in
- * {@link net.sf.saxon.lib.FeatureKeys}</p>
- *
- * @param name the name of the configuration property
- * @param value the value of the configuration property
- * @throws XQException
- */
-
- public void setProperty(String name, String value) throws XQException {
- SaxonXQDataSource.checkNotNull(name, "name");
- SaxonXQDataSource.checkNotNull(value, "value");
- if ("allowExternalFunctions".equals(name)) {
- setAllowExternalFunctions(value);
- } else if ("dtdValidation".equals(name)) {
- setDtdValidation(value);
- } else if ("expandAttributeDefaults".equals(name)) {
- setExpandAttributeDefaults(value);
- } else if ("expandXInclude".equals(name)) {
- setExpandXInclude(value);
- } else if ("retainLineNumbers".equals(name)) {
- setRetainLineNumbers(value);
- } else if ("schemaValidationMode".equals(name)) {
- setSchemaValidationMode(value);
- } else if ("stripWhitespace".equals(name)) {
- setStripWhitespace(value);
- } else if ("useXsiSchemaLocation".equals(name)) {
- setUseXsiSchemaLocation(value);
- } else if ("xmlVersion".equals(name)) {
- setXmlVersion(value);
- } else if ("xsdVersion".equals(name)) {
- setXsdVersion(value);
- } else {
- try {
- config.setConfigurationProperty(name, value);
- } catch (IllegalArgumentException err) {
- throw new XQException("Unrecognized property or invalid value for " + name + ": " + err.getMessage());
- } catch (NullPointerException err) {
- throw new XQException("Null property name or value");
- }
- }
- }
-
- static void checkNotNull(/*@Nullable*/ Object arg, String name) throws XQException {
- if (arg == null) {
- throw new XQException("Argument " + name + " is null");
- }
- }
-
- /**
- * Say whether queries are allowed to call external functions.
- * @param value set to "true" if external function calls are allowed (default) or "false" otherwise
- */
-
- public void setAllowExternalFunctions(String value) {
- if ("true".equals(value)) {
- config.setBooleanProperty(FeatureKeys.ALLOW_EXTERNAL_FUNCTIONS, true);
- } else if ("false".equals(value)) {
- config.setBooleanProperty(FeatureKeys.ALLOW_EXTERNAL_FUNCTIONS, false);
- } else {
- throw new IllegalArgumentException("allowExternalFunctions");
- }
- }
-
- /**
- * Ask whether queries are allowed to call external functions.
- * @return "true" if external function calls are allowed, "false" otherwise
- */
-
- /*@NotNull*/ public String getAllowExternalFunctions() {
- return (config.getBooleanProperty(FeatureKeys.ALLOW_EXTERNAL_FUNCTIONS) ? "true" : "false");
- }
-
- /**
- * Say whether source documents are to be parsed with DTD validation enabled
- * @param value "true" if DTD validation is to be enabled, otherwise "false". Default is "false".
- */
-
- public void setDtdValidation(String value) {
- if ("true".equals(value)) {
- config.setValidation(true);
- } else if ("false".equals(value)) {
- config.setValidation(false);
- } else {
- throw new IllegalArgumentException("dtdValidation");
- }
- }
-
- /**
- * Ask whether source documents are to be parsed with DTD validation enabled
- * @return "true" if DTD validation is to be enabled, otherwise "false". Default is "false".
- */
-
- /*@NotNull*/ public String getDtdValidation() {
- return (config.isValidation() ? "true" : "false");
- }
-
- /**
- * Say whether whether fixed and default values defined
- * in a schema or DTD will be expanded. By default, or if the value is "true" (and for conformance with the
- * specification) validation against a DTD or schema will cause default values defined in the schema
- * or DTD to be inserted into the document. Setting this feature to "false" suppresses this behaviour. In
- * the case of DTD-defined defaults this only works if the XML parser reports whether each attribute was
- * specified in the source or generated by expanding a default value. Not all XML parsers report this
- * information.
- * @param value "true" if default values are to be expanded, otherwise "false". Default is "true".
- */
-
- public void setExpandAttributeDefaults(String value) {
- if ("true".equals(value)) {
- config.setExpandAttributeDefaults(true);
- } else if ("false".equals(value)) {
- config.setExpandAttributeDefaults(false);
- } else {
- throw new IllegalArgumentException("expandAttributeDefaults");
- }
- }
-
- /**
- * Ask whether fixed or default values defined in a schema or DTD will be expanded
- * @return "true" if such values will be expanded, otherwise "false"
- */
-
- /*@NotNull*/ public String getExpandAttributeDefaults() {
- return (config.isExpandAttributeDefaults() ? "true" : "false");
- }
-
- /**
- * Say whether XInclude processing is to be applied to source documents
- * @param value "true" if XInclude directives are to expanded, otherwise "false". Default is "false".
- */
-
- public void setExpandXInclude(String value) {
- if ("true".equals(value)) {
- config.setXIncludeAware(true);
- } else if ("false".equals(value)) {
- config.setXIncludeAware(false);
- } else {
- throw new IllegalArgumentException("expandXInclude");
- }
- }
-
- /**
- * Ask whether XInclude processing is to be applied to source documents
- * @return "true" if XInclude directives are to expanded, otherwise "false". Default is "false".
- */
-
- /*@NotNull*/ public String getExpandXInclude() {
- return (config.isXIncludeAware() ? "true" : "false");
- }
-
-
- /**
- * Say whether source documents should have line and column information retained. This
- * information is available via extension functions <code>saxon:line-number()</code> and
- * <code>saxon:column-number()</code>
- * @param value "true" if line and column information is to be retained, otherwise "false". Default is "false".
- */
-
- public void setRetainLineNumbers(String value) {
- if ("true".equals(value)) {
- config.setLineNumbering(true);
- } else if ("false".equals(value)) {
- config.setLineNumbering(false);
- } else {
- throw new IllegalArgumentException("retainLineNumbers");
- }
- }
-
- /**
- * Ask whether line and column information will be retained for source documents
- * @return "true" if line and column information is retained, otherwise "false"
- */
-
- /*@NotNull*/ public String getRetainLineNumbers() {
- return (config.isLineNumbering() ? "true" : "false");
- }
-
- /**
- * Say whether source documents should be validated against a schema
- * @param value set to "strict" if source documents are to be subjected to strict validation,
- * "lax" if source documents are to be subjected to lax validation, "skip" if source documents
- * are not to be subjected to schema validation
- */
-
- public void setSchemaValidationMode(String value) {
- if ("strict".equals(value)) {
- config.setSchemaValidationMode(Validation.STRICT);
- } else if ("lax".equals(value)) {
- config.setSchemaValidationMode(Validation.LAX);
- } else if ("skip".equals(value)) {
- config.setSchemaValidationMode(Validation.SKIP);
- } else {
- throw new IllegalArgumentException("schemaValidationMode");
- }
- }
-
- /**
- * Ask whether source documents will be validated against a schema
- * @return "strict" if source documents are to be subjected to strict validation,
- * "lax" if source documents are to be subjected to lax validation, "skip" if source documents
- * are not to be subjected to schema validation
- */
-
- public String getSchemaValidationMode() {
- return Validation.toString(config.getSchemaValidationMode());
- }
-
- /**
- * Say whether whitespace should be stripped when loading source documents
- * @param value "all" if all whitespace text nodes are to be stripped, "ignorable" if
- * only whitespace text nodes in elements defined in a schema or DTD as having element-only
- * content are to be stripped, "none" if no whitespace text nodes are to be stripped
- */
-
- public void setStripWhitespace(String value) {
- if ("all".equals(value)) {
- config.setStripsWhiteSpace(Whitespace.ALL);
- } else if ("ignorable".equals(value)) {
- config.setStripsWhiteSpace(Whitespace.IGNORABLE);
- } else if ("none".equals(value)) {
- config.setStripsWhiteSpace(Whitespace.NONE);
- } else {
- throw new IllegalArgumentException("stripWhitespace");
- }
- }
-
- /**
- * Ask whether whitespace will be stripped when loading source documents
- * @return "all" if all whitespace text nodes are to be stripped, "ignorable" if
- * only whitespace text nodes in elements defined in a schema or DTD as having element-only
- * content are to be stripped, "none" if no whitespace text nodes are to be stripped
- */
-
- /*@NotNull*/ public String getStripWhitespace() {
- switch (config.getStripsWhiteSpace()) {
- case Whitespace.ALL: return "all";
- case Whitespace.IGNORABLE: return "ignorable";
- default: return "none";
- }
- }
-
- /**
- * Say whether the schema processor is to take account of xsi:schemaLocation and
- * xsi:noNamespaceSchemaLocation attributes encountered in an instance document being validated
- * @param value set to "true" if these attributes are to be recognized (default) or "false" otherwise
- */
-
- public void setUseXsiSchemaLocation(String value) {
- if ("true".equals(value)) {
- config.setConfigurationProperty(FeatureKeys.USE_XSI_SCHEMA_LOCATION, BooleanValue.TRUE);
- } else if ("false".equals(value)) {
- config.setConfigurationProperty(FeatureKeys.USE_XSI_SCHEMA_LOCATION, BooleanValue.FALSE);
- } else {
- throw new IllegalArgumentException("useXsiSchemaLocation");
- }
- }
-
- /**
- * Ask whether the schema processor is to take account of xsi:schemaLocation and
- * xsi:noNamespaceSchemaLocation attributes encountered in an instance document being validated
- * @return "true" if these attributes are to be recognized (default) or "false" otherwise
- */
-
- /*@NotNull*/ public String getUseXsiSchemaLocation() {
- Boolean b = (Boolean)config.getConfigurationProperty(FeatureKeys.USE_XSI_SCHEMA_LOCATION);
- return (b.booleanValue() ? "true" : "false");
- }
-
- /**
- * Say whether XML 1.0 or XML 1.1 rules for XML names are to be followed
- * @param value "1.0" (default) if XML 1.0 rules are to be used, "1.1" if XML 1.1
- * rules apply
- */
-
- public void setXmlVersion(String value) {
- if ("1.0".equals(value)) {
- config.setXMLVersion(Configuration.XML10);
- } else if ("1.1".equals(value)) {
- config.setXMLVersion(Configuration.XML11);
- } else {
- throw new IllegalArgumentException("xmlVersion");
- }
- }
-
- /**
- * Ask whether XML 1.0 or XML 1.1 rules for XML names are to be followed
- * @return "1.0" if XML 1.0 rules are to be used, "1.1" if XML 1.1
- * rules apply
- */
-
- /*@NotNull*/ public String getXmlVersion() {
- return (config.getXMLVersion() == Configuration.XML10 ? "1.0" : "1.1");
- }
-
- /**
- * Say whether XML Schema 1.0 syntax must be used or whether XML Schema 1.1 features are allowed
- * @param value "1.0" (default) if XML Schema 1.0 rules are to be followed, "1.1" if XML Schema 1.1
- * features may be used
- */
-
- public void setXsdVersion(String value) {
- if ("1.0".equals(value)) {
- config.setConfigurationProperty(FeatureKeys.XSD_VERSION, "1.0");
- } else if ("1.1".equals(value)) {
- config.setConfigurationProperty(FeatureKeys.XSD_VERSION, "1.1");
- } else {
- throw new IllegalArgumentException("xsdVersion");
- }
- }
-
- /**
- * Ask whether XML Schema 1.0 syntax must be used or whether XML Schema 1.1 features are allowed
- * @return "1.0" (default) if XML Schema 1.0 rules are to be followed, "1.1" if XML Schema 1.1
- * features may be used
- */
-
- /*@Nullable*/ public String getXsdVersion() {
- return (String)config.getConfigurationProperty(FeatureKeys.XSD_VERSION);
- }
-
- /**
- * Register an extension function that is to be made available within any query. This method
- * allows deep integration of an extension function implemented as an instance of
- * {@link net.sf.saxon.lib.ExtensionFunctionDefinition}, using an arbitrary name and namespace.
- * This supplements the ability to call arbitrary Java methods using a namespace and local name
- * that are related to the Java class and method name.
- * <p><i>This method is a Saxon extension to the XQJ interface</i></p>
- * @param function the class that implements the extension function. This must be a class that extends
- * {@link net.sf.saxon.lib.ExtensionFunctionCall}, and it must have a public zero-argument
- * constructor
- * @throws IllegalArgumentException if the class cannot be instantiated or does not extend
- * {@link net.sf.saxon.lib.ExtensionFunctionCall}
- * @since 9.2
- */
-
- public void registerExtensionFunction(ExtensionFunctionDefinition function) {
- try {
- config.registerExtensionFunction(function);
- } catch (Exception err) {
- throw new IllegalArgumentException(err);
- }
- }
-}
-
diff --git a/sf/saxon/xqj/SaxonXQDynamicContext.java b/sf/saxon/xqj/SaxonXQDynamicContext.java
deleted file mode 100644
index 9025df8..0000000
--- a/sf/saxon/xqj/SaxonXQDynamicContext.java
+++ /dev/null
@@ -1,270 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.Configuration;
-import net.sf.saxon.om.Sequence;
-import net.sf.saxon.om.SequenceTool;
-import net.sf.saxon.query.DynamicQueryContext;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.type.AtomicType;
-import net.sf.saxon.type.ItemType;
-import net.sf.saxon.value.*;
-import org.w3c.dom.Node;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.Source;
-import javax.xml.xquery.*;
-import java.io.InputStream;
-import java.io.Reader;
-import java.util.GregorianCalendar;
-import java.util.TimeZone;
-
-/**
- * Saxon implementation of the XQJ DynamicContext interface
- */
-
-public abstract class SaxonXQDynamicContext extends Closable implements XQDynamicContext {
-
- protected SaxonXQConnection connection;
-
- protected abstract DynamicQueryContext getDynamicContext();
-
- protected final Configuration getConfiguration() {
- return connection.getConfiguration();
- }
-
- protected abstract SaxonXQDataFactory getDataFactory() throws XQException;
-
- protected abstract boolean externalVariableExists(QName name);
-
- /*@Nullable*/ private TimeZone implicitTimeZone = null;
-
- public void bindAtomicValue(QName varname, String value, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- checkNotNull(value);
- checkNotNull(type);
- SaxonXQItem item = (SaxonXQItem) getDataFactory().createItemFromAtomicValue(value, type);
- bindExternalVariable(varname, item.getSaxonItem());
- }
-
- public void bindBoolean(QName varname, boolean value, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- BooleanValue target = BooleanValue.get(value);
- checkAtomic(type, target);
- bindExternalVariable(varname, target);
- }
-
- public void bindByte(QName varname, byte value, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- SaxonXQItem item = (SaxonXQItem) getDataFactory().createItemFromByte(value, type);
- AtomicValue target = (AtomicValue)item.getSaxonItem();
- checkAtomic(type, target);
- bindExternalVariable(varname, target);
- }
-
- public void bindDocument(QName varname, InputStream value, String baseURI, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- SaxonXQItem item = (SaxonXQItem)connection.createItemFromDocument(value, baseURI, type);
- bindExternalVariable(varname, item.getSaxonItem());
- }
-
- public void bindDocument(QName varname, Reader value, String baseURI, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- SaxonXQItem item = (SaxonXQItem)connection.createItemFromDocument(value, baseURI, type);
- bindExternalVariable(varname, item.getSaxonItem());
- }
-
- public void bindDocument(QName varname, Source value, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- SaxonXQItem item = (SaxonXQItem)connection.createItemFromDocument(value, type);
- bindExternalVariable(varname, item.getSaxonItem());
- }
-
- public void bindDocument(QName varname, String value, String baseURI, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- SaxonXQItem item = (SaxonXQItem)connection.createItemFromDocument(value, baseURI, type);
- bindExternalVariable(varname, item.getSaxonItem());
- }
-
- public void bindDocument(QName varname, /*@NotNull*/ XMLStreamReader value, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- SaxonXQItem item = (SaxonXQItem)connection.createItemFromDocument(value, type);
- bindExternalVariable(varname, item.getSaxonItem());
- }
-
- public void bindDouble(QName varname, double value, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- AtomicValue target = new DoubleValue(value);
- checkAtomic(type, target);
- bindExternalVariable(varname, target);
- }
-
- public void bindFloat(QName varname, float value, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- AtomicValue target = new FloatValue(value);
- checkAtomic(type, target);
- bindExternalVariable(varname, target);
- }
-
- public void bindInt(QName varname, int value, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- SaxonXQItem item = (SaxonXQItem) getDataFactory().createItemFromInt(value, type);
- AtomicValue target = (AtomicValue)item.getSaxonItem();
- checkAtomic(type, target);
- bindExternalVariable(varname, target);
- }
-
- public void bindItem(QName varname, /*@NotNull*/ XQItem value) throws XQException {
- checkNotClosed();
- ((SaxonXQItem) value).checkNotClosed();
- checkNotNull(varname);
- bindExternalVariable(varname, ((SaxonXQItem) value).getSaxonItem());
- }
-
- public void bindLong(QName varname, long value, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- SaxonXQItem item = (SaxonXQItem) getDataFactory().createItemFromLong(value, type);
- AtomicValue target = (AtomicValue)item.getSaxonItem();
- checkAtomic(type, target);
- bindExternalVariable(varname, target);
- }
-
- public void bindNode(QName varname, Node value, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- SaxonXQItem item = (SaxonXQItem) getDataFactory().createItemFromNode(value, type);
- bindExternalVariable(varname, item.getSaxonItem());
- }
-
- public void bindObject(QName varname, /*@NotNull*/ Object value, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- SaxonXQItem item = (SaxonXQItem) getDataFactory().createItemFromObject(value, type);
- bindExternalVariable(varname, item.getSaxonItem());
-
- }
-
- public void bindSequence(QName varname, /*@NotNull*/ XQSequence value) throws XQException {
- checkNotClosed();
- ((Closable)value).checkNotClosed();
- checkNotNull(varname);
- try {
- if (value instanceof SaxonXQForwardSequence) {
- getDynamicContext().setParameter(getClarkName(varname),
- ((SaxonXQForwardSequence) value).getCleanIterator());
- } else if (value instanceof SaxonXQSequence) {
- bindExternalVariable(varname, ((SaxonXQSequence) value).getValue());
- } else {
- throw new XQException("XQSequence value is not a Saxon sequence");
- }
- } catch (XPathException de) {
- XQException err = new XQException(de.getMessage());
- err.initCause(de);
- throw err;
- }
- }
-
- public void bindShort(QName varname, short value, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- SaxonXQItem item = (SaxonXQItem) getDataFactory().createItemFromShort(value, type);
- AtomicValue target = (AtomicValue)item.getSaxonItem();
- checkAtomic(type, target);
- bindExternalVariable(varname, target);
- }
-
- public void bindString(QName varname, String value, XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(varname);
- SaxonXQItem item = (SaxonXQItem) getDataFactory().createItemFromString(value, type);
- AtomicValue target = (AtomicValue)item.getSaxonItem();
- checkAtomic(type, target);
- bindExternalVariable(varname, target);
- }
-
- /*@Nullable*/ public TimeZone getImplicitTimeZone() throws XQException {
- checkNotClosed();
- if (implicitTimeZone != null) {
- return implicitTimeZone;
- } else {
- return new GregorianCalendar().getTimeZone();
- }
- }
-
- public void setImplicitTimeZone(TimeZone implicitTimeZone) throws XQException {
- checkNotClosed();
- GregorianCalendar now = new GregorianCalendar(implicitTimeZone);
- try {
- getDynamicContext().setCurrentDateTime(new DateTimeValue(now, true));
- } catch (XPathException e) {
- throw new XQException(e.getMessage());
- }
- this.implicitTimeZone = implicitTimeZone;
- }
-
-
- private void bindExternalVariable(QName varName, /*@NotNull*/ Sequence value) throws XQException {
- checkNotNull(varName);
- checkNotNull(value);
- try {
- if (varName.equals(XQConstants.CONTEXT_ITEM)) {
- getDynamicContext().setContextItem(SequenceTool.asItem(value));
- } else {
- if (!externalVariableExists(varName)) {
- throw new XQException("No external variable named " + varName + " exists in the query");
- }
- getDynamicContext().setParameterValue(getClarkName(varName), value);
- }
- } catch (XPathException e) {
- XQException err = new XQException(e.getMessage());
- err.initCause(e);
- throw err;
- }
- }
-
- private void checkAtomic(/*@Nullable*/ XQItemType type, AtomicValue value) throws XQException {
- if (type == null) {
- return;
- }
- ItemType itemType = ((SaxonXQItemType)type).getSaxonItemType();
- if (!itemType.isPlainType()) {
- throw new XQException("Target type is not atomic");
- }
- AtomicType at = (AtomicType)itemType;
- if (!at.matchesItem(value, true, getConfiguration())) {
- throw new XQException("value is invalid for specified type");
- }
- }
-
-
- /*@NotNull*/ private static String getClarkName(QName qname) {
- String uri = qname.getNamespaceURI();
- return "{" + (uri == null ? "" : uri) + "}" + qname.getLocalPart();
- }
-
- private static void checkNotNull(/*@Nullable*/ Object arg) throws XQException {
- if (arg == null) {
- throw new XQException("Argument is null");
- }
- }
-
-}
\ No newline at end of file
diff --git a/sf/saxon/xqj/SaxonXQExpression.java b/sf/saxon/xqj/SaxonXQExpression.java
deleted file mode 100644
index 94d0414..0000000
--- a/sf/saxon/xqj/SaxonXQExpression.java
+++ /dev/null
@@ -1,132 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.query.DynamicQueryContext;
-import net.sf.saxon.query.StaticQueryContext;
-import net.sf.saxon.query.XQueryExpression;
-import net.sf.saxon.trans.XPathException;
-
-import javax.xml.namespace.QName;
-import javax.xml.xquery.XQException;
-import javax.xml.xquery.XQExpression;
-import javax.xml.xquery.XQResultSequence;
-import javax.xml.xquery.XQStaticContext;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-
-/**
- * Saxon implementation of the XQJ XQExpression interface
- */
-public class SaxonXQExpression extends SaxonXQDynamicContext implements XQExpression {
-
- private SaxonXQStaticContext sqc;
- private DynamicQueryContext context;
-
- SaxonXQExpression(SaxonXQConnection connection) throws XQException {
- this.connection = connection;
- context = new DynamicQueryContext(connection.getConfiguration());
- context.setApplyFunctionConversionRulesToExternalVariables(false);
- sqc = (SaxonXQStaticContext)connection.getStaticContext(); // this takes a snapshot copy
- setClosableContainer(connection);
- }
-
- SaxonXQExpression(SaxonXQConnection connection, SaxonXQStaticContext staticContext) {
- this.connection = connection;
- context = new DynamicQueryContext(connection.getConfiguration());
- context.setApplyFunctionConversionRulesToExternalVariables(false);
- sqc = new SaxonXQStaticContext(staticContext); // take a snapshot copy
- setClosableContainer(connection);
- }
-
- protected DynamicQueryContext getDynamicContext() {
- return context;
- }
-
- protected SaxonXQDataFactory getDataFactory() throws XQException {
- return connection;
- }
-
- public void cancel() throws XQException {
- checkNotClosed();
- //
- }
-
- public void executeCommand(Reader command) throws XQException {
- checkNotClosed();
- throw new XQException("Saxon does not recognize any non-XQuery commands");
- }
-
- public void executeCommand(String command) throws XQException {
- checkNotClosed();
- throw new XQException("Saxon does not recognize any non-XQuery commands");
- }
-
- public XQResultSequence executeQuery(InputStream query) throws XQException {
- checkNotClosed();
- try {
- StaticQueryContext env = sqc.getSaxonStaticQueryContext();
- XQueryExpression exp = env.compileQuery(query, null);
- SaxonXQPreparedExpression pe = new SaxonXQPreparedExpression(connection, exp, sqc, context);
- return pe.executeQuery();
- } catch (XPathException e) {
- XQException xqe = new XQException(e.getMessage());
- xqe.initCause(e);
- throw xqe;
- } catch (IOException e) {
- XQException xqe = new XQException(e.getMessage());
- xqe.initCause(e);
- throw xqe;
- }
- }
-
- public XQResultSequence executeQuery(Reader query) throws XQException {
- checkNotClosed();
- SaxonXQDataSource.checkNotNull(query, "query");
- try {
- StaticQueryContext env = sqc.getSaxonStaticQueryContext();
- XQueryExpression exp = env.compileQuery(query);
- SaxonXQPreparedExpression pe = new SaxonXQPreparedExpression(connection, exp, sqc, context);
- return pe.executeQuery();
- } catch (XPathException e) {
- XQException xqe = new XQException(e.getMessage());
- xqe.initCause(e);
- throw xqe;
- } catch (IOException e) {
- XQException xqe = new XQException(e.getMessage());
- xqe.initCause(e);
- throw xqe;
- }
- }
-
- public XQResultSequence executeQuery(String query) throws XQException {
- checkNotClosed();
- try {
- StaticQueryContext env = sqc.getSaxonStaticQueryContext();
- XQueryExpression exp = env.compileQuery(query);
- SaxonXQPreparedExpression pe = new SaxonXQPreparedExpression(connection, exp, sqc, context);
- XQResultSequence result = pe.executeQuery();
- ((Closable)result).setClosableContainer(this);
- return result;
- } catch (XPathException e) {
- XQException xqe = new XQException(e.getMessage());
- xqe.initCause(e);
- throw xqe;
- }
- }
-
- public XQStaticContext getStaticContext() throws XQException {
- checkNotClosed();
- return sqc;
- }
-
- protected boolean externalVariableExists(QName name) {
- return true;
- }
-}
\ No newline at end of file
diff --git a/sf/saxon/xqj/SaxonXQForwardSequence.java b/sf/saxon/xqj/SaxonXQForwardSequence.java
deleted file mode 100644
index baa473c..0000000
--- a/sf/saxon/xqj/SaxonXQForwardSequence.java
+++ /dev/null
@@ -1,359 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.Configuration;
-import net.sf.saxon.event.PipelineConfiguration;
-import net.sf.saxon.evpull.*;
-import net.sf.saxon.functions.Insert;
-import net.sf.saxon.om.Item;
-import net.sf.saxon.om.SequenceIterator;
-import net.sf.saxon.query.QueryResult;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.tree.iter.SingletonIterator;
-import org.w3c.dom.Node;
-import org.xml.sax.ContentHandler;
-
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.Result;
-import javax.xml.transform.sax.SAXResult;
-import javax.xml.xquery.*;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.net.URI;
-import java.util.Properties;
-
-/**
- * The class is a Saxon implementation of the XQJ interface XQResultSequence. This
- * implementation is used to represent a sequence that can only be read in a forwards direction.
- */
-public class SaxonXQForwardSequence extends Closable implements XQResultSequence {
-
- private SequenceIterator iterator;
- SaxonXQPreparedExpression expression;
- int position = 0; // set to -count when positioned after the end
- int lastReadPosition = Integer.MIN_VALUE; // used to prevent reading the same item twice, which XQJ doesn't allow
-
- protected SaxonXQForwardSequence(SequenceIterator iterator, SaxonXQPreparedExpression expression) {
- this.iterator = iterator;
- this.expression = expression;
- setClosableContainer(expression);
- }
-
- /*@Nullable*/ SequenceIterator getCleanIterator() throws XPathException {
- return iterator.getAnother();
- }
-
- Configuration getConfiguration() {
- return expression.getConnection().getConfiguration();
- }
-
- public XQConnection getConnection() throws XQException {
- checkNotClosed();
- return expression.getConnection();
- }
-
- public String getAtomicValue() throws XQException {
- return getCurrentXQItem(true).getAtomicValue();
- }
-
- public boolean getBoolean() throws XQException {
- return getCurrentXQItem(true).getBoolean();
- }
-
- public byte getByte() throws XQException {
- return getCurrentXQItem(true).getByte();
- }
-
- public double getDouble() throws XQException {
- return getCurrentXQItem(true).getDouble();
- }
-
- public float getFloat() throws XQException {
- return getCurrentXQItem(true).getFloat();
- }
-
- public int getInt() throws XQException {
- return getCurrentXQItem(true).getInt();
- }
-
- public XMLStreamReader getItemAsStream() throws XQException {
- return getCurrentXQItem(true).getItemAsStream();
- }
-
- public String getItemAsString(Properties props) throws XQException {
- return getCurrentXQItem(true).getItemAsString(props);
- }
-
- public XQItemType getItemType() throws XQException {
- return getCurrentXQItem(false).getItemType();
- }
-
- public long getLong() throws XQException {
- return getCurrentXQItem(true).getLong();
- }
-
- public Node getNode() throws XQException {
- return getCurrentXQItem(true).getNode();
- }
-
- public URI getNodeUri() throws XQException {
- return getCurrentXQItem(false).getNodeUri();
- }
-
- public Object getObject() throws XQException {
- return getCurrentXQItem(true).getObject();
- }
-
- public short getShort() throws XQException {
- return getCurrentXQItem(true).getShort();
- }
-
- public boolean instanceOf(XQItemType type) throws XQException {
- return getCurrentXQItem(false).instanceOf(type);
- }
-
- public void writeItem(OutputStream os, Properties props) throws XQException {
- getCurrentXQItem(true).writeItem(os, props);
- }
-
- public void writeItem(Writer ow, Properties props) throws XQException {
- getCurrentXQItem(true).writeItem(ow, props);
- }
-
- public void writeItemToResult(Result result) throws XQException {
- getCurrentXQItem(true).writeItemToResult(result);
- }
-
- public void writeItemToSAX(ContentHandler saxHandler) throws XQException {
- getCurrentXQItem(true).writeItemToSAX(saxHandler);
- }
-
- public boolean absolute(int itempos) throws XQException {
- throw new XQException("Sequence is forwards-only");
- }
-
- public void afterLast() throws XQException {
- throw new XQException("Sequence is forwards-only");
- }
-
- public void beforeFirst() throws XQException {
- throw new XQException("Sequence is forwards-only");
- }
-
- public int count() throws XQException {
- throw new XQException("Sequence is forwards-only");
- }
-
- public boolean first() throws XQException {
- throw new XQException("Sequence is forwards-only");
- }
-
- /*@NotNull*/ public XQItem getItem() throws XQException {
- return getCurrentXQItem(true);
- }
-
- public int getPosition() throws XQException {
- throw new XQException("Sequence is forwards-only");
- }
-
- /*@NotNull*/ public XMLStreamReader getSequenceAsStream() throws XQException {
- checkNotClosed();
- checkOnlyReadOnce();
- EventIterator ei = new EventIteratorOverSequence(iterator);
- ei = new BracketedDocumentIterator(ei);
- Configuration config = getConfiguration();
- PipelineConfiguration pipe = config.makePipelineConfiguration();
- pipe.setHostLanguage(Configuration.XQUERY);
- ei = new Decomposer(ei, pipe);
- return new EventToStaxBridge(ei, pipe);
- }
-
- public String getSequenceAsString(Properties props) throws XQException {
- checkNotClosed();
- StringWriter sw = new StringWriter();
- writeSequence(sw, props);
- return sw.toString();
- }
-
- public boolean isAfterLast() throws XQException {
- throw new XQException("Sequence is forwards-only");
- }
-
- public boolean isBeforeFirst() throws XQException {
- throw new XQException("Sequence is forwards-only");
- }
-
- public boolean isFirst() throws XQException {
- throw new XQException("Sequence is forwards-only");
- }
-
- public boolean isLast() throws XQException {
- throw new XQException("Sequence is forwards-only");
- }
-
- public boolean isOnItem() throws XQException {
- checkNotClosed();
- return position > 0;
- }
-
- public boolean isScrollable() throws XQException {
- checkNotClosed();
- return false;
- }
-
- public boolean last() throws XQException {
- throw new XQException("Sequence is forwards-only");
- }
-
- public boolean next() throws XQException {
- checkNotClosed();
- if (position < 0) {
- return false;
- }
- try {
- Item next = iterator.next();
- if (next == null) {
- position = -1;
- return false;
- } else {
- position++;
- return true;
- }
- } catch (XPathException e) {
- throw newXQException(e);
- }
- }
-
- public boolean previous() throws XQException {
- throw new XQException("Sequence is forwards-only");
- }
-
- public boolean relative(int itempos) throws XQException {
- checkNotClosed();
-// if (itempos < 0) {
- throw new XQException("Sequence is forwards-only, cannot move backwards");
-// } else {
-// for (int i=0; i<itempos; i++) {
-// if (!next()) {
-// return false;
-// }
-// }
-// return true;
-// }
- }
-
- public void writeSequence(OutputStream os, /*@Nullable*/ Properties props) throws XQException {
- checkNotNull(os);
- checkNotClosed();
- checkOnlyReadOnce();
- if (props == null) {
- props = new Properties();
- }
- props = SaxonXQSequence.setDefaultProperties(props);
- SequenceIterator iter = iterator;
- if (isOnItem()) {
- iter = new Insert.InsertIterator(
- SingletonIterator.makeIterator(iter.current()),
- iter, 0);
- }
- try {
- QueryResult.serializeSequence(iter, getConfiguration(), os, props);
- } catch (XPathException e) {
- throw newXQException(e);
- }
- }
-
- public void writeSequence(Writer ow, /*@Nullable*/ Properties props) throws XQException {
- checkNotClosed();
- checkNotNull(ow);
- checkOnlyReadOnce();
- if (props == null) {
- props = new Properties();
- } else {
- SaxonXQItem.validateSerializationProperties(props, expression.getConfiguration());
- }
- props = SaxonXQSequence.setDefaultProperties(props);
- PrintWriter pw;
- if (ow instanceof PrintWriter) {
- pw = (PrintWriter)ow;
- } else {
- pw = new PrintWriter(ow);
- }
- SequenceIterator iter = iterator;
- if (isOnItem()) {
- iter = new Insert.InsertIterator(
- SingletonIterator.makeIterator(iter.current()),
- iter, 0);
- }
- try {
- QueryResult.serializeSequence(iter, getConfiguration(), pw, props);
- } catch (XPathException e) {
- throw newXQException(e);
- }
- }
-
- public void writeSequenceToResult(Result result) throws XQException {
- checkNotClosed();
- checkNotNull(result);
- checkOnlyReadOnce();
- Properties props = SaxonXQSequence.setDefaultProperties(null);
- try {
- QueryResult.serializeSequence(iterator, getConfiguration(), result, props);
- } catch (XPathException e) {
- throw newXQException(e);
- }
- }
-
- public void writeSequenceToSAX(ContentHandler saxHandler) throws XQException {
- checkNotClosed();
- checkNotNull(saxHandler);
- writeSequenceToResult(new SAXResult(saxHandler));
- }
-
- /*@NotNull*/ private XQItem getCurrentXQItem(boolean onceOnly) throws XQException {
- checkNotClosed();
- if (position == 0) {
- throw new XQException("The XQSequence is positioned before the first item");
- } else if (position < 0) {
- throw new XQException("The XQSequence is positioned after the last item");
- }
- if (onceOnly) {
- checkOnlyReadOnce();
- }
- SaxonXQItem item = new SaxonXQItem(iterator.current(), expression.getConnection());
- item.setClosableContainer(this);
- return item;
- }
-
- /*@Nullable*/ Item getSaxonItem() {
- return iterator.current();
- }
-
-
- private void checkNotNull(/*@Nullable*/ Object arg) throws XQException {
- if (arg == null) {
- throw new XQException("Argument is null");
- }
- }
-
- private void checkOnlyReadOnce() throws XQException {
- if (position == lastReadPosition) {
- throw new XQException("XQJ does not allow the same item to be read more than once");
- }
- lastReadPosition = position;
- }
-
- /*@NotNull*/ private XQException newXQException(/*@NotNull*/ Exception err) {
- XQException xqe = new XQException(err.getMessage());
- xqe.initCause(err);
- return xqe;
- }
-}
\ No newline at end of file
diff --git a/sf/saxon/xqj/SaxonXQItem.java b/sf/saxon/xqj/SaxonXQItem.java
deleted file mode 100644
index 58c134e..0000000
--- a/sf/saxon/xqj/SaxonXQItem.java
+++ /dev/null
@@ -1,327 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.Configuration;
-import net.sf.saxon.dom.NodeOverNodeInfo;
-import net.sf.saxon.event.PipelineConfiguration;
-import net.sf.saxon.event.Receiver;
-import net.sf.saxon.event.TreeReceiver;
-import net.sf.saxon.evpull.*;
-import net.sf.saxon.expr.instruct.ResultDocument;
-import net.sf.saxon.lib.SerializerFactory;
-import net.sf.saxon.om.DocumentInfo;
-import net.sf.saxon.om.Item;
-import net.sf.saxon.om.NodeInfo;
-import net.sf.saxon.om.StructuredQName;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.tree.wrapper.VirtualNode;
-import net.sf.saxon.value.*;
-import org.w3c.dom.Node;
-import org.xml.sax.ContentHandler;
-
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.Result;
-import javax.xml.transform.sax.SAXResult;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.xquery.XQConnection;
-import javax.xml.xquery.XQException;
-import javax.xml.xquery.XQItemType;
-import javax.xml.xquery.XQResultItem;
-import java.io.OutputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Enumeration;
-import java.util.Properties;
-
-/**
- * This Saxon class is used to implement both the XQItem and XQResultItem interfaces in XQJ.
- * Where the item is not a real XQResultItem, getConnection() will return null.
- */
-public class SaxonXQItem extends Closable implements XQResultItem, SaxonXQItemAccessor {
-
- /*@Nullable*/ private Item item;
- private Configuration config;
- SaxonXQDataFactory dataFactory;
-
- public SaxonXQItem(/*@Nullable*/ Item item, /*@NotNull*/ SaxonXQDataFactory factory) {
- if (item == null) {
- throw new NullPointerException("item");
- }
- this.item = item;
- dataFactory = factory;
- config = factory.getConfiguration();
- setClosableContainer(factory);
- }
-
- Configuration getConfiguration() {
- return config;
- }
-
- /*@Nullable*/ public Item getSaxonItem() {
- return item;
- }
-
- /*@Nullable*/ public XQConnection getConnection() throws XQException {
- checkNotClosed();
- if (dataFactory instanceof XQConnection) {
- return (XQConnection)dataFactory;
- } else {
- return null;
- }
- }
-
- public String getAtomicValue() throws XQException {
- checkNotClosed();
- if (item instanceof AtomicValue) {
- return item.getStringValue();
- }
- throw new XQException("Failed to getAtomicValue: item is a node, or is closed");
- }
-
- public boolean getBoolean() throws XQException {
- checkNotClosed();
- if (item instanceof BooleanValue) {
- return ((BooleanValue)item).getBooleanValue();
- }
- throw new XQException("Failed in getBoolean: item is not a boolean, or is closed");
- }
-
- public byte getByte() throws XQException {
- checkNotClosed();
- if (item instanceof AtomicValue) {
- AtomicValue prim = ((AtomicValue)item);
- return (byte)longValue(prim, -128, 127);
- }
- throw new XQException("Failed in getByte: item is not an atomic value, or is closed");
- }
-
- private static long longValue(/*@NotNull*/ AtomicValue value, long min, long max) throws XQException {
- if (value instanceof NumericValue) {
- if (value instanceof DoubleValue || value instanceof FloatValue) {
- throw new XQException("Value is a double or float");
- }
- if (!((NumericValue)value).isWholeNumber()) {
- throw new XQException("Value is not a whole number");
- }
- try {
- long val = ((NumericValue)value).longValue();
- if (val >= min && val <= max) {
- return val;
- } else {
- throw new XQException("Value is out of range for requested type");
- }
- } catch (XPathException err) {
- XQException xqe = new XQException(err.getMessage());
- xqe.initCause(err);
- throw xqe;
- }
- }
- throw new XQException("Value is not numeric");
- }
-
- public double getDouble() throws XQException {
- checkNotClosed();
- if (item instanceof DoubleValue) {
- return ((DoubleValue)item).getDoubleValue();
- }
- throw new XQException("Failed in getDouble: item is not a double, or is closed");
- }
-
- public float getFloat() throws XQException {
- checkNotClosed();
- if (item instanceof FloatValue) {
- return ((FloatValue)item).getFloatValue();
- }
- throw new XQException("Failed in getFloat: item is not a float, or is closed");
- }
-
- public int getInt() throws XQException {
- checkNotClosed();
- if (item instanceof AtomicValue) {
- AtomicValue prim = ((AtomicValue)item);
- return (int)longValue(prim, Integer.MIN_VALUE, Integer.MAX_VALUE);
- }
- throw new XQException("Failed in getInt: item is not an atomic value, or is closed");
- }
-
- /*@NotNull*/ public XMLStreamReader getItemAsStream() throws XQException {
- // The spec (section 12.1) requires that the item be converted into a document, and we
- // then read events corresponding to this document
- checkNotClosed();
- PipelineConfiguration pipe = config.makePipelineConfiguration();
- pipe.setHostLanguage(Configuration.XQUERY);
- if (item instanceof DocumentInfo) {
- EventIterator eventIterator = new Decomposer((NodeInfo)item, pipe);
- return new EventToStaxBridge(eventIterator, pipe);
- } else {
- EventIterator contentIterator = new SingletonEventIterator(item);
- EventIterator eventIterator = new BracketedDocumentIterator(contentIterator);
- eventIterator = new Decomposer(eventIterator, pipe);
- return new EventToStaxBridge(eventIterator, pipe);
- }
- }
-
- public String getItemAsString(/*@Nullable*/ Properties props) throws XQException {
- checkNotClosed();
- if (props == null) {
- props = new Properties();
- } else {
- validateSerializationProperties(props, config);
- }
- props = SaxonXQSequence.setDefaultProperties(props);
- StringWriter writer = new StringWriter();
- writeItem(writer, props);
- return writer.toString();
- }
-
- protected static void validateSerializationProperties(/*@NotNull*/ Properties props, Configuration config) throws XQException {
- Properties validatedProps = new Properties();
- for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
- String name = (String)e.nextElement();
- String value = props.getProperty(name);
- String localName = name;
- String uri = "";
- if (name.startsWith("{")) {
- StructuredQName qName = StructuredQName.fromClarkName(name);
- localName = qName.getLocalPart();
- uri = qName.getURI();
- }
- try {
- ResultDocument.setSerializationProperty(validatedProps, uri, localName, value, null, false, config);
- } catch (XPathException ex) {
- throw new XQException("Invalid serialization property: " + ex.getMessage());
- }
- }
- }
-
- /*@NotNull*/ public XQItemType getItemType() throws XQException {
- checkNotClosed();
- if (item instanceof AtomicValue) {
- return new SaxonXQItemType(
- ((AtomicValue)item).getItemType(),
- getConfiguration());
- } else {
- return new SaxonXQItemType((NodeInfo)item);
- }
- }
-
- public long getLong() throws XQException {
- checkNotClosed();
- if (item instanceof AtomicValue) {
- AtomicValue prim = ((AtomicValue)item);
- return (byte)longValue(prim, Long.MIN_VALUE, Long.MAX_VALUE);
- }
- throw new XQException("Failed in getLong: item is not an atomic value, or is closed");
- }
-
- public Node getNode() throws XQException {
- checkNotClosed();
- if (!(item instanceof NodeInfo)) {
- throw new XQException("Failed in getNode: item is an atomic value, or is closed");
- }
- if (item instanceof VirtualNode) {
- Object n = ((VirtualNode)item).getRealNode();
- if (n instanceof Node) {
- return (Node)n;
- }
- }
- return NodeOverNodeInfo.wrap((NodeInfo)item);
- }
-
- /*@NotNull*/ public URI getNodeUri() throws XQException {
- checkNotClosed();
- if (item instanceof NodeInfo) {
- try {
- String systemId = ((NodeInfo)item).getSystemId();
- if (systemId == null) {
- return new URI("");
- }
- return new URI(systemId);
- } catch (URISyntaxException e) {
- throw new XQException("System ID of node is not a valid URI");
- }
- }
- throw new XQException("Item is not a node");
- }
-
- public Object getObject() throws XQException {
- checkNotClosed();
- return dataFactory.getObjectConverter().toObject(this);
- }
-
- public short getShort() throws XQException {
- checkNotClosed();
- if (item instanceof AtomicValue) {
- AtomicValue prim = ((AtomicValue)item);
- return (short)longValue(prim, Short.MIN_VALUE, Short.MAX_VALUE);
- }
- throw new XQException("Failed in getShort: item is not an atomic value, or is closed");
- }
-
- public boolean instanceOf(/*@NotNull*/ XQItemType type) throws XQException {
- checkNotClosed();
- checkNotNull(type);
- return ((SaxonXQItemType)type).getSaxonItemType().matchesItem(item, false, config);
- }
-
- public void writeItem(OutputStream os, Properties props) throws XQException {
- checkNotClosed();
- checkNotNull(os);
- writeItemToResult(new StreamResult(os), props);
- }
-
- public void writeItem(Writer ow, Properties props) throws XQException {
- checkNotClosed();
- checkNotNull(ow);
- writeItemToResult(new StreamResult(ow), props);
- }
-
- public void writeItemToResult(Result result) throws XQException {
- checkNotClosed();
- checkNotNull(result);
- writeItemToResult(result, new Properties());
- }
-
- private void writeItemToResult(Result result, /*@Nullable*/ Properties props) throws XQException {
- checkNotClosed();
- checkNotNull(result);
- if (props == null) {
- props = new Properties();
- }
- props = SaxonXQSequence.setDefaultProperties(props);
- try {
- SerializerFactory sf = config.getSerializerFactory();
- PipelineConfiguration pipe = config.makePipelineConfiguration();
- Receiver out = sf.getReceiver(result, pipe, props);
- TreeReceiver tr = new TreeReceiver(out);
- tr.open();
- tr.append(item, 0, NodeInfo.ALL_NAMESPACES);
- tr.close();
- } catch (XPathException e) {
- XQException xqe = new XQException(e.getMessage());
- xqe.initCause(e);
- throw xqe;
- }
- }
-
- public void writeItemToSAX(ContentHandler saxHandler) throws XQException {
- checkNotClosed();
- checkNotNull(saxHandler);
- writeItemToResult(new SAXResult(saxHandler));
- }
-
- private void checkNotNull(/*@Nullable*/ Object arg) throws XQException {
- if (arg == null) {
- throw new XQException("Argument is null");
- }
- }
-
-}
\ No newline at end of file
diff --git a/sf/saxon/xqj/SaxonXQItemAccessor.java b/sf/saxon/xqj/SaxonXQItemAccessor.java
deleted file mode 100644
index 0d26d05..0000000
--- a/sf/saxon/xqj/SaxonXQItemAccessor.java
+++ /dev/null
@@ -1,28 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.om.Item;
-
-import javax.xml.xquery.XQException;
-
-/**
- * All Saxon implementations of XQItemAccessor must implement this interface
- */
-public interface SaxonXQItemAccessor {
-
- /**
- * Get the current item, in the form of a Saxon Item object. This allows access to non-XQJ methods
- * to manipulate the item, which will not necessarily be stable from release to release. The resulting
- * Item will be an instance of either {@link net.sf.saxon.om.NodeInfo} or {@link net.sf.saxon.value.AtomicValue}.
- * @return the current item
- */
-
- /*@Nullable*/ public Item getSaxonItem() throws XQException;
-}
-
diff --git a/sf/saxon/xqj/SaxonXQItemType.java b/sf/saxon/xqj/SaxonXQItemType.java
deleted file mode 100644
index 2c3f958..0000000
--- a/sf/saxon/xqj/SaxonXQItemType.java
+++ /dev/null
@@ -1,260 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.Configuration;
-import net.sf.saxon.om.NamePool;
-import net.sf.saxon.om.NodeInfo;
-import net.sf.saxon.om.StandardNames;
-import net.sf.saxon.pattern.DocumentNodeTest;
-import net.sf.saxon.pattern.NameTest;
-import net.sf.saxon.pattern.NodeKindTest;
-import net.sf.saxon.pattern.NodeTest;
-import net.sf.saxon.type.*;
-import net.sf.saxon.z.IntIterator;
-import net.sf.saxon.z.IntSet;
-
-import javax.xml.namespace.QName;
-import javax.xml.xquery.XQException;
-import javax.xml.xquery.XQItemType;
-import javax.xml.xquery.XQSequenceType;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-/**
- * Saxon implementation of the XQJ XQItemType interface
- */
-public class SaxonXQItemType implements XQItemType {
-
- /*@NotNull*/ private ItemType itemType;
- /*@NotNull*/ private Configuration config;
-
- protected SaxonXQItemType(/*@NotNull*/ ItemType itemType, /*@NotNull*/ Configuration config) {
- this.itemType = itemType;
- this.config = config;
- }
-
- protected SaxonXQItemType(/*@NotNull*/ NodeInfo node) {
- config = node.getConfiguration();
- itemType = Type.getItemType(node, config.getTypeHierarchy());
- }
-
- public int getBaseType() throws XQException {
- if (itemType instanceof AtomicType) {
- AtomicType at = (AtomicType)itemType;
- while (!at.isBuiltInType()) {
- at = (AtomicType)at.getBaseType();
- }
- return SaxonXQDataFactory.mapSaxonTypeToXQJ(at.getFingerprint());
- } else if (itemType instanceof NodeTest) {
- NodeTest it = (NodeTest)itemType;
- if (it instanceof DocumentNodeTest) {
- it = ((DocumentNodeTest)it).getElementTest();
- }
- if ((it.getNodeKindMask() &
- (1<<Type.DOCUMENT | 1<<Type.TEXT | 1<<Type.COMMENT | 1<<Type.PROCESSING_INSTRUCTION | 1<<Type.NAMESPACE)) != 0) {
- throw new XQException("Wrong node kind for getBaseType()");
- }
- SchemaType contentType = it.getContentType();
- if (contentType.isAtomicType()) {
- AtomicType at = (AtomicType)contentType;
- while (!at.isBuiltInType()) {
- at = (AtomicType)at.getBaseType();
- }
- return SaxonXQDataFactory.mapSaxonTypeToXQJ(at.getFingerprint());
- } else if (contentType.isSimpleType()) {
- if (((SimpleType)contentType).isListType()) {
- int fp = contentType.getFingerprint();
- if (fp == StandardNames.XS_NMTOKENS) {
- return XQBASETYPE_NMTOKENS;
- } else if (fp == StandardNames.XS_ENTITIES) {
- return XQBASETYPE_ENTITIES;
- } else if (fp == StandardNames.XS_IDREFS) {
- return XQBASETYPE_IDREFS;
- }
- }
- return XQBASETYPE_ANYSIMPLETYPE;
- } else if (contentType == Untyped.getInstance()) {
- return XQBASETYPE_UNTYPED;
- } else {
- return XQBASETYPE_ANYTYPE;
- }
-
- } else {
- throw new XQException("Wrong item type for getBaseType()");
- }
- }
-
- public int getItemKind() {
- if (itemType instanceof AtomicType) {
- return XQITEMKIND_ATOMIC;
- } else if (itemType instanceof NodeTest) {
- if (itemType instanceof DocumentNodeTest) {
- return XQITEMKIND_DOCUMENT_ELEMENT;
- }
- int x = itemType.getPrimitiveType();
- switch (x) {
- case Type.DOCUMENT:
- return XQITEMKIND_DOCUMENT;
- case Type.ELEMENT:
- return XQITEMKIND_ELEMENT;
- case Type.ATTRIBUTE:
- return XQITEMKIND_ATTRIBUTE;
- case Type.TEXT:
- return XQITEMKIND_TEXT;
- case Type.COMMENT:
- return XQITEMKIND_COMMENT;
- case Type.PROCESSING_INSTRUCTION:
- return XQITEMKIND_PI;
- case Type.NODE:
- return XQITEMKIND_NODE;
- }
- }
- return XQITEMKIND_ITEM;
- }
-
- public int getItemOccurrence() {
- return XQSequenceType.OCC_EXACTLY_ONE;
- }
-
- /*@Nullable*/ public QName getNodeName() throws XQException {
- ItemType type = itemType;
- if (type instanceof DocumentNodeTest) {
- type = ((DocumentNodeTest)type).getElementTest();
- }
- if (type instanceof NodeTest) {
- if ((((NodeTest)type).getNodeKindMask() &
- (1<<Type.DOCUMENT | 1<<Type.TEXT | 1<<Type.COMMENT | 1<<Type.PROCESSING_INSTRUCTION | 1<<Type.NAMESPACE)) != 0) {
- throw new XQException("Wrong node kind for getNodeName()");
- }
- IntSet set = ((NodeTest)type).getRequiredNodeNames();
- if (set != null && set.size() == 1) {
- IntIterator ii = set.iterator();
- int fp = (ii.hasNext() ? ii.next() : -1);
- NamePool pool = config.getNamePool();
- String uri = pool.getURI(fp);
- String local = pool.getLocalName(fp);
- return new QName(uri, local);
- } else {
- return null;
- }
- }
- throw new XQException("getNodeName() is not defined for this kind of item type");
- }
-
- /*@Nullable*/ public String getPIName() throws XQException {
- if (itemType instanceof NameTest && itemType.getPrimitiveType() == Type.PROCESSING_INSTRUCTION) {
- NamePool pool = config.getNamePool();
- return pool.getLocalName(((NameTest)itemType).getFingerprint());
- } else if (itemType instanceof NodeKindTest && itemType.getPrimitiveType() == Type.PROCESSING_INSTRUCTION) {
- return null;
- } else {
- throw new XQException("Item kind is not a processing instruction");
- }
- }
-
- /*@Nullable*/ public URI getSchemaURI() {
- try {
- if (itemType instanceof NodeTest) {
- SchemaType content = ((NodeTest)itemType).getContentType();
- if (content == null) {
- return null;
- }
- String systemId = content.getSystemId();
- if (systemId == null) {
- return null;
- }
- return new URI(systemId);
- } else if (itemType instanceof AtomicType) {
- String systemId = ((AtomicType)itemType).getSystemId();
- return (systemId == null ? null : new URI(systemId));
- } else {
- return null;
- }
- } catch (URISyntaxException e) {
- return null;
- }
- }
-
- /*@Nullable*/ public String toString() {
- return itemType.toString();
- }
-
- /*@NotNull*/ public QName getTypeName() throws XQException {
- ItemType type = itemType;
- if (type instanceof AtomicType) {
- int fp = ((AtomicType)type).getFingerprint();
- NamePool pool = config.getNamePool();
- String uri = pool.getURI(fp);
- String local = pool.getLocalName(fp);
- return new QName(uri, local);
- }
- if (type instanceof DocumentNodeTest) {
- type = ((DocumentNodeTest)type).getElementTest();
- }
- if (type instanceof NodeTest) {
- if ((((NodeTest)type).getNodeKindMask() &
- (1<<Type.DOCUMENT | 1<<Type.TEXT | 1<<Type.COMMENT | 1<<Type.PROCESSING_INSTRUCTION | 1<<Type.NAMESPACE)) != 0) {
- throw new XQException("getTypeName() failed: itemType is not a document, element, or attribute test");
- }
- SchemaType t = ((NodeTest)type).getContentType();
- if (t != null) {
- int fp = ((NodeTest)type).getContentType().getFingerprint();
- NamePool pool = config.getNamePool();
- String uri = pool.getURI(fp);
- String local = pool.getLocalName(fp);
- return new QName(uri, local);
- }
- }
- throw new XQException("getTypeName() failed: itemType is not a document, element, or attribute test");
- }
-
- public boolean isAnonymousType() {
- ItemType type = itemType;
- if (type instanceof DocumentNodeTest) {
- type = ((DocumentNodeTest)type).getElementTest();
- }
- if (type instanceof NodeTest) {
- SchemaType t = ((NodeTest)type).getContentType();
- if (t != null) {
- return t.isAnonymousType();
- }
- }
- return false;
- }
-
- public boolean isElementNillable() {
- return (itemType instanceof NodeTest) && ((NodeTest)itemType).getNodeKindMask() == 1<<Type.ELEMENT && ((NodeTest)itemType).isNillable();
- }
-
-
- /*@NotNull*/ public XQItemType getItemType() {
- return this;
- }
-
- /*@Nullable*/ AtomicType getAtomicType() {
- if (itemType instanceof AtomicType) {
- return (AtomicType)itemType;
- } else {
- return null;
- }
- }
-
- /*@Nullable*/ ItemType getSaxonItemType() {
- return itemType;
- }
-
- public boolean equals(/*@NotNull*/ Object obj) {
- return obj instanceof SaxonXQItemType &&
- itemType.equals(((SaxonXQItemType)obj).itemType);
- }
-
- public int hashCode() {
- return itemType.hashCode();
- }
-}
\ No newline at end of file
diff --git a/sf/saxon/xqj/SaxonXQMetaData.java b/sf/saxon/xqj/SaxonXQMetaData.java
deleted file mode 100644
index a18a83a..0000000
--- a/sf/saxon/xqj/SaxonXQMetaData.java
+++ /dev/null
@@ -1,163 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.Configuration;
-import net.sf.saxon.Version;
-
-import javax.xml.xquery.XQException;
-import javax.xml.xquery.XQMetaData;
-import java.util.Set;
-
-/**
- * Saxon implementation of the XQMetaData interface
- */
-public class SaxonXQMetaData implements XQMetaData {
-
- private SaxonXQConnection connection;
-
- /**
- * Create the metadata for a given Saxon configuration
- * @param connection the Saxon connection
- */
-
- public SaxonXQMetaData(SaxonXQConnection connection) {
- this.connection = connection;
- }
-
- public int getMaxExpressionLength() throws XQException {
- checkNotClosed();
- checkNotClosed();
- return Integer.MAX_VALUE;
- }
-
- public int getMaxUserNameLength() throws XQException {
- checkNotClosed();
- return Integer.MAX_VALUE;
- }
-
- public int getProductMajorVersion() throws XQException {
- checkNotClosed();
- return Version.getStructuredVersionNumber()[0];
- }
-
- public int getProductMinorVersion() throws XQException {
- checkNotClosed();
- return Version.getStructuredVersionNumber()[1];
- }
-
- /*@NotNull*/ public String getProductName() throws XQException {
- checkNotClosed();
- return Version.getProductName();
- }
-
- /*@NotNull*/ public String getProductVersion() throws XQException {
- checkNotClosed();
- return Version.getProductVersion();
- }
-
- public Set getSupportedXQueryEncodings() throws XQException {
- checkNotClosed();
- return java.nio.charset.Charset.availableCharsets().keySet();
- }
-
- /*@Nullable*/ public String getUserName() throws XQException {
- checkNotClosed();
- return null;
- }
-
- public int getXQJMajorVersion() throws XQException {
- checkNotClosed();
- return 0;
- }
-
- public int getXQJMinorVersion() throws XQException {
- checkNotClosed();
- return 9;
- }
-
- /*@NotNull*/ public String getXQJVersion() throws XQException {
- checkNotClosed();
- return "0.9";
- }
-
- public boolean isFullAxisFeatureSupported() throws XQException {
- checkNotClosed();
- return true;
- }
-
- public boolean isModuleFeatureSupported() throws XQException {
- checkNotClosed();
- return true;
- }
-
- public boolean isReadOnly() throws XQException {
- checkNotClosed();
- return true;
- }
-
- public boolean isSchemaImportFeatureSupported() throws XQException {
- checkNotClosed();
- return connection.getConfiguration().isLicensedFeature(Configuration.LicenseFeature.ENTERPRISE_XQUERY);
- }
-
- public boolean isSchemaValidationFeatureSupported() throws XQException {
- checkNotClosed();
- return connection.getConfiguration().isLicensedFeature(Configuration.LicenseFeature.ENTERPRISE_XQUERY);
- }
-
- public boolean isSerializationFeatureSupported() throws XQException {
- checkNotClosed();
- return true;
- }
-
- public boolean isStaticTypingExtensionsSupported() throws XQException {
- checkNotClosed();
- return false;
- }
-
- public boolean isStaticTypingFeatureSupported() throws XQException {
- checkNotClosed();
- return false;
- }
-
- public boolean isTransactionSupported() throws XQException {
- checkNotClosed();
- return false;
- }
-
- public boolean isUserDefinedXMLSchemaTypeSupported() throws XQException {
- checkNotClosed();
- return connection.getConfiguration().isLicensedFeature(Configuration.LicenseFeature.ENTERPRISE_XQUERY);
- }
-
- public boolean isXQueryEncodingDeclSupported() throws XQException {
- checkNotClosed();
- return true;
- }
-
- public boolean isXQueryEncodingSupported(String encoding) throws XQException {
- checkNotClosed();
- return getSupportedXQueryEncodings().contains(encoding);
- }
-
- public boolean isXQueryXSupported() throws XQException {
- checkNotClosed();
- return false;
- }
-
- public boolean wasCreatedFromJDBCConnection() throws XQException {
- checkNotClosed();
- return false;
- }
-
- private void checkNotClosed() throws XQException {
- connection.checkNotClosed();
- }
-}
-
diff --git a/sf/saxon/xqj/SaxonXQPreparedExpression.java b/sf/saxon/xqj/SaxonXQPreparedExpression.java
deleted file mode 100644
index e0f6e5a..0000000
--- a/sf/saxon/xqj/SaxonXQPreparedExpression.java
+++ /dev/null
@@ -1,197 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.expr.Expression;
-import net.sf.saxon.expr.instruct.GlobalParam;
-import net.sf.saxon.expr.instruct.GlobalVariable;
-import net.sf.saxon.lib.NamespaceConstant;
-import net.sf.saxon.om.SequenceIterator;
-import net.sf.saxon.om.StructuredQName;
-import net.sf.saxon.query.DynamicQueryContext;
-import net.sf.saxon.query.XQueryExpression;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.type.ItemType;
-import net.sf.saxon.value.SequenceExtent;
-import net.sf.saxon.value.SequenceType;
-import net.sf.saxon.z.IntHashSet;
-import net.sf.saxon.z.IntIterator;
-
-import javax.xml.namespace.QName;
-import javax.xml.xquery.*;
-import java.util.HashMap;
-import java.util.HashSet;
-
-/**
- * Saxon implementation of the XQJ interface XQPreparedExpression. This represents a compiled XQuery
- * expression, together with the dynamic context for its evaluation. Note that this means the object
- * should not be used in more than one thread concurrently.
- * <p>
- * Note that an expression is scrollable or not depending on the scrollability property of the XQConnection
- * that was used to compile this expression (at the time it was compiled). If the expression is scrollable then
- * its results are delivered in an XQSequence that supports scrolling backwards as well as forwards.
- * <p>
- * For full Javadoc details, see the XQJ interface specification.
- */
-public class SaxonXQPreparedExpression extends SaxonXQDynamicContext implements XQPreparedExpression {
-
- private XQueryExpression expression;
- private SaxonXQStaticContext staticContext;
- private DynamicQueryContext context;
- private boolean scrollable;
-
- protected SaxonXQPreparedExpression(SaxonXQConnection connection,
- XQueryExpression expression,
- /*@NotNull*/ SaxonXQStaticContext sqc,
- DynamicQueryContext context)
- throws XQException {
- this.connection = connection;
- this.expression = expression;
- this.staticContext = new SaxonXQStaticContext(sqc); // take a snapshot of the supplied static context
- this.context = context;
- scrollable = sqc.getScrollability() == XQConstants.SCROLLTYPE_SCROLLABLE;
- setClosableContainer(connection);
- }
-
- protected DynamicQueryContext getDynamicContext() {
- return context;
- }
-
- protected SaxonXQConnection getConnection() {
- return connection;
- }
-
- protected SaxonXQDataFactory getDataFactory() throws XQException {
- if (connection.isClosed()) {
- close();
- }
- checkNotClosed();
- return connection;
- }
-
- protected XQueryExpression getXQueryExpression() {
- return expression;
- }
-
- protected SaxonXQStaticContext getSaxonXQStaticContext() {
- return staticContext;
- }
-
- public void cancel() throws XQException {
- checkNotClosed();
- }
-
- /*@NotNull*/ public XQResultSequence executeQuery() throws XQException {
- checkNotClosed();
- try {
- SequenceIterator iter = expression.iterator(context);
- if (scrollable) {
- SequenceExtent value = new SequenceExtent(iter);
- return new SaxonXQSequence(value, this);
- } else {
- return new SaxonXQForwardSequence(iter, this);
- }
- } catch (XPathException de) {
- XQException xqe = new XQException(de.getMessage());
- xqe.initCause(de);
- throw xqe;
- }
- }
-
- /*@NotNull*/ public QName[] getAllExternalVariables() throws XQException {
- checkNotClosed();
- HashMap<StructuredQName, GlobalVariable> vars = expression.getExecutable().getCompiledGlobalVariables();
- if (vars == null || vars.isEmpty()) {
- return EMPTY_QNAME_ARRAY;
- } else {
- HashSet<StructuredQName> params = new HashSet<StructuredQName>(vars.size());
- for (GlobalVariable var : vars.values()) {
- if (var instanceof GlobalParam) {
- StructuredQName q = var.getVariableQName();
- if (!(q.getURI().equals(NamespaceConstant.SAXON) && q.getLocalPart().equals("context-item"))) {
- params.add(q);
- }
- }
- }
- QName[] qnames = new QName[params.size()];
- int q=0;
- for (StructuredQName name : params) {
- qnames[q++] = new QName(name.getURI(), name.getLocalPart(), name.getPrefix());
- }
- return qnames;
- }
- }
-
- /*@NotNull*/ private static QName[] EMPTY_QNAME_ARRAY = new QName[0];
-
- /*@NotNull*/ public QName[] getAllUnboundExternalVariables() throws XQException {
- checkNotClosed();
- java.util.Collection<StructuredQName> boundParameters = getDynamicContext().getParameters().getKeys();
- IntHashSet unbound = new IntHashSet(boundParameters.size());
- QName[] all = getAllExternalVariables();
- for (int i=0; i<all.length; i++) {
- StructuredQName sq = new StructuredQName("", all[i].getNamespaceURI(), all[i].getLocalPart());
- if (!boundParameters.contains(sq)) {
- unbound.add(i);
- }
- }
- QName[] unboundq = new QName[unbound.size()];
- int c = 0;
- IntIterator iter = unbound.iterator();
- while (iter.hasNext()) {
- int x = iter.next();
- unboundq[c++] = all[x];
- }
- return unboundq;
- }
-
- public XQStaticContext getStaticContext() throws XQException {
- checkNotClosed();
- return staticContext; // a snapshot of the static context at the time the expression was created
- // old code in Saxon 9.2:
- // return new SaxonXQExpressionContext(expression);
- }
-
- /*@NotNull*/ public XQSequenceType getStaticResultType() throws XQException {
- checkNotClosed();
- Expression exp = expression.getExpression(); // unwrap two layers!
- ItemType itemType = exp.getItemType(connection.getConfiguration().getTypeHierarchy());
- int cardinality = exp.getCardinality();
- SequenceType staticType = SequenceType.makeSequenceType(itemType, cardinality);
- return new SaxonXQSequenceType(staticType, connection.getConfiguration());
- }
-
- /*@NotNull*/ public XQSequenceType getStaticVariableType(QName name) throws XQException {
- checkNotClosed();
- checkNotNull(name);
- StructuredQName qn = new StructuredQName(
- name.getPrefix(), name.getNamespaceURI(), name.getLocalPart());
- HashMap vars = expression.getExecutable().getCompiledGlobalVariables();
- GlobalVariable var = (vars == null ? null : (GlobalVariable)vars.get(qn));
- if (var == null) {
- throw new XQException("Variable " + name + " is not declared");
- }
- return new SaxonXQSequenceType(var.getRequiredType(), connection.getConfiguration());
- }
-
-
- protected boolean externalVariableExists(QName name) {
- StructuredQName qn = new StructuredQName(
- name.getPrefix(), name.getNamespaceURI(), name.getLocalPart());
- HashMap vars = expression.getExecutable().getCompiledGlobalVariables();
- GlobalVariable var = (vars == null ? null : (GlobalVariable)vars.get(qn));
- return var != null && var instanceof GlobalParam;
- }
-
- private void checkNotNull(/*@Nullable*/ Object arg) throws XQException {
- if (arg == null) {
- throw new XQException("Argument is null");
- }
- }
-
-}
\ No newline at end of file
diff --git a/sf/saxon/xqj/SaxonXQSequence.java b/sf/saxon/xqj/SaxonXQSequence.java
deleted file mode 100644
index fc8851c..0000000
--- a/sf/saxon/xqj/SaxonXQSequence.java
+++ /dev/null
@@ -1,426 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.Configuration;
-import net.sf.saxon.event.PipelineConfiguration;
-import net.sf.saxon.evpull.*;
-import net.sf.saxon.expr.TailIterator;
-import net.sf.saxon.om.GroundedValue;
-import net.sf.saxon.om.Item;
-import net.sf.saxon.om.SequenceIterator;
-import net.sf.saxon.query.QueryResult;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.tree.iter.EmptyIterator;
-import org.w3c.dom.Node;
-import org.xml.sax.ContentHandler;
-
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Result;
-import javax.xml.transform.sax.SAXResult;
-import javax.xml.xquery.*;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.net.URI;
-import java.util.Properties;
-
-/**
- * Saxon implementation of the XQSequence interface in XQJ, which represents an XDM sequence together
- * with a current position. This class is used for a sequence that can be read forwards, backwards,
- * or by absolute position.
- */
-public class SaxonXQSequence extends Closable implements XQResultSequence, SaxonXQItemAccessor {
-
- private GroundedValue value;
- private int position;
- private SaxonXQPreparedExpression expression;
- private SaxonXQDataFactory factory;
-
- SaxonXQSequence(GroundedValue value, SaxonXQDataFactory factory) {
- this.value = value;
- this.factory = factory;
- setClosableContainer(factory);
- }
-
- SaxonXQSequence(GroundedValue value, /*@NotNull*/ SaxonXQPreparedExpression expression) {
- this.value = value;
- this.expression = expression;
- this.factory = expression.getConnection();
- setClosableContainer(expression);
- }
-
- GroundedValue getValue() {
- return value;
- }
-
- Configuration getConfiguration() {
- return factory.getConfiguration();
- }
-
- public boolean absolute(int itempos) throws XQException {
- checkNotClosed();
- if (itempos > 0) {
- if (itempos <= value.getLength()) {
- position = itempos;
- return true;
- } else {
- position = -1;
- return false;
- }
- } else if (itempos < 0) {
- if (-itempos <= value.getLength()) {
- position = value.getLength() + itempos + 1;
- return true;
- } else {
- position = 0;
- return false;
- }
- } else {
- position = 0;
- return false;
- }
- }
-
- public void afterLast() throws XQException {
- checkNotClosed();
- position = -1;
- }
-
- public void beforeFirst() throws XQException {
- checkNotClosed();
- position = 0;
- }
-
- public int count() throws XQException {
- checkNotClosed();
- return value.getLength();
- }
-
- public boolean first() throws XQException {
- checkNotClosed();
- if (value.getLength() == 0) {
- position = 0;
- return false;
- } else {
- position = 1;
- return true;
- }
- }
-
- /*@Nullable*/ public XQItem getItem() throws XQException {
- checkNotClosed();
- SaxonXQItem item = new SaxonXQItem(value.itemAt(position - 1), factory);
- item.setClosableContainer(this);
- return item;
- }
-
- /*@Nullable*/ public Item getSaxonItem() throws XQException {
- return value.itemAt(position - 1);
- }
-
- public int getPosition() throws XQException {
- checkNotClosed();
- if (position >= 0) {
- return position;
- } else {
- return value.getLength() + 1;
- }
- }
-
- /*@NotNull*/ public XMLStreamReader getSequenceAsStream() throws XQException {
- checkNotClosed();
- EventIterator ei = new EventIteratorOverSequence(iterateRemainder());
- ei = new BracketedDocumentIterator(ei);
- Configuration config = getConfiguration();
- PipelineConfiguration pipe = config.makePipelineConfiguration();
- pipe.setHostLanguage(Configuration.XQUERY);
- ei = new Decomposer(ei, pipe);
- return new EventToStaxBridge(ei, pipe);
- }
-
- public String getSequenceAsString(Properties props) throws XQException {
- checkNotClosed();
- StringWriter sw = new StringWriter();
- writeSequence(sw, props);
- return sw.toString();
- }
-
- public boolean isAfterLast() throws XQException {
- checkNotClosed();
- return position < 0;
- }
-
- public boolean isBeforeFirst() throws XQException {
- checkNotClosed();
- return position == 0 && value.getLength() != 0;
- }
-
- public boolean isFirst() throws XQException {
- checkNotClosed();
- return position == 1;
- }
-
- public boolean isLast() throws XQException {
- checkNotClosed();
- return position == value.getLength();
- }
-
- public boolean isOnItem() throws XQException {
- checkNotClosed();
- return position >= 1;
- }
-
- public boolean isScrollable() throws XQException {
- checkNotClosed();
- return true;
- }
-
- public boolean last() throws XQException {
- checkNotClosed();
- int n = value.getLength();
- if (n == 0) {
- position = -1;
- return false;
- } else {
- position = n;
- return true;
- }
- }
-
- public boolean next() throws XQException {
- checkNotClosed();
- if (position == value.getLength()) {
- position = -1;
- return false;
- } else {
- position++;
- return true;
- }
- }
-
- public boolean previous() throws XQException {
- checkNotClosed();
- if (position == -1) {
- return last();
- }
- position--;
- return (position != 0);
- }
-
- public boolean relative(int itempos) throws XQException {
- checkNotClosed();
- if (position == -1) {
- position = value.getLength() + 1;
- }
- position += itempos;
- if (position <= 0) {
- position = 0;
- return false;
- }
- if (position > value.getLength()) {
- position = -1;
- return false;
- }
- return true;
- }
-
- public void writeSequence(OutputStream os, /*@Nullable*/ Properties props) throws XQException {
- checkNotClosed();
- checkNotNull(os);
- if (props == null) {
- props = new Properties();
- }
- props = SaxonXQSequence.setDefaultProperties(props);
- try {
- QueryResult.serializeSequence(iterateRemainder(), getConfiguration(), os, props);
- position = -1;
- } catch (XPathException e) {
- throw newXQException(e);
- }
- }
-
- public void writeSequence(Writer ow, /*@Nullable*/ Properties props) throws XQException {
- checkNotClosed();
- checkNotNull(ow);
- if (props == null) {
- props = new Properties();
- }
- props = setDefaultProperties(props);
- try {
- PrintWriter pw;
- if (ow instanceof PrintWriter) {
- pw = (PrintWriter)ow;
- } else {
- pw = new PrintWriter(ow);
- }
- QueryResult.serializeSequence(iterateRemainder(), getConfiguration(), pw, props);
- position = -1;
- } catch (XPathException e) {
- throw newXQException(e);
- }
- }
-
- public void writeSequenceToResult(Result result) throws XQException {
- checkNotClosed();
- Properties props = SaxonXQSequence.setDefaultProperties(null);
- try {
- QueryResult.serializeSequence(iterateRemainder(), getConfiguration(), result, props);
- } catch (XPathException e) {
- throw newXQException(e);
- }
- }
-
- public void writeSequenceToSAX(ContentHandler saxHandler) throws XQException {
- checkNotClosed();
- writeSequenceToResult(new SAXResult(saxHandler));
- }
-
- public String getAtomicValue() throws XQException {
- return getCurrentItem().getAtomicValue();
- }
-
- public boolean getBoolean() throws XQException {
- return getCurrentItem().getBoolean();
- }
-
- public byte getByte() throws XQException {
- return getCurrentItem().getByte();
- }
-
- public double getDouble() throws XQException {
- return getCurrentItem().getDouble();
- }
-
- public float getFloat() throws XQException {
- return getCurrentItem().getFloat();
- }
-
- public int getInt() throws XQException {
- return getCurrentItem().getInt();
- }
-
- /*@NotNull*/ public XMLStreamReader getItemAsStream() throws XQException {
- return getCurrentItem().getItemAsStream();
- }
-
- public String getItemAsString(Properties props) throws XQException {
- return getCurrentItem().getItemAsString(props);
- }
-
- /*@NotNull*/ public XQItemType getItemType() throws XQException {
- return getCurrentItem().getItemType();
- }
-
- public long getLong() throws XQException {
- return getCurrentItem().getLong();
- }
-
- public Node getNode() throws XQException {
- return getCurrentItem().getNode();
- }
-
- /*@NotNull*/ public URI getNodeUri() throws XQException {
- return getCurrentItem().getNodeUri();
- }
-
- public Object getObject() throws XQException {
- return getCurrentItem().getObject();
- }
-
- public short getShort() throws XQException {
- return getCurrentItem().getShort();
- }
-
- public boolean instanceOf(/*@NotNull*/ XQItemType type) throws XQException {
- return getCurrentItem().instanceOf(type);
- }
-
- public void writeItem(OutputStream os, Properties props) throws XQException {
- getCurrentItem().writeItem(os, props);
- }
-
- public void writeItem(Writer ow, Properties props) throws XQException {
- getCurrentItem().writeItem(ow, props);
- }
-
- public void writeItemToResult(Result result) throws XQException {
- getCurrentItem().writeItemToResult(result);
- }
-
- public void writeItemToSAX(ContentHandler saxHandler) throws XQException {
- getCurrentItem().writeItemToSAX(saxHandler);
- }
-
- /*@Nullable*/ private SaxonXQItem getCurrentItem() throws XQException {
- checkNotClosed();
- if (position == 0) {
- throw new XQException("Sequence is positioned before first item");
- }
- if (position < 0) {
- throw new XQException("Sequence is positioned after last item");
- }
- SaxonXQItem item = new SaxonXQItem(value.itemAt(position-1), factory);
- item.setClosableContainer(this);
- return item;
- }
-
- public XQConnection getConnection() throws XQException {
- checkNotClosed();
- if (expression == null) {
- throw new IllegalStateException("Connection not available");
- }
- return expression.getConnection();
- }
-
- /*@Nullable*/ private SequenceIterator iterateRemainder() throws XQException {
- try {
- if (position == 0) {
- return value.iterate();
- } else if (position < 0) {
- return EmptyIterator.getInstance();
- } else {
- return TailIterator.make(value.iterate(), position);
- }
- } catch (XPathException e) {
- throw newXQException(e);
- }
- }
-
- private void checkNotNull(/*@Nullable*/ Object arg) throws XQException {
- if (arg == null) {
- throw new XQException("Argument is null");
- }
- }
-
- /*@NotNull*/ private XQException newXQException(/*@NotNull*/ Exception err) {
- XQException xqe = new XQException(err.getMessage());
- xqe.initCause(err);
- return xqe;
- }
-
- /*@Nullable*/ static Properties setDefaultProperties(/*@Nullable*/ Properties props) {
- Properties newProps = (props == null ? new Properties() : new Properties(props));
- boolean changed = false;
- if (newProps.getProperty(OutputKeys.METHOD) == null) {
- newProps.setProperty(OutputKeys.METHOD, "xml");
- changed = true;
- }
- if (newProps.getProperty(OutputKeys.INDENT) == null) {
- newProps.setProperty(OutputKeys.INDENT, "yes");
- changed = true;
- }
- if (newProps.getProperty(OutputKeys.OMIT_XML_DECLARATION) == null) {
- newProps.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- changed = true;
- }
- return (changed || props == null ? newProps : props);
- }
-}
\ No newline at end of file
diff --git a/sf/saxon/xqj/SaxonXQSequenceType.java b/sf/saxon/xqj/SaxonXQSequenceType.java
deleted file mode 100644
index d732622..0000000
--- a/sf/saxon/xqj/SaxonXQSequenceType.java
+++ /dev/null
@@ -1,71 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.Configuration;
-import net.sf.saxon.expr.StaticProperty;
-import net.sf.saxon.value.SequenceType;
-
-import javax.xml.xquery.XQItemType;
-import javax.xml.xquery.XQSequenceType;
-
-/**
- * Saxon implementation of the XQJ SequenceType interface
- */
-
-
-public class SaxonXQSequenceType implements XQSequenceType {
-
- SequenceType sequenceType;
- Configuration config;
-
- SaxonXQSequenceType(SequenceType sequenceType, Configuration config) {
- this.sequenceType = sequenceType;
- this.config = config;
- }
-
- public int getItemOccurrence() {
- int cardinality = sequenceType.getCardinality();
- switch (cardinality) {
- case StaticProperty.EXACTLY_ONE:
- return XQSequenceType.OCC_EXACTLY_ONE;
- case StaticProperty.ALLOWS_ZERO_OR_ONE:
- return XQSequenceType.OCC_ZERO_OR_ONE;
- case StaticProperty.ALLOWS_ONE_OR_MORE:
- return XQSequenceType.OCC_ONE_OR_MORE;
- case StaticProperty.ALLOWS_ZERO_OR_MORE:
- return XQSequenceType.OCC_ZERO_OR_MORE;
- default:
- return XQSequenceType.OCC_ZERO_OR_MORE;
- }
- }
-
- /*@NotNull*/ public XQItemType getItemType() {
- return new SaxonXQItemType(sequenceType.getPrimaryType(), config);
- }
-
- /*@Nullable*/ public String getString() {
- String s = sequenceType.getPrimaryType().toString();
- switch (sequenceType.getCardinality()) {
- case StaticProperty.EXACTLY_ONE:
- return s;
- case StaticProperty.ALLOWS_ZERO_OR_ONE:
- return s + "?";
- case StaticProperty.ALLOWS_ONE_OR_MORE:
- return s + "+";
- case StaticProperty.ALLOWS_ZERO_OR_MORE:
- return s + "*";
- default:
- return s;
- }
- }
-
- /*@Nullable*/ public String toString() {
- return getString();
- }
-}
\ No newline at end of file
diff --git a/sf/saxon/xqj/SaxonXQStaticContext.java b/sf/saxon/xqj/SaxonXQStaticContext.java
deleted file mode 100644
index 3151617..0000000
--- a/sf/saxon/xqj/SaxonXQStaticContext.java
+++ /dev/null
@@ -1,368 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.Configuration;
-import net.sf.saxon.lib.NamespaceConstant;
-import net.sf.saxon.lib.Validation;
-import net.sf.saxon.query.StaticQueryContext;
-
-import javax.xml.xquery.XQConstants;
-import javax.xml.xquery.XQException;
-import javax.xml.xquery.XQItemType;
-import javax.xml.xquery.XQStaticContext;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * Saxon implementation of the XQJ XQStaticContext interface
- */
-public class SaxonXQStaticContext implements XQStaticContext {
-
- private Configuration config;
- private int bindingMode = XQConstants.BINDING_MODE_IMMEDIATE;
- private int holdability = XQConstants.HOLDTYPE_HOLD_CURSORS_OVER_COMMIT;
- private int scrollability = XQConstants.SCROLLTYPE_FORWARD_ONLY;
- /*@NotNull*/ private Map<String, String> namespaces = new HashMap<String, String>();
- private String baseURI = "";
- boolean preserveBoundarySpace = false;
- boolean constructionModeIsPreserve = false;
- boolean inheritNamespaces = true;
- boolean preserveNamespaces = true;
- boolean emptyLeast = true;
- boolean isOrdered = true;
- /*@Nullable*/ SaxonXQItemType contextItemStaticType = null;
- String defaultCollationName = NamespaceConstant.CODEPOINT_COLLATION_URI;
- String defaultElementNamespace = "";
- String defaultFunctionNamespace = NamespaceConstant.FN;
-
- /**
- * Create a SaxonXQStaticContext object, the Saxon implementation of XQStaticContext in XQJ
- * @param config the Saxon configuration
- */
-
- public SaxonXQStaticContext(Configuration config) {
- this.config = config;
- }
-
- /**
- * Create a SaxonXQStaticContext object as a copy of another SaxonXQStaticContext object
- * @param sc the static context to be copied
- */
-
- public SaxonXQStaticContext(/*@NotNull*/ SaxonXQStaticContext sc) {
- this.config = sc.config;
- this.bindingMode = sc.bindingMode;
- this.holdability = sc.holdability;
- this.scrollability = sc.scrollability;
- this.namespaces = new HashMap<String, String>(sc.namespaces);
- this.baseURI = sc.baseURI;
- this.preserveBoundarySpace = sc.preserveBoundarySpace;
- this.constructionModeIsPreserve = sc.constructionModeIsPreserve;
- this.inheritNamespaces = sc.inheritNamespaces;
- this.preserveNamespaces = sc.preserveNamespaces;
- this.emptyLeast = sc.emptyLeast;
- this.isOrdered = sc.isOrdered;
- this.contextItemStaticType = sc.contextItemStaticType;
- this.defaultCollationName = sc.defaultCollationName;
- this.defaultElementNamespace = sc.defaultElementNamespace;
- this.defaultFunctionNamespace = sc.defaultFunctionNamespace;
- }
-
- /**
- * Get a new Saxon StaticQueryContext object holding the information held in this
- * XQStaticContext
- * @return a newly constructed StaticQueryContext object
- */
-
- /*@NotNull*/ protected StaticQueryContext getSaxonStaticQueryContext() {
- StaticQueryContext sqc = config.newStaticQueryContext();
- sqc.setSchemaAware(config.isLicensedFeature(Configuration.LicenseFeature.SCHEMA_VALIDATION));
- sqc.setBaseURI(baseURI);
- sqc.setConstructionMode(constructionModeIsPreserve ? Validation.PRESERVE : Validation.STRIP);
- sqc.setDefaultElementNamespace(defaultElementNamespace);
- sqc.setDefaultFunctionNamespace(defaultFunctionNamespace);
- sqc.setEmptyLeast(emptyLeast);
- sqc.setInheritNamespaces(inheritNamespaces);
- sqc.setPreserveBoundarySpace(preserveBoundarySpace);
- sqc.setPreserveNamespaces(preserveNamespaces);
- if (contextItemStaticType != null) {
- sqc.setRequiredContextItemType(contextItemStaticType.getSaxonItemType());
- }
- for (Map.Entry<String, String> e : namespaces.entrySet()) {
- sqc.declareNamespace(e.getKey(), e.getValue());
- }
- return sqc;
- }
-
-
- public void declareNamespace(String prefix, String uri) throws XQException {
- checkNotNull(prefix);
- checkNotNull(uri);
- if (uri.length() == 0) {
- namespaces.remove(prefix);
- } else {
- namespaces.put(prefix, uri);
- }
- }
-
- public String getBaseURI() {
- return baseURI;
- }
-
-
- public int getBindingMode() {
- return bindingMode;
- }
-
- public int getBoundarySpacePolicy() {
- return preserveBoundarySpace
- ? XQConstants.BOUNDARY_SPACE_PRESERVE
- : XQConstants.BOUNDARY_SPACE_STRIP;
- }
-
- public int getConstructionMode() {
- return constructionModeIsPreserve
- ? XQConstants.CONSTRUCTION_MODE_PRESERVE
- : XQConstants.CONSTRUCTION_MODE_STRIP;
- }
-
-
- /*@Nullable*/ public XQItemType getContextItemStaticType() {
- return contextItemStaticType;
- }
-
- public int getCopyNamespacesModeInherit() {
- return inheritNamespaces ?
- XQConstants.COPY_NAMESPACES_MODE_INHERIT :
- XQConstants.COPY_NAMESPACES_MODE_NO_INHERIT;
- }
-
- public int getCopyNamespacesModePreserve() {
- return preserveNamespaces ?
- XQConstants.COPY_NAMESPACES_MODE_PRESERVE :
- XQConstants.COPY_NAMESPACES_MODE_NO_PRESERVE;
- }
-
- public String getDefaultCollation() {
- return defaultCollationName;
- }
-
- public String getDefaultElementTypeNamespace() {
- return defaultElementNamespace;
- }
-
- public String getDefaultFunctionNamespace() {
- return defaultFunctionNamespace;
- }
-
- public int getDefaultOrderForEmptySequences() {
- return emptyLeast ?
- XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST :
- XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_GREATEST;
- }
-
- /*@NotNull*/ public String[] getNamespacePrefixes() {
- String[] result = new String[namespaces.size()];
- Iterator iter = namespaces.keySet().iterator();
- for (int i=0; i<result.length; i++) {
- iter.hasNext();
- result[i] = (String)iter.next();
- }
- return result;
- }
-
- public String getNamespaceURI(String prefix) throws XQException {
- checkNotNull(prefix);
- String uri = namespaces.get(prefix);
- if (uri == null) {
- throw new XQException("Unknown prefix");
- }
- return uri;
- }
-
- public int getOrderingMode() {
- return isOrdered
- ? XQConstants.ORDERING_MODE_ORDERED
- : XQConstants.ORDERING_MODE_UNORDERED;
- }
-
- public int getHoldability() {
- return holdability;
- }
-
- public int getQueryLanguageTypeAndVersion() {
- return XQConstants.LANGTYPE_XQUERY;
- }
-
- public int getQueryTimeout() {
- return 0;
- }
-
- public int getScrollability() {
- return scrollability;
- }
-
-
- public void setBaseURI(String baseUri) throws XQException {
- checkNotNull(baseUri);
- this.baseURI = baseUri;
- }
-
- public void setBindingMode(int bindingMode) throws XQException {
- switch (bindingMode) {
- case XQConstants.BINDING_MODE_IMMEDIATE:
- case XQConstants.BINDING_MODE_DEFERRED:
- this.bindingMode = bindingMode;
- break;
- default:
- throw new XQException("Invalid value for binding mode - " + bindingMode);
- }
- }
-
- public void setBoundarySpacePolicy(int policy) throws XQException {
- switch (policy) {
- case XQConstants.BOUNDARY_SPACE_PRESERVE:
- preserveBoundarySpace = true;
- break;
- case XQConstants.BOUNDARY_SPACE_STRIP:
- preserveBoundarySpace = false;
- break;
- default:
- throw new XQException("Invalid value for boundary space policy - " + policy);
- }
- }
-
- public void setConstructionMode(int mode) throws XQException {
- switch (mode) {
- case XQConstants.CONSTRUCTION_MODE_PRESERVE:
- constructionModeIsPreserve = true;
- break;
- case XQConstants.CONSTRUCTION_MODE_STRIP:
- constructionModeIsPreserve = false;
- break;
- default:
- throw new XQException("Invalid value for construction mode - " + mode);
- }
- }
-
- public void setContextItemStaticType(/*@Nullable*/ XQItemType contextItemType) {
- this.contextItemStaticType = (SaxonXQItemType)contextItemType;
- }
-
- public void setCopyNamespacesModeInherit(int mode) throws XQException {
- switch (mode) {
- case XQConstants.COPY_NAMESPACES_MODE_INHERIT:
- inheritNamespaces = true;
- break;
- case XQConstants.COPY_NAMESPACES_MODE_NO_INHERIT:
- inheritNamespaces = false;
- break;
- default:
- throw new XQException("Invalid value for namespaces inherit mode - " + mode);
- }
- }
-
- public void setCopyNamespacesModePreserve(int mode) throws XQException {
- switch (mode) {
- case XQConstants.COPY_NAMESPACES_MODE_PRESERVE:
- preserveNamespaces = true;
- break;
- case XQConstants.COPY_NAMESPACES_MODE_NO_PRESERVE:
- preserveNamespaces = false;
- break;
- default:
- throw new XQException("Invalid value for namespaces preserve mode - " + mode);
- }
- }
-
- public void setDefaultCollation(String uri) throws XQException {
- checkNotNull(uri);
- defaultCollationName = uri;
- }
-
- public void setDefaultElementTypeNamespace(String uri) throws XQException {
- checkNotNull(uri);
- defaultElementNamespace = uri;
- }
-
- public void setDefaultFunctionNamespace(String uri) throws XQException {
- checkNotNull(uri);
- defaultFunctionNamespace = uri;
- }
-
- public void setDefaultOrderForEmptySequences(int order) throws XQException {
- switch (order) {
- case XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_GREATEST:
- emptyLeast = false;
- break;
- case XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST:
- emptyLeast = true;
- break;
- default:
- throw new XQException("Invalid value for default order for empty sequences - " + order);
- }
- }
-
- public void setOrderingMode(int mode) throws XQException {
- switch (mode) {
- case XQConstants.ORDERING_MODE_ORDERED:
- isOrdered = true;
- break;
- case XQConstants.ORDERING_MODE_UNORDERED:
- isOrdered = false;
- break;
- default:
- throw new XQException("Invalid ordering mode - " + mode);
- }
- }
-
- public void setQueryTimeout(int seconds) throws XQException {
- if (seconds < 0) {
- throw new XQException("Query timeout must not be negative");
- }
- // no-op
- }
-
- public void setHoldability(int holdability) throws XQException {
- switch (holdability) {
- case XQConstants.HOLDTYPE_HOLD_CURSORS_OVER_COMMIT:
- case XQConstants.HOLDTYPE_CLOSE_CURSORS_AT_COMMIT:
- this.holdability = holdability;
- break;
- default:
- throw new XQException("Invalid holdability value - " + holdability);
- }
- }
-
- public void setQueryLanguageTypeAndVersion(int langtype) throws XQException {
- if (langtype != XQConstants.LANGTYPE_XQUERY) {
- throw new XQException("XQueryX is not supported");
- }
- }
-
- public void setScrollability(int scrollability) throws XQException {
- switch (scrollability) {
- case XQConstants.SCROLLTYPE_FORWARD_ONLY:
- case XQConstants.SCROLLTYPE_SCROLLABLE:
- this.scrollability = scrollability;
- break;
- default:
- throw new XQException("Invalid scrollability value - " + scrollability);
- }
- }
-
- protected void checkNotNull(/*@Nullable*/ Object arg) throws XQException {
- if (arg == null) {
- throw new XQException("Argument is null");
- }
- }
-
-}
-
diff --git a/sf/saxon/xqj/StandardObjectConverter.java b/sf/saxon/xqj/StandardObjectConverter.java
deleted file mode 100644
index 29912b6..0000000
--- a/sf/saxon/xqj/StandardObjectConverter.java
+++ /dev/null
@@ -1,284 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2013 Saxonica Limited.
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-package net.sf.saxon.xqj;
-
-import net.sf.saxon.Configuration;
-import net.sf.saxon.dom.DOMObjectModel;
-import net.sf.saxon.dom.NodeOverNodeInfo;
-import net.sf.saxon.event.Builder;
-import net.sf.saxon.event.PipelineConfiguration;
-import net.sf.saxon.event.Sender;
-import net.sf.saxon.evpull.PullEventSource;
-import net.sf.saxon.evpull.StaxToEventBridge;
-import net.sf.saxon.expr.EarlyEvaluationContext;
-import net.sf.saxon.expr.JPConverter;
-import net.sf.saxon.om.Item;
-import net.sf.saxon.om.NodeInfo;
-import net.sf.saxon.om.SequenceTool;
-import net.sf.saxon.om.StandardNames;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.tree.tiny.TinyBuilder;
-import net.sf.saxon.type.AtomicType;
-import net.sf.saxon.type.BuiltInAtomicType;
-import net.sf.saxon.type.ExternalObjectType;
-import net.sf.saxon.value.*;
-import net.sf.saxon.value.StringValue;
-import org.w3c.dom.Node;
-
-import javax.xml.datatype.DatatypeConstants;
-import javax.xml.datatype.Duration;
-import javax.xml.datatype.XMLGregorianCalendar;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.Source;
-import javax.xml.xquery.XQException;
-import javax.xml.xquery.XQItemAccessor;
-import javax.xml.xquery.XQItemType;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-/**
- * This class provides all the conversion methods used to convert data between XDM values
- * and Java values in the XQJ API. At one time the XQJ specification defined such a class,
- * and it has been retained in the Saxon implementation.
- * <p>
- * This handler implements the mappings defined in the XQJ specification. In addition,
- * it defines the following mappings, which are applied after those defined in XQJ:</p>
- *
- * <p>For fromObject:</p>
- * <ul>
- * <li>If the supplied object is an instance of javax.xml.transform.Source, a document
- * node is constructed from the source and the resulting node is returned as the Item</li>
- * <li>If the supplied object is an instance of javax.xml.stream.XMLStreamReader, a document
- * node is constructed from the XMLStreamReader and the resulting node is returned as the Item</li>
- * <li>If the supplied object is
- * </ul>
- */
-public class StandardObjectConverter implements ObjectConverter {
-
- Configuration config;
-
- /**
- * CreateCharacter an instance of the class
- * @param factory the factory object
- */
-
- public StandardObjectConverter(/*@NotNull*/ SaxonXQDataFactory factory) {
- config = factory.getConfiguration();
- }
-
- //@SuppressWarnings({"ConstantConditions"})
- /*@Nullable*/ public Object toObject(/*@NotNull*/ XQItemAccessor xqItemAccessor) throws XQException {
- Item item = ((SaxonXQItemAccessor)xqItemAccessor).getSaxonItem();
- if (item instanceof AtomicValue) {
- AtomicValue p = ((AtomicValue)item);
- int t = p.getItemType().getPrimitiveType();
- switch (t) {
- case StandardNames.XS_ANY_URI:
- return p.getStringValue();
- case StandardNames.XS_BASE64_BINARY:
- return ((Base64BinaryValue)p).getBinaryValue();
- case StandardNames.XS_BOOLEAN:
- return Boolean.valueOf(((BooleanValue)p).getBooleanValue());
- case StandardNames.XS_DATE:
- return new SaxonXMLGregorianCalendar((CalendarValue)p);
- case StandardNames.XS_DATE_TIME:
- return new SaxonXMLGregorianCalendar((CalendarValue)p);
- case StandardNames.XS_DECIMAL:
- return ((DecimalValue)p).getDecimalValue();
- case StandardNames.XS_DOUBLE:
- return new Double(((DoubleValue)p).getDoubleValue());
- case StandardNames.XS_DURATION:
- return new SaxonDuration((DurationValue)p);
- case StandardNames.XS_FLOAT:
- return new Float(((FloatValue)p).getFloatValue());
- case StandardNames.XS_G_DAY:
- case StandardNames.XS_G_MONTH:
- case StandardNames.XS_G_MONTH_DAY:
- case StandardNames.XS_G_YEAR:
- case StandardNames.XS_G_YEAR_MONTH:
- return new SaxonXMLGregorianCalendar((CalendarValue)p);
- case StandardNames.XS_HEX_BINARY:
- return ((HexBinaryValue)p).getBinaryValue();
- case StandardNames.XS_INTEGER:
- if (p instanceof BigIntegerValue) {
- return ((BigIntegerValue)p).asBigInteger();
- } else {
- int sub = ((AtomicType)p.getItemType()).getFingerprint();
- switch (sub) {
- case StandardNames.XS_INTEGER:
- case StandardNames.XS_NEGATIVE_INTEGER:
- case StandardNames.XS_NON_NEGATIVE_INTEGER:
- case StandardNames.XS_NON_POSITIVE_INTEGER:
- case StandardNames.XS_POSITIVE_INTEGER:
- case StandardNames.XS_UNSIGNED_LONG:
- return BigInteger.valueOf(((Int64Value)p).longValue());
- case StandardNames.XS_BYTE:
- return Byte.valueOf((byte)((Int64Value)p).longValue());
- case StandardNames.XS_INT:
- case StandardNames.XS_UNSIGNED_SHORT:
- return Integer.valueOf((int)((Int64Value)p).longValue());
- case StandardNames.XS_LONG:
- case StandardNames.XS_UNSIGNED_INT:
- return Long.valueOf(((Int64Value)p).longValue());
- case StandardNames.XS_SHORT:
- case StandardNames.XS_UNSIGNED_BYTE:
- return Short.valueOf((short)((Int64Value)p).longValue());
- default:
- throw new XQException("Unrecognized integer subtype " + sub);
- }
- }
- case StandardNames.XS_QNAME:
- return ((QualifiedNameValue)p).toJaxpQName();
- case StandardNames.XS_STRING:
- case StandardNames.XS_UNTYPED_ATOMIC:
- return p.getStringValue();
- case StandardNames.XS_TIME:
- return new SaxonXMLGregorianCalendar((CalendarValue)p);
- case StandardNames.XS_DAY_TIME_DURATION:
- return new SaxonDuration((DurationValue)p);
- case StandardNames.XS_YEAR_MONTH_DURATION:
- return new SaxonDuration((DurationValue)p);
- default:
- throw new XQException("unsupported type");
- }
- } else {
- return NodeOverNodeInfo.wrap((NodeInfo)item);
- }
- }
-
- /**
- * Convert a Java object to a Saxon Item
- * @param value the Java object. If null is supplied, null is returned.
- * @return the corresponding Item
- * @throws XQException
- */
-
- /*@Nullable*/ public Item convertToItem(/*@NotNull*/ Object value) throws XQException {
- if (value == null) {
- return null;
- }
- try {
- if (value instanceof Boolean) {
- return BooleanValue.get(((Boolean)value).booleanValue());
- } else if (value instanceof byte[]) {
- return new HexBinaryValue((byte[])value);
- } else if (value instanceof Byte) {
- return new Int64Value(((Byte)value).byteValue(), BuiltInAtomicType.BYTE, false);
- } else if (value instanceof Float) {
- return new FloatValue(((Float)value).floatValue());
- } else if (value instanceof Double) {
- return new DoubleValue(((Double)value).doubleValue());
- } else if (value instanceof Integer) {
- return new Int64Value(((Integer)value).intValue(), BuiltInAtomicType.INT, false);
- } else if (value instanceof Long) {
- return new Int64Value(((Long)value).longValue(), BuiltInAtomicType.LONG, false);
- } else if (value instanceof Short) {
- return new Int64Value(((Short)value).shortValue(), BuiltInAtomicType.SHORT, false);
- } else if (value instanceof String) {
- return new StringValue((String)value);
- } else if (value instanceof BigDecimal) {
- return new DecimalValue((BigDecimal)value);
- } else if (value instanceof BigInteger) {
- return new BigIntegerValue((BigInteger)value);
- } else if (value instanceof SaxonDuration) {
- return ((SaxonDuration)value).getDurationValue();
- } else if (value instanceof Duration) {
- // this is simpler and safer (but perhaps slower) than extracting all the components
- return DurationValue.makeDuration(value.toString()).asAtomic();
- } else if (value instanceof SaxonXMLGregorianCalendar) {
- return ((SaxonXMLGregorianCalendar)value).toCalendarValue();
- } else if (value instanceof XMLGregorianCalendar) {
- XMLGregorianCalendar g = (XMLGregorianCalendar)value;
- QName gtype = g.getXMLSchemaType();
- if (gtype.equals(DatatypeConstants.DATETIME)) {
- return DateTimeValue.makeDateTimeValue(value.toString(), config.getConversionRules()).asAtomic();
- } else if (gtype.equals(DatatypeConstants.DATE)) {
- return DateValue.makeDateValue(value.toString(), config.getConversionRules()).asAtomic();
- } else if (gtype.equals(DatatypeConstants.TIME)) {
- return TimeValue.makeTimeValue(value.toString()).asAtomic();
- } else if (gtype.equals(DatatypeConstants.GYEAR)) {
- return GYearValue.makeGYearValue(value.toString(), config.getConversionRules()).asAtomic();
- } else if (gtype.equals(DatatypeConstants.GYEARMONTH)) {
- return GYearMonthValue.makeGYearMonthValue(value.toString(), config.getConversionRules()).asAtomic();
- } else if (gtype.equals(DatatypeConstants.GMONTH)) {
- return GMonthValue.makeGMonthValue(value.toString(), config.getConversionRules()).asAtomic();
- } else if (gtype.equals(DatatypeConstants.GMONTHDAY)) {
- return GMonthDayValue.makeGMonthDayValue(value.toString(), config.getConversionRules()).asAtomic();
- } else if (gtype.equals(DatatypeConstants.GDAY)) {
- return GDayValue.makeGDayValue(value.toString(), config.getConversionRules()).asAtomic();
- } else {
- throw new AssertionError("Unknown Gregorian date type");
- }
- } else if (value instanceof QName) {
- QName q = (QName)value;
- return new QNameValue(q.getPrefix(), q.getNamespaceURI(), q.getLocalPart(),
- BuiltInAtomicType.QNAME, null);
- } else if (value instanceof Node) {
- JPConverter jp = DOMObjectModel.getInstance().getJPConverter(Node.class, config);
- return SequenceTool.asItem(jp.convert(value, new EarlyEvaluationContext(config, null)));
- //return Value.asItem(DOMObjectModel.getInstance().convertObjectToXPathValue(value, config));
- } else if (value instanceof Source) {
- // Saxon extension to the XQJ specification
- PipelineConfiguration pipe = config.makePipelineConfiguration();
- Builder b = new TinyBuilder(pipe);
- Sender.send((Source)value, b, null);
- NodeInfo node = b.getCurrentRoot();
- b.reset();
- return node;
- } else if (value instanceof XMLStreamReader) {
- // Saxon extension to the XQJ specification
- StaxToEventBridge bridge = new StaxToEventBridge();
- bridge.setXMLStreamReader((XMLStreamReader)value);
- PipelineConfiguration pipe = config.makePipelineConfiguration();
- bridge.setPipelineConfiguration(pipe);
- Builder b = new TinyBuilder(pipe);
- Sender.send(new PullEventSource(bridge), b, null);
- NodeInfo node = b.getCurrentRoot();
- b.reset();
- return node;
- } else {
- throw new XPathException("Java object cannot be converted to an XQuery value");
- }
- } catch (XPathException e) {
- XQException xqe = new XQException(e.getMessage());
- xqe.initCause(e);
- throw xqe;
- }
- }
-
- /**
- * Convert a Java object to an Item, when a required type has been specified. Note that Saxon only calls
- * this method when none of the standard conversions defined in the XQJ specification is able to handle
- * the object.
- * @param value the supplied Java object. If null is supplied, null is returned.
- * @param type the required XPath data type
- * @return the Item that results from the conversion
- * @throws XQException if the Java object cannot be converted to an XQItem
- */
-
- /*@Nullable*/ public Item convertToItem(Object value, /*@NotNull*/ XQItemType type) throws XQException {
- if (value == null) {
- return null;
- }
- if (((SaxonXQItemType)type).getSaxonItemType() instanceof ExternalObjectType) {
- Item result = new ObjectValue(value);
- if (((SaxonXQItemType)type).getSaxonItemType().matches(result, null)) {
- return result;
- } else {
- throw new XQException("The result of wrapping an object of class " + value.getClass().getName() +
- " does not match the required type " + type.toString());
- }
- } else {
- throw new XQException("Supplied Java object cannot be converted to an XQItem");
- }
- }
-
-
-
-}
\ No newline at end of file
diff --git a/sf/saxon/xqj/package.html b/sf/saxon/xqj/package.html
deleted file mode 100644
index 8a638c6..0000000
--- a/sf/saxon/xqj/package.html
+++ /dev/null
@@ -1,38 +0,0 @@
-<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
-<!-- Copyright (c) 2013 Saxonica Limited. -->
-<!-- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -->
-<!-- If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
-<!-- This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. -->
-<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
-
-<html>
-<head>
-<title>Package overview: net.sf.saxon.xqj</title>
-
-</head>
- <body>
- <p>This package contains an implementation of the XQJ specification
- defined in JSR 225. This API is not yet part of the Java Standard Edition platform, but it
- is widely supported by a variety of Java-based XQuery engines.</p>
-
- <p>Saxon's implementation of the {@link javax.xml.xquery.XQDataSource} class is
- {@link net.sf.saxon.xqj.SaxonXQDataSource}. Generally, this is the only class
- that applications need to access directly (all other access can be done by using
- standard XQJ interfaces). However, if there is a need to mix XQuery access with other
- Saxon functionality such as schema processing, then it is often useful to cast the
- XQJ objects to their underlying Saxon implementation classes, which make additional
- methods available.</p>
-
- <p>In general it is not possible to mix Saxon implementation classes of the XQJ interface
- with implementation classes from other vendors. That is, if an interface specifies that
- a value of an XQJ type must be passed as an argument, Saxon in general requires the value
- to belong to a Saxon implementation of that interface.</p>
-
- <p align="center"><i>Michael H. Kay<br/>
-Saxonica Limited<br/>
-30 July 2010</i></p>
-
- </body>
-</html>
-
-
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/saxonhe.git
More information about the pkg-java-commits
mailing list