* @author Remy Maucherat
*/
public class EnvironmentEntryMetaDataParser extends MetaDataElementParser {
public static EnvironmentEntryMetaData parse(XMLStreamReader reader) throws XMLStreamException {
EnvironmentEntryMetaData environmentEntry = new EnvironmentEntryMetaData();
// 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: {
environmentEntry.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 (environmentEntry.getDescriptions() == null) {
environmentEntry.setDescriptions(descriptions);
}
continue;
}
if (ResourceInjectionMetaDataParser.parse(reader, environmentEntry)) {
continue;
}
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case ENV_ENTRY_NAME:
environmentEntry.setEnvEntryName(reader.getElementText());
break;
case ENV_ENTRY_TYPE:
environmentEntry.setType(reader.getElementText());
break;
case ENV_ENTRY_VALUE:
environmentEntry.setValue(reader.getElementText());
break;
default: throw unexpectedElement(reader);
}
}