[xpath2] committing few improvements to data types implementation
diff --git a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/PsychoPathTypeHelper.java b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/PsychoPathTypeHelper.java
index bb6b496..13ba50e 100644
--- a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/PsychoPathTypeHelper.java
+++ b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/PsychoPathTypeHelper.java
@@ -7,9 +7,8 @@
*
* Contributors:
* Mukul Gandhi - initial API and implementation
- * Mukul Gandhi - bug 323900 - improving computing the typed value of element &
- * attribute nodes, where the schema type of nodes
- * are simple, with varieties 'list' and 'union'.
+ * Mukul Gandhi - bug 323900 - improving computing the typed value of element and attribute nodes, where the
+ * schema type of nodes are simple, with varieties 'list' and 'union'.
*******************************************************************************/
package org.eclipse.wst.xml.xpath2.processor;
@@ -18,21 +17,19 @@
import org.apache.xerces.xs.XSTypeDefinition;
/*
- * An PsychoPath helper class providing useful module implementations for
- * commonly performed "XML schema" evaluation tasks.
+ * An PsychoPath Engine helper class providing useful module implementations for commonly
+ * performed "XML schema" evaluation tasks.
*/
public class PsychoPathTypeHelper {
- // PsychoPath engine specific constants to support new built-in types,
- // introduced in XML Schema 1.1.
+ // PsychoPath engine specific constants to support new built-in types, introduced in XML Schema 1.1.
public static short DAYTIMEDURATION_DT = -100;
public static short YEARMONTHDURATION_DT = -101;
/*
- * Get Xerces "schema type" short code, given a type definition instance
- * object. PsychoPath engine uses few custom type 'short codes', to
- * support XML Schema 1.1.
+ * Get Xerces "schema type" short code, given a type definition instance object. PsychoPath engine uses few custom
+ * type 'short codes', to support XML Schema 1.1.
*/
public static short getXSDTypeShortCode(XSTypeDefinition typeDef) {
@@ -46,8 +43,7 @@
typeCode = YEARMONTHDURATION_DT;
}
- return (typeCode != -100) ? typeCode : ((XSSimpleTypeDefinition)
- typeDef).getBuiltInKind();
+ return (typeCode != -100) ? typeCode : ((XSSimpleTypeDefinition) typeDef).getBuiltInKind();
} // getXSDTypeShortCode
diff --git a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/NodeType.java b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/NodeType.java
index afed517..eb38c1e 100644
--- a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/NodeType.java
+++ b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/NodeType.java
@@ -238,19 +238,15 @@
return new XSUntypedAtomic(strValue);
}
- return SchemaTypeValueFactory.newSchemaTypeValue(PsychoPathTypeHelper.
- getXSDTypeShortCode
- (typeDef), strValue);
+ return SchemaTypeValueFactory.newSchemaTypeValue(PsychoPathTypeHelper.getXSDTypeShortCode(typeDef), strValue);
} // getTypedValueForPrimitiveType
/*
- * Construct the "typed value" from a "string value", given the simpleType
- * of the node.
+ * Construct the "typed value" from a "string value", given the simpleType of the node.
*/
- protected ResultSequence getXDMTypedValue(XSTypeDefinition typeDef,
- ShortList itemValTypes) {
+ protected ResultSequence getXDMTypedValue(XSTypeDefinition typeDef, ShortList itemValTypes) {
ResultSequence rs = ResultSequenceFactory.create_new();
@@ -263,23 +259,20 @@
ResultSequence rsSimpleContent = null;
if (typeDef instanceof XSComplexTypeDefinition) {
- XSComplexTypeDefinition complexTypeDefinition =
- (XSComplexTypeDefinition) typeDef;
+ XSComplexTypeDefinition complexTypeDefinition = (XSComplexTypeDefinition) typeDef;
simpType = complexTypeDefinition.getSimpleType();
if (simpType != null) {
- // element has a complexType with a "simple content model"
- rsSimpleContent = getTypedValueForSimpleContent(simpType,
- itemValTypes);
+ // element has a complexType with a simple content
+ rsSimpleContent = getTypedValueForSimpleContent(simpType, itemValTypes);
}
else {
- // element has a complexType with "complex content"
+ // element has a complexType with complex content
rs.add(new XSUntypedAtomic(string_value()));
}
} else {
// element has a simpleType
simpType = (XSSimpleTypeDefinition) typeDef;
- rsSimpleContent = getTypedValueForSimpleContent(simpType,
- itemValTypes);
+ rsSimpleContent = getTypedValueForSimpleContent(simpType, itemValTypes);
}
if (rsSimpleContent != null) {
@@ -295,29 +288,23 @@
/*
* Helper method to construct typed value of an XDM node.
*/
- private ResultSequence getTypedValueForSimpleContent(
- XSSimpleTypeDefinition
- simpType,
- ShortList itemValueTypes) {
+ private ResultSequence getTypedValueForSimpleContent(XSSimpleTypeDefinition simpType, ShortList itemValueTypes) {
ResultSequence rs = ResultSequenceFactory.create_new();
if (simpType.getVariety() == XSSimpleTypeDefinition.VARIETY_ATOMIC) {
- AnyType schemaTypeValue = SchemaTypeValueFactory.newSchemaTypeValue
- (PsychoPathTypeHelper.getXSDTypeShortCode
- (simpType), string_value());
+ AnyType schemaTypeValue = SchemaTypeValueFactory.newSchemaTypeValue(PsychoPathTypeHelper.getXSDTypeShortCode(simpType),
+ string_value());
if (schemaTypeValue != null) {
rs.add(schemaTypeValue);
} else {
rs.add(new XSUntypedAtomic(string_value()));
}
}
- else if (simpType.getVariety() == XSSimpleTypeDefinition.
- VARIETY_LIST) {
+ else if (simpType.getVariety() == XSSimpleTypeDefinition.VARIETY_LIST) {
addAtomicListItemsToResultSet(simpType, itemValueTypes, rs);
}
- else if (simpType.getVariety() == XSSimpleTypeDefinition.
- VARIETY_UNION) {
+ else if (simpType.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
getTypedValueForVarietyUnion(simpType, rs);
}
@@ -327,40 +314,27 @@
/*
- * If the variety of simpleType was 'list', add the typed "list item"
- * values to the parent result set.
+ * If the variety of simpleType was 'list', add the typed "list item" values to the parent result set.
*/
- private void addAtomicListItemsToResultSet(XSSimpleTypeDefinition simpType,
- ShortList itemValueTypes,
- ResultSequence rs) {
+ private void addAtomicListItemsToResultSet(XSSimpleTypeDefinition simpType, ShortList itemValueTypes, ResultSequence rs) {
- // tokenize the string value by a 'longest sequence' of
- // white-spaces. this gives us the list items as string values.
+ // tokenize the string value by a 'longest sequence' of white-spaces. this gives us the list items as string values.
String[] listItemsStrValues = string_value().split("\\s+");
XSSimpleTypeDefinition itemType = simpType.getItemType();
- if (itemType.getVariety() == XSSimpleTypeDefinition.
- VARIETY_ATOMIC) {
- for (int listItemIdx = 0; listItemIdx < listItemsStrValues.
- length; listItemIdx++) {
- // add an atomic typed value (whose type is the "item
- // type" of the list, and "string value" is the "string
+ if (itemType.getVariety() == XSSimpleTypeDefinition.VARIETY_ATOMIC) {
+ for (int listItemIdx = 0; listItemIdx < listItemsStrValues.length; listItemIdx++) {
+ // add an atomic typed value (whose type is the "item type" of the list, and "string value" is the "string
// value of the list item") to the "result sequence".
- rs.add(SchemaTypeValueFactory.newSchemaTypeValue
- (PsychoPathTypeHelper.getXSDTypeShortCode
- (itemType),
- listItemsStrValues[listItemIdx]));
+ rs.add(SchemaTypeValueFactory.newSchemaTypeValue(PsychoPathTypeHelper.getXSDTypeShortCode(itemType),
+ listItemsStrValues[listItemIdx]));
}
}
- else if (itemType.getVariety() == XSSimpleTypeDefinition.
- VARIETY_UNION) {
+ else if (itemType.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
// here the list items may have different atomic types
- for (int listItemIdx = 0; listItemIdx < listItemsStrValues.
- length; listItemIdx++) {
+ for (int listItemIdx = 0; listItemIdx < listItemsStrValues.length; listItemIdx++) {
String listItem = listItemsStrValues[listItemIdx];
- rs.add(SchemaTypeValueFactory.newSchemaTypeValue
- (itemValueTypes.item(listItemIdx),
- listItem));
+ rs.add(SchemaTypeValueFactory.newSchemaTypeValue(itemValueTypes.item(listItemIdx), listItem));
}
}
@@ -368,28 +342,19 @@
/*
- * If the variety of simpleType was 'union', find the typed value (and
- * added to the parent 'result set') to be returned as the typed value
- * of the parent node, by considering the member types of the union (i.e
- * whichever member type first in order, can successfully validate the
- * string value of the parent node).
+ * If the variety of simpleType was 'union', find the typed value (and added to the parent 'result set')
+ * to be returned as the typed value of the parent node, by considering the member types of the union (i.e
+ * whichever member type first in order, can successfully validate the string value of the parent node).
*/
- private void getTypedValueForVarietyUnion(XSSimpleTypeDefinition simpType,
- ResultSequence rs) {
+ private void getTypedValueForVarietyUnion(XSSimpleTypeDefinition simpType, ResultSequence rs) {
XSObjectList memberTypes = simpType.getMemberTypes();
- // check member types in order, to find that which one can
- // successfully validate the string value.
- for (int memTypeIdx = 0; memTypeIdx < memberTypes.getLength();
- memTypeIdx++) {
- XSSimpleType memSimpleType = (XSSimpleType) memberTypes.item
- (memTypeIdx);
+ // check member types in order, to find that which one can successfully validate the string value.
+ for (int memTypeIdx = 0; memTypeIdx < memberTypes.getLength(); memTypeIdx++) {
+ XSSimpleType memSimpleType = (XSSimpleType) memberTypes.item(memTypeIdx);
if (isValueValidForSimpleType(string_value(), memSimpleType)) {
- rs.add(SchemaTypeValueFactory.newSchemaTypeValue
- (PsychoPathTypeHelper.getXSDTypeShortCode
- (memSimpleType),
- string_value()));
+ rs.add(SchemaTypeValueFactory.newSchemaTypeValue(PsychoPathTypeHelper.getXSDTypeShortCode(memSimpleType), string_value()));
// no more memberTypes need to be checked
break;
}
@@ -399,11 +364,9 @@
/*
- * Determine if a "string value" is valid for a given simpleType definition.
- * This is a helped method for other methods.
+ * Determine if a "string value" is valid for a given simpleType definition. This is a helped method for other methods.
*/
- private boolean isValueValidForSimpleType (String value, XSSimpleType
- simplType) {
+ private boolean isValueValidForSimpleType (String value, XSSimpleType simplType) {
boolean isValueValid = true;
diff --git a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/SchemaTypeValueFactory.java b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/SchemaTypeValueFactory.java
index 7e60097..19dba85 100644
--- a/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/SchemaTypeValueFactory.java
+++ b/bundles/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/SchemaTypeValueFactory.java
@@ -7,13 +7,10 @@
*
* Contributors:
* Mukul Gandhi - initial API and implementation
- * Mukul Gandhi - bug 318313 - improvements to computation of typed values
- * of nodes, when validated by XML Schema
+ * Mukul Gandhi - bug 318313 - improvements to computation of typed values of nodes, when validated by XML Schema
* primitive types.
- * Mukul Gandhi - bug 323900 - improving computing the typed value of
- * element & attribute nodes, where the schema
- * type of nodes are simple, with varieties
- * 'list' and 'union'.
+ * Mukul Gandhi - bug 323900 - improving computing the typed value of element and attribute nodes, where the schema
+ * type of nodes are simple, with varieties 'list' and 'union'.
*******************************************************************************/
package org.eclipse.wst.xml.xpath2.processor.internal.types;
@@ -25,8 +22,8 @@
import org.eclipse.wst.xml.xpath2.processor.PsychoPathTypeHelper;
/**
- * A factory class implementation, to construct PsychoPath schema type
- * representation corresponding to XML Schema types.
+ * A factory class implementation, to construct PsychoPath schema type representation corresponding
+ * to XML Schema types.
*/
public class SchemaTypeValueFactory {
@@ -37,8 +34,7 @@
}
if (typeDef == XSConstants.BOOLEAN_DT) {
- return new XSBoolean(Boolean.valueOf(strValue).
- booleanValue());
+ return new XSBoolean(Boolean.valueOf(strValue).booleanValue());
}
if (typeDef == XSConstants.DATE_DT) {
@@ -157,9 +153,43 @@
return QName.parse_QName(strValue);
}
+ // string and it's subtypes
if (typeDef == XSConstants.STRING_DT) {
return new XSString(strValue);
- }
+ }
+
+ if (typeDef == XSConstants.NORMALIZEDSTRING_DT) {
+ return new XSNormalizedString(strValue);
+ }
+
+ if (typeDef == XSConstants.TOKEN_DT) {
+ return new XSToken(strValue);
+ }
+
+ if (typeDef == XSConstants.NAME_DT) {
+ return new XSName(strValue);
+ }
+
+ if (typeDef == XSConstants.NCNAME_DT) {
+ return new XSNCName(strValue);
+ }
+
+ if (typeDef == XSConstants.ENTITY_DT) {
+ return new XSEntity(strValue);
+ }
+
+ if (typeDef == XSConstants.ID_DT) {
+ return new XSID(strValue);
+ }
+
+ if (typeDef == XSConstants.IDREF_DT) {
+ return new XSIDREF(strValue);
+ }
+
+ if (typeDef == XSConstants.NMTOKEN_DT) {
+ return new XSNMTOKEN(strValue);
+ }
+ // end of, string types
if (typeDef == XSConstants.TIME_DT) {
return XSTime.parse_time(strValue);