* @author Remy Maucherat
*/
public class FilterMappingMetaDataParser extends MetaDataElementParser {
public static FilterMappingMetaData parse(XMLStreamReader reader) throws XMLStreamException {
FilterMappingMetaData filterMapping = new FilterMappingMetaData();
// 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: {
filterMapping.setId(value);
break;
}
default: throw unexpectedAttribute(reader, i);
}
}
// Handle elements
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case FILTER_NAME:
filterMapping.setFilterName(reader.getElementText());
break;
case URL_PATTERN:
List<String> urlPatterns = filterMapping.getUrlPatterns();
if (urlPatterns == null) {
urlPatterns = new ArrayList<String>();
filterMapping.setUrlPatterns(urlPatterns);
}
urlPatterns.add(reader.getElementText());
break;
case SERVLET_NAME:
List<String> servletNames = filterMapping.getServletNames();
if (servletNames == null) {
servletNames = new ArrayList<String>();
filterMapping.setServletNames(servletNames);
}
servletNames.add(reader.getElementText());
break;
case DISPATCHER:
List<DispatcherType> dispatchers = filterMapping.getDispatchers();
if (dispatchers == null) {
dispatchers = new ArrayList<DispatcherType>();
filterMapping.setDispatchers(dispatchers);
}
dispatchers.add(DispatcherType.valueOf(reader.getElementText()));
break;
default: throw unexpectedElement(reader);
}