Class SwitchExpression

    • Constructor Detail

      • SwitchExpression

        public SwitchExpression​(SwitchExpression.SwitchCaseInfo switchCaseInfo)
        Create a switch expression
        Parameters:
        switchCaseInfo - details of the expression to be constructed
    • Method Detail

      • setInstruction

        public void setInstruction​(boolean inst)
        Say whether this switch expression originates as an XSLT instruction
        Parameters:
        inst - true if this started life as an xsl:choose instruction
      • isInstruction

        public boolean isInstruction()
        Ask whether this expression is an instruction. In XSLT streamability analysis this is used to distinguish constructs corresponding to XSLT instructions from other constructs.
        Overrides:
        isInstruction in class Expression
        Returns:
        true if this construct originates as an XSLT instruction
      • getSubjectExpression

        public Expression getSubjectExpression()
        Get the subject expression (the expression that computes the switch value)
        Returns:
        the expression that computes the switch value
      • getCaseMap

        public java.util.Map<AtomicMatchKey,​java.lang.Integer> getCaseMap()
        Get the map from XPathComparable objects representing the values to the expressions to be executed for each of these values
        Returns:
        the map of case clauses
      • getOtherwiseExpression

        public Expression getOtherwiseExpression()
        Get the default ("otherwise") expression
        Returns:
        the "otherwise" expression giving the value to be returned if none of the cases match
      • getAction

        public Operand getAction​(int index)
      • getActions

        public java.util.List<Operand> getActions()
      • getOtherwiseOperand

        public Operand getOtherwiseOperand()
      • operands

        public java.lang.Iterable<Operand> operands()
        Description copied from class: Expression
        Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.

        If the expression is a Callable, then it is required that the order of the operands returned by this function is the same as the order of arguments supplied to the corresponding call() method.

        Overrides:
        operands in class Expression
        Returns:
        an iterator containing the sub-expressions of this expression
      • getCollation

        public StringCollator getCollation()
        Get the collation used
        Returns:
        the collation
      • allowExtractingCommonSubexpressions

        public boolean allowExtractingCommonSubexpressions()
        Ask whether common subexpressions found in the operands of this expression can be extracted and evaluated outside the expression itself. The result is irrelevant in the case of operands evaluated with a different focus, which will never be extracted in this way, even if they have no focus dependency.
        Overrides:
        allowExtractingCommonSubexpressions in class Expression
        Returns:
        false for this kind of expression
      • copy

        public Expression copy​(RebindingMap rebindings)
        Copy an expression. This makes a deep copy.
        Specified by:
        copy in class Expression
        Parameters:
        rebindings - variables that need to be re-bound
        Returns:
        the copy of the original expression
      • export

        public void export​(ExpressionPresenter out)
                    throws XPathException
        Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
        Specified by:
        export in interface ExportAgent
        Specified by:
        export in class Expression
        Parameters:
        out - the expression presenter used to display the structure
        Throws:
        XPathException - if the export fails, for example if an expression is found that won't work in the target environment.
      • getItemType

        public ItemType getItemType()
        Determine the data type of the expression, if possible. All expression return sequences, in general; this method determines the type of the items within the sequence, assuming that (a) this is known in advance, and (b) it is the same for all items in the sequence.

        This method should always return a result, though it may be the best approximation that is available at the time.

        Specified by:
        getItemType in class Expression
        Returns:
        a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known at compile time)
      • unordered

        public Expression unordered​(boolean retainAllNodes,
                                    boolean forStreaming)
                             throws XPathException
        Replace this expression by a simpler expression that delivers the results without regard to order.
        Overrides:
        unordered in class Expression
        Parameters:
        retainAllNodes - set to true if the result must contain exactly the same nodes as the original; set to false if the result can eliminate (or introduce) duplicates.
        forStreaming - set to true if optimizing for streaming
        Returns:
        an expression that delivers the same nodes in a more convenient order
        Throws:
        XPathException - if the rewrite fails
      • evaluateItem

        public Item evaluateItem​(XPathContext context)
                          throws XPathException
        Evaluate an expression as a single item. This always returns either a single Item or null (denoting the empty sequence). No conversion is done. This method should not be used unless the static type of the expression is a subtype of "item" or "item?": that is, it should not be called if the expression may return a sequence. There is no guarantee that this condition will be detected.
        Overrides:
        evaluateItem in class Expression
        Parameters:
        context - The context in which the expression is to be evaluated
        Returns:
        the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence
        Throws:
        XPathException - if any dynamic error occurs evaluating the expression
      • iterate

        public SequenceIterator iterate​(XPathContext context)
                                 throws XPathException
        Return an Iterator to iterate over the values of a sequence. The value of every expression can be regarded as a sequence, so this method is supported for all expressions. This default implementation handles iteration for expressions that return singleton values: for non-singleton expressions, the subclass must provide its own implementation.
        Overrides:
        iterate in class Expression
        Parameters:
        context - supplies the context for evaluation
        Returns:
        a SequenceIterator that can be used to iterate over the result of the expression
        Throws:
        XPathException - if any dynamic error occurs evaluating the expression
      • process

        public void process​(Outputter output,
                            XPathContext context)
                     throws XPathException
        Process the instruction, without returning any tail calls
        Overrides:
        process in class Expression
        Parameters:
        output - the destination for the result
        context - The dynamic context, giving access to the current node,
        Throws:
        XPathException - if a dynamic error occurs
      • getImplementationMethod

        public int getImplementationMethod()
        Description copied from class: Expression
        An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is provided directly. The other methods will always be available indirectly, using an implementation that relies on one of the other methods.
        Specified by:
        getImplementationMethod in class Expression
        Returns:
        the implementation method, for example Expression.ITERATE_METHOD or Expression.EVALUATE_METHOD or Expression.PROCESS_METHOD
      • getExpressionName

        public java.lang.String getExpressionName()
        Get a name identifying the kind of expression, in terms meaningful to a user.
        Overrides:
        getExpressionName in class Expression
        Returns:
        a name identifying the kind of expression, in terms meaningful to a user. The name will always be in the form of a lexical XML QName, and should match the name used in export() output displaying the expression.
      • getStreamerName

        public java.lang.String getStreamerName()
        Description copied from class: Expression
        Get the (partial) name of a class that supports streaming of this kind of expression
        Overrides:
        getStreamerName in class Expression
        Returns:
        the partial name of a class that can be instantiated to provide streaming support in Saxon-EE, or null if there is no such class
      • getElaborator

        public Elaborator getElaborator()
        Make an elaborator for this expression
        Overrides:
        getElaborator in class Expression
        Returns:
        a suitable elaborator