Package org.apache.juneau
Class Context
java.lang.Object
org.apache.juneau.Context
- All Implemented Interfaces:
- AnnotationProvider
- Direct Known Subclasses:
- BeanContext,- BeanContextable,- Config,- ConfigStore,- RestContext,- RestOpContext
Base class for all Context beans.
 
Context beans follow the convention of havinTg the following parts:
- A Context.Builderclass for configuring the context bean.- This bean is non-thread-safe and meant for one-time use.
 
- A Context(Builder)constructor that takes in a builder object.- This bean is thread-safe and cacheable/reusable.
 
- A ContextSessionclass for doing work.- This bean is non-thread-safe and meant for one-time use.
 Notes:- This class is thread safe and reusable.
 See Also:
- 
Nested Class SummaryNested Classes
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final Predicate<AnnotationInfo<?>>Predicate for annotations that themselves are annotated withContextApply.Fields inherited from interface org.apache.juneau.AnnotationProviderDEFAULT, DISABLE_ANNOTATION_CACHING
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedCopy constructor.protectedContext(Context.Builder builder) Constructor for this class.
- 
Method SummaryModifier and TypeMethodDescriptioncopy()Creates a builder from this context object.static Context.BuildercreateBuilder(Class<? extends Context> type) Instantiates a builder of the specified context class.Create a session builder based on the properties defined on this context.<A extends Annotation>
 AfirstAnnotation(Class<A> type, Class<?> onClass, Predicate<A> filter) Finds the first matching annotation on the specified class.<A extends Annotation>
 AfirstAnnotation(Class<A> type, Constructor<?> onConstructor, Predicate<A> filter) Finds the first matching annotation on the specified constructor.<A extends Annotation>
 AfirstAnnotation(Class<A> type, Field onField, Predicate<A> filter) Finds the first matching annotation on the specified field.<A extends Annotation>
 AfirstAnnotation(Class<A> type, Method onMethod, Predicate<A> filter) Finds the first matching annotation on the specified method.<A extends Annotation>
 AfirstDeclaredAnnotation(Class<A> type, Class<?> onClass, Predicate<A> filter) Finds the first matching declared annotations on the specified class.<A extends Annotation>
 voidforEachAnnotation(Class<A> type, Class<?> onClass, Predicate<A> filter, Consumer<A> action) Performs an action on the matching annotations on the specified class.<A extends Annotation>
 voidforEachAnnotation(Class<A> type, Constructor<?> onConstructor, Predicate<A> filter, Consumer<A> action) Performs an action on the matching annotations on the specified constructor.<A extends Annotation>
 voidforEachAnnotation(Class<A> type, Field onField, Predicate<A> filter, Consumer<A> action) Performs an action on the matching annotations on the specified field.<A extends Annotation>
 voidforEachAnnotation(Class<A> type, Method onMethod, Predicate<A> filter, Consumer<A> action) Performs an action on the matching annotations on the specified method.<A extends Annotation>
 voidforEachDeclaredAnnotation(Class<A> type, Class<?> onClass, Predicate<A> filter, Consumer<A> action) Performs an action on the matching declared annotations on the specified class.Returns a session to use for this context.<A extends Annotation>
 booleanhasAnnotation(Class<A> type, Class<?> onClass) Returnstrue ifgetAnnotation(a,c) returns a non-null value.<A extends Annotation>
 booleanhasAnnotation(Class<A> type, Constructor<?> onConstructor) Returnstrue ifgetAnnotation(a,c) returns a non-null value.<A extends Annotation>
 booleanhasAnnotation(Class<A> type, Field onField) Returnstrue ifgetAnnotation(a,f) returns a non-null value.<A extends Annotation>
 booleanhasAnnotation(Class<A> type, Method onMethod) Returnstrue ifgetAnnotation(a,m) returns a non-null value.protected voidinit(Context.Builder builder) Perform optional initialization on builder before it is used.booleanisDebug()Debug mode.<A extends Annotation>
 AlastAnnotation(Class<A> type, Class<?> onClass, Predicate<A> filter) Finds the last matching annotation on the specified class.<A extends Annotation>
 AlastAnnotation(Class<A> type, Constructor<?> onConstructor, Predicate<A> filter) Finds the last matching annotation on the specified constructor.<A extends Annotation>
 AlastAnnotation(Class<A> type, Field onField, Predicate<A> filter) Finds the last matching annotation on the specified field.<A extends Annotation>
 AlastAnnotation(Class<A> type, Method onMethod, Predicate<A> filter) Finds the last matching annotation on the specified method.<A extends Annotation>
 AlastDeclaredAnnotation(Class<A> type, Class<?> onClass, Predicate<A> filter) Finds the last matching declared annotations on the specified class.protected JsonMapReturns the properties on this bean as a map for debugging.toString()
