Search in sources :

Example 26 with Expression

use of org.apache.xpath.Expression in project robovm by robovm.

the class VariableSafeAbsRef method execute.

/**
   * Dereference the variable, and return the reference value.  Note that lazy 
   * evaluation will occur.  If a variable within scope is not found, a warning 
   * will be sent to the error listener, and an empty nodeset will be returned.
   *
   *
   * @param xctxt The runtime execution context.
   *
   * @return The evaluated variable, or an empty nodeset if not found.
   *
   * @throws javax.xml.transform.TransformerException
   */
public XObject execute(XPathContext xctxt, boolean destructiveOK) throws javax.xml.transform.TransformerException {
    XNodeSet xns = (XNodeSet) super.execute(xctxt, destructiveOK);
    DTMManager dtmMgr = xctxt.getDTMManager();
    int context = xctxt.getContextNode();
    if (dtmMgr.getDTM(xns.getRoot()).getDocument() != dtmMgr.getDTM(context).getDocument()) {
        Expression expr = (Expression) xns.getContainedIter();
        xns = (XNodeSet) expr.asIterator(xctxt, context);
    }
    return xns;
}
Also used : DTMManager(org.apache.xml.dtm.DTMManager) Expression(org.apache.xpath.Expression) XNodeSet(org.apache.xpath.objects.XNodeSet)

Example 27 with Expression

use of org.apache.xpath.Expression in project robovm by robovm.

the class WalkerFactory method createDefaultStepPattern.

/**
   * Create a StepPattern that is contained within a LocationPath.
   *
   *
   * @param compiler The compiler that holds the syntax tree/op map to
   * construct from.
   * @param stepOpCodePos The current op code position within the opmap.
   * @param mpi The MatchPatternIterator to which the steps will be attached.
   * @param analysis 32 bits of analysis, from which the type of AxesWalker
   *                 may be influenced.
   * @param tail The step that is the first step analyzed, but the last 
   *                  step in the relative match linked list, i.e. the tail.
   *                  May be null.
   * @param head The step that is the current head of the relative 
   *                 match step linked list.
   *                 May be null.
   *
   * @return the head of the list.
   *
   * @throws javax.xml.transform.TransformerException
   */
private static StepPattern createDefaultStepPattern(Compiler compiler, int opPos, MatchPatternIterator mpi, int analysis, StepPattern tail, StepPattern head) throws javax.xml.transform.TransformerException {
    int stepType = compiler.getOp(opPos);
    boolean simpleInit = false;
    boolean prevIsOneStepDown = true;
    int whatToShow = compiler.getWhatToShow(opPos);
    StepPattern ai = null;
    int axis, predicateAxis;
    switch(stepType) {
        case OpCodes.OP_VARIABLE:
        case OpCodes.OP_EXTFUNCTION:
        case OpCodes.OP_FUNCTION:
        case OpCodes.OP_GROUP:
            prevIsOneStepDown = false;
            Expression expr;
            switch(stepType) {
                case OpCodes.OP_VARIABLE:
                case OpCodes.OP_EXTFUNCTION:
                case OpCodes.OP_FUNCTION:
                case OpCodes.OP_GROUP:
                    expr = compiler.compile(opPos);
                    break;
                default:
                    expr = compiler.compile(opPos + 2);
            }
            axis = Axis.FILTEREDLIST;
            predicateAxis = Axis.FILTEREDLIST;
            ai = new FunctionPattern(expr, axis, predicateAxis);
            simpleInit = true;
            break;
        case OpCodes.FROM_ROOT:
            whatToShow = DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT;
            axis = Axis.ROOT;
            predicateAxis = Axis.ROOT;
            ai = new StepPattern(DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT, axis, predicateAxis);
            break;
        case OpCodes.FROM_ATTRIBUTES:
            whatToShow = DTMFilter.SHOW_ATTRIBUTE;
            axis = Axis.PARENT;
            predicateAxis = Axis.ATTRIBUTE;
            // ai = new StepPattern(whatToShow, Axis.SELF, Axis.SELF);
            break;
        case OpCodes.FROM_NAMESPACE:
            whatToShow = DTMFilter.SHOW_NAMESPACE;
            axis = Axis.PARENT;
            predicateAxis = Axis.NAMESPACE;
            // ai = new StepPattern(whatToShow, axis, predicateAxis);
            break;
        case OpCodes.FROM_ANCESTORS:
            axis = Axis.DESCENDANT;
            predicateAxis = Axis.ANCESTOR;
            break;
        case OpCodes.FROM_CHILDREN:
            axis = Axis.PARENT;
            predicateAxis = Axis.CHILD;
            break;
        case OpCodes.FROM_ANCESTORS_OR_SELF:
            axis = Axis.DESCENDANTORSELF;
            predicateAxis = Axis.ANCESTORORSELF;
            break;
        case OpCodes.FROM_SELF:
            axis = Axis.SELF;
            predicateAxis = Axis.SELF;
            break;
        case OpCodes.FROM_PARENT:
            axis = Axis.CHILD;
            predicateAxis = Axis.PARENT;
            break;
        case OpCodes.FROM_PRECEDING_SIBLINGS:
            axis = Axis.FOLLOWINGSIBLING;
            predicateAxis = Axis.PRECEDINGSIBLING;
            break;
        case OpCodes.FROM_PRECEDING:
            axis = Axis.FOLLOWING;
            predicateAxis = Axis.PRECEDING;
            break;
        case OpCodes.FROM_FOLLOWING_SIBLINGS:
            axis = Axis.PRECEDINGSIBLING;
            predicateAxis = Axis.FOLLOWINGSIBLING;
            break;
        case OpCodes.FROM_FOLLOWING:
            axis = Axis.PRECEDING;
            predicateAxis = Axis.FOLLOWING;
            break;
        case OpCodes.FROM_DESCENDANTS_OR_SELF:
            axis = Axis.ANCESTORORSELF;
            predicateAxis = Axis.DESCENDANTORSELF;
            break;
        case OpCodes.FROM_DESCENDANTS:
            axis = Axis.ANCESTOR;
            predicateAxis = Axis.DESCENDANT;
            break;
        default:
            //"Programmer's assertion: unknown opcode: "
            throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[] { Integer.toString(stepType) }));
    }
    if (null == ai) {
        // %REVIEW%
        whatToShow = compiler.getWhatToShow(opPos);
        ai = new StepPattern(whatToShow, compiler.getStepNS(opPos), compiler.getStepLocalName(opPos), axis, predicateAxis);
    }
    if (false || DEBUG_PATTERN_CREATION) {
        System.out.print("new step: " + ai);
        System.out.print(", axis: " + Axis.getNames(ai.getAxis()));
        System.out.print(", predAxis: " + Axis.getNames(ai.getAxis()));
        System.out.print(", what: ");
        System.out.print("    ");
        ai.debugWhatToShow(ai.getWhatToShow());
    }
    int argLen = compiler.getFirstPredicateOpPos(opPos);
    ai.setPredicates(compiler.getCompiledPredicates(argLen));
    return ai;
}
Also used : FunctionPattern(org.apache.xpath.patterns.FunctionPattern) Expression(org.apache.xpath.Expression) ContextMatchStepPattern(org.apache.xpath.patterns.ContextMatchStepPattern) StepPattern(org.apache.xpath.patterns.StepPattern)

