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