Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * Licensed to the Apache Software Foundation (ASF) under one or more
    * contributor license agreements.  See the NOTICE file distributed with
    * this work for additional information regarding copyright ownership.
    * The ASF licenses this file to You under the Apache License, Version 2.0
    * (the "License"); you may not use this file except in compliance with
    * the License.  You may obtain a copy of the License at
    * 
    *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  package org.apache.tomcat.util.modeler;
  
  
  import static org.jboss.web.CoyoteMessages.MESSAGES;
  
  
  
  
  /*
   * Changes from commons.modeler:
   * 
   *  - use DynamicMBean
   *  - remove methods not used in tomcat and redundant/not very generic
   *  - must be created from the ManagedBean - I don't think there were any direct
   *    uses, but now it is required.
   *  - some of the gratuituous flexibility removed - instead this is more predictive and
   *    strict with the use cases.
   *  - all Method and metadata is stored in ManagedBean. BaseModelBMean and ManagedBean act
   *    like Object and Class. 
   *  - setModelMBean is no longer called on resources ( not used in tomcat )
   *  - no caching of Methods for now - operations and setters are not called repeatedly in most 
   *  management use cases. Getters should't be called very frequently either - and even if they
   *  are, the overhead of getting the method should be small compared with other JMX costs ( RMI, etc ).
   *  We can add getter cache if needed.
   *  - removed unused constructor, fields
   *  
   *  TODO:
   *   - clean up catalina.mbeans, stop using weird inheritance
   */

Basic implementation of the DynamicMBean interface, which supports the minimal requirements of the interface contract.

This can be used directly to wrap an existing java bean, or inside an mlet or anywhere an MBean would be used. Limitations:

  • Only managed resources of type objectReference are supportd.
  • Caching of attribute values and operation results is not supported. All calls to invoke() are immediately executed.
  • Persistence of MBean attributes and operations is not supported.
  • All classes referenced as attribute types, operation parameters, or operation return values must be one of the following:
    • One of the Java primitive types (boolean, byte, char, double, float, integer, long, short). Corresponding value will be wrapped in the appropriate wrapper class automatically.
    • Operations that return no value should declare a return type of void.
  • Attribute caching is not supported

Author(s):
Craig R. McClanahan
Costin Manolache
 
 
     // ----------------------------------------------------------- Constructors
 
    
Construct a ModelMBean with default ModelMBeanInfo information.

Throws:
javax.management.MBeanException if the initializer of an object throws an exception
javax.management.RuntimeOperationsException if an IllegalArgumentException occurs
 
     protected BaseModelMBean() throws MBeanExceptionRuntimeOperationsException {
         super();
     }
 
     // ----------------------------------------------------- Instance Variables
 
     protected ObjectName oname=null;

    
Notification broadcaster for attribute changes.
 
     protected BaseNotificationBroadcaster attributeBroadcaster = null;

    
Notification broadcaster for general notifications.
 
     protected BaseNotificationBroadcaster generalBroadcaster = null;
    
    
Metadata for the mbean instance.
 
     protected ManagedBean managedBean = null;

    
The managed resource this MBean is associated with (if any).
 
     protected Object resource = null;
 
     // --------------------------------------------------- DynamicMBean Methods
     // TODO: move to ManagedBean
     static final Object[] NO_ARGS_PARAM=new Object[0];
     static final Class[] NO_ARGS_PARAM_SIG=new Class[0];
     
     protected String resourceType = null;
 
     // key: operation val: invoke method
     //private Hashtable invokeAttMap=new Hashtable();
 
    
Obtain and return the value of a specific attribute of this MBean.

