Coverage Report - org.apache.ojb.broker.core.proxy.ProxyFactoryCGLIBImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ProxyFactoryCGLIBImpl
N/A
N/A
1.5
 
 1  
 package org.apache.ojb.broker.core.proxy;
 2  
 
 3  
 /* Copyright 2002-2005 The Apache Software Foundation
 4  
  *
 5  
  * Licensed under the Apache License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 import java.util.HashMap;
 18  
 
 19  
 import net.sf.cglib.proxy.Callback;
 20  
 import net.sf.cglib.proxy.Enhancer;
 21  
 import net.sf.cglib.proxy.Factory;
 22  
 
 23  
 /**
 24  
  * @author andrew.clute
 25  
  *
 26  
  */
 27  
 public class ProxyFactoryCGLIBImpl extends AbstractProxyFactory {
 28  
 
 29  
     HashMap proxyFactories = new HashMap();
 30  
 
 31  
     public Class getDefaultIndirectionHandlerClass() {
 32  
         return IndirectionHandlerCGLIBImpl.class;
 33  
     }
 34  
 
 35  
     /**
 36  
      * Returns the class of the base class that the given IndirectionHandler must extend/implement
 37  
      * 
 38  
      */
 39  
     public Class getIndirectionHandlerBaseClass() {
 40  
         return IndirectionHandlerCGLIB.class;
 41  
     }
 42  
 
 43  
     public OJBProxy createProxy(Class proxyClass, IndirectionHandler handler) throws Exception {
 44  
 
 45  
         Factory factory = (Factory)proxyFactories.get(proxyClass);
 46  
         Object result = null;
 47  
         if (factory == null) {
 48  
             Class[] interfaces;
 49  
             if (proxyClass.isInterface()) {
 50  
                 interfaces = new Class[] { proxyClass, OJBProxy.class };
 51  
             } else {
 52  
                 interfaces = new Class[] { OJBProxy.class };
 53  
             }
 54  
 
 55  
             result = (Factory)Enhancer.create(proxyClass, interfaces, (Callback)handler);
 56  
             proxyFactories.put(proxyClass, result);
 57  
         } else {
 58  
             result = factory.newInstance((Callback)handler);
 59  
         }
 60  
         return (OJBProxy)result;
 61  
     }
 62  
 
 63  
     public boolean isNormalOjbProxy(Object proxyOrObject) {
 64  
         return super.isNormalOjbProxy(proxyOrObject) && (proxyOrObject instanceof Factory);
 65  
     }
 66  
 
 67  
     public IndirectionHandler getDynamicIndirectionHandler(Object obj) {
 68  
         return (IndirectionHandler)((Factory)obj).getCallbacks()[0];
 69  
 
 70  
     }
 71  
 
 72  
     public boolean interfaceRequiredForProxyGeneration() {
 73  
         return false;
 74  
     }
 75  
     
 76  
     
 77  
 
 78  
 }