use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic in project webtools.sourceediting by eclipse.
the class Function method convert_argument.
// convert argument according to section 3.1.5 of xpath 2.0 spec
/**
* Convert the input argument according to section 3.1.5 of specification.
*
* @param arg
* input argument.
* @param expected
* Expected Sequence type.
* @throws DynamicError
* Dynamic error.
* @return Converted argument.
*/
public static org.eclipse.wst.xml.xpath2.api.ResultSequence convert_argument(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, SeqType expected) throws DynamicError {
ResultBuffer result = new ResultBuffer();
// XXX: Should use type_class instead and use item.getClass().isAssignableTo(expected.type_class())
AnyType expected_type = expected.type();
// expected is atomic
if (expected_type instanceof AnyAtomicType) {
AnyAtomicType expected_aat = (AnyAtomicType) expected_type;
// atomize
org.eclipse.wst.xml.xpath2.api.ResultSequence rs = FnData.atomize(arg);
// cast untyped to expected type
for (Iterator i = rs.iterator(); i.hasNext(); ) {
AnyType item = (AnyType) i.next();
if (item instanceof XSUntypedAtomic) {
// create a new item of the expected
// type initialized with from the string
// value of the item
ResultSequence converted = null;
if (expected_aat instanceof XSString) {
XSString strType = new XSString(item.getStringValue());
converted = ResultSequenceFactory.create_new(strType);
} else {
converted = ResultSequenceFactory.create_new(item);
}
result.concat(converted);
} else // xs:anyURI promotion to xs:string
if (item instanceof XSAnyURI && expected_aat instanceof XSString) {
result.add(new XSString(item.getStringValue()));
} else // numeric type promotion
if (item instanceof NumericType) {
if (expected_aat instanceof XSDouble) {
XSDouble doubleType = new XSDouble(item.getStringValue());
result.add(doubleType);
} else {
result.add(item);
}
} else {
result.add(item);
}
}
// do sequence type matching on converted arguments
return expected.match(result.getSequence());
} else {
// do sequence type matching on converted arguments
return expected.match(arg);
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic in project webtools.sourceediting by eclipse.
the class FsPlus method convert_args.
/**
* Convert and promote arguments for operation.
*
* @param args
* input arguments.
* @param sc
* @throws DynamicError
* Dynamic error.
* @return Result of conversion.
*/
private static Collection convert_args(Collection args) throws DynamicError {
Collection result = new ArrayList();
// Keep track of numeric types for promotion
boolean has_float = false;
boolean has_double = false;
// atomize arguments
for (Iterator i = args.iterator(); i.hasNext(); ) {
org.eclipse.wst.xml.xpath2.api.ResultSequence rs = FnData.atomize((org.eclipse.wst.xml.xpath2.api.ResultSequence) i.next());
if (rs.empty())
return new ArrayList();
if (rs.size() > 1)
throw new DynamicError(TypeError.invalid_type(null));
AnyType arg = (AnyType) rs.item(0);
if (arg instanceof XSUntypedAtomic) {
arg = new XSDouble(arg.getStringValue());
}
if (arg instanceof XSDouble)
has_double = true;
if (arg instanceof XSFloat)
has_float = true;
result.add(ResultBuffer.wrap(arg));
}
if (has_double)
has_float = false;
if (has_double || has_float) {
Collection result2 = new ArrayList();
// promote arguments
for (Iterator i = result.iterator(); i.hasNext(); ) {
org.eclipse.wst.xml.xpath2.api.ResultSequence rs = (org.eclipse.wst.xml.xpath2.api.ResultSequence) i.next();
Item arg = rs.item(0);
if (has_double && (arg instanceof XSFloat)) {
arg = new XSDouble(((XSFloat) arg).float_value());
} else if (has_double && (arg instanceof XSDecimal)) {
arg = new XSDouble(((XSDecimal) arg).getValue().doubleValue());
} else if (has_float && (arg instanceof XSDecimal)) {
arg = new XSFloat(((XSDecimal) arg).getValue().floatValue());
}
result2.add(arg);
}
return result2;
}
return result;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic in project webtools.sourceediting by eclipse.
the class NodeType method getXDMTypedValue.
// getTypedValueForPrimitiveType
/*
* Construct the "typed value" from a "string value", given the simpleType of the node.
*/
protected ResultSequence getXDMTypedValue(TypeDefinition typeDef, List itemValTypes) {
if ("anySimpleType".equals(typeDef.getName()) || "anyAtomicType".equals(typeDef.getName())) {
return new XSUntypedAtomic(getStringValue());
} else {
SimpleTypeDefinition simpType = null;
if (typeDef instanceof ComplexTypeDefinition) {
ComplexTypeDefinition complexTypeDefinition = (ComplexTypeDefinition) typeDef;
simpType = complexTypeDefinition.getSimpleType();
if (simpType != null) {
// element has a complexType with a simple content
return getTypedValueForSimpleContent(simpType, itemValTypes);
} else {
// element has a complexType with complex content
return new XSUntypedAtomic(getStringValue());
}
} else {
// element has a simpleType
simpType = (SimpleTypeDefinition) typeDef;
return getTypedValueForSimpleContent(simpType, itemValTypes);
}
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic in project webtools.sourceediting by eclipse.
the class FsConvertOperand method convert_operand.
/**
* Convert-Operand operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fs: operation.
*/
public static ResultSequence convert_operand(Collection args) throws DynamicError {
assert args.size() == 2;
Iterator iter = args.iterator();
ResultSequence actual = (ResultSequence) iter.next();
ResultSequence expected = (ResultSequence) iter.next();
if (expected.size() != 1)
DynamicError.throw_type_error();
Item at = expected.first();
if (!(at instanceof AnyAtomicType))
DynamicError.throw_type_error();
AnyAtomicType exp_aat = (AnyAtomicType) at;
ResultBuffer result = new ResultBuffer();
// 1
if (actual.empty())
return result.getSequence();
// convert sequence
for (Iterator i = actual.iterator(); i.hasNext(); ) {
AnyType item = (AnyType) i.next();
// 2
if (item instanceof XSUntypedAtomic) {
// a
if (exp_aat instanceof XSUntypedAtomic)
result.add(new XSString(item.getStringValue()));
else // b
if (exp_aat instanceof NumericType)
result.add(new XSDouble(item.getStringValue()));
else // c
{
assert exp_aat instanceof CtrType;
CtrType cons = (CtrType) exp_aat;
result.concat(cons.constructor(new XSString(item.getStringValue())));
}
} else
// 4
result.add(item);
}
return result.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic in project webtools.sourceediting by eclipse.
the class FsEq method value_convert_args.
/**
* Converts arguments to values.
*
* @param args
* Result from expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of conversion.
*/
private static Collection value_convert_args(Collection args) throws DynamicError {
Collection result = new ArrayList(args.size());
// atomize arguments
for (Iterator i = args.iterator(); i.hasNext(); ) {
ResultSequence rs = (ResultSequence) i.next();
// FnData.fast_atomize(rs);
rs = FnData.atomize(rs);
if (rs.empty())
return new ArrayList();
if (rs.size() > 1)
throw new DynamicError(TypeError.invalid_type(null));
Item arg = rs.first();
if (arg instanceof XSUntypedAtomic)
arg = new XSString(arg.getStringValue());
result.add(arg);
}
return result;
}
Aggregations