1 package picocontainer.hierarchical;
2
3 import picocontainer.defaults.DefaultComponentFactory;
4 import picocontainer.PicoInvocationTargetInitailizationException;
5
6 import java.lang.reflect.Constructor;
7 import java.lang.reflect.Proxy;
8 import java.lang.reflect.InvocationHandler;
9 import java.lang.reflect.Method;
10
11
12 public class ImplementationHidingComponentFactory extends DefaultComponentFactory {
13
14 public Object createComponent(Class compType, Constructor constructor, Object[] args) throws PicoInvocationTargetInitailizationException {
15 Object component = super.createComponent(compType, constructor, args);
16 return Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {compType}, new ImplementationHidingProxy(component));
17 }
18
19 private class ImplementationHidingProxy implements InvocationHandler {
20 private Object componentInstance;
21
22 public ImplementationHidingProxy(Object componentInstance) {
23 this.componentInstance = componentInstance;
24 }
25
26 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
27 return method.invoke(componentInstance, args);
28 }
29 }
30 }
This page was automatically generated by Maven