Search in sources :

Example 16 with MarshalException

use of org.exolab.castor.xml.MarshalException 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 17 with MarshalException

use of org.exolab.castor.xml.MarshalException 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

MarshalException (org.exolab.castor.xml.MarshalException)17 ValidationException (org.exolab.castor.xml.ValidationException)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 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 FaultFamily (alma.acs.alarmsystem.generated.FaultFamily)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 Vector (java.util.Vector)2 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)2