| 1 | |
package org.apache.ojb.broker.core.proxy; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 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 | |
|
| 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 | |
|
| 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 | |
} |