[334842] [xpath2] improving support for the data types Name, NCName, ENTITY, ID, IDREF and NMTOKEN
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 2054d39..412d641 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
@@ -26,6 +26,8 @@
  *     Jesper Moller - bug 297707 - Missing the empty-sequence() type
  *     Mukul Gandhi - bug 309585 - implementation of xs:normalizedString data type
  *     Mukul Gandhi - bug 334478 - implementation of xs:token data type
+ *     Mukul Gandhi - bug 334842 - improving support for the data types Name, NCName, ENTITY, 
+ *                                 ID, IDREF and NMTOKEN. 
  *******************************************************************************/
 
 package org.eclipse.wst.xml.xpath2.processor.function;
@@ -52,6 +54,9 @@
 		add_type(new XSString());
 		add_type(new XSNormalizedString());
 		add_type(new XSToken());
+		add_type(new XSName());
+		add_type(new XSNCName());
+		add_type(new XSNMTOKEN());
 		add_type(new XSBoolean());
 		add_type(new XSUntypedAtomic());
 		add_type(new XSNotation());
@@ -94,7 +99,6 @@
 		add_type(new XSGDay());
 
 		add_type(new QName());
-		add_type(new XSNCName());
 		add_type(new XSAnyURI());
 		add_type(new XSYearMonthDuration());
 		add_type(new XSDayTimeDuration());
diff --git a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSEntity.java b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSEntity.java
index 8318dfe..d91841b 100644
--- a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSEntity.java
+++ b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSEntity.java
@@ -7,7 +7,8 @@
  *
  * Contributors:
  *     David Carver (STAR) bug 228223 - initial API and implementation
- *     Mukul Gandhi - bug 280798 - PsychoPath support for JDK 1.4
+ *     Mukul Gandhi - bug 334842 - improving support for the data types Name, NCName, ENTITY, 
+ *                                 ID, IDREF and NMTOKEN.
  *******************************************************************************/
 
 package org.eclipse.wst.xml.xpath2.processor.internal.types;
@@ -61,9 +62,14 @@
 			return rs;
 
 		AnyAtomicType aat = (AnyAtomicType) arg.first();
+		String strValue = aat.string_value();
 		
+		if (!isConstraintSatisfied(strValue)) {
+			// invalid input
+			DynamicError.throw_type_error();
+		}
 
-		rs.add(new XSEntity(aat.string_value()));
+		rs.add(new XSEntity(strValue));
 
 		return rs;
 
diff --git a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSID.java b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSID.java
index a344ab7..94f802e 100644
--- a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSID.java
+++ b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSID.java
@@ -7,7 +7,8 @@
  *
  * Contributors:
  *     David Carver (STAR) bug 228223 - initial API and implementation
- *     Mukul Gandhi - bug 280798 - PsychoPath support for JDK 1.4
+ *     Mukul Gandhi - bug 334842 - improving support for the data types Name, NCName, ENTITY, 
+ *                                 ID, IDREF and NMTOKEN.
  *******************************************************************************/
 package org.eclipse.wst.xml.xpath2.processor.internal.types;
 
@@ -47,8 +48,14 @@
 			return rs;
 
 		AnyAtomicType aat = (AnyAtomicType) arg.first();
+		String strValue = aat.string_value();
+		
+		if (!isConstraintSatisfied(strValue)) {
+			// invalid input
+			DynamicError.throw_type_error();
+		}
 
-		rs.add(new XSID(aat.string_value()));
+		rs.add(new XSID(strValue));
 
 		return rs;
 	}
diff --git a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSIDREF.java b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSIDREF.java
index a8560ca..cb8e3a3 100644
--- a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSIDREF.java
+++ b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSIDREF.java
@@ -7,7 +7,8 @@
  *
  * Contributors:
  *     David Carver (STAR) bug 228223 - initial API and implementation
- *     Mukul Gandhi - bug 280798 - PsychoPath support for JDK 1.4
+ *     Mukul Gandhi - bug 334842 - improving support for the data types Name, NCName, ENTITY, 
+ *                                 ID, IDREF and NMTOKEN.
  *******************************************************************************/
 package org.eclipse.wst.xml.xpath2.processor.internal.types;
 
@@ -47,8 +48,14 @@
 			return rs;
 
 		AnyAtomicType aat = (AnyAtomicType) arg.first();
+		String strValue = aat.string_value();
+		
+		if (!isConstraintSatisfied(strValue)) {
+			// invalid input
+			DynamicError.throw_type_error();
+		}
 
-		rs.add(new XSIDREF(aat.string_value()));
+		rs.add(new XSIDREF(strValue));
 
 		return rs;
 	}
diff --git a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSNCName.java b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSNCName.java
index 5a569a6..d0560de 100644
--- a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSNCName.java
+++ b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSNCName.java
@@ -1,17 +1,19 @@
 /*******************************************************************************
- * 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
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0 
- *     Mukul Gandhi - bug 280798 - PsychoPath support for JDK 1.4
+ *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0
+ *     Mukul Gandhi - bug 334842 - improving support for the data types Name, NCName, ENTITY, 
+ *                                 ID, IDREF and NMTOKEN. 
  *******************************************************************************/
 
 package org.eclipse.wst.xml.xpath2.processor.internal.types;
 
+import org.apache.xerces.util.XMLChar;
 import org.eclipse.wst.xml.xpath2.processor.DynamicError;
 import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
 import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
@@ -19,7 +21,7 @@
 /**
  * A representation of the NCName datatype
  */
