[Ejtools-cvs] applications/management.browser/src/main/org/ejtools/management/browser/state Workbenc
Brought to you by:
letiemble
From: <let...@us...> - 2003-12-14 08:40:54
|
Update of /cvsroot/ejtools/applications/management.browser/src/main/org/ejtools/management/browser/state In directory sc8-pr-cvs1:/tmp/cvs-serv21061/management.browser/src/main/org/ejtools/management/browser/state Modified Files: WorkbenchState.java WorkbenchStoreVisitor.java Log Message: Add more javadocs. Adjust workspace persistence. Index: WorkbenchState.java =================================================================== RCS file: /cvsroot/ejtools/applications/management.browser/src/main/org/ejtools/management/browser/state/WorkbenchState.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WorkbenchState.java 27 Nov 2003 01:39:48 -0000 1.1 --- WorkbenchState.java 13 Dec 2003 22:31:57 -0000 1.2 *************** *** 1,159 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.management.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.graph.frame.GraphInternalFrame; ! import org.ejtools.management.browser.Browser; ! import org.ejtools.management.browser.frame.ServerInternalFrame; ! import org.ejtools.management.browser.model.ManagedObject; ! import org.ejtools.management.browser.model.Server; ! import org.ejtools.management.browser.state.rules.GraphInternalFrameRule; ! import org.ejtools.management.browser.state.rules.ManagementGraphRule; ! import org.ejtools.management.browser.state.rules.ManagedObjectRule; ! import org.ejtools.management.browser.state.rules.ServerInternalFrameRule; ! import org.ejtools.management.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 ! * @version $Revision$ ! * @created 3 juin 2003 ! */ ! 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/graph-frame", new GraphInternalFrameRule()); ! handler.addRule("/workbench/management-frame", new ServerInternalFrameRule()); ! handler.addRule("/workbench/management-frame/profile", new ProfileRule()); ! handler.addRule("/workbench/management-frame/profile/property", new ProfileRule.ProfilePropertyRule()); ! handler.addRule("/workbench/management-frame/management-server", new ServerRule()); ! handler.addRule("/workbench/management-frame/management-server/management-object", new ManagedObjectRule()); ! handler.addRule("/workbench/management-frame/management-server/management-object/management-graph", new ManagementGraphRule()); ! ! 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(GraphInternalFrame.class); ! visitor.registerForPersistence(Server.class); ! visitor.registerForPersistence(ManagedObject.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(); ! } ! } ! } --- 1,159 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.management.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.graph.frame.GraphInternalFrame; ! import org.ejtools.management.browser.Browser; ! import org.ejtools.management.browser.frame.ServerInternalFrame; ! import org.ejtools.management.browser.model.ManagedObject; ! import org.ejtools.management.browser.model.Server; ! import org.ejtools.management.browser.state.rules.GraphInternalFrameRule; ! import org.ejtools.management.browser.state.rules.ManagementGraphRule; ! import org.ejtools.management.browser.state.rules.ManagedObjectRule; ! import org.ejtools.management.browser.state.rules.ServerInternalFrameRule; ! import org.ejtools.management.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 ! * @version $Revision$ ! * @created 3 juin 2003 ! */ ! 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/graph-frame", new GraphInternalFrameRule()); ! handler.addRule("/workbench/management-frame", new ServerInternalFrameRule()); ! handler.addRule("/workbench/management-frame/profile", new ProfileRule()); ! handler.addRule("/workbench/management-frame/profile/property", new ProfileRule.ProfilePropertyRule()); ! handler.addRule("/workbench/management-frame/management-server", new ServerRule()); ! handler.addRule("/workbench/management-frame/management-server/management-object", new ManagedObjectRule()); ! handler.addRule("/workbench/management-frame/management-server/management-object/management-graph", new ManagementGraphRule()); ! ! 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(GraphInternalFrame.class); ! visitor.registerForPersistence(Server.class); ! visitor.registerForPersistence(ManagedObject.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(); ! } ! } ! } Index: WorkbenchStoreVisitor.java =================================================================== RCS file: /cvsroot/ejtools/applications/management.browser/src/main/org/ejtools/management/browser/state/WorkbenchStoreVisitor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WorkbenchStoreVisitor.java 27 Nov 2003 01:39:48 -0000 1.1 --- WorkbenchStoreVisitor.java 13 Dec 2003 22:31:57 -0000 1.2 *************** *** 1,184 **** ! /* ! * ianRR, is a new RR ! * ! * Distributable under LGPL license. ! * See terms at http://opensource.org/licenses/lgpl-license.php ! */ ! package org.ejtools.management.browser.state; ! ! import java.util.Iterator; ! ! import org.apache.log4j.Logger; ! import org.ejtools.beans.Sort; ! import org.ejtools.graph.frame.GraphInternalFrame; ! import org.ejtools.graph.service.GraphConsumer; ! import org.ejtools.graph.service.GraphProducer; ! import org.ejtools.management.browser.Browser; ! import org.ejtools.management.browser.frame.ServerInternalFrame; ! import org.ejtools.management.browser.model.ManagedObject; ! import org.ejtools.management.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$ ! * @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("management-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(GraphInternalFrame o) { ! logger.debug("GraphInternalFrame"); ! ! Element eFrame = this.document.createElement("graph-frame"); ! eFrame.setAttribute("name", o.getName()); ! eFrame.setAttribute("delay", String.valueOf(o.getDelay())); ! eFrame.setAttribute("scale", String.valueOf(o.getScale())); ! ! 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("management-server"); ! server.setAttribute("name", o.getName()); ! server.setAttribute("connected", "" + o.isConnected()); ! ! 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(), GraphInternalFrame.class)); ! this.persist(Sort.getChildrenByClass(o.iterator(), ServerInternalFrame.class)); ! this.popCurrentNode(); ! } ! ! ! /** ! * Description of the Method ! * ! * @param o Description of the Parameter ! */ ! public void persist(ManagedObject o) { ! try { ! int g = o.getGraphProducers().size(); ! boolean notif = o.isRegisteredForNotifications(); ! ! if ((g > 0) || notif) { ! Element resource = this.document.createElement("management-object"); ! resource.setAttribute("objectName", o.getCanonicalName()); ! ! if (notif) { ! resource.setAttribute("listen", "true"); ! } ! if (g > 0) { ! GraphConsumer[] consumers = o.getGraphConsumers(); ! ! for (Iterator iterator = o.getGraphProducers().keySet().iterator(); iterator.hasNext(); ) { ! String attribute = (String) iterator.next(); ! GraphProducer producer = (GraphProducer) o.getGraphProducers().get(attribute); ! ! GraphConsumer consumer = null; ! for (int i = 0; i < consumers.length; i++) { ! GraphConsumer gc = consumers[i]; ! if (gc.containsGraphProducer(producer)) { ! consumer = gc; ! } ! } ! if (consumer != null) { ! Element graph = this.document.createElement("management-graph"); ! graph.setAttribute("attribute", attribute); ! graph.setAttribute("target", consumer.toString()); ! resource.appendChild(graph); ! } ! //else ! //{ ! // logger.warn("A graph producer is not linked to a graph consumer !!!"); ! //} ! } ! } ! this.peekCurrentNode().appendChild(resource); ! this.pushCurrentNode(resource); ! this.persist(o.iterator()); ! this.popCurrentNode(); ! } ! } catch (Exception e) { ! e.printStackTrace(); ! } ! } ! } --- 1,184 ---- ! /* ! * ianRR, is a new RR ! * ! * Distributable under LGPL license. ! * See terms at http://opensource.org/licenses/lgpl-license.php ! */ ! package org.ejtools.management.browser.state; ! ! import java.util.Iterator; ! ! import org.apache.log4j.Logger; ! import org.ejtools.beans.Sort; ! import org.ejtools.graph.frame.GraphInternalFrame; ! import org.ejtools.graph.service.GraphConsumer; ! import org.ejtools.graph.service.GraphProducer; ! import org.ejtools.management.browser.Browser; ! import org.ejtools.management.browser.frame.ServerInternalFrame; ! import org.ejtools.management.browser.model.ManagedObject; ! import org.ejtools.management.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$ ! * @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("management-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(GraphInternalFrame o) { ! logger.debug("GraphInternalFrame"); ! ! Element eFrame = this.document.createElement("graph-frame"); ! eFrame.setAttribute("name", o.getName()); ! eFrame.setAttribute("delay", String.valueOf(o.getDelay())); ! eFrame.setAttribute("scale", String.valueOf(o.getScale())); ! ! 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("management-server"); ! server.setAttribute("name", o.getName()); ! server.setAttribute("connected", "" + o.isConnected()); ! ! 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(), GraphInternalFrame.class)); ! this.persist(Sort.getChildrenByClass(o.iterator(), ServerInternalFrame.class)); ! this.popCurrentNode(); ! } ! ! ! /** ! * Description of the Method ! * ! * @param o Description of the Parameter ! */ ! public void persist(ManagedObject o) { ! try { ! int g = o.getGraphProducers().size(); ! boolean notif = o.isRegisteredForNotifications(); ! ! if ((g > 0) || notif) { ! Element resource = this.document.createElement("management-object"); ! resource.setAttribute("objectName", o.getCanonicalName()); ! ! if (notif) { ! resource.setAttribute("listen", "true"); ! } ! if (g > 0) { ! GraphConsumer[] consumers = o.getGraphConsumers(); ! ! for (Iterator iterator = o.getGraphProducers().keySet().iterator(); iterator.hasNext(); ) { ! String attribute = (String) iterator.next(); ! GraphProducer producer = (GraphProducer) o.getGraphProducers().get(attribute); ! ! GraphConsumer consumer = null; ! for (int i = 0; i < consumers.length; i++) { ! GraphConsumer gc = consumers[i]; ! if (gc.containsGraphProducer(producer)) { ! consumer = gc; ! } ! } ! if (consumer != null) { ! Element graph = this.document.createElement("management-graph"); ! graph.setAttribute("attribute", attribute); ! graph.setAttribute("target", consumer.toString()); ! resource.appendChild(graph); ! } ! //else ! //{ ! // logger.warn("A graph producer is not linked to a graph consumer !!!"); ! //} ! } ! } ! this.peekCurrentNode().appendChild(resource); ! this.pushCurrentNode(resource); ! this.persist(o.iterator()); ! this.popCurrentNode(); ! } ! } catch (Exception e) { ! e.printStackTrace(); ! } ! } ! } |