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.Attribute;
021: import javax.management.AttributeNotFoundException;
022: import javax.management.InstanceNotFoundException;
023: import javax.management.MBeanException;
024: import javax.management.ReflectionException;
025: import javax.management.RuntimeOperationsException;
026: import javax.management.modelmbean.InvalidTargetObjectTypeException;
027:
028: import org.apache.catalina.connector.Connector;
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: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
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: Object result = null;
086: try {
087: Connector connector = (Connector) getManagedResource();
088: result = IntrospectionUtils.getProperty(connector, name);
089: } catch (InstanceNotFoundException e) {
090: throw new MBeanException(e);
091: } catch (InvalidTargetObjectTypeException e) {
092: throw new MBeanException(e);
093: }
094:
095: return result;
096:
097: }
098:
099: /**
100: * Set the value of a specific attribute of this MBean.
101: *
102: * @param attribute The identification of the attribute to be set
103: * and the new value
104: *
105: * @exception AttributeNotFoundException if this attribute is not
106: * supported by this MBean
107: * @exception MBeanException if the initializer of an object
108: * throws an exception
109: * @exception ReflectionException if a Java reflection exception
110: * occurs when invoking the getter
111: */
112: public void setAttribute(Attribute attribute)
113: throws AttributeNotFoundException, MBeanException,
114: ReflectionException {
115:
116: // Validate the input parameters
117: if (attribute == null)
118: throw new RuntimeOperationsException(
119: new IllegalArgumentException("Attribute is null"),
120: "Attribute is null");
121: String name = attribute.getName();
122: Object value = attribute.getValue();
123: if (name == null)
124: throw new RuntimeOperationsException(
125: new IllegalArgumentException(
126: "Attribute name is null"),
127: "Attribute name is null");
128:
129: try {
130: Connector connector = (Connector) getManagedResource();
131: IntrospectionUtils.setProperty(connector, name, String
132: .valueOf(value));
133: } catch (InstanceNotFoundException e) {
134: throw new MBeanException(e);
135: } catch (InvalidTargetObjectTypeException e) {
136: throw new MBeanException(e);
137: }
138:
139: }
140:
141: }
|