geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdam...@apache.org
Subject cvs commit: incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/jmx MBeanServerEndPointImpl.java
Date Thu, 27 May 2004 14:23:21 GMT
gdamour     2004/05/27 07:23:21

  Modified:    sandbox/messaging/src/java/org/apache/geronimo/messaging/jmx
                        MBeanServerEndPointImpl.java
  Added:       sandbox/messaging/src/java/org/apache/geronimo/messaging/reference
                        ReferenceableEnhancer.java
  Log:
  Adds an utility class to inject the Referenceable interface to an object.
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/reference/ReferenceableEnhancer.java
  
  Index: ReferenceableEnhancer.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed 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.geronimo.messaging.reference;
  
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Set;
  
  import net.sf.cglib.proxy.Enhancer;
  import net.sf.cglib.proxy.LazyLoader;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/27 14:23:21 $
   */
  public class ReferenceableEnhancer
  {
  
      /**
       * Injects the Referenceable interface to the set of interfaces of anOpaque.
       * 
       * @param anOpaque Object to be enhanced.
       * @return An object implementing all the interfaces of anOpaque plus the
       * Referenceable interface.
       */
      public static Object enhance(final Object anOpaque) {
          // Injects the Referenceable interface.
          Set interfaces = new HashSet();
          Class current = anOpaque.getClass();
          while ( null != current ) {
              Class[] intfs = current.getInterfaces();
              for (int i = 0; i < intfs.length; i++) {
                  interfaces.add(intfs[i]);
              }
              current = current.getSuperclass();
          }
          Class[] newInterfaces = new Class[interfaces.size() + 1];
          int i = 1;
          newInterfaces[0] = Referenceable.class;
          for (Iterator iter = interfaces.iterator(); iter.hasNext();) {
              newInterfaces[i++] = (Class) iter.next();
          }
          
          Enhancer enhancer = new Enhancer();
          enhancer.setInterfaces(newInterfaces);
          enhancer.setCallbackType(LazyLoader.class);
          enhancer.setCallback(new LazyLoader() {
              public Object loadObject() throws Exception {
                  return anOpaque;
              }
          });
          // Gets rid of the Factory interface.
          enhancer.setUseFactory(false);
          return enhancer.create();
      }
      
  }
  
  
  
  1.2       +5 -22     incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/jmx/MBeanServerEndPointImpl.java
  
  Index: MBeanServerEndPointImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/jmx/MBeanServerEndPointImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MBeanServerEndPointImpl.java	24 May 2004 12:12:47 -0000	1.1
  +++ MBeanServerEndPointImpl.java	27 May 2004 14:23:21 -0000	1.2
  @@ -19,13 +19,10 @@
   
   import javax.management.MBeanServer;
   
  -import net.sf.cglib.proxy.Enhancer;
  -import net.sf.cglib.proxy.LazyLoader;
  -
   import org.apache.geronimo.kernel.KernelMBean;
   import org.apache.geronimo.messaging.AbstractEndPoint;
   import org.apache.geronimo.messaging.Node;
  -import org.apache.geronimo.messaging.reference.Referenceable;
  +import org.apache.geronimo.messaging.reference.ReferenceableEnhancer;
   
   /**
    * MBeanServerEndPoint implementation.
  @@ -58,23 +55,9 @@
           if ( null == aKernel ) {
               throw new IllegalArgumentException("Kernel is required.");
           }
  -        // Injects the Referenceable interface.
  -        Enhancer enhancer = new Enhancer();
  -        enhancer.setInterfaces(
  -                new Class[] {MBeanServer.class, Referenceable.class});
  -        enhancer.setCallbackType(LazyLoader.class);
  -        enhancer.setCallback(new LazyLoader() {
  -            public Object loadObject() throws Exception {
  -                return aKernel.getMBeanServer();
  -            }
  -        });
  -        // Gets rid of the Factory interface.
  -        // Implementation note: when the proxy was implementing it, the
  -        // ReferenceableInfo was defining two interfaces MBeanServer and
  -        // Factory. Upon deserialization these two interfaces were MBeanServer
  -        // and MBeanServer.
  -        enhancer.setUseFactory(false);
  -        server = (MBeanServer) enhancer.create();
  +        
  +        server = (MBeanServer)
  +            ReferenceableEnhancer.enhance(aKernel.getMBeanServer());
       }
   
       public MBeanServer getMBeanServer() {
  
  
  

Mime
View raw message