KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > model > J2EEServerMdl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.management.model;
25
26 import javax.management.*;
27 import java.util.*;
28
29 //import com.sun.enterprise.management.util.J2EEManagementObjectUtility;
30
//import com.sun.enterprise.tools.admin.RealmTool;
31

32 public class J2EEServerMdl extends J2EEManagedObjectMdl {
33
34     /**
35      * required for storing restart flag
36      */

37     private boolean restartRequired = false;
38     
39     private String JavaDoc serverVendor = "Sun Microsystems, Inc.";
40     private static String JavaDoc MANAGED_OBJECT_TYPE = "J2EEServer";
41     
42     public J2EEServerMdl() {
43         /*
44         super(System.getProperty(com.sun.enterprise.server.J2EEServer.J2EE_APPNAME, "j2ee") +
45             System.getProperty(com.sun.enterprise.server.J2EEServer.J2EE_SERVER_ID_PROP, "100"), false, false, false);
46         //this.serverName = System.getProperty(com.sun.enterprise.server.J2EEServer.J2EE_APPNAME) + System.getProperty(com.sun.enterprise.server.J2EEServer.J2EE_SERVER_ID_PROP);
47          */

48         super("j2ee100", false, false, false);
49     }
50
51 /**
52 * A list of all applications deployed on this J2EEServer.
53 * @supplierCardinality 0..*
54 * /
55     public String[] getdeployedObjects(){
56         Set apps = findNames("j2eeType=J2EEApplication,J2EEServer=" + getJ2EEServer());
57         apps.addAll(findNames("j2eeType=EJBModule,J2EEServer=" + getJ2EEServer()));
58         apps.addAll(findNames("j2eeType=WebModule,J2EEServer=" + getJ2EEServer()));
59         apps.addAll(findNames("j2eeType=ResourceAdapterModule,J2EEServer=" + getJ2EEServer()));
60         apps.addAll(findNames("j2eeType=AppClientModule,J2EEServer=" + getJ2EEServer()));
61
62         Iterator it = apps.iterator();
63         String [] deployed = new String[apps.size()];
64         int i =0;
65         while(it.hasNext()) {
66             deployed[i++] = ((ObjectName)it.next()).toString();
67         }
68         return deployed;
69     }
70
71 /**
72 * A list of resources available to this server.
73 * @supplierCardinality 0..*
74 * /
75     public String[] getresources() {
76         Set res = findNames("j2eeType=JCAResource,J2EEServer=" + getJ2EEServer());
77         res.addAll(findNames("j2eeType=JavaMailResource,J2EEServer=" + getJ2EEServer()));
78         res.addAll(findNames("j2eeType=JDBCResource,J2EEServer=" + getJ2EEServer()));
79         res.addAll(findNames("j2eeType=JMSResource,J2EEServer=" + getJ2EEServer()));
80         res.addAll(findNames("j2eeType=JNDIResource,J2EEServer=" + getJ2EEServer()));
81         res.addAll(findNames("j2eeType=JTAResource,J2EEServer=" + getJ2EEServer()));
82         res.addAll(findNames("j2eeType=RMI_IIOPResource,J2EEServer=" + getJ2EEServer()));
83         res.addAll(findNames("j2eeType=URLResource,J2EEServer=" + getJ2EEServer()));
84         res.addAll(findNames("j2eeType=AdminObjectResource,J2EEServer=" + getJ2EEServer()));
85         Iterator it = res.iterator();
86         String [] resources = new String[res.size()];
87         int i =0;
88         while(it.hasNext()) {
89             resources[i++] = ((ObjectName)it.next()).toString();
90         }
91         return resources;
92     }
93
94 /**
95 * A list of nodes that this J2EEServer spans.
96 * @supplierCardinality 1..*
97 * /
98     public String[] getnodes(){
99         try {
100             return new String [] { (java.net.InetAddress.getLocalHost()).toString() };
101         } catch(Exception e) {
102             return new String[0];
103         }
104     }
105
106 /**
107 * A list of all Java virtual machines on which this J2EEServer has running threads.
108 * @supplierCardinality 0..*
109 * /
110     public String[] getjavaVMs() {
111         Set vms = findNames("j2eeType=JVM");
112
113         Iterator it = vms.iterator();
114         String [] jvms = new String[vms.size()];
115         int i =0;
116         while(it.hasNext()) {
117             jvms[i++] = ((ObjectName)it.next()).toString();
118         }
119         return jvms;
120     }
121
122     /**
123     * Identifies the J2EE platform vendor of this J2EEServer. The value of serverVendor is specified by the vendor.
124     */

125     public String JavaDoc getserverVendor(){
126         return serverVendor;
127     }
128
129     /**
130     * Identifies the J2EE platform version of this J2EEServer. The value of serverVersion is specified by the vendor.
131     * /
132     public String getserverVersion() {
133         return com.sun.enterprise.Version.fullVersion;
134     }
135     /**
136      * The type of the J2EEManagedObject as specified by JSR77. The class that implements a specific type must override this method and return the appropriate type string.
137      */

138     public String JavaDoc getj2eeType() {
139         return MANAGED_OBJECT_TYPE;
140     }
141     
142     /**
143      * The name of the J2EEManagedObject. All managed objects must have a unique name within the context of the management
144      * domain. The name must not be null.
145      */

146     public String JavaDoc getobjectName() {
147         Set s = findNames("j2eeType="+getj2eeType()+",name="+getJ2EEServer());
148         Object JavaDoc [] objs = s.toArray();
149         if (objs.length > 0) {
150             String JavaDoc name = ((ObjectName)objs[0]).toString();
151             return name;
152         } else {
153             return null;
154         }
155     }
156     
157     //Resources section START
158

159     /*
160     public void addJdbcDataSource( String jndiName,
161                                     String url)
162                                     throws Exception {
163         J2EEManagementObjectUtility.addJdbcDataSource(jndiName,
164                                     url);
165     }
166     
167     public void addJdbcXADataSource( String jndiName,
168                                     String userName,
169                                     String password,
170                                     String datasourceClassname,
171                                     String[] propNames,
172                                     String[] propValues)
173                                     throws Exception {
174         J2EEManagementObjectUtility.addJdbcXADataSource(jndiName,
175                                     userName,
176                                     password,
177                                     datasourceClassname,
178                                     propNames,
179                                     propValues);
180     }
181       
182      */

183     
184     /**
185      * Add a JdbcDriver Dynamically
186      */

187     
188     /*
189     public void addJdbcDriver(String driver) throws Exception {
190         J2EEManagementObjectUtility.addJdbcDriver(driver);
191     }
192     
193     public void addConnectorResource( String jndiName,
194                                         String appName,
195                                         String connectorName,
196                                         String userName,
197                                         String password,
198                                         String cfType,
199                                         String[] propNames,
200                                         String[] propValues)
201                                         throws Exception {
202                                              
203         J2EEManagementObjectUtility.addConnectorResource(jndiName,
204                                         appName,
205                                         connectorName,
206                                         userName,
207                                         password,
208                                         cfType,
209                                         propNames,
210                                         propValues);
211     }
212     
213     public void addJMSDestination( String jndiName,
214                                         String resType)
215                                         throws Exception {
216         J2EEManagementObjectUtility.addJMSDestination(jndiName,
217                                         resType);
218     }
219         
220     public void addJMSConnectionFactory( String jndiName,
221                                         String resType,
222                                         String[] propNames,
223                                         String[] propValues)
224                                         throws Exception {
225         J2EEManagementObjectUtility.addJMSConnectionFactory(jndiName,
226                                         resType,
227                                         propNames,
228                                         propValues);
229     }
230     
231     public void addAdminObjectResource (String jndiName,
232                                                 String appName,
233                                                 String connectorName,
234                                                 String adminObjectType,
235                                                 String[] propNames,
236                                                 String[] propValues)
237                                                 throws Exception {
238         J2EEManagementObjectUtility.addAdminObjectResource(jndiName,
239                                                 appName,
240                                                 connectorName,
241                                                 adminObjectType,
242                                                 propNames,
243                                                 propValues);
244     }
245      */

246     
247     /**
248      * Set of ObjectName
249      * see tests1.3/mejb
250      */

251     
252     /*
253     public Set listResources(String resourceType) {
254         return findNames("j2eeType="+resourceType + ",J2EEServer="+this.getJ2EEServer());
255     }
256     
257     public void removeResource(String resourceType, String name) throws Exception {
258         J2EEManagementObjectUtility.removeResource(resourceType, name);
259     }
260     //Resources section END
261
262     // Realm section START
263     public ArrayList showRealms() throws Exception {
264         return RealmTool.showRealms();
265     }
266
267     public ArrayList listUsersInRealm(String realmName) throws Exception {
268         return RealmTool.listUsersInRealm(realmName);
269     }
270
271     public ArrayList listGroupsInDefaultRealm() throws Exception {
272         return RealmTool.listGroupsInDefaultRealm();
273     }
274
275     public void addUserToDefaultRealm(String username, String password, String[] groupName)
276                                                                            throws Exception {
277         RealmTool.addUserToDefaultRealm(username, password, groupName);
278     }
279
280     public void addGroupToDefaultRealm(String groupName) throws Exception {
281         boolean b = RealmTool.addGroupToDefaultRealm(groupName);
282         if(b) restartRequired = true;
283     }
284
285     public void importCertificate(String certificateFileName) throws Exception {
286         boolean b = RealmTool.importCertificate(certificateFileName);
287         if(b) restartRequired = true;
288     }
289
290     public ArrayList getUserGroups(String username) throws Exception {
291         return RealmTool.getUserGroups(username);
292     }
293
294     public void removeUserFromRealm(String realmName, String username) throws Exception {
295         boolean b = RealmTool.removeUserFromRealm(realmName, username);
296         if(b) restartRequired = true;
297     }
298
299     public void removeGroupFromDefaultRealm(String groupName) throws Exception {
300         boolean b = RealmTool.removeGroupFromDefaultRealm(groupName);
301         if(b) restartRequired = true;
302     }
303     // Realm section END
304     
305      */

306     
307     //General Purpose APIs START
308

309     /**
310      * This API can be used to see if any change you made through these mbeans
311      * require a server restart
312      * NYI
313      */

314     /*
315     public boolean isRestartNeeded() {
316     return restartRequired;
317     }
318     //General Purpose APIs
319      */

320 }
321
Popular Tags