Package net.sf.saxon.xpath

Examples of net.sf.saxon.xpath.DynamicError


        } else if (target==Object.class) {
            return getStringValue();
        } else {
            Object o = super.convertToJava(target, config, context);
            if (o == null) {
                throw new DynamicError("Conversion of dateTime to " + target.getName() +
                        " is not supported");
            }
            return o;
        }
    }
View Full Code Here


        Stripper s = controller.makeStripper(b);
        try {
            new Sender(controller.getConfiguration()).send(source, s);
            return b.getCurrentDocument();
        } catch (XPathException err) {
            throw new DynamicError(err);
        }
    }
View Full Code Here

    public FloatValue(CharSequence val) throws DynamicError {
        try {
            this.value = (float)Value.stringToNumber(val);
        } catch (NumberFormatException e) {
            throw new DynamicError("Cannot convert string " + Err.wrap(val, Err.VALUE) + " to a float");
        }
    }
View Full Code Here

        case Type.ATOMIC:
        case Type.ITEM:
            return this;
        case Type.INTEGER:
            if (Float.isNaN(value)) {
                DynamicError err = new DynamicError("Cannot convert float NaN to an integer");
                err.setErrorCode("FORG0001");
                err.setXPathContext(context);
                throw err;
            }
            if (Float.isInfinite(value)) {
                DynamicError err = new DynamicError("Cannot convert float infinity to an integer");
                err.setErrorCode("FORG0001");
                err.setXPathContext(context);
                throw err;
            }
            if (value > Long.MAX_VALUE || value < Long.MIN_VALUE) {
                return new BigIntegerValue(new BigDecimal(value).toBigInteger());
            }
            return new IntegerValue((long)value);
        case Type.DECIMAL:
            return new DecimalValue(value);
        case Type.DOUBLE:
            return new DoubleValue((double)value);
        case Type.STRING:
            return new StringValue(getStringValue());
        case Type.UNTYPED_ATOMIC:
            return new UntypedAtomicValue(getStringValue());
        default:
            DynamicError err = new DynamicError("Cannot convert float to " +
                                     StandardNames.getDisplayName(requiredType));
            err.setXPathContext(context);
            err.setErrorCode("FORG0001");
            throw err;
        }
    }
View Full Code Here

        } else if (target==char.class || target==Character.class) {
            return new Character((char)value);
        } else {
            Object o = super.convertToJava(target, config, context);
            if (o == null) {
                DynamicError err = new DynamicError("Conversion of float to " + target.getName() +
                        " is not supported");
                err.setXPathContext(context);
                err.setErrorCode("SAXON:0000");
            }
            return o;
        }
    }
