* @author Remy Maucherat
*/
public class SecurityRoleMetaDataParser extends MetaDataElementParser {
public static SecurityRoleMetaData parse(XMLStreamReader reader) throws XMLStreamException {
SecurityRoleMetaData securityRole = new SecurityRoleMetaData();
// Handle attributes
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i ++) {
final String value = reader.getAttributeValue(i);
if (reader.getAttributeNamespace(i) != null) {
continue;
}
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case ID: {
securityRole.setId(value);
break;
}
default: throw unexpectedAttribute(reader, i);
}
}
DescriptionsImpl descriptions = new DescriptionsImpl();
// Handle elements
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
if (DescriptionsMetaDataParser.parse(reader, descriptions)) {
if (securityRole.getDescriptions() == null) {
securityRole.setDescriptions(descriptions);
}
continue;
}
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case ROLE_NAME:
securityRole.setRoleName(reader.getElementText());
break;
case PRINCIPAL_NAME:
Set<String> principalNames = securityRole.getPrincipals();
if (principalNames == null) {
principalNames = new HashSet<String>();
securityRole.setPrincipals(principalNames);
}
principalNames.add(reader.getElementText());
break;
default: throw unexpectedElement(reader);
}