* @author Remy Maucherat
*/
public class MultipartConfigMetaDataParser extends MetaDataElementParser {
public static MultipartConfigMetaData parse(XMLStreamReader reader) throws XMLStreamException {
MultipartConfigMetaData multipartConfig = new MultipartConfigMetaData();
// 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: {
multipartConfig.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 LOCATION:
multipartConfig.setLocation(reader.getElementText());
break;
case MAX_FILE_SIZE:
try {
multipartConfig.setMaxFileSize(Long.valueOf(reader.getElementText()));
} catch (NumberFormatException e) {
throw unexpectedValue(reader, e);
}
break;
case MAX_REQUEST_SIZE:
try {
multipartConfig.setMaxRequestSize(Long.valueOf(reader.getElementText()));
} catch (NumberFormatException e) {
throw unexpectedValue(reader, e);
}
break;
case FILE_SIZE_THRESHOLD:
try {
multipartConfig.setFileSizeThreshold(Integer.valueOf(reader.getElementText()));
} catch (NumberFormatException e) {
throw unexpectedValue(reader, e);
}
break;
default: throw unexpectedElement(reader);