View Full Code Here

                Object result = invokeConstructor(constructor, params);
                //Object result = constructor.newInstance(params);

                return asIterator(result, context);
            } catch (InstantiationException err0) {
                DynamicError e = new DynamicError("Cannot instantiate class", err0);
                e.setXPathContext(context);
                throw e;
            } catch (IllegalAccessException err1) {
                DynamicError e =  new DynamicError("Constructor access is illegal", err1);
                e.setXPathContext(context);
                throw e;
            } catch (IllegalArgumentException err2) {
                DynamicError e =  new DynamicError("Argument is of wrong type", err2);
                e.setXPathContext(context);
                throw e;
            } catch (NullPointerException err2) {
                DynamicError e =  new DynamicError("Object is null");
                e.setXPathContext(context);
                throw e;
            } catch (InvocationTargetException err3) {
                Throwable ex = err3.getTargetException();
                if (ex instanceof XPathException) {
                    throw (XPathException) ex;
                } else {
                    if (context.getController().isTracing() ||
                            context.getController().getConfiguration().isTraceExternalFunctions()) {
                        err3.getTargetException().printStackTrace();
                    }
                    DynamicError e = new DynamicError("Exception in extension function: " +
                            err3.getTargetException().toString(), ex);
                    e.setXPathContext(context);
                    throw e;
                }
            }
        } else if (theMethod instanceof Method) {
            Method method = (Method) theMethod;
            boolean isStatic = Modifier.isStatic(method.getModifiers());
            Object theInstance;
            theParameterTypes = method.getParameterTypes();
            boolean usesContext = theParameterTypes.length > 0 &&
                    (theParameterTypes[0] == XPathContext.class);
            if (isStatic) {
                theInstance = null;
            } else {
                if (argValues.length == 0) {
                    DynamicError e = new DynamicError("Must supply an argument for an instance-level extension function");
                    e.setXPathContext(context);
                    throw e;
                }
                Value arg0 = argValues[0];
                theInstance = arg0.convertToJava(theClass, config, context);
                // this fails if the first argument is not of a suitable class
            }

            Object[] params = new Object[theParameterTypes.length];

            if (usesContext) {
                params[0] = context;
            }

            setupParams(argValues, params, theParameterTypes,
                    (usesContext ? 1 : 0),
                    (isStatic ? 0 : 1),
                    context
            );

            try {
                Object result = invokeMethod(method, theInstance, params);
                //Object result = method.invoke(theInstance, params);
                if (method.getReturnType().toString().equals("void")) {
                    // method returns void:
                    // tried (method.getReturnType()==Void.class) unsuccessfully
                    return EmptyIterator.getInstance();
                }
                return asIterator(result, context);

            } catch (IllegalAccessException err1) {
                throw new DynamicError("Method access is illegal", err1);
            } catch (IllegalArgumentException err2) {
                throw new DynamicError("Argument is of wrong type", err2);
            } catch (NullPointerException err2) {
                throw new DynamicError("Object is null", err2);
            } catch (InvocationTargetException err3) {
                Throwable ex = err3.getTargetException();
                if (ex instanceof XPathException) {
                    throw (XPathException) ex;
                } else {
                    if (context.getController().isTracing() ||
                            context.getController().getConfiguration().isTraceExternalFunctions()) {
                        err3.getTargetException().printStackTrace();
                    }
                    throw new DynamicError("Exception in extension function " +
                            err3.getTargetException().toString(), ex);
                }
            }
        } else if (theMethod instanceof Field) {

            // Start of code added by GS

            Field field = (Field) theMethod;
            boolean isStatic = Modifier.isStatic(field.getModifiers());
            Object theInstance;
            if (isStatic) {
                theInstance = null;
            } else {
                if (argValues.length == 0) {
                    DynamicError e = new DynamicError("Must supply an argument for an instance-level extension function");
                    e.setXPathContext(context);
                    throw e;
                }
                Value arg0 = argValues[0];
                theInstance = arg0.convertToJava(theClass, config, context);
                // this fails if the first argument is not of a suitable class
            }

            try {
                Object result = getField(field, theInstance);
                return asIterator(result, context);

            } catch (IllegalAccessException err1) {
                DynamicError e = new DynamicError("Field access is illegal", err1);
                e.setXPathContext(context);
                throw e;
            } catch (IllegalArgumentException err2) {
                DynamicError e = new DynamicError("Argument is of wrong type", err2);
                e.setXPathContext(context);
                throw e;
            }
        } else {
            throw new AssertionError("property " + theMethod + " is neither constructor, method, nor field");
        }
View Full Code Here

            badDate("Non-numeric component", s);
        }
    }

    private void badDate(String msg, CharSequence value) throws XPathException {
        DynamicError err = new DynamicError("Invalid date " + Err.wrap(value, Err.VALUE) + ". " + msg);
        err.setErrorCode("FORG0001");
        throw err;
    }
View Full Code Here

            GDayValue gd = new GDayValue();
            gd.setDateValue(this);
            return gd;

        default:
            DynamicError err = new DynamicError("Cannot convert date to " +
                                     StandardNames.getDisplayName(requiredType));
            err.setXPathContext(context);
            err.setErrorCode("FORG0001");
            throw err;
        }
    }
View Full Code Here

        } else if (target==Object.class) {
            return getStringValue();
        } else {
            Object o = super.convertToJava(target, config, context);
            if (o == null) {
                throw new DynamicError("Conversion of date to " + target.getName() +
                        " is not supported");
            }
            return o;
        }
    }
View Full Code Here

            int months = ((MonthDurationValue)duration).getLengthInMonths();
            GregorianCalendar cal2 = (GregorianCalendar)calendar.clone();
            cal2.add(Calendar.MONTH, months);
            return new DateValue(cal2, zoneSpecified, tzOffset);
        } else {
            DynamicError err = new DynamicError(
                    "Date arithmetic is not supported on xs:duration, only on its subtypes");
            err.setIsTypeError(true);
            throw err;
        }
    }
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.