Example usage for javax.xml.bind ValidationEvent getLocator

List of usage examples for javax.xml.bind ValidationEvent getLocator

Introduction

In this page you can find the example usage for javax.xml.bind ValidationEvent getLocator.

Prototype

public ValidationEventLocator getLocator();

Source Link

Document

Retrieve the locator for this warning/error.

Usage

From source file:org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil.java

private static void logValidationEvents(URL pluginJarFileUrl, ValidationEventCollector validationEventCollector,
        Log logger) {//  w w w. j a va 2s  .c  om
    for (ValidationEvent event : validationEventCollector.getEvents()) {
        // First build the message to be logged. The message will look something like this:
        //
        //   Validation fatal error while parsing [jopr-jboss-as-plugin-4.3.0-SNAPSHOT.jar:META-INF/rhq-plugin.xml]
        //   at line 221, column 94: cvc-minInclusive-valid: Value '20000' is not facet-valid with respect to
        //   minInclusive '30000' for type '#AnonType_defaultIntervalmetric'.
        //
        StringBuilder message = new StringBuilder();
        String severity = null;
        switch (event.getSeverity()) {
        case ValidationEvent.WARNING:
            severity = "warning";
            break;
        case ValidationEvent.ERROR:
            severity = "error";
            break;
        case ValidationEvent.FATAL_ERROR:
            severity = "fatal error";
            break;
        }
        message.append("Validation ").append(severity);
        File pluginJarFile = new File(pluginJarFileUrl.getPath());
        message.append(" while parsing [").append(pluginJarFile.getName()).append(":")
                .append(PLUGIN_DESCRIPTOR_PATH).append("]");
        ValidationEventLocator locator = event.getLocator();
        message.append(" at line ").append(locator.getLineNumber());
        message.append(", column ").append(locator.getColumnNumber());
        message.append(": ").append(event.getMessage());

        // Now write the message to the log at an appropriate level.
        switch (event.getSeverity()) {
        case ValidationEvent.WARNING:
        case ValidationEvent.ERROR:
            logger.warn(message);
            break;
        case ValidationEvent.FATAL_ERROR:
            logger.error(message);
            break;
        }
    }
}

From source file:org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorUtil.java

private static void logValidationEvents(URL pluginJarFileUrl,
        ValidationEventCollector validationEventCollector) {
    for (ValidationEvent event : validationEventCollector.getEvents()) {
        // First build the message to be logged. The message will look something like this:
        ////from  ww w. ja  v a2  s .  co  m
        //   Validation fatal error while parsing [jopr-jboss-as-plugin-4.3.0-SNAPSHOT.jar:META-INF/rhq-plugin.xml]
        //   at line 221, column 94: cvc-minInclusive-valid: Value '20000' is not facet-valid with respect to
        //   minInclusive '30000' for type '#AnonType_defaultIntervalmetric'.
        //
        StringBuilder message = new StringBuilder();
        String severity = null;
        switch (event.getSeverity()) {
        case ValidationEvent.WARNING:
            severity = "warning";
            break;
        case ValidationEvent.ERROR:
            severity = "error";
            break;
        case ValidationEvent.FATAL_ERROR:
            severity = "fatal error";
            break;
        }
        message.append("Validation ").append(severity);
        File pluginJarFile = new File(pluginJarFileUrl.getPath());
        message.append(" while parsing [").append(pluginJarFile.getName()).append(":")
                .append(PLUGIN_DESCRIPTOR_PATH).append("]");
        ValidationEventLocator locator = event.getLocator();
        message.append(" at line ").append(locator.getLineNumber());
        message.append(", column ").append(locator.getColumnNumber());
        message.append(": ").append(event.getMessage());

        // Now write the message to the log at an appropriate level.
        switch (event.getSeverity()) {
        case ValidationEvent.WARNING:
        case ValidationEvent.ERROR:
            LOG.warn(message);
            break;
        case ValidationEvent.FATAL_ERROR:
            LOG.error(message);
            break;
        }
    }
}

From source file:org.squidy.designer.model.ModelViewHandler.java

/**
 * Parses a given input stream (should contain model and diagram code as xml
 * structure) and returns it as an object structure.
 * /*from   w  w  w .jav a2s.  c  om*/
 * @param inputStream
 *            The input stream should contain model and diagram structure.
 * @return The parsed XMI document containing model and diagram in object
 *         representation.
 * @throws SquidyException
 */
