* @throws ParsingException
* if there was an error during parsing
*/
public static TargetMatch getInstance(Node root, int matchType, PolicyMetaData metaData)
throws ParsingException {
Function function;
Evaluatable eval = null;
AttributeValue attrValue = null;
AttributeFactory attrFactory = AttributeFactory.getInstance();
// get the function type, making sure that it's really a correct
// Target function
String funcName = root.getAttributes().getNamedItem("MatchId").getNodeValue();
FunctionFactory factory = FunctionFactory.getTargetInstance();
try {
URI funcId = new URI(funcName);
function = factory.createFunction(funcId);
} catch (URISyntaxException use) {
throw new ParsingException("Error parsing TargetMatch", use);
} catch (UnknownIdentifierException uie) {
throw new ParsingException("Unknown MatchId", uie);
} catch (FunctionTypeException fte) {
// try to create an abstract function
try {
URI funcId = new URI(funcName);
function = factory.createAbstractFunction(funcId, root);
} catch (Exception e) {
// any exception here is an error
throw new ParsingException("invalid abstract function", e);
}
}
// next, get the designator or selector being used, and the attribute
// value paired with it
NodeList nodes = root.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
String name = node.getNodeName();
if (name.equals(NAMES[matchType] + "AttributeDesignator")) {
eval = AttributeDesignator.getInstance(node, matchType, metaData);
} else if (name.equals("AttributeSelector")) {
eval = AttributeSelector.getInstance(node, metaData);
} else if (name.equals("AttributeValue")) {
try {
attrValue = attrFactory.createValue(node);
} catch (UnknownIdentifierException uie) {
throw new ParsingException("Unknown Attribute Type", uie);
}
}
}
// finally, check that the inputs are valid for this function
List<Evaluatable> inputs = new ArrayList<Evaluatable>();
inputs.add(attrValue);
inputs.add(eval);
function.checkInputsNoBag(inputs);
return new TargetMatch(matchType, function, eval, attrValue);
}