* @author Remy Maucherat
*/
public class VariableMetaDataParser extends MetaDataElementParser {
public static VariableMetaData parse(XMLStreamReader reader) throws XMLStreamException {
VariableMetaData variable = new VariableMetaData();
// 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: {
variable.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 (variable.getDescriptions() == null) {
variable.setDescriptions(descriptions);
}
continue;
}
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case NAME_GIVEN:
variable.setNameGiven(reader.getElementText());
break;
case NAME_FROM_ATTRIBUTE:
variable.setNameFromAttribute(reader.getElementText());
break;
case VARIABLE_CLASS:
variable.setVariableClass(reader.getElementText());
break;
case DECLARE:
variable.setDeclare(reader.getElementText());
break;
case SCOPE:
variable.setScope(VariableScopeType.valueOf(reader.getElementText()));
break;
default: throw unexpectedElement(reader);
}
}