/** * Write out all the sub-parts as XML elements where the * "childType" is the name of the XML element and the properties * are attributes of the element. Recurse for any subparts. */ private void writeSubPart(Element actionReport, MessagePart part, String childType) { Document d = actionReport.getOwnerDocument(); Element messagePart = d.createElement(childType); actionReport.appendChild(messagePart); for (Map.Entry prop : part.getProps().entrySet()) { messagePart.setAttribute(prop.getKey().toString(), prop.getValue().toString()); } for (MessagePart subPart : part.getChildren()) writeSubPart(messagePart, subPart, subPart.getChildrenType()); }
private void writePart(Element actionReport, MessagePart part, String childType) { Document d = actionReport.getOwnerDocument(); Element messagePart = d.createElement("message-part"); actionReport.appendChild(messagePart); if (childType != null) { messagePart.setAttribute("type", childType); } for (Map.Entry prop : part.getProps().entrySet()) { Element p = d.createElement("property"); messagePart.appendChild(p); p.setAttribute("name", prop.getKey().toString()); p.setAttribute("value", prop.getValue().toString()); } messagePart.setAttribute("message", part.getMessage()); for (MessagePart subPart : part.getChildren()) writeSubPart(messagePart, subPart, subPart.getChildrenType()); }
private void writePart(Element actionReport, MessagePart part, String childType) { Document d = actionReport.getOwnerDocument(); Element messagePart = d.createElement("message-part"); actionReport.appendChild(messagePart); if (childType != null) { messagePart.setAttribute("type", childType); } for (Map.Entry prop : part.getProps().entrySet()) { Element p = d.createElement("property"); messagePart.appendChild(p); p.setAttribute("name", prop.getKey().toString()); Object value = prop.getValue(); if (value instanceof List) { addListElement(p, (List)value); } else if (value instanceof Map) { addMapElement(p, (Map)value); } else { p.setAttribute("value", prop.getValue().toString()); } } messagePart.setAttribute("message", part.getMessage()); for (MessagePart subPart : part.getChildren()) { writePart(messagePart, subPart, subPart.getChildrenType()); } }
attr.putValue("children-type", part.getChildrenType()); attr.putValue("use-main-children-attribute", "true"); StringBuilder keys = null;
private void messageToString(int indentLevel, String id, MessagePart msg, StringBuilder sb) { if (msg == null) { return; } addIndent(indentLevel, sb); sb.append("MESSAGE - ").append(id).append(EOL); if (msg.getMessage() != null && !msg.getMessage().isEmpty()) { addIndent(indentLevel, sb); sb.append(" : ").append(msg.getMessage()).append(EOL); } if (msg.getChildrenType() != null) { addIndent(indentLevel, sb); sb.append(" childrenType: ").append(msg.getChildrenType()).append(EOL); } for (Map.Entry<Object, Object> entry : msg.getProps().entrySet()) { addIndent(indentLevel, sb); sb.append(" >").append(entry.getKey()).append(" = ").append(entry.getValue()); sb.append(EOL); } if (msg.getChildren() != null) { int counter = 0; for (MessagePart child : msg.getChildren()) { messageToString(indentLevel + 1, id + ".M" + counter, child, sb); counter++; } } }
private void copyMessagePart(MessagePart source, MessagePart dest) { if (source == null || dest == null) { return; } dest.setMessage(source.getMessage()); dest.setChildrenType(source.getChildrenType()); Properties props = source.getProps(); if (props != null) { for (Map.Entry<Object, Object> entry : props.entrySet()) { dest.addProperty((String) entry.getKey(), (String) entry.getValue()); } } for (MessagePart chmp : source.getChildren()) { copyMessagePart(chmp, dest.addChild()); } }