org.apache.webbeans.proxy
Class NormalScopeProxyFactory

java.lang.Object
  extended by org.apache.webbeans.proxy.AbstractProxyFactory
      extended by org.apache.webbeans.proxy.NormalScopeProxyFactory

public class NormalScopeProxyFactory
extends AbstractProxyFactory

This factory creates proxies which delegate the method invocations 1:1 to an instance which gets resolved via a Provider.


Field Summary
static String FIELD_INSTANCE_PROVIDER
          the name of the field which stores the Provider for the Contextual Instance
static String FIELD_PROTECTED_METHODS
          the Method[] for all protected methods.
 
Fields inherited from class org.apache.webbeans.proxy.AbstractProxyFactory
FIELD_BEAN_PASSIVATION_ID, MAX_CLASSLOAD_TRIES, MODIFIER_VARARGS, webBeansContext
 
Constructor Summary
NormalScopeProxyFactory(WebBeansContext webBeansContext)
           
 
Method Summary
protected  void createConstructor(org.apache.xbean.asm5.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, String classFileName, Constructor<?> ignored)
          Each of our interceptor/decorator proxies has exactly 1 constructor which invokes the super ct + sets the delegation field.
protected  void createInstanceVariables(org.apache.xbean.asm5.ClassWriter cw, Class<?> classToProxy, String classFileName)
          generate the bytecode for creating the instance variables of the class
<T> T
createNormalScopeProxy(javax.enterprise.inject.spi.Bean<T> bean)
           
<T> Class<T>
createProxyClass(javax.enterprise.inject.spi.Bean<T> bean, ClassLoader classLoader, Class<T> classToProxy)
           
<T> Class<T>
createProxyClass(ClassLoader classLoader, Class<T> classToProxy)
           
<T> T
createProxyInstance(Class<T> proxyClass, javax.inject.Provider provider)
           
protected  void createSerialisation(org.apache.xbean.asm5.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, String classFileName)
          generate the bytecode for serialization.
protected  void delegateInterceptedMethods(ClassLoader classLoader, org.apache.xbean.asm5.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] interceptedMethods)
          In the NormalScope proxying case this is used for all the protected methods as they need to get invoked via reflection.
protected  void delegateNonInterceptedMethods(ClassLoader classLoader, org.apache.xbean.asm5.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods)
          generate the bytecode for invoking all non-intercepted methods
static Object delegateProtectedMethod(Method method, Object instance, Object[] params)
          This method get invoked via generated ASM code.
 javax.inject.Provider getInstanceProvider(ClassLoader classLoader, javax.enterprise.inject.spi.Bean<?> bean)
           
 javax.inject.Provider getInstanceProvider(OwbNormalScopeProxy proxyInstance)
           
protected  Class getMarkerInterface()
           
static
<T> T
unwrapInstance(T proxyInstance)
           
 
Methods inherited from class org.apache.webbeans.proxy.AbstractProxyFactory
createArrayDefinition, createProxyClass, createProxyClass, fixPreservedPackages, generateReturn, getCastType, getPrimitiveMethod, getProxyClassLoader, getReturnInsn, getUnusedProxyClassName, getVarInsn, getWrapperType, pushIntOntoStack, pushMethodParameterArray, unproxyableMethod, unsafeNewInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIELD_INSTANCE_PROVIDER

public static final String FIELD_INSTANCE_PROVIDER
the name of the field which stores the Provider for the Contextual Instance

See Also:
Constant Field Values

FIELD_PROTECTED_METHODS

public static final String FIELD_PROTECTED_METHODS
the Method[] for all protected methods. We need to invoke them via reflection.

See Also:
Constant Field Values
Constructor Detail

NormalScopeProxyFactory

public NormalScopeProxyFactory(WebBeansContext webBeansContext)
Method Detail

getMarkerInterface

protected Class getMarkerInterface()
Specified by:
getMarkerInterface in class AbstractProxyFactory
Returns:
the marker interface which should be used for this proxy.

unwrapInstance

public static <T> T unwrapInstance(T proxyInstance)

getInstanceProvider

