01: /*
02: * Copyright 2002,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.catalina.mbeans;
18:
19: import javax.management.Attribute;
20: import javax.management.AttributeNotFoundException;
21: import javax.management.InstanceNotFoundException;
22: import javax.management.MBeanException;
23: import javax.management.ReflectionException;
24: import javax.management.RuntimeOperationsException;
25: import javax.management.modelmbean.InvalidTargetObjectTypeException;
26:
27: import org.apache.catalina.deploy.ContextResourceLink;
28: import org.apache.catalina.deploy.NamingResources;
29: import org.apache.commons.modeler.BaseModelMBean;
30:
31: /**
32: * <p>A <strong>ModelMBean</strong> implementation for the
33: * <code>org.apache.catalina.deploy.ContextResourceLink</code> component.</p>
34: *
35: * @author Amy Roh
36: * @version $Revision: 1.3 $ $Date: 2004/02/27 14:58:44 $
37: */
38:
39: public class ContextResourceLinkMBean extends BaseModelMBean {
40:
41: // ----------------------------------------------------------- Constructors
42:
43: /**
44: * Construct a <code>ModelMBean</code> with default
45: * <code>ModelMBeanInfo</code> information.
46: *
47: * @exception MBeanException if the initializer of an object
48: * throws an exception
49: * @exception RuntimeOperationsException if an IllegalArgumentException
50: * occurs
51: */
52: public ContextResourceLinkMBean() throws MBeanException,
53: RuntimeOperationsException {
54:
55: super ();
56:
57: }
58:
59: // ----------------------------------------------------- Instance Variables
60:
61: // ------------------------------------------------------------- Attributes
62:
63: /**
64: * Set the value of a specific attribute of this MBean.
65: *
66: * @param attribute The identification of the attribute to be set
67: * and the new value
68: *
69: * @exception AttributeNotFoundException if this attribute is not
70: * supported by this MBean
71: * @exception MBeanException if the initializer of an object
72: * throws an exception
73: * @exception ReflectionException if a Java reflection exception
74: * occurs when invoking the getter
75: */
76: public void setAttribute(Attribute attribute)
77: throws AttributeNotFoundException, MBeanException,
78: ReflectionException {
79:
80: super .setAttribute(attribute);
81:
82: ContextResourceLink crl = null;
83: try {
84: crl = (ContextResourceLink) getManagedResource();
85: } catch (InstanceNotFoundException e) {
86: throw new MBeanException(e);
87: } catch (InvalidTargetObjectTypeException e) {
88: throw new MBeanException(e);
89: }
90:
91: // cannot use side-efects. It's removed and added back each time
92: // there is a modification in a resource.
93: NamingResources nr = crl.getNamingResources();
94: nr.removeResourceLink(crl.getName());
95: nr.addResourceLink(crl);
96: }
97:
98: }
|