use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType in project webtools.sourceediting by eclipse.
the class FnSum method sum.
/**
* Sum operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:sum operation.
*/
public static ResultSequence sum(ResultSequence arg, AnyAtomicType zero) throws DynamicError {
if (arg.empty())
return ResultSequenceFactory.create_new(zero);
MathPlus total = null;
TypePromoter tp = new ScalarTypePromoter();
tp.considerSequence(arg);
for (Iterator i = arg.iterator(); i.hasNext(); ) {
AnyAtomicType conv = tp.promote((AnyType) i.next());
if (conv == null) {
conv = zero;
}
if (conv instanceof XSDouble && ((XSDouble) conv).nan() || conv instanceof XSFloat && ((XSFloat) conv).nan()) {
return ResultSequenceFactory.create_new(tp.promote(new XSFloat(Float.NaN)));
}
if (total == null) {
total = (MathPlus) conv;
} else {
total = (MathPlus) total.plus(ResultSequenceFactory.create_new(conv)).first();
}
}
return ResultSequenceFactory.create_new((AnyType) total);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit cast expression
*
* @param cexp
* is the cast expression.
* @return a new function
*/
public Object visit(CastExpr cexp) {
ResultSequence rs = (ResultSequence) cexp.left().accept(this);
SingleType st = (SingleType) cexp.right();
rs = FnData.atomize(rs);
if (rs.size() > 1)
report_error(TypeError.invalid_type(null));
if (rs.empty()) {
if (st.qmark())
return rs;
else
report_error(TypeError.invalid_type(null));
}
AnyType at = (AnyType) rs.item(0);
if (!(at instanceof AnyAtomicType))
report_error(TypeError.invalid_type(null));
AnyAtomicType aat = (AnyAtomicType) at;
QName type = st.type();
// prepare args from function
Collection args = new ArrayList();
args.add(ResultSequenceFactory.create_new(aat));
try {
Function function = cexp.function();
if (function == null) {
function = _sc.resolveFunction(type.asQName(), args.size());
cexp.set_function(function);
}
if (function == null)
report_error(TypeError.invalid_type(null));
return function.evaluate(args, _ec);
} catch (DynamicError err) {
report_error(err);
// unreach
return null;
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method do_step.
// this will evaluate the step expression for the whole focus and return
// the result.
//
// i.e. It will execute the step expression for each item in the focus
// [each time changing the context item].
private ResultSequence do_step(StepExpr se) {
ResultBuffer rs = new ResultBuffer();
ArrayList results = new ArrayList();
// 0: don't know yet
int type = 0;
// 1: atomic
// 2: node
Focus focus = focus();
int original_pos = focus.position();
// execute step for all items in focus
while (true) {
results.add(se.accept(this));
// go to next
if (!focus.advance_cp())
break;
}
// make sure we didn't change focus
focus.set_position(original_pos);
boolean node_types = false;
// check the results
for (Iterator i = results.iterator(); i.hasNext(); ) {
ResultSequence result = (ResultSequence) i.next();
// make sure results are of same type, and add them in
for (Iterator j = result.iterator(); j.hasNext(); ) {
AnyType item = (AnyType) j.next();
// first item
if (type == 0) {
if (item instanceof AnyAtomicType)
type = 1;
else if (item instanceof NodeType)
type = 2;
else
assert false;
}
// make sure we got coherent types
switch(type) {
// atomic... just concat
case 1:
if (!(item instanceof AnyAtomicType))
report_error(TypeError.mixed_vals(null));
rs.add(item);
break;
case 2:
node_types = true;
if (!(item instanceof NodeType))
report_error(TypeError.mixed_vals(null));
rs.add(item);
break;
default:
assert false;
}
}
}
// XXX lame
if (node_types) {
rs = NodeType.linarize(rs);
}
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType in project webtools.sourceediting by eclipse.
the class XercesFloatUserDefined method constructor.
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
ResultSequence rs = ResultSequenceFactory.create_new();
if (arg.empty())
return rs;
// AnyAtomicType aat = (AnyAtomicType) arg.first();
AnyType aat = arg.first();
XSSimpleTypeDefinition simpletype = (XSSimpleTypeDefinition) typeInfo;
if (simpletype != null) {
if (simpletype.isDefinedFacet(XSSimpleTypeDefinition.FACET_MININCLUSIVE)) {
String minValue = simpletype.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MININCLUSIVE);
float iminValue = Float.parseFloat(minValue);
float actualValue = Float.parseFloat(aat.getStringValue());
if (actualValue < iminValue) {
throw DynamicError.invalidForCastConstructor();
}
}
if (simpletype.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE)) {
String maxValue = simpletype.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE);
float imaxValue = Float.parseFloat(maxValue);
float actualValue = Float.parseFloat(aat.getStringValue());
if (actualValue > imaxValue) {
throw DynamicError.invalidForCastConstructor();
}
}
}
rs.add(new XercesFloatUserDefined(Float.parseFloat(aat.getStringValue())));
return rs;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType in project webtools.sourceediting by eclipse.
the class XercesQNameUserDefined method constructor.
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
ResultSequence rs = ResultSequenceFactory.create_new();
if (arg.empty())
return rs;
// AnyAtomicType aat = (AnyAtomicType) arg.first();
AnyType aat = arg.first();
QName qname = QName.parse_QName(aat.getStringValue());
rs.add(qname);
return rs;
}
Aggregations