01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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;
21: import javax.management.AttributeNotFoundException;
22: import javax.management.InstanceNotFoundException;
23: import javax.management.MBeanException;
24: import javax.management.ReflectionException;
25: import javax.management.RuntimeOperationsException;
26: import javax.management.modelmbean.InvalidTargetObjectTypeException;
27:
28: import org.apache.catalina.deploy.ContextEnvironment;
29: import org.apache.catalina.deploy.NamingResources;
30: import org.apache.tomcat.util.modeler.BaseModelMBean;
31:
32: /**
33: * <p>A <strong>ModelMBean</strong> implementation for the
34: * <code>org.apache.catalina.deploy.ContextEnvironment</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 ContextEnvironmentMBean extends BaseModelMBean {
41:
42: // ----------------------------------------------------------- Constructors
43:
44: /**
45: * Construct a <code>ModelMBean</code> with default
46: * <code>ModelMBeanInfo</code> information.
47: *
48: * @exception MBeanException if the initializer of an object
49: * throws an exception
50: * @exception RuntimeOperationsException if an IllegalArgumentException
51: * occurs
52: */
53: public ContextEnvironmentMBean() throws MBeanException,
54: RuntimeOperationsException {
55:
56: super ();
57:
58: }
59:
60: // ----------------------------------------------------- Instance Variables
61:
62: // ------------------------------------------------------------- Attributes
63:
64: /**
65: * Set the value of a specific attribute of this MBean.
66: *
67: * @param attribute The identification of the attribute to be set
68: * and the new value
69: *
70: * @exception AttributeNotFoundException if this attribute is not
71: * supported by this MBean
72: * @exception MBeanException if the initializer of an object
73: * throws an exception
74: * @exception ReflectionException if a Java reflection exception
75: * occurs when invoking the getter
76: */
77: public void setAttribute(Attribute attribute)
78: throws AttributeNotFoundException, MBeanException,
79: ReflectionException {
80:
81: super .setAttribute(attribute);
82:
83: ContextEnvironment ce = null;
84: try {
85: ce = (ContextEnvironment) getManagedResource();
86: } catch (InstanceNotFoundException e) {
87: throw new MBeanException(e);
88: } catch (InvalidTargetObjectTypeException e) {
89: throw new MBeanException(e);
90: }
91:
92: // cannot use side-efects. It's removed and added back each time
93: // there is a modification in a resource.
94: NamingResources nr = ce.getNamingResources();
95: nr.removeEnvironment(ce.getName());
96: nr.addEnvironment(ce);
97: }
98:
99: }
|