KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > server > MBeanServerImpl


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.server;
23
24 import java.io.ByteArrayInputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.ObjectInputStream JavaDoc;
27 import java.lang.reflect.Constructor JavaDoc;
28 import java.lang.reflect.InvocationTargetException JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.HashSet JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.Set JavaDoc;
36 import java.security.ProtectionDomain JavaDoc;
37 import java.security.AccessController JavaDoc;
38 import java.security.PrivilegedAction JavaDoc;
39 import java.security.PrivilegedExceptionAction JavaDoc;
40 import java.security.PrivilegedActionException JavaDoc;
41
42 import javax.management.Attribute JavaDoc;
43 import javax.management.AttributeList JavaDoc;
44 import javax.management.AttributeNotFoundException JavaDoc;
45 import javax.management.InstanceAlreadyExistsException JavaDoc;
46 import javax.management.InstanceNotFoundException JavaDoc;
47 import javax.management.IntrospectionException JavaDoc;
48 import javax.management.InvalidAttributeValueException JavaDoc;
49 import javax.management.JMException JavaDoc;
50 import javax.management.ListenerNotFoundException JavaDoc;
51 import javax.management.MBeanException JavaDoc;
52 import javax.management.MBeanInfo JavaDoc;
53 import javax.management.MBeanParameterInfo JavaDoc;
54 import javax.management.MBeanRegistrationException JavaDoc;
55 import javax.management.MBeanServer JavaDoc;
56 import javax.management.MBeanServerDelegate JavaDoc;
57 import javax.management.NotCompliantMBeanException JavaDoc;
58 import javax.management.NotificationBroadcaster JavaDoc;
59 import javax.management.NotificationFilter JavaDoc;
60 import javax.management.NotificationListener JavaDoc;
61 import javax.management.ObjectInstance JavaDoc;
62 import javax.management.ObjectName JavaDoc;
63 import javax.management.OperationsException JavaDoc;
64 import javax.management.QueryExp JavaDoc;
65 import javax.management.ReflectionException JavaDoc;
66 import javax.management.RuntimeErrorException JavaDoc;
67 import javax.management.RuntimeMBeanException JavaDoc;
68 import javax.management.RuntimeOperationsException JavaDoc;
69 import javax.management.JMRuntimeException JavaDoc;
70 import javax.management.MBeanPermission JavaDoc;
71 import javax.management.MalformedObjectNameException JavaDoc;
72 import javax.management.MBeanTrustPermission JavaDoc;
73 import javax.management.loading.ClassLoaderRepository JavaDoc;
74 import javax.management.modelmbean.DescriptorSupport JavaDoc;
75 import javax.management.modelmbean.ModelMBean JavaDoc;
76 import javax.management.modelmbean.ModelMBeanAttributeInfo JavaDoc;
77 import javax.management.modelmbean.ModelMBeanConstructorInfo JavaDoc;
78 import javax.management.modelmbean.ModelMBeanInfo JavaDoc;
79 import javax.management.modelmbean.ModelMBeanInfoSupport JavaDoc;
80 import javax.management.modelmbean.ModelMBeanNotificationInfo JavaDoc;
81 import javax.management.modelmbean.ModelMBeanOperationInfo JavaDoc;
82
83 import org.jboss.logging.Logger;
84 import org.jboss.mx.loading.LoaderRepository;
85 import org.jboss.mx.modelmbean.ModelMBeanConstants;
86 import org.jboss.mx.modelmbean.RequiredModelMBeanInstantiator;
87 import org.jboss.mx.notification.MBeanServerListenerRegistry;
88 import org.jboss.mx.server.registry.MBeanEntry;
89 import org.jboss.mx.server.registry.MBeanRegistry;
90 import org.jboss.mx.service.ServiceConstants;
91 import org.jboss.mx.util.JMXExceptionDecoder;
92 import org.jboss.mx.util.PropertyAccess;
93 import org.jboss.util.NestedRuntimeException;
94
95 /**
96  * MBean server implementation.
97  *
98  * The MBean server behaviour can be configured by setting the following
99  * system properties: <ul>
100  * <li><tt>jbossmx.loader.repository.class</tt>
101  ({@link ServerConstants#LOADER_REPOSITORY_CLASS_PROPERTY LOADER_REPOSITORY_CLASS_PROPERTY})</li>
102  * <li><tt>jbossmx.mbean.registry.class</tt>
103  ({@link ServerConstants#MBEAN_REGISTRY_CLASS_PROPERTY MBEAN_REGISTRY_CLASS_PROPERTY})</li>
104  * <li><tt>jbossmx.required.modelmbean.class</tt>
105  ({@link ServerConstants#REQUIRED_MODELMBEAN_CLASS_PROPERTY REQUIRED_MODELMBEAN_CLASS_PROPERTY})</li>
106  * </ul>
107  *
108  * The loader repository is used for managing class loaders in the MBean server.
109  * The default repository uses the <tt>UnifiedLoaderRepository</tt> implementation
110  * ({@link ServerConstants#DEFAULT_LOADER_REPOSITORY_CLASS DEFAULT_LOADER_REPOSITORY_CLASS}).<p>
111  *
112  * The default registry is
113  * ({@link ServerConstants#DEFAULT_MBEAN_REGISTRY_CLASS DEFAULT_MBEAN_REGISTRY_CLASS}).<p>
114  *
115  * The <tt>RequiredModelMBean</tt> uses <tt>XMBean</tt> implementation by default
116  * ({@link ServerConstants#DEFAULT_REQUIRED_MODELMBEAN_CLASS DEFAULT_REQUIRED_MODELMBEAN_CLASS}).
117  *
118  * @see javax.management.MBeanServer
119  * @see javax.management.modelmbean.RequiredModelMBean
120  * @see org.jboss.mx.server.ServerConstants
121  * @see org.jboss.mx.loading.LoaderRepository
122  * @see org.jboss.mx.loading.UnifiedLoaderRepository3
123  * @see org.jboss.mx.modelmbean.XMBean
124  *
125  * @author <a HREF="mailto:juha@jboss.org">Juha Lindfors</a>.
126  * @author <a HREF="mailto:trevor@protocool.com">Trevor Squires</a>.
127  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
128  * @author <a HREF="mailto:thomas.diesler@jboss.com">Thomas Diesler</a>.
129  * @author Scott.Stark@jboss.org
130  * @version $Revision: 57108 $
131  */

