/** * Make an atomizer with a given operand * * @param sequence the operand * @param role (may be null) additional information for diagnostics * @return an Atomizer that atomizes the given operand, or another expression that returns the same result */ public static Expression makeAtomizer(Expression sequence, RoleDiagnostic role) { if (sequence instanceof Literal && ((Literal) sequence).getValue() instanceof AtomicSequence) { return sequence; } else { return new Atomizer(sequence, role); } }
/** * Make an atomizer with a given operand * * @param sequence the operand * @return an Atomizer that atomizes the given operand, or another expression that returns the same result */ public static Expression makeAtomizer(Expression sequence) { if (sequence instanceof Literal && ((Literal) sequence).getValue() instanceof AtomicSequence) { return sequence; } else { return new Atomizer(sequence); } }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new Atomizer(getBaseExpression().copy(), config); }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new Atomizer(getBaseExpression().copy(), config); }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new Atomizer(getBaseExpression().copy(), config); }
/** * Simplify and validate. * @param visitor an expression visitor */ public Expression simplify(ExpressionVisitor visitor) throws XPathException { Atomizer a = new Atomizer(argument[0], visitor.getConfiguration()); ExpressionTool.copyLocationInfo(this, a); return visitor.simplify(a); }
/** * Simplify and validate. * @param visitor an expression visitor */ public Expression simplify(ExpressionVisitor visitor) throws XPathException { Atomizer a = new Atomizer(argument[0], visitor.getConfiguration()); ExpressionTool.copyLocationInfo(this, a); return visitor.simplify(a); }
/** * Simplify and validate. * @param visitor an expression visitor */ public Expression simplify(ExpressionVisitor visitor) throws XPathException { Atomizer a = new Atomizer(argument[0], visitor.getConfiguration()); ExpressionTool.copyLocationInfo(this, a); return visitor.simplify(a); }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression * @param rebindings */ /*@NotNull*/ public Expression copy(RebindingMap rebindings) { Atomizer copy = new Atomizer(getBaseExpression().copy(rebindings), roleDiagnostic); copy.untyped = untyped; copy.singleValued = singleValued; ExpressionTool.copyLocationInfo(this, copy); return copy; }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression * @param rebindings */ /*@NotNull*/ public Expression copy(RebindingMap rebindings) { Atomizer copy = new Atomizer(getBaseExpression().copy(rebindings)); copy.untyped = untyped; copy.singleValued = singleValued; ExpressionTool.copyLocationInfo(this, copy); return copy; }
/** * Make a string-join expression that concatenates the string-values of items in * a sequence with intervening spaces. This may be simplified later as a result * of type-checking. * @param exp the base expression, evaluating to a sequence * @param env the static context * @return a call on string-join to create a string containing the * representations of the items in the sequence separated by spaces. */ public static Expression makeStringJoin(Expression exp, StaticContext env) { exp = new Atomizer(exp, env.getConfiguration()); final TypeHierarchy th = env.getConfiguration().getTypeHierarchy(); ItemType t = exp.getItemType(th); if (!t.equals(BuiltInAtomicType.STRING) && !t.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { exp = new AtomicSequenceConverter(exp, BuiltInAtomicType.STRING); } StringJoin fn = (StringJoin)SystemFunction.makeSystemFunction( "string-join", new Expression[]{exp, new StringLiteral(StringValue.SINGLE_SPACE)}); ExpressionTool.copyLocationInfo(exp, fn); return fn; }
/** * Make a string-join expression that concatenates the string-values of items in * a sequence with intervening spaces. This may be simplified later as a result * of type-checking. * @param exp the base expression, evaluating to a sequence * @param env the static context * @return a call on string-join to create a string containing the * representations of the items in the sequence separated by spaces. */ public static Expression makeStringJoin(Expression exp, StaticContext env) { exp = new Atomizer(exp, env.getConfiguration()); final TypeHierarchy th = env.getConfiguration().getTypeHierarchy(); ItemType t = exp.getItemType(th); if (!t.equals(BuiltInAtomicType.STRING) && !t.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { exp = new AtomicSequenceConverter(exp, BuiltInAtomicType.STRING); } StringJoin fn = (StringJoin)SystemFunction.makeSystemFunction( "string-join", new Expression[]{exp, new StringLiteral(StringValue.SINGLE_SPACE)}); ExpressionTool.copyLocationInfo(exp, fn); return fn; }
/** * An internal key definition is used to support the idref() function. The key definition * is equivalent to xsl:key match="element(*, xs:IDREF) | element(*, IDREFS) | * attribute(*, xs:IDREF) | attribute(*, IDREFS)" use=".". This method creates this * key definition. * @param config The configuration. This is needed because the patterns that are * generated need access to schema information. */ private void registerIdrefKey(Configuration config) { PatternFinder idref = IdrefTest.getInstance(); Expression eval = new Atomizer(new ContextItemExpression(), config); StringLiteral regex = new StringLiteral("\\s"); Tokenize use = (Tokenize)SystemFunction.makeSystemFunction("tokenize", new Expression[]{eval, regex}); KeyDefinition key = new KeyDefinition(idref, use, null, null); key.setIndexedItemType(BuiltInAtomicType.STRING); try { addKeyDefinition(StandardNames.getStructuredQName(StandardNames.XS_IDREFS), key, config); } catch (XPathException err) { throw new AssertionError(err); // shouldn't happen } }
/** * An internal key definition is used to support the idref() function. The key definition * is equivalent to xsl:key match="element(*, xs:IDREF) | element(*, IDREFS) | * attribute(*, xs:IDREF) | attribute(*, IDREFS)" use=".". This method creates this * key definition. * @param config The configuration. This is needed because the patterns that are * generated need access to schema information. */ private void registerIdrefKey(Configuration config) { PatternFinder idref = IdrefTest.getInstance(); Expression eval = new Atomizer(new ContextItemExpression(), config); StringLiteral regex = new StringLiteral("\\s"); Tokenize use = (Tokenize)SystemFunction.makeSystemFunction("tokenize", new Expression[]{eval, regex}); KeyDefinition key = new KeyDefinition(idref, use, null, null); key.setIndexedItemType(BuiltInAtomicType.STRING); try { addKeyDefinition(StandardNames.getStructuredQName(StandardNames.XS_IDREFS), key, config); } catch (XPathException err) { throw new AssertionError(err); // shouldn't happen } }
private SequenceIterator rawIterator(XPathContextMajor context) throws XPathException { SequenceIterator iterator = expression.iterate(context); if (sortKey != null) { Expression key = sortKey.expression; if (key.getItemType(config.getTypeHierarchy()) instanceof NodeTest) { sortKey.expression = new Atomizer(key, config); } SortKeyDefinition sk = new SortKeyDefinition(); sk.setSortKey(sortKey.expression); AtomicComparer comp = sk.makeComparator(context); AtomicComparer[] comps = {comp}; iterator = new SortedIterator(context, iterator, this, comps); ((SortedIterator)iterator).setHostLanguage(Configuration.XPATH); } return iterator; }
/** * Make an expression that extracts the first item of a sequence, after atomization */ public static Expression makeFirstItem(Expression exp, StaticContext env) { final TypeHierarchy th = env.getConfiguration().getTypeHierarchy(); if (!exp.getItemType(th).isAtomicType()) { exp = new Atomizer(exp, env.getConfiguration()); } if (Cardinality.allowsMany(exp.getCardinality())) { exp = new FirstItemExpression(exp); } if (!th.isSubType(exp.getItemType(th), BuiltInAtomicType.STRING)) { exp = new AtomicSequenceConverter(exp, BuiltInAtomicType.STRING); } return exp; }
/** * Make an expression that extracts the first item of a sequence, after atomization */ public static Expression makeFirstItem(Expression exp, StaticContext env) { final TypeHierarchy th = env.getConfiguration().getTypeHierarchy(); if (!exp.getItemType(th).isAtomicType()) { exp = new Atomizer(exp, env.getConfiguration()); } if (Cardinality.allowsMany(exp.getCardinality())) { exp = new FirstItemExpression(exp); } if (!th.isSubType(exp.getItemType(th), BuiltInAtomicType.STRING)) { exp = new AtomicSequenceConverter(exp, BuiltInAtomicType.STRING); } return exp; }
/** * Make an expression that extracts the first item of a sequence, after atomization */ public static Expression makeFirstItem(Expression exp, StaticContext env) { final TypeHierarchy th = env.getConfiguration().getTypeHierarchy(); if (!exp.getItemType(th).isAtomicType()) { exp = new Atomizer(exp, env.getConfiguration()); } if (Cardinality.allowsMany(exp.getCardinality())) { exp = new FirstItemExpression(exp); } if (!th.isSubType(exp.getItemType(th), BuiltInAtomicType.STRING)) { exp = new AtomicSequenceConverter(exp, BuiltInAtomicType.STRING); } return exp; }
public Expression compile(Executable exec) throws XPathException { if (select == null) { Expression b = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true); b.setContainer(this); if (b == null) { b = new Literal(EmptySequence.getInstance()); } try { StaticContext env = getStaticContext(); Atomizer atomizedSortKey = new Atomizer(makeExpressionVisitor().simplify(b), env.getConfiguration()); ExpressionTool.copyLocationInfo(b, atomizedSortKey); sortKeyDefinition.setSortKey(atomizedSortKey); } catch (XPathException e) { compileError(e); } } // Simplify the sort key definition - this is especially important in the case where // all aspects of the sort key are known statically. sortKeyDefinition = sortKeyDefinition.simplify(makeExpressionVisitor()); // not an executable instruction return null; }
public Expression compile(Executable exec) throws XPathException { if (select == null) { Expression b = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true); b.setContainer(this); if (b == null) { b = new Literal(EmptySequence.getInstance()); } try { StaticContext env = getStaticContext(); Atomizer atomizedSortKey = new Atomizer(makeExpressionVisitor().simplify(b), env.getConfiguration()); ExpressionTool.copyLocationInfo(b, atomizedSortKey); sortKeyDefinition.setSortKey(atomizedSortKey); } catch (XPathException e) { compileError(e); } } // Simplify the sort key definition - this is especially important in the case where // all aspects of the sort key are known statically. sortKeyDefinition = sortKeyDefinition.simplify(makeExpressionVisitor()); // not an executable instruction return null; }