Parameters:
name Name of the requested attribute
Throws:
javax.management.AttributeNotFoundException if this attribute is not supported by this MBean
javax.management.MBeanException if the initializer of an object throws an exception
javax.management.ReflectionException if a Java reflection exception occurs when invoking the getter
 
     public Object getAttribute(String name)
         throws AttributeNotFoundExceptionMBeanException,
             ReflectionException {
         // Validate the input parameters
         if (name == null)
             throw new RuntimeOperationsException
                 (new IllegalArgumentException(.nullAttributeName()),
                         .nullAttributeName());
 
         if( ( instanceof DynamicMBean) && 
              ! (  instanceof BaseModelMBean )) {
             return ((DynamicMBean)).getAttribute(name);
         }
         
         Method m=.getGetter(namethis);
         Object result = null;
         try {
             Class declaring=m.getDeclaringClass();
             // workaround for catalina weird mbeans - the declaring class is BaseModelMBean.
             // but this is the catalina class.
             ifdeclaring.isAssignableFrom(this.getClass()) ) {
                 result = m.invoke(this );
             } else {
                 synchronized () {
                     result = m.invoke( );
                 }
             }
         } catch (InvocationTargetException e) {
             Throwable t = e.getTargetException();
             if (t == null)
                 t = e;
             if (t instanceof RuntimeException)
                 throw new RuntimeOperationsException
                     ((RuntimeExceptiont.errorGettingAttribute(name));
             else if (t instanceof Error)
                 throw new RuntimeErrorException
                     ((Errort.errorGettingAttribute(name));
             else
                 throw new MBeanException
                     (e.errorGettingAttribute(name));
         } catch (Exception e) {
             throw new MBeanException
                 (e.errorGettingAttribute(name));
         }
 
         // Return the results of this method invocation
         // FIXME - should we validate the return type?
         return (result);
     }


    
Obtain and return the values of several attributes of this MBean.

Parameters:
names Names of the requested attributes
 
     public AttributeList getAttributes(String names[]) {
 
         // Validate the input parameters
         if (names == null)
             throw new RuntimeOperationsException
                 (new IllegalArgumentException(.nullAttributeNameList()),
                         .nullAttributeNameList());
 
         // Prepare our response, eating all exceptions
         AttributeList response = new AttributeList();
         for (int i = 0; i < names.lengthi++) {
             try {
                 response.add(new Attribute(names[i],getAttribute(names[i])));
             } catch (Exception e) {
                 ; // Not having a particular attribute in the response
                 ; // is the indication of a getter problem
             }
         }
         return (response);
 
     }
 
     public void setManagedBean(ManagedBean managedBean) {
         this. = managedBean;
     }

    
Return the MBeanInfo object for this MBean.
 
     public MBeanInfo getMBeanInfo() {
         return .getMBeanInfo();
     }


    
Invoke a particular method on this MBean, and return any returned value.

IMPLEMENTATION NOTE - This implementation will attempt to invoke this method on the MBean itself, or (if not available) on the managed resource object associated with this MBean.

Parameters:
name Name of the operation to be invoked
params Array containing the method parameters of this operation
signature Array containing the class names representing the signature of this operation
Throws:
javax.management.MBeanException if the initializer of an object throws an exception
ReflectioNException if a Java reflection exception occurs when invoking a method
 
     public Object invoke(String nameObject params[], String signature[])
         throws MBeanExceptionReflectionException 
     {
         if( ( instanceof DynamicMBean) && 
              ! (  instanceof BaseModelMBean )) {
             return ((DynamicMBean)).invoke(nameparamssignature);
         }
     
         // Validate the input parameters
         if (name == null)
             throw new RuntimeOperationsException
                 (new IllegalArgumentException(.nullMethodName()),
                         .nullMethodName());
 
 	MethodKey mkey = new MethodKey(namesignature);
         Method method.getInvoke(nameparamssignaturethis);
         
         // Invoke the selected method on the appropriate object
         Object result = null;
         try {
             ifmethod.getDeclaringClass().isAssignableFromthis.getClass()) ) {
                 result = method.invoke(thisparams );
             } else {
                 synchronized () {
                     result = method.invoke(params);
                 }
             }
         } catch (InvocationTargetException e) {
             Throwable t = e.getTargetException();
             if (t == null)
                 t = e;
             if (t instanceof RuntimeException)
                 throw new RuntimeOperationsException
                     ((RuntimeExceptiont.errorInvokingMethod(name));
             else if (t instanceof Error)
                 throw new RuntimeErrorException
                     ((Errort.errorInvokingMethod(name));
             else
                 throw new MBeanException
                     ((Exception)t.errorInvokingMethod(name));
         } catch (Exception e) {
             throw new MBeanException
                 (e.errorInvokingMethod(name));
         }
 
         // Return the results of this method invocation
         // FIXME - should we validate the return type?
         return (result);
 
     }
 
     static Class getAttributeClass(String signature)
         throws ReflectionException
     {
         if (signature.equals(..getName()))
             return .;
         else if (signature.equals(..getName()))
             return .;
         else if (signature.equals(..getName()))
             return .;
         else if (signature.equals(..getName()))
             return .;
         else if (signature.equals(..getName()))
             return .;
         else if (signature.equals(..getName()))
             return .;
         else if (signature.equals(..getName()))
             return .;
         else if (signature.equals(..getName()))
             return .;
         else {
             try {
                 ClassLoader cl=Thread.currentThread().getContextClassLoader();
                 ifcl!=null )
                     return cl.loadClass(signature); 
             } catchClassNotFoundException e ) {
             }
             try {
                 return Class.forName(signature);
             } catch (ClassNotFoundException e) {
                 throw new ReflectionException(e);
             }
         }
     }

    
