}
protected BNNode visitVariable(Node parent) {
NodeList l = parent.getChildNodes();
BNNode bbnnode = null; // = new BeliefNode("XXX");
int max;
String propType = "nature";
NamedNodeMap attrs = parent.getAttributes();
if (attrs != null) {
max = attrs.getLength();
for (int i = 0; i < max; i++) {
Node attr = attrs.item(i);
String name = attr.getNodeName();
String value = attr.getNodeValue();
if (name.equals("TYPE")) {
propType = value;
if (value.equals("decision")) {
bbnnode = new BNNode("XXX", BNNode.NodeType.decision);
} else if (value.equals("utility")) {
bbnnode = new BNNode("XXX", BNNode.NodeType.utility);
} else { // otherwise it's just "nature"
bbnnode = new BNNode("XXX",
BNNode.NodeType.probabilistic);
}
} else if (Setting.DEBUG) {
System.out.println(
"Unhandled variable property attribute " + name);
}
}
}
if (!propType.equals("nature") && !propType.equals("decision")
&& !propType.equals("utility")) { // $NON-NLS-1$
throw new RuntimeException("Unknown node type " + propType);
}
if (l == null) {
return null;
}
LinkedList<String> values = new LinkedList<String>();
max = l.getLength();
for (int i = 0; i < max; i++) {
Node node = l.item(i);
switch (node.getNodeType()) {
case Node.ELEMENT_NODE:
String name = node.getNodeName();
if (name.equals("NAME")) { // $NON-NLS-1$
String desc = getElementValue(node);
bbnnode.setName(desc);
} else if (name.equals("OUTCOME") || name.equals("VALUE")) {
String value = getElementValue(node);
if (value != null) {
values.add(value);
}
} else if (name.equals("PROPERTY")) {
String value = getElementValue(node);
parseProperty(value, bbnnode);
} else if (Setting.DEBUG) {
System.out.println("Unhandled variable element " + name);
}
break;
case Node.DOCUMENT_NODE:
case Node.COMMENT_NODE:
case Node.TEXT_NODE:
// Ignore this
break;
default:
if (Setting.DEBUG) {
System.out.println("Unhandled node " + node.getNodeName());
}
}
}
if (propType.equals("nature") || propType.equals("utility")) {
String[] valArr = new String[values.size()];
values.toArray(valArr);
LabelDomain dom = new LabelDomain(bbnnode.getName(), valArr);
// (String[]) values.toArray());
bbnnode.setDomain(dom);
}
return bbnnode;
}