1 7 package org.ejtools.management.browser.state; 8 9 import java.util.Iterator ; 10 11 import org.apache.log4j.Logger; 12 import org.ejtools.beans.Sort; 13 import org.ejtools.graph.frame.GraphInternalFrame; 14 import org.ejtools.graph.service.GraphConsumer; 15 import org.ejtools.graph.service.GraphProducer; 16 import org.ejtools.management.browser.Browser; 17 import org.ejtools.management.browser.frame.ServerInternalFrame; 18 import org.ejtools.management.browser.model.ManagedObject; 19 import org.ejtools.management.browser.model.Server; 20 import org.ejtools.util.service.Profile; 21 import org.ejtools.util.state.DefaultStoreVisitor; 22 import org.w3c.dom.Document ; 23 import org.w3c.dom.Element ; 24 25 26 31 public class WorkbenchStoreVisitor extends DefaultStoreVisitor { 32 private Document document; 33 private static Logger logger = Logger.getLogger(WorkbenchStoreVisitor.class); 34 35 36 41 public WorkbenchStoreVisitor(Document document) { 42 this.document = document; 43 this.pushCurrentNode(this.document); 44 } 45 46 47 52 public void persist(ServerInternalFrame o) { 53 logger.debug("ServerInternalFrame"); 54 55 Element eFrame = this.document.createElement("management-frame"); 56 eFrame.setAttribute("title", o.getTitle()); 57 Element eProfile = this.document.createElement("profile"); 58 eFrame.appendChild(eProfile); 59 60 Profile profile = o.getProfile(); 61 for (Iterator iterator = profile.keySet().iterator(); iterator.hasNext(); ) { 62 String key = (String ) iterator.next(); 63 Element property = this.document.createElement("property"); 64 property.setAttribute("key", key); 65 property.appendChild(this.document.createTextNode(profile.getProperty(key))); 66 eProfile.appendChild(property); 67 } 68 69 this.peekCurrentNode().appendChild(eFrame); 70 this.pushCurrentNode(eFrame); 71 this.persist(o.iterator()); 72 this.popCurrentNode(); 73 } 74 75 76 81 public void persist(GraphInternalFrame o) { 82 logger.debug("GraphInternalFrame"); 83 84 Element eFrame = this.document.createElement("graph-frame"); 85 eFrame.setAttribute("name", o.getName()); 86 eFrame.setAttribute("delay", String.valueOf(o.getDelay())); 87 eFrame.setAttribute("scale", String.valueOf(o.getScale())); 88 89 this.peekCurrentNode().appendChild(eFrame); 90 this.pushCurrentNode(eFrame); 91 this.persist(o.iterator()); 92 this.popCurrentNode(); 93 } 94 95 96 101 public void persist(Server o) { 102 logger.debug("Server"); 103 104 Element server = this.document.createElement("management-server"); 105 server.setAttribute("name", o.getName()); 106 server.setAttribute("connected", "" + o.isConnected()); 107 108 this.peekCurrentNode().appendChild(server); 109 this.pushCurrentNode(server); 110 this.persist(o.iterator()); 111 this.popCurrentNode(); 112 } 113 114 119 public void persist(Browser o) { 120 logger.debug("Browser"); 121 122 Element workbench = this.document.createElement("workbench"); 123 124 this.peekCurrentNode().appendChild(workbench); 125 this.pushCurrentNode(workbench); 126 this.persist(Sort.getChildrenByClass(o.iterator(), GraphInternalFrame.class)); 127 this.persist(Sort.getChildrenByClass(o.iterator(), ServerInternalFrame.class)); 128 this.popCurrentNode(); 129 } 130 131 132 137 public void persist(ManagedObject o) { 138 try { 139 int g = o.getGraphProducers().size(); 140 boolean notif = o.isRegisteredForNotifications(); 141 142 if ((g > 0) || notif) { 143 Element resource = this.document.createElement("management-object"); 144 resource.setAttribute("objectName", o.getCanonicalName()); 145 146 if (notif) { 147 resource.setAttribute("listen", "true"); 148 } 149 if (g > 0) { 150 GraphConsumer[] consumers = o.getGraphConsumers(); 151 152 for (Iterator iterator = o.getGraphProducers().keySet().iterator(); iterator.hasNext(); ) { 153 String attribute = (String ) iterator.next(); 154 GraphProducer producer = (GraphProducer) o.getGraphProducers().get(attribute); 155 156 GraphConsumer consumer = null; 157 for (int i = 0; i < consumers.length; i++) { 158 GraphConsumer gc = consumers[i]; 159 if (gc.containsGraphProducer(producer)) { 160 consumer = gc; 161 } 162 } 163 if (consumer != null) { 164 Element graph = this.document.createElement("management-graph"); 165 graph.setAttribute("attribute", attribute); 166 graph.setAttribute("target", consumer.toString()); 167 resource.appendChild(graph); 168 } 169 } 174 } 175 this.peekCurrentNode().appendChild(resource); 176 this.pushCurrentNode(resource); 177 this.persist(o.iterator()); 178 this.popCurrentNode(); 179 } 180 } catch (Exception e) { 181 e.printStackTrace(); 182 } 183 } 184 } 185 | Popular Tags |