Package javax.xml.bind

Examples of javax.xml.bind.ValidationEventHandler


         Unmarshaller u = jc.createUnmarshaller();        

         if (schema != null) {
            SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
            u.setSchema(factory.newSchema(new StreamSource(schema)));
            u.setEventHandler(new ValidationEventHandler() {
               @Override
               public boolean handleEvent(ValidationEvent event) {              
                  int severity = event.getSeverity();
                  return (severity != ValidationEvent.FATAL_ERROR && severity != ValidationEvent.ERROR);
               }
View Full Code Here


        final SAXParser parser = Saxs.namespaceAwareFactory().newSAXParser();

        final JAXBContext ctx = getContext(type);
        final Unmarshaller unmarshaller = ctx.createUnmarshaller();
        unmarshaller.setEventHandler(new ValidationEventHandler() {
            public boolean handleEvent(final ValidationEvent validationEvent) {
                System.out.println(validationEvent);
                return false;
            }
        });
View Full Code Here

        if (schema != null) {
            SchemaFactory factory = getOrCreateSchemaFactory();
            try {
                Schema newSchema = factory.newSchema(getSources());
                unmarshaller.setSchema(newSchema);
                unmarshaller.setEventHandler(new ValidationEventHandler() {
                    public boolean handleEvent(ValidationEvent event) {
                        // stop unmarshalling if the event is an ERROR or FATAL ERROR
                        return event.getSeverity() == ValidationEvent.WARNING;
                    }
                });
View Full Code Here

        if (schema != null) {
            SchemaFactory factory = getOrCreateSchemaFactory();
            try {
                Schema newSchema = factory.newSchema(getSources());
                marshaller.setSchema(newSchema);
                marshaller.setEventHandler(new ValidationEventHandler() {
                    public boolean handleEvent(ValidationEvent event) {
                        // stop marshalling if the event is an ERROR or FATAL ERROR
                        return event.getSeverity() == ValidationEvent.WARNING;
                    }
                });
View Full Code Here

    protected Unmarshaller createUnmarshaller() throws JAXBException, SAXException, FileNotFoundException,
        MalformedURLException {
        Unmarshaller unmarshaller = getContext().createUnmarshaller();
        if (schema != null) {
            unmarshaller.setSchema(cachedSchema);
            unmarshaller.setEventHandler(new ValidationEventHandler() {
                public boolean handleEvent(ValidationEvent event) {
                    // stop unmarshalling if the event is an ERROR or FATAL
                    // ERROR
                    return event.getSeverity() == ValidationEvent.WARNING;
                }
View Full Code Here

    protected Marshaller createMarshaller() throws JAXBException, SAXException, FileNotFoundException,
        MalformedURLException {
        Marshaller marshaller = getContext().createMarshaller();
        if (schema != null) {
            marshaller.setSchema(cachedSchema);
            marshaller.setEventHandler(new ValidationEventHandler() {
                public boolean handleEvent(ValidationEvent event) {
                    // stop marshalling if the event is an ERROR or FATAL ERROR
                    return event.getSeverity() == ValidationEvent.WARNING;
                }
            });
View Full Code Here

        endAttributes();
    }


    public void reportError( ValidationEvent ve ) throws SAXException {
        ValidationEventHandler handler;

        try {
            handler = marshaller.getEventHandler();
        } catch( JAXBException e ) {
            throw new SAXException2(e);
        }

        if(!handler.handleEvent(ve)) {
            if(ve.getLinkedException() instanceof Exception)
                throw new SAXException2((Exception)ve.getLinkedException());
            else
                throw new SAXException2(ve.getMessage());
        }
View Full Code Here

            ArrayList<Object> cycle = new ArrayList<Object>(stack);
            Collections.reverse(cycle);
            cycle.add(bean);
            String message = "Marshal cycle detected " + cycle;
            if (marshaller != null) {
                ValidationEventHandler validationEventHandler = marshaller.getEventHandler();
                if (validationEventHandler != null) {
                    validationEventHandler.handleEvent(new ValidationEventImpl(ValidationEvent.FATAL_ERROR, message, new ValidationEventLocatorImpl(bean, null)));
                }
            }
            throw new UnmarshalException(message);

        }
View Full Code Here

    private void validationError(String message, Location location, Throwable cause) throws JAXBException {
        validationError(message, new ValidationEventLocatorImpl(location), cause);
    }

    private void validationError(String message, ValidationEventLocatorImpl locator, Throwable cause) throws JAXBException {
        ValidationEventHandler validationEventHandler = null;
        if (marshaller != null) {
            validationEventHandler = marshaller.getEventHandler();
        } else if (unmarshaller != null) {
            validationEventHandler = unmarshaller.getEventHandler();
        }
        if (validationEventHandler == null || !validationEventHandler.handleEvent(new ValidationEventImpl(ValidationEvent.ERROR, message, locator, cause))) {
            throw new UnmarshalException(message, cause);
        }
    }
View Full Code Here

//
    private final UnmarshallerImpl parent;
    private boolean aborted = false;
   
    public void handleEvent(ValidationEvent event, boolean canRecover ) throws SAXException {
        ValidationEventHandler eventHandler;
        try {
            eventHandler = parent.getEventHandler();
        } catch( JAXBException e ) {
            // impossible.
            throw new JAXBAssertionError();
        }

        boolean recover = eventHandler.handleEvent(event);
       
        // if the handler says "abort", we will not return the object
        // from the unmarshaller.getResult()
        if(!recover)    aborted = true;
       
View Full Code Here

TOP

Related Classes of javax.xml.bind.ValidationEventHandler

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.