/** * 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 {@link #initialValue} * method to set the values of browser-locals. * * @param 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 */ public void set(T value) { BrowserActions.currentBrowserActions().browserLocals.put(this, 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 {@link #initialValue} * method to set the values of browser-locals. * * @param 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 */ public void set(T value) { BrowserActions.currentBrowserActions().browserLocals.put(this, value); }
/** * Removes the current browser context's value for this browser-local * variable. If this browser-local variable is subsequently * {@linkplain #get read} by the current browser context, its value will be * reinitialized by invoking its {@link #initialValue} method, * unless its value is {@linkplain #set set} by the current browser context * in the interim. This may result in multiple invocations of the * <tt>initialValue</tt> method in the current browser context. * * @throws IllegalStateException if there is no active browser context */ public void remove() { BrowserActions.currentBrowserActions().browserLocals.remove(this); }
/** * Removes the current browser context's value for this browser-local * variable. If this browser-local variable is subsequently * {@linkplain #get read} by the current browser context, its value will be * reinitialized by invoking its {@link #initialValue} method, * unless its value is {@linkplain #set set} by the current browser context * in the interim. This may result in multiple invocations of the * <tt>initialValue</tt> method in the current browser context. * * @throws IllegalStateException if there is no active browser context */ public void remove() { BrowserActions.currentBrowserActions().browserLocals.remove(this); }
/** * 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 {@link #initialValue} method. * * @return the current browser context's value of this browser-local * @throws IllegalStateException if there is no active browser context */ public T get() { BrowserActions browser = BrowserActions.currentBrowserActions(); T result = (T) browser.browserLocals.get(this); if (result == null) { T init = initialValue(); if (init != null) { browser.browserLocals.put(this, init); return init; } } return result; }
/** * 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 {@link #initialValue} method. * * @return the current browser context's value of this browser-local * @throws IllegalStateException if there is no active browser context */ public T get() { BrowserActions browser = BrowserActions.currentBrowserActions(); T result = (T) browser.browserLocals.get(this); if (result == null) { T init = initialValue(); if (init != null) { browser.browserLocals.put(this, init); return init; } } return result; }
/** * Performs the given action in a context associated to this browser actions. * * @param <T> return type of the given action * @param action action to be invoked in the context * @return value returned by the given action * @throws Exception */ public <T> T performAction(Callable<T> action) throws Exception { if (currentBrowserActions.get() != null && currentBrowserActions.get() != this) { throw new IllegalStateException("There is an browser interleaving of " + currentBrowserActions().getName() + " and " + this.getName() + "."); } currentBrowserActions.set(this); lastBrowserActions.set(this); try { return action.call(); } finally { currentBrowserActions.set(null); } }
/** * Performs the given action in a context associated to this browser actions. * * @param <T> return type of the given action * @param action action to be invoked in the context * @return value returned by the given action * @throws Exception */ public <T> T performAction(Callable<T> action) throws Exception { if (currentBrowserActions.get() != null && currentBrowserActions.get() != this) { throw new IllegalStateException("There is an browser interleaving of " + currentBrowserActions().getName() + " and " + this.getName() + "."); } currentBrowserActions.set(this); lastBrowserActions.set(this); try { return action.call(); } finally { currentBrowserActions.set(null); } }