KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > server > interceptor > DefaultMBeanServerInterceptor


1 /*
2  * Copyright (C) MX4J.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package mx4j.server.interceptor;
10
11 import java.util.List JavaDoc;
12
13 import javax.management.Attribute JavaDoc;
14 import javax.management.AttributeList JavaDoc;
15 import javax.management.AttributeNotFoundException JavaDoc;
16 import javax.management.InvalidAttributeValueException JavaDoc;
17 import javax.management.ListenerNotFoundException JavaDoc;
18 import javax.management.MBeanException JavaDoc;
19 import javax.management.MBeanInfo JavaDoc;
20 import javax.management.MBeanRegistrationException JavaDoc;
21 import javax.management.NotificationFilter JavaDoc;
22 import javax.management.NotificationListener JavaDoc;
23 import javax.management.ReflectionException JavaDoc;
24
25 import mx4j.ImplementationException;
26 import mx4j.log.Log;
27 import mx4j.log.Logger;
28 import mx4j.server.MBeanMetaData;
29
30 /**
31  * Base class for MBeanServer --> MBean interceptors.
32  *
33  * @author <a HREF="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
34  * @version $Revision: 1.9 $
35  */

36 public abstract class DefaultMBeanServerInterceptor implements MBeanServerInterceptor, DefaultMBeanServerInterceptorMBean
37 {
38     private boolean enabled = true;
39     private String JavaDoc logCategory;
40     private List JavaDoc chain;
41
42     protected DefaultMBeanServerInterceptor()
43     {
44         // It's amazing how setting up here this string dramatically reduces the times to get the Logger instance
45
logCategory = getClass().getName() + "." + getType();
46     }
47
48     /**
49      * Returns whether this interceptor is enabled
50      * @see #setEnabled
51      */

52     public boolean isEnabled()
53     {
54         return enabled;
55     }
56
57     /**
58      * Enables or disables this interceptor
59      * @see #isEnabled
60      */

61     public void setEnabled(boolean enabled)
62     {
63         this.enabled = enabled;
64     }
65
66     /**
67      * Returns the type of this interceptor
68      */

69     public abstract String JavaDoc getType();
70
71     protected synchronized MBeanServerInterceptor getNext()
72     {
73         int index = chain.indexOf(this);
74         MBeanServerInterceptor next = (MBeanServerInterceptor)chain.get(index + 1);
75         next.setChain(chain);
76         return next;
77     }
78
79     public synchronized void setChain(List JavaDoc chain)
80     {
81         this.chain = chain;
82     }
83
84     protected Logger getLogger()
85     {
86         return Log.getLogger(logCategory);
87     }
88
89     public void addNotificationListener(MBeanMetaData metadata, NotificationListener JavaDoc listener, NotificationFilter JavaDoc filter, Object JavaDoc handback)
90     {
91         getNext().addNotificationListener(metadata, listener, filter, handback);
92     }
93
94    public void removeNotificationListener(MBeanMetaData metadata, NotificationListener JavaDoc listener) throws ListenerNotFoundException JavaDoc
95    {
96       getNext().removeNotificationListener(metadata, listener);
97    }
98
99     public void removeNotificationListener(MBeanMetaData metadata, NotificationListener JavaDoc listener, NotificationFilter JavaDoc filter, Object JavaDoc handback) throws ListenerNotFoundException JavaDoc
100     {
101         getNext().removeNotificationListener(metadata, listener, filter, handback);
102     }
103
104     public void instantiate(MBeanMetaData metadata, String JavaDoc className, String JavaDoc[] params, Object JavaDoc[] args) throws ReflectionException JavaDoc, MBeanException JavaDoc
105     {
106         getNext().instantiate(metadata, className, params, args);
107     }
108
109     public void registration(MBeanMetaData metadata, int operation) throws MBeanRegistrationException JavaDoc
110     {
111         getNext().registration(metadata, operation);
112     }
113
114     public MBeanInfo JavaDoc getMBeanInfo(MBeanMetaData metadata)
115     {
116         return getNext().getMBeanInfo(metadata);
117     }
118
119     public Object JavaDoc invoke(MBeanMetaData metadata, String JavaDoc method, String JavaDoc[] params, Object JavaDoc[] args) throws MBeanException JavaDoc, ReflectionException JavaDoc
120     {
121         return getNext().invoke(metadata, method, params, args);
122     }
123
124     public AttributeList JavaDoc getAttributes(MBeanMetaData metadata, String JavaDoc[] attributes)
125     {
126         return getNext().getAttributes(metadata, attributes);
127     }
128
129     public AttributeList JavaDoc setAttributes(MBeanMetaData metadata, AttributeList JavaDoc attributes)
130     {
131         return getNext().setAttributes(metadata, attributes);
132     }
133
134     public Object JavaDoc getAttribute(MBeanMetaData metadata, String JavaDoc attribute) throws MBeanException JavaDoc, AttributeNotFoundException JavaDoc, ReflectionException JavaDoc
135     {
136         return getNext().getAttribute(metadata, attribute);
137     }
138
139     public void setAttribute(MBeanMetaData metadata, Attribute JavaDoc attribute) throws MBeanException JavaDoc, AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc, ReflectionException JavaDoc
140     {
141         getNext().setAttribute(metadata, attribute);
142     }
143 }
144
Popular Tags