Search in sources :

Example 1 with ValidationException

use of javax.xml.bind.ValidationException in project OpenAM by OpenRock.

the class ValidatorImpl method validate.

private boolean validate(Object o, boolean validateId) throws ValidationException {
    try {
        //ValidatableObject vo = Util.toValidatableObject(o);
        ValidatableObject vo = jaxbContext.getGrammarInfo().castToValidatableObject(o);
        if (vo == null)
            throw new ValidationException(Messages.format(Messages.NOT_VALIDATABLE));
        EventInterceptor ei = new EventInterceptor(eventHandler);
        ValidationContext context = new ValidationContext(jaxbContext, ei, validateId);
        context.validate(vo);
        context.reconcileIDs();
        return !ei.hadError();
    } catch (SAXException e) {
        // we need a consistent mechanism to convert SAXException into JAXBException
        Exception nested = e.getException();
        if (nested != null) {
            throw new ValidationException(nested);
        } else {
            throw new ValidationException(e);
        }
    //return false;
    }
}
Also used : ValidationException(javax.xml.bind.ValidationException) SAXException(org.xml.sax.SAXException) PropertyException(javax.xml.bind.PropertyException) ValidationException(javax.xml.bind.ValidationException) SAXException(org.xml.sax.SAXException)

Example 2 with ValidationException

use of javax.xml.bind.ValidationException in project OpenAM by OpenRock.

the class ValidatorImpl method validate.

private boolean validate(Object o, boolean validateId) throws ValidationException {
    try {
        //ValidatableObject vo = Util.toValidatableObject(o);
        ValidatableObject vo = jaxbContext.getGrammarInfo().castToValidatableObject(o);
        if (vo == null)
            throw new ValidationException(Messages.format(Messages.NOT_VALIDATABLE));
        EventInterceptor ei = new EventInterceptor(eventHandler);
        ValidationContext context = new ValidationContext(jaxbContext, ei, validateId);
        context.validate(vo);
        context.reconcileIDs();
        return !ei.hadError();
    } catch (SAXException e) {
        // we need a consistent mechanism to convert SAXException into JAXBException
        Exception nested = e.getException();
        if (nested != null) {
            throw new ValidationException(nested);
        } else {
            throw new ValidationException(e);
        }
    //return false;
    }
}
Also used : ValidationException(javax.xml.bind.ValidationException) SAXException(org.xml.sax.SAXException) PropertyException(javax.xml.bind.PropertyException) ValidationException(javax.xml.bind.ValidationException) SAXException(org.xml.sax.SAXException)

Example 3 with ValidationException

use of javax.xml.bind.ValidationException in project OpenAM by OpenRock.

the class ValidatorImpl method validate.

private boolean validate(Object o, boolean validateId) throws ValidationException {
    try {
        //ValidatableObject vo = Util.toValidatableObject(o);
        ValidatableObject vo = jaxbContext.getGrammarInfo().castToValidatableObject(o);
        if (vo == null)
            throw new ValidationException(Messages.format(Messages.NOT_VALIDATABLE));
        EventInterceptor ei = new EventInterceptor(eventHandler);
        ValidationContext context = new ValidationContext(jaxbContext, ei, validateId);
        context.validate(vo);
        context.reconcileIDs();
        return !ei.hadError();
    } catch (SAXException e) {
        // we need a consistent mechanism to convert SAXException into JAXBException
        Exception nested = e.getException();
        if (nested != null) {
            throw new ValidationException(nested);
        } else {
            throw new ValidationException(e);
        }
    //return false;
    }
}
Also used : ValidationException(javax.xml.bind.ValidationException) SAXException(org.xml.sax.SAXException) PropertyException(javax.xml.bind.PropertyException) ValidationException(javax.xml.bind.ValidationException) SAXException(org.xml.sax.SAXException)

Example 4 with ValidationException

use of javax.xml.bind.ValidationException in project OpenAM by OpenRock.

the class ValidatorImpl method validate.

private boolean validate(Object o, boolean validateId) throws ValidationException {
    try {
        //ValidatableObject vo = Util.toValidatableObject(o);
        ValidatableObject vo = jaxbContext.getGrammarInfo().castToValidatableObject(o);
        if (vo == null)
            throw new ValidationException(Messages.format(Messages.NOT_VALIDATABLE));
        EventInterceptor ei = new EventInterceptor(eventHandler);
        ValidationContext context = new ValidationContext(jaxbContext, ei, validateId);
        context.validate(vo);
        context.reconcileIDs();
        return !ei.hadError();
    } catch (SAXException e) {
        // we need a consistent mechanism to convert SAXException into JAXBException
        Exception nested = e.getException();
        if (nested != null) {
            throw new ValidationException(nested);
        } else {
            throw new ValidationException(e);
        }
    //return false;
    }
}
Also used : ValidationException(javax.xml.bind.ValidationException) SAXException(org.xml.sax.SAXException) PropertyException(javax.xml.bind.PropertyException) ValidationException(javax.xml.bind.ValidationException) SAXException(org.xml.sax.SAXException)

Example 5 with ValidationException

use of javax.xml.bind.ValidationException in project tomee by apache.

the class JaxbOpenejb method writeConfig.

public static void writeConfig(final String configFile, final Openejb openejb) throws OpenEJBException {
    OutputStream out = null;
    try {
        final File file = new File(configFile);
        out = IO.write(file);
        marshal(Openejb.class, openejb, out);
    } catch (final IOException e) {
        throw new OpenEJBException(messages().format("conf.1040", configFile, e.getLocalizedMessage()), e);
    } catch (final MarshalException e) {
        if (e.getCause() instanceof IOException) {
            throw new OpenEJBException(messages().format("conf.1040", configFile, e.getLocalizedMessage()), e);
        } else {
            throw new OpenEJBException(messages().format("conf.1050", configFile, e.getLocalizedMessage()), e);
        }
    } catch (final ValidationException e) {
        /* NOTE: This doesn't seem to ever happen. When the object graph
             * is invalid, the MarshalException is thrown, not this one as you
             * would think.
             */
        throw new OpenEJBException(messages().format("conf.1060", configFile, e.getLocalizedMessage()), e);
    } catch (final JAXBException e) {
        throw new OpenEJBException(e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (final Exception e) {
            // no-op
            }
        }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) MarshalException(javax.xml.bind.MarshalException) ValidationException(javax.xml.bind.ValidationException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) File(java.io.File) MarshalException(javax.xml.bind.MarshalException) MalformedURLException(java.net.MalformedURLException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) ValidationException(javax.xml.bind.ValidationException)

Aggregations

ValidationException (javax.xml.bind.ValidationException)5 SAXException (org.xml.sax.SAXException)5 PropertyException (javax.xml.bind.PropertyException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 MalformedURLException (java.net.MalformedURLException)1 JAXBException (javax.xml.bind.JAXBException)1 MarshalException (javax.xml.bind.MarshalException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 OpenEJBException (org.apache.openejb.OpenEJBException)1