- 
Field Details- 
CONTEXT_APPLY_FILTERPredicate for annotations that themselves are annotated withContextApply.
 
- 
- 
Constructor Details- 
ContextCopy constructor.- Parameters:
- copyFrom- The context to copy from.
 
- 
ContextConstructor for this class.- Parameters:
- builder- The builder for this class.
 
 
- 
- 
Method Details- 
createBuilderInstantiates a builder of the specified context class.Looks for a public static method called create that returns an object that can be passed into a public or protected constructor of the class.- Parameters:
- type- The builder to create.
- Returns:
- A new builder.
 
- 
initPerform optional initialization on builder before it is used.Default behavior is a no-op. - Parameters:
- builder- The builder to initialize.
 
- 
copyCreates a builder from this context object.Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations. - Returns:
- A new Builder object.
 
- 
createSessionCreate a session builder based on the properties defined on this context.Use this method for creating sessions where you want to override basic settings. Otherwise, use getSession()directly.- Returns:
- A new session builder.
 
- 
getSessionReturns a session to use for this context.Note that subclasses may opt to return a reusable non-modifiable session. - Returns:
- A new session object.
 
- 
isDebugDebug mode.- Returns:
- true if debug mode is enabled.
- See Also:
 
- 
forEachAnnotationpublic <A extends Annotation> void forEachAnnotation(Class<A> type, Class<?> onClass, Predicate<A> filter, Consumer<A> action) Description copied from interface:AnnotationProviderPerforms an action on the matching annotations on the specified class.- Specified by:
- forEachAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onClass- The class to search on.
- filter- A predicate to apply to the entries to determine if action should be performed. Can be- null .
- action- An action to perform on the entry.
 
- 
firstAnnotationpublic <A extends Annotation> A firstAnnotation(Class<A> type, Class<?> onClass, Predicate<A> filter) Description copied from interface:AnnotationProviderFinds the first matching annotation on the specified class.- Specified by:
- firstAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onClass- The class to search on.
- filter- A predicate to apply to the entries to determine if value should be used. Can be- null .
- Returns:
- The matched annotation, or null if not found.
 
- 
lastAnnotationpublic <A extends Annotation> A lastAnnotation(Class<A> type, Class<?> onClass, Predicate<A> filter) Description copied from interface:AnnotationProviderFinds the last matching annotation on the specified class.- Specified by:
- lastAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onClass- The class to search on.
- filter- A predicate to apply to the entries to determine if value should be used. Can be- null .
- Returns:
- The matched annotation, or null if not found.
 
- 
forEachDeclaredAnnotationpublic <A extends Annotation> void forEachDeclaredAnnotation(Class<A> type, Class<?> onClass, Predicate<A> filter, Consumer<A> action) Description copied from interface:AnnotationProviderPerforms an action on the matching declared annotations on the specified class.- Specified by:
- forEachDeclaredAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onClass- The class to search on.
- filter- A predicate to apply to the entries to determine if action should be performed. Can be- null .
- action- An action to perform on the entry.
 
- 
firstDeclaredAnnotationpublic <A extends Annotation> A firstDeclaredAnnotation(Class<A> type, Class<?> onClass, Predicate<A> filter) Description copied from interface:AnnotationProviderFinds the first matching declared annotations on the specified class.- Specified by:
- firstDeclaredAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onClass- The class to search on.
- filter- A predicate to apply to the entries to determine if value should be used. Can be- null .
- Returns:
- The matched annotation, or null if no annotations matched.
 
- 
lastDeclaredAnnotationpublic <A extends Annotation> A lastDeclaredAnnotation(Class<A> type, Class<?> onClass, Predicate<A> filter) Description copied from interface:AnnotationProviderFinds the last matching declared annotations on the specified class.- Specified by:
- lastDeclaredAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onClass- The class to search on.
- filter- A predicate to apply to the entries to determine if value should be used. Can be- null .
- Returns:
- The matched annotation, or null if no annotations matched.
 
- 
forEachAnnotationpublic <A extends Annotation> void forEachAnnotation(Class<A> type, Method onMethod, Predicate<A> filter, Consumer<A> action) Description copied from interface:AnnotationProviderPerforms an action on the matching annotations on the specified method.- Specified by:
- forEachAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onMethod- The method to search on.
- filter- A predicate to apply to the entries to determine if action should be performed. Can be- null .
- action- An action to perform on the entry.
 
