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.Attribute;
020: import javax.management.AttributeNotFoundException;
021: import javax.management.InstanceNotFoundException;
022: import javax.management.MBeanException;
023: import javax.management.ReflectionException;
024: import javax.management.RuntimeOperationsException;
025: import javax.management.modelmbean.InvalidTargetObjectTypeException;
026:
027: import org.apache.coyote.ProtocolHandler;
028: import org.apache.coyote.tomcat5.CoyoteConnector;
029: import org.apache.tomcat.util.IntrospectionUtils;
030:
031: /**
032: * <p>A <strong>ModelMBean</strong> implementation for the
033: * <code>org.apache.coyote.tomcat5.CoyoteConnector</code> component.</p>
034: *
035: * @author Amy Roh
036: * @version $Revision: 1.6 $ $Date: 2004/05/27 23:43:42 $
037: */
038:
039: public class ConnectorMBean extends ClassNameMBean {
040:
041: // ----------------------------------------------------------- Constructors
042:
043: /**
044: * Construct a <code>ModelMBean</code> with default
045: * <code>ModelMBeanInfo</code> information.
046: *
047: * @exception MBeanException if the initializer of an object
048: * throws an exception
049: * @exception RuntimeOperationsException if an IllegalArgumentException
050: * occurs
051: */
052: public ConnectorMBean() throws MBeanException,
053: RuntimeOperationsException {
054:
055: super ();
056:
057: }
058:
059: // ------------------------------------------------------------- Attributes
060:
061: /**
062: * Obtain and return the value of a specific attribute of this MBean.
063: *
064: * @param name Name of the requested attribute
065: *
066: * @exception AttributeNotFoundException if this attribute is not
067: * supported by this MBean
068: * @exception MBeanException if the initializer of an object
069: * throws an exception
070: * @exception ReflectionException if a Java reflection exception
071: * occurs when invoking the getter
072: */
073: public Object getAttribute(String name)
074: throws AttributeNotFoundException, MBeanException,
075: ReflectionException {
076:
077: Object attribute = null;
078: // Validate the input parameters
079: if (name == null)
080: throw new RuntimeOperationsException(
081: new IllegalArgumentException(
082: "Attribute name is null"),
083: "Attribute name is null");
084:
085: CoyoteConnector connector = null;
086: try {
087: connector = (CoyoteConnector) getManagedResource();
088: } catch (InstanceNotFoundException e) {
089: throw new MBeanException(e);
090: } catch (InvalidTargetObjectTypeException e) {
091: throw new MBeanException(e);
092: }
093:
094: if (("algorithm").equals(name) || ("keystoreType").equals(name)
095: || ("maxThreads").equals(name)
096: || ("maxSpareThreads").equals(name)
097: || ("minSpareThreads").equals(name)) {
098:
099: if (("keystoreType").equals(name)) {
100: name = "keyType";
101: }
102:
103: ProtocolHandler protocolHandler = connector
104: .getProtocolHandler();
105: /* check the Protocol first, since JkCoyote has an independent
106: * configure method.
107: */
108: try {
109: if (protocolHandler != null) {
110: attribute = IntrospectionUtils.getAttribute(
111: protocolHandler, name);
112: }
113: } catch (Exception e) {
114: throw new MBeanException(e);
115: }
116: } else {
117: attribute = super .getAttribute(name);
118: }
119:
120: return attribute;
121:
122: }
123:
124: /**
125: * Set the value of a specific attribute of this MBean.
126: *
127: * @param attribute The identification of the attribute to be set
128: * and the new value
129: *
130: * @exception AttributeNotFoundException if this attribute is not
131: * supported by this MBean
132: * @exception MBeanException if the initializer of an object
133: * throws an exception
134: * @exception ReflectionException if a Java reflection exception
135: * occurs when invoking the getter
136: */
137: public void setAttribute(Attribute attribute)
138: throws AttributeNotFoundException, MBeanException,
139: ReflectionException {
140:
141: // Validate the input parameters
142: if (attribute == null)
143: throw new RuntimeOperationsException(
144: new IllegalArgumentException("Attribute is null"),
145: "Attribute is null");
146: String name = attribute.getName();
147: Object value = attribute.getValue();
148: if (name == null)
149: throw new RuntimeOperationsException(
150: new IllegalArgumentException(
151: "Attribute name is null"),
152: "Attribute name is null");
153:
154: CoyoteConnector connector = null;
155: try {
156: connector = (CoyoteConnector) getManagedResource();
157: } catch (InstanceNotFoundException e) {
158: throw new MBeanException(e);
159: } catch (InvalidTargetObjectTypeException e) {
160: throw new MBeanException(e);
161: }
162:
163: if (("algorithm").equals(name) || ("keystoreType").equals(name)
164: || ("maxThreads").equals(name)
165: || ("maxSpareThreads").equals(name)
166: || ("minSpareThreads").equals(name)) {
167:
168: if (("keystoreType").equals(name)) {
169: name = "keyType";
170: }
171:
172: ProtocolHandler protocolHandler = connector
173: .getProtocolHandler();
174: /* check the Protocol first, since JkCoyote has an independent
175: * configure method.
176: */
177: try {
178: if (protocolHandler != null) {
179: IntrospectionUtils.setAttribute(protocolHandler,
180: name, value);
181: }
182: } catch (Exception e) {
183: throw new MBeanException(e);
184: }
185:
186: } else {
187: super .setAttribute(attribute);
188: }
189:
190: }
191:
192: // ------------------------------------------------------------- Operations
193:
194: }
|