Example 28 with Expression

use of org.apache.xpath.Expression in project robovm by robovm.

the class FuncExtFunction method execute.

/**
   * Execute the function.  The function must return
   * a valid object.
   * @param xctxt The current execution context.
   * @return A valid XObject.
   *
   * @throws javax.xml.transform.TransformerException
   */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
    if (xctxt.isSecureProcessing())
        throw new javax.xml.transform.TransformerException(XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_EXTENSION_FUNCTION_CANNOT_BE_INVOKED, new Object[] { toString() }));
    XObject result;
    Vector argVec = new Vector();
    int nArgs = m_argVec.size();
    for (int i = 0; i < nArgs; i++) {
        Expression arg = (Expression) m_argVec.elementAt(i);
        XObject xobj = arg.execute(xctxt);
        /*
       * Should cache the arguments for func:function
       */
        xobj.allowDetachToRelease(false);
        argVec.addElement(xobj);
    }
    //dml
    ExtensionsProvider extProvider = (ExtensionsProvider) xctxt.getOwnerObject();
    Object val = extProvider.extFunction(this, argVec);
    if (null != val) {
        result = XObject.create(val, xctxt);
    } else {
        result = new XNull();
    }
    return result;
}
Also used : ExtensionsProvider(org.apache.xpath.ExtensionsProvider) XNull(org.apache.xpath.objects.XNull) Expression(org.apache.xpath.Expression) XObject(org.apache.xpath.objects.XObject) Vector(java.util.Vector) XObject(org.apache.xpath.objects.XObject)

Aggregations

Expression (org.apache.xpath.Expression)28 XObject (org.apache.xpath.objects.XObject)8 QName (org.apache.xml.utils.QName)6 TransformerException (javax.xml.transform.TransformerException)4 ExpressionOwner (org.apache.xpath.ExpressionOwner)4 XPathContext (org.apache.xpath.XPathContext)4 LocPathIterator (org.apache.xpath.axes.LocPathIterator)4 XNodeSet (org.apache.xpath.objects.XNodeSet)4 StepPattern (org.apache.xpath.patterns.StepPattern)4 Vector (java.util.Vector)2 DTM (org.apache.xml.dtm.DTM)2 DTMIterator (org.apache.xml.dtm.DTMIterator)2 DTMManager (org.apache.xml.dtm.DTMManager)2 SerializationHandler (org.apache.xml.serializer.SerializationHandler)2 XMLString (org.apache.xml.utils.XMLString)2 ExtensionsProvider (org.apache.xpath.ExtensionsProvider)2 NodeSetDTM (org.apache.xpath.NodeSetDTM)2 XPath (org.apache.xpath.XPath)2 WrongNumberArgsException (org.apache.xpath.functions.WrongNumberArgsException)2 XNull (org.apache.xpath.objects.XNull)2