KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jndi > 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.jndi.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.jndi.browser.Browser;
14 import org.ejtools.jndi.browser.frame.ServerInternalFrame;
15 import org.ejtools.jndi.browser.model.Server;
16 import org.ejtools.util.service.Profile;
17 import org.ejtools.util.state.DefaultStoreVisitor;
18 import org.w3c.dom.Document JavaDoc;
19 import org.w3c.dom.Element JavaDoc;
20
21
22 /**
23  * @version $Revision: 1.2 $
24  * @author Laurent Etiemble
25  * @created 3 juin 2003
26  */

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

37    public WorkbenchStoreVisitor(Document JavaDoc document) {
38       this.document = document;
39       this.pushCurrentNode(this.document);
40    }
41
42
43    /**
44     * Description of the Method
45     *
46     * @param o Description of the Parameter
47     */

48    public void persist(ServerInternalFrame o) {
49       logger.debug("ServerInternalFrame");
50
51       Element JavaDoc eFrame = this.document.createElement("jndi-frame");
52       eFrame.setAttribute("title", o.getTitle());
53       Element JavaDoc eProfile = this.document.createElement("profile");
54       eFrame.appendChild(eProfile);
55
56       Profile profile = o.getProfile();
57       for (Iterator JavaDoc iterator = profile.keySet().iterator(); iterator.hasNext(); ) {
58          String JavaDoc key = (String JavaDoc) iterator.next();
59          Element JavaDoc property = this.document.createElement("property");
60          property.setAttribute("key", key);
61          property.appendChild(this.document.createTextNode(profile.getProperty(key)));
62          eProfile.appendChild(property);
63       }
64
65       this.peekCurrentNode().appendChild(eFrame);
66       this.pushCurrentNode(eFrame);
67       this.persist(o.iterator());
68       this.popCurrentNode();
69    }
70
71
72    /**
73     * Description of the Method
74     *
75     * @param o Description of the Parameter
76     */

77    public void persist(Server o) {
78       logger.debug("Server");
79
80       Element JavaDoc server = this.document.createElement("jndi-server");
81       server.setAttribute("name", o.getName());
82
83       this.peekCurrentNode().appendChild(server);
84       this.pushCurrentNode(server);
85       this.persist(o.iterator());
86       this.popCurrentNode();
87    }
88
89    /**
90     * Description of the Method
91     *
92     * @param o Description of the Parameter
93     */

94    public void persist(Browser o) {
95       logger.debug("Browser");
96
97       Element JavaDoc workbench = this.document.createElement("workbench");
98
99       this.peekCurrentNode().appendChild(workbench);
100       this.pushCurrentNode(workbench);
101       this.persist(Sort.getChildrenByClass(o.iterator(), ServerInternalFrame.class));
102       this.popCurrentNode();
103    }
104 }
105
Popular Tags