[334478] [xpath2] implementation of xs:token data type
diff --git a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/function/XSCtrLibrary.java b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/function/XSCtrLibrary.java index d8b74bb..2054d39 100644 --- a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/function/XSCtrLibrary.java +++ b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/function/XSCtrLibrary.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 Andrea Bittau, University College London, and others + * Copyright (c) 2005, 2009 Andrea Bittau, University College London, and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -25,53 +25,13 @@ * David Carver - bug 262765 - implementation of xs:untypedAtomic data type. * Jesper Moller - bug 297707 - Missing the empty-sequence() type * Mukul Gandhi - bug 309585 - implementation of xs:normalizedString data type - * Mukul Gandhi - bug 280798 - PsychoPath support for JDK 1.4 + * Mukul Gandhi - bug 334478 - implementation of xs:token data type *******************************************************************************/ package org.eclipse.wst.xml.xpath2.processor.function; import org.eclipse.wst.xml.xpath2.processor.internal.function.ConstructorFL; -import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType; -import org.eclipse.wst.xml.xpath2.processor.internal.types.QName; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBase64Binary; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSByte; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDate; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSEntity; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSGDay; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSGMonth; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSGMonthDay; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSGYear; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSGYearMonth; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSHexBinary; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSID; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSIDREF; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSInt; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSLong; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSNCName; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSNegativeInteger; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSNonNegativeInteger; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSNonPositiveInteger; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSNormalizedString; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSNotation; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSPositiveInteger; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSShort; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSString; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSUnsignedByte; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSUnsignedInt; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSUnsignedLong; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSUnsignedShort; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic; -import org.eclipse.wst.xml.xpath2.processor.internal.types.XSYearMonthDuration; +import org.eclipse.wst.xml.xpath2.processor.internal.types.*; /** * XML Schema control library support. @@ -91,16 +51,15 @@ // add types here add_type(new XSString()); add_type(new XSNormalizedString()); + add_type(new XSToken()); add_type(new XSBoolean()); add_type(new XSUntypedAtomic()); add_type(new XSNotation()); add_abstract_type("anyAtomicType", new AnyAtomicType() { - public String string_type() { return null; } - public String string_value() { return null; }
diff --git a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSNormalizedString.java b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSNormalizedString.java index 58c45ee..65225a8 100644 --- a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSNormalizedString.java +++ b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSNormalizedString.java
@@ -7,7 +7,7 @@ * * Contributors: * Mukul Gandhi - bug 309585 - implementation of xs:normalizedString data type - * Mukul Gandhi - bug 280798 - PsychoPath support for JDK 1.4 + * Mukul Gandhi - bug 334478 - refactoring code to cater to xs:token data type *******************************************************************************/ package org.eclipse.wst.xml.xpath2.processor.internal.types; @@ -76,12 +76,7 @@ AnyType aat = arg.first(); String srcString = aat.string_value(); - - // the xs:normalizedString value cannot contain, 'carriage return', - // 'line feed' and 'tab' characters. - if ((srcString.indexOf("\r") != -1) || - (srcString.indexOf("\n") != -1) || - (srcString.indexOf("\t") != -1)) { + if (!isSatisfiesConstraints(srcString)) { // invalid input DynamicError.throw_type_error(); } @@ -90,5 +85,22 @@ return rs; } + + /* + * Does the string in context satisfies constraints of the datatype, xs:normalizedString. + */ + protected boolean isSatisfiesConstraints(String srcString) { + + boolean isNormalizedStr = true; + + // the xs:normalizedString value cannot contain, 'carriage return', 'line feed' and 'tab' characters. + if ((srcString.indexOf("\r") != -1) || (srcString.indexOf("\n") != -1) || (srcString.indexOf("\t") != -1)) { + // invalid input + isNormalizedStr = false; + } + + return isNormalizedStr; + + } // isSatisfiesConstraints }
diff --git a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSToken.java b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSToken.java new file mode 100644 index 0000000..c8fa3ed --- /dev/null +++ b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSToken.java
@@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2011 Mukul Gandhi, and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mukul Gandhi - bug 334478 - implementation of xs:token data type + *******************************************************************************/ + +package org.eclipse.wst.xml.xpath2.processor.internal.types; + +import org.eclipse.wst.xml.xpath2.processor.DynamicError; +import org.eclipse.wst.xml.xpath2.processor.ResultSequence; +import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory; + +/** + * A representation of the xs:token datatype + */ +public class XSToken extends XSNormalizedString { + + private static final String XS_TOKEN = "xs:token"; + + /** + * Initialises using the supplied String + * + * @param x + * The String to initialise to + */ + public XSToken(String x) { + super(x); + } + + /** + * Initialises to null + */ + public XSToken() { + this(null); + } + + /** + * Retrieves the datatype's full pathname + * + * @return "xs:token" which is the datatype's full pathname + */ + public String string_type() { + return XS_TOKEN; + } + + /** + * Retrieves the datatype's name + * + * @return "token" which is the datatype's name + */ + public String type_name() { + return "token"; + } + + /** + * Creates a new ResultSequence consisting of the extractable String in the + * supplied ResultSequence + * + * @param arg + * The ResultSequence from which to extract the String + * @return New ResultSequence consisting of the supplied String + * @throws DynamicError + */ + public ResultSequence constructor(ResultSequence arg) throws DynamicError { + ResultSequence rs = ResultSequenceFactory.create_new(); + + if (arg.empty()) + return rs; + + AnyType aat = arg.first(); + + String srcString = aat.string_value(); + if (!isSatisfiesConstraints(srcString)) { + // invalid input + DynamicError.throw_type_error(); + } + + rs.add(new XSToken(srcString)); + + return rs; + } + + /* + * Does the string in context satisfies constraints of the datatype, xs:token. + */ + protected boolean isSatisfiesConstraints(String srcString) { + + boolean isToken = true; + + // satisfies constraints of xs:normalizedString and additionally must satisfy the condition, + // the string must not have leading or trailing spaces and that have no internal sequences of two or more spaces. + if (!super.isSatisfiesConstraints(srcString) || srcString.startsWith(" ") || + srcString.endsWith(" ") || srcString.indexOf(" ") != -1) { + isToken = false; + } + + return isToken; + + } // isSatisfiesConstraints + +}