Set the value of a specific attribute of this MBean.

Parameters:
attribute The identification of the attribute to be set and the new value
Throws:
javax.management.AttributeNotFoundException if this attribute is not supported by this MBean
javax.management.MBeanException if the initializer of an object throws an exception
javax.management.ReflectionException if a Java reflection exception occurs when invoking the getter
 
     public void setAttribute(Attribute attribute)
         throws AttributeNotFoundExceptionMBeanException,
         ReflectionException
     {
         if..isDebugEnabled() )
             ..debug("Setting attribute " + this + " " + attribute );
 
         if( ( instanceof DynamicMBean) && 
              ! (  instanceof BaseModelMBean )) {
             try {
                 ((DynamicMBean)).setAttribute(attribute);
             } catch (InvalidAttributeValueException e) {
                 throw new MBeanException(e);                
             }
             return;
         }
         
         // Validate the input parameters
         if (attribute == null)
             throw new RuntimeOperationsException
                 (new IllegalArgumentException(.nullAttribute()),
                         .nullAttribute());
 
         String name = attribute.getName();
         Object value = attribute.getValue();
 
         if (name == null)
             throw new RuntimeOperationsException
                 (new IllegalArgumentException(.nullAttributeName()),
                         .nullAttributeName());
 
         Object oldValue=null;
         //if( getAttMap.get(name) != null )
         //    oldValue=getAttribute( name );
 
         Method m=.getSetter(name,this,);
 
         try {
             ifm.getDeclaringClass().isAssignableFromthis.getClass()) ) {
                 m.invoke(thisnew Object[] { value });
             } else {
                 synchronized () {
                     m.invoke(new Object[] { value });
                 }
             }
         } catch (InvocationTargetException e) {
             Throwable t = e.getTargetException();
             if (t == null)
                 t = e;
             if (t instanceof RuntimeException)
                 throw new RuntimeOperationsException
                     ((RuntimeExceptiont.errorSettingAttribute(name));
             else if (t instanceof Error)
                 throw new RuntimeErrorException
                     ((Errort.errorSettingAttribute(name));
             else
                 throw new MBeanException
                     (e.errorSettingAttribute(name));
         } catch (Exception e) {
             throw new MBeanException
                 (e.errorSettingAttribute(name));
         }
         try {
             sendAttributeChangeNotification(new AttributenameoldValue),
                     attribute);
         } catch(Exception ex) {
         }
         //attributes.put( name, value );
 //        if( source != null ) {
 //            // this mbean is asscoiated with a source - maybe we want to persist
 //            source.updateField(oname, name, value);
 //        }
     }
 
     public String toString() {
         if==null ) 
             return "BaseModelMbean[" +  + "]";
         return .toString();
     }

    
Set the values of several attributes of this MBean.

Parameters:
attributes THe names and values to be set
Returns:
The list of attributes that were set and their new values
 
     public AttributeList setAttributes(AttributeList attributes) {
         AttributeList response = new AttributeList();
 
         // Validate the input parameters
         if (attributes == null)
             return response;
         
         // Prepare and return our response, eating all exceptions
         String names[] = new String[attributes.size()];
         int n = 0;
         Iterator items = attributes.iterator();
         while (items.hasNext()) {
             Attribute item = (Attributeitems.next();
             names[n++] = item.getName();
             try {
                 setAttribute(item);
             } catch (Exception e) {
                 ; // Ignore all exceptions
             }
         }
 
         return (getAttributes(names));
 
     }
 
 
     // ----------------------------------------------------- ModelMBean Methods
 

    
Get the instance handle of the object against which we execute all methods in this ModelMBean management interface.

Throws:
javax.management.InstanceNotFoundException if the managed resource object cannot be found
javax.management.MBeanException if the initializer of the object throws an exception
javax.management.RuntimeOperationsException if the managed resource or the resource type is null or invalid
 
     public Object getManagedResource()
 
         if ( == null)
             throw new RuntimeOperationsException
                 (new IllegalArgumentException(.nullManagedResource()),
                         .nullManagedResource());
 
         return ;
 
     }


    