-public class XSNCName extends XSString {
+public class XSNCName extends XSName {
 	private static final String XS_NC_NAME = "xs:NCName";
 
 	/**
@@ -68,14 +70,35 @@
 	 */
 	public ResultSequence constructor(ResultSequence arg) throws DynamicError {
 		ResultSequence rs = ResultSequenceFactory.create_new();
-
+		
 		if (arg.empty())
 			return rs;
 
 		AnyAtomicType aat = (AnyAtomicType) arg.first();
+		String strValue = aat.string_value();
+		
+		if (!isConstraintSatisfied(strValue)) {
+			// invalid input
+			DynamicError.throw_type_error();
+		}
 
-		rs.add(new XSNCName(aat.string_value()));
+		rs.add(new XSNCName(strValue));
 
 		return rs;
 	}
+	
+	/*
+	 * Check if a string satisfies the constraints of NCName data type.
+	 */
+	protected boolean isConstraintSatisfied(String strValue) {
+		
+		boolean isValidNCName = true;
+		
+		if (!XMLChar.isValidNCName(strValue)) {
+			isValidNCName = false;
+		}
+		
+		return isValidNCName;
+		
+	} // isConstraintSatisfied
 }
diff --git a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSNMTOKEN.java b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSNMTOKEN.java
new file mode 100644
index 0000000..2d57c9b
--- /dev/null
+++ b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSNMTOKEN.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * 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 - initial API and implementation
+ *     Mukul Gandhi - bug 334842 - improving support for the data types Name, NCName, ENTITY, 
+ *                                 ID, IDREF and NMTOKEN. 
+ *******************************************************************************/
+
+package org.eclipse.wst.xml.xpath2.processor.internal.types;
+
+import org.apache.xerces.util.XMLChar;
+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 NMTOKEN datatype
+ */
+public class XSNMTOKEN extends XSToken {
+	private static final String XS_NMTOKEN = "xs:NMTOKEN";
+
+	/**
+	 * Initialises using the supplied String
+	 * 
+	 * @param x
+	 *            String to be stored
+	 */
+	public XSNMTOKEN(String x) {
+		super(x);
+	}
+
+	/**
+	 * Initialises to null
+	 */
+	public XSNMTOKEN() {
+		this(null);
+	}
+
+	/**
+	 * Retrieves the datatype's full pathname
+	 * 
+	 * @return "xs:NMTOKEN" which is the datatype's full pathname
+	 */
+	public String string_type() {
+		return XS_NMTOKEN;
+	}
+
+	/**
+	 * Retrieves the datatype's name
+	 * 
+	 * @return "NMTOKEN" which is the datatype's name
+	 */
+	public String type_name() {
+		return "NMTOKEN";
+	}
+
+	/**
+	 * Creates a new ResultSequence consisting of the extractable NMTOKEN within
+	 * the supplied ResultSequence
+	 * 
+	 * @param arg
+	 *            The ResultSequence from which to extract the NMTOKEN
+	 * @return New ResultSequence consisting of the NMTOKEN supplied
+	 * @throws DynamicError
+	 */
+	public ResultSequence constructor(ResultSequence arg) throws DynamicError {
+		ResultSequence rs = ResultSequenceFactory.create_new();
+
+		if (arg.empty())
+			return rs;
+
+		AnyAtomicType aat = (AnyAtomicType) arg.first();
+		String strValue = aat.string_value();
+		
+		if (!XMLChar.isValidNmtoken(strValue)) {
+			// invalid input
+			DynamicError.throw_type_error();
+		}
+
+		rs.add(new XSNMTOKEN(strValue));
+
+		return rs;
+	}
+}
diff --git a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSName.java b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSName.java
new file mode 100644
index 0000000..1620536
--- /dev/null
+++ b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSName.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * 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 - initial API and implementation
+ *     Mukul Gandhi - bug 334842 - improving support for the data types Name, NCName, ENTITY, 
+ *                                 ID, IDREF and NMTOKEN.
+ *******************************************************************************/
+
+package org.eclipse.wst.xml.xpath2.processor.internal.types;
+
+import org.apache.xerces.util.XMLChar;
+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 Name datatype
+ */
+public class XSName extends XSToken {
+	private static final String XS_NAME = "xs:Name";
+
+	/**
+	 * Initialises using the supplied String
+	 * 
+	 * @param x
+	 *            String to be stored
+	 */
+	public XSName(String x) {
+		super(x);
+	}
+
+	/**
+	 * Initialises to null
+	 */
+	public XSName() {
+		this(null);
+	}
+
+	/**
+	 * Retrieves the datatype's full pathname
+	 * 
+	 * @return "xs:Name" which is the datatype's full pathname
+	 */
+	public String string_type() {
+		return XS_NAME;
+	}
+
+	/**
+	 * Retrieves the datatype's name
+	 * 
+	 * @return "Name" which is the datatype's name
+	 */
+	public String type_name() {
+		return "Name";
+	}
+
+	/**
+	 * Creates a new ResultSequence consisting of the extractable Name within
+	 * the supplied ResultSequence
+	 * 
+	 * @param arg
+	 *            The ResultSequence from which to extract the Name
+	 * @return New ResultSequence consisting of the Name supplied
+	 * @throws DynamicError
+	 */
+	public ResultSequence constructor(ResultSequence arg) throws DynamicError {
+		ResultSequence rs = ResultSequenceFactory.create_new();
+
+		if (arg.empty())
+			return rs;
+
+		AnyAtomicType aat = (AnyAtomicType) arg.first();
+		String strValue = aat.string_value();
+		
+		if (!XMLChar.isValidName(strValue)) {
+			// invalid input
+			DynamicError.throw_type_error();
+		}
+
+		rs.add(new XSName(strValue));
+
+		return rs;
+	}
+}