Class Context

java.lang.Object
org.apache.juneau.Context
Direct Known Subclasses:
BeanContext, BeanContextable, Config, ConfigStore, RestContext, RestOpContext

public abstract class Context extends Object
Base class for all Context beans.

Context beans follow the convention of havinTg the following parts:

  • A Context.Builder class 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 ContextSession class for doing work.
    • This bean is non-thread-safe and meant for one-time use.
    Notes:
    • This class is thread safe and reusable.
  • Field Details

  • Constructor Details

    • Context

      protected Context(Context.Builder builder)
      Constructor for this class.
      Parameters:
      builder - The builder for this class.
      Cannot be null.
    • Context

      protected Context(Context copyFrom)
      Copy constructor.
      Parameters:
      copyFrom - The context to copy from.
  • Method Details

    • createBuilder

      public static Context.Builder createBuilder(Class<? extends Context> type)
      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.
    • 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.
    • getAnnotationProvider

      Returns the annotation provider for this context.
      Returns:
      The annotation provider for this context.
    • 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

      public boolean isDebug()
      Debug mode.
      Returns:
      true if debug mode is enabled.
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • init

      protected void init(Context.Builder builder)
      Perform optional initialization on builder before it is used.

      Default behavior is a no-op.

      Parameters:
      builder - The builder to initialize.
    • properties

      Returns the properties on this bean as a map for debugging.
      Returns:
      The properties on this bean as a map for debugging.