Search in sources :

Example 1 with MarshalException

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

the class TMapSaveToEmfMigrationTask 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 ("tMap".equals(componentName)) {
                    modified = true;
                    Unmarshaller unmarshaller = new Unmarshaller(ExternalMapperData.class);
                    unmarshaller.setWhitespacePreserve(true);
                    try {
                        ExternalMapperData externalData = (ExternalMapperData) unmarshaller.unmarshal(stringReader);
                        final MapperData emfMapperData = MapperFactory.eINSTANCE.createMapperData();
                        MapperHelper.saveDataToEmf(externalData, emfMapperData);
                        nodeType.setNodeData(emfMapperData);
                        nodeType.setStringData("");
                    } catch (MarshalException e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    } catch (ValidationException 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) ValidationException(org.exolab.castor.xml.ValidationException) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) MapperData(org.talend.designer.mapper.model.emf.mapper.MapperData) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) 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) Unmarshaller(org.exolab.castor.xml.Unmarshaller) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 2 with MarshalException

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

the class DynamicProxyFactoryTest method testInvalidXml.

public void testInvalidXml() throws DynWrapperException {
    XmlComponentOperations serverProxy = createServerProxy();
    assertNotNull(serverProxy);
    XmlEntityStruct entStructObsProp = serverProxy.createObsProposal();
    XmlEntityStructHolder xesh = new XmlEntityStructHolder();
    // send invalid xml
    entStructObsProp.xmlString = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + //			"<ns1:ObsProposal xmlns:ns1=\"AlmaTest/ObsProposal\">" +
    "	<ns1:ObsProposalEntity entityIdEncrypted=\"ljasd;ljfa;lsfd\"" + "		entityId=\"uid://X0000000000000000/X00000001\" entityTypeName=\"ObsProposal\"/>" + "	<ns1:PerformanceGoals>peak performance enduring a 24-7-365 schedule.</ns1:PerformanceGoals>" + "</ns1:ObsProposal>";
    try {
        serverProxy.xmlInOutMethod(entStructObsProp, xesh);
        fail("invalid XML should have caused an exception");
    } catch (UndeclaredThrowableException e) {
        Throwable cause = e.getCause();
        assertTrue(cause instanceof DynWrapperException);
        Throwable cause2 = cause.getCause();
        assertTrue(cause2 instanceof MarshalException);
        assertTrue(((MarshalException) cause2).getCause() instanceof org.xml.sax.SAXException);
    }
}
Also used : XmlEntityStructHolder(alma.xmlentity.XmlEntityStructHolder) MarshalException(org.exolab.castor.xml.MarshalException) XmlComponentOperations(alma.demo.XmlComponentOperations) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) XmlEntityStruct(alma.xmlentity.XmlEntityStruct)

Example 3 with MarshalException

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

the class ACSAlarmDAOImpl method getReductionRules.

public alma.alarmsystem.alarmmessage.generated.ReductionDefinitions getReductionRules() {
    if (conf == null)
        throw new IllegalStateException("null configuration accessor");
    alma.alarmsystem.alarmmessage.generated.ReductionDefinitions rds;
    String xml;
    try {
        xml = conf.getConfiguration(REDUCTION_DEFINITION_PATH);
    } catch (CDBRecordDoesNotExistEx e) {
        rds = new alma.alarmsystem.alarmmessage.generated.ReductionDefinitions();
        ReductionLinkDefinitionListType rld = new ReductionLinkDefinitionListType();
        rld.setReductionLink(new alma.alarmsystem.alarmmessage.generated.ReductionLinkType[0]);
        rds.setLinksToCreate(rld);
        alma.alarmsystem.alarmmessage.generated.Thresholds ths = new alma.alarmsystem.alarmmessage.generated.Thresholds();
        ths.setThreshold(new alma.alarmsystem.alarmmessage.generated.Threshold[0]);
        rds.setThresholds(ths);
        return rds;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    StringReader FFReader = new StringReader(xml);
    Unmarshaller FF_unmarshaller = new Unmarshaller(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions.class);
    FF_unmarshaller.setValidation(false);
    try {
        rds = (alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) FF_unmarshaller.unmarshal(FFReader);
    } catch (MarshalException e) {
        e.printStackTrace();
        return null;
    } catch (ValidationException e) {
        e.printStackTrace();
        return null;
    }
    try {
        rds.validate();
    } catch (ValidationException e) {
        e.printStackTrace();
    }
    return rds;
}
Also used : Thresholds(alma.alarmsystem.alarmmessage.generated.Thresholds) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) Thresholds(alma.alarmsystem.alarmmessage.generated.Thresholds) ReductionDefinitions(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) ReductionDefinitions(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) 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) ReductionLinkType(alma.alarmsystem.alarmmessage.generated.ReductionLinkType) StringReader(java.io.StringReader) Unmarshaller(org.exolab.castor.xml.Unmarshaller) ReductionLinkDefinitionListType(alma.alarmsystem.alarmmessage.generated.ReductionLinkDefinitionListType) Threshold(alma.alarmsystem.alarmmessage.generated.Threshold)

Example 4 with MarshalException

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

the class ACSCategoryDAOImpl method getCategories.

public Categories getCategories() {
    if (conf == null || !conf.isWriteable())
        throw new IllegalStateException("no writable configuration accessor");
    Categories cats;
    String xml;
    try {
        xml = conf.getConfiguration(CATEGORY_DEFINITION_PATH);
    } catch (CDBRecordDoesNotExistEx e) {
        cats = new Categories();
        return cats;
    } catch (Exception e1) {
        e1.printStackTrace();
        return null;
    }
    StringReader FFReader = new StringReader(xml);
    Unmarshaller FF_unmarshaller = new Unmarshaller(Categories.class);
    FF_unmarshaller.setValidation(false);
    try {
        cats = (Categories) FF_unmarshaller.unmarshal(FFReader);
    } catch (MarshalException e1) {
        e1.printStackTrace();
        return null;
    } catch (ValidationException e1) {
        e1.printStackTrace();
        return null;
    }
    try {
        cats.validate();
    } catch (ValidationException e1) {
        e1.printStackTrace();
    }
    return cats;
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) Categories(alma.acs.alarmsystem.generated.Categories) StringReader(java.io.StringReader) Unmarshaller(org.exolab.castor.xml.Unmarshaller) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) IOException(java.io.IOException) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx)

Example 5 with MarshalException

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

Aggregations

MarshalException (org.exolab.castor.xml.MarshalException)22 ValidationException (org.exolab.castor.xml.ValidationException)21 IOException (java.io.IOException)20 MappingException (org.exolab.castor.mapping.MappingException)8 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 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)4 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 FaultFamily (alma.acs.alarmsystem.generated.FaultFamily)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 Vector (java.util.Vector)2 PersistencyException (org.cristalise.kernel.common.PersistencyException)2 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)2