use of org.exolab.castor.xml.ValidationException in project OpenClinica by OpenClinica.
the class ImportRuleServlet method handleLoadCastor.
private RulesPostImportContainer handleLoadCastor(File xmlFile) {
RulesPostImportContainer ruleImport = null;
try {
// create an XMLContext instance
XMLContext xmlContext = new XMLContext();
// create and set a Mapping instance
Mapping mapping = xmlContext.createMapping();
// mapping.loadMapping(SpringServletAccess.getPropertiesDir(context) + "mapping.xml");
mapping.loadMapping(getCoreResources().getURL("mapping.xml"));
xmlContext.addMapping(mapping);
// create a new Unmarshaller
Unmarshaller unmarshaller = xmlContext.createUnmarshaller();
unmarshaller.setWhitespacePreserve(false);
unmarshaller.setClass(RulesPostImportContainer.class);
// Create a Reader to the file to unmarshal from
FileReader reader = new FileReader(xmlFile);
ruleImport = (RulesPostImportContainer) unmarshaller.unmarshal(reader);
ruleImport.initializeRuleDef();
logRuleImport(ruleImport);
return ruleImport;
} 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());
}
}
use of org.exolab.castor.xml.ValidationException 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.ValidationException 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.ValidationException 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.ValidationException in project ACS by ACS-Community.
the class ReductionManager method saveToCDB.
public void saveToCDB() {
Set<String> keyset = _objState.keySet();
String[] objs = new String[keyset.size()];
keyset.toArray(objs);
ReductionDefinitions rds = ((ACSAlarmDAOImpl) _alarmDAO).getReductionRules();
boolean flush = false;
try {
for (int i = 0; i < objs.length; i++) {
ObjectState os = _objState.get(objs[i]);
String[] spl = objs[i].split(",");
String[] p = spl[0].split(":");
String[] c = spl[1].split(":");
ReductionLinkType rl = new ReductionLinkType();
AlarmDefinition ad;
Parent gp = new Parent();
ad = new AlarmDefinition();
ad.setFaultFamily(p[0]);
ad.setFaultMember(p[1]);
ad.setFaultCode(Integer.parseInt(p[2]));
gp.setAlarmDefinition(ad);
Child gc = new Child();
ad = new AlarmDefinition();
ad.setFaultFamily(c[0]);
ad.setFaultMember(c[1]);
ad.setFaultCode(Integer.parseInt(c[2]));
gc.setAlarmDefinition(ad);
rl.setParent(gp);
rl.setChild(gc);
if (spl[2].compareTo("n") == 0)
rl.setType(ReductionLinkTypeTypeType.NODE);
else
rl.setType(ReductionLinkTypeTypeType.MULTIPLICITY);
rl.validate();
switch(os.getAction()) {
case //Error, no state assigned.
-1:
break;
case 0:
break;
case 1:
((ACSAlarmDAOImpl) _alarmDAO).addReductionRule(rds, rl);
flush = true;
break;
case 2:
((ACSAlarmDAOImpl) _alarmDAO).updateReductionRule(rds, rl);
flush = true;
break;
case 3:
((ACSAlarmDAOImpl) _alarmDAO).deleteReductionRule(rds, rl);
flush = true;
break;
default:
//Shouldn't happen.
break;
}
}
keyset = _thrState.keySet();
objs = new String[keyset.size()];
keyset.toArray(objs);
for (int i = 0; i < objs.length; i++) {
AlarmDefinition al;
String[] p = objs[i].split(":");
al = new AlarmDefinition();
al.setFaultFamily(p[0]);
al.setFaultMember(p[1]);
al.setFaultCode(Integer.parseInt(p[2]));
ReductionRule rr = getMRParentByTriplet(p[0], p[1], Integer.parseInt(p[2]));
Threshold th = new Threshold();
th.setAlarmDefinition(al);
if (rr == null)
th.setValue(0);
else
th.setValue(rr.getThreshold());
ObjectState ts = _thrState.get(objs[i]);
th.validate();
switch(ts.getAction()) {
case //Error, no state assigned.
-1:
break;
case 0:
break;
case 1:
((ACSAlarmDAOImpl) _alarmDAO).addThreshold(rds, th);
flush = true;
break;
case 2:
((ACSAlarmDAOImpl) _alarmDAO).updateThreshold(rds, th);
flush = true;
break;
case 3:
((ACSAlarmDAOImpl) _alarmDAO).deleteThreshold(rds, th);
flush = true;
break;
default:
//Shouldn't happen.
break;
}
}
_objState.clear();
_thrState.clear();
if (flush)
((ACSAlarmDAOImpl) _alarmDAO).flushReductionRules(rds);
for (ReductionRule rr : _nodeReductionRules) for (Alarm al : rr.getChildren()) if (rr.getIsNodeReduction())
_objState.put(new String(rr.getParent().getAlarmId() + "," + al.getAlarmId() + ",n"), new ObjectState(false));
for (ReductionRule rr : _multiReductionRules) {
for (Alarm al : rr.getChildren()) if (!rr.getIsNodeReduction())
_objState.put(new String(rr.getParent().getAlarmId() + "," + al.getAlarmId() + ",m"), new ObjectState(false));
_thrState.put(rr.getParent().getAlarmId(), new ObjectState(false));
}
} catch (ValidationException e) {
e.printStackTrace();
}
}
Aggregations