Package org.atmosphere.inject
Class InjectableObjectFactory
- java.lang.Object
-
- org.atmosphere.inject.InjectableObjectFactory
-
- All Implemented Interfaces:
AtmosphereObjectFactory<Injectable<?>>,AtmosphereConfigAware
public class InjectableObjectFactory extends java.lang.Object implements AtmosphereObjectFactory<Injectable<?>>
Support injection of Atmosphere's Internal object usingAtmosphereConfig,AtmosphereFramework,{@link org.atmosphere.cpr.BroadcasterFactory,AtmosphereResourceFactory,DefaultMetaBroadcasterandAtmosphereResourceSessionFactoryand classes implementing theInjectabledefined inside META_INF/services/org.atmosphere.inject.Inject- Author:
- Jeanfrancois Arcand
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Loggerlogger
-
Constructor Summary
Constructors Constructor Description InjectableObjectFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AtmosphereObjectFactoryallowInjectionOf(Injectable<?> injectable)Pass information to the underlying Dependency Injection ImplementationAtmosphereObjectFactoryallowInjectionOf(Injectable<?> injectable, boolean first)<U> voidapplyMethods(U instance, java.lang.Class<U> defaultType)voidconfigure(AtmosphereConfig config)Configure an AtmosphereFramework object.protected <T,U extends T>
voidfieldInjectionException(java.lang.reflect.Field field, U instance, java.lang.Class<T> clazz, java.lang.Exception ex)<U> UgetInjectable(java.lang.Class<U> u)Use this method to retrieve availableInjectable.<T> Tinject(T instance)ApplyInjectableandInjectIntrospectorto a class already constructed.<U> voidinjectFields(java.util.Set<java.lang.reflect.Field> fields, U instance, AtmosphereFramework framework, java.util.LinkedList<Injectable<?>> injectable)<U> voidinjectInjectable(U instance, java.lang.Class<? extends U> defaultType, AtmosphereFramework framework)protected voidinjectionFailed()InjectableObjectFactorylistener(InjectionListener i)protected <T,U extends T>
voidmethodInjectionException(java.lang.reflect.Method m, U instance, java.lang.Class<T> clazz, java.lang.Exception ex)booleanneedRequestScoped(java.lang.Class defaultType)<T,U extends T>
UnewClassInstance(java.lang.Class<T> classType, java.lang.Class<U> defaultType)Delegate the creation of Object to the underlying object provider like Spring, Guice, etc.protected <T,U extends T>
voidnullFieldInjectionFor(java.lang.reflect.Field field, U instance, java.lang.Class<T> clazz)protected <T,U extends T>
voidpostFieldInjection(java.lang.reflect.Field field, U instance, java.lang.Class<T> clazz)protected <T,U extends T>
voidpostMethodInjection(java.lang.reflect.Method method, U instance, java.lang.Class<T> clazz)protected <T,U extends T>
voidpreFieldInjection(java.lang.reflect.Field field, U instance, java.lang.Class<T> clazz)protected <T,U extends T>
voidpreMethodInjection(java.lang.reflect.Method method, U instance, java.lang.Class<T> clazz)voidrequestScoped(java.lang.Object instance, java.lang.Class defaultType)voidrequestScoped(java.lang.Object instance, java.lang.Class defaultType, AtmosphereResource r)protected voidretryInjection(AtmosphereFramework framework)java.lang.StringtoString()
-
-
-
Method Detail
-
configure
public void configure(AtmosphereConfig config)
Description copied from interface:AtmosphereConfigAwareConfigure an AtmosphereFramework object.- Specified by:
configurein interfaceAtmosphereConfigAware- Parameters:
config-AtmosphereConfig
-
retryInjection
protected void retryInjection(AtmosphereFramework framework)
-
newClassInstance
public <T,U extends T> U newClassInstance(java.lang.Class<T> classType, java.lang.Class<U> defaultType) throws java.lang.InstantiationException, java.lang.IllegalAccessExceptionDescription copied from interface:AtmosphereObjectFactoryDelegate the creation of Object to the underlying object provider like Spring, Guice, etc. When creating a class, it is important to check if the class can be configured via its implementation of theAtmosphereConfigAware.AtmosphereConfigAware.configure(AtmosphereConfig)should be called in that case.- Specified by:
newClassInstancein interfaceAtmosphereObjectFactory<Injectable<?>>- Parameters:
classType- The class' type to be createddefaultType- a class to be created @return an instance of T- Throws:
java.lang.InstantiationExceptionjava.lang.IllegalAccessException
-
inject
public <T> T inject(T instance) throws java.lang.InstantiationException, java.lang.IllegalAccessExceptionApplyInjectableandInjectIntrospectorto a class already constructed.- Parameters:
instance- the instance to inject to.- Returns:
- Throws:
java.lang.InstantiationExceptionjava.lang.IllegalAccessException
-
applyMethods
public <U> void applyMethods(U instance, java.lang.Class<U> defaultType) throws java.lang.IllegalAccessException- Type Parameters:
U-- Parameters:
instance- the requested object.defaultType- the type of the requested object- Throws:
java.lang.IllegalAccessException
-
injectInjectable
public <U> void injectInjectable(U instance, java.lang.Class<? extends U> defaultType, AtmosphereFramework framework) throws java.lang.IllegalAccessException- Type Parameters:
U-- Parameters:
instance- the requested object.defaultType- the type of the requested objectframework- theAtmosphereFramework- Throws:
java.lang.IllegalAccessException
-
injectFields
public <U> void injectFields(java.util.Set<java.lang.reflect.Field> fields, U instance, AtmosphereFramework framework, java.util.LinkedList<Injectable<?>> injectable) throws java.lang.IllegalAccessException- Throws:
java.lang.IllegalAccessException
-
allowInjectionOf
public AtmosphereObjectFactory allowInjectionOf(Injectable<?> injectable)
Description copied from interface:AtmosphereObjectFactoryPass information to the underlying Dependency Injection Implementation- Specified by:
allowInjectionOfin interfaceAtmosphereObjectFactory<Injectable<?>>- Parameters:
injectable- an Z- Returns:
- this
-
allowInjectionOf
public AtmosphereObjectFactory allowInjectionOf(Injectable<?> injectable, boolean first)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getInjectable
public <U> U getInjectable(java.lang.Class<U> u)
Use this method to retrieve availableInjectable. This method is for application that inject their ownInjectableand needs already constructed classes.- Type Parameters:
U- the type- Parameters:
u- the class- Returns:
- the class if exists, null if not
-
requestScoped
public void requestScoped(java.lang.Object instance, java.lang.Class defaultType, AtmosphereResource r) throws java.lang.IllegalAccessException- Throws:
java.lang.IllegalAccessException
-
requestScoped
public void requestScoped(java.lang.Object instance, java.lang.Class defaultType) throws java.lang.IllegalAccessException- Throws:
java.lang.IllegalAccessException
-
needRequestScoped
public boolean needRequestScoped(java.lang.Class defaultType) throws java.lang.IllegalAccessException- Throws:
java.lang.IllegalAccessException
-
listener
public InjectableObjectFactory listener(InjectionListener i)
-
injectionFailed
protected void injectionFailed()
-
nullFieldInjectionFor
protected <T,U extends T> void nullFieldInjectionFor(java.lang.reflect.Field field, U instance, java.lang.Class<T> clazz)
-
fieldInjectionException
protected <T,U extends T> void fieldInjectionException(java.lang.reflect.Field field, U instance, java.lang.Class<T> clazz, java.lang.Exception ex)
-
methodInjectionException
protected <T,U extends T> void methodInjectionException(java.lang.reflect.Method m, U instance, java.lang.Class<T> clazz, java.lang.Exception ex)
-
preFieldInjection
protected <T,U extends T> void preFieldInjection(java.lang.reflect.Field field, U instance, java.lang.Class<T> clazz)
-
postFieldInjection
protected <T,U extends T> void postFieldInjection(java.lang.reflect.Field field, U instance, java.lang.Class<T> clazz)
-
preMethodInjection
protected <T,U extends T> void preMethodInjection(java.lang.reflect.Method method, U instance, java.lang.Class<T> clazz)
-
postMethodInjection
protected <T,U extends T> void postMethodInjection(java.lang.reflect.Method method, U instance, java.lang.Class<T> clazz)
-
-