* @author Remy Maucherat
*/
public class LocaleEncodingsMetaDataParser extends MetaDataElementParser {
public static LocaleEncodingsMetaData parse(XMLStreamReader reader) throws XMLStreamException {
LocaleEncodingsMetaData localeEncodings = new LocaleEncodingsMetaData();
// 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: {
localeEncodings.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 LOCALE_ENCODING_MAPPING:
List<LocaleEncodingMetaData> localeEncodingsList = localeEncodings.getMappings();
if (localeEncodingsList == null) {
localeEncodingsList = new ArrayList<LocaleEncodingMetaData>();
localeEncodings.setMappings(localeEncodingsList);
}
localeEncodingsList.add(LocaleEncodingMetaDataParser.parse(reader));
break;
default: throw unexpectedElement(reader);
}