}
if (version == null) {
// It is likely an error to not have a version at this point though
version = Version.SERVLET_3_0;
}
WebMetaData wmd = null;
switch (version) {
case SERVLET_2_2: wmd = new Web22MetaData(); break;
case SERVLET_2_3: wmd = new Web23MetaData(); break;
case SERVLET_2_4: wmd = new Web24MetaData(); break;
case SERVLET_2_5: wmd = new Web25MetaData(); break;
case SERVLET_3_0: wmd = new Web30MetaData(); break;
}
// 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: {
wmd.setId(value);
break;
}
case VERSION: {
wmd.setVersion(value);
break;
}
case METADATA_COMPLETE: {
if (wmd instanceof Web25MetaData || wmd instanceof Web30MetaData) {
if (Boolean.TRUE.equals(Boolean.valueOf(value))) {
if (wmd instanceof Web25MetaData) {
((Web25MetaData) wmd).setMetadataComplete(true);
}
if (wmd instanceof Web30MetaData) {
((Web30MetaData) wmd).setMetadataComplete(true);
}
}
} else {
throw unexpectedAttribute(reader, i);
}
break;
}
default: throw unexpectedAttribute(reader, i);
}
}
DescriptionGroupMetaData descriptionGroup = new DescriptionGroupMetaData();
EnvironmentRefsGroupMetaData env = new EnvironmentRefsGroupMetaData();
// Handle elements
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
if (WebCommonMetaDataParser.parse(reader, wmd)) {
continue;
}
if (EnvironmentRefsGroupMetaDataParser.parse(reader, env)) {
if (wmd.getJndiEnvironmentRefsGroup() == null) {
wmd.setJndiEnvironmentRefsGroup(env);
}
continue;
}
if (DescriptionGroupMetaDataParser.parse(reader, descriptionGroup)) {
if (wmd.getDescriptionGroup() == null) {
wmd.setDescriptionGroup(descriptionGroup);
}
continue;
}
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case ABSOLUTE_ORDERING:
if (wmd instanceof Web30MetaData) {
((Web30MetaData) wmd).setAbsoluteOrdering(AbsoluteOrderingMetaDataParser.parse(reader));
} else {
throw unexpectedElement(reader);
}
break;
case MODULE_NAME:
if (wmd instanceof Web30MetaData) {
((Web30MetaData) wmd).setModuleName(reader.getElementText());
} else {
throw unexpectedElement(reader);
}
break;
case TAGLIB:
if (wmd instanceof Web22MetaData || wmd instanceof Web23MetaData) {
JspConfigMetaData jspConfig = wmd.getJspConfig();
if (jspConfig == null) {
jspConfig = new JspConfigMetaData();
wmd.setJspConfig(jspConfig);
}
List<TaglibMetaData> taglibs = jspConfig.getTaglibs();
if (taglibs == null) {
taglibs = new ArrayList<TaglibMetaData>();
jspConfig.setTaglibs(taglibs);