Example usage for javax.xml.bind ValidationEventLocator getColumnNumber

List of usage examples for javax.xml.bind ValidationEventLocator getColumnNumber

Introduction

In this page you can find the example usage for javax.xml.bind ValidationEventLocator getColumnNumber.

Prototype

public int getColumnNumber();

Source Link

Document

Return the column number if available

Usage

From source file:org.eclipse.smila.utils.jaxb.JaxbUtils.java

/**
 * Creates the validation event handler.
 * /*from  w w w.  j  a va  2s  . co m*/
 * @return the validation event handler
 */
public static ValidationEventHandler createValidationEventHandler() {
    return new ValidationEventHandler() {
        public boolean handleEvent(final ValidationEvent ve) {
            final Log log = LogFactory.getLog(JaxbUtils.class);
            if (ve.getSeverity() != ValidationEvent.WARNING) {
                final ValidationEventLocator vel = ve.getLocator();
                if (log.isErrorEnabled()) {
                    log.error("Line:Col[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + "]:"
                            + ve.getMessage());
                }
                return false;
            }
            return true;
        }
    };
}

From source file:org.modeldriven.fuml.bind.DefaultValidationEventHandler.java

public boolean handleEvent(ValidationEvent ve) {
    boolean result = this.cumulative;
    this.errorCount++;
    ValidationEventLocator vel = ve.getLocator();

    String message = "Line:Col:Offset[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + ":"
            + String.valueOf(vel.getOffset()) + "] - " + ve.getMessage();

    switch (ve.getSeverity()) {
    case ValidationEvent.WARNING:
        log.warn(message);//  w  ww  . j  a  v  a 2  s. c  o  m
        break;
    case ValidationEvent.ERROR:
        log.error(message);
        break;
    case ValidationEvent.FATAL_ERROR:
        log.fatal(message);
        break;
    default:
        log.error(message);
    }
    return result;
}

From source file:org.plasma.config.PlasmaConfigValidationEventHandler.java

public boolean handleEvent(ValidationEvent ve) {
    boolean result = this.cumulative;
    this.errorCount++;
    ValidationEventLocator vel = ve.getLocator();

    String message = "Line:Col:Offset[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + ":"
            + String.valueOf(vel.getOffset()) + "] - " + ve.getMessage();

    switch (ve.getSeverity()) {
    case ValidationEvent.WARNING:
        log.warn(message);/*  w ww . ja v  a  2s. c  o m*/
        break;
    case ValidationEvent.ERROR:
    case ValidationEvent.FATAL_ERROR:
        log.fatal(message);
        throw new ConfigurationException(message);
    default:
        log.error(message);
    }
    return result;
}

From source file:org.plasma.provisioning.cli.XSDTool.java

private static void writeSchemaStagingModel(Model stagingModel, String location, String fileName) {
    try {/*from   w ww .  j  a  va 2  s  .  c om*/
        BindingValidationEventHandler debugHandler = new BindingValidationEventHandler() {
            public int getErrorCount() {
                return 0;
            }

            public boolean handleEvent(ValidationEvent ve) {
                ValidationEventLocator vel = ve.getLocator();

                String message = "Line:Col:Offset[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + ":"
                        + String.valueOf(vel.getOffset()) + "] - " + ve.getMessage();

                switch (ve.getSeverity()) {
                default:
                    //log.debug(message);
                }
                return true;
            }
        };
        ProvisioningModelDataBinding binding = new ProvisioningModelDataBinding(debugHandler);
        String xml = binding.marshal(stagingModel);
        binding.validate(xml);

        File provDebugFile = null;
        if (location != null)
            provDebugFile = new File(location, fileName);
        else
            provDebugFile = File.createTempFile(fileName, "");
        FileOutputStream provDebugos = new FileOutputStream(provDebugFile);
        log.debug("Writing provisioning model to: " + provDebugFile.getAbsolutePath());
        binding.marshal(stagingModel, provDebugos);
    } catch (JAXBException e) {
        log.debug(e.getMessage(), e);
    } catch (SAXException e) {
        log.debug(e.getMessage(), e);
    } catch (IOException e) {
        log.debug(e.getMessage(), e);
    }

}

From source file:org.plasma.sdo.helper.PlasmaQueryHelper.java

