List of usage examples for javax.xml.bind ValidationEventLocator getLineNumber
public int getLineNumber();
From source file:org.eclipse.smila.utils.jaxb.JaxbUtils.java
/** * Creates the validation event handler. * //w ww . ja va2 s. c o 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);// ww w . j a va 2 s .co 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.multicore_association.measure.mem.generate.MemCodeGen.java
/** * Get the data which need to make CSource from SHIM file. * @return Flag for success judgements//from w w w.j ava2s .com */ private boolean getDataFromShim() { boolean ch = true; try { JAXBContext context = JAXBContext.newInstance(PACKAGENAME); Unmarshaller unmarshaller = context.createUnmarshaller(); /* validation check setup */ if (!shimSchemaPath.equals("")) { SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new File(shimSchemaPath)); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(new ValidationEventHandler() { @Override public boolean handleEvent(ValidationEvent event) { if ((event.getSeverity() == ValidationEvent.FATAL_ERROR) || (event.getSeverity() == ValidationEvent.ERROR)) { ValidationEventLocator loc = event.getLocator(); parseErrList.add(" Line[" + loc.getLineNumber() + "] : " + event.getMessage()); } return true; } }); } sysConf = unmarshaller.unmarshal(new StreamSource(shimf), SystemConfiguration.class).getValue(); if (parseErrList.size() > 0) { System.err.println("Error: input SHIM file validation error"); System.err.println(" Validation error location:"); for (int i = 0; i < parseErrList.size(); i++) { System.err.println(parseErrList.get(i)); } return false; } // JAXBElement<SystemConfiguration> root = unmarshaller.unmarshal(new StreamSource(shimf), SystemConfiguration.class); // sysConf = root.getValue(); } catch (Exception e) { System.err.println("Error: failed to parse the SHIM file, please check the contents of the file"); return false; } ch = makeCPUListFromShim(); if (!ch) { return ch; } ch = makeSlaveListFromShim(); if (!ch) { return ch; } ch = makeAddressSpaceListFromShim(); if (!ch) { return ch; } ch = makeAccessPatternListFromShim(); if (!ch) { return ch; } return ch; }
From source file:org.multicore_association.measure.mem.writeback.SetResultToShim.java
/** * Set the value to read the existing SHIM file. * @return Flag for success judgements//from w ww . j a v a 2s.c o m * @throws ShimFileFormatException * @throws ShimFileGenerateException */ private static boolean appendToExistingShim() { /* * append to existing llvm-shim */ SystemConfiguration sysConf = null; try { JAXBContext context = JAXBContext.newInstance(SystemConfiguration.class); Unmarshaller unmarshaller = context.createUnmarshaller(); /* validation check setup */ if (!shimSchemaPath.equals("")) { SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new File(shimSchemaPath)); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(new ValidationEventHandler() { @Override public boolean handleEvent(ValidationEvent event) { if ((event.getSeverity() == ValidationEvent.FATAL_ERROR) || (event.getSeverity() == ValidationEvent.ERROR)) { ValidationEventLocator loc = event.getLocator(); parseErrList.add(" Line[" + loc.getLineNumber() + "] : " + event.getMessage()); } return true; } }); } sysConf = unmarshaller.unmarshal(new StreamSource(shimf), SystemConfiguration.class).getValue(); if (parseErrList.size() > 0) { System.err.println("Error: input SHIM file validation error"); System.err.println(" Validation error location:"); for (int i = 0; i < parseErrList.size(); i++) { System.err.println(parseErrList.get(i)); } return false; } } catch (Exception e) { System.err.println("Error: failed to parse the SHIM file, please check the contents of the file"); e.printStackTrace(); return false; } AddressSpaceSet addrSpaceSet = sysConf.getAddressSpaceSet(); if (addrSpaceSet == null) { System.err.println("Error: failed to parse the SHIM file, please check the contents of the file"); return false; } List<AddressSpace> addrSpaceList = addrSpaceSet.getAddressSpace(); if (addrSpaceList == null) { System.err.println("Error: failed to parse the SHIM file, please check the contents of the file"); return false; } masterComponentMap = new HashMap<String, MasterComponent>(); slaveComponentMap = new HashMap<String, SlaveComponent>(); accessTypeMap = new HashMap<String, AccessType>(); List<String> route = new ArrayList<String>(); ComponentSet cs = sysConf.getComponentSet(); route.add(cs.getName()); makeRefMapFromComponentSet(cs, route); for (int i = 0; i < measureList.size(); i++) { MeasurementsCSVData data = measureList.get(i); route.clear(); /* * search AddressSpaceName */ AddressSpace addrSp = null; for (Iterator<AddressSpace> j = addrSpaceList.iterator(); j.hasNext();) { AddressSpace as = j.next(); if (as.getName() != null && as.getName().equals(data.getAddressSpaceName())) { addrSp = as; break; } } if (addrSp == null) { System.err.println("Error: Unknown 'Address Space' name (\"" + data.getAddressSpaceName() + "\")."); return false; } route.add(addrSp.getName()); /* * search SubSpaceName */ SubSpace subSp = null; List<SubSpace> ssList = addrSp.getSubSpace(); for (Iterator<SubSpace> j = ssList.iterator(); j.hasNext();) { SubSpace ss = j.next(); route.add(ss.getName()); String path = createPathName(route); route.remove(ss.getName()); if (path != null && path.equals(data.getSubSpaceName())) { subSp = ss; break; } } if (subSp == null) { System.err.println("Error: Unknown 'Sub Space' name (\"" + data.getSubSpaceName() + "\")."); return false; } /* * search SlaveComponentRef in MasterSlaveBinding */ MasterSlaveBindingSet msBindSet = null; msBindSet = subSp.getMasterSlaveBindingSet(); if (msBindSet == null) { continue; } MasterSlaveBinding msBind = null; List<MasterSlaveBinding> msBindList = msBindSet.getMasterSlaveBinding(); SlaveComponent scComp = slaveComponentMap.get(data.getSlaveComponentName()); if (scComp == null) { System.err.println( "Error: Unknown 'Slave Comonent' name (\"" + data.getSlaveComponentName() + "\")."); return false; } for (Iterator<MasterSlaveBinding> j = msBindList.iterator(); j.hasNext();) { MasterSlaveBinding msb = j.next(); SlaveComponent sca = (SlaveComponent) msb.getSlaveComponentRef(); if (sca != null && sca.getId().equals(scComp.getId())) { msBind = msb; break; } } if (msBind == null) { continue; } /* * search MasterComponentRef in Accessor */ Accessor accessor = null; List<Accessor> acList = msBind.getAccessor(); MasterComponent mcComp = masterComponentMap.get(data.getMasterComponentName()); if (mcComp == null) { System.err.println( "Error: Unknown 'Master Comonent' name (\"" + data.getMasterComponentName() + "\")."); return false; } for (Iterator<Accessor> j = acList.iterator(); j.hasNext();) { Accessor ac = j.next(); MasterComponent mc = (MasterComponent) ac.getMasterComponentRef(); if (mc != null && mc.getId().equals(mcComp.getId())) { accessor = ac; break; } } if (accessor == null) { continue; } /* * search PerformanceSet */ PerformanceSet perfrmSet = null; if (accessor.getPerformanceSet().size() != 0) { perfrmSet = accessor.getPerformanceSet().get(0); } if (perfrmSet == null) { continue; } /* * search Performance */ List<Performance> pfrmList = perfrmSet.getPerformance(); AccessType atComp = accessTypeMap.get(data.getAccessTypeName()); if (atComp == null) { System.err.println("Error: Unknown 'Access Type' name (\"" + data.getAccessTypeName() + "\")."); return false; } for (Iterator<Performance> j = pfrmList.iterator(); j.hasNext();) { Performance pfm = j.next(); AccessType at = (AccessType) pfm.getAccessTypeRef(); if (at != null && at.getId().equals(atComp.getId())) { Latency latency = new Latency(); Pitch pitch = new Pitch(); latency.setBest(data.getBestLatency()); latency.setWorst(data.getWorstLatency()); latency.setTypical(data.getTypicalLatency()); pitch.setBest(data.getBestPitch()); pitch.setWorst(data.getWorstPitch()); pitch.setTypical(data.getTypicalPitch()); pfm.setLatency(latency); pfm.setPitch(pitch); break; } } } try { JAXBContext context = JAXBContext.newInstance(SystemConfiguration.class.getPackage().getName()); Marshaller marshaller = context.createMarshaller(); /* validation check setup */ if (!shimSchemaPath.equals("")) { SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new File(shimSchemaPath)); marshaller.setSchema(schema); } QName qname = new QName("", "SystemConfiguration"); JAXBElement<SystemConfiguration> elem = new JAXBElement<SystemConfiguration>(qname, SystemConfiguration.class, sysConf); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // marshaller.marshal(elem, new PrintStream(shimf)); marshaller.marshal(elem, System.out); } catch (JAXBException e) { e.printStackTrace(); System.err.println("Error: exception occurs in SHIM file generation"); //$NON-NLS-1$ return false; } catch (SAXException e) { e.printStackTrace(); System.err.println("Error: output SHIM file validation error"); //$NON-NLS-1$ return false; } return true; }
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 www .ja v a 2 s.c om 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 ww . j ava2 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.sdo.helper.PlasmaQueryHelper.java
private void writeStagingModel(Model stagingModel, String location, String fileName) { try {/*from w ww .ja v a2 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 {//from w w w . j a v a 2s.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.xml.uml.DefaultUMLModelAssembler.java
private Document buildDocumentModel(Query query, String destNamespaceURI, String destNamespacePrefix) { ProvisioningModelAssembler stagingAssembler = new ProvisioningModelAssembler(query, destNamespaceURI, destNamespacePrefix);/*from ww w . java 2s .c om*/ 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) {// 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; } } }