Class MemoryStore.Builder

Enclosing class:
MemoryStore

public static class MemoryStore.Builder extends ConfigStore.Builder
Builder class.
  • Constructor Details

    • Builder

      protected Builder()
      Constructor, default settings.
    • Builder

      protected Builder(MemoryStore copyFrom)
      Copy constructor.
      Parameters:
      copyFrom - The bean to copy from.
    • Builder

      protected Builder(MemoryStore.Builder copyFrom)
      Copy constructor.
      Parameters:
      copyFrom - The builder to copy from.
  • Method Details

    • copy

      Description copied from class: Context.Builder
      Copy creator.
      Specified by:
      copy in class ConfigStore.Builder
      Returns:
      A new mutable copy of this builder.
    • build

      public MemoryStore build()
      Description copied from class: Context.Builder
      Build the object.
      Overrides:
      build in class Context.Builder
      Returns:
      The built object.
    • annotations

      Description copied from class: Context.Builder
      Defines annotations to apply to specific classes and methods.

      Allows you to dynamically apply Juneau annotations typically applied directly to classes and methods. Useful in cases where you want to use the functionality of the annotation on beans and bean properties but do not have access to the code to do so.

      As a rule, any Juneau annotation with an on() method can be used with this setting.

      The following example shows the equivalent methods for applying the @Bean annotation:

      // Class with explicit annotation. @Bean(properties="street,city,state") public class A {...} // Class with annotation applied via @BeanConfig public class B {...} // Java REST method with @BeanConfig annotation. @RestGet(...) @Bean(on="B", properties="street,city,state") public void doFoo() {...}

      In general, the underlying framework uses this method when it finds dynamically applied annotations on config annotations. However, concrete implementations of annotations are also provided that can be passed directly into builder classes like so:

      // Create a concrete @Bean annotation. Bean annotation = BeanAnnotation.create(B.class).properties("street,city,state").build(); // Apply it to a serializer. WriterSerializer serializer = JsonSerializer.create().annotations(annotation).build(); // Serialize a bean with the dynamically applied annotation. String json = serializer.serialize(new B());

      The following is the list of annotations builders provided that can be constructed and passed into the builder class:

      The syntax for the on() pattern match parameter depends on whether it applies to a class, method, field, or constructor. The valid pattern matches are:

      • Classes:
        • Fully qualified:
          • "com.foo.MyClass"
        • Fully qualified inner class:
          • "com.foo.MyClass$Inner1$Inner2"
        • Simple:
          • "MyClass"
        • Simple inner:
          • "MyClass$Inner1$Inner2"
          • "Inner1$Inner2"
          • "Inner2"
      • Methods:
        • Fully qualified with args:
          • "com.foo.MyClass.myMethod(String,int)"
          • "com.foo.MyClass.myMethod(java.lang.String,int)"
          • "com.foo.MyClass.myMethod()"
        • Fully qualified:
          • "com.foo.MyClass.myMethod"
        • Simple with args:
          • "MyClass.myMethod(String,int)"
          • "MyClass.myMethod(java.lang.String,int)"
          • "MyClass.myMethod()"
        • Simple:
          • "MyClass.myMethod"
        • Simple inner class:
          • "MyClass$Inner1$Inner2.myMethod"
          • "Inner1$Inner2.myMethod"
          • "Inner2.myMethod"
      • Fields:
        • Fully qualified:
          • "com.foo.MyClass.myField"
        • Simple:
          • "MyClass.myField"
        • Simple inner class:
          • "MyClass$Inner1$Inner2.myField"
          • "Inner1$Inner2.myField"
          • "Inner2.myField"
      • Constructors:
        • Fully qualified with args:
          • "com.foo.MyClass(String,int)"
          • "com.foo.MyClass(java.lang.String,int)"
          • "com.foo.MyClass()"
        • Simple with args:
          • "MyClass(String,int)"
          • "MyClass(java.lang.String,int)"
          • "MyClass()"
        • Simple inner class:
          • "MyClass$Inner1$Inner2()"
          • "Inner1$Inner2()"
          • "Inner2()"
      • A comma-delimited list of anything on this list.
      See Also:
      Overrides:
      annotations in class ConfigStore.Builder
      Parameters:
      values - The annotations to register with the context.
      Returns:
      This object.
    • apply

      Description copied from class: Context.Builder
      Applies a set of applied to this builder.

      An AnnotationWork consists of a single pair of AnnotationInfo that represents an annotation instance, and AnnotationApplier which represents the code used to apply the values in that annotation to a specific builder.

      Example:

      // A class annotated with a config annotation. @BeanConfig(sortProperties="$S{sortProperties,false}") public class MyClass {...} // Find all annotations that themselves are annotated with @ContextPropertiesApply. AnnotationList annotations = ClassInfo.of(MyClass.class).getAnnotationList(CONTEXT_APPLY_FILTER); VarResolverSession vrs = VarResolver.DEFAULT.createSession(); AnnotationWorkList work = AnnotationWorkList.of(vrs, annotations); // Apply any settings found on the annotations. WriterSerializer serializer = JsonSerializer .create() .apply(work) .build();

      Overrides:
      apply in class ConfigStore.Builder
      Parameters:
      work - The list of annotations and appliers to apply to this builder.
      Returns:
      This object.
    • applyAnnotations

      public MemoryStore.Builder applyAnnotations(Class<?>... fromClasses)
      Description copied from class: Context.Builder
      Applies any of the various @XConfig annotations on the specified class to this context.

      Any annotations found that themselves are annotated with ContextApply will be resolved and applied as properties to this builder. These annotations include:

      Annotations on classes are appended in the following order:

      1. On the package of this class.
      2. On interfaces ordered parent-to-child.
      3. On parent classes ordered parent-to-child.
      4. On this class.

      The default var resolver VarResolver.DEFAULT is used to resolve any variables in annotation field values.

      Example:

      // A class annotated with a config annotation. @BeanConfig(sortProperties="$S{sortProperties,false}") public class MyClass {...} // Apply any settings found on the annotations. WriterSerializer serializer = JsonSerializer .create() .applyAnnotations(MyClass.class) .build();

      Overrides:
      applyAnnotations in class ConfigStore.Builder
      Parameters:
      fromClasses - The classes on which the annotations are defined.
      Returns:
      This object.
    • applyAnnotations

      public MemoryStore.Builder applyAnnotations(Method... fromMethods)
      Description copied from class: Context.Builder
      Applies any of the various @XConfig annotations on the specified method to this context.

      Any annotations found that themselves are annotated with ContextApply will be resolved and applied as properties to this builder. These annotations include:

      Annotations on methods are appended in the following order:

      1. On the package of the method class.
      2. On interfaces ordered parent-to-child.
      3. On parent classes ordered parent-to-child.
      4. On the method class.
      5. On this method and matching methods ordered parent-to-child.

      The default var resolver VarResolver.DEFAULT is used to resolve any variables in annotation field values.

      Example:

      // A method annotated with a config annotation. public class MyClass { @BeanConfig(sortProperties="$S{sortProperties,false}") public void myMethod() {...} } // Apply any settings found on the annotations. WriterSerializer serializer = JsonSerializer .create() .applyAnnotations(MyClass.class.getMethod("myMethod")) .build();

      Overrides:
      applyAnnotations in class ConfigStore.Builder
      Parameters:
      fromMethods - The methods on which the annotations are defined.
      Returns:
      This object.
    • cache

      public MemoryStore.Builder cache(Cache<HashKey,? extends Context> value)
      Description copied from class: Context.Builder
      Specifies a cache to use for hashkey-based caching.
      Overrides:
      cache in class ConfigStore.Builder
      Parameters:
      value - The cache.
      Returns:
      This object.
    • debug

      Description copied from class: Context.Builder
      Context configuration property:  Debug mode.

      Enables the following additional information during serialization:

      Enables the following additional information during parsing:

      • When bean setters throws exceptions, the exception includes the object stack information in order to determine how that method was invoked.
      Example:

      // Create a serializer with debug enabled. WriterSerializer serializer = JsonSerializer .create() .debug() .build(); // Create a POJO model with a recursive loop. public class MyBean { public Object f; } MyBean bean = new MyBean(); bean.f = bean; // Throws a SerializeException and not a StackOverflowError String json = serializer.serialize(bean);

      See Also:
      Overrides:
      debug in class ConfigStore.Builder
      Returns:
      This object.
    • debug

      public MemoryStore.Builder debug(boolean value)
      Description copied from class: Context.Builder
      Same as Context.Builder.debug() but allows you to explicitly specify the value.
      Overrides:
      debug in class ConfigStore.Builder
      Parameters:
      value - The value for this setting.
      Returns:
      This object.
    • impl

      Description copied from class: Context.Builder
      Specifies a pre-instantiated bean for the Context.Builder.build() method to return.
      Overrides:
      impl in class ConfigStore.Builder
      Parameters:
      value - The value for this setting.
      Returns:
      This object.
    • type

      public MemoryStore.Builder type(Class<? extends Context> value)
      Description copied from class: Context.Builder
      Associates a context class with this builder.

      This is the type of object that this builder creates when the Context.Builder.build() method is called.

      By default, it's the outer class of where the builder class is defined.

      Overrides:
      type in class ConfigStore.Builder
      Parameters:
      value - The context class that this builder should create.
      Returns:
      This object.