KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > util > J2EEModuleUtil


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
25 package com.sun.enterprise.management.util;
26
27 import com.sun.enterprise.management.agent.MEJBUtility;
28 import java.util.*;
29 import javax.management.ObjectName JavaDoc;
30
31 public class J2EEModuleUtil {
32
33     public static String JavaDoc[] getjavaVMs() {
34         Set x = findNames("j2eeType=JVM");
35         Iterator it = x.iterator();
36         String JavaDoc vms[] = new String JavaDoc[x.size()];
37         int i = 0;
38         while(it.hasNext())
39             vms[i++] = ((ObjectName JavaDoc)it.next()).toString();
40         return vms;
41     }
42
43     public static Set findNames(String JavaDoc keys) {
44         Set s = new HashSet();
45         ObjectName JavaDoc namepattern = null;
46         try {
47             String JavaDoc pattern = getDomainName() + ":" + keys + ",*";
48             namepattern = new ObjectName JavaDoc(pattern);
49         }
50         catch(Exception JavaDoc e) {
51             e.printStackTrace();
52         }
53         if(namepattern != null) {
54             MEJBUtility mejb = MEJBUtility.getMEJBUtility();
55             if(mejb != null)
56                 try {
57                     s = mejb.queryNames(namepattern, null);
58                 }
59                 catch(Exception JavaDoc e) {
60                     e.printStackTrace();
61                 }
62         }
63         return s;
64     }
65
66     public static String JavaDoc getDomainName() {
67         return "com.sun.appserv";
68     }
69 }
Popular Tags