use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString 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.XSString 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;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.
the class FsEq method do_general_pair.
/**
* Making sure that the types are the same before comparing the inputs.
*
* @param a
* input1 of any type.
* @param b
* input2 of any type.
* @param dc
* Dynamic Context
* @throws DynamicError
* Dynamic error.
* @return Result of Equality operation.
*/
private static boolean do_general_pair(AnyType a, AnyType b, Method comparator, DynamicContext ec) throws DynamicError {
// double
if ((a instanceof XSUntypedAtomic && b instanceof NumericType) || (b instanceof XSUntypedAtomic && a instanceof NumericType)) {
if (a instanceof XSUntypedAtomic)
a = new XSDouble(a.getStringValue());
else
b = new XSDouble(b.getStringValue());
} else // untyped to string
if ((a instanceof XSUntypedAtomic && (b instanceof XSString || b instanceof XSUntypedAtomic) || (b instanceof XSUntypedAtomic && (a instanceof XSString || a instanceof XSUntypedAtomic)))) {
if (a instanceof XSUntypedAtomic)
a = new XSString(a.getStringValue());
if (b instanceof XSUntypedAtomic)
b = new XSString(b.getStringValue());
} else // TODO: This makes no sense as implemented before
if (a instanceof XSUntypedAtomic) {
// ResultSequence converted = ResultSequenceFactory.create_new(a);
// assert converted.size() == 1;
// a = converted.first();
} else if (b instanceof XSUntypedAtomic) {
// ResultSequence converted = ResultSequenceFactory.create_new(b);
// assert converted.size() == 1;
// b = converted.first();
}
// rule d
// if value comparison is true, return true.
ResultSequence one = ResultSequenceFactory.create_new(a);
ResultSequence two = ResultSequenceFactory.create_new(b);
Collection args = new ArrayList();
args.add(one);
args.add(two);
Object[] margs = { args, ec };
ResultSequence result = null;
try {
result = (ResultSequence) comparator.invoke(null, margs);
} catch (IllegalAccessException err) {
assert false;
} catch (InvocationTargetException err) {
Throwable ex = err.getTargetException();
if (ex instanceof RuntimeException)
throw (RuntimeException) ex;
throw new RuntimeException(ex);
}
if (((XSBoolean) result.first()).value())
return true;
return false;
}
Aggregations