Package io.milton.context
Class RequestContext
- java.lang.Object
-
- io.milton.context.Context
-
- io.milton.context.RequestContext
-
- All Implemented Interfaces:
Contextual,RemovalCallback
public class RequestContext extends Context implements RemovalCallback
-
-
Field Summary
-
Fields inherited from class io.milton.context.Context
itemByClass, itemByName
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> TC(Class<T> c)For convenience, equivalent to RequestContext.getCurrent().get(c) This method assumes that the requested class is required and will throw an exception if it is not foundstatic <T> TC(Class<T> c, boolean required)For convenience, equivalent to RequestContext.getCurrent().get(c) Returns the object in context of the given type or null if not found and required is false.static RequestContextgetCurrent()static RequestContextgetInstance(RootContext parent)protected RegistrationgetOrCreateRegistration(Class c, Context context)protected RegistrationgetRegistration(Class c)protected RegistrationgetRegistration(String id)RootContextgetRootContext()voidonRemove(Object item)Called when this request context goes out of context.static RequestContextpeekInstance()
-
-
-
Method Detail
-
C
public static <T> T C(Class<T> c) throws ClassNotInContextException
For convenience, equivalent to RequestContext.getCurrent().get(c) This method assumes that the requested class is required and will throw an exception if it is not found- Type Parameters:
T- - the type expected to be returned- Parameters:
c- - the class to- Returns:
- - an object of the given type
- Throws:
ClassNotInContextException
-
C
public static <T> T C(Class<T> c, boolean required) throws ClassNotInContextException
For convenience, equivalent to RequestContext.getCurrent().get(c) Returns the object in context of the given type or null if not found and required is false.- Type Parameters:
T-- Parameters:
c-required- - if true will throw an exception if the requested class is not found. Otherwise will return null.- Returns:
- - an object of the given type
- Throws:
ClassNotInContextException
-
getCurrent
public static RequestContext getCurrent()
-
getInstance
public static RequestContext getInstance(RootContext parent)
-
peekInstance
public static RequestContext peekInstance()
-
getRootContext
public RootContext getRootContext()
-
getRegistration
protected Registration getRegistration(Class c)
- Overrides:
getRegistrationin classContext
-
getRegistration
protected Registration getRegistration(String id)
- Overrides:
getRegistrationin classContext
-
getOrCreateRegistration
protected Registration getOrCreateRegistration(Class c, Context context)
-
onRemove
public void onRemove(Object item)
Called when this request context goes out of context. Should shutdown all of its contents- Specified by:
onRemovein interfaceRemovalCallback
-
-