Search in sources :

Example 6 with ValidationException

use of org.exolab.castor.xml.ValidationException in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method flushReductionRules.

public void flushReductionRules(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions rds) {
    if (conf == null || !conf.isWriteable())
        throw new IllegalStateException("no writable configuration accessor");
    if (rds == null)
        throw new IllegalArgumentException("Null Reduction Definitions 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(rds);
    } catch (MarshalException e) {
        e.printStackTrace();
        return;
    } catch (ValidationException e) {
        e.printStackTrace();
        return;
    }
    try {
        conf.deleteConfiguration(REDUCTION_DEFINITION_PATH);
        conf.addConfiguration(REDUCTION_DEFINITION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
    //System.err.println(FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
    } catch (org.omg.CORBA.UNKNOWN e) {
        try {
            conf.addConfiguration(REDUCTION_DEFINITION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new IllegalStateException("Reduction Rules already exists");
    }
}
Also used : Marshaller(org.exolab.castor.xml.Marshaller) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) StringWriter(java.io.StringWriter) 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)

Example 7 with ValidationException

use of org.exolab.castor.xml.ValidationException in project ACS by ACS-Community.

the class AlarmManager method saveToCDB.

public void saveToCDB() {
    Set<String> keyset = _objState.keySet();
    String[] objs = new String[keyset.size()];
    keyset.toArray(objs);
    for (int i = 0; i < objs.length; i++) {
        try {
            ObjectState os = _objState.get(objs[i]);
            FaultFamily ff = getFaultFamily(objs[i]);
            if (ff != null)
                ff.validate();
            switch(os.getAction()) {
                case //Error, no state assigned.
                -1:
                    break;
                case 0:
                    break;
                case 1:
                    ((ACSAlarmDAOImpl) _alarmDAO).addFaultFamily(ff);
                    break;
                case 2:
                    ((ACSAlarmDAOImpl) _alarmDAO).updateFaultFamily(ff);
                    break;
                case 3:
                    ff = new FaultFamily();
                    ff.setName(objs[i]);
                    ((ACSAlarmDAOImpl) _alarmDAO).removeFaultFamily(ff);
                    break;
                default:
                    //Shouldn't happen.
                    break;
            }
            _objState.remove(objs[i]);
            _objState.put(objs[i], new ObjectState(false));
        } catch (ValidationException e) {
            e.printStackTrace();
        }
    }
}
Also used : ValidationException(org.exolab.castor.xml.ValidationException) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) ACSAlarmDAOImpl(cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)

Example 8 with ValidationException

use of org.exolab.castor.xml.ValidationException in project ACS by ACS-Community.

the class ACSCategoryDAOImpl method flushCategories.

public void flushCategories(Categories cats) {
    if (conf == null || !conf.isWriteable())
        throw new IllegalStateException("no writable configuration accessor");
    if (cats == null)
        throw new IllegalArgumentException("Null Categories 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(cats);
    } catch (MarshalException e) {
        e.printStackTrace();
        return;
    } catch (ValidationException e) {
        e.printStackTrace();
        return;
    }
    try {
        conf.deleteConfiguration(CATEGORY_DEFINITION_PATH);
        conf.addConfiguration(CATEGORY_DEFINITION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
    } catch (org.omg.CORBA.UNKNOWN e) {
        try {
            conf.addConfiguration(CATEGORY_DEFINITION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    } catch (CDBXMLErrorEx e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
        throw new IllegalStateException("Category already exists");
    }
}
Also used : Marshaller(org.exolab.castor.xml.Marshaller) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) StringWriter(java.io.StringWriter) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) IOException(java.io.IOException) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) IOException(java.io.IOException)

Example 9 with ValidationException

use of org.exolab.castor.xml.ValidationException in project OpenClinica by OpenClinica.

the class MetaDataReportBean method handleLoadCastor.

private String handleLoadCastor(RulesPostImportContainer rpic) {
    try {
        // Create Mapping
        Mapping mapping = new Mapping();
        mapping.loadMapping(getCoreResources().getURL("mappingMarshallerMetadata.xml"));
        // Create XMLContext
        XMLContext xmlContext = new XMLContext();
        xmlContext.setProperty(XMLConfiguration.NAMESPACES, "true");
        xmlContext.addMapping(mapping);
        StringWriter writer = new StringWriter();
        Marshaller marshaller = xmlContext.createMarshaller();
        // marshaller.setNamespaceMapping("castor", "http://castor.org/sample/mapping/");
        marshaller.setWriter(writer);
        marshaller.marshal(rpic);
        String result = writer.toString();
        String newResult = result.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
        return newResult;
    } 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) StringWriter(java.io.StringWriter) 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) FileNotFoundException(java.io.FileNotFoundException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) MappingException(org.exolab.castor.mapping.MappingException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) IOException(java.io.IOException) MappingException(org.exolab.castor.mapping.MappingException)

Example 10 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)

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