KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > management > browser > state > WorkbenchStoreVisitor


1 /*
2  * ianRR, is a new RR
3  *
4  * Distributable under LGPL license.
5  * See terms at http://opensource.org/licenses/lgpl-license.php
6  */

7 package org.ejtools.management.browser.state;
8
9 import java.util.Iterator JavaDoc;
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 JavaDoc;
23 import org.w3c.dom.Element JavaDoc;
24
25
26 /**
27  * @version $Revision: 1.2 $
28  * @author Laurent Etiemble
29  * @created 3 juin 2003
30  */

31 public class WorkbenchStoreVisitor extends DefaultStoreVisitor {
32    private Document JavaDoc document;
33    private static Logger logger = Logger.getLogger(WorkbenchStoreVisitor.class);
34
35
36    /**
37     * Constructor for the WorkbenchStoreVisitor object
38     *
39     * @param document Description of the Parameter
40     */

41    public WorkbenchStoreVisitor(Document JavaDoc document) {
42       this.document = document;
43       this.pushCurrentNode(this.document);
44    }
45
46
47    /**
48     * Description of the Method
49     *
50     * @param o Description of the Parameter
51     */

52    public void persist(ServerInternalFrame o) {
53       logger.debug("ServerInternalFrame");
54
55       Element JavaDoc eFrame = this.document.createElement("management-frame");
56       eFrame.setAttribute("title", o.getTitle());
57       Element JavaDoc eProfile = this.document.createElement("profile");
58       eFrame.appendChild(eProfile);
59
60       Profile profile = o.getProfile();
61       for (Iterator JavaDoc iterator = profile.keySet().iterator(); iterator.hasNext(); ) {
62          String JavaDoc key = (String JavaDoc) iterator.next();
63          Element JavaDoc 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    /**
77     * Description of the Method
78     *
79     * @param o Description of the Parameter
80     */

81    public void persist(GraphInternalFrame o) {
82       logger.debug("GraphInternalFrame");
83
84       Element JavaDoc 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    /**
97     * Description of the Method
98     *
99     * @param o Description of the Parameter
100     */

101    public void persist(Server o) {
102       logger.debug("Server");
103
104       Element JavaDoc 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    /**
115     * Description of the Method
116     *
117     * @param o Description of the Parameter
118     */

119    public void persist(Browser o) {
120       logger.debug("Browser");
121
122       Element JavaDoc 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    /**
133     * Description of the Method
134     *
135     * @param o Description of the Parameter
136     */

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 JavaDoc 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 JavaDoc iterator = o.getGraphProducers().keySet().iterator(); iterator.hasNext(); ) {
153                   String JavaDoc attribute = (String JavaDoc) 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 JavaDoc graph = this.document.createElement("management-graph");
165                      graph.setAttribute("attribute", attribute);
166                      graph.setAttribute("target", consumer.toString());
167                      resource.appendChild(graph);
168                   }
169                   //else
170
//{
171
// logger.warn("A graph producer is not linked to a graph consumer !!!");
172
//}
173
}
174             }
175             this.peekCurrentNode().appendChild(resource);
176             this.pushCurrentNode(resource);
177             this.persist(o.iterator());
178             this.popCurrentNode();
179          }
180       } catch (Exception JavaDoc e) {
181          e.printStackTrace();
182       }
183    }
184 }
185
Popular Tags