You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/11/14 04:43:21 UTC
svn commit: r1034930 - in /click/trunk/click/framework/src/org/apache/click:
ActionEventDispatcher.java ControlRegistry.java
Author: sabob
Date: Sun Nov 14 03:43:21 2010
New Revision: 1034930
URL: http://svn.apache.org/viewvc?rev=1034930&view=rev
Log:
added hasThreadLocal methods and made access to instances public for easier customization
Modified:
click/trunk/click/framework/src/org/apache/click/ActionEventDispatcher.java
click/trunk/click/framework/src/org/apache/click/ControlRegistry.java
Modified: click/trunk/click/framework/src/org/apache/click/ActionEventDispatcher.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/ActionEventDispatcher.java?rev=1034930&r1=1034929&r2=1034930&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/ActionEventDispatcher.java (original)
+++ click/trunk/click/framework/src/org/apache/click/ActionEventDispatcher.java Sun Nov 14 03:43:21 2010
@@ -69,7 +69,7 @@ public class ActionEventDispatcher {
// Constants --------------------------------------------------------------
/** The thread local dispatcher holder. */
- private static final ThreadLocal<DispatcherStack> THREAD_LOCAL_DISPATCHER
+ private static final ThreadLocal<DispatcherStack> THREAD_LOCAL_DISPATCHER_STACK
= new ThreadLocal<DispatcherStack>();
// Variables --------------------------------------------------------------
@@ -129,6 +129,33 @@ public class ActionEventDispatcher {
}
/**
+ * Return the thread local ActionEventDispatcher instance.
+ *
+ * @return the thread local ActionEventDispatcher instance.
+ * @throws RuntimeException if an ActionEventDispatcher is not available on
+ * the thread
+ */
+ public static ActionEventDispatcher getThreadLocalDispatcher() {
+ return getDispatcherStack().peek();
+ }
+
+ /**
+ * Returns true if an ActionEventDispatcher instance is available on the
+ * current thread, false otherwise.
+ * <p/>
+ * Unlike {@link #getThreadLocalDispatcher()} this method can safely be used
+ * and will not throw an exception if an ActionEventDispatcher is not
+ * available on the current thread.
+ */
+ public static boolean hasThreadLocalDispatcher() {
+ DispatcherStack dispatcherStack = THREAD_LOCAL_DISPATCHER_STACK.get();
+ if (dispatcherStack == null) {
+ return false;
+ }
+ return !dispatcherStack.isEmpty();
+ }
+
+ /**
* Fire all the registered action events after the Page Controls have been
* processed and return true if the page should continue processing.
*
@@ -177,17 +204,6 @@ public class ActionEventDispatcher {
}
/**
- * Return the thread local dispatcher instance.
- *
- * @return the thread local dispatcher instance.
- * @throws RuntimeException if a ActionEventDispatcher is not available on the
- * thread
- */
- protected static ActionEventDispatcher getThreadLocalDispatcher() {
- return getDispatcherStack().peek();
- }
-
- /**
* Fire the actions for the given listener list and event source list which
* return true if the page should continue processing.
* <p/>
@@ -508,7 +524,7 @@ public class ActionEventDispatcher {
ActionEventDispatcher actionEventDispatcher = dispatcherStack.pop();
if (dispatcherStack.isEmpty()) {
- THREAD_LOCAL_DISPATCHER.set(null);
+ THREAD_LOCAL_DISPATCHER_STACK.set(null);
}
return actionEventDispatcher;
@@ -520,11 +536,11 @@ public class ActionEventDispatcher {
* @return stack data structure where ActionEventDispatcher are stored
*/
static DispatcherStack getDispatcherStack() {
- DispatcherStack dispatcherStack = THREAD_LOCAL_DISPATCHER.get();
+ DispatcherStack dispatcherStack = THREAD_LOCAL_DISPATCHER_STACK.get();
if (dispatcherStack == null) {
dispatcherStack = new DispatcherStack(2);
- THREAD_LOCAL_DISPATCHER.set(dispatcherStack);
+ THREAD_LOCAL_DISPATCHER_STACK.set(dispatcherStack);
}
return dispatcherStack;
Modified: click/trunk/click/framework/src/org/apache/click/ControlRegistry.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/ControlRegistry.java?rev=1034930&r1=1034929&r2=1034930&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/ControlRegistry.java (original)
+++ click/trunk/click/framework/src/org/apache/click/ControlRegistry.java Sun Nov 14 03:43:21 2010
@@ -95,7 +95,7 @@ public class ControlRegistry {
// Constants --------------------------------------------------------------
/** The thread local registry holder. */
- private static final ThreadLocal<RegistryStack> THREAD_LOCAL_REGISTRY =
+ private static final ThreadLocal<RegistryStack> THREAD_LOCAL_REGISTRY_STACK =
new ThreadLocal<RegistryStack>();
// Variables --------------------------------------------------------------
@@ -123,6 +123,33 @@ public class ControlRegistry {
// Public Methods ---------------------------------------------------------
/**
+ * Return the thread local ControlRegistry instance.
+ *
+ * @return the thread local ControlRegistry instance.
+ * @throws RuntimeException if a ControlRegistry is not available on the
+ * thread
+ */
+ public static ControlRegistry getThreadLocalRegistry() {
+ return getRegistryStack().peek();
+ }
+
+ /**
+ * Returns true if a ControlRegistry instance is available on the current
+ * thread, false otherwise.
+ * <p/>
+ * Unlike {@link #getThreadLocalRegistry()} this method can safely be used
+ * and will not throw an exception if a ControlRegistry is not available on
+ * the current thread.
+ */
+ public static boolean hasThreadLocalRegistry() {
+ RegistryStack registryStack = THREAD_LOCAL_REGISTRY_STACK.get();
+ if (registryStack == null) {
+ return false;
+ }
+ return !registryStack.isEmpty();
+ }
+
+ /**
* Register the control to be processed by the Click runtime if the control
* is the Ajax target. A control is an Ajax target if the
* {@link Control#isAjaxTarget(org.apache.click.Context)} method returns true.
@@ -322,10 +349,6 @@ public class ControlRegistry {
return interceptors;
}
- static ControlRegistry getThreadLocalRegistry() {
- return getRegistryStack().peek();
- }
-
/**
* Adds the specified ControlRegistry on top of the registry stack.
*
@@ -346,21 +369,21 @@ public class ControlRegistry {
ControlRegistry controlRegistry = registryStack.pop();
if (registryStack.isEmpty()) {
- THREAD_LOCAL_REGISTRY.set(null);
+ THREAD_LOCAL_REGISTRY_STACK.set(null);
}
return controlRegistry;
}
static RegistryStack getRegistryStack() {
- RegistryStack controlRegistry = THREAD_LOCAL_REGISTRY.get();
+ RegistryStack registryStack = THREAD_LOCAL_REGISTRY_STACK.get();
- if (controlRegistry == null) {
- controlRegistry = new RegistryStack(2);
- THREAD_LOCAL_REGISTRY.set(controlRegistry);
+ if (registryStack == null) {
+ registryStack = new RegistryStack(2);
+ THREAD_LOCAL_REGISTRY_STACK.set(registryStack);
}
- return controlRegistry;
+ return registryStack;
}
/**