* @throws IllegalArgumentException if the specified Xml element was not valid.
*/
public static OrderPatch createFromXml(Element orderPatchElement) throws DavException {
if (!DomUtil.matches(orderPatchElement, XML_ORDERPATCH, NAMESPACE)) {
log.warn("ORDERPATH request body must start with an 'orderpatch' element.");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
// retrieve the href of the orderingtype element
String orderingType;
Element otype = DomUtil.getChildElement(orderPatchElement, XML_ORDERING_TYPE, NAMESPACE);
if (otype != null) {
orderingType = DomUtil.getChildText(otype, DavConstants.XML_HREF, DavConstants.NAMESPACE);
} else {
log.warn("ORDERPATH request body must contain an 'ordering-type' child element.");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
// set build the list of ordering instructions
List tmpList = new ArrayList();
ElementIterator it = DomUtil.getChildren(orderPatchElement, XML_ORDER_MEMBER, NAMESPACE);
while (it.hasNext()) {
Element el = it.nextElement();
try {
// retrieve text 'DAV:segment' child of this DAV:order-member element
String segment = DomUtil.getChildText(el, XML_SEGMENT, NAMESPACE);
// retrieve the 'DAV:position' child element
Position pos = Position.createFromXml(DomUtil.getChildElement(el, XML_POSITION, NAMESPACE));
Member om = new Member(segment, pos);
tmpList.add(om);
} catch (IllegalArgumentException e) {
log.warn("Invalid element in 'orderpatch' request body: " + e.getMessage());
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
}
Member[] instructions = (Member[]) tmpList.toArray(new Member[tmpList.size()]);
return new OrderPatch(orderingType, instructions);
}