Set the instance handle of the object against which we will execute all methods in this ModelMBean management interface. This method will detect and call "setModelMbean" method. A resource can implement this method to get a reference to the model mbean. The reference can be used to send notification and access the registry. The caller can provide the mbean instance or the object name to the resource, if needed.

Parameters:
resource The resource object to be managed
type The type of reference for the managed resource ("ObjectReference", "Handle", "IOR", "EJBHandle", or "RMIReference")
Throws:
javax.management.InstanceNotFoundException if the managed resource object cannot be found
javax.management.modelmbean.InvalidTargetObjectTypeException if this ModelMBean is asked to handle a reference type it cannot deal with
javax.management.MBeanException if the initializer of the object throws an exception
javax.management.RuntimeOperationsException if the managed resource or the resource type is null or invalid
 
     public void setManagedResource(Object resourceString type)
         throws InstanceNotFoundException
     {
         if (resource == null)
             throw new RuntimeOperationsException
                 (new IllegalArgumentException(.nullManagedResource()),
                         .nullManagedResource());
 
 //        if (!"objectreference".equalsIgnoreCase(type))
 //            throw new InvalidTargetObjectTypeException(type);
 
         this. = resource;
         this. = resource.getClass().getName();
         
 //        // Make the resource aware of the model mbean.
 //        try {
 //            Method m=resource.getClass().getMethod("setModelMBean",
 //                    new Class[] {ModelMBean.class});
 //            if( m!= null ) {
 //                m.invoke(resource, new Object[] {this});
 //            }
 //        } catch( NoSuchMethodException t ) {
 //            // ignore
 //        } catch( Throwable t ) {
 //            log.error( "Can't set model mbean ", t );
 //        }
     }
 
 
     // ------------------------------ ModelMBeanNotificationBroadcaster Methods
 

    
Add an attribute change notification event listener to this MBean.

Parameters:
listener Listener that will receive event notifications
name Name of the attribute of interest, or null to indicate interest in all attributes
handback Handback object to be sent along with event notifications
Throws:
java.lang.IllegalArgumentException if the listener parameter is null
 
         (NotificationListener listenerString nameObject handback)
         throws IllegalArgumentException {
 
         if (listener == null)
             throw new IllegalArgumentException(.nullListener());
         if ( == null)
              = new BaseNotificationBroadcaster();
 
         if..isDebugEnabled() )
             ..debug("addAttributeNotificationListener " + listener);
 
         BaseAttributeFilter filter = new BaseAttributeFilter(name);
             (listenerfilterhandback);
 
     }


    
Remove an attribute change notification event listener from this MBean.

Parameters:
listener The listener to be removed
name The attribute name for which no more events are required
Throws:
javax.management.ListenerNotFoundException if this listener is not registered in the MBean
 
         (NotificationListener listenerString name)
         throws ListenerNotFoundException {
 
         if (listener == null)
             throw new IllegalArgumentException(.nullListener());
         if ( == null)
              = new BaseNotificationBroadcaster();
 
         // FIXME - currently this removes *all* notifications for this listener
 
     }


    
Remove an attribute change notification event listener from this MBean.

Parameters:
listener The listener to be removed
attributeName The attribute name for which no more events are required
handback Handback object to be sent along with event notifications
Throws:
javax.management.ListenerNotFoundException if this listener is not registered in the MBean
 
         (NotificationListener listenerString attributeNameObject handback)
         throws ListenerNotFoundException {
 
         removeAttributeChangeNotificationListener(listenerattributeName);
 
     }


    
Send an AttributeChangeNotification to all registered listeners.

Parameters:
notification The AttributeChangeNotification that will be passed
Throws:
javax.management.MBeanException if an object initializer throws an exception
javax.management.RuntimeOperationsException wraps IllegalArgumentException when the specified notification is null or invalid
 
     public void sendAttributeChangeNotification
         (AttributeChangeNotification notification)
         throws MBeanExceptionRuntimeOperationsException {
 
         if (notification == null)
             throw new RuntimeOperationsException
                 (new IllegalArgumentException(.nullNotification()),
                         .nullNotification());
         if ( == null)
             return// This means there are no registered listeners
         if..isDebugEnabled() )
             ..debug"AttributeChangeNotification " + notification );
         .sendNotification(notification);
 
     }


    
