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;
}
}
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);
}
}
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;
}
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;
}
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");
}
}
Aggregations