boolean currentNegative = false;
Element currentAceElm = null;
Element currentGrantDenyElm = null;
Enumeration permissions = security.enumeratePermissions(sToken, objectNode, true);
while (permissions.hasMoreElements()) {
NodePermission perm = (NodePermission)permissions.nextElement();
if (!perm.getSubjectUri().equals(currentSubjectUri)
|| (perm.isNegative() && !currentNegative || !perm.isNegative() && currentNegative)) {
// save previous ACE
if (currentAceElm != null) {
xmlValue.add(currentAceElm);
}
// new ACE
currentAceElm = new Element(E_ACE, DNSP);
// principal
if (perm.isInvert()) {
Element invertElm = new Element(E_INVERT, DNSP);
invertElm.addContent(createPrincipalElement(perm.getSubjectUri()));
currentAceElm.addContent(invertElm);
}
else {
currentAceElm.addContent(createPrincipalElement(perm.getSubjectUri()));
}
// grant/deny
currentGrantDenyElm = perm.isNegative()
? new Element(E_DENY, DNSP)
: new Element(E_GRANT, DNSP);
currentAceElm.addContent(currentGrantDenyElm);
// inherited
String inheritedFrom = perm.getInheritedFrom();
if (inheritedFrom != null && inheritedFrom.length() > 0) {
currentAceElm.addContent(createInheritedElement(inheritedFrom));
}
// protected
if (perm.isProtected()) {
currentAceElm.addContent(new Element(E_PROTECTED, DNSP));
}
currentSubjectUri = perm.getSubjectUri();
currentNegative = perm.isNegative();
}
currentGrantDenyElm.addContent(createPrivilegeElement(perm.getActionUri()));
}
// save last ACE
if (currentAceElm != null) {
xmlValue.add(currentAceElm);