Send an AttributeChangeNotification to all registered listeners.

Parameters:
oldValue The original value of the Attribute
newValue The new value of the Attribute
Throws:
javax.management.MBeanException if an object initializer throws an exception
javax.management.RuntimeOperationsException wraps IllegalArgumentException when the specified notification is null or invalid
 
     public void sendAttributeChangeNotification
         (Attribute oldValueAttribute newValue)
         throws MBeanExceptionRuntimeOperationsException {
 
         // Calculate the class name for the change notification
         String type = null;
         if (newValue.getValue() != null)
             type = newValue.getValue().getClass().getName();
         else if (oldValue.getValue() != null)
             type = oldValue.getValue().getClass().getName();
         else
             return;  // Old and new are both null == no change
 
         AttributeChangeNotification notification =
             new AttributeChangeNotification
             (this, 1, System.currentTimeMillis(),
              "Attribute value has changed",
              oldValue.getName(), type,
              oldValue.getValue(), newValue.getValue());
         sendAttributeChangeNotification(notification);
 
     }




    
Send a Notification to all registered listeners as a jmx.modelmbean.general notification.

Parameters:
notification The Notification that will be passed
Throws:
javax.management.MBeanException if an object initializer throws an exception
javax.management.RuntimeOperationsException wraps IllegalArgumentException when the specified notification is null or invalid
 
     public void sendNotification(Notification notification)
         throws MBeanExceptionRuntimeOperationsException {
 
         if (notification == null)
             throw new RuntimeOperationsException
                 (new IllegalArgumentException(.nullNotification()),
                         .nullNotification());
         if ( == null)
             return// This means there are no registered listeners
         .sendNotification(notification);
 
     }


    
Send a Notification which contains the specified string as a jmx.modelmbean.generic notification.

Parameters:
message The message string to be passed
Throws:
javax.management.MBeanException if an object initializer throws an exception
javax.management.RuntimeOperationsException wraps IllegalArgumentException when the specified notification is null or invalid
 
     public void sendNotification(String message)
         throws MBeanExceptionRuntimeOperationsException {
 
         if (message == null)
             throw new RuntimeOperationsException
                 (new IllegalArgumentException(.nullMessage()),
                         .nullMessage());
         Notification notification = new Notification
             ("jmx.modelmbean.generic"this, 1, message);
         sendNotification(notification);
 
     }
 
 
 
 
     // ---------------------------------------- NotificationBroadcaster Methods
 

    
Add a notification event listener to this MBean.

Parameters:
listener Listener that will receive event notifications
filter Filter object used to filter event notifications actually delivered, or null for no filtering
handback Handback object to be sent along with event notifications
Throws:
java.lang.IllegalArgumentException if the listener parameter is null
 
     public void addNotificationListener(NotificationListener listener,
                                         NotificationFilter filter,
                                         Object handback)
         throws IllegalArgumentException {
 
         if (listener == null)
             throw new IllegalArgumentException(.nullListener());
 
         if..isDebugEnabled() ) ..debug("addNotificationListener " + listener);
 
         if ( == null)
              = new BaseNotificationBroadcaster();
             (listenerfilterhandback);
 
         // We'll send the attribute change notifications to all listeners ( who care )
         // The normal filtering can be used.
         // The problem is that there is no other way to add attribute change listeners
         // to a model mbean ( AFAIK ). I suppose the spec should be fixed.
         if ( == null)
              = new BaseNotificationBroadcaster();
 
         if..isDebugEnabled() )
             ..debug("addAttributeNotificationListener " + listener);
 
                 (listenerfilterhandback);
     }


    
