Package net.sf.saxon.instruct

Examples of net.sf.saxon.instruct.UserFunction


                "declare function f:t1($v1 as xs:integer, $v2 as xdt:untypedAtomic*) { " +
                "   $v1 div $v2" +
                "};" +
                "10");

        final UserFunction fn1 = sqc.getUserDefinedFunction("f.ns", "t1", 2);
        final Controller controller = exp1.getController();
        final Value[] arglist = new Value[2];
        arglist[0] = new IntegerValue(10);
        for (int i=3; i<10; i++) {
            arglist[1] = new IntegerValue(i);
            final Value result = fn1.call(arglist, controller);
            System.out.println(arglist[0] + " div " + arglist[1] + " = " + result);
        }
    }
View Full Code Here


     */

    public Expression bind(int nameCode, String uri, String local, Expression[] staticArgs)
            throws XPathException {
        long key = ((long)staticArgs.length)<<32 | (nameCode & 0xfffff);
        UserFunction fn = (UserFunction)functions.get(new Long(key));
        if (fn == null) {
            return null;
        }
        StandaloneContext env = new StandaloneContext(config); // this is needed only for the name pool
        UserFunctionCall fc = new UserFunctionCall();
        fc.setFunctionNameCode(nameCode);
        fc.setArguments(staticArgs);
        fc.setFunction(fn, env);
        fc.setStaticType(fn.getResultType());
        return fc;
    }
View Full Code Here

        if (fd != null) {
            UserFunctionCall ufc = new UserFunctionCall();
            ufc.setFunctionNameCode(nameCode);
            ufc.setArguments(arguments);
            ufc.setStaticType(fd.getResultType());
            UserFunction fn = fd.getUserFunction();
            if (fn == null) {
                // not yet compiled
                fd.registerReference(ufc);
            } else {
                ufc.setFunction(fn, fd.getStaticContext());
View Full Code Here

     * be objects of class {@link UserFunction}
     */

    public static void gatherCalledFunctions(Expression e, List list) {
        if (e instanceof UserFunctionCall) {
            UserFunction function = ((UserFunctionCall)e).getFunction();
            if (!list.contains(function)) {
                list.add(function);
            }
        } else {
            for (Iterator children = e.iterateSubExpressions(); children.hasNext();) {
View Full Code Here

        presenter.startElement("functions");
        for (int i=0; i<libraryList.size(); i++) {
            FunctionLibrary lib = (FunctionLibrary)libraryList.get(i);
            if (lib instanceof ExecutableFunctionLibrary) {
                for (Iterator f = ((ExecutableFunctionLibrary)lib).iterateFunctions(); f.hasNext();) {
                    UserFunction func = (UserFunction)f.next();
                    presenter.startElement("function");
                    presenter.emitAttribute("name", func.getFunctionName().getDisplayName());
                    presenter.emitAttribute("line", func.getLineNumber()+"");
                    presenter.emitAttribute("module", func.getSystemId());
                    func.getBody().explain(presenter);
                    presenter.endElement();
                }
            }
        }
        presenter.endElement();
View Full Code Here

        if (fd != null) {
            UserFunctionCall ufc = new UserFunctionCall();
            ufc.setFunctionName(fd.getFunctionName());
            ufc.setArguments(arguments);
            ufc.setStaticType(fd.getResultType());
            UserFunction fn = fd.getUserFunction();
            if (fn == null) {
                // not yet compiled
                fd.registerReference(ufc);
                ufc.setConfirmed(true);
            } else {
View Full Code Here

    public SequenceIterator iterate(XPathContext context) throws XPathException {
        final XPathContextMajor cm = (XPathContextMajor)context;
        while (true) {
            SequenceIterator iter = operand.iterate(cm);
            ValueRepresentation extent = SequenceExtent.makeSequenceExtent(iter);
            UserFunction fn = cm.getTailCallFunction();
            if (fn == null) {
               return Value.asIterator(extent);
            }
            if (fn != containingFunction) {
                return Value.asIterator(tailCallDifferentFunction(fn, cm));
View Full Code Here

    public Item evaluateItem(XPathContext context) throws XPathException {
        final XPathContextMajor cm = (XPathContextMajor)context;
        while (true) {
            Item item = operand.evaluateItem(context);
            UserFunction fn = cm.getTailCallFunction();
            if (fn == null) {
               return item;
            }
            if (fn != containingFunction) {
                return Value.asItem(tailCallDifferentFunction(fn, cm));
View Full Code Here

    public void process(XPathContext context) throws XPathException {
        final XPathContextMajor cm = (XPathContextMajor)context;
        while (true) {
            operand.process(context);
            UserFunction fn = cm.getTailCallFunction();
            if (fn == null) {
               return;
            }
            if (fn != containingFunction) {
                Value.asValue(tailCallDifferentFunction(fn, cm)).process(cm);
View Full Code Here

     * the function call, but no function was found.
     */

    public Expression bind(StructuredQName functionName, Expression[] staticArgs, StaticContext env)
            throws XPathException {
        UserFunction fn = (UserFunction)functions.get(makeKey(functionName, staticArgs.length));
        if (fn == null) {
            return null;
        }
        ExpressionVisitor visitor = ExpressionVisitor.make(env);
        UserFunctionCall fc = new UserFunctionCall();
        fc.setFunctionName(functionName);
        fc.setArguments(staticArgs);
        fc.setFunction(fn);
        fc.checkFunctionCall(fn, visitor);
        fc.setStaticType(fn.getResultType(config.getTypeHierarchy()));
        return fc;
    }
View Full Code Here

TOP

Related Classes of net.sf.saxon.instruct.UserFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.