Search in sources :

Example 16 with ValidationException

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

the class ACSAlarmSystemDAOImpl method getConfiguration.

public AlarmSystemConfiguration getConfiguration() {
    if (conf == null)
        throw new IllegalStateException("null configuration accessor");
    AlarmSystemConfiguration asc;
    String xml;
    try {
        xml = conf.getConfiguration(ALARM_SYSTEM_CONFIGURATION_PATH);
    } catch (CDBRecordDoesNotExistEx e) {
        asc = new AlarmSystemConfiguration();
        ConfigurationProperty cp = new ConfigurationProperty();
        cp.setName("Implementation");
        cp.setContent("ACS");
        asc.addConfigurationProperty(cp);
        return asc;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    StringReader FFReader = new StringReader(xml);
    Unmarshaller FF_unmarshaller = new Unmarshaller(AlarmSystemConfiguration.class);
    FF_unmarshaller.setValidation(false);
    try {
        asc = (AlarmSystemConfiguration) FF_unmarshaller.unmarshal(FFReader);
    } catch (MarshalException e) {
        e.printStackTrace();
        return null;
    } catch (ValidationException e) {
        e.printStackTrace();
        return null;
    }
    try {
        asc.validate();
    } catch (ValidationException e) {
        e.printStackTrace();
    }
    return asc;
}
Also used : ConfigurationProperty(alma.alarmsystem.alarmmessage.generated.ConfigurationProperty) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) AlarmSystemConfiguration(alma.alarmsystem.alarmmessage.generated.AlarmSystemConfiguration) StringReader(java.io.StringReader) Unmarshaller(org.exolab.castor.xml.Unmarshaller) IOException(java.io.IOException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx)

Example 17 with ValidationException

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

the class ACSAlarmSystemDAOImpl method flushConfiguration.

public void flushConfiguration(AlarmSystemConfiguration asc) {
    if (conf == null || !conf.isWriteable())
        throw new IllegalStateException("no writable configuration accessor");
    if (asc == null)
        throw new IllegalArgumentException("Null Alarm System Configuration 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(asc);
    } catch (MarshalException e) {
        e.printStackTrace();
        return;
    } catch (ValidationException e) {
        e.printStackTrace();
        return;
    }
    try {
        conf.deleteConfiguration(ALARM_SYSTEM_CONFIGURATION_PATH);
        conf.addConfiguration(ALARM_SYSTEM_CONFIGURATION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
    } catch (CDBRecordDoesNotExistEx e) {
        try {
            conf.addConfiguration(ALARM_SYSTEM_CONFIGURATION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    } catch (org.omg.CORBA.UNKNOWN e) {
        try {
            conf.addConfiguration(ALARM_SYSTEM_CONFIGURATION_PATH, FFWriter.toString().replaceFirst("xsi:type=\".*\"", ""));
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
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) IOException(java.io.IOException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx)

Example 18 with ValidationException

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

the class CategoryManager method saveToCDB.

public void saveToCDB() {
    Set<String> keyset = _objState.keySet();
    String[] objs = new String[keyset.size()];
    keyset.toArray(objs);
    Categories cats = ((ACSCategoryDAOImpl) _categoryDAO).getCategories();
    boolean flush = false;
    try {
        for (int i = 0; i < objs.length; i++) {
            ObjectState os = _objState.get(objs[i]);
            Category c = getCategoryByPath(objs[i]);
            if (c != null)
                c.validate();
            switch(os.getAction()) {
                case //Error, no state assigned.
                -1:
                    break;
                case 0:
                    break;
                case 1:
                    ((ACSCategoryDAOImpl) _categoryDAO).addCategory(cats, c);
                    flush = true;
                    break;
                case 2:
                    ((ACSCategoryDAOImpl) _categoryDAO).updateCategory(cats, c);
                    flush = true;
                    break;
                case 3:
                    c = new Category();
                    c.setPath(objs[i]);
                    ((ACSCategoryDAOImpl) _categoryDAO).deleteCategory(cats, c);
                    flush = true;
                    break;
                default:
                    //Shouldn't happen.
                    break;
            }
        }
        _objState.clear();
        if (flush)
            ((ACSCategoryDAOImpl) _categoryDAO).flushCategories(cats);
        for (Category c : _categoryList) _objState.put(c.getPath(), new ObjectState(false));
    } catch (ValidationException e) {
        e.printStackTrace();
    }
}
Also used : Category(alma.acs.alarmsystem.generated.Category) ValidationException(org.exolab.castor.xml.ValidationException) Categories(alma.acs.alarmsystem.generated.Categories) ACSCategoryDAOImpl(cl.utfsm.acs.acg.dao.ACSCategoryDAOImpl)

Example 19 with ValidationException

use of org.exolab.castor.xml.ValidationException in project tdi-studio-se by Talend.

the class ELTMapSaveToEmfMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    IProxyRepositoryFactory factory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
    ProcessType processType = getProcessType(item);
    boolean modified = false;
    if (processType != null) {
        for (Object obj : processType.getNode()) {
            NodeType nodeType = (NodeType) obj;
            StringReader stringReader = null;
            if (nodeType.getStringData() != null && !"".equals(nodeType.getStringData())) {
                stringReader = new StringReader(nodeType.getStringData());
            }
            final String componentName = nodeType.getComponentName();
            if (stringReader != null) {
                if (componentName != null && componentName.startsWith("tELT") && componentName.endsWith("Map")) {
                    modified = true;
                    StringBuilder input = null;
                    Unmarshaller unmarshaller = new Unmarshaller(ExternalDbMapData.class);
                    unmarshaller.setWhitespacePreserve(true);
                    try {
                        BufferedReader r = new BufferedReader(stringReader);
                        input = new StringBuilder();
                        String line;
                        while ((line = r.readLine()) != null) {
                            input.append(line);
                            //$NON-NLS-0$
                            input.append("\r\n");
                        }
                        //$NON-NLS-0$ //$NON-NLS-1$
                        String buf = input.toString().replaceAll("<table-entries .*?>.*?</table-entries>", "");
                        stringReader.close();
                        stringReader = new StringReader(buf);
                        ExternalDbMapData externalData = (ExternalDbMapData) unmarshaller.unmarshal(stringReader);
                        DBMapData emfMapperData = DbmapFactory.eINSTANCE.createDBMapData();
                        DBMapHelper.saveDataToEmf(emfMapperData, externalData);
                        nodeType.setNodeData(emfMapperData);
                        nodeType.setStringData("");
                    } catch (MarshalException e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    } catch (ValidationException e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    } catch (IOException e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    } finally {
                        if (stringReader != null) {
                            stringReader.close();
                        }
                    }
                }
            }
        }
    }
    try {
        if (modified) {
            factory.save(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } else {
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) DBMapData(org.talend.designer.dbmap.model.emf.dbmap.DBMapData) ValidationException(org.exolab.castor.xml.ValidationException) ExternalDbMapData(org.talend.designer.dbmap.external.data.ExternalDbMapData) IOException(java.io.IOException) IOException(java.io.IOException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) Unmarshaller(org.exolab.castor.xml.Unmarshaller) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

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