Author: tv
Date: Wed Sep 18 12:00:31 2013
New Revision: 1524376
URL: http://svn.apache.org/r1524376
Log:
Add Annotation @TurbineLoader to inject a loader instance into objects.
Added:
turbine/core/trunk/src/java/org/apache/turbine/annotation/TurbineLoader.java
(with props)
Modified:
turbine/core/trunk/src/java/org/apache/turbine/annotation/AnnotationProcessor.java
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=1524376&r1=1524375&r2=1524376&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
Wed Sep 18 12:00:31 2013
@@ -28,8 +28,10 @@ import org.apache.commons.lang.StringUti
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.turbine.Turbine;
+import org.apache.turbine.modules.Loader;
import org.apache.turbine.services.ServiceManager;
import org.apache.turbine.services.TurbineServices;
+import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
import org.apache.turbine.util.TurbineException;
/**
@@ -121,6 +123,11 @@ public class AnnotationProcessor
try
{
+ if (log.isDebugEnabled())
+ {
+ log.debug("Injection of " + serviceName + " into
object " + object);
+ }
+
field.set(object, service);
}
catch (IllegalArgumentException e)
@@ -153,6 +160,11 @@ public class AnnotationProcessor
try
{
+ if (log.isDebugEnabled())
+ {
+ log.debug("Injection of " + conf + " into object "
+ object);
+ }
+
field.set(object, conf);
}
catch (IllegalArgumentException e)
@@ -166,6 +178,32 @@ public class AnnotationProcessor
+ conf + " into object " + object, e);
}
}
+ else if (field.isAnnotationPresent(TurbineLoader.class))
+ {
+ TurbineLoader la =
field.getAnnotation(TurbineLoader.class);
+ Loader<?> loader =
TurbineAssemblerBroker.getLoader(la.value());
+ field.setAccessible(true);
+
+ try
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Injection of " + loader + " into object
" + object);
+ }
+
+ field.set(object, loader);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new TurbineException("Could not inject loader "
+ + loader + " into object " + object, e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new TurbineException("Could not inject loader "
+ + loader + " into object " + object, e);
+ }
+ }
}
clazz = clazz.getSuperclass();
Added:
turbine/core/trunk/src/java/org/apache/turbine/annotation/TurbineLoader.java
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/annotation/TurbineLoader.java?rev=1524376&view=auto
==============================================================================
---
turbine/core/trunk/src/java/org/apache/turbine/annotation/TurbineLoader.java
(added)
+++
turbine/core/trunk/src/java/org/apache/turbine/annotation/TurbineLoader.java
Wed Sep 18 12:00:31 2013
@@ -0,0 +1,42 @@
+package org.apache.turbine.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.turbine.modules.Assembler;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Annotation to mark fields in modules that require a loader to be injected
+ */
+@Retention( RetentionPolicy.RUNTIME )
+@Target( ElementType.FIELD )
+public @interface TurbineLoader
+{
+ /**
+ * Get the class of the loader target to inject
+ *
+ * @return the class the loader is responsible for
+ */
+ Class<? extends Assembler> value();
+}
Propchange:
turbine/core/trunk/src/java/org/apache/turbine/annotation/TurbineLoader.java
------------------------------------------------------------------------------
svn:mime-type = text/plain