Package net.sf.saxon.instruct

Examples of net.sf.saxon.instruct.UserFunction


    public SequenceType[] getFunctionSignature(StructuredQName functionName, int arity) {
        XSLFunction fn = stylesheet.getStylesheetFunction(functionName, arity);
        if (fn != null) {
            SequenceType[] sig = new SequenceType[arity+1];
            UserFunction uf = fn.getCompiledFunction();
            if (uf == null) {
                // XSLT: function not yet compiled
                Arrays.fill(sig, SequenceType.ANY_SEQUENCE);
            } else {
                UserFunctionParameter[] params = uf.getParameterDefinitions();
                sig[0] = uf.getResultType(stylesheet.getConfiguration().getTypeHierarchy());
                for (int i=0; i<params.length; i++) {
                    sig[i+1] = params[i].getRequiredType();
                }
            }
            return sig;           
View Full Code Here


                    return sig;
                }
            }
            return null;
        }
        UserFunction uf = functions.get(makeKey(functionName, arity));
        if (uf != null) {
            SequenceType[] sig = new SequenceType[arity+1];
            UserFunctionParameter[] params = uf.getParameterDefinitions();
            sig[0] = uf.getResultType(config.getTypeHierarchy());
            for (int i=0; i<params.length; i++) {
                sig[i+1] = params[i].getRequiredType();
            }
            return sig;
        } else {
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 = 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

    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

        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

     * 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

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

        final UserFunction fn1 = exp1.getStaticContext().getUserDefinedFunction("f.ns", "t1", 2);
        if (fn1 == null) {
            throw new IllegalStateException("Function f:t1() not found");
        }
        final Controller controller = exp1.newController();
        final Value[] arglist = new Value[2];
        arglist[0] = new Int64Value(10);
        for (int i = 3; i < 10; i++) {
            arglist[1] = new Int64Value(i);
            final ValueRepresentation result = fn1.call(arglist, controller);
            System.out.println(arglist[0] + " div " + arglist[1] + " = " + result);
        }
    }
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

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.