* @param policy The policy to save.
* @return A DOM document.
* @throws AccessControlException when something went wrong.
*/
public static Document savePolicy(DefaultPolicy policy) throws AccessControlException {
NamespaceHelper helper;
try {
helper =
new NamespaceHelper(
AccessController.NAMESPACE,
AccessController.DEFAULT_PREFIX,
POLICY_ELEMENT);
} catch (ParserConfigurationException e) {
throw new AccessControlException(e);
}
Credential[] credentials = policy.getCredentials();
Element policyElement = helper.getDocument().getDocumentElement();
for (int i = 0; i < credentials.length; i++) {
Accreditable accreditable = credentials[i].getAccreditable();
Element accreditableElement = save(accreditable, helper);
Role[] roles = credentials[i].getRoles();
for (int j = 0; j < roles.length; j++) {
Element roleElement = helper.createElement(ROLE_ELEMENT);
roleElement.setAttribute(ID_ATTRIBUTE, roles[j].getId());
accreditableElement.appendChild(roleElement);
}
policyElement.appendChild(accreditableElement);
}
policyElement.setAttribute(SSL_ATTRIBUTE, Boolean.toString(policy.isSSLProtected()));
return helper.getDocument();
}