- 
firstAnnotationpublic <A extends Annotation> A firstAnnotation(Class<A> type, Method onMethod, Predicate<A> filter) Description copied from interface:AnnotationProviderFinds the first matching annotation on the specified method.- Specified by:
- firstAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onMethod- The method to search on.
- filter- A predicate to apply to the entries to determine if value should be used. Can be- null .
- Returns:
- The matched annotation, or null if no annotations matched.
 
- 
lastAnnotationDescription copied from interface:AnnotationProviderFinds the last matching annotation on the specified method.- Specified by:
- lastAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onMethod- The method to search on.
- filter- A predicate to apply to the entries to determine if value should be used. Can be- null .
- Returns:
- The matched annotation, or null if no annotations matched.
 
- 
forEachAnnotationpublic <A extends Annotation> void forEachAnnotation(Class<A> type, Field onField, Predicate<A> filter, Consumer<A> action) Description copied from interface:AnnotationProviderPerforms an action on the matching annotations on the specified field.- Specified by:
- forEachAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onField- The field to search on.
- filter- A predicate to apply to the entries to determine if action should be performed. Can be- null .
- action- An action to perform on the entry.
 
- 
firstAnnotationDescription copied from interface:AnnotationProviderFinds the first matching annotation on the specified field.- Specified by:
- firstAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onField- The field to search on.
- filter- A predicate to apply to the entries to determine if value should be used. Can be- null .
- Returns:
- The matched annotation, or null if no annotations matched.
 
- 
lastAnnotationDescription copied from interface:AnnotationProviderFinds the last matching annotation on the specified field.- Specified by:
- lastAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onField- The field to search on.
- filter- A predicate to apply to the entries to determine if value should be used. Can be- null .
- Returns:
- The matched annotation, or null if no annotations matched.
 
- 
forEachAnnotationpublic <A extends Annotation> void forEachAnnotation(Class<A> type, Constructor<?> onConstructor, Predicate<A> filter, Consumer<A> action) Description copied from interface:AnnotationProviderPerforms an action on the matching annotations on the specified constructor.- Specified by:
- forEachAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onConstructor- The constructor to search on.
- filter- A predicate to apply to the entries to determine if action should be performed. Can be- null .
- action- An action to perform on the entry.
 
- 
firstAnnotationpublic <A extends Annotation> A firstAnnotation(Class<A> type, Constructor<?> onConstructor, Predicate<A> filter) Description copied from interface:AnnotationProviderFinds the first matching annotation on the specified constructor.- Specified by:
- firstAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onConstructor- The constructor to search on.
- filter- A predicate to apply to the entries to determine if value should be used. Can be- null .
- Returns:
- The matched annotation, or null if no annotations matched.
 
- 
lastAnnotationpublic <A extends Annotation> A lastAnnotation(Class<A> type, Constructor<?> onConstructor, Predicate<A> filter) Description copied from interface:AnnotationProviderFinds the last matching annotation on the specified constructor.- Specified by:
- lastAnnotationin interface- AnnotationProvider
- Type Parameters:
- A- The annotation type to find.
- Parameters:
- type- The annotation type to find.
- onConstructor- The constructor to search on.
- filter- A predicate to apply to the entries to determine if value should be used. Can be- null .
- Returns:
- The matched annotation, or null if no annotations matched.
 
- 
hasAnnotationReturnstrue ifgetAnnotation(a,c) returns a non-null value.- Type Parameters:
- A- The annotation being checked for.
- Parameters:
- type- The annotation being checked for.
- onClass- The class being checked on.
- Returns:
- true if the annotation exists on the specified class.
 
- 
hasAnnotationReturnstrue ifgetAnnotation(a,m) returns a non-null value.- Type Parameters:
- A- The annotation being checked for.
- Parameters:
- type- The annotation being checked for.
- onMethod- The method being checked on.
- Returns:
- true if the annotation exists on the specified method.
 
- 
hasAnnotationReturnstrue ifgetAnnotation(a,f) returns a non-null value.- Type Parameters:
- A- The annotation being checked for.
- Parameters:
- type- The annotation being checked for.
- onField- The field being checked on.
- Returns:
- true if the annotation exists on the specified field.
 
- 
hasAnnotationReturnstrue ifgetAnnotation(a,c) returns a non-null value.- Type Parameters:
- A- The annotation being checked for.
- Parameters:
- type- The annotation being checked for.
- onConstructor- The constructor being checked on.
- Returns:
- true if the annotation exists on the specified field.
 
- 
propertiesReturns the properties on this bean as a map for debugging.- Returns:
- The properties on this bean as a map for debugging.
 
- 
toString
 
-