KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jmx > browser > web > JMXContainer


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.jmx.browser.web;
8
9 import java.beans.beancontext.BeanContextServicesSupport JavaDoc;
10 import java.util.Collection JavaDoc;
11 import java.util.Set JavaDoc;
12
13 import javax.management.ObjectInstance JavaDoc;
14 import javax.management.ObjectName JavaDoc;
15 import javax.management.QueryExp JavaDoc;
16
17 import org.ejtools.jmx.browser.mbean.View;
18 import org.ejtools.jmx.browser.model.Resource;
19 import org.ejtools.jmx.browser.model.Server;
20 import org.ejtools.jmx.browser.model.service.CacheService;
21 import org.ejtools.jmx.browser.model.service.CacheServiceProvider;
22 import org.ejtools.jmx.browser.model.service.ConnectionServiceProvider;
23 import org.ejtools.jmx.browser.model.service.CustomizationServiceProvider;
24 import org.ejtools.jmx.browser.model.service.NotificationServiceProvider;
25
26
27 /**
28  * Description of the Class
29  *
30  * @author letiemble
31  * @created 25 avril 2002
32  * @version $Revision: 1.6 $
33  * @todo Javadoc to complete
34  */

35 public class JMXContainer extends BeanContextServicesSupport JavaDoc
36 {
37    /** Description of the Field */
38    protected CacheServiceProvider cacheProvider;
39    /** Description of the Field */
40    protected ConnectionServiceProvider connectionProvider;
41    /** Description of the Field */
42    protected CustomizationServiceProvider customizationProvider;
43    /** Description of the Field */
44    protected NotificationServiceProvider notificationProvider;
45    /** Description of the Field */
46    protected Server server;
47
48
49    /** Constructor for the JMXTree object */
50    public JMXContainer()
51    {
52       try
53       {
54          this.connectionProvider = new ConnectionServiceProvider();
55          this.notificationProvider = new NotificationServiceProvider();
56          this.cacheProvider = new CacheServiceProvider();
57          this.customizationProvider = new CustomizationServiceProvider();
58          this.server = new Server();
59
60          this.add(this.cacheProvider);
61          this.add(this.connectionProvider);
62          this.add(this.notificationProvider);
63          this.add(this.customizationProvider);
64          this.add(this.server);
65       }
66       catch (Exception JavaDoc e)
67       {
68          e.printStackTrace();
69       }
70    }
71
72
73    /** Description of the Method */
74    public void clearNotifications()
75    {
76       this.notificationProvider.clearAll();
77    }
78
79
80    /**
81     * Description of the Method
82     *
83     * @param className Description of the Parameter
84     * @param name Description of the Parameter
85     * @param loaderName Description of the Parameter
86     * @param params Description of the Parameter
87     * @param signature Description of the Parameter
88     * @return Description of the Return Value
89     * @exception Exception Description of the Exception
90     */

91    public ObjectInstance JavaDoc createMBean(java.lang.String JavaDoc className, ObjectName JavaDoc name, ObjectName JavaDoc loaderName, java.lang.Object JavaDoc[] params, java.lang.String JavaDoc[] signature)
92       throws Exception JavaDoc
93    {
94       return this.server.createMBean(className, name, loaderName, params, signature);
95    }
96
97
98    /**
99     * Getter for the count attribute
100     *
101     * @return The value of count attribute
102     */

103    public int getCount()
104    {
105       return this.server.getCount();
106    }
107
108
109    /**
110     * Getter for the defaultDomain attribute
111     *
112     * @return The value of defaultDomain attribute
113     */

114    public String JavaDoc getDefaultDomain()
115    {
116       return this.server.getDefaultDomain();
117    }
118
119
120    /**
121     * Gets the notifications attribute of the JMXContainer object
122     *
123     * @return The notifications value
124     */

125    public Collection JavaDoc getNotifications()
126    {
127       return this.notificationProvider.listAll();
128    }
129
130
131    /**
132     * Getter for the server attribute
133     *
134     * @return The value of server attribute
135     */

136    public Collection JavaDoc getServer()
137    {
138       return this.server;
139    }
140
141
142    /**
143     * Gets the view attribute of the JMXContainer object
144     *
145     * @param index Description of the Parameter
146     * @return The view value
147     */

148    public View getView(int index)
149    {
150       return this.customizationProvider.getView(index);
151    }
152
153
154    /**
155     * Gets the views attribute of the JMXContainer object
156     *
157     * @return The views value
158     */

159    public Collection JavaDoc getViews()
160    {
161       return this.customizationProvider.getViews();
162    }
163
164
165    /**
166     * Description of the Method
167     *
168     * @param name Description of the Parameter
169     * @param exp Description of the Parameter
170     * @return Description of the Return Value
171     * @exception Exception Description of the Exception
172     */

173    public Set JavaDoc query(ObjectName JavaDoc name, QueryExp JavaDoc exp)
174       throws Exception JavaDoc
175    {
176       return this.server.query(name, exp);
177    }
178
179
180    /** Description of the Method */
181    public void refresh()
182    {
183       this.server.refresh();
184    }
185
186
187    /**
188     * Description of the Method
189     *
190     * @param objectName Description of the Parameter
191     * @return Description of the Return Value
192     */

193    public Object JavaDoc searchObjectName(String JavaDoc objectName)
194    {
195       Resource resource = (Resource) this.cacheProvider.get(CacheService.RESOURCE_TYPE, objectName);
196       try
197       {
198          if ((resource != null) && (resource.isRegistered()))
199          {
200             return resource;
201          }
202       }
203       catch (Exception JavaDoc e)
204       {
205          e.printStackTrace();
206       }
207       return null;
208    }
209    
210    //Slobodan Vujsinovic 2005.06.27.
211
/**
212     * Description of the Method
213     *
214     * @param objectName Description of the Parameter
215     * @param refresh Wether to refresh MBean server connection or not
216     * @return Description of the Return Value
217     */

218    public Object JavaDoc searchObjectName(String JavaDoc objectName, boolean refreshServer)
219    {
220       if (refreshServer){
221               
222               if (this.server.isConnected())
223               {
224                  this.server.disconnect();
225               }
226               
227               refresh();
228               Resource resource = (Resource) this.cacheProvider.get(CacheService.RESOURCE_TYPE, objectName);
229               try
230               {
231                  if ((resource != null) && (resource.isRegistered()))
232                  {
233                     return resource;
234                  }
235               }
236               catch (Exception JavaDoc e)
237               {
238                  e.printStackTrace();
239               }
240               return null;
241           } else {
242             return searchObjectName(objectName);
243           }
244    }
245 }
246
Popular Tags