132 public class MBeanServerImpl
133    implements MBeanServer JavaDoc, ServerConstants, ServiceConstants, ModelMBeanConstants
134 {
135    // Constants ------------------------------------------------------
136

137    /**
138     * No parameters array
139     */

140    private static final Object JavaDoc[] NOPARAMS = new Object JavaDoc[0];
141
142    /**
143     * No signature array
144     */

145    private static final String JavaDoc[] NOSIG = new String JavaDoc[0];
146
147    // Attributes ----------------------------------------------------
148

149    /**
150     * The wrapping MBeanServer
151     */

152    protected MBeanServer JavaDoc outer = null;
153
154    /**
155     * Registry used by this server to map MBean object names to resource references.
156     */

157    protected MBeanRegistry registry = null;
158
159    /**
160     * The notification registrations
161     */

162    private MBeanServerListenerRegistry listeners = new MBeanServerListenerRegistry();
163
164    /**
165     * This server's class loader repository
166     */

167    private ClassLoaderRepository JavaDoc classLoaderRepository;
168
169    // Static --------------------------------------------------------
170

171    /**
172     * The logger
173     */

174    private static Logger log = Logger.getLogger(MBeanServerImpl.class);
175
176    
177    // Constructors --------------------------------------------------
178

179    /**
180     * Creates an MBean server implementation with a given default domain name and
181     * registers the mandatory server delegate MBean to the server
182     * ({@link ServerConstants#MBEAN_SERVER_DELEGATE MBEAN_SERVER_DELEGATE}).
183     *
184     * @param defaultDomain default domain name
185     * @param outer the wrapping MBeanServer, passed to MBeans
186     * at registration.
187     * @param delegate the delegate to use
188     * for Notifications.
189     */

190    public MBeanServerImpl(String JavaDoc defaultDomain, MBeanServer JavaDoc outer, MBeanServerDelegate JavaDoc delegate)
191    {
192       // Determine the MBeanServer to pass to MBeans
193
if (outer == null)
194          this.outer = this;
195       else
196          this.outer = outer;
197
198       // the very first thing to do is to create a class loader repository
199
this.classLoaderRepository = getClassLoaderRepository();
200
201       // the second first thing to do is to create a registry instance
202
this.registry = createRegistry(defaultDomain);
203       
204       // The first MBean to be registered should be the server delegate
205
// to guarantee correct functionality (other MBeans may be dependent
206
// on the existence of the delegate).
207
try
208       {
209          // the magic token that allows us to register to the
210
// protected JMImplementation domain
211
HashMap JavaDoc valueMap = new HashMap JavaDoc();
212          valueMap.put(JMI_DOMAIN, JMI_DOMAIN);
213
214          // register the delegate
215
registry.registerMBean(delegate,
216                  new ObjectName JavaDoc(MBEAN_SERVER_DELEGATE),
217                  valueMap);
218          
219          // We expose the registry as an MBean for other components
220
ModelMBean JavaDoc rmm = RequiredModelMBeanInstantiator.instantiate();
221          rmm.setModelMBeanInfo(getRegistryManagementInterface());
222          rmm.setManagedResource(registry, "ObjectReference");
223
224          // register the registry MBean
225
registry.registerMBean(rmm, new ObjectName JavaDoc(MBEAN_REGISTRY), valueMap);
226          
227          // register the loader repository
228
//String loaderClassMBeanName = classLoaderRepository.getClass().getName() + "MBean";
229
//ClassLoader cl = classLoaderRepository.getClass().getClassLoader();
230
//Class mbean = cl.loadClass(loaderClassMBeanName);
231

232          //there must be a class with the MBean extension.
233
ObjectName JavaDoc loaderName = new ObjectName JavaDoc(DEFAULT_LOADER_NAME);
234          registry.registerMBean(classLoaderRepository, loaderName, valueMap);
235
236       }
237       catch (Exception JavaDoc e)
238       {
239          throw new RuntimeException JavaDoc("Cannot create MBeanServer", e);
240       }
241    }
242
243    // MBeanServer implementation ------------------------------------
244

245    public Object JavaDoc instantiate(String JavaDoc className)
246            throws ReflectionException JavaDoc, MBeanException JavaDoc
247    {
248       return instantiate(className, (ClassLoader JavaDoc) null, NOPARAMS, NOSIG);
249    }
250
251    public Object JavaDoc instantiate(String JavaDoc className, Object JavaDoc[] params, String JavaDoc[] signature)
252            throws ReflectionException JavaDoc, MBeanException JavaDoc
253    {
254       return instantiate(className, (ClassLoader JavaDoc) null, params, signature);
255    }
256
257    public Object JavaDoc instantiate(String JavaDoc className, ObjectName JavaDoc loaderName)
258            throws ReflectionException JavaDoc, MBeanException JavaDoc, InstanceNotFoundException JavaDoc
259    {
260       return instantiate(className, loaderName, NOPARAMS, NOSIG);
261    }
262
263    public Object JavaDoc instantiate(String JavaDoc className, ObjectName JavaDoc loaderName, Object JavaDoc[] params, String JavaDoc[] signature)
264            throws ReflectionException JavaDoc, MBeanException JavaDoc, InstanceNotFoundException JavaDoc
265    {
266       ClassLoader JavaDoc cl = null;
267
268       // if instantiate() is called with null loader name, we use the cl that
269
// loaded the MBean server (see javadoc)
270

271       try
272       {
273          if (loaderName != null)
274             cl = (ClassLoader JavaDoc) registry.get(loaderName).getResourceInstance();
275       }
276       catch (ClassCastException JavaDoc e)
277       {
278          throw new ReflectionException JavaDoc(e, loaderName + " is not a class loader.");
279       }
280
281       if (cl == null)
282          cl = this.getClass().getClassLoader();
283       if (cl == null)
284          cl = ClassLoader.getSystemClassLoader();
285
286       return instantiate(className, cl, params, signature);
287    }
288
289    public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc name)
290            throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc, MBeanException JavaDoc, NotCompliantMBeanException JavaDoc
291    {
292       try
293       {
294          Object JavaDoc mbean = instantiate(className);
295          return registerMBean(mbean, name, (ClassLoader JavaDoc) null);
296       }
297       catch (SecurityException JavaDoc e)
298       {
299          throw e;
300       }
301       catch (ReflectionException JavaDoc refex)
302       {
303          // Note, the CTS wants a NotCompliantMBeanException for this case
304
if (refex.getCause() instanceof InstantiationException JavaDoc)
305             throw new NotCompliantMBeanException JavaDoc("Cannot instanciate MBean: " + className);
306          else
307             throw refex;
308       }
309    }
310
311    public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc name, Object JavaDoc[] params, String JavaDoc[] signature)
312            throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc, MBeanException JavaDoc, NotCompliantMBeanException JavaDoc
313    {
314       try
315       {
316          Object JavaDoc mbean = instantiate(className, params, signature);
317          return registerMBean(mbean, name, (ClassLoader JavaDoc) null);
318       }
319       catch (ReflectionException JavaDoc refex)
320       {
321          return handleExceptionOnCreate(refex, className);
322       }
323    }
324
325    public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc name, ObjectName JavaDoc loaderName)
326            throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc, MBeanException JavaDoc, NotCompliantMBeanException JavaDoc, InstanceNotFoundException JavaDoc
327    {
328       try
329       {
330          Object JavaDoc mbean = instantiate(className, loaderName);
331          return registerMBean(mbean, name, loaderName);
332       }
333       catch (ReflectionException JavaDoc refex)
334       {
335          return handleExceptionOnCreate(refex, className);
336       }
337    }
338
339    public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc name, ObjectName JavaDoc loaderName, Object JavaDoc[] params, String JavaDoc[] signature)
340            throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc, MBeanException JavaDoc, NotCompliantMBeanException JavaDoc, InstanceNotFoundException JavaDoc
341    {
342       try
343       {
344          Object JavaDoc mbean = instantiate(className, loaderName, params, signature);
345          return registerMBean(mbean, name, loaderName);
346       }
347       catch (ReflectionException JavaDoc refex)
348       {
349          return handleExceptionOnCreate(refex, className);
350       }
351    }
352
353    /**
354     * The CTS wants a NotCompliantMBeanException in case the MBean cannot be created.
355     * We need this, because instanciate cannot throw NotCompliantMBeanException.
356     */

