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 Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Predicate<AnnotationInfo<?>>Predicate for annotations that themselves are annotated withContextApply.Fields inherited from interface org.apache.juneau.AnnotationProvider
DEFAULT, DISABLE_ANNOTATION_CACHING -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCopy constructor.protectedContext(Context.Builder builder) Constructor for this class. -
Method Summary
Modifier 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_FILTER
Predicate for annotations that themselves are annotated withContextApply.
-
-
Constructor Details
-
Context
Copy constructor.- Parameters:
copyFrom- The context to copy from.
-
Context
Constructor for this class.- Parameters:
builder- The builder for this class.
-
-
Method Details
-
createBuilder
Instantiates 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.
-
init
Perform optional initialization on builder before it is used.Default behavior is a no-op.
- Parameters:
builder- The builder to initialize.
-
copy
Creates 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.
-
createSession
Create 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.
-
getSession
Returns a session to use for this context.Note that subclasses may opt to return a reusable non-modifiable session.
- Returns:
- A new session object.
-
isDebug
Debug mode.- Returns:
true if debug mode is enabled.- See Also:
-
forEachAnnotation
public <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 interfaceAnnotationProvider- 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 benull .action- An action to perform on the entry.
-
firstAnnotation
public <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 interfaceAnnotationProvider- 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 benull .- Returns:
- The matched annotation, or
null if not found.
-
lastAnnotation
public <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 interfaceAnnotationProvider- 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 benull .- Returns:
- The matched annotation, or
null if not found.
-
forEachDeclaredAnnotation
public <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 interfaceAnnotationProvider- 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 benull .action- An action to perform on the entry.
-
firstDeclaredAnnotation
public <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 interfaceAnnotationProvider- 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 benull .- Returns:
- The matched annotation, or
null if no annotations matched.
-
lastDeclaredAnnotation
public <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 interfaceAnnotationProvider- 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 benull .- Returns:
- The matched annotation, or
null if no annotations matched.
-
forEachAnnotation
public <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 interfaceAnnotationProvider- 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 benull .action- An action to perform on the entry.
-
firstAnnotation
public <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 interfaceAnnotationProvider- 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 benull .- Returns:
- The matched annotation, or
null if no annotations matched.
-
lastAnnotation
Description copied from interface:AnnotationProviderFinds the last matching annotation on the specified method.- Specified by:
lastAnnotationin interfaceAnnotationProvider- 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 benull .- Returns:
- The matched annotation, or
null if no annotations matched.
-
forEachAnnotation
public <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 interfaceAnnotationProvider- 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 benull .action- An action to perform on the entry.
-
firstAnnotation
Description copied from interface:AnnotationProviderFinds the first matching annotation on the specified field.- Specified by:
firstAnnotationin interfaceAnnotationProvider- 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 benull .- Returns:
- The matched annotation, or
null if no annotations matched.
-
lastAnnotation
Description copied from interface:AnnotationProviderFinds the last matching annotation on the specified field.- Specified by:
lastAnnotationin interfaceAnnotationProvider- 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 benull .- Returns:
- The matched annotation, or
null if no annotations matched.
-
forEachAnnotation
public <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 interfaceAnnotationProvider- 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 benull .action- An action to perform on the entry.
-
firstAnnotation
public <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 interfaceAnnotationProvider- 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 benull .- Returns:
- The matched annotation, or
null if no annotations matched.
-
lastAnnotation
public <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 interfaceAnnotationProvider- 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 benull .- Returns:
- The matched annotation, or
null if no annotations matched.
-
hasAnnotation
Returnstrue 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.
-
hasAnnotation
Returnstrue 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.
-
hasAnnotation
Returnstrue 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.
-
hasAnnotation
Returnstrue 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.
-
properties
Returns the properties on this bean as a map for debugging.- Returns:
- The properties on this bean as a map for debugging.
-
toString
-