KickJava   Java API By Example, From Geeks To Geeks.

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


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.MBeanServer JavaDoc;
25 import javax.management.MalformedObjectNameException JavaDoc;
26 import javax.management.ObjectName JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Set JavaDoc;
30
31 /**
32  * Root class of the JBoss JSR-77 implementation of
33  *
34  * @author <a HREF="mailto:andreas@jboss.org">Andreas Schaefer</a>
35  * @author <a HREF="mailto:scott.stark@jboss.org">Scott Stark</a>
36  * @author <a HREF="mailto:thomas.diesler@jboss.org">Thomas Diesler</a>
37  * @version $Revision: 40550 $
38  */

39 public class J2EEDomain extends J2EEManagedObject
40    implements J2EEDomainMBean
41 {
42
43    // Attributes ----------------------------------------------------
44
/**
45     * The local server J2EEDomain implementation name
46     */

47    private static String JavaDoc domainName = null;
48
49    /**
50     * list of servers associated with the domain as strings
51     */

52    private List JavaDoc serverNames = new ArrayList JavaDoc();
53
54    // Static --------------------------------------------------------
55
/**
56     * Get the local J2EEDomain instance name
57     *
58     * @return the J2EEDomain object name for the local server.
59     */

60    public static String JavaDoc getDomainName()
61    {
62       return domainName;
63    }
64
65    /**
66     * Query for the J2EEServer MBean in the given domain.
67     *
68     * @param mbeanServer the local MBeanServer
69     * @return the J2EEServer name if found, null otherwise
70     */

71    public static ObjectName JavaDoc getDomainServerName(MBeanServer JavaDoc mbeanServer)
72    {
73       ObjectName JavaDoc domainServer = null;
74       try
75       {
76          // Query for all MBeans matching the J2EEServer naming convention
77
ObjectName JavaDoc serverQuery = new ObjectName JavaDoc(domainName + ":" +
78                  J2EEManagedObject.TYPE + "=" + J2EETypeConstants.J2EEServer + "," + "*");
79
80          Set JavaDoc servers = mbeanServer.queryNames(serverQuery, null);
81          if (servers.isEmpty() == false)
82          {
83             domainServer = (ObjectName JavaDoc) servers.iterator().next();
84          }
85       }
86       catch (Exception JavaDoc ignore)
87       {
88       }
89       return domainServer;
90    }
91
92    // Constructors --------------------------------------------------
93

94    public J2EEDomain(String JavaDoc domainName)
95            throws MalformedObjectNameException JavaDoc,
96            InvalidParentException
97    {
98       super(domainName, J2EETypeConstants.J2EEDomain, domainName);
99       J2EEDomain.domainName = domainName;
100    }
101
102    // Public --------------------------------------------------------
103

104    /**
105     * Return the J2EEServer names associated with this domain.
106     *
107     * @jmx:managed-attribute
108     */

109    public String JavaDoc[] getservers()
110    {
111       String JavaDoc[] servers = new String JavaDoc[serverNames.size()];
112       serverNames.toArray(servers);
113       return servers;
114    }
115
116    /**
117     * @jmx:managed-operation
118     */

119    public String JavaDoc getserver(int pIndex)
120    {
121       if (pIndex >= 0 && pIndex < serverNames.size())
122       {
123          return (String JavaDoc) serverNames.get(pIndex);
124       }
125       return null;
126    }
127
128    // J2EEManagedObject implementation ----------------------------------------------
129

130    public void addChild(ObjectName JavaDoc pChild)
131    {
132       String JavaDoc lType = J2EEManagedObject.getType(pChild);
133       if (J2EETypeConstants.J2EEServer.equals(lType))
134       {
135          serverNames.add(pChild.getCanonicalName());
136       }
137    }
138
139    public void removeChild(ObjectName JavaDoc pChild)
140    {
141       String JavaDoc lType = J2EEManagedObject.getType(pChild);
142       if (J2EETypeConstants.J2EEServer.equals(lType))
143       {
144          serverNames.remove(pChild.getCanonicalName());
145       }
146    }
147    // Object overrides ---------------------------------------------------
148

149    public String JavaDoc toString()
150    {
151       return "J2EEDomain { " + super.toString() + " } [ " +
152               ", servers: " + serverNames +
153               " ]";
154    }
155
156    // Package protected ---------------------------------------------
157

158    // Protected -----------------------------------------------------
159

160    // Private -------------------------------------------------------
161

162    // Inner classes -------------------------------------------------
163
}
164
Popular Tags