Search in sources :

Example 1 with LineAwareElement

use of org.csstudio.opibuilder.persistence.LineAwareXMLParser.LineAwareElement in project yamcs-studio by yamcs.

the class XMLUtil method setPropertiesFromXML.

@SuppressWarnings("rawtypes")
private static void setPropertiesFromXML(Element element, AbstractWidgetModel model) {
    if (model == null || element == null)
        return;
    String versionOnFile = element.getAttributeValue(XMLATTR_VERSION);
    model.setVersionOnFile(Version.parseVersion(versionOnFile));
    if (element instanceof LineAwareElement) {
        model.setLineNumber(((LineAwareElement) element).getLineNumber());
    }
    List children = element.getChildren();
    Iterator iterator = children.iterator();
    Set<String> propIdSet = model.getAllPropertyIDs();
    while (iterator.hasNext()) {
        Element subElement = (Element) iterator.next();
        // handle property
        if (propIdSet.contains(subElement.getName())) {
            String propId = subElement.getName();
            try {
                model.setPropertyValue(propId, model.getProperty(propId).readValueFromXML(subElement));
            } catch (Exception e) {
                String errorMessage = "Failed to read the " + propId + " property for " + model.getName() + ". " + "The default property value will be setted instead. \n" + e;
                // MessageDialog.openError(null, "OPI File format error", errorMessage + "\n" + e.getMessage());
                OPIBuilderPlugin.getLogger().log(Level.WARNING, errorMessage, e);
                ConsoleService.getInstance().writeWarning(errorMessage);
            }
        }
    }
}
Also used : LineAwareElement(org.csstudio.opibuilder.persistence.LineAwareXMLParser.LineAwareElement) LineAwareElement(org.csstudio.opibuilder.persistence.LineAwareXMLParser.LineAwareElement) Element(org.jdom.Element) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) JDOMException(org.jdom.JDOMException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 LineAwareElement (org.csstudio.opibuilder.persistence.LineAwareXMLParser.LineAwareElement)1 Element (org.jdom.Element)1 JDOMException (org.jdom.JDOMException)1