AttributeFactory attrFactory = AttributeFactory.getInstance();
// First check that we're really parsing an Attribute
if (! SunxacmlUtil.getNodeName(root).equals("Attribute")) {
throw new ParsingException("Attribute object cannot be created " +
"with root node of type: " +
SunxacmlUtil.getNodeName(root));
}
NamedNodeMap attrs = root.getAttributes();
try {
id = new URI(attrs.getNamedItem("AttributeId").getNodeValue());
} catch (Exception e) {
throw new ParsingException("Error parsing required attribute " +
"AttributeId in AttributeType", e);
}
try {
type = new URI(attrs.getNamedItem("DataType").getNodeValue());
} catch (Exception e) {
throw new ParsingException("Error parsing required attribute " +
"DataType in AttributeType", e);
}
try {
Node issuerNode = attrs.getNamedItem("Issuer");
if (issuerNode != null)
issuer = issuerNode.getNodeValue();
Node instantNode = attrs.getNamedItem("IssueInstant");
if (instantNode != null)
issueInstant = DateTimeAttribute.
getInstance(instantNode.getNodeValue());
} catch (Exception e) {
// shouldn't happen, but just in case...
throw new ParsingException("Error parsing optional AttributeType"
+ " attribute", e);
}
// now we get the attribute value
NodeList nodes = root.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (SunxacmlUtil.getNodeName(node).equals("AttributeValue")) {
// only one value can be in an Attribute
/*
* SECURITY-157: multiple values
*
* if (value != null)
throw new ParsingException("Too many values in Attribute");
*/
// now get the value
try {
value = attrFactory.createValue(node, type);
} catch (UnknownIdentifierException uie) {
throw new ParsingException("Unknown AttributeId", uie);
}
if(valueSet == null)
valueSet = new HashSet<AttributeValue>();
valueSet.add(value);
}
}
// make sure we got a value
if (value == null)
throw new ParsingException("Attribute must contain a value");
return new Attribute(id, type, issuer, issueInstant, valueSet);
}