// Parse; die if not well-formed
Document doc = null;
try {
doc = m_domParser.parse(policyStream);
} catch (Exception e) {
throw new ValidationException("Policy invalid; malformed XML", e);
}
if (schemaValidate) {
// XSD-validate; die if not schema-valid
try {
m_validator.validate(new DOMSource(doc));
} catch (Exception e) {
throw new ValidationException("Policy invalid; schema"
+ " validation failed", e);
}
}
// Construct AbstractPolicy from doc; die if root isn't "Policy[Set]"
Element root = doc.getDocumentElement();
String rootName = root.getTagName();
try {
if (rootName.equals("Policy")) {
return Policy.getInstance(root);
} else if (rootName.equals("PolicySet")) {
return PolicySet.getInstance(root);
} else {
throw new ValidationException("Policy invalid; root element is "
+ rootName + ", but should be "
+ "Policy or PolicySet");
}
} catch (ParsingException e) {
throw new ValidationException("Policy invalid; failed parsing by "
+ "Sun XACML implementation", e);
}
}