Node node = widgetNodeList.item(i);
//System.out.println("node:" + node + "---" + "Node type:" + node.getNodeType()); //debug
if (node.getNodeType() == Node.ELEMENT_NODE) {
//It is a widget node. Process its properties.
String widgetTypeName = node.getNodeName();
WidgetAdapter adapter = adapterForWidgetType.get(widgetTypeName);
String widgetName = null;
JComponent widget = adapter.New();
Set<String> readProperties = new HashSet<String>();
NodeList propertyNodeList = node.getChildNodes();
for (int j = 0; j < propertyNodeList.getLength(); j++) {
Node propertyNode = propertyNodeList.item(j);
if (propertyNode.getNodeType() == Node.ELEMENT_NODE) {
String propertyName = propertyNode.getNodeName();
if (readProperties.contains(propertyName)) {
// TODO Output an error message or throw an exception?
System.err.println("The property '" + propertyName + "' is duplicated.");
} else {
if (propertyName.equals("name")) {
widgetName = propertyNode.getTextContent();
widget.setName(widgetName);
} else {
String str = propertyNode.getTextContent();
String type = adapter.getPropertyType(propertyName);
try {
adapter.setProperty(widget, propertyName,
convertToObject(type, str));
} catch (Exception e) {
System.err.println("invalid conversion: " + str + " as " + type);
}
}
}
readProperties.add(propertyName);
}
}
// Set a property to the default value if it is not found in the AVM XML.
for (String property : adapter.getAllPropertyNames()) {
if (!readProperties.contains(property)) {
adapter.resetPropertyToDefaultValue(widget, property);
}
}
parent.add(widget);
}