Example usage for javax.xml.bind ValidationEvent getMessage

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

Introduction

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

Prototype

public String getMessage();

Source Link

Document

Retrieve the text message for this warning/error.

Usage

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);//from  w w w .j a va2  s .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 {//  w w w .java  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.PlasmaQueryHelper.java

private void writeStagingModel(Model stagingModel, String location, String fileName) {
    try {/*w ww. j a  va2 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.PlasmaXSDHelper.java

private void writeSchemaStagingModel(Model stagingModel, String location, String fileName) {
    try {/*www . j  ava  2 s  . 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.xml.uml.DefaultUMLModelAssembler.java

private Document buildDocumentModel(Query query, String destNamespaceURI, String destNamespacePrefix) {
    ProvisioningModelAssembler stagingAssembler = new ProvisioningModelAssembler(query, destNamespaceURI,
            destNamespacePrefix);//from   ww  w .j  av 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  ava2s  .  co 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.plugins.url.XmlIndexParser.java

@SuppressWarnings("unchecked")
protected Map<String, RemotePackageInfo> jaxbParse(InputStream indexStream, URL indexUrl, String rootUrlString)
        throws Exception {

    JAXBContext jaxbContext = JAXBContext.newInstance(XmlSchemas.PKG_CONTENTSOURCE_PACKAGEDETAILS);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

    // Enable schema validation
    URL pluginSchemaURL = XmlIndexParser.class.getClassLoader().getResource(PLUGIN_SCHEMA_PATH);
    Schema pluginSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
            .newSchema(pluginSchemaURL);
    unmarshaller.setSchema(pluginSchema);

    ValidationEventCollector vec = new ValidationEventCollector();
    unmarshaller.setEventHandler(vec);//from w  w  w  .  j a v a 2 s.c o m

    BufferedReader reader = new BufferedReader(new InputStreamReader(indexStream));
    JAXBElement<PackageType> packagesXml = (JAXBElement<PackageType>) unmarshaller.unmarshal(reader);

    for (ValidationEvent event : vec.getEvents()) {
        log.debug("URL content source index [" + indexUrl + "] message {Severity: " + event.getSeverity()
                + ", Message: " + event.getMessage() + ", Exception: " + event.getLinkedException() + "}");
    }

    Map<String, RemotePackageInfo> fileList = new HashMap<String, RemotePackageInfo>();

    List<PackageDetailsType> allPackages = packagesXml.getValue().getPackage();
    for (PackageDetailsType pkg : allPackages) {
        URL locationUrl = new URL(rootUrlString + pkg.getLocation());
        ContentProviderPackageDetails details = translateXmlToDomain(pkg);
        FullRemotePackageInfo rpi = new FullRemotePackageInfo(locationUrl, details);
        fileList.put(stripLeadingSlash(rpi.getLocation()), rpi);
    }

    return fileList;
}

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:
        ///* w  w w.  ja  va2  s.  com*/
        //   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.
 * //  www.  ja  va 2  s .  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  ww. java  2 s. 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;
    }
}