357    private ObjectInstance JavaDoc handleExceptionOnCreate(ReflectionException JavaDoc refex, String JavaDoc className)
358            throws NotCompliantMBeanException JavaDoc, ReflectionException JavaDoc
359    {
360       if (refex.getCause() instanceof InstantiationException JavaDoc)
361          throw new NotCompliantMBeanException JavaDoc("Cannot instanciate MBean: " + className);
362
363       throw refex;
364    }
365
366    /**
367     * Registers a pre-existing object as an MBean with the MBean server. If the object name given is null,
368     * the MBean must provide its own name by implementing the MBeanRegistration interface and returning the name
369     * from the preRegister method.
370     */

371    public ObjectInstance JavaDoc registerMBean(Object JavaDoc object, ObjectName JavaDoc name)
372            throws InstanceAlreadyExistsException JavaDoc,
373            MBeanRegistrationException JavaDoc,
374            NotCompliantMBeanException JavaDoc
375    {
376       return registerMBean(object, name, (ClassLoader JavaDoc) null);
377    }
378
379    public void unregisterMBean(ObjectName JavaDoc name)
380            throws InstanceNotFoundException JavaDoc, MBeanRegistrationException JavaDoc
381    {
382       // Get the mbean to remove
383
MBeanEntry entry = registry.get(name);
384       Object JavaDoc mbean = entry.getResourceInstance();
385       name = entry.getObjectName();
386
387       checkMBeanPermission(entry.getResourceClassName(), null, name, "unregisterMBean");
388
389       try
390       {
391          final Object JavaDoc[] args = {name};
392          final String JavaDoc[] sig = {ObjectName JavaDoc.class.getName()};
393          try
394          {
395             AccessController.doPrivileged(
396                new PrivilegedExceptionAction JavaDoc()
397                {
398                   public Object JavaDoc run() throws Exception JavaDoc
399                   {
400                      return invoke(new ObjectName JavaDoc(MBEAN_REGISTRY),
401                         "unregisterMBean", args, sig);
402                   }
403                }
404             );
405          }
406          catch(PrivilegedActionException JavaDoc e)
407          {
408             throw e.getException();
409          }
410       }
411       catch (Throwable JavaDoc t)
412       {
413          Throwable JavaDoc result = JMXExceptionDecoder.decodeToJMXException(t);
414          if (result instanceof InstanceNotFoundException JavaDoc)
415             throw (InstanceNotFoundException JavaDoc) result;
416          if (result instanceof MBeanRegistrationException JavaDoc)
417             throw (MBeanRegistrationException JavaDoc) result;
418          if ( result instanceof JMRuntimeException JavaDoc )
419             throw (JMRuntimeException JavaDoc) result;
420          if (result instanceof MBeanException JavaDoc)
421          {
422             MBeanException JavaDoc e = (MBeanException JavaDoc) result;
423             t = e.getTargetException();
424             if (t instanceof InstanceNotFoundException JavaDoc)
425                throw (InstanceNotFoundException JavaDoc) t;
426             if (t instanceof MBeanRegistrationException JavaDoc)
427                throw (MBeanRegistrationException JavaDoc) t;
428          }
429          if (result instanceof RuntimeException JavaDoc)
430             throw new RuntimeMBeanException JavaDoc((RuntimeException JavaDoc) result);
431          if (result instanceof Error JavaDoc)
432             throw new RuntimeErrorException JavaDoc((Error JavaDoc) result);
433
434          // for some other reason, unregistration failed
435
throw new MBeanRegistrationException JavaDoc(new InvocationTargetException JavaDoc(t), "Cannot unregister MBean");
436       }
437       
438       // Unregistration worked, remove any proxies for a broadcaster
439
if (mbean instanceof NotificationBroadcaster JavaDoc)
440          listeners.remove(name);
441    }
442
443    public ObjectInstance JavaDoc getObjectInstance(ObjectName JavaDoc name)
444            throws InstanceNotFoundException JavaDoc
445    {
446       ObjectInstance JavaDoc oi = registry.getObjectInstance(name);
447       checkMBeanPermission(oi.getClassName(), null, name,
448          "getObjectInstance");
449
450       return oi;
451    }
452
453    public Set JavaDoc queryMBeans(ObjectName JavaDoc name, QueryExp JavaDoc query)
454    {
455       // At least one mbean must be queriable
456
checkMBeanPermission(null, null, null, "queryMBeans");
457
458       // Set up the query
459
Set JavaDoc result = new HashSet JavaDoc();
460       if (query != null)
461          query.setMBeanServer(outer);
462
463       SecurityManager JavaDoc sm = System.getSecurityManager();
464       // Get the possible MBeans
465
List JavaDoc entries = registry.findEntries(name);
466       Iterator JavaDoc iterator = entries.iterator();
467       while (iterator.hasNext())
468       {
469          // Check each MBean against the query
470
MBeanEntry entry = (MBeanEntry) iterator.next();
471          ObjectName JavaDoc objectName = entry.getObjectName();
472          // The permission check must be done before the query is applied
473
if( sm != null )
474          {
475             try
476             {
477                checkMBeanPermission(entry.getResourceClassName(), null,
478                   objectName, "queryMBeans");
479             }
480             catch(SecurityException JavaDoc e)
481             {
482                if( log.isTraceEnabled() )
483                   log.trace("Excluded mbean due to security: "+objectName);
484                continue;
485             }
486          }
487          // Check the mbean against the query
488
if (queryMBean(objectName, query) == true)
489          {
490             try
491             {
492                ObjectInstance JavaDoc instance = registry.getObjectInstance(objectName);
493                result.add(instance);
494             }
495             catch (InstanceNotFoundException JavaDoc ignored)
496             {
497             }
498          }
499       }
500
501       return result;
502    }
503
504    public Set JavaDoc queryNames(ObjectName JavaDoc name, QueryExp JavaDoc query)
505    {
506       // At least one mbean must be queriable
507
checkMBeanPermission(null, null, null, "queryNames");
508
509       // Set up the query
510
Set JavaDoc result = new HashSet JavaDoc();
511       if (query != null)
512          query.setMBeanServer(outer);
513
514       SecurityManager JavaDoc sm = System.getSecurityManager();
515       // Get the possible MBeans
516
List JavaDoc entries = registry.findEntries(name);
517       Iterator JavaDoc iterator = entries.iterator();
518       while (iterator.hasNext())
519       {
520          // Check each MBean against the query
521
MBeanEntry entry = (MBeanEntry) iterator.next();
522          ObjectName JavaDoc objectName = entry.getObjectName();
523          // The permission check must be done before the query is applied
524
if( sm != null )
525          {
526             try
527             {
528                checkMBeanPermission(entry.getResourceClassName(), null,
529                   objectName, "queryNames");
530             }
531             catch(SecurityException JavaDoc e)
532             {
533                if( log.isTraceEnabled() )
534                   log.trace("Excluded mbean due to security: "+objectName);
535                continue;
536             }
537          }
538          // Check the mbean against the query
539
if (queryMBean(objectName, query) == true)
540             result.add(objectName);
541       }
542
543       return result;
544    }
545
546    public boolean isRegistered(ObjectName JavaDoc name)
547    {
548       return registry.contains(name);
549    }
550
551    public java.lang.Integer JavaDoc getMBeanCount()
552    {
553       return new Integer JavaDoc(registry.getSize());
554    }
555
556    public Object JavaDoc getAttribute(ObjectName JavaDoc name, String JavaDoc attribute)
557            throws MBeanException JavaDoc, AttributeNotFoundException JavaDoc, InstanceNotFoundException JavaDoc, ReflectionException JavaDoc
558    {
559       MBeanEntry entry = registry.get(name);
560       checkMBeanPermission(entry.getResourceClassName(), attribute, name,
561          "getAttribute");
562
563       MBeanInvoker mbean = entry.getInvoker();
564
565       return mbean.getAttribute(attribute);
566    }
567
568    public AttributeList JavaDoc getAttributes(ObjectName JavaDoc name, String JavaDoc[] attributes)
569            throws InstanceNotFoundException JavaDoc, ReflectionException JavaDoc
570    {
571       MBeanEntry entry = registry.get(name);
572       String JavaDoc className = entry.getResourceClassName();
573       /* Access to an attribute is required and this check will fail only
574       if access to no attributes are allowed and will result in a security
575       exception rather than an empty list.
576       */

577       checkMBeanPermission(className, null, name, "getAttribute");
578       
579       MBeanInvoker mbean = entry.getInvoker();
580       AttributeList JavaDoc list = mbean.getAttributes(attributes);
581       SecurityManager JavaDoc sm = System.getSecurityManager();
582       if( sm != null )
583       {
584          // Remove any attributes that are not allowed
585
Iterator JavaDoc iter = list.iterator();
586          while( iter.hasNext() )
587          {
588             Attribute JavaDoc attr = (Attribute JavaDoc) iter.next();
589             String JavaDoc aname = attr.getName();
590             try
591             {
592                checkMBeanPermission(className, aname, name, "getAttribute");
593             }
594             catch(SecurityException JavaDoc e)
595             {
596                if( log.isTraceEnabled() )
597                   log.trace("Excluded attribute due to security: "+aname);
598                iter.remove();
599             }
600          }
601       }
602       return list;
603    }
604
605    public void setAttribute(ObjectName JavaDoc name, Attribute JavaDoc attribute)
606            throws InstanceNotFoundException JavaDoc, AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
607    {
608       MBeanEntry entry = registry.get(name);
609       String JavaDoc attributeName = null;
610       if (attribute != null)
611          attributeName = attribute.getName();
612       checkMBeanPermission(entry.getResourceClassName(), attributeName,
613          name, "setAttribute");
614
615       MBeanInvoker mbean = entry.getInvoker();
616
617       mbean.setAttribute(attribute);
618    }
619
620    public AttributeList JavaDoc setAttributes(ObjectName JavaDoc name, AttributeList JavaDoc attributes)
621            throws InstanceNotFoundException JavaDoc, ReflectionException JavaDoc
622    {
623       MBeanEntry entry = registry.get(name);
624
625       String JavaDoc className = entry.getResourceClassName();
626       /* Access to an attribute is required and this check will fail only
627       if access to no attributes are allowed and will result in a security
628       exception rather than an empty list.
629       */

630       checkMBeanPermission(className, null, name, "setAttribute");
631
632       MBeanInvoker mbean = entry.getInvoker();
633       AttributeList JavaDoc list = mbean.setAttributes(attributes);
634       SecurityManager JavaDoc sm = System.getSecurityManager();
635       if( sm != null )
636       {
637          // Remove any attributes that are not allowed
638
Iterator JavaDoc iter = list.iterator();
639          while( iter.hasNext() )
640          {
641             Attribute JavaDoc attr = (Attribute JavaDoc) iter.next();
642             String JavaDoc aname = attr.getName();
643             try
644             {
645                checkMBeanPermission(className, aname, name, "setAttribute");
646             }
647