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()); }
/** * 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 boolean superSimple(MessagePart part) { // this is mainly here for backward compatability for when this Reporter // only wrote out the main message. List<MessagePart> list = part.getChildren(); Properties props = part.getProps(); boolean hasChildren = (list != null && !list.isEmpty()); boolean hasProps = (props != null && props.size() > 0); // return true if we are very very simple! return !hasProps && !hasChildren; }
Properties props = res.getReport().getTopMessagePart().getProps(); String uptimeStr = props.getProperty("Uptime"); String pidstr = props.getProperty("Pid");
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 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()); } }
private void write(MessagePart part, PrintWriter writer) { writer.println("{ " + quote("name") + ":" + quote(part.getMessage())); if (top) { writer.println(", " + quote("command") + ":" + quote(actionDescription)); writer.println(", " + quote("exit_code") + ":" + quote("" + this.exitCode)); top = false; } writeProperties(part.getProps(), writer); boolean first = true; for (MessagePart child : part.getChildren()) { if (first == true) { writer.println(", " + quote("result") + " : ["); } else { writer.println(","); } first = false; write(child, writer); } if (first == false) { //close the array writer.println("]"); } writer.println("}"); }
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()); } }
private void write(int level, MessagePart part, PrintWriter writer) { String mess = part.getMessage(); if (mess==null){ mess = "";//better than a null string output } if (level>6) { writer.println(mess); } else { writer.println("<h" + level + ">" + mess + "</h" + level + ">"); } write(part.getProps(), writer); for (MessagePart child : part.getChildren()) { write(level+1, child, writer); } }
@Override public Collection<String> getDeployedApplications() throws GlassFishException { try { CommandExecutorImpl executer = habitat.getService(CommandExecutorImpl.class); ActionReport report = executer.executeCommand("list-components"); Properties props = report.getTopMessagePart().getProps(); return new ArrayList<String>(props.stringPropertyNames()); } catch (Exception e) { throw new GlassFishException(e); } }
@Override public Collection<String> getDeployedApplications() throws GlassFishException { try { CommandExecutorImpl executer = habitat.getComponent(CommandExecutorImpl.class); ActionReport report = executer.executeCommand("list-components"); Properties props = report.getTopMessagePart().getProps(); return new ArrayList<String>(props.stringPropertyNames()); } catch (Exception e) { throw new GlassFishException(e); } }
private void write(String indent, MessagePart part, StringBuilder out) { out.append(indent).append(part.getMessage()).append('\n'); write(indent + INDENT, part.getProps(), out); for (MessagePart child : part.getChildren()) { write(indent + INDENT, child, out); } }