KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 import javax.management.Attribute JavaDoc;
22 import javax.management.AttributeNotFoundException JavaDoc;
23 import javax.management.InstanceNotFoundException JavaDoc;
24 import javax.management.MBeanException JavaDoc;
25 import javax.management.ReflectionException JavaDoc;
26 import javax.management.RuntimeOperationsException JavaDoc;
27 import javax.management.modelmbean.InvalidTargetObjectTypeException JavaDoc;
28
29 import org.apache.catalina.deploy.ContextEnvironment;
30 import org.apache.catalina.deploy.NamingResources;
31 import org.apache.tomcat.util.modeler.BaseModelMBean;
32
33
34 /**
35  * <p>A <strong>ModelMBean</strong> implementation for the
36  * <code>org.apache.catalina.deploy.ContextEnvironment</code> component.</p>
37  *
38  * @author Amy Roh
39  * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
40  */

41
42 public class ContextEnvironmentMBean extends BaseModelMBean {
43
44
45     // ----------------------------------------------------------- Constructors
46

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

57     public ContextEnvironmentMBean()
58         throws MBeanException JavaDoc, RuntimeOperationsException JavaDoc {
59
60         super();
61
62     }
63
64
65     // ----------------------------------------------------- Instance Variables
66

67
68     // ------------------------------------------------------------- Attributes
69

70     
71     /**
72      * Set the value of a specific attribute of this MBean.
73      *
74      * @param attribute The identification of the attribute to be set
75      * and the new value
76      *
77      * @exception AttributeNotFoundException if this attribute is not
78      * supported by this MBean
79      * @exception MBeanException if the initializer of an object
80      * throws an exception
81      * @exception ReflectionException if a Java reflection exception
82      * occurs when invoking the getter
83      */

84      public void setAttribute(Attribute JavaDoc attribute)
85         throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc,
86         ReflectionException JavaDoc {
87
88         super.setAttribute(attribute);
89         
90         ContextEnvironment ce = null;
91         try {
92             ce = (ContextEnvironment) getManagedResource();
93         } catch (InstanceNotFoundException JavaDoc e) {
94             throw new MBeanException JavaDoc(e);
95         } catch (InvalidTargetObjectTypeException JavaDoc e) {
96              throw new MBeanException JavaDoc(e);
97         }
98         
99         // cannot use side-efects. It's removed and added back each time
100
// there is a modification in a resource.
101
NamingResources nr = ce.getNamingResources();
102         nr.removeEnvironment(ce.getName());
103         nr.addEnvironment(ce);
104     }
105     
106 }
107
Popular Tags