public javax.inject.Provider getInstanceProvider(OwbNormalScopeProxy proxyInstance)
Returns:
the internal instance which gets proxied.

createNormalScopeProxy

public <T> T createNormalScopeProxy(javax.enterprise.inject.spi.Bean<T> bean)

getInstanceProvider

public javax.inject.Provider getInstanceProvider(ClassLoader classLoader,
                                                 javax.enterprise.inject.spi.Bean<?> bean)

createProxyClass

public <T> Class<T> createProxyClass(javax.enterprise.inject.spi.Bean<T> bean,
                                     ClassLoader classLoader,
                                     Class<T> classToProxy)

createSerialisation

protected void createSerialisation(org.apache.xbean.asm5.ClassWriter cw,
                                   String proxyClassFileName,
                                   Class<?> classToProxy,
                                   String classFileName)
Description copied from class: AbstractProxyFactory
generate the bytecode for serialization.

Specified by:
createSerialisation in class AbstractProxyFactory

createProxyClass

public <T> Class<T> createProxyClass(ClassLoader classLoader,
                                     Class<T> classToProxy)
                          throws ProxyGenerationException
Type Parameters:
T -
Parameters:
classLoader - to use for creating the class in
classToProxy - the class for which a subclass will get generated
Returns:
the proxy class
Throws:
ProxyGenerationException

createProxyInstance

public <T> T createProxyInstance(Class<T> proxyClass,
                                 javax.inject.Provider provider)
                      throws ProxyGenerationException
Throws:
ProxyGenerationException

createConstructor

protected void createConstructor(org.apache.xbean.asm5.ClassWriter cw,
                                 String proxyClassFileName,
                                 Class<?> classToProxy,
                                 String classFileName,
                                 Constructor<?> ignored)
                          throws ProxyGenerationException
Description copied from class: AbstractProxyFactory
Each of our interceptor/decorator proxies has exactly 1 constructor which invokes the super ct + sets the delegation field.

Specified by:
createConstructor in class AbstractProxyFactory
Throws:
ProxyGenerationException

createInstanceVariables

protected void createInstanceVariables(org.apache.xbean.asm5.ClassWriter cw,
                                       Class<?> classToProxy,
                                       String classFileName)
Description copied from class: AbstractProxyFactory
generate the bytecode for creating the instance variables of the class

Specified by:
createInstanceVariables in class AbstractProxyFactory

delegateInterceptedMethods

protected void delegateInterceptedMethods(ClassLoader classLoader,
                                          org.apache.xbean.asm5.ClassWriter cw,
                                          String proxyClassFileName,
                                          Class<?> classToProxy,
                                          Method[] interceptedMethods)
                                   throws ProxyGenerationException
In the NormalScope proxying case this is used for all the protected methods as they need to get invoked via reflection.

Specified by:
delegateInterceptedMethods in class AbstractProxyFactory
Throws:
ProxyGenerationException

delegateNonInterceptedMethods

protected void delegateNonInterceptedMethods(ClassLoader classLoader,
                                             org.apache.xbean.asm5.ClassWriter cw,
                                             String proxyClassFileName,
                                             Class<?> classToProxy,
                                             Method[] noninterceptedMethods)
                                      throws ProxyGenerationException
Description copied from class: AbstractProxyFactory
generate the bytecode for invoking all non-intercepted methods

Specified by:
delegateNonInterceptedMethods in class AbstractProxyFactory
Throws:
ProxyGenerationException

delegateProtectedMethod

public static Object delegateProtectedMethod(Method method,
                                             Object instance,
                                             Object[] params)
This method get invoked via generated ASM code. It delegates to the underlying protected Method so we don't need to do all the reflection stuff in our generated bytecode. This is needed as we cannot invoke instanceProvider.get().targetMethod() directly if targetMethod is protected. Please see Java LangSpec 6.6.2 about the complex rules for calling 'protected' methods.

See Also:
generateDelegationMethod(org.apache.xbean.asm5.ClassWriter, java.lang.reflect.Method, int, Class, String)


Copyright © 2008–2015 The Apache Software Foundation. All rights reserved.