1 22 package org.objectweb.petals.kernel.mx4j; 23 24 import java.io.IOException ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 import javax.management.JMException ; 29 import javax.management.MBeanServer ; 30 import javax.xml.parsers.DocumentBuilder ; 31 32 import mx4j.tools.adaptor.http.HttpCommandProcessor; 33 import mx4j.tools.adaptor.http.HttpInputStream; 34 import mx4j.tools.adaptor.http.ServerCommandProcessor; 35 36 import org.w3c.dom.Document ; 37 import org.w3c.dom.Element ; 38 import org.w3c.dom.Node ; 39 import org.w3c.dom.NodeList ; 40 41 46 public class PetalsCommandProcessor implements HttpCommandProcessor { 47 48 51 protected DocumentBuilder documentBuilder; 52 53 56 protected ServerCommandProcessor serverCommandProcessor = new ServerCommandProcessor(); 57 58 61 public Document executeRequest(HttpInputStream httpInputStream) 62 throws IOException , JMException { 63 Document document = preProcess(httpInputStream); 64 Document outDocument = documentBuilder.newDocument(); 65 Element petalsNode = outDocument.createElement("petals"); 66 outDocument.appendChild(petalsNode); 67 NodeList mbeans = document.getDocumentElement().getChildNodes(); 68 Element servicesNode = outDocument.createElement("services"); 69 Element composNode = outDocument.createElement("components"); 70 List <Node > compos = new ArrayList <Node >(); 71 List <Node > services = new ArrayList <Node >(); 72 for (int i = 0; i < mbeans.getLength(); i++) { 73 Element mbean = (Element ) mbeans.item(i); 74 String objectName = mbean.getAttribute("objectname"); 75 if (objectName.indexOf("type=engine") > -1) { 76 compos.add(mbean); 78 } else if (objectName.indexOf("type=binding") > -1) { 79 compos.add(mbean); 81 } else if (objectName.indexOf("type=installer") > -1) { 82 compos.add(mbean); 84 } else if (objectName.indexOf("type=service") > -1) { 85 services.add(mbean); 87 } 88 } 89 for (Node node : services) { 90 Node tmpNode = outDocument.adoptNode(node); 91 servicesNode.appendChild(tmpNode); 92 } 93 for (Node node : compos) { 94 Node tmpNode = outDocument.adoptNode(node); 95 composNode.appendChild(tmpNode); 96 } 97 petalsNode.appendChild(servicesNode); 98 petalsNode.appendChild(composNode); 99 return outDocument; 100 } 101 102 105 public void setDocumentBuilder(DocumentBuilder documentBuilder) { 106 this.documentBuilder = documentBuilder; 107 serverCommandProcessor.setDocumentBuilder(documentBuilder); 108 } 109 110 113 public void setMBeanServer(MBeanServer mBeanServer) { 114 serverCommandProcessor.setMBeanServer(mBeanServer); 115 } 116 117 126 protected Document preProcess(HttpInputStream httpInputStream) 127 throws IOException , JMException { 128 return serverCommandProcessor.executeRequest(httpInputStream); 129 } 130 131 } 132 | Popular Tags |