From: Erik Brakkee Date: Sat, 31 Jul 2010 17:33:16 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.7~119 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=94ddca39fadbe7931a17c179424afd123bd2863a;p=utils --- diff --git a/support/inject/src/main/java/org/wamblee/inject/Injectable.java b/support/inject/src/main/java/org/wamblee/inject/Injectable.java index ccc408f7..7cfdc3d1 100644 --- a/support/inject/src/main/java/org/wamblee/inject/Injectable.java +++ b/support/inject/src/main/java/org/wamblee/inject/Injectable.java @@ -15,22 +15,19 @@ */ package org.wamblee.inject; - - /** * This abstract base class performs injection at construction. Be sure not to * initialize fields of derived classes to null as these will override the * initializations of this base class. * - * This class uses {@link InjectorBuilder} to obtain an implementation of - * a {@link InjectorFactory} to use. + * This class uses {@link InjectorBuilder} to obtain an implementation of a + * {@link InjectorFactory} to use. * * @author Erik Brakkee */ public abstract class Injectable { - private final Injector injector = - InjectorBuilder.getInjector(); + private final Injector injector = InjectorBuilder.getInjector(); /** * Inheritance style constructor. @@ -39,19 +36,19 @@ public abstract class Injectable { inject(); } - /** - * Inject references. This can be useful when injection is to be done again after construction - * to obtain new references or after zeroing out of the references. + * Inject references. This can be useful when injection is to be done again + * after construction to obtain new references or after zeroing out of the + * references. */ public void inject() { injector.inject(this); - } - - + } + /** * Gets the default injector. - * @return Injector. + * + * @return Injector. */ public Injector getInjector() { return injector; diff --git a/support/inject/src/main/java/org/wamblee/inject/Injector.java b/support/inject/src/main/java/org/wamblee/inject/Injector.java index e42cc5f7..42d458f5 100644 --- a/support/inject/src/main/java/org/wamblee/inject/Injector.java +++ b/support/inject/src/main/java/org/wamblee/inject/Injector.java @@ -16,8 +16,8 @@ package org.wamblee.inject; /** - * Interface used to perform injection with. An injector instance knows how to perform injection in - * one or more specific classes. + * Interface used to perform injection with. An injector instance knows how to + * perform injection in one or more specific classes. * * @author Erik Brakkee */ @@ -28,8 +28,10 @@ public interface Injector { * * @param aComponent * Component to inject into. - * @throws IllegalArgumentException In case the argument passed is not supported for injection - * @throws NullPointerException In case the argument passed is null. + * @throws IllegalArgumentException + * In case the argument passed is not supported for injection + * @throws NullPointerException + * In case the argument passed is null. */ void inject(Object aComponent); diff --git a/support/inject/src/main/java/org/wamblee/inject/InjectorBuilder.java b/support/inject/src/main/java/org/wamblee/inject/InjectorBuilder.java index fe6c2a93..f0c0292b 100644 --- a/support/inject/src/main/java/org/wamblee/inject/InjectorBuilder.java +++ b/support/inject/src/main/java/org/wamblee/inject/InjectorBuilder.java @@ -20,25 +20,28 @@ import java.util.ServiceLoader; /** * Utility for obtaining an implementation of the {@link InjectorFactory} using - * {@link ServiceLoader} and for obtaining a {@link SimpleInjector}. + * {@link ServiceLoader} and for obtaining a {@link SimpleInjector}. * - * The builder takes care that the factory and simple injector are built only once. - * For test code, make sure to call {@link #setInjectorFactory(InjectorFactory)} - * before each test case to force the retrieval of a new factory and injector. This - * is important because if the simple injector is not created again it will use - * cached {@link Injector} instances from other tests. + * The builder takes care that the factory and simple injector are built only + * once. For test code, make sure to call + * {@link #setInjectorFactory(InjectorFactory)} before each test case to force + * the retrieval of a new factory and injector. This is important because if the + * simple injector is not created again it will use cached {@link Injector} + * instances from other tests. * * @author Erik Brakkee */ public class InjectorBuilder { private static InjectorFactory FACTORY; - - private static SimpleInjector INJECTOR; + + private static SimpleInjector INJECTOR; /** - * Sets the injector factory. This is useful for testing. - * @param aFactory Factory to use. + * Sets the injector factory. This is useful for testing. + * + * @param aFactory + * Factory to use. */ public static void setInjectorFactory(InjectorFactory aFactory) { FACTORY = aFactory; @@ -53,18 +56,20 @@ public class InjectorBuilder { */ public static InjectorFactory getInjectorFactory() { if (FACTORY == null) { - FACTORY = findInjectorFactory(); + FACTORY = findInjectorFactory(); INJECTOR = new SimpleInjector(FACTORY); } return FACTORY; } - + /** - * Gets an injector that support injection into any type of object and - * performs caching of the injector obtained from the {@link InjectorFactory}. + * Gets an injector that support injection into any type of object and + * performs caching of the injector obtained from the + * {@link InjectorFactory}. + * * @return Injector. */ - public static Injector getInjector() { + public static Injector getInjector() { getInjectorFactory(); return INJECTOR; } diff --git a/support/inject/src/main/java/org/wamblee/inject/InjectorCache.java b/support/inject/src/main/java/org/wamblee/inject/InjectorCache.java index 3e272f5f..63136847 100644 --- a/support/inject/src/main/java/org/wamblee/inject/InjectorCache.java +++ b/support/inject/src/main/java/org/wamblee/inject/InjectorCache.java @@ -33,7 +33,8 @@ public class InjectorCache { /** * Constructs an empty cache. * - * @param aInjectorFactory Injector factory to create Injectors. + * @param aInjectorFactory + * Injector factory to create Injectors. */ public InjectorCache(InjectorFactory aInjectorFactory) { injectorFactory = aInjectorFactory; diff --git a/support/inject/src/main/java/org/wamblee/inject/InjectorFactory.java b/support/inject/src/main/java/org/wamblee/inject/InjectorFactory.java index d36720de..104c4e27 100644 --- a/support/inject/src/main/java/org/wamblee/inject/InjectorFactory.java +++ b/support/inject/src/main/java/org/wamblee/inject/InjectorFactory.java @@ -15,14 +15,13 @@ */ package org.wamblee.inject; - /** - * The injector factory is responsible for creating injectors for a given class. - * This must be implemneted to interface to specific dependency injection frameworks or for - * testing. + * The injector factory is responsible for creating injectors for a given class. + * This must be implemneted to interface to specific dependency injection + * frameworks or for testing. * - * Implementations of this class must have a default no-arg constructor to be usable by - * {@link InjectorBuilder}. + * Implementations of this class must have a default no-arg constructor to be + * usable by {@link InjectorBuilder}. * * @author Erik Brakkee */ @@ -30,8 +29,10 @@ public interface InjectorFactory { /** * Creates an injector. + * * @return Injector fot he given class. - * @throws IllegalArgumentException In case the given class cannot be used. + * @throws IllegalArgumentException + * In case the given class cannot be used. */ Injector create(Class aClass); diff --git a/support/inject/src/main/java/org/wamblee/inject/SimpleInjector.java b/support/inject/src/main/java/org/wamblee/inject/SimpleInjector.java index b41eb4c3..449a65a3 100644 --- a/support/inject/src/main/java/org/wamblee/inject/SimpleInjector.java +++ b/support/inject/src/main/java/org/wamblee/inject/SimpleInjector.java @@ -15,7 +15,6 @@ */ package org.wamblee.inject; - /** * The main entry point for programmatic dependency injection. A different * {@link InjectorFactory} can be plugged in for testing. @@ -23,6 +22,7 @@ package org.wamblee.inject; *

* Given the following class: *

+ * *
  *   class Pojo {
  *     @EJB
@@ -47,13 +47,12 @@ package org.wamblee.inject;
  * The SimpleInjector should be cached. This is because the
  * SimpleInjector caches the {@link Injector} objects that it uses
  * internally for performance. This is done because creation of these internal
- * Injector objects may be costly. Caching the simple injector makes sure
- * that a class is not analysed again for annotations every time injection is
- * used.
+ * Injector objects may be costly. Caching the simple injector
+ * makes sure that a class is not analysed again for annotations every time
+ * injection is used.
  * 
  * For more advanced cases, the injector factory can also be directly
- * constructed instead of being obtained through the
- * {@link InjectorBuilder}.
+ * constructed instead of being obtained through the {@link InjectorBuilder}.
  * 
  * @author Erik Brakkee
  */
diff --git a/support/inject/src/test/java/org/wamblee/inject/InjectableTest.java b/support/inject/src/test/java/org/wamblee/inject/InjectableTest.java
index 150d4ad3..1eeb0647 100644
--- a/support/inject/src/test/java/org/wamblee/inject/InjectableTest.java
+++ b/support/inject/src/test/java/org/wamblee/inject/InjectableTest.java
@@ -22,8 +22,8 @@ import org.junit.Test;
 public class InjectableTest {
 
     @Test
-    public void testInjectInDerivedClass() { 
-        Pojo pojo = new Pojo(); 
-        assertEquals(TestInjectorFactory.MAGIC_VALUE, pojo.getValue()); 
+    public void testInjectInDerivedClass() {
+        Pojo pojo = new Pojo();
+        assertEquals(TestInjectorFactory.MAGIC_VALUE, pojo.getValue());
     }
 }
diff --git a/support/inject/src/test/java/org/wamblee/inject/InjectorBuilderTest.java b/support/inject/src/test/java/org/wamblee/inject/InjectorBuilderTest.java
index e1c10a80..95fbb7f9 100644
--- a/support/inject/src/test/java/org/wamblee/inject/InjectorBuilderTest.java
+++ b/support/inject/src/test/java/org/wamblee/inject/InjectorBuilderTest.java
@@ -17,29 +17,29 @@ package org.wamblee.inject;
 
 import org.junit.After;
 import org.junit.Test;
-import static junit.framework.TestCase.*; 
+import static junit.framework.TestCase.*;
 
-import static org.mockito.Mockito.*; 
+import static org.mockito.Mockito.*;
 
 public class InjectorBuilderTest {
-    
+
     @After
-    public void tearDown() { 
+    public void tearDown() {
         InjectorBuilder.setInjectorFactory(null);
     }
 
     @Test
-    public void testGetInjectorFactory() { 
-        InjectorFactory factory = InjectorBuilder.getInjectorFactory(); 
+    public void testGetInjectorFactory() {
+        InjectorFactory factory = InjectorBuilder.getInjectorFactory();
         assertTrue(factory instanceof TestInjectorFactory);
     }
-    
+
     @Test
-    public void testOVerrideInjectorFactory() { 
+    public void testOVerrideInjectorFactory() {
         InjectorFactory factory = mock(InjectorFactory.class);
-        
-        InjectorBuilder.setInjectorFactory(factory); 
-        InjectorFactory factory2 = InjectorBuilder.getInjectorFactory(); 
-        assertSame(factory, factory2);  
+
+        InjectorBuilder.setInjectorFactory(factory);
+        InjectorFactory factory2 = InjectorBuilder.getInjectorFactory();
+        assertSame(factory, factory2);
     }
 }
diff --git a/support/inject/src/test/java/org/wamblee/inject/InjectorCacheTest.java b/support/inject/src/test/java/org/wamblee/inject/InjectorCacheTest.java
index 8a5b2dee..bcf62874 100644
--- a/support/inject/src/test/java/org/wamblee/inject/InjectorCacheTest.java
+++ b/support/inject/src/test/java/org/wamblee/inject/InjectorCacheTest.java
@@ -20,43 +20,47 @@ import static junit.framework.Assert.*;
 import org.junit.Test;
 
 public class InjectorCacheTest {
-    
-    private static class MyInjector implements Injector { 
-        private String classname; 
-        
-        public MyInjector(String aClassname) { 
-            classname = aClassname; 
+
+    private static class MyInjector implements Injector {
+        private String classname;
+
+        public MyInjector(String aClassname) {
+            classname = aClassname;
         }
+
         @Override
         public void inject(Object aComponent) {
             throw new RuntimeException("not implemented");
         }
+
         public String getClassname() {
             return classname;
         }
     }
 
     @Test
-    public void testCache() { 
+    public void testCache() {
         InjectorFactory factory = new InjectorFactory() {
-            
+
             @Override
             public Injector create(Class aClass) {
                 return new MyInjector(aClass.getName());
             }
         };
-        InjectorCache cache = new InjectorCache(factory); 
+        InjectorCache cache = new InjectorCache(factory);
         // Unrealistic exmaple, but sufficient for test.
-      
+
         Injector injector = cache.getInjector(String.class);
-        assertEquals(String.class.getName(), ((MyInjector)injector).getClassname());
-        
-        Injector injector2 = cache.getInjector(String.class); 
+        assertEquals(String.class.getName(), ((MyInjector) injector)
+            .getClassname());
+
+        Injector injector2 = cache.getInjector(String.class);
         assertSame(injector, injector2);
-        
-        // verify we get another one for another class. 
+
+        // verify we get another one for another class.
         Injector injector3 = cache.getInjector(Long.class);
-        assertEquals(Long.class.getName(), ((MyInjector)injector3).getClassname());
-        
+        assertEquals(Long.class.getName(), ((MyInjector) injector3)
+            .getClassname());
+
     }
 }
diff --git a/support/inject/src/test/java/org/wamblee/inject/Pojo.java b/support/inject/src/test/java/org/wamblee/inject/Pojo.java
index 38afd7bb..2a3c6a12 100644
--- a/support/inject/src/test/java/org/wamblee/inject/Pojo.java
+++ b/support/inject/src/test/java/org/wamblee/inject/Pojo.java
@@ -17,12 +17,12 @@ package org.wamblee.inject;
 
 public class Pojo extends Injectable {
 
-    private String value; 
-    
+    private String value;
+
     public void setValue(String aValue) {
         value = aValue;
     }
-    
+
     public String getValue() {
         return value;
     }