This is an automated email from the ASF dual-hosted git repository.

gk pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/turbine-core.git

commit 3c249f1ee9b01be235687b63e183bca5ac25701d
Author: Georg Kallidis <[email protected]>
AuthorDate: Mon Aug 14 12:29:21 2023 +0200

    Annotationprocessor if key was foud, but could not be aasigned, log if not 
found showing default value, more exact javadoc
---
 .../turbine/annotation/AnnotationProcessor.java    | 46 ++++++++++++++++------
 src/java/org/apache/turbine/modules/Assembler.java |  3 ++
 src/java/org/apache/turbine/modules/Loader.java    |  2 +-
 3 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/src/java/org/apache/turbine/annotation/AnnotationProcessor.java 
b/src/java/org/apache/turbine/annotation/AnnotationProcessor.java
index e25e8b37..8979f51f 100644
--- a/src/java/org/apache/turbine/annotation/AnnotationProcessor.java
+++ b/src/java/org/apache/turbine/annotation/AnnotationProcessor.java
@@ -328,7 +328,7 @@ public class AnnotationProcessor
     }
 
     /**
-     * Inject Turbine configuration into field of object
+     * Inject Turbine loader into field of object
      *
      * @param object the object to process
      * @param assembler AssemblerBrokerService, provides the loader
@@ -356,10 +356,11 @@ public class AnnotationProcessor
     }
     
     /**
-     * Inject Turbine configuration into field of object
+     * Inject Turbine tool into field of object and 
+     * injects annotations provided in the tool.
      *
      * @param object the object to process
-     * @param assembler AssemblerBrokerService, provides the loader
+     * @param assembler AssemblerBrokerService, provides the tool
      * @param field the field
      * @param annotation the value of the annotation
      *
@@ -427,7 +428,7 @@ public class AnnotationProcessor
                 if ( String.class.isAssignableFrom( type ) )
                 {
                     String value = conf.getString(key);
-                    log.debug("Injection of {} into object {}", value, object);
+                    log.debug("Injection of key {} into object {}", value, 
object);
 
                     field.setAccessible(true);
                     field.set(object, value);
@@ -435,7 +436,7 @@ public class AnnotationProcessor
                 else if ( Boolean.TYPE.isAssignableFrom( type ) )
                 {
                     boolean value = conf.getBoolean(key);
-                    log.debug("Injection of {} into object {}", value, object);
+                    log.debug("Injection of key {} into object {}", value, 
object);
 
                     field.setAccessible(true);
                     field.setBoolean(object, value);
@@ -443,7 +444,7 @@ public class AnnotationProcessor
                 else if ( Integer.TYPE.isAssignableFrom( type ) )
                 {
                     int value = conf.getInt(key);
-                    log.debug("Injection of {} into object {}", value, object);
+                    log.debug("Injection of key {} into object {}", value, 
object);
 
                     field.setAccessible(true);
                     field.setInt(object, value);
@@ -451,7 +452,7 @@ public class AnnotationProcessor
                 else if ( Long.TYPE.isAssignableFrom( type ) )
                 {
                     long value = conf.getLong(key);
-                    log.debug("Injection of {} into object {}", value, object);
+                    log.debug("Injection of key {} into object {}", value, 
object);
 
                     field.setAccessible(true);
                     field.setLong(object, value);
@@ -459,7 +460,7 @@ public class AnnotationProcessor
                 else if ( Short.TYPE.isAssignableFrom( type ) )
                 {
                     short value = conf.getShort(key);
-                    log.debug("Injection of {} into object {}", value, object);
+                    log.debug("Injection of key {} into object {}", value, 
object);
 
                     field.setAccessible(true);
                     field.setShort(object, value);
@@ -467,7 +468,7 @@ public class AnnotationProcessor
                 else if ( Long.TYPE.isAssignableFrom( type ) )
                 {
                     long value = conf.getLong(key);
-                    log.debug("Injection of {} into object {}", value, object);
+                    log.debug("Injection of key {} into object {}", value, 
object);
 
                     field.setAccessible(true);
                     field.setLong(object, value);
@@ -475,7 +476,7 @@ public class AnnotationProcessor
                 else if ( Float.TYPE.isAssignableFrom( type ) )
                 {
                     float value = conf.getFloat(key);
-                    log.debug("Injection of {} into object {}", value, object);
+                    log.debug("Injection of key {} into object {}", value, 
object);
 
                     field.setAccessible(true);
                     field.setFloat(object, value);
@@ -483,7 +484,7 @@ public class AnnotationProcessor
                 else if ( Double.TYPE.isAssignableFrom( type ) )
                 {
                     double value = conf.getDouble(key);
-                    log.debug("Injection of {} into object {}", value, object);
+                    log.debug("Injection of key {} into object {}", value, 
object);
 
                     field.setAccessible(true);
                     field.setDouble(object, value);
@@ -491,7 +492,7 @@ public class AnnotationProcessor
                 else if ( Byte.TYPE.isAssignableFrom( type ) )
                 {
                     byte value = conf.getByte(key);
-                    log.debug("Injection of {} into object {}", value, object);
+                    log.debug("Injection of key {} into object {}", value, 
object);
 
                     field.setAccessible(true);
                     field.setByte(object, value);
@@ -499,11 +500,21 @@ public class AnnotationProcessor
                 else if ( List.class.isAssignableFrom( type ) )
                 {
                     List<Object> values = conf.getList(key);
-                    log.debug("Injection of {} into object {}", values, 
object);
+                    log.debug("Injection of key {} into object {}", values, 
object);
 
                     field.setAccessible(true);
                     field.set(object, values);
+                } else {
+                    throw new TurbineException("Could not inject type " + 
+                      type + " into object " + object + ". Type "+ type + " 
not assignable in configuration "
+                      + conf + " (allowed: String, Boolean, List, Number 
Types, "+ Configuration.class.getName() + ").");
                 }
+            } else {
+                field.setAccessible(true);
+                Object defaultValue = field.get(object);
+                // this should not throw an error as it might be set later 
from container  e. g. session.timeout 
+                // we might check field.get<Type> to show the default value of 
the field, but this is only a guess, it might be set even later..
+                log.info("No key {} of type {} injected into object {}. Field 
{} is set to default {}.", key, type, object, field.getName(), defaultValue);
             }
         }
         catch (IllegalArgumentException | IllegalAccessException e)
@@ -562,6 +573,15 @@ public class AnnotationProcessor
         }
     }
 
+    /**
+     * Injects Turbine service into method fields 
+     * 
+     * @param object the object to process
+     * @param manager the service manager
+     * @param method The method
+     * @param annotation the value of the annotation
+     * @throws TurbineException
+     */
     private static void injectTurbineService(Object object, ServiceManager 
manager, Method method, TurbineService annotation) throws TurbineException
     {
         String serviceName = null;
diff --git a/src/java/org/apache/turbine/modules/Assembler.java 
b/src/java/org/apache/turbine/modules/Assembler.java
index d4d72544..7d6a4771 100644
--- a/src/java/org/apache/turbine/modules/Assembler.java
+++ b/src/java/org/apache/turbine/modules/Assembler.java
@@ -23,6 +23,9 @@ package org.apache.turbine.modules;
  * This is an interface that defines what an Assembler is. All the current
  * modules extend off of this class. It is currently empty and future use is 
yet
  * to be determined.
+ * 
+ * Currently this are mostly one of the classes, which could be loaded by 
{@link Loader}.
+ * Check also the assembler classes having a loader {@link GenericLoader}.
  *
  * @author <a href="mailto:[email protected]";>Dave Bryson</a>
  * @author <a href="mailto:[email protected]";>Peter Courcoux</a>
diff --git a/src/java/org/apache/turbine/modules/Loader.java 
b/src/java/org/apache/turbine/modules/Loader.java
index 96e6defc..1185832c 100644
--- a/src/java/org/apache/turbine/modules/Loader.java
+++ b/src/java/org/apache/turbine/modules/Loader.java
@@ -20,7 +20,7 @@ package org.apache.turbine.modules;
  */
 
 /**
- * A common interface for Screen, Layout and Navigation Loader
+ * A common interface for Assembler classes like Action, Screen, Layout, 
Navigation Loader
  *
  * @author <a href="mailto:[email protected]";>Henning P. Schmiedehausen</a>
  * @param <T> the specialized assembler type

Reply via email to