Return an MBeanNotificationInfo object describing the notifications sent by this MBean.
 
 
         // Acquire the set of application notifications
         MBeanNotificationInfo current[] = getMBeanInfo().getNotifications();
         if (current == null)
             current = new MBeanNotificationInfo[0];
         MBeanNotificationInfo response[] =
             new MBeanNotificationInfo[current.length + 2];
  //       Descriptor descriptor = null;
 
         // Fill in entry for general notifications
 //        descriptor = new DescriptorSupport
 //            (new String[] { "name=GENERIC",
 //                            "descriptorType=notification",
 //                            "log=T",
 //                            "severity=5",
 //                            "displayName=jmx.modelmbean.generic" });
         response[0] = new MBeanNotificationInfo
             (new String[] { "jmx.modelmbean.generic" },
              "GENERIC",
              "Text message notification from the managed resource");
              //descriptor);
 
         // Fill in entry for attribute change notifications
 //        descriptor = new DescriptorSupport
 //            (new String[] { "name=ATTRIBUTE_CHANGE",
 //                            "descriptorType=notification",
 //                            "log=T",
 //                            "severity=5",
 //                            "displayName=jmx.attribute.change" });
         response[1] = new MBeanNotificationInfo
             (new String[] { "jmx.attribute.change" },
              "ATTRIBUTE_CHANGE",
              "Observed MBean attribute value has changed");
              //descriptor);
 
         // Copy remaining notifications as reported by the application
         System.arraycopy(current, 0, response, 2, current.length);
         return (response);
 
     }


    
Remove a notification event listener from this MBean.

Parameters:
listener The listener to be removed (any and all registrations for this listener will be eliminated)
Throws:
javax.management.ListenerNotFoundException if this listener is not registered in the MBean
 
     public void removeNotificationListener(NotificationListener listener)
         throws ListenerNotFoundException {
 
         if (listener == null)
             throw new IllegalArgumentException(.nullListener());
         if ( == null)
              = new BaseNotificationBroadcaster();
 
 
     }


    
Remove a notification event listener from this MBean.

Parameters:
listener The listener to be removed (any and all registrations for this listener will be eliminated)
handback Handback object to be sent along with event notifications
Throws:
javax.management.ListenerNotFoundException if this listener is not registered in the MBean
 
     public void removeNotificationListener(NotificationListener listener,
                                            Object handback)
         throws ListenerNotFoundException {
 
         removeNotificationListener(listener);
 
     }


    
Remove a notification event listener from this MBean.

Parameters:
listener The listener to be removed (any and all registrations for this listener will be eliminated)
filter Filter object used to filter event notifications actually delivered, or null for no filtering
handback Handback object to be sent along with event notifications
Throws:
javax.management.ListenerNotFoundException if this listener is not registered in the MBean
 
     public void removeNotificationListener(NotificationListener listener,
                                            NotificationFilter filter,
                                            Object handback)
         throws ListenerNotFoundException {
 
         removeNotificationListener(listener);
 
     }
 
 
     // ------------------------------------------------ PersistentMBean Methods
 

    
Instantiates this MBean instance from data found in the persistent store. The data loaded could include attribute and operation values. This method should be called during construction or initialization of the instance, and before the MBean is registered with the MBeanServer.

IMPLEMENTATION NOTE - This implementation does not support persistence.

Throws:
InstanceNotFoundException if the managed resource object cannot be found
MBeanException if the initializer of the object throws an exception
RuntimeOperationsException if an exception is reported by the persistence mechanism
 
 //    public void load() throws InstanceNotFoundException,
 //        MBeanException, RuntimeOperationsException {
 //        // XXX If a context was set, use it to load the data
 //        throw new MBeanException
 //            (new IllegalStateException("Persistence is not supported"),
 //             "Persistence is not supported");
 //
 //    }
 

    
Capture the current state of this MBean instance and write it out to the persistent store. The state stored could include attribute and operation values. If one of these methods of persistence is not supported, a "service not found" exception will be thrown.

IMPLEMENTATION NOTE - This implementation does not support persistence.

Throws:
InstanceNotFoundException if the managed resource object cannot be found
MBeanException if the initializer of the object throws an exception, or persistence is not supported
RuntimeOperationsException if an exception is reported by the persistence mechanism
 
 //    public void store() throws InstanceNotFoundException,
 //        MBeanException, RuntimeOperationsException {
 //
 //        // XXX if a context was set, use it to store the data
 //        throw new MBeanException
 //            (new IllegalStateException("Persistence is not supported"),
 //             "Persistence is not supported");
 //
 //    }
 
     // --------------------  BaseModelMBean methods --------------------
 
    
Set the type of the mbean. This is used as a key to locate the description in the Registry.

Parameters:
type the type of classname of the modeled object
 
 //    void setModeledType( String type ) {
 //        initModelInfo(type);
 //        createResource();
 //    }
     
Set the type of the mbean. This is used as a key to locate the description in the Registry.

