KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.management.Attribute JavaDoc;
21 import javax.management.AttributeNotFoundException JavaDoc;
22 import javax.management.InstanceNotFoundException JavaDoc;
23 import javax.management.MBeanException JavaDoc;
24 import javax.management.ReflectionException JavaDoc;
25 import javax.management.RuntimeOperationsException JavaDoc;
26 import javax.management.modelmbean.InvalidTargetObjectTypeException JavaDoc;
27
28 import org.apache.catalina.connector.Connector;
29 import org.apache.tomcat.util.IntrospectionUtils;
30
31
32 /**
33  * <p>A <strong>ModelMBean</strong> implementation for the
34  * <code>org.apache.coyote.tomcat5.CoyoteConnector</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 ConnectorMBean extends ClassNameMBean {
41
42
43     // ----------------------------------------------------------- Constructors
44

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

55     public ConnectorMBean()
56         throws MBeanException JavaDoc, RuntimeOperationsException JavaDoc {
57
58         super();
59
60     }
61
62
63     // ------------------------------------------------------------- Attributes
64

65
66     /**
67      * Obtain and return the value of a specific attribute of this MBean.
68      *
69      * @param name Name of the requested attribute
70      *
71      * @exception AttributeNotFoundException if this attribute is not
72      * supported by this MBean
73      * @exception MBeanException if the initializer of an object
74      * throws an exception
75      * @exception ReflectionException if a Java reflection exception
76      * occurs when invoking the getter
77      */

78     public Object JavaDoc getAttribute(String JavaDoc name) throws AttributeNotFoundException JavaDoc,
79             MBeanException JavaDoc, ReflectionException JavaDoc {
80
81         Object JavaDoc attribute = null;
82         // Validate the input parameters
83
if (name == null)
84             throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc(
85                     "Attribute name is null"), "Attribute name is null");
86
87         Object JavaDoc result = null;
88         try {
89             Connector connector = (Connector) getManagedResource();
90             result = IntrospectionUtils.getProperty(connector, name);
91         } catch (InstanceNotFoundException JavaDoc e) {
92             throw new MBeanException JavaDoc(e);
93         } catch (InvalidTargetObjectTypeException JavaDoc e) {
94             throw new MBeanException JavaDoc(e);
95         }
96
97         return result;
98
99     }
100
101     
102     /**
103      * Set the value of a specific attribute of this MBean.
104      *
105      * @param attribute The identification of the attribute to be set
106      * and the new value
107      *
108      * @exception AttributeNotFoundException if this attribute is not
109      * supported by this MBean
110      * @exception MBeanException if the initializer of an object
111      * throws an exception
112      * @exception ReflectionException if a Java reflection exception
113      * occurs when invoking the getter
114      */

115      public void setAttribute(Attribute JavaDoc attribute)
116             throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc,
117             ReflectionException JavaDoc {
118
119         // Validate the input parameters
120
if (attribute == null)
121             throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc(
122                     "Attribute is null"), "Attribute is null");
123         String JavaDoc name = attribute.getName();
124         Object JavaDoc value = attribute.getValue();
125         if (name == null)
126             throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc(
127                     "Attribute name is null"), "Attribute name is null");
128
129         try {
130             Connector connector = (Connector) getManagedResource();
131             IntrospectionUtils.setProperty(connector, name, String.valueOf(value));
132         } catch (InstanceNotFoundException JavaDoc e) {
133             throw new MBeanException JavaDoc(e);
134         } catch (InvalidTargetObjectTypeException JavaDoc e) {
135             throw new MBeanException JavaDoc(e);
136         }
137   
138     }
139
140
141 }
142
Popular Tags