Search in sources :

Example 16 with ValidationEvent

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

the class Util method handleTypeMismatchError.

/**
     * Reports that the type of an object in a property is unexpected.  
     */
public static void handleTypeMismatchError(XMLSerializer serializer, Object parentObject, String fieldName, Object childObject) throws AbortSerializationException {
    ValidationEvent ve = new ValidationEventImpl(// maybe it should be a fatal error.
    ValidationEvent.ERROR, Messages.format(Messages.ERR_TYPE_MISMATCH, getUserFriendlyTypeName(parentObject), fieldName, getUserFriendlyTypeName(childObject)), new ValidationEventLocatorExImpl(parentObject, fieldName));
    serializer.reportError(ve);
}
Also used : ValidationEventImpl(javax.xml.bind.helpers.ValidationEventImpl) ValidationEvent(javax.xml.bind.ValidationEvent) ValidationEventLocatorExImpl(com.sun.xml.bind.util.ValidationEventLocatorExImpl)

Example 17 with ValidationEvent

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

the class Util method handlePrintConversionException.

/**
     * Reports a print conversion error while marshalling.
     */
public static void handlePrintConversionException(Object caller, Exception e, XMLSerializer serializer) throws SAXException {
    if (e instanceof SAXException)
        //        will be thrown) 
        throw (SAXException) e;
    String message = e.getMessage();
    if (message == null) {
        message = e.toString();
    }
    ValidationEvent ve = new PrintConversionEventImpl(ValidationEvent.ERROR, message, new ValidationEventLocatorImpl(caller), e);
    serializer.reportError(ve);
}
Also used : ValidationEvent(javax.xml.bind.ValidationEvent) ValidationEventLocatorImpl(javax.xml.bind.helpers.ValidationEventLocatorImpl) PrintConversionEventImpl(javax.xml.bind.helpers.PrintConversionEventImpl) SAXException(org.xml.sax.SAXException)

Example 18 with ValidationEvent

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

the class Util method handleTypeMismatchError.

/**
     * Reports that the type of an object in a property is unexpected.  
     */
public static void handleTypeMismatchError(XMLSerializer serializer, Object parentObject, String fieldName, Object childObject) throws AbortSerializationException {
    ValidationEvent ve = new ValidationEventImpl(// maybe it should be a fatal error.
    ValidationEvent.ERROR, Messages.format(Messages.ERR_TYPE_MISMATCH, getUserFriendlyTypeName(parentObject), fieldName, getUserFriendlyTypeName(childObject)), new ValidationEventLocatorExImpl(parentObject, fieldName));
    serializer.reportError(ve);
}
Also used : ValidationEventImpl(javax.xml.bind.helpers.ValidationEventImpl) ValidationEvent(javax.xml.bind.ValidationEvent) ValidationEventLocatorExImpl(com.sun.xml.bind.util.ValidationEventLocatorExImpl)

Example 19 with ValidationEvent

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

the class Util method handleTypeMismatchError.

/**
     * Reports that the type of an object in a property is unexpected.  
     */
public static void handleTypeMismatchError(XMLSerializer serializer, Object parentObject, String fieldName, Object childObject) throws AbortSerializationException {
    ValidationEvent ve = new ValidationEventImpl(// maybe it should be a fatal error.
    ValidationEvent.ERROR, Messages.format(Messages.ERR_TYPE_MISMATCH, getUserFriendlyTypeName(parentObject), fieldName, getUserFriendlyTypeName(childObject)), new ValidationEventLocatorExImpl(parentObject, fieldName));
    serializer.reportError(ve);
}
Also used : ValidationEventImpl(javax.xml.bind.helpers.ValidationEventImpl) ValidationEvent(javax.xml.bind.ValidationEvent) ValidationEventLocatorExImpl(com.sun.xml.bind.util.ValidationEventLocatorExImpl)

Example 20 with ValidationEvent

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

the class Utils method convertJAXBToElement.

/**
     * Converts a JAXB object to a <code>org.w3c.dom.Element</code>.
     *
     * @param jaxbObj a JAXB object
     * @return a <code>org.w3c.dom.Element</code>
     * @throws JAXBException if an error occurs while converting JAXB object.
     * @supported.api
     */
public static Element convertJAXBToElement(Object jaxbObj, boolean checkIdref) throws JAXBException {
    Marshaller m = jc.createMarshaller();
    try {
        m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl());
    } catch (PropertyException ex) {
        debug.error("Utils.convertJAXBToElement", ex);
    }
    if (!checkIdref) {
        m.setEventHandler(new DefaultValidationEventHandler() {

            public boolean handleEvent(ValidationEvent event) {
                if (event instanceof NotIdentifiableEvent) {
                    return true;
                }
                return super.handleEvent(event);
            }
        });
    }
    Document doc = null;
    try {
        doc = XMLUtils.newDocument();
    } catch (Exception ex) {
        debug.error("Utils.convertJAXBToElement:", ex);
    }
    m.marshal(jaxbObj, doc);
    return doc.getDocumentElement();
}
Also used : Marshaller(javax.xml.bind.Marshaller) PropertyException(javax.xml.bind.PropertyException) ValidationEvent(javax.xml.bind.ValidationEvent) DefaultValidationEventHandler(javax.xml.bind.helpers.DefaultValidationEventHandler) Document(org.w3c.dom.Document) NotIdentifiableEvent(javax.xml.bind.NotIdentifiableEvent) PropertyException(javax.xml.bind.PropertyException) JAXBException(javax.xml.bind.JAXBException)

Aggregations

ValidationEvent (javax.xml.bind.ValidationEvent)31 ValidationEventHandler (javax.xml.bind.ValidationEventHandler)18 Unmarshaller (javax.xml.bind.Unmarshaller)13 JAXBContext (javax.xml.bind.JAXBContext)12 InputSource (org.xml.sax.InputSource)11 SAXSource (javax.xml.transform.sax.SAXSource)10 SAXParser (javax.xml.parsers.SAXParser)9 SAXParserFactory (javax.xml.parsers.SAXParserFactory)9 SAXException (org.xml.sax.SAXException)6 ValidationEventLocatorExImpl (com.sun.xml.bind.util.ValidationEventLocatorExImpl)5 Marshaller (javax.xml.bind.Marshaller)5 PrintConversionEventImpl (javax.xml.bind.helpers.PrintConversionEventImpl)5 ValidationEventImpl (javax.xml.bind.helpers.ValidationEventImpl)5 ValidationEventLocatorImpl (javax.xml.bind.helpers.ValidationEventLocatorImpl)5 JAXBException (javax.xml.bind.JAXBException)3 SchemaFactory (javax.xml.validation.SchemaFactory)3 StringWriter (java.io.StringWriter)2 Writer (java.io.Writer)2 PropertyException (javax.xml.bind.PropertyException)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2