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 package org.apache.catalina.mbeans;
18
19 import javax.management.Attribute;
20 import javax.management.AttributeNotFoundException;
21 import javax.management.MBeanException;
22 import javax.management.ReflectionException;
23 import javax.management.RuntimeOperationsException;
24
25 import org.apache.catalina.connector.Connector;
26 import org.apache.tomcat.util.IntrospectionUtils;
27 import org.apache.tomcat.util.res.StringManager;
28
29 /**
30  * <p>A <strong>ModelMBean</strong> implementation for the
31  * <code>org.apache.coyote.tomcat5.CoyoteConnector</code> component.</p>
32  *
33  * @author Amy Roh
34  */

35 public class ConnectorMBean extends ClassNameMBean<Connector> {
36
37     private static final StringManager sm = StringManager.getManager(ConnectorMBean.class);
38
39     /**
40      * Obtain and return the value of a specific attribute of this MBean.
41      *
42      * @param name Name of the requested attribute
43      *
44      * @exception AttributeNotFoundException if this attribute is not
45      *  supported by this MBean
46      * @exception MBeanException if the initializer of an object
47      *  throws an exception
48      * @exception ReflectionException if a Java reflection exception
49      *  occurs when invoking the getter
50      */

51     @Override
52     public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException,
53             ReflectionException {
54
55         // Validate the input parameters
56         if (name == null) {
57             throw new RuntimeOperationsException(
58                     new IllegalArgumentException(sm.getString("mBean.nullName")),
59                     sm.getString("mBean.nullName"));
60         }
61
62         Connector connector = doGetManagedResource();
63         return IntrospectionUtils.getProperty(connector, name);
64     }
65
66
67     /**
68      * Set the value of a specific attribute of this MBean.
69      *
70      * @param attribute The identification of the attribute to be set
71      *  and the new value
72      *
73      * @exception AttributeNotFoundException if this attribute is not
74      *  supported by this MBean
75      * @exception MBeanException if the initializer of an object
76      *  throws an exception
77      * @exception ReflectionException if a Java reflection exception
78      *  occurs when invoking the getter
79      */

80      @Override
81     public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException,
82             ReflectionException {
83
84         // Validate the input parameters
85         if (attribute == null) {
86             throw new RuntimeOperationsException(new IllegalArgumentException(
87                     sm.getString("mBean.nullAttribute")), sm.getString("mBean.nullAttribute"));
88         }
89         String name = attribute.getName();
90         Object value = attribute.getValue();
91         if (name == null) {
92             throw new RuntimeOperationsException(
93                     new IllegalArgumentException(sm.getString("mBean.nullName")),
94                     sm.getString("mBean.nullName"));
95         }
96
97         Connector connector = doGetManagedResource();
98         IntrospectionUtils.setProperty(connector, name, String.valueOf(value));
99     }
100 }
101