KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > jmx > ChainedMBeanServerBuilder


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Marc Wick.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.controller.jmx;
26
27 import javax.management.MBeanServer JavaDoc;
28 import javax.management.MBeanServerBuilder JavaDoc;
29 import javax.management.MBeanServerDelegate JavaDoc;
30
31 /**
32  * Base class for chained MBeanServerBuilders. <br>
33  * By default this class delegates all method calls to the nested
34  * MBeanServerBuilder. <br>
35  * See the MX4J documentation on how to use correctly this class. <br>
36  * <br>
37  * Example implementation:
38  *
39  * <pre>
40  *
41  *
42  *
43  * public class LoggingBuilder extends ChainedMBeanServerBuilder
44  * {
45  * public LoggingBuilder()
46  * {
47  * super(new MBeanServerBuilder());
48  * }
49  *
50  * public MBeanServer newMBeanServer(String defaultDomain, MBeanServer outer, MBeanServerDelegate delegate)
51  * {
52  * LoggingMBeanServer external = new LoggingMBeanServer();
53  * MBeanServer nested = getBuilder().newMBeanServer(defaultDomain, outer == null ? external : outer, delegate);
54  * external.setMBeanServer(nested);
55  * return external;
56  * }
57  * }
58  *
59  * public class LoggingMBeanServer extends ChainedMBeanServer
60  * {
61  * protected void setMBeanServer(MBeanServer server)
62  * {
63  * super.setMBeanServer(server);
64  * }
65  *
66  * public Object getAttribute(ObjectName objectName, String attribute)
67  * throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException
68  * {
69  * Object value = super.getAttribute(objectName, attribute);
70  * System.out.println(&quot;Value is: &quot; + value);
71  * return value;
72  * }
73  *
74  * ...
75  * }
76  *
77  *
78  *
79  * </pre>
80  *
81  * @author <a HREF="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
82  * @version 1.0
83  */

84 public class ChainedMBeanServerBuilder extends javax.management.MBeanServerBuilder JavaDoc
85 {
86   private final MBeanServerBuilder builder;
87
88   /**
89    * Creates a new chained MBeanServerBuilder
90    *
91    * @param builder The MBeanServerBuilder this object delegates to.
92    */

93   public ChainedMBeanServerBuilder(MBeanServerBuilder builder)
94   {
95     if (builder == null)
96       throw new IllegalArgumentException JavaDoc();
97     this.builder = builder;
98   }
99
100   /**
101    * Forwards the call to the chained builder.
102    *
103    * @see MBeanServerBuilder#newMBeanServerDelegate
104    */

105   public MBeanServerDelegate JavaDoc newMBeanServerDelegate()
106   {
107     return getMBeanServerBuilder().newMBeanServerDelegate();
108   }
109
110   /**
111    * Forwards the call to the chained builder.
112    *
113    * @see MBeanServerBuilder#newMBeanServer(java.lang.String,
114    * javax.management.MBeanServer, javax.management.MBeanServerDelegate)
115    */

116   public MBeanServer JavaDoc newMBeanServer(String JavaDoc defaultDomain, MBeanServer JavaDoc outer,
117       MBeanServerDelegate JavaDoc delegate)
118   {
119     return getMBeanServerBuilder().newMBeanServer(defaultDomain, outer,
120         delegate);
121   }
122
123   /**
124    * Returns the chained MBeanServerBuilder this object delegates to.
125    */

126   protected MBeanServerBuilder getMBeanServerBuilder()
127   {
128     return builder;
129   }
130
131 }
132
Popular Tags