Class ScopedObjectHolder<T>

java.lang.Object
org.concordion.api.ScopedObjectHolder<T>
Type Parameters:
T - type of wrapped object

public abstract class ScopedObjectHolder<T> extends Object
A factory and holder for objects that are to have their scope managed by Concordion.

When the get() method is invoked, the wrapped object is lazily constructed by calling the create() method.

When annotated with ConcordionScoped, the scope will be managed by Concordion and the object destroyed when it goes out of scope.

For example:

 @ConcordionScoped(Scope.SPECIFICATION)
 private ScopedObjectHolder<Browser> browserHolder = new ScopedObjectHolder<Browser>() {
     @Override
     protected Browser create() {
         return new Browser();
     }

     @Override
     protected void destroy(Browser browser) {
         browser.close();
     };
 };
 

The browser will be constructed in the first method that calls browserHolder.get().

The browser will be destroyed when the specification completes.

Since:
2.0.0
  • Constructor Details

    • ScopedObjectHolder

      public ScopedObjectHolder()
  • Method Details

    • create

      protected abstract T create()
    • destroy

      protected void destroy(T t)
    • get

      public T get()
      Return the value of the variable. Uses lazy initialisation to call the create() method (implemented safely for Java 5.0+, see http://www.oracle.com/technetwork/articles/javase/bloch-effective-08-qa-140880.html).
      Returns:
      value of scoped variable
    • isCreated

      public boolean isCreated()
      Returns a value that indicates whether the current scoped object has been created.
      Returns:
      true if the scoped object has been created (by calling get()), false otherwise.