* @author mschrag
*/
public class ERXXmlRestParser implements IERXRestParser {
protected ERXRestRequestNode createRequestNodeForElement(Element element, boolean rootNode, ERXRestFormat.Delegate delegate, ERXRestContext context) {
String name = element.getTagName();
ERXRestRequestNode requestNode = new ERXRestRequestNode(name, rootNode);
String valueStr = element.getNodeValue();
NamedNodeMap attributeNodes = element.getAttributes();
for (int attributeNum = 0; attributeNum < attributeNodes.getLength(); attributeNum++) {
Node attribute = attributeNodes.item(attributeNum);
requestNode.setAttributeForKey(attribute.getNodeValue(), attribute.getNodeName());
}
NodeList childNodes = element.getChildNodes();
for (int childNodeNum = 0; childNodeNum < childNodes.getLength(); childNodeNum++) {
Node childNode = childNodes.item(childNodeNum);
if (childNode instanceof Element) {
Element childElement = (Element) childNode;
ERXRestRequestNode childRequestNode = createRequestNodeForElement(childElement, false, delegate, context);
if (childRequestNode != null) {
String childRequestNodeName = childRequestNode.name();
// MS: this is a huge hack, but it turns out that it's surprinsingly tricky to
// identify an array in XML ... I'm cheating here and just saying that if the
// node name is uppercase, it represents a new object and not an attribute ...
// this will totally break on rails-style lowercase class names, but for now
// this flag is just a heuristic
if (childRequestNodeName == null || Character.isUpperCase(childRequestNodeName.charAt(0))) {
childRequestNode.setRootNode(true);
requestNode.setArray(true);
}
requestNode.addChild(childRequestNode);
}
}