[Ejtools-cvs] applications/jmx.browser/src/main/org/ejtools/jmx/browser/frame ServerInternalFrame.ja
Brought to you by:
letiemble
From: <let...@us...> - 2003-12-14 08:40:22
|
Update of /cvsroot/ejtools/applications/jmx.browser/src/main/org/ejtools/jmx/browser/frame In directory sc8-pr-cvs1:/tmp/cvs-serv11709/jmx.browser/src/main/org/ejtools/jmx/browser/frame Modified Files: ServerInternalFrame.java Log Message: Add more javadocs. Adjust some things. Index: ServerInternalFrame.java =================================================================== RCS file: /cvsroot/ejtools/applications/jmx.browser/src/main/org/ejtools/jmx/browser/frame/ServerInternalFrame.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ServerInternalFrame.java 27 Nov 2003 01:13:06 -0000 1.4 --- ServerInternalFrame.java 13 Dec 2003 22:15:07 -0000 1.5 *************** *** 1,322 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jmx.browser.frame; ! ! import java.awt.BorderLayout; ! import java.beans.PropertyChangeEvent; ! import java.beans.PropertyEditor; ! import java.util.Arrays; ! import java.util.Enumeration; ! import java.util.ResourceBundle; ! import java.util.StringTokenizer; ! import java.util.Vector; ! ! import javax.management.ObjectName; ! import javax.swing.JMenuBar; ! ! import org.apache.log4j.Logger; ! import org.ejtools.adwt.BeanContextTreePanel; ! import org.ejtools.adwt.action.Command; ! import org.ejtools.adwt.action.action.RefreshAction; ! import org.ejtools.adwt.service.BeanContextInternalFrame; ! import org.ejtools.adwt.service.MenuBarServiceProvider; ! import org.ejtools.adwt.service.ToolBarServiceProvider; ! import org.ejtools.beans.CustomPropertyEditorManager; ! import org.ejtools.jmx.browser.action.CreateMBeanAction; ! import org.ejtools.jmx.browser.action.ShowNotificationsAction; ! import org.ejtools.jmx.browser.dialog.CreateMBeanDialog; ! import org.ejtools.jmx.browser.model.Resource; ! import org.ejtools.jmx.browser.model.Server; ! import org.ejtools.jmx.browser.model.service.CacheService; ! import org.ejtools.jmx.browser.model.service.CacheServiceProvider; ! import org.ejtools.jmx.browser.model.service.ConnectionServiceProvider; ! import org.ejtools.jmx.browser.model.service.CustomizationServiceProvider; ! import org.ejtools.jmx.browser.model.service.NotificationServiceProvider; ! import org.ejtools.util.service.Profile; ! import org.ejtools.util.service.ProfileHolder; ! ! /** ! * Description of the Class ! * ! * @author <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @version $Revision$ ! * @created 5 septembre 2002 ! */ ! public class ServerInternalFrame extends BeanContextInternalFrame implements ProfileHolder ! { ! /** Description of the Field */ ! protected CacheServiceProvider cacheProvider; ! /** Description of the Field */ ! protected ConnectionServiceProvider connectionProvider; ! /** Description of the Field */ ! protected CustomizationServiceProvider customizationProvider; ! /** Description of the Field */ ! protected MenuBarServiceProvider menubarProvider; ! /** Description of the Field */ ! protected NotificationsInternalFrame notificationFrame; ! /** Description of the Field */ ! protected NotificationServiceProvider notificationProvider; ! /** Description of the Field */ ! protected Profile profile = null; ! /** Description of the Field */ ! protected Server server = null; ! /** Description of the Field */ ! protected ToolBarServiceProvider toolbarProvider; ! /** Description of the Field */ ! private static Logger logger = Logger.getLogger(ServerInternalFrame.class); ! /** Description of the Field */ ! private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.jmx.browser.Resources"); ! ! ! /**Constructor for the ServerInternalFrame object */ ! public ServerInternalFrame() { } ! ! ! /** ! * Gets the profile attribute of the ServerInternalFrame object ! * ! * @return The profile value ! */ ! public Profile getProfile() ! { ! return this.profile; ! } ! ! ! /** ! * @param event Description of the Parameter ! */ ! public void propertyChange(PropertyChangeEvent event) ! { ! if (event.getPropertyName().equals("name")) ! { ! String newName = (String) event.getNewValue(); ! this.setTitle(resources.getString("connection.text.prefix") + " : " + newName); ! } ! } ! ! ! /** ! * Description of the Method ! * ! * @param objectName Description of the Parameter ! * @return Description of the Return Value ! */ ! public Resource queryMBean(String objectName) ! { ! Resource resource = (Resource) this.cacheProvider.get(CacheService.RESOURCE_TYPE, objectName); ! try ! { ! if ((resource != null) && (resource.isRegistered())) ! { ! return resource; ! } ! } ! catch (Exception e) ! { ! logger.warn("Cannot find ObjectName " + objectName, e); ! } ! return null; ! } ! ! ! public void setProfile(Profile profile) ! { ! this.profile = profile; ! } ! ! ! /** ! * Sets the server attribute of the ServerInternalFrame object ! * ! * @param server The new server value ! */ ! public void setServer(Server server) ! { ! this.connectionProvider = new ConnectionServiceProvider(this.profile); ! this.cacheProvider = new CacheServiceProvider(); ! this.customizationProvider = new CustomizationServiceProvider(); ! this.notificationProvider = new NotificationServiceProvider(); ! this.menubarProvider = new MenuBarServiceProvider(); ! this.toolbarProvider = new ToolBarServiceProvider(); ! ! this.server = server; ! this.server.setProfile(this.profile); ! ! this.add(this.connectionProvider); ! this.add(this.cacheProvider); ! this.add(this.notificationProvider); ! this.add(this.customizationProvider); ! this.add(this.menubarProvider); ! this.add(this.toolbarProvider); ! ! this.add(this.server); ! this.notificationFrame = new NotificationsInternalFrame(this.notificationProvider); ! ! this.server.addPropertyChangeListener("name", this); ! this.server.addPropertyChangeListener("name", this.notificationFrame); ! ! this.add(new RefreshAction( ! new Command() ! { ! public void execute() ! { ! ServerInternalFrame.this.server.refresh(); ! } ! })); ! ! this.add(new CreateMBeanAction( ! new Command() ! { ! public void execute() ! { ! ServerInternalFrame.this.createMBean(); ! } ! })); ! ! this.add(new ShowNotificationsAction( ! new Command() ! { ! public void execute() ! { ! ServerInternalFrame.this.showNotificationFrame(); ! } ! })); ! ! BeanContextTreePanel panel = new BeanContextTreePanel(this.server); ! panel.setIndexer(new ResourceIndexer()); ! panel.selectRoot(); ! ! this.frame.setJMenuBar((JMenuBar) this.menubarProvider.getContainer()); ! this.frame.getContentPane().add(this.toolbarProvider.getContainer(), BorderLayout.NORTH); ! this.frame.getContentPane().add(panel, BorderLayout.CENTER); ! } ! ! ! /** Description of the Method */ ! protected void createMBean() ! { ! Vector domains = new Vector(); ! for (Enumeration enum = cacheProvider.keys(CacheService.DOMAIN_TYPE); enum.hasMoreElements(); ) ! { ! domains.add(enum.nextElement() + ":"); ! } ! Object[] domainValues = domains.toArray(); ! Arrays.sort(domainValues); ! ! Vector classes = new Vector(); ! for (Enumeration enum = cacheProvider.keys(CacheService.RESOURCE_TYPE); enum.hasMoreElements(); ) ! { ! Resource resource = (Resource) cacheProvider.get(CacheService.RESOURCE_TYPE, enum.nextElement()); ! if (!classes.contains(resource.getClassName())) ! { ! classes.add(resource.getClassName()); ! } ! } ! Object[] classValues = classes.toArray(); ! Arrays.sort(classValues); ! ! CreateMBeanDialog dialog = new CreateMBeanDialog(null, domainValues, classValues); ! dialog.show(); ! ! Object object = dialog.getObjectName(); ! if (object == null) ! { ! return; ! } ! try ! { ! String className = null; ! ObjectName name = null; ! ObjectName loaderName = null; ! String sParameters = null; ! String sSignature = null; ! ! Object[] parameters = null; ! String[] signature = null; ! ! name = new ObjectName(object.toString()); ! className = dialog.getObjectClass(); ! ! if ("".equals(dialog.getClassLoader())) ! { ! loaderName = null; ! } ! else ! { ! loaderName = new ObjectName(dialog.getClassLoader()); ! } ! ! sParameters = dialog.getParameters(); ! sSignature = dialog.getSignature(); ! if ((!"".equals(sParameters)) && (!"".equals(sSignature))) ! { ! StringTokenizer stParameters = new StringTokenizer(sParameters, ","); ! StringTokenizer stSignature = new StringTokenizer(sSignature, ","); ! if (stParameters.countTokens() == stSignature.countTokens()) ! { ! try ! { ! parameters = new String[stParameters.countTokens()]; ! signature = new String[stSignature.countTokens()]; ! ! for (int i = 0; stParameters.hasMoreTokens(); i++) ! { ! signature[i] = stSignature.nextToken(); ! Class cl = Thread.currentThread().getContextClassLoader().loadClass(signature[i]); ! PropertyEditor pe = CustomPropertyEditorManager.findEditor(cl); ! pe.setAsText(stParameters.nextToken()); ! parameters[i] = pe.getValue(); ! } ! } ! catch (Exception e) ! { ! logger.error("Exception while parsing parameters", e); ! } ! } ! } ! ! this.server.createMBean(className, name, loaderName, parameters, signature); ! } ! catch (Exception e) ! { ! logger.error("Exception while creating MBean", e); ! } ! } ! ! ! /** Description of the Method */ ! protected void initializeBeanContextResources() ! { ! super.initializeBeanContextResources(); ! ! // Hack to update the window title ! this.server.setName(""); ! this.server.setName(resources.getString("connection.text.untitled")); ! } ! ! ! /** Description of the Method */ ! protected void releaseBeanContextResources() ! { ! this.notificationFrame.close(); ! this.server.clear(); ! super.releaseBeanContextResources(); ! } ! ! ! /** Description of the Method */ ! protected void showNotificationFrame() ! { ! NotificationsInternalFrame frame = ServerInternalFrame.this.notificationFrame; ! if (!this.getBeanContext().contains(frame)) ! { ! this.getBeanContext().add(frame); ! } ! frame.activate(); ! } ! } --- 1,322 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.jmx.browser.frame; ! ! import java.awt.BorderLayout; ! import java.beans.PropertyChangeEvent; ! import java.beans.PropertyEditor; ! import java.util.Arrays; ! import java.util.Enumeration; ! import java.util.ResourceBundle; ! import java.util.StringTokenizer; ! import java.util.Vector; ! ! import javax.management.ObjectName; ! import javax.swing.JMenuBar; ! ! import org.apache.log4j.Logger; ! import org.ejtools.adwt.BeanContextTreePanel; ! import org.ejtools.adwt.action.Command; ! import org.ejtools.adwt.action.action.RefreshAction; ! import org.ejtools.adwt.service.BeanContextInternalFrame; ! import org.ejtools.adwt.service.MenuBarServiceProvider; ! import org.ejtools.adwt.service.ToolBarServiceProvider; ! import org.ejtools.beans.CustomPropertyEditorManager; ! import org.ejtools.jmx.browser.action.CreateMBeanAction; ! import org.ejtools.jmx.browser.action.ShowNotificationsAction; ! import org.ejtools.jmx.browser.dialog.CreateMBeanDialog; ! import org.ejtools.jmx.browser.model.Resource; ! import org.ejtools.jmx.browser.model.Server; ! import org.ejtools.jmx.browser.model.service.CacheService; ! import org.ejtools.jmx.browser.model.service.CacheServiceProvider; ! import org.ejtools.jmx.browser.model.service.ConnectionServiceProvider; ! import org.ejtools.jmx.browser.model.service.CustomizationServiceProvider; ! import org.ejtools.jmx.browser.model.service.NotificationServiceProvider; ! import org.ejtools.util.service.Profile; ! import org.ejtools.util.service.ProfileHolder; ! ! /** ! * Description of the Class ! * ! * @author <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @version $Revision$ ! * @created 5 septembre 2002 ! */ ! public class ServerInternalFrame extends BeanContextInternalFrame implements ProfileHolder ! { ! /** Description of the Field */ ! protected CacheServiceProvider cacheProvider; ! /** Description of the Field */ ! protected ConnectionServiceProvider connectionProvider; ! /** Description of the Field */ ! protected CustomizationServiceProvider customizationProvider; ! /** Description of the Field */ ! protected MenuBarServiceProvider menubarProvider; ! /** Description of the Field */ ! protected NotificationsInternalFrame notificationFrame; ! /** Description of the Field */ ! protected NotificationServiceProvider notificationProvider; ! /** Description of the Field */ ! protected Profile profile = null; ! /** Description of the Field */ ! protected Server server = null; ! /** Description of the Field */ ! protected ToolBarServiceProvider toolbarProvider; ! /** Description of the Field */ ! private static Logger logger = Logger.getLogger(ServerInternalFrame.class); ! /** Description of the Field */ ! private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.jmx.browser.Resources"); ! ! ! /**Constructor for the ServerInternalFrame object */ ! public ServerInternalFrame() { } ! ! ! /** ! * Gets the profile attribute of the ServerInternalFrame object ! * ! * @return The profile value ! */ ! public Profile getProfile() ! { ! return this.profile; ! } ! ! ! /** ! * @param event Description of the Parameter ! */ ! public void propertyChange(PropertyChangeEvent event) ! { ! if (event.getPropertyName().equals("name")) ! { ! String newName = (String) event.getNewValue(); ! this.setTitle(resources.getString("connection.text.prefix") + " : " + newName); ! } ! } ! ! ! /** ! * Description of the Method ! * ! * @param objectName Description of the Parameter ! * @return Description of the Return Value ! */ ! public Resource queryMBean(String objectName) ! { ! Resource resource = (Resource) this.cacheProvider.get(CacheService.RESOURCE_TYPE, objectName); ! try ! { ! if ((resource != null) && (resource.isRegistered())) ! { ! return resource; ! } ! } ! catch (Exception e) ! { ! logger.warn("Cannot find ObjectName " + objectName, e); ! } ! return null; ! } ! ! ! public void setProfile(Profile profile) ! { ! this.profile = profile; ! } ! ! ! /** ! * Sets the server attribute of the ServerInternalFrame object ! * ! * @param server The new server value ! */ ! public void setServer(Server server) ! { ! this.connectionProvider = new ConnectionServiceProvider(this.profile); ! this.cacheProvider = new CacheServiceProvider(); ! this.customizationProvider = new CustomizationServiceProvider(); ! this.notificationProvider = new NotificationServiceProvider(); ! this.menubarProvider = new MenuBarServiceProvider(); ! this.toolbarProvider = new ToolBarServiceProvider(); ! ! this.server = server; ! this.server.setProfile(this.profile); ! ! this.add(this.connectionProvider); ! this.add(this.cacheProvider); ! this.add(this.notificationProvider); ! this.add(this.customizationProvider); ! this.add(this.menubarProvider); ! this.add(this.toolbarProvider); ! ! this.add(this.server); ! this.notificationFrame = new NotificationsInternalFrame(this.notificationProvider); ! ! this.server.addPropertyChangeListener("name", this); ! this.server.addPropertyChangeListener("name", this.notificationFrame); ! ! this.add(new RefreshAction( ! new Command() ! { ! public void execute() ! { ! ServerInternalFrame.this.server.refresh(); ! } ! })); ! ! this.add(new CreateMBeanAction( ! new Command() ! { ! public void execute() ! { ! ServerInternalFrame.this.createMBean(); ! } ! })); ! ! this.add(new ShowNotificationsAction( ! new Command() ! { ! public void execute() ! { ! ServerInternalFrame.this.showNotificationFrame(); ! } ! })); ! ! BeanContextTreePanel panel = new BeanContextTreePanel(this.server); ! panel.setIndexer(new ResourceIndexer()); ! panel.selectRoot(); ! ! this.frame.setJMenuBar((JMenuBar) this.menubarProvider.getContainer()); ! this.frame.getContentPane().add(this.toolbarProvider.getContainer(), BorderLayout.NORTH); ! this.frame.getContentPane().add(panel, BorderLayout.CENTER); ! } ! ! ! /** Description of the Method */ ! protected void createMBean() ! { ! Vector domains = new Vector(); ! for (Enumeration enum = cacheProvider.keys(CacheService.DOMAIN_TYPE); enum.hasMoreElements(); ) ! { ! domains.add(enum.nextElement() + ":"); ! } ! Object[] domainValues = domains.toArray(); ! Arrays.sort(domainValues); ! ! Vector classes = new Vector(); ! for (Enumeration enum = cacheProvider.keys(CacheService.RESOURCE_TYPE); enum.hasMoreElements(); ) ! { ! Resource resource = (Resource) cacheProvider.get(CacheService.RESOURCE_TYPE, enum.nextElement()); ! if (!classes.contains(resource.getClassName())) ! { ! classes.add(resource.getClassName()); ! } ! } ! Object[] classValues = classes.toArray(); ! Arrays.sort(classValues); ! ! CreateMBeanDialog dialog = new CreateMBeanDialog(null, domainValues, classValues); ! dialog.show(); ! ! Object object = dialog.getObjectName(); ! if (object == null) ! { ! return; ! } ! try ! { ! String className = null; ! ObjectName name = null; ! ObjectName loaderName = null; ! String sParameters = null; ! String sSignature = null; ! ! Object[] parameters = null; ! String[] signature = null; ! ! name = new ObjectName(object.toString()); ! className = dialog.getObjectClass(); ! ! if ("".equals(dialog.getClassLoader())) ! { ! loaderName = null; ! } ! else ! { ! loaderName = new ObjectName(dialog.getClassLoader()); ! } ! ! sParameters = dialog.getParameters(); ! sSignature = dialog.getSignature(); ! if ((!"".equals(sParameters)) && (!"".equals(sSignature))) ! { ! StringTokenizer stParameters = new StringTokenizer(sParameters, ","); ! StringTokenizer stSignature = new StringTokenizer(sSignature, ","); ! if (stParameters.countTokens() == stSignature.countTokens()) ! { ! try ! { ! parameters = new String[stParameters.countTokens()]; ! signature = new String[stSignature.countTokens()]; ! ! for (int i = 0; stParameters.hasMoreTokens(); i++) ! { ! signature[i] = stSignature.nextToken(); ! Class cl = Thread.currentThread().getContextClassLoader().loadClass(signature[i]); ! PropertyEditor pe = CustomPropertyEditorManager.findEditor(cl); ! pe.setAsText(stParameters.nextToken()); ! parameters[i] = pe.getValue(); ! } ! } ! catch (Exception e) ! { ! logger.error("Exception while parsing parameters", e); ! } ! } ! } ! ! this.server.createMBean(className, name, loaderName, parameters, signature); ! } ! catch (Exception e) ! { ! logger.error("Exception while creating MBean", e); ! } ! } ! ! ! /** Description of the Method */ ! protected void initializeBeanContextResources() ! { ! super.initializeBeanContextResources(); ! ! // Hack to update the window title ! this.server.setName(""); ! this.server.setName(resources.getString("connection.text.untitled")); ! } ! ! ! /** Description of the Method */ ! protected void releaseBeanContextResources() ! { ! this.notificationFrame.close(); ! this.server.clear(); ! super.releaseBeanContextResources(); ! } ! ! ! /** Description of the Method */ ! protected void showNotificationFrame() ! { ! NotificationsInternalFrame frame = ServerInternalFrame.this.notificationFrame; ! if (!this.getBeanContext().contains(frame)) ! { ! this.getBeanContext().add(frame); ! } ! frame.activate(); ! } ! } |