[Ejtools-cvs] applications/jndi.browser/src/main/org/ejtools/jndi/browser/state WorkbenchState.java,
Brought to you by:
letiemble
From: <let...@us...> - 2003-11-27 01:30:33
|
Update of /cvsroot/ejtools/applications/jndi.browser/src/main/org/ejtools/jndi/browser/state In directory sc8-pr-cvs1:/tmp/cvs-serv17169/jndi.browser/src/main/org/ejtools/jndi/browser/state Added Files: WorkbenchState.java WorkbenchStoreVisitor.java Log Message: Address Todo #755528 Address Todo #800902 --- NEW FILE: WorkbenchState.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package org.ejtools.jndi.browser.state; import java.beans.beancontext.BeanContext; import java.io.File; import java.net.URL; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.ejtools.jndi.browser.Browser; import org.ejtools.jndi.browser.frame.ServerInternalFrame; import org.ejtools.jndi.browser.model.Server; import org.ejtools.jndi.browser.state.rules.ServerInternalFrameRule; import org.ejtools.jndi.browser.state.rules.ServerRule; import org.ejtools.util.service.ProfileRule; import org.ejtools.util.state.LoadHandler; import org.ejtools.util.state.StoreVisitor; import org.w3c.dom.Document; /** * @author Laurent Etiemble * @created 3 juin 2003 * @version $Revision: 1.1 $ */ public class WorkbenchState { /** Description of the Field */ private BeanContext context; /** Description of the Field */ private Document document; /** Description of the Field */ private URL workbenchURL; /** *Constructor for the FilePersistenceStore object * * @param context Description of the Parameter */ public WorkbenchState(BeanContext context) { this.context = context; } /** * Gets the workbenchFile attribute of the WorkbenchStore object * * @return The workbenchFile value */ public URL getWorkbenchURL() { return this.workbenchURL; } /** Description of the Method */ public void load() { // Check that the URL is not null andthat URL is a file if ((this.workbenchURL == null) && (!this.workbenchURL.getProtocol().equals("file"))) { return; } try { LoadHandler handler = new LoadHandler(); handler.getContext().put("CONTAINER", this.context); handler.addRule("/workbench/jndi-frame", new ServerInternalFrameRule()); handler.addRule("/workbench/jndi-frame/profile", new ProfileRule()); handler.addRule("/workbench/jndi-frame/profile/property", new ProfileRule.ProfilePropertyRule()); handler.addRule("/workbench/jndi-frame/jmx-server", new ServerRule()); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); File file = new File(this.workbenchURL.getFile()); parser.parse(file, handler); } catch (Exception e) { e.printStackTrace(); } } /** * Sets the workbenchFile attribute of the WorkbenchStore object * * @param workbenchURL The new workbenchURL value */ public void setWorkbenchURL(URL workbenchURL) { this.workbenchURL = workbenchURL; } /** Description of the Method */ public void store() { // Check that the URL is not null andthat URL is a file if ((this.workbenchURL == null) && (!this.workbenchURL.getProtocol().equals("file"))) { return; } try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbFactory.newDocumentBuilder(); this.document = builder.newDocument(); StoreVisitor visitor = new WorkbenchStoreVisitor(this.document); visitor.registerForPersistence(Browser.class); visitor.registerForPersistence(ServerInternalFrame.class); visitor.registerForPersistence(Server.class); visitor.persist(this.context); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.setOutputProperty("indent", "true"); Source source = new DOMSource(this.document); File file = new File(this.workbenchURL.getFile()); Result result = new StreamResult(file); transformer.transform(source, result); } catch (Exception e) { e.printStackTrace(); } } } --- NEW FILE: WorkbenchStoreVisitor.java --- /* * ianRR, is a new RR * * Distributable under LGPL license. * See terms at http://opensource.org/licenses/lgpl-license.php */ package org.ejtools.jndi.browser.state; import java.util.Iterator; import org.apache.log4j.Logger; import org.ejtools.beans.Sort; import org.ejtools.jndi.browser.Browser; import org.ejtools.jndi.browser.frame.ServerInternalFrame; import org.ejtools.jndi.browser.model.Server; import org.ejtools.util.service.Profile; import org.ejtools.util.state.DefaultStoreVisitor; import org.w3c.dom.Document; import org.w3c.dom.Element; /** * @version $Revision: 1.1 $ * @author Laurent Etiemble * @created 3 juin 2003 */ public class WorkbenchStoreVisitor extends DefaultStoreVisitor { private Document document; private static Logger logger = Logger.getLogger(WorkbenchStoreVisitor.class); /** * Constructor for the WorkbenchStoreVisitor object * * @param document Description of the Parameter */ public WorkbenchStoreVisitor(Document document) { this.document = document; this.pushCurrentNode(this.document); } /** * Description of the Method * * @param o Description of the Parameter */ public void persist(ServerInternalFrame o) { logger.debug("ServerInternalFrame"); Element eFrame = this.document.createElement("jndi-frame"); eFrame.setAttribute("title", o.getTitle()); Element eProfile = this.document.createElement("profile"); eFrame.appendChild(eProfile); Profile profile = o.getProfile(); for (Iterator iterator = profile.keySet().iterator(); iterator.hasNext(); ) { String key = (String) iterator.next(); Element property = this.document.createElement("property"); property.setAttribute("key", key); property.appendChild(this.document.createTextNode(profile.getProperty(key))); eProfile.appendChild(property); } this.peekCurrentNode().appendChild(eFrame); this.pushCurrentNode(eFrame); this.persist(o.iterator()); this.popCurrentNode(); } /** * Description of the Method * * @param o Description of the Parameter */ public void persist(Server o) { logger.debug("Server"); Element server = this.document.createElement("jndi-server"); server.setAttribute("name", o.getName()); this.peekCurrentNode().appendChild(server); this.pushCurrentNode(server); this.persist(o.iterator()); this.popCurrentNode(); } /** * Description of the Method * * @param o Description of the Parameter */ public void persist(Browser o) { logger.debug("Browser"); Element workbench = this.document.createElement("workbench"); this.peekCurrentNode().appendChild(workbench); this.pushCurrentNode(workbench); this.persist(Sort.getChildrenByClass(o.iterator(), ServerInternalFrame.class)); this.popCurrentNode(); } } |