/**
* Generate XML data.
*/
public void generate() throws IOException, SAXException, ProcessingException {
ComponentSelector principalproviders = null;
PrincipalProvider principalprovider = null;
try {
principalproviders = (ComponentSelector)this.manager.lookup(PrincipalProvider.ROLE+"Selector");
principalprovider = (PrincipalProvider)principalproviders.select(this.principalprovidername);
Principal[] principals = principalprovider.getPrincipals(this.principalcaller);
PrincipalGroup[] principalgroups = principalprovider.getPrincipalGroups(this.principalcaller);
this.contentHandler.startDocument();
this.contentHandler.startPrefixMapping("",PL_NS);
this.contentHandler.startElement(PL_NS, LIST_ELEMENT_NAME,
LIST_ELEMENT_NAME, new AttributesImpl());
AttributesImpl attributes;
for(int i=0; i<principals.length; i++) {
attributes = new AttributesImpl();
attributes.addAttribute("", NAME_ATTR_NAME, NAME_ATTR_NAME, "CDATA", principals[i].getName());
if (principals[i].getRole()!=null)
attributes.addAttribute("", ROLE_ATTR_NAME, ROLE_ATTR_NAME, "CDATA", principals[i].getRole());
if (principals[i].getPassword()!=null)
attributes.addAttribute("", PASSWORD_ATTR_NAME, PASSWORD_ATTR_NAME, "CDATA", principals[i].getPassword());
this.contentHandler.startElement(PL_NS, PRINCIPAL_ELEMENT_NAME,
PRINCIPAL_ELEMENT_NAME, attributes);
this.contentHandler.endElement(PL_NS, PRINCIPAL_ELEMENT_NAME, PRINCIPAL_ELEMENT_NAME);
}
for(int i=0; i<principalgroups.length; i++) {
attributes = new AttributesImpl();
attributes.addAttribute("", NAME_ATTR_NAME, NAME_ATTR_NAME, "CDATA", principalgroups[i].getName());
this.contentHandler.startElement(PL_NS, PRINCIPALGROUP_ELEMENT_NAME,
PRINCIPALGROUP_ELEMENT_NAME, attributes);
Principal[] members = principalprovider.members(this.principalcaller, principalgroups[i]);
for(int j=0; j<members.length; j++) {
attributes = new AttributesImpl();
attributes.addAttribute("", NAME_ATTR_NAME, NAME_ATTR_NAME, "CDATA", members[j].getName());
if (members[j].getRole()!=null)
attributes.addAttribute("", ROLE_ATTR_NAME, ROLE_ATTR_NAME, "CDATA", members[j].getRole());
if (members[j].getPassword()!=null)
attributes.addAttribute("", PASSWORD_ATTR_NAME, PASSWORD_ATTR_NAME, "CDATA",
members[j].getPassword());
this.contentHandler.startElement(PL_NS, PRINCIPAL_ELEMENT_NAME,
PRINCIPAL_ELEMENT_NAME, attributes);
this.contentHandler.endElement(PL_NS, PRINCIPAL_ELEMENT_NAME, PRINCIPAL_ELEMENT_NAME);
}
this.contentHandler.endElement(PL_NS, PRINCIPALGROUP_ELEMENT_NAME, PRINCIPALGROUP_ELEMENT_NAME);
}
this.contentHandler.endElement(PL_NS, LIST_ELEMENT_NAME, LIST_ELEMENT_NAME);
this.contentHandler.endPrefixMapping("");
this.contentHandler.endDocument();
} catch (ComponentException ce) {
getLogger().error("Could not lookup for component.", ce);
} finally {
if (principalprovider!=null)
principalproviders.release(principalprovider);
principalprovider = null;
if (principalproviders!=null)
this.manager.release(principalproviders);
principalproviders = null;