* @author Remy Maucherat
*/
public class ValidatorMetaDataParser extends MetaDataElementParser {
public static ValidatorMetaData parse(XMLStreamReader reader) throws XMLStreamException {
ValidatorMetaData validator = new ValidatorMetaData();
// 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: {
validator.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 (validator.getDescriptions() == null) {
validator.setDescriptions(descriptions);
}
continue;
}
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case VALIDATOR_CLASS:
validator.setValidatorClass(reader.getElementText().trim());
break;
case INIT_PARAM:
List<ParamValueMetaData> initParams = validator.getInitParams();
if (initParams == null) {
initParams = new ArrayList<ParamValueMetaData>();
validator.setInitParams(initParams);
}
initParams.add(ParamValueMetaDataParser.parse(reader));
break;
default: throw unexpectedElement(reader);
}