public Data load(InputStream inputStream) throws SquidyException {
    try {
        Unmarshaller unmarshaller = getContext().createUnmarshaller();
        unmarshaller.setEventHandler(new ValidationEventHandler() {

            /* (non-Javadoc)
             * @see javax.xml.bind.ValidationEventHandler#handleEvent(javax.xml.bind.ValidationEvent)
             */
            public boolean handleEvent(ValidationEvent e) {
                ValidationEventLocator locator = e.getLocator();
                if (LOG.isErrorEnabled()) {
                    LOG.error("Error while reading input stream: \"" + e.getMessage() + "\" [line="
                            + locator.getLineNumber() + ", column=" + locator.getColumnNumber() + "]");
                }
                return true;
            }
        });

        return (Data) unmarshaller.unmarshal(inputStream);
    } catch (JAXBException e) {
        throw new SquidyException("Could not unmarshal input stream.", e);
    }
}

From source file:org.squidy.manager.parser.ModelHandler.java

/**
 * Parses a given input stream (should contain model and diagram code as xml
 * structure) and returns it as an object structure.
 * /*  w  w w  . j a  v a 2s.c o  m*/
 * @param inputStream
 *            The input stream should contain model and diagram structure.
 * @return The parsed XMI document containing model and diagram in object
 *         representation.
 */
@SuppressWarnings("restriction")
public Data load(InputStream inputStream) {
    try {
        Unmarshaller unmarshaller = getContext().createUnmarshaller();
        unmarshaller.setEventHandler(new ValidationEventHandler() {

            /*
             * (non-Javadoc)
             * 
             * @see
             * javax.xml.bind.ValidationEventHandler#handleEvent(javax.xml
             * .bind.ValidationEvent)
             */
            public boolean handleEvent(ValidationEvent e) {
                // Ignore this as workspace-shape is located in not
                // referenced squidy-designer module
                if (e.getMessage().startsWith("unexpected element (uri:\"\", local:\"workspace-shape\")")) {
                    return true;
                }

                ValidationEventLocator locator = e.getLocator();
                if (LOG.isErrorEnabled()) {
                    LOG.error("Error while reading input stream: \"" + e.getMessage() + "\" [line="
                            + locator.getLineNumber() + ", column=" + locator.getColumnNumber() + "]"
                            + e.getLinkedException());
                }
                return true;
            }
        });

        return (Data) unmarshaller.unmarshal(inputStream);
    } catch (JAXBException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(e.getMessage(), e);
        }
        return null;
    }
}

From source file:org.sweble.wikitext.dumpreader.DumpReader.java

private void setSchema(URL schemaUrl) throws Exception {
    SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);

    sf.setResourceResolver(new LSResourceResolverImplementation());

    Schema schema = sf.newSchema(schemaUrl);

    unmarshaller.setSchema(schema);// w ww. j  av a2  s .c om

    unmarshaller.setEventHandler(new ValidationEventHandler() {
        public boolean handleEvent(ValidationEvent ve) {
            try {
                return DumpReader.this.handleEvent(ve, ve.getLocator());
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new WrappedException(e);
            }
        }
    });
}

From source file:securitytools.veracode.http.VeracodeValidationEventHandler.java

@Override
public boolean handleEvent(ValidationEvent event) {
    StringBuilder sb = new StringBuilder();
    sb.append("Severity=").append(event.getSeverity()).append(" ");
    sb.append("Message=").append(event.getMessage()).append(" ");
    sb.append("LinkedException=").append(event.getLinkedException()).append(" ");
    sb.append("Line=").append(event.getLocator().getLineNumber()).append(" ");
    sb.append("Column=").append(event.getLocator().getColumnNumber()).append(" ");
    sb.append("Offset=").append(event.getLocator().getOffset()).append(" ");
    sb.append("Object=").append(event.getLocator().getObject()).append(" ");
    sb.append("Node=").append(event.getLocator().getNode()).append(" ");
    sb.append("URL=").append(event.getLocator().getURL());

    LOG.error(sb.toString(), event.getLinkedException());
    return true;// ww  w  .  java  2s .c  om
}