001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.catalina.mbeans;
019:
020: import javax.management.MBeanException;
021: import javax.management.MBeanServer;
022: import javax.management.RuntimeOperationsException;
023:
024: import org.apache.catalina.Valve;
025: import org.apache.catalina.core.StandardHost;
026: import org.apache.tomcat.util.modeler.BaseModelMBean;
027: import org.apache.tomcat.util.modeler.ManagedBean;
028: import org.apache.tomcat.util.modeler.Registry;
029:
030: /**
031: * <p>A <strong>ModelMBean</strong> implementation for the
032: * <code>org.apache.catalina.core.StandardHost</code> component.</p>
033: *
034: * @author Amy Roh
035: * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
036: */
037:
038: public class StandardHostMBean extends BaseModelMBean {
039:
040: /**
041: * The <code>MBeanServer</code> for this application.
042: */
043: private static MBeanServer mserver = MBeanUtils.createServer();
044:
045: // ----------------------------------------------------------- Constructors
046:
047: /**
048: * Construct a <code>ModelMBean</code> with default
049: * <code>ModelMBeanInfo</code> information.
050: *
051: * @exception MBeanException if the initializer of an object
052: * throws an exception
053: * @exception RuntimeOperationsException if an IllegalArgumentException
054: * occurs
055: */
056: public StandardHostMBean() throws MBeanException,
057: RuntimeOperationsException {
058:
059: super ();
060:
061: }
062:
063: // ------------------------------------------------------------- Attributes
064:
065: // ------------------------------------------------------------- Operations
066:
067: /**
068: * Add an alias name that should be mapped to this Host
069: *
070: * @param alias The alias to be added
071: *
072: * @exception Exception if an MBean cannot be created or registered
073: */
074: public void addAlias(String alias) throws Exception {
075:
076: StandardHost host = (StandardHost) this .resource;
077: host.addAlias(alias);
078:
079: }
080:
081: /**
082: * Return the set of alias names for this Host
083: *
084: * @exception Exception if an MBean cannot be created or registered
085: */
086: public String[] findAliases() throws Exception {
087:
088: StandardHost host = (StandardHost) this .resource;
089: return host.findAliases();
090:
091: }
092:
093: /**
094: * Return the MBean Names of the Valves assoicated with this Host
095: *
096: * @exception Exception if an MBean cannot be created or registered
097: */
098: public String[] getValves() throws Exception {
099:
100: Registry registry = MBeanUtils.createRegistry();
101: StandardHost host = (StandardHost) this .resource;
102: String mname = MBeanUtils.createManagedName(host);
103: ManagedBean managed = registry.findManagedBean(mname);
104: String domain = null;
105: if (managed != null) {
106: domain = managed.getDomain();
107: }
108: if (domain == null)
109: domain = mserver.getDefaultDomain();
110: Valve[] valves = host.getValves();
111: String[] mbeanNames = new String[valves.length];
112: for (int i = 0; i < valves.length; i++) {
113: mbeanNames[i] = MBeanUtils.createObjectName(domain,
114: valves[i]).toString();
115: }
116:
117: return mbeanNames;
118:
119: }
120:
121: /**
122: * Return the specified alias name from the aliases for this Host
123: *
124: * @param alias Alias name to be removed
125: *
126: * @exception Exception if an MBean cannot be created or registered
127: */
128: public void removeAlias(String alias) throws Exception {
129:
130: StandardHost host = (StandardHost) this.resource;
131: host.removeAlias(alias);
132:
133: }
134:
135: }
|