Example #1
0
        internal static XdmSequenceType FromSequenceType(JSequenceType seqType)
        {
            XdmItemType itemType = XdmItemType.MakeXdmItemType(seqType.getPrimaryType());
            char        occ;

            if (seqType.getCardinality() == JStaticProperty.ALLOWS_ZERO_OR_MORE)
            {
                occ = '*';
            }
            else if (seqType.getCardinality() == JStaticProperty.ALLOWS_ONE_OR_MORE)
            {
                occ = '+';
            }
            else if (seqType.getCardinality() == JStaticProperty.ALLOWS_ZERO_OR_ONE)
            {
                occ = '?';
            }
            else if (seqType.getCardinality() == JStaticProperty.ALLOWS_ZERO)
            {
                occ = 'º';     //xBA
            }
            else
            {
                occ = ' ';
            }
            return(new XdmSequenceType(itemType, occ));
        }
Example #2
0
        internal static XdmSequenceType FromSequenceType(JSequenceType seqType)
        {
            XdmItemType itemType = XdmItemType.MakeXdmItemType(seqType.getPrimaryType());
            char        occ;

            if (seqType.getCardinality() == JStaticProperty.ALLOWS_ZERO_OR_MORE)
            {
                occ = ZERO_OR_MORE;
            }
            else if (seqType.getCardinality() == JStaticProperty.ALLOWS_ONE_OR_MORE)
            {
                occ = ONE_OR_MORE;
            }
            else if (seqType.getCardinality() == JStaticProperty.ALLOWS_ZERO_OR_ONE)
            {
                occ = ZERO_OR_ONE;
            }
            else if (seqType.getCardinality() == JStaticProperty.ALLOWS_ZERO)
            {
                occ = ZERO;
            }
            else
            {
                occ = ONE;
            }
            if (itemType == null)
            {
                return(null);
            }
            return(new XdmSequenceType(itemType, occ));
        }
Example #3
0
 public override JSequenceType[] getArgumentTypes()
 {
     XdmSequenceType[] dt = definition.ArgumentTypes;
     JSequenceType[]   jt = new JSequenceType[dt.Length];
     for (int i = 0; i < dt.Length; i++)
     {
         jt[i] = dt[i].ToSequenceType();
     }
     return(jt);
 }
Example #4
0
        ///<summary>
        /// Call a global user-defined function in the compiled query.
        ///</summary>
        ///<remarks>
        /// If this is called more than once (to evaluate the same function repeatedly with different arguments,
        /// or to evaluate different functions) then the sequence of evaluations uses the same values of global
        /// variables including external variables (query parameters); the effect of any changes made to query parameters
        /// between calls is undefined.
        /// </remarks>
        /// <param name="function">
        /// The name of the function to be called
        /// </param>
        /// <param name="arguments">
        /// The values of the arguments to be supplied to the function. These
        /// must be of the correct type as defined in the function signature (there is no automatic
        /// conversion to the required type).
        /// </param>
        /// <exception cref="ArgumentException">If no function has been defined with the given name and arity
        /// or if any of the arguments does not match its required type according to the function
        /// signature.</exception>
        /// <exception cref="DynamicError">If a dynamic error occurs in evaluating the function.
        /// </exception>

        public XdmValue CallFunction(QName function, XdmValue[] arguments)
        {
            JUserFunction fn = exp.getMainModule().getUserDefinedFunction(
                function.Uri, function.LocalName, arguments.Length);

            if (fn == null)
            {
                throw new ArgumentException("No function with name " + function.ClarkName +
                                            " and arity " + arguments.Length + " has been declared in the query");
            }
            try {
                // TODO: use the same controller in other interfaces such as run(), and expose it in a trapdoor API
                if (controller == null)
                {
                    controller = exp.newController(context);
                    context.initializeController(controller);
                    controller.initializeController(context.getParameters());
                }
                JSequence[] vr = new JSequence[arguments.Length];

                for (int i = 0; i < arguments.Length; i++)
                {
                    JSequenceType type = fn.getParameterDefinitions()[i].getRequiredType();
                    vr[i] = arguments[i].Unwrap();
                    if (!type.matches(vr[i], controller.getConfiguration().getTypeHierarchy()))
                    {
                        throw new ArgumentException("Argument " + (i + 1) +
                                                    " of function " + function.ClarkName +
                                                    " does not match the required type " + type.toString());
                    }
                }
                JSequence result = fn.call(vr, controller);
                return(XdmValue.Wrap(result));
            } catch (JXPathException e) {
                throw new DynamicError(e);
            }
        }
Example #5
0
        internal JSequenceType ToSequenceType()
        {
            JItemType jit = itemType.Unwrap();

            return(JSequenceType.makeSequenceType(jit, occurrences));
        }
Example #6
0
        internal JSequenceType ToSequenceType()
        {
            JItemTypeType jit = itemType.Unwrap().getUnderlyingItemType();

            return(JSequenceType.makeSequenceType(jit, occurrence));
        }
Example #7
0
        public override JSequenceType getResultType(JSequenceType[] argumentTypes)
        {
            XdmSequenceType[] dt = new XdmSequenceType[argumentTypes.Length];
            for (int i = 0; i < dt.Length; i++)
            {
                dt[i] = XdmSequenceType.FromSequenceType(argumentTypes[i]);
            }

            XdmSequenceType rt = definition.ResultType(dt);
            return rt.ToSequenceType();
        }
Example #8
0
 public override JSequenceType[] getArgumentTypes()
 {
     XdmSequenceType[] dt = definition.ArgumentTypes;
     JSequenceType[] jt = new JSequenceType[dt.Length];
     for (int i = 0; i < dt.Length; i++)
     {
         jt[i] = dt[i].ToSequenceType();
     }
     return jt;
 }
Example #9
0
 internal static XdmSequenceType FromSequenceType(JSequenceType seqType)
 {
     XdmItemType itemType = XdmItemType.MakeXdmItemType(seqType.getPrimaryType());
         char occ;
         if (seqType.getCardinality() == JStaticProperty.ALLOWS_ZERO_OR_MORE)
         {
             occ = '*';
         }
         else if (seqType.getCardinality() == JStaticProperty.ALLOWS_ONE_OR_MORE)
         {
             occ = '+';
         }
         else if (seqType.getCardinality() == JStaticProperty.ALLOWS_ZERO_OR_ONE)
         {
             occ = '?';
         }
         else if (seqType.getCardinality() == JStaticProperty.ALLOWS_ZERO)
         {
             occ = 'º'; //xBA
         }
         else
         {
             occ = ' ';
         }
         return new XdmSequenceType(itemType, occ);
 }