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