1 12 13 package org.ejtools.jmx.browser.state; 14 15 16 17 import java.util.Iterator ; 18 19 import org.w3c.dom.Document ; 20 21 import org.w3c.dom.Element ; 22 23 24 25 import org.apache.log4j.Logger; 26 27 import org.ejtools.beans.Sort; 28 29 import org.ejtools.graph.frame.GraphInternalFrame; 30 31 import org.ejtools.graph.service.GraphConsumer; 32 33 import org.ejtools.graph.service.GraphProducer; 34 35 import org.ejtools.jmx.browser.Browser; 36 37 import org.ejtools.jmx.browser.frame.ServerInternalFrame; 38 39 import org.ejtools.jmx.browser.model.Domain; 40 41 import org.ejtools.jmx.browser.model.Resource; 42 43 import org.ejtools.jmx.browser.model.Server; 44 45 import org.ejtools.util.service.Profile; 46 47 import org.ejtools.util.state.DefaultStoreVisitor; 48 49 50 51 52 53 62 63 public class WorkbenchStoreVisitor extends DefaultStoreVisitor { 64 65 private Document document; 66 67 private static Logger logger = Logger.getLogger(WorkbenchStoreVisitor.class); 68 69 70 71 72 73 82 83 public WorkbenchStoreVisitor(Document document) { 84 85 this.document = document; 86 87 this.pushCurrentNode(this.document); 88 89 } 90 91 92 93 94 95 104 105 public void persist(ServerInternalFrame o) { 106 107 logger.debug("ServerInternalFrame"); 108 109 110 111 Element eFrame = this.document.createElement("jmx-frame"); 112 113 eFrame.setAttribute("title", o.getTitle()); 114 115 Element eProfile = this.document.createElement("profile"); 116 117 eFrame.appendChild(eProfile); 118 119 120 121 Profile profile = o.getProfile(); 122 123 for (Iterator iterator = profile.keySet().iterator(); iterator.hasNext(); ) { 124 125 String key = (String ) iterator.next(); 126 127 Element property = this.document.createElement("property"); 128 129 property.setAttribute("key", key); 130 131 property.appendChild(this.document.createTextNode(profile.getProperty(key))); 132 133 eProfile.appendChild(property); 134 135 } 136 137 138 139 this.peekCurrentNode().appendChild(eFrame); 140 141 this.pushCurrentNode(eFrame); 142 143 this.persist(o.iterator()); 144 145 this.popCurrentNode(); 146 147 } 148 149 150 151 152 153 162 163 public void persist(GraphInternalFrame o) { 164 165 logger.debug("GraphInternalFrame"); 166 167 168 169 Element eFrame = this.document.createElement("graph-frame"); 170 171 eFrame.setAttribute("name", o.getName()); 172 173 eFrame.setAttribute("delay", String.valueOf(o.getDelay())); 174 175 eFrame.setAttribute("scale", String.valueOf(o.getScale())); 176 177 178 179 this.peekCurrentNode().appendChild(eFrame); 180 181 this.pushCurrentNode(eFrame); 182 183 this.persist(o.iterator()); 184 185 this.popCurrentNode(); 186 187 } 188 189 190 191 192 193 202 203 public void persist(Server o) { 204 205 logger.debug("Server"); 206 207 208 209 Element server = this.document.createElement("jmx-server"); 210 211 server.setAttribute("name", o.getName()); 212 213 server.setAttribute("connected", "" + o.isConnected()); 214 215 216 217 this.peekCurrentNode().appendChild(server); 218 219 this.pushCurrentNode(server); 220 221 this.persist(o.iterator()); 222 223 this.popCurrentNode(); 224 225 } 226 227 228 229 230 231 240 241 public void persist(Domain o) { 242 243 this.persist(o.iterator()); 244 245 } 246 247 248 249 250 251 260 261 public void persist(Browser o) { 262 263 logger.debug("Browser"); 264 265 266 267 Element workbench = this.document.createElement("workbench"); 268 269 270 271 this.peekCurrentNode().appendChild(workbench); 272 273 this.pushCurrentNode(workbench); 274 275 this.persist(Sort.getChildrenByClass(o.iterator(), GraphInternalFrame.class)); 276 277 this.persist(Sort.getChildrenByClass(o.iterator(), ServerInternalFrame.class)); 278 279 this.popCurrentNode(); 280 281 } 282 283 284 285 286 287 296 297 public void persist(Resource o) { 298 299 try { 300 301 int g = o.getGraphProducers().size(); 302 303 boolean notif = o.isRegisteredForNotifications(); 304 305 306 307 if ((g > 0) || notif) { 308 309 Element resource = this.document.createElement("jmx-resource"); 310 311 resource.setAttribute("objectName", o.getCanonicalName()); 312 313 314 315 if (notif) { 316 317 resource.setAttribute("listen", "true"); 318 319 } 320 321 if (g > 0) { 322 323 GraphConsumer[] consumers = o.getGraphConsumers(); 324 325 326 327 for (Iterator iterator = o.getGraphProducers().keySet().iterator(); iterator.hasNext(); ) { 328 329 String attribute = (String ) iterator.next(); 330 331 GraphProducer producer = (GraphProducer) o.getGraphProducers().get(attribute); 332 333 334 335 GraphConsumer consumer = null; 336 337 for (int i = 0; i < consumers.length; i++) { 338 339 GraphConsumer gc = consumers[i]; 340 341 if (gc.containsGraphProducer(producer)) { 342 343 consumer = gc; 344 345 } 346 347 } 348 349 if (consumer != null) { 350 351 Element graph = this.document.createElement("jmx-graph"); 352 353 graph.setAttribute("attribute", attribute); 354 355 graph.setAttribute("target", consumer.toString()); 356 357 resource.appendChild(graph); 358 359 } 360 361 363 365 367 369 } 370 371 } 372 373 this.peekCurrentNode().appendChild(resource); 374 375 this.pushCurrentNode(resource); 376 377 this.persist(o.iterator()); 378 379 this.popCurrentNode(); 380 381 } 382 383 } catch (Exception e) { 384 385 e.printStackTrace(); 386 387 } 388 389 } 390 391 } 392 393 | Popular Tags |