KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > management > j2ee > J2EEServer


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.management.j2ee;
23
24 import javax.management.MalformedObjectNameException JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.List JavaDoc;
28
29 /**
30  * JBoss implementation of the JSR-77 {@link javax.management.j2ee.J2EEServer
31  * J2EEServer}.
32  *
33  * @author <a HREF="mailto:andreas@jboss.org">Andreas Schaefer</a>
34  * @author <a HREF="mailto:thomas.diesler@jboss.org">Thomas Diesler</a>
35  * @version $Revision: 40550 $
36  */

37 public class J2EEServer extends J2EEManagedObject
38    implements J2EEServerMBean
39 {
40    // Constants -----------------------------------------------------
41

42    // Attributes ----------------------------------------------------
43

44    // list of object names as strings
45
private List JavaDoc deployedObjectNames = new ArrayList JavaDoc();
46
47    // list of object names as strings
48
private List JavaDoc resourceNames = new ArrayList JavaDoc();
49
50    // list of object names as strings
51
private List JavaDoc mJVMs = new ArrayList JavaDoc();
52
53    private String JavaDoc mServerVendor = null;
54
55    private String JavaDoc mServerVersion = null;
56
57    // Static --------------------------------------------------------
58

59    // Constructors --------------------------------------------------
60

61    public J2EEServer(String JavaDoc pName, ObjectName JavaDoc pDomain, String JavaDoc pServerVendor,
62                      String JavaDoc pServerVersion)
63            throws
64            MalformedObjectNameException JavaDoc,
65            InvalidParentException
66    {
67       super(J2EETypeConstants.J2EEServer, pName, pDomain);
68       mServerVendor = pServerVendor;
69       mServerVersion = pServerVersion;
70    }
71
72    // Public --------------------------------------------------------
73

74    /**
75     * @jmx:managed-attribute
76     */

77    public String JavaDoc[] getdeployedObjects()
78    {
79       String JavaDoc[] deployedObjects = new String JavaDoc[deployedObjectNames.size()];
80       deployedObjectNames.toArray(deployedObjects);
81       return deployedObjects;
82    }
83
84    /**
85     * @jmx:managed-operation
86     */

87    public String JavaDoc getdeployedObject(int pIndex)
88    {
89       if (pIndex >= 0 && pIndex < deployedObjectNames.size())
90       {
91          return (String JavaDoc) deployedObjectNames.get(pIndex);
92       }
93       return null;
94    }
95
96    /**
97     * @jmx:managed-attribute
98     */

99    public String JavaDoc[] getresources()
100    {
101       String JavaDoc[] resources = new String JavaDoc[resourceNames.size()];
102       resourceNames.toArray(resources);
103       return resources;
104    }
105
106    /**
107     * @jmx:managed-operation
108     */

109    public String JavaDoc getresource(int pIndex)
110    {
111       if (pIndex >= 0 && pIndex < resourceNames.size())
112       {
113          return (String JavaDoc) resourceNames.get(pIndex);
114       }
115       return null;
116    }
117
118    /**
119     * @jmx:managed-attribute
120     */

121    public String JavaDoc[] getjavaVMs()
122    {
123       String JavaDoc[] jvms = new String JavaDoc[mJVMs.size()];
124       mJVMs.toArray(jvms);
125       return jvms;
126    }
127
128    /**
129     * @jmx:managed-operation
130     */

131    public String JavaDoc getjavaVM(int pIndex)
132    {
133       if (pIndex >= 0 && pIndex < mJVMs.size())
134       {
135          return (String JavaDoc) mJVMs.get(pIndex);
136       }
137       else
138       {
139          return null;
140       }
141    }
142
143    /**
144     * @jmx:managed-attribute
145     */

146    public String JavaDoc getserverVendor()
147    {
148       return mServerVendor;
149    }
150
151    /**
152     * @jmx:managed-attribute
153     */

154    public String JavaDoc getserverVersion()
155    {
156       return mServerVersion;
157    }
158
159    public void addChild(ObjectName JavaDoc pChild)
160    {
161       String JavaDoc lType = J2EEManagedObject.getType(pChild);
162       if (J2EETypeConstants.J2EEApplication.equals(lType) ||
163               J2EETypeConstants.EJBModule.equals(lType) ||
164               J2EETypeConstants.ResourceAdapterModule.equals(lType) ||
165               J2EETypeConstants.WebModule.equals(lType) ||
166               J2EETypeConstants.ServiceModule.equals(lType))
167       {
168          deployedObjectNames.add(pChild.getCanonicalName());
169       }
170       else if (J2EETypeConstants.JVM.equals(lType))
171       {
172          mJVMs.add(pChild.getCanonicalName());
173       }
174       else if (J2EETypeConstants.JNDIResource.equals(lType) ||
175               J2EETypeConstants.JMSResource.equals(lType) ||
176               J2EETypeConstants.URLResource.equals(lType) ||
177               J2EETypeConstants.JTAResource.equals(lType) ||
178               J2EETypeConstants.JavaMailResource.equals(lType) ||
179               J2EETypeConstants.JDBCResource.equals(lType) ||
180               J2EETypeConstants.RMI_IIOPResource.equals(lType) ||
181               J2EETypeConstants.JCAResource.equals(lType))
182       {
183          resourceNames.add(pChild.getCanonicalName());
184       }
185    }
186
187    public void removeChild(ObjectName JavaDoc pChild)
188    {
189       String JavaDoc lType = J2EEManagedObject.getType(pChild);
190       if (J2EETypeConstants.J2EEApplication.equals(lType) ||
191               J2EETypeConstants.EJBModule.equals(lType) ||
192               J2EETypeConstants.ResourceAdapterModule.equals(lType) ||
193               J2EETypeConstants.WebModule.equals(lType) ||
194               J2EETypeConstants.ServiceModule.equals(lType))
195       {
196          deployedObjectNames.remove(pChild.getCanonicalName());
197       }
198       else if (J2EETypeConstants.JVM.equals(lType))
199       {
200          mJVMs.remove(pChild.getCanonicalName());
201       }
202       else if (J2EETypeConstants.JNDIResource.equals(lType) ||
203               J2EETypeConstants.JMSResource.equals(lType) ||
204               J2EETypeConstants.URLResource.equals(lType) ||
205               J2EETypeConstants.JTAResource.equals(lType) ||
206               J2EETypeConstants.JavaMailResource.equals(lType) ||
207               J2EETypeConstants.JDBCResource.equals(lType) ||
208               J2EETypeConstants.RMI_IIOPResource.equals(lType) ||
209               J2EETypeConstants.JCAResource.equals(lType))
210       {
211          resourceNames.remove(pChild.getCanonicalName());
212       }
213    }
214
215    public String JavaDoc toString()
216    {
217       return "J2EEServer { " + super.toString() + " } [ " +
218               "depoyed objects: " + deployedObjectNames +
219               ", resources: " + resourceNames +
220               ", JVMs: " + mJVMs +
221               ", J2EE vendor: " + mServerVendor +
222               " ]";
223    }
224
225    // Package protected ---------------------------------------------
226

227    // Protected -----------------------------------------------------
228

229    // Private -------------------------------------------------------
230

231    // Inner classes -------------------------------------------------
232
}
233
Popular Tags