use of org.exolab.castor.xml.ValidationException in project opennms by OpenNMS.
the class SpectrumTrapImporter method main.
public static void main(String[] argv) {
SpectrumTrapImporter importer = new SpectrumTrapImporter();
importer.configureArgs(argv);
try {
importer.afterPropertiesSet();
} catch (Throwable e) {
importer.printHelp("Fatal exception caught at startup: " + e.getMessage());
System.exit(1);
}
Events events = new Events();
try {
events = importer.makeEvents();
} catch (IOException e) {
importer.printHelp("Fatal exception caught at runtime: " + e.getMessage());
}
try {
// events.marshal(importer.getOutputWriter());
StringWriter sw = new StringWriter();
events.marshal(sw);
importer.prettyPrintXML(sw.toString());
} catch (MarshalException e) {
importer.printHelp("Fatal exception while marshaling output: " + e.getMessage());
} catch (ValidationException e) {
importer.printHelp("Fatal exception while validating output: " + e.getMessage());
} catch (IOException e) {
importer.printHelp("Fatal I/O exception: " + e.getMessage(), e);
} catch (SAXException e) {
importer.printHelp("Fatal SAX exception: " + e.getMessage());
} catch (ParserConfigurationException e) {
importer.printHelp("Fatal parser configuration exception: " + e.getMessage());
}
}
use of org.exolab.castor.xml.ValidationException in project ACS by ACS-Community.
the class CompHelperGenerator method getFilePar.
/**
* Method getFilePar. Gets information about COBs from xml input string.
* @param contents
* @return ComponentHelperInfo
*/
protected ComponentHelperInfo getFilePar(String contents) {
ComponentHelperInfo compHelpInfo = null;
if (m_verbose) {
System.out.println(contents);
}
Reader xmlReader = null;
try {
xmlReader = new StringReader(contents);
if (xmlReader != null) {
compHelpInfo = ComponentHelperInfo.unmarshalComponentHelperInfo(xmlReader);
}
} catch (ValidationException e) {
e.printStackTrace();
} catch (MarshalException e) {
e.printStackTrace();
} finally {
if (xmlReader != null)
try {
xmlReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return compHelpInfo;
}
use of org.exolab.castor.xml.ValidationException in project OpenClinica by OpenClinica.
the class DownloadRuleSetXmlServlet method handleLoadCastor.
private FileWriter handleLoadCastor(FileWriter writer, RulesPostImportContainer rpic) {
try {
// Create Mapping
Mapping mapping = new Mapping();
mapping.loadMapping(getCoreResources().getURL("mappingMarshaller.xml"));
// Create XMLContext
XMLContext xmlContext = new XMLContext();
xmlContext.addMapping(mapping);
Marshaller marshaller = xmlContext.createMarshaller();
marshaller.setWriter(writer);
marshaller.marshal(rpic);
return writer;
} catch (FileNotFoundException ex) {
throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
} catch (IOException ex) {
throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
} catch (MarshalException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (ValidationException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (MappingException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (Exception e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
}
}
use of org.exolab.castor.xml.ValidationException in project ACS by ACS-Community.
the class ACSAlarmDAOImpl method updateFaultFamily.
public void updateFaultFamily(FaultFamily ff) {
if (conf == null || !conf.isWriteable())
throw new IllegalStateException("no writable configuration accessor");
if (ff == null)
throw new IllegalArgumentException("Null FaultFamily argument");
StringWriter FFWriter = new StringWriter();
Marshaller FF_marshaller;
try {
FF_marshaller = new Marshaller(FFWriter);
} catch (IOException e) {
e.printStackTrace();
return;
}
FF_marshaller.setValidation(false);
try {
FF_marshaller.marshal(ff);
} catch (MarshalException e) {
e.printStackTrace();
return;
} catch (ValidationException e) {
e.printStackTrace();
return;
}
String path = ALARM_DEFINITION_PATH + "/" + ff.getName();
try {
try {
conf.getConfiguration(path);
conf.deleteConfiguration(path);
} catch (CDBRecordDoesNotExistEx e) {
//Record does not exist, so we skip removing it.
throw new IllegalStateException("FaultFamily doesn't exist");
}
conf.addConfiguration(path, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
} catch (IllegalStateException e) {
throw e;
} catch (Exception e) {
e.printStackTrace();
return;
}
Vector<FaultFamily> ffs = new Vector<FaultFamily>();
ffs.add(ff);
removeAlarmsMap(ffs);
generateAlarmsMap(ffs);
}
use of org.exolab.castor.xml.ValidationException in project ACS by ACS-Community.
the class ACSAlarmDAOImpl method addFaultFamily.
public void addFaultFamily(FaultFamily ff) {
if (conf == null || !conf.isWriteable())
throw new IllegalStateException("no writable configuration accessor");
if (ff == null)
throw new IllegalArgumentException("Null FaultFamily argument");
StringWriter FFWriter = new StringWriter();
Marshaller FF_marshaller;
try {
FF_marshaller = new Marshaller(FFWriter);
} catch (IOException e) {
e.printStackTrace();
return;
}
FF_marshaller.setValidation(false);
try {
FF_marshaller.marshal(ff);
} catch (MarshalException e) {
e.printStackTrace();
return;
} catch (ValidationException e) {
e.printStackTrace();
return;
}
String path = ALARM_DEFINITION_PATH + "/" + ff.getName();
try {
conf.addConfiguration(path, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
} catch (Exception e) {
throw new IllegalStateException("FaultFamily already exists");
}
Vector<FaultFamily> ffs = new Vector<FaultFamily>();
ffs.add(ff);
generateAlarmsMap(ffs);
}
Aggregations