use of org.exolab.castor.xml.Unmarshaller in project ACS by ACS-Community.
the class ACSAlarmDAOImpl method loadAlarms.
/**
* Load alarms from CDB.
*
* Read the alarms by the alarm definitions file of the CDB.
* The initialization of the alarms is not complete at this stage.
* In fact the categories are assigned to alarms when reading the
* categories from the CDB by ACSCategoryDAOImpl
*
*
* @throws Exception In case of error while parsing XML definition files
*
* @see ACSCategoryDAOImpl
*/
public List<FaultFamily> loadAlarms() throws Exception {
if (conf == null) {
throw new IllegalStateException("Missing dal");
}
String xml;
try {
xml = conf.getConfiguration(ALARM_DEFINITION_PATH);
} catch (Throwable t) {
throw new RuntimeException("Couldn't read alarm XML: " + ALARM_DEFINITION_PATH, t);
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
} catch (Exception e) {
throw new Exception("Error building the DocumentBuilder from the DocumentBuilderFactory", e);
}
StringReader stringReader = new StringReader(xml);
InputSource inputSource = new InputSource(stringReader);
Document doc;
try {
doc = builder.parse(inputSource);
if (doc == null) {
throw new Exception("The builder returned a null Document after parsing");
}
} catch (Exception e) {
throw new Exception("Error parsing XML: " + xml, e);
}
NodeList docChilds = doc.getChildNodes();
if (docChilds == null || docChilds.getLength() != 1) {
throw new Exception("Malformed xml: only one node (AlarmDefinitions) expected");
}
Node alarmDefNode = docChilds.item(0);
if (alarmDefNode == null || alarmDefNode.getNodeName() != XML_DOCUMENT_TYPE) {
throw new Exception("Malformed xml: " + XML_DOCUMENT_TYPE + " not found");
}
NodeList alarmDefsNodes = alarmDefNode.getChildNodes();
Unmarshaller FF_unmarshaller = new Unmarshaller(FaultFamily.class);
FF_unmarshaller.setValidation(false);
FF_unmarshaller.setWhitespacePreserve(true);
Vector<FaultFamily> cdbFamilies = new Vector<FaultFamily>();
for (int t = 0; t < alarmDefsNodes.getLength(); t++) {
Node alarmDef = alarmDefsNodes.item(t);
try {
FaultFamily family = (FaultFamily) FF_unmarshaller.unmarshal(alarmDef);
if (family == null) {
throw new Exception("Error unmarshalling a family node");
}
cdbFamilies.add(family);
} catch (Exception e) {
throw new Exception("Error parsing " + alarmDef.getNodeName(), e);
}
}
generateAlarmsMap(cdbFamilies);
loadReductionRules();
return cdbFamilies;
}
use of org.exolab.castor.xml.Unmarshaller 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.Unmarshaller in project ACS by ACS-Community.
the class ACSCategoryDAOImpl method loadCategories.
/**
* Load the categories from the CDB.
* <P>
* Loads all the category from the CDB and build an internal
* representation of category.
* The category is also added to all the alarms having the
* fault family specified in the XML.
* <P>
* All the categories derive from ROOT that is built here
* as default (in this way the user does ot need to add the ROOT
* entry in the CDB).
*
* @return list of Category entries read from CDB
* @throws Exception In case of error reading the values from the CDB
*/
public alma.acs.alarmsystem.generated.Category[] loadCategories() throws Exception {
if (conf == null) {
throw new IllegalStateException("Missing dal");
}
categories.clear();
String xml;
try {
xml = conf.getConfiguration(CATEGORY_DEFINITION_PATH);
} catch (Throwable t) {
throw new RuntimeException("Couldn't read alarm list", t);
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
} catch (Exception e) {
throw new Exception("Error building the DocumentBuilder from the DocumentBuilderFactory", e);
}
StringReader stringReader = new StringReader(xml);
InputSource inputSource = new InputSource(stringReader);
Document doc;
try {
doc = builder.parse(inputSource);
if (doc == null) {
throw new Exception("The builder returned a null Document after parsing");
}
} catch (Exception e) {
throw new Exception("Error parsing XML: " + xml, e);
}
NodeList docChilds = doc.getChildNodes();
if (docChilds == null || docChilds.getLength() != 1) {
throw new Exception("Malformed xml: only one node (categories) expected");
}
Node categoriesNode = docChilds.item(0);
Unmarshaller FF_unmarshaller = new Unmarshaller(Categories.class);
FF_unmarshaller.setValidation(false);
FF_unmarshaller.setWhitespacePreserve(true);
Categories daoCategories;
try {
daoCategories = (Categories) FF_unmarshaller.unmarshal(categoriesNode);
logger.log(AcsLogLevel.DEBUG, "Categories definition read");
} catch (Exception e) {
throw new Exception("Error parsing " + CATEGORY_DEFINITION_PATH, e);
}
alma.acs.alarmsystem.generated.Category[] daoCategory = daoCategories.getCategory();
if (daoCategory == null || daoCategory.length == 0) {
logger.log(AcsLogLevel.DEBUG, "No category defined");
}
// Add the root Category
addRootCategory();
// Goes through all the Categories read from the CDB
for (alma.acs.alarmsystem.generated.Category category : daoCategory) {
cern.laser.business.definition.data.CategoryDefinition definition = new cern.laser.business.definition.data.CategoryDefinition(category.getPath(), category.getDescription());
CategoryImpl ci = new CategoryImpl();
// will get filled in later
ci.setAlarmIds(new HashSet());
ci.setCategoryId(new Integer(nextCatID++));
ci.setChildrenIds(new HashSet<Integer>());
ci.setDescription(definition.getDescription());
ci.setName(definition.getPath());
ci.setPath(definition.getPath());
ci.setAlarmIds(new HashSet());
setParentID(ci);
// Stores the categories
categories.put(ci.getCategoryId(), ci);
catPathToCategory.put(ci.getPath(), ci);
logger.log(AcsLogLevel.DEBUG, "Category " + ci.getName() + " added with ID=" + ci.getCategoryId());
// Check if the category is defined as default.
if (category.hasIsDefault() && category.getIsDefault() == true) {
if (defaultCategory != null) {
StringBuilder str = new StringBuilder("CDB misconfiguration: default category defined more then once (actual default: ");
str.append(defaultCategory.getPath());
str.append(", new default: ");
str.append(category.getPath());
logger.log(AcsLogLevel.WARNING, str.toString());
} else {
defaultCategory = ci;
}
}
// A category contains a set of child ids.
// This method adjusts the references of categories between the parent
// and the child
adjustParentIDs(ci.getName(), ci.getCategoryId());
// Connect alarms to this category
for (alma.acs.alarmsystem.generated.Category cat : daoCategories.getCategory()) {
if (cat.getPath().equals(ci.getPath())) {
String[] families = cat.getAlarms().getFaultFamily();
for (String faultFamily : families) {
assignCategoryToAlarms(ci, faultFamily);
}
}
}
}
// Assign core alarms to ROOT category
assignCategoryOfCoreAlarms();
// Log a message if no category has been defined in the CDB
if (defaultCategory == null) {
logger.log(AcsLogLevel.WARNING, "No default category defined in CDB");
} else {
// Check if there are alarms without category to assign to the default
assignDefaultCategory(defaultCategory);
}
return daoCategory;
}
use of org.exolab.castor.xml.Unmarshaller in project camel by apache.
the class AbstractCastorDataFormat method createUnmarshaller.
public Unmarshaller createUnmarshaller(Exchange exchange) throws Exception {
// need to create new marshaller as we may have concurrent processing
Unmarshaller answer = xmlContext.createUnmarshaller();
answer.setValidation(isValidation());
return answer;
}
use of org.exolab.castor.xml.Unmarshaller 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