private void writeStagingModel(Model stagingModel, String location, String fileName) {
    try {/*  www.ja  v  a  2s  .c o  m*/
        BindingValidationEventHandler debugHandler = new BindingValidationEventHandler() {
            public int getErrorCount() {
                return 0;
            }

            public boolean handleEvent(ValidationEvent ve) {
                ValidationEventLocator vel = ve.getLocator();

                String message = "Line:Col:Offset[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + ":"
                        + String.valueOf(vel.getOffset()) + "] - " + ve.getMessage();

                switch (ve.getSeverity()) {
                default:
                    log.debug(message);
                }
                return true;
            }
        };
        ProvisioningModelDataBinding binding = new ProvisioningModelDataBinding(debugHandler);
        String xml = binding.marshal(stagingModel);
        binding.validate(xml);

        File provDebugFile = null;
        if (location != null)
            provDebugFile = new File(location, fileName);
        else
            provDebugFile = File.createTempFile(fileName, "");
        FileOutputStream provDebugos = new FileOutputStream(provDebugFile);
        log.debug("Writing provisioning model to: " + provDebugFile.getAbsolutePath());
        binding.marshal(stagingModel, provDebugos);
    } catch (JAXBException e) {
        log.debug(e.getMessage(), e);
    } catch (SAXException e) {
        log.debug(e.getMessage(), e);
    } catch (IOException e) {
        log.debug(e.getMessage(), e);
    }

}

From source file:org.plasma.sdo.helper.PlasmaXSDHelper.java

private void writeSchemaStagingModel(Model stagingModel, String location, String fileName) {
    try {//from w w  w.  j a v a 2 s  .  co m
        BindingValidationEventHandler debugHandler = new BindingValidationEventHandler() {
            public int getErrorCount() {
                return 0;
            }

            public boolean handleEvent(ValidationEvent ve) {
                ValidationEventLocator vel = ve.getLocator();

                String message = "Line:Col:Offset[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + ":"
                        + String.valueOf(vel.getOffset()) + "] - " + ve.getMessage();

                switch (ve.getSeverity()) {
                default:
                    log.debug(message);
                }
                return true;
            }
        };
        ProvisioningModelDataBinding binding = new ProvisioningModelDataBinding(debugHandler);
        String xml = binding.marshal(stagingModel);
        binding.validate(xml);

        File provDebugFile = null;
        if (location != null)
            provDebugFile = new File(location, fileName);
        else
            provDebugFile = File.createTempFile(fileName, "");
        FileOutputStream provDebugos = new FileOutputStream(provDebugFile);
        log.debug("Writing provisioning model to: " + provDebugFile.getAbsolutePath());
        binding.marshal(stagingModel, provDebugos);
    } catch (JAXBException e) {
        log.debug(e.getMessage(), e);
    } catch (SAXException e) {
        log.debug(e.getMessage(), e);
    } catch (IOException e) {
        log.debug(e.getMessage(), e);
    }

}

From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java

private Document buildDocumentModel(Query query, String destNamespaceURI, String destNamespacePrefix) {
    ProvisioningModelAssembler stagingAssembler = new ProvisioningModelAssembler(query, destNamespaceURI,
            destNamespacePrefix);//from  w  ww  .  jav a2  s. co m
    Model model = stagingAssembler.getModel();

    if (log.isDebugEnabled()) {
        try {
            BindingValidationEventHandler debugHandler = new BindingValidationEventHandler() {
                public int getErrorCount() {
                    return 0;
                }

                public boolean handleEvent(ValidationEvent ve) {
                    ValidationEventLocator vel = ve.getLocator();

                    String message = "Line:Col:Offset[" + vel.getLineNumber() + ":" + vel.getColumnNumber()
                            + ":" + String.valueOf(vel.getOffset()) + "] - " + ve.getMessage();
                    String sev = "";
                    switch (ve.getSeverity()) {
                    case ValidationEvent.WARNING:
                        sev = "WARNING";
                        break;
                    case ValidationEvent.ERROR:
                        sev = "ERROR";
                        break;
                    case ValidationEvent.FATAL_ERROR:
                        sev = "FATAL_ERROR";
                        break;
                    default:
                    }
                    log.debug(sev + " - " + message);

                    return true;
                }
            };
            ProvisioningModelDataBinding binding = new ProvisioningModelDataBinding(debugHandler);
            String xml = binding.marshal(model);
            binding.validate(xml);
            log.debug(xml);
        } catch (JAXBException e) {
            log.debug(e.getMessage(), e);
        } catch (SAXException e) {
            log.debug(e.getMessage(), e);
        }
    }

    return buildDocumentModel(model, destNamespaceURI, destNamespacePrefix);
}

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

private static void logValidationEvents(URL pluginJarFileUrl, ValidationEventCollector validationEventCollector,
        Log logger) {//from w w w .j  a v a  2s. c o m
    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 w  w  w.j  av  a 2s. c  o  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.ja v  a 2  s  .co m*/
 * @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);
    }
}