KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > modelmbean > RequiredModelMBeanInvoker


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mx.modelmbean;
23
24 import javax.management.Attribute JavaDoc;
25 import javax.management.AttributeList JavaDoc;
26 import javax.management.AttributeNotFoundException JavaDoc;
27 import javax.management.DynamicMBean JavaDoc;
28 import javax.management.InvalidAttributeValueException JavaDoc;
29 import javax.management.MBeanException JavaDoc;
30 import javax.management.ReflectionException JavaDoc;
31 import javax.management.RuntimeMBeanException JavaDoc;
32 import javax.management.RuntimeOperationsException JavaDoc;
33 import javax.management.ServiceNotFoundException JavaDoc;
34 import javax.management.modelmbean.RequiredModelMBean JavaDoc;
35
36 import org.jboss.mx.server.RawDynamicInvoker;
37
38 /** An invoker that handles the 'ops' that are part of the RequiredModelMBean
39  * that must be handled at that level rather than its delegate.
40  *
41  * @author Scott.Stark@jboss.org
42  * @version $Revison:$
43  */

44 public class RequiredModelMBeanInvoker extends RawDynamicInvoker
45 {
46    RequiredModelMBean JavaDoc mbean;
47
48    public RequiredModelMBeanInvoker(DynamicMBean JavaDoc resource)
49    {
50       super(resource);
51       mbean = (RequiredModelMBean JavaDoc) resource;
52    }
53
54    public Object JavaDoc getAttribute(String JavaDoc name) throws AttributeNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
55    {
56       try
57       {
58          return super.getAttribute(name);
59       }
60       catch (ReflectionException JavaDoc e)
61       {
62          // Another inconsistency
63
Exception JavaDoc ex = e.getTargetException();
64          if ((ex instanceof ClassNotFoundException JavaDoc) == false &&
65              (ex instanceof NoSuchMethodException JavaDoc) == false)
66          {
67             log.debug("Rewrapping reflection exception: ", e);
68             throw new MBeanException JavaDoc(new ServiceNotFoundException JavaDoc(ex.getMessage()), e.getMessage());
69          }
70          else
71             throw e;
72       }
73    }
74
75    public void setAttribute(Attribute JavaDoc attribute)
76       throws AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
77    {
78       // Another inconsistency
79
if (attribute == null)
80          throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc("Null attribute"));
81       try
82       {
83          super.setAttribute(attribute);
84       }
85       catch (ReflectionException JavaDoc e)
86       {
87          // Another inconsistency
88
Exception JavaDoc ex = e.getTargetException();
89          if ((ex instanceof ClassNotFoundException JavaDoc) == false &&
90              (ex instanceof NoSuchMethodException JavaDoc) == false)
91          {
92             log.debug("Rewrapping reflection exception: ", e);
93             throw new MBeanException JavaDoc(new ServiceNotFoundException JavaDoc(ex.getMessage()), e.getMessage());
94          }
95          else
96             throw e;
97       }
98    }
99
100    public AttributeList JavaDoc getAttributes(String JavaDoc[] attributes)
101    {
102       if (attributes == null)
103          throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc("Null attributes"));
104       return super.getAttributes(attributes);
105    }
106
107    public AttributeList JavaDoc setAttributes(AttributeList JavaDoc attributes)
108    {
109       if (attributes == null)
110          throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc("Null attributes"));
111       return super.setAttributes(attributes);
112    }
113
114    public Object JavaDoc invoke(String JavaDoc name, Object JavaDoc[] args, String JavaDoc[] signature) throws
115       MBeanException JavaDoc, ReflectionException JavaDoc
116    {
117       Object JavaDoc value;
118
119       if (name == null)
120          throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc("Null operation"));
121       else if( name.equals("getNotificationInfo") )
122          value = mbean.getNotificationInfo();
123       else
124       {
125          try
126          {
127             value = super.invoke(name, args, signature);
128          }
129          catch (RuntimeMBeanException JavaDoc e)
130          {
131             // For some reason (not mentioned in the spec) these have to
132
// be wrapped in MBeanExceptions for RMM
133
throw new MBeanException JavaDoc(e.getTargetException(), e.getMessage());
134          }
135          catch (ReflectionException JavaDoc e)
136          {
137             // Another inconsistency
138
Exception JavaDoc ex = e.getTargetException();
139             if ((ex instanceof ClassNotFoundException JavaDoc) == false &&
140                 (ex instanceof NoSuchMethodException JavaDoc) == false)
141             {
142                log.debug("Rewrapping reflection exception: ", e);
143                throw new MBeanException JavaDoc(new ServiceNotFoundException JavaDoc(ex.getMessage()), e.getMessage());
144             }
145             else
146                throw e;
147          }
148       }
149       return value;
150    }
151 }
152
Popular Tags