Parameters:
type the type of classname of the modeled object
 
 //    void initModelInfo( String type ) {
 //        try {
//            if( log.isDebugEnabled())
//                log.debug("setModeledType " + type);
//            log.debug( "Set model Info " + type);
//            if(type==null) {
//                return;
//            }
//            resourceType=type;
//            //Thread.currentThread().setContextClassLoader(BaseModelMBean.class.getClassLoader());
//            Class c=null;
//            try {
//                c=Class.forName( type);
//            } catch( Throwable t ) {
//                log.debug( "Error creating class " + t);
//            }
//            // The class c doesn't need to exist
//            ManagedBean descriptor=getRegistry().findManagedBean(c, type);
//            if( descriptor==null ) 
//                return;
//            this.setModelMBeanInfo(descriptor.createMBeanInfo());
//        } catch( Throwable ex) {
//            log.error( "TCL: " + Thread.currentThread().getContextClassLoader(),
//                    ex);
//        }
//    }

    
Set the type of the mbean. This is used as a key to locate the description in the Registry.
//    protected void createResource() {
//        try {
//            //Thread.currentThread().setContextClassLoader(BaseModelMBean.class.getClassLoader());
//            Class c=null;
//            try {
//                c=Class.forName( resourceType );
//                resource = c.newInstance();
//            } catch( Throwable t ) {
//                log.error( "Error creating class " + t);
//            }
//        } catch( Throwable ex) {
//            log.error( "TCL: " + Thread.currentThread().getContextClassLoader(),
//                    ex);
//        }
//    }
    public String getModelerType() {
        return ;
    }
    public String getClassName() {
        return getModelerType();
    }
    public ObjectName getJmxName() {
        return ;
    }
    public String getObjectName() {
        if ( != null) {
            return .toString();
        } else {
            return null;
        }
    }
//    public void setRegistry(Registry registry) {
//        this.registry = registry;
//    }
//    public Registry getRegistry() {
//        // XXX Need a better solution - to avoid the static
//        if( registry == null )
//            registry=Registry.getRegistry();
//        return registry;
//    }
    // ------------------------------------------------------ Protected Methods


    
Create and return a default ModelMBeanInfo object.
//    protected ModelMBeanInfo createDefaultModelMBeanInfo() {
//        return (new ModelMBeanInfoSupport(this.getClass().getName(),
//                                          "Default ModelMBean",
//                                          null, null, null, null));
//    }

    
Is the specified ModelMBeanInfo instance valid?

IMPLEMENTATION NOTE - This implementation does not check anything, but this method can be overridden as required.

Parameters:
info The ModelMBeanInfo object to check
//    protected boolean isModelMBeanInfoValid(ModelMBeanInfo info) {
//        return (true);
//    }
    // -------------------- Registration  --------------------
    // XXX We can add some method patterns here- like setName() and
    // setDomain() for code that doesn't implement the Registration
    public ObjectName preRegister(MBeanServer server,
                                  ObjectName name)
            throws Exception
    {
            ..debug("preRegister " +  + " " + name );
        =name;
        if instanceof MBeanRegistration ) {
             = ((MBeanRegistration)).preRegister(servername );
        }
        return ;
    }
    public void postRegister(Boolean registrationDone) {
        if instanceof MBeanRegistration ) {
            ((MBeanRegistration)).postRegister(registrationDone);
        }
    }
    public void preDeregister() throws Exception {
        if instanceof MBeanRegistration ) {
            ((MBeanRegistration)).preDeregister();
        }
    }
    public void postDeregister() {
        if instanceof MBeanRegistration ) {
            ((MBeanRegistration)).postDeregister();
        }
    }
    static class MethodKey {
	private String name;
	private String[] signature;
	MethodKey(String nameString[] signature) {
	    this. = name;
	    if(signature == null) {
		signature = new String[0];
	    }
	    this. = signature;
	public boolean equals(Object other) {
	    if(!(other instanceof MethodKey)) {
		return false;
	    }
	    MethodKey omk = (MethodKey)other;
	    if(!.equals(omk.name)) {
		return false;
	    }
	    if(. != omk.signature.length) {
		return false;
	    }
	    for(int i=0; i < .i++) {
		if(![i].equals(omk.signature[i])) {
		    return false;
	    }
	    return true;
	public int hashCode() {
	    return .hashCode();
    }
New to GrepCode? Check out our FAQ X