You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/10/25 23:53:09 UTC
svn commit: r1188939 - in /tapestry/tapestry5/trunk:
tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/PostInjection.java
Author: hlship
Date: Tue Oct 25 21:53:09 2011
New Revision: 1188939
URL: http://svn.apache.org/viewvc?rev=1188939&view=rev
Log:
TAP5-1723: Tapestry should honor the javax.annotation.PostConstruct as the same as the Tapestry PostInjection annotation
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
tapestry/tapestry5/trunk/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/PostInjection.java
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java?rev=1188939&r1=1188938&r2=1188939&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java Tue Oct 25 21:53:09 2011
@@ -28,6 +28,7 @@ import org.apache.tapestry5.plastic.Meth
import org.apache.tapestry5.plastic.PlasticUtils;
import org.slf4j.Logger;
+import javax.annotation.PostConstruct;
import javax.inject.Named;
import java.io.Closeable;
import java.io.IOException;
@@ -1572,11 +1573,16 @@ public class InternalUtils
});
}
+ private static boolean hasAnnotation(AccessibleObject member, Class<? extends Annotation> annotationType)
+ {
+ return member.getAnnotation(annotationType) != null;
+ }
+
private static <T> void extendPlanForPostInjectionMethods(ConstructionPlan<T> plan, OperationTracker tracker, ObjectLocator locator, InjectionResources resources, Class<T> instantiatedClass)
{
for (Method m : instantiatedClass.getMethods())
{
- if (m.getAnnotation(PostInjection.class) != null)
+ if (hasAnnotation(m, PostInjection.class) || hasAnnotation(m, PostConstruct.class))
{
extendPlanForPostInjectionMethod(plan, tracker, locator, resources, m);
}
Modified: tapestry/tapestry5/trunk/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/PostInjection.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/PostInjection.java?rev=1188939&r1=1188938&r2=1188939&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/PostInjection.java (original)
+++ tapestry/tapestry5/trunk/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/PostInjection.java Tue Oct 25 21:53:09 2011
@@ -1,4 +1,4 @@
-// Copyright 2008, 2009 The Apache Software Foundation
+// Copyright 2008, 2009, 2011 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -22,6 +22,10 @@ import java.lang.annotation.*;
* after field injection. It should be placed on a <strong>public method</strong>. Any return value from the method is
* ignored. The order of invocation for classes with multiple marked methods (including methods inherited from
* super-classes) is not, at this time, defined.
+ * <p/>
+ * Tapestry also honors the {@link javax.annotation.PostConstruct} annotation, and treats it identically to
+ * PostInjection. This is both more flexible than PostConstruct (in that methods may have parameters, and multiple methods
+ * may be annotated) but also falls short (Tapestry will only seek out public methods).
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)