KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > mbeans > StandardHostMBean


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.catalina.mbeans;
19
20
21 import javax.management.MBeanException JavaDoc;
22 import javax.management.MBeanServer JavaDoc;
23 import javax.management.RuntimeOperationsException JavaDoc;
24
25 import org.apache.catalina.Valve;
26 import org.apache.catalina.core.StandardHost;
27 import org.apache.tomcat.util.modeler.BaseModelMBean;
28 import org.apache.tomcat.util.modeler.ManagedBean;
29 import org.apache.tomcat.util.modeler.Registry;
30
31
32 /**
33  * <p>A <strong>ModelMBean</strong> implementation for the
34  * <code>org.apache.catalina.core.StandardHost</code> component.</p>
35  *
36  * @author Amy Roh
37  * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
38  */

39
40 public class StandardHostMBean extends BaseModelMBean {
41
42     /**
43      * The <code>MBeanServer</code> for this application.
44      */

45     private static MBeanServer JavaDoc mserver = MBeanUtils.createServer();
46
47     // ----------------------------------------------------------- Constructors
48

49
50     /**
51      * Construct a <code>ModelMBean</code> with default
52      * <code>ModelMBeanInfo</code> information.
53      *
54      * @exception MBeanException if the initializer of an object
55      * throws an exception
56      * @exception RuntimeOperationsException if an IllegalArgumentException
57      * occurs
58      */

59     public StandardHostMBean()
60         throws MBeanException JavaDoc, RuntimeOperationsException JavaDoc {
61
62         super();
63
64     }
65
66
67     // ------------------------------------------------------------- Attributes
68

69
70
71     // ------------------------------------------------------------- Operations
72

73
74    /**
75      * Add an alias name that should be mapped to this Host
76      *
77      * @param alias The alias to be added
78      *
79      * @exception Exception if an MBean cannot be created or registered
80      */

81     public void addAlias(String JavaDoc alias)
82         throws Exception JavaDoc {
83
84         StandardHost host = (StandardHost) this.resource;
85         host.addAlias(alias);
86
87     }
88
89
90    /**
91      * Return the set of alias names for this Host
92      *
93      * @exception Exception if an MBean cannot be created or registered
94      */

95     public String JavaDoc [] findAliases()
96         throws Exception JavaDoc {
97
98         StandardHost host = (StandardHost) this.resource;
99         return host.findAliases();
100
101     }
102
103
104    /**
105      * Return the MBean Names of the Valves assoicated with this Host
106      *
107      * @exception Exception if an MBean cannot be created or registered
108      */

109     public String JavaDoc [] getValves()
110         throws Exception JavaDoc {
111
112         Registry registry = MBeanUtils.createRegistry();
113         StandardHost host = (StandardHost) this.resource;
114         String JavaDoc mname = MBeanUtils.createManagedName(host);
115         ManagedBean managed = registry.findManagedBean(mname);
116         String JavaDoc domain = null;
117         if (managed != null) {
118             domain = managed.getDomain();
119         }
120         if (domain == null)
121             domain = mserver.getDefaultDomain();
122         Valve [] valves = host.getValves();
123         String JavaDoc [] mbeanNames = new String JavaDoc[valves.length];
124         for (int i = 0; i < valves.length; i++) {
125             mbeanNames[i] =
126                 MBeanUtils.createObjectName(domain, valves[i]).toString();
127         }
128
129         return mbeanNames;
130
131     }
132
133
134    /**
135      * Return the specified alias name from the aliases for this Host
136      *
137      * @param alias Alias name to be removed
138      *
139      * @exception Exception if an MBean cannot be created or registered
140      */

141     public void removeAlias(String JavaDoc alias)
142         throws Exception JavaDoc {
143
144         StandardHost host = (StandardHost) this.resource;
145         host.removeAlias(alias);
146
147     }
148
149
150 }
151
Popular Tags