List of usage examples for javax.xml.bind ValidationEvent getSeverity
public int getSeverity();
From source file:org.plasma.sdo.helper.PlasmaQueryHelper.java
private void writeStagingModel(Model stagingModel, String location, String fileName) { try {//from www. ja v a 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.sdo.helper.PlasmaXSDHelper.java
private void writeSchemaStagingModel(Model stagingModel, String location, String fileName) { try {/* w w w. j a 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.xml.uml.DefaultUMLModelAssembler.java
private Document buildDocumentModel(Query query, String destNamespaceURI, String destNamespacePrefix) { ProvisioningModelAssembler stagingAssembler = new ProvisioningModelAssembler(query, destNamespaceURI, destNamespacePrefix);// w w w. j a va 2s . com 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 va 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.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 ww . j a v a 2s.com 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: ///* www .j a va2 s.c om*/ // 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: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;/*from ww w .j av a2s .c om*/ }