Author: tv
Date: Fri Jan 15 13:20:43 2016
New Revision: 1724798

URL: http://svn.apache.org/viewvc?rev=1724798&view=rev
Log:
Add List support to @TurbineConfiguration
Update docs

Modified:
    
turbine/core/trunk/src/java/org/apache/turbine/annotation/AnnotationProcessor.java
    
turbine/core/trunk/src/test/org/apache/turbine/annotation/AnnotationProcessorTest.java
    turbine/core/trunk/xdocs/howto/annotations.xml

Modified: 
turbine/core/trunk/src/java/org/apache/turbine/annotation/AnnotationProcessor.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/annotation/AnnotationProcessor.java?rev=1724798&r1=1724797&r2=1724798&view=diff
==============================================================================
--- 
turbine/core/trunk/src/java/org/apache/turbine/annotation/AnnotationProcessor.java
 (original)
+++ 
turbine/core/trunk/src/java/org/apache/turbine/annotation/AnnotationProcessor.java
 Fri Jan 15 13:20:43 2016
@@ -23,6 +23,7 @@ package org.apache.turbine.annotation;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
+import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.locks.ReentrantLock;
@@ -215,6 +216,17 @@ public class AnnotationProcessor
                     field.setAccessible(true);
                     field.set(object, value);
                 }
+                else if ( Boolean.TYPE.isAssignableFrom( type ) )
+                {
+                    boolean value = conf.getBoolean(key);
+                    if (log.isDebugEnabled())
+                    {
+                        log.debug("Injection of " + value + " into object " + 
object);
+                    }
+
+                    field.setAccessible(true);
+                    field.setBoolean(object, value);
+                }
                 else if ( Integer.TYPE.isAssignableFrom( type ) )
                 {
                     int value = conf.getInt(key);
@@ -292,16 +304,16 @@ public class AnnotationProcessor
                     field.setAccessible(true);
                     field.setByte(object, value);
                 }
-                else if ( Boolean.TYPE.isAssignableFrom( type ) )
+                else if ( List.class.isAssignableFrom( type ) )
                 {
-                    boolean value = conf.getBoolean(key);
+                    List<Object> values = conf.getList(key);
                     if (log.isDebugEnabled())
                     {
-                        log.debug("Injection of " + value + " into object " + 
object);
+                        log.debug("Injection of " + values + " into object " + 
object);
                     }
 
                     field.setAccessible(true);
-                    field.setBoolean(object, value);
+                    field.set(object, values);
                 }
             }
         }

Modified: 
turbine/core/trunk/src/test/org/apache/turbine/annotation/AnnotationProcessorTest.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/test/org/apache/turbine/annotation/AnnotationProcessorTest.java?rev=1724798&r1=1724797&r2=1724798&view=diff
==============================================================================
--- 
turbine/core/trunk/src/test/org/apache/turbine/annotation/AnnotationProcessorTest.java
 (original)
+++ 
turbine/core/trunk/src/test/org/apache/turbine/annotation/AnnotationProcessorTest.java
 Fri Jan 15 13:20:43 2016
@@ -23,6 +23,8 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 
+import java.util.List;
+
 import org.apache.commons.configuration.Configuration;
 import org.apache.fulcrum.factory.FactoryService;
 import org.apache.turbine.modules.Screen;
@@ -32,6 +34,7 @@ import org.apache.turbine.util.TurbineCo
 import org.apache.turbine.util.TurbineException;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -58,6 +61,9 @@ public class AnnotationProcessorTest
     @TurbineConfiguration("template.homepage")
     private String templateHomepage;
 
+    @TurbineConfiguration("module.packages")
+    private List<String> modulePackages;
+
     @TurbineConfiguration("does.not.exist")
     private long notModified = 1;
 
@@ -98,6 +104,9 @@ public class AnnotationProcessorTest
         assertFalse(moduleCache);
         assertEquals(20, actionCacheSize);
         assertEquals("Index.vm", templateHomepage);
+        assertNotNull(modulePackages);
+        assertEquals(3, modulePackages.size());
+        assertEquals("org.apache.turbine.services.template.modules", 
modulePackages.get(1));
         assertEquals(1, notModified);
 
         assertNotNull(screenLoader);
@@ -105,7 +114,7 @@ public class AnnotationProcessorTest
         assertNotNull(factory);
     }
 
-    @Test
+    @Ignore("For performance tests only") @Test
     public void testProcessingPerformance() throws TurbineException
     {
         long startTime = System.currentTimeMillis();

Modified: turbine/core/trunk/xdocs/howto/annotations.xml
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/xdocs/howto/annotations.xml?rev=1724798&r1=1724797&r2=1724798&view=diff
==============================================================================
--- turbine/core/trunk/xdocs/howto/annotations.xml (original)
+++ turbine/core/trunk/xdocs/howto/annotations.xml Fri Jan 15 13:20:43 2016
@@ -75,10 +75,10 @@ will throw an exception.
 
 <subsection name="@TurbineConfiguration">
 The annotation can only be used with a field. 
-A declared field in a class annotated with <code>@TurbineConfiguration</code>
-gets injected an instance of the Turbine configuration object at
-the time the instance of the class is created. The field should have 
-the type <code>Configuration</code>
+If a declared field of the type <code>Configuration</code> is annotated 
+with <code>@TurbineConfiguration</code>, Turbine will inject an instance 
+of the Turbine configuration object at the time the instance of the class 
+is created. 
 <source><![CDATA[
 // Injected configuration instance
 @TurbineConfiguration
@@ -96,6 +96,26 @@ actionConfig = Turbine.getConfiguration(
 ]]></source>
 The annotation supports an optional parameter, the 
 prefix of the configuration subset to retrieve.
+<br />
+If other fields having simple types are annotated with 
+<code>@TurbineConfiguration</code>, Turbine will inject the corresponding
+configuration value. In this case, the annotation parameter defines the
+configuration key and is required. Strings, Lists and most simple types
+are supported. The value will only be set if the key is found in the 
+configuration, so that the field can be initialized with a default value. 
+<source><![CDATA[
+// Injected configuration value
+@TurbineConfiguration( "module.cache" )
+private boolean moduleCache = true;
+
+@TurbineConfiguration( "template.homepage" )
+private String templateHomepage;
+]]></source>
+This is the equivalent of
+<source><![CDATA[
+moduleCache = Turbine.getConfiguration().getBoolean("module.cache", true);
+templateHomepage = Turbine.getConfiguration().getString("template.homepage");
+]]></source>
 </subsection>
 
 <subsection name="@TurbineLoader">


Reply via email to