Package net.sf.saxon.xpath

Examples of net.sf.saxon.xpath.DynamicError


    {
        Object obj = Loader.getInstance(className);
        if (obj instanceof URIResolver) {
            return (URIResolver)obj;
        }
        throw new DynamicError("Class " + className + " is not a URIResolver");
    }
View Full Code Here


                                new UntypedAtomicValue(getStringValue()));
        } else {
            SchemaType stype = config.getSchemaType(annotation);
            if (stype == null) {
                String typeName = getNamePool().getDisplayName(annotation);
                throw new DynamicError("Unknown type annotation " +
                        Err.wrap(typeName) + " in document instance");
            } else {
                return stype.getTypedValue(this);
            }
        }
View Full Code Here

            if (tracing) {
                // The exception is often masked, especially when calling extension
                // functions
                System.err.println("No Java class " + className + " could be loaded");
            }
            throw new DynamicError("Failed to load " + className, e );
        }

    }
View Full Code Here

    public static Object getInstance(String className) throws XPathException {
        Class theclass = getClass(className, false);
        try {
            return theclass.newInstance();
        } catch (Exception err) {
            throw new DynamicError("Failed to instantiate class " + className, err);
        }
    }
View Full Code Here

    public GDayValue(){};

    public GDayValue(CharSequence value) throws XPathException {
        Matcher m = regex.matcher(value);
        if (!m.matches()) {
            throw new DynamicError("Cannot convert '" + value + "' to a gDay");
        }
        String base = m.group(1);
        String tz = m.group(2);
        String date = "2000-01-" + base + (tz==null ? "" : tz);
        setLexicalValue(date);
View Full Code Here

        case Type.STRING:
            return new StringValue(getStringValue());
        case Type.UNTYPED_ATOMIC:
            return new UntypedAtomicValue(getStringValue());
        default:
            DynamicError err = new DynamicError("Cannot convert gDay to " +
                    StandardNames.getDisplayName(requiredType));
            err.setErrorCode("FORG0001");
            throw err;
        }
    }
View Full Code Here

    public Item evaluateItem(XPathContext context) throws XPathException {
        if (error instanceof XPathException) {
            throw (XPathException)error;
        } else {
            throw new DynamicError(error);
        }
    }
View Full Code Here

            openDocument();
        }
        if ((properties & ReceiverOptions.NO_SPECIAL_CHARS) == 0) {
            int badchar = testCharacters(chars);
            if (badchar != 0) {
                throw new DynamicError(
                        "Output character not available in this encoding (decimal " + badchar + ")");
            }
        }
        try {
            writer.write(chars.toString());
        } catch (java.io.IOException err) {
            throw new DynamicError(err);
        }
    }
View Full Code Here

                list = new ArrayList(100);
            } else {
                try {
                    list = (Collection)target.newInstance();
                } catch (Exception e) {
                    DynamicError de = new DynamicError("Cannot instantiate collection class " + target);
                    de.setXPathContext(context);
                    throw de;
                }
            }
            SequenceIterator iter = iterate(null);
            while (true) {
                Item it = iter.next();
                if (it == null) {
                    return list;
                }
                list.add(it);
            }
        } else if (target.isArray()) {
            Class component = target.getComponentType();
            if (component.isAssignableFrom(Item.class) ||
                    component.isAssignableFrom(NodeInfo.class) ||
                    component.isAssignableFrom(DocumentInfo.class) ||
                    component.isAssignableFrom(Node.class)) {
                SequenceExtent extent = materialize();
                int length = extent.getLength();
                Object array = Array.newInstance(component, length);
                for (int i=0; i<length; i++) {
                    try {
                        Array.set(array, i, extent.itemAt(i));
                    } catch (Exception err) {
                        DynamicError d = new DynamicError(
                                "Cannot convert item in sequence to the component type of the Java array", err);
                        d.setXPathContext(context);
                        throw d;
                    }
                }
                return array;
            } else {
                // try atomizing the sequence
                SequenceIterator it = new Atomizer(this).iterate(context);
                int length;
                if (it instanceof LastPositionFinder) {
                    length = ((LastPositionFinder)it).getLastPosition();
                } else {
                    SequenceExtent extent = new SequenceExtent(it);
                    length = extent.getLength();
                    it = extent.iterate(context);
                }
                Object array = Array.newInstance(component, length);
                for (int i=0; i<length; i++) {
                    try {
                        AtomicValue val = (AtomicValue)it.next();
                        Object jval = val.convertToJava(component, config, context);
                        Array.set(array, i, jval);
                    } catch (Exception err) {
                        DynamicError d = new DynamicError(
                                "Cannot convert item in atomized sequence to the component type of the Java array", err);
                        d.setXPathContext(context);
                        throw d;
                    }
                }
                return array;
            }

        } else if (target.isAssignableFrom(NodeList.class)) {
            return DOMNodeList.checkAndMake(materialize());
        } else if (target.isAssignableFrom(Item.class) ||
                target.isAssignableFrom(NodeInfo.class) ||
                target.isAssignableFrom(DocumentInfo.class) ||
                target.isAssignableFrom(Node.class)) {

            // try passing the first item in the sequence
            SequenceIterator iter = iterate(null);
            Item first = null;
            while (true) {
                Item next = iter.next();
                if (next == null) {
                    break;
                }
                if (first != null) {
                    DynamicError err = new DynamicError("Sequence contains more than one value; Java method expects only one");
                    err.setXPathContext(context);
                    throw err;
                }
                first = next;
            }
            if (first == null) {
                // sequence is empty; pass a Java null
                return null;
            }
            if (target.isAssignableFrom(first.getClass())) {
                // covers Item, NodeInfo and DOM Node
                return first;
            }
            Object n = first;
            while (n instanceof VirtualNode) {
                // If we've got a wrapper around a DOM or JDOM node, and the user wants a DOM
                // or JDOM node, we unwrap it
                Object vn = ((VirtualNode) n).getUnderlyingNode();
                if (target.isAssignableFrom(vn.getClass())) {
                    return vn;
                } else {
                    n = vn;
                }
            }
            throw new DynamicError("Cannot convert supplied XPath value to the required type for the extension function");
        } else {
            // try atomizing the value
            SequenceIterator it = new Atomizer(this).iterate(context);
            Item first = null;
            while (true) {
                Item next = it.next();
                if (next == null) {
                    break;
                }
                if (first != null) {
                    DynamicError err = new DynamicError("Sequence contains more than one value; Java method expects only one");
                    err.setXPathContext(context);
                    throw err;
                }
                first = next;
            }
            if (first == null) {
View Full Code Here

            // don't evaluate the default if a value has been supplied or if it has already been
            // evaluated by virtue of a forwards reference

        } else {
            if (isRequiredParam()) {
                DynamicError e = new DynamicError("No value supplied for required parameter");
                e.setXPathContext(context);
                e.setErrorCode("XT0700");
                throw e;
            }
            context.setLocalVariable(getSlotNumber(), getSelectValue(context));
        }
        return null;
View Full Code Here

TOP

Related Classes of net.sf.saxon.xpath.DynamicError

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.