Search in sources :

Example 11 with ValidationException

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());
    }
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) StringWriter(java.io.StringWriter) Events(org.opennms.netmgt.xml.eventconf.Events) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 12 with ValidationException

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;
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) IOException(java.io.IOException) ComponentHelperInfo(alma.acs.tools.comphelpergen.generated.ComponentHelperInfo)

Example 13 with ValidationException

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());
    }
}
Also used : Marshaller(org.exolab.castor.xml.Marshaller) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) XMLContext(org.exolab.castor.xml.XMLContext) FileNotFoundException(java.io.FileNotFoundException) Mapping(org.exolab.castor.mapping.Mapping) IOException(java.io.IOException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) MappingException(org.exolab.castor.mapping.MappingException) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) MappingException(org.exolab.castor.mapping.MappingException)

Example 14 with ValidationException

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);
}
Also used : Marshaller(org.exolab.castor.xml.Marshaller) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) IOException(java.io.IOException) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) PatternSyntaxException(java.util.regex.PatternSyntaxException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx) StringWriter(java.io.StringWriter) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) Vector(java.util.Vector)

Example 15 with ValidationException

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);
}
Also used : Marshaller(org.exolab.castor.xml.Marshaller) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) StringWriter(java.io.StringWriter) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) IOException(java.io.IOException) Vector(java.util.Vector) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) PatternSyntaxException(java.util.regex.PatternSyntaxException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

ValidationException (org.exolab.castor.xml.ValidationException)19 MarshalException (org.exolab.castor.xml.MarshalException)16 IOException (java.io.IOException)15 StringWriter (java.io.StringWriter)7 Marshaller (org.exolab.castor.xml.Marshaller)7 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)6 StringReader (java.io.StringReader)6 Unmarshaller (org.exolab.castor.xml.Unmarshaller)6 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)5 FileNotFoundException (java.io.FileNotFoundException)4 MalformedURLException (java.net.MalformedURLException)4 PatternSyntaxException (java.util.regex.PatternSyntaxException)4 FaultFamily (alma.acs.alarmsystem.generated.FaultFamily)3 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 Mapping (org.exolab.castor.mapping.Mapping)3 MappingException (org.exolab.castor.mapping.MappingException)3 XMLContext (org.exolab.castor.xml.XMLContext)3 Categories (alma.acs.alarmsystem.generated.Categories)2 ReductionDefinitions (alma.alarmsystem.alarmmessage.generated.ReductionDefinitions)2 ReductionLinkType (alma.alarmsystem.alarmmessage.generated.ReductionLinkType)2