Class BrowserLocal<T>

java.lang.Object
org.jboss.arquillian.graphene.context.BrowserLocal<T>

public class BrowserLocal<T> extends Object
This class provides browser-local variables. These variables differ from their normal counterparts in that each browser context that accesses one (via its get or set method) has its own, independently initialized copy of the variable. BrowserLocal instances are typically private static fields in classes that wish to associate state with a browser context.
Author:
Jan Papousek
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    get()
    Returns the value in the current browser context's copy of this browser-local variable.
    Returns the value in the last browser context's copy of this browser-local variable.
    protected T
    Returns the current browser context's "initial value" for this browser-local variable.
    void
    Removes the current browser context's value for this browser-local variable.
    void
    set(T value)
    Sets the current browser context's copy of this browser-local variable to the specified value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BrowserLocal

      public BrowserLocal()
  • Method Details

    • get

      public T get()
      Returns the value in the current browser context's copy of this browser-local variable. If the variable has no value for the current browser context, it is first initialized to the value returned by an invocation of the initialValue() method.
      Returns:
      the current browser context's value of this browser-local
      Throws:
      IllegalStateException - if there is no active browser context
    • getLast

      public T getLast()
      Returns the value in the last browser context's copy of this browser-local variable. If the variable has no value for the last browser context, it is first initialized to the value returned by an invocation of the initialValue() method.

      If the last browser context is not available, null is returned.

      Returns:
      the last browser context's value of this browser-local
    • initialValue

      protected T initialValue()
      Returns the current browser context's "initial value" for this browser-local variable. This method will be invoked the first time a browser context accesses the variable with the get() method, unless the browser context previously invoked the set(T) method, in which case the initialValue method will not be invoked for the browser context. Normally, this method is invoked at most once per browser context, but it may be invoked again in case of subsequent invocations of remove() followed by get().

      This implementation simply returns null; if the programmer desires browser-local variables to have an initial value other than null, BrowserLocal must be subclassed, and this method overridden. Typically, an anonymous inner class will be used.

      Returns:
      the initial value for this browser-local
    • remove

      public void remove()
      Removes the current browser context's value for this browser-local variable. If this browser-local variable is subsequently read by the current browser context, its value will be reinitialized by invoking its initialValue() method, unless its value is set by the current browser context in the interim. This may result in multiple invocations of the initialValue method in the current browser context.
      Throws:
      IllegalStateException - if there is no active browser context
    • set

      public void set(T value)
      Sets the current browser context's copy of this browser-local variable to the specified value. Most subclasses will have no need to override this method, relying solely on the initialValue() method to set the values of browser-locals.
      Parameters:
      value - the value to be stored in the current browser context's copy of this browser-local.
      Throws:
      IllegalStateException - if there is no active browser context