net.sf.saxon.expr

## Class CastingExpression

- java.lang.Object
- - net.sf.saxon.expr.Expression
  - - net.sf.saxon.expr.UnaryExpression
    - - net.sf.saxon.expr.CastingExpression

- All Implemented Interfaces:
    Serializable, SourceLocator, LocationProvider, SaxonLocator, InstructionInfo, Locator
  Direct Known Subclasses:
    CastableExpression, CastExpression

      public abstract class CastingExpression
      extends UnaryExpression

  Casting Expression: abstract superclass for "cast as X" and "castable as X", which share a good deal of logic
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Converter` | `converter`
    `protected NamespaceResolver` | `nsResolver`

    - ### Fields inherited from class net.sf.saxon.expr.UnaryExpression

      `operand`

    - ### Fields inherited from class net.sf.saxon.expr.Expression

      `EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, EVENT_FEED_METHOD, INHERITED_CONTEXT, INSPECTION_CONTEXT, ITEM_FEED_METHOD, ITERATE_METHOD, locationId, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, NAVIGATION_CONTEXT, NODE_VALUE_CONTEXT, PROCESS_METHOD, PUSH_SELECTION, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, W3C_CONSUMING, W3C_FREE_RANGING, W3C_GROUP_CONSUMING, W3C_MOTIONLESS, WATCH_METHOD`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CastingExpression(Expression source, AtomicType target, boolean allowEmpty)` Create a cast expression

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `allowsEmpty()` Ask whether the expression accepts an empty sequence as input (producing an empty sequence as output)
    `int` | `computeSpecialProperties()` Determine the special properties of this expression
    `Converter` | `getConverter()` Get the Converter allocated to implement this cast expression, if any
    `NamespaceResolver` | `getNamespaceResolver()` Get the namespace resolver, if any
    `int` | `getStreamability(int syntacticContext, boolean allowExtensions, List<String> reasons)` Get the "sweep" of this expression as defined in the W3C streamability specifications.
    `AtomicType` | `getTargetPrimitiveType()` Get the primitive base type of the target type of the cast
    `AtomicType` | `getTargetType()` Get the target type (the result type)
    `boolean` | `isOperandIsStringLiteral()` Ask whether the operand to the cast expression was supplied in the form of a string literal.
    `void` | `setAllowEmpty(boolean allow)` Say whether the expression accepts an empty sequence as input (producing an empty sequence as output)
    `void` | `setNamespaceResolver(NamespaceResolver resolver)` Set the namespace resolver, if any
    `void` | `setOperandIsStringLiteral(boolean option)` Say whether the operand to the cast expression was supplied in the form of a string literal.
    `void` | `setTargetType(AtomicType type)` Set the target type
    `Expression` | `simplify(ExpressionVisitor visitor)` Simplify the expression

    - ### Methods inherited from class net.sf.saxon.expr.UnaryExpression

      `computeCardinality, displayOperator, equals, explain, getBaseExpression, getItemType, hashCode, iterateSubExpressions, optimize, promote, replaceSubExpression, toString, typeCheck`

    - ### Methods inherited from class net.sf.saxon.expr.Expression

      `addToPathMap, adoptChildExpression, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, copy, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, evaluatePendingUpdates, explain, getCardinality, getColumnNumber, getColumnNumber, getConstructType, getContainer, getDependencies, getEvaluationMethod, getExecutable, getExpressionCompiler, getExpressionName, getHostLanguage, getImplementationMethod, getIntegerBounds, getIntrinsicDependencies, getLineNumber, getLineNumber, getLocationId, getLocationProvider, getObjectName, getProperties, getProperty, getPublicId, getSlotsUsed, getSpecialProperties, getStreamingAdjunct, getSystemId, getSystemId, hasVariableBinding, implementsStaticTypeCheck, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, iterate, iterateEvents, iterateSubExpressionInfo, markTailFunctionCalls, process, resetLocalStaticProperties, setContainer, setEvaluationMethod, setFiltered, setFlattened, setLocationId, staticTypeCheck, suppressValidation, toPattern, toStreamingPattern, typeError`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### converter

          protected Converter converter

    - #### nsResolver

          protected NamespaceResolver nsResolver

  - ### Constructor Detail

    - #### CastingExpression

          public CastingExpression(Expression source,
                           AtomicType target,
                           boolean allowEmpty)

      Create a cast expression
      Parameters:
        `source` - expression giving the value to be converted
        `target` - the type to which the value is to be converted
        `allowEmpty` - true if the expression allows an empty sequence as input, producing an empty sequence as output. If false, an empty sequence is a type error.

  - ### Method Detail

    - #### getTargetPrimitiveType

          public AtomicType getTargetPrimitiveType()

      Get the primitive base type of the target type of the cast
      Returns:
        the primitive type of the target type

    - #### setTargetType

          public void setTargetType(AtomicType type)

      Set the target type
      Parameters:
        `type` - the target type for the cast

    - #### getTargetType

          public AtomicType getTargetType()

      Get the target type (the result type)
      Returns:
        the target type

    - #### setAllowEmpty

          public void setAllowEmpty(boolean allow)

      Say whether the expression accepts an empty sequence as input (producing an empty sequence as output)
      Parameters:
        `allow` - true if an empty sequence is accepted

    - #### allowsEmpty

          public boolean allowsEmpty()

      Ask whether the expression accepts an empty sequence as input (producing an empty sequence as output)
      Returns:
        true if an empty sequence is accepted

    - #### setOperandIsStringLiteral

          public void setOperandIsStringLiteral(boolean option)

      Say whether the operand to the cast expression was supplied in the form of a string literal. This is relevant only for XPath 2.0 / XQuery 1.0, and then only when the target type is a QName or NOTATION.
      Parameters:
        `option` - true if the operand was supplied as a string literal

    - #### isOperandIsStringLiteral

          public boolean isOperandIsStringLiteral()

      Ask whether the operand to the cast expression was supplied in the form of a string literal. This is relevant only for XPath 2.0 / XQuery 1.0, and then only when the target type is a QName or NOTATION.
      Returns:
        true if the operand was supplied as a string literal

    - #### getConverter

          public Converter getConverter()

      Get the Converter allocated to implement this cast expression, if any
      Returns:
        the Converter if one has been statically allocated, or null if not

    - #### setNamespaceResolver

          public void setNamespaceResolver(NamespaceResolver resolver)

      Set the namespace resolver, if any
      Parameters:
        `resolver` - the namespace resolver to be used if the target type is namespace-sensitive

    - #### getNamespaceResolver

          public NamespaceResolver getNamespaceResolver()

      Get the namespace resolver, if any
      Returns:
        the namespace resolver that was statically allocated if the target type is namespace-sensitive

    - #### simplify

          public Expression simplify(ExpressionVisitor visitor)
                              throws XPathException

      Simplify the expression
      Overrides:
        `simplify` in class `UnaryExpression`
      Parameters:
        `visitor` - an expression visitor
      Returns:
        the simplified expression
      Throws:
        `XPathException` - if an error is discovered during expression rewriting

    - #### computeSpecialProperties

          public int computeSpecialProperties()

      Determine the special properties of this expression
      Overrides:
        `computeSpecialProperties` in class `UnaryExpression`
      Returns:
        `StaticProperty.NON_CREATIVE`.

    - #### getStreamability

          public int getStreamability(int syntacticContext,
                             boolean allowExtensions,
                             List<String> reasons)

      Get the "sweep" of this expression as defined in the W3C streamability specifications. This provides an assessment of stylesheet code against the W3C criteria for guaranteed streamability, and is implemented to allow these criteria to be tested. It is not the case that all expression that emerge as streamable from this analysis are currently capable of being streamed by Saxon
      Overrides:
        `getStreamability` in class `Expression`
      Parameters:
        `syntacticContext` - one of the values `Expression.NAVIGATION_CONTEXT`, `Expression.NODE_VALUE_CONTEXT`, `Expression.INHERITED_CONTEXT`, `Expression.INSPECTION_CONTEXT`
        `allowExtensions` - if false, the definition of "guaranteed streamability" in the W3C specification is used. If true, Saxon extensions are permitted, which make some constructs streamable that would not be so according to W3C rules.
        `reasons` -
      Returns:
        one of the values `Expression.W3C_MOTIONLESS`, `Expression.W3C_CONSUMING`, `Expression.W3C_GROUP_CONSUMING`, `Expression.W3C_FREE_RANGING`

Copyright (c) 2004-2013 Saxonica Limited. All rights reserved.