/*
* Set value of XPath2 context variable $value, if element has a complex type with simple content.
*/
private void setValueOf$ValueForCTWithSimpleContent(String value, XSComplexTypeDefinition typeDef) {
XSComplexTypeDefinition cmplxTypeDef = (XSComplexTypeDefinition)typeDef;
XSSimpleTypeDefinition complexTypeSimplContentType = cmplxTypeDef.getSimpleType();
if (complexTypeSimplContentType.getVariety() == XSSimpleTypeDefinition.VARIETY_LIST) {
// simple content type has variety xs:list
XSSimpleTypeDefinition listItemType = complexTypeSimplContentType.getItemType();
// split the "string value" of list contents, into non white-space tokens.
StringTokenizer values = new StringTokenizer(value, " \n\t\r");
// construct a list of atomic XDM items, to assign to XPath2 context variable $value.
List xdmItemList = new ArrayList();
final XSObjectList memberTypes = listItemType.getMemberTypes();
if (memberTypes.getLength() > 0) {
// itemType of xs:list has variety 'union'. here list items may have different types, which are determined below.
while (values.hasMoreTokens()) {
String itemValue = values.nextToken();
XSSimpleTypeDefinition listItemTypeForUnion = getActualListItemTypeForVarietyUnion(memberTypes, itemValue);
xdmItemList.add(SchemaTypeValueFactory.newSchemaTypeValue(listItemTypeForUnion.getBuiltInKind(), itemValue));
}
}
else {
// every list item has a same type (the itemType of xs:list).
while (values.hasMoreTokens()) {
String itemValue = values.nextToken();
xdmItemList.add(SchemaTypeValueFactory.newSchemaTypeValue(listItemType.getBuiltInKind(), itemValue));
}
}
// assign an XPath2 sequence to xpath context variable $value
fDynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
"value"), getXPath2ResultSequence(xdmItemList));
}
else if (complexTypeSimplContentType.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
// simple content type has variety xs:union
XSSimpleTypeDefinition simpleContentTypeForUnion = getActualListItemTypeForVarietyUnion
(complexTypeSimplContentType.getMemberTypes(), value);
fDynamicContext.set_variable(new org.eclipse.wst.xml.xpath2.processor.internal.types.QName("value"),
SchemaTypeValueFactory.newSchemaTypeValue(simpleContentTypeForUnion.getBuiltInKind(),
value));
}
else {
// simple content type has variety atomic
setValueOf$ValueForSTVarietyAtomic(value, getXercesXSDTypeCodeFor$Value(cmplxTypeDef.getSimpleType()));
}
} // setValueOf$ValueForCTWithSimpleContent