InterceptorResolutionService.BeanInterceptorInfo interceptorInfo = ir.calculateInterceptorInfo(bean.getTypes(), bean.getQualifiers(), annotatedType);
Assert.assertNotNull(interceptorInfo);
// not via BeanManager but native. We will proxy it ourselfs
ClassMultiInterceptedClass internalInstance = new ClassMultiInterceptedClass();
CreationalContext<ClassMultiInterceptedClass> cc = getBeanManager().createCreationalContext(bean);
// step 1.
// calculate the interceptor-method info
Map<Method, List<Interceptor<?>>> methodInterceptors = new HashMap<Method, List<Interceptor<?>>>();
List<Method> nonBusinessMethods = new ArrayList<Method>();
for (Map.Entry<Method, InterceptorResolutionService.BusinessMethodInterceptorInfo> miEntry : interceptorInfo.getBusinessMethodsInfo().entrySet())
{
Method interceptedMethod = miEntry.getKey();
InterceptorResolutionService.BusinessMethodInterceptorInfo mii = miEntry.getValue();
List<Interceptor<?>> activeInterceptors = new ArrayList<Interceptor<?>>();
if (mii.getEjbInterceptors() != null)
{
for (Interceptor<?> i : mii.getEjbInterceptors())
{
activeInterceptors.add(i);
}
}
if (mii.getCdiInterceptors() != null)
{
for (Interceptor<?> i : mii.getCdiInterceptors())
{
activeInterceptors.add(i);
}
}
if (activeInterceptors.size() > 0)
{
methodInterceptors.put(interceptedMethod, activeInterceptors);
}
}
// step 2.
// creating the Proxy Class itself
InterceptorDecoratorProxyFactory pf = new InterceptorDecoratorProxyFactory(getWebBeansContext());
// we take a fresh URLClassLoader to not blur the test classpath with synthetic classes.
ClassLoader classLoader = this.getClass().getClassLoader(); // new URLClassLoader(new URL[0]);
Method[] businessMethods = methodInterceptors.keySet().toArray(new Method[methodInterceptors.size()]);
Method[] nonInterceptedMethods = interceptorInfo.getNonInterceptedMethods().toArray(new Method[interceptorInfo.getNonInterceptedMethods().size()]);
Class<? extends ClassMultiInterceptedClass> proxyClass = pf.createProxyClass(bean, classLoader, ClassMultiInterceptedClass.class, businessMethods, nonInterceptedMethods);
Assert.assertNotNull(proxyClass);
// step 3.
// creating the InterceptorHandler for each intercepted instance later at runtime
Map<Interceptor<?>,Object> interceptorInstances = new HashMap<Interceptor<?>, Object>();
for (Interceptor interceptorBean : interceptorInfo.getCdiInterceptors())
{
Object interceptorInstance = interceptorBean.create(cc);
interceptorInstances.put(interceptorBean, interceptorInstance);
}
InterceptorHandler interceptorHandler
= new DefaultInterceptorHandler<ClassMultiInterceptedClass>(internalInstance, internalInstance, methodInterceptors, interceptorInstances, null);
ClassMultiInterceptedClass proxyInstance = pf.createProxyInstance(proxyClass, internalInstance, interceptorHandler);
Assert.assertNotNull(proxyInstance);
Assert.assertEquals(internalInstance, proxyInstance.getSelf());
proxyInstance.setMeaningOfLife(42);
Assert.assertEquals(42, proxyInstance.getMeaningOfLife());
// for testing with the old proxies
//X proxyInstance = getInstance(ClassMultiInterceptedClass.class);
//X this is for creating the NormalScoping Proxy which is now separate