javadoc updates
[utils] / test / enterprise / src / main / java / org / wamblee / support / ThreadSpecificProxyFactory.java
index 1e9c3468d355370d81242d8ed39d1eb2b61f3fe2..26a7610450991d92e5a4619cd6cafd273f0b0e36 100644 (file)
@@ -26,6 +26,12 @@ import java.lang.reflect.Proxy;
  * 
  * It is used for instance to pass a transaction scoped entity manager around.
  * 
+ * The {@link #set(Object)} method sets the current service instance for the current thread. 
+ * The {@link #get()} method gets the current service instance for the current thread. 
+ * The {@link #getProxy()} method gets a proxy that will delegate at runtime to the thread-specific 
+ * instance. The result from this method can be passed at construction of an object that will be used
+ * by multiple threads. 
+ * 
  * @param T
  *            Interface to proxy.
  * @author Erik Brakkee
@@ -49,28 +55,42 @@ public class ThreadSpecificProxyFactory<T> {
     private Class clazz;
 
     /**
-     * Constructs the factory. 
-     * @param aClass Interface class of the service to proxy. 
+     * Constructs the factory.
+     * 
+     * @param aClass
+     *            Interface class of the service to proxy.
      */
     public ThreadSpecificProxyFactory(Class<T> aClass) {
-        if ( !aClass.isInterface() ) { 
-            throw new IllegalArgumentException("Class " + aClass.getName() + " is not an interface");
+        if (!aClass.isInterface()) {
+            throw new IllegalArgumentException("Class " + aClass.getName() +
+                " is not an interface");
         }
         clazz = aClass;
     }
 
     /**
-     * Sets the thread-specific service. 
-     * @param aService Service, use null value to reset.  
+     * Sets the thread-specific service.
+     * 
+     * @param aService
+     *            Service, use null value to reset.
      */
     public void set(T aService) {
         svc.set(aService);
     }
+    
+    /**
+     * Gets the current thread-specific service. 
+     * @return Service. 
+     */
+    public T get() { 
+        return svc.get();
+    }
 
     /**
-     * Gets the proxy that delegates to the thread-specific instance set by 
+     * Gets the proxy that delegates to the thread-specific instance set by
      * {@link #set(Object)}
-     * @return Proxy. 
+     * 
+     * @return Proxy.
      */
     public T getProxy() {
         InvocationHandler handler = new ThreadSpecificInvocationHandler();
@@ -82,8 +102,9 @@ public class ThreadSpecificProxyFactory<T> {
                 new Class[] { InvocationHandler.class }).newInstance(
                 new Object[] { handler });
             return proxy;
-        } catch (Exception e) { 
-            throw new RuntimeException("Could not create proxy for " + clazz.getName(), e);
+        } catch (Exception e) {
+            throw new RuntimeException("Could not create proxy for " +
+                clazz.getName(), e);
         }
     }
 }