Repository: incubator-juneau
Updated Branches:
  refs/heads/master 6d63a4183 -> 9f059be90


Allow static and non-private @RestHook methods.

Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/9f059be9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/9f059be9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/9f059be9

Branch: refs/heads/master
Commit: 9f059be9033364d7e0e2c373a7d572f552758e57
Parents: 6d63a41
Author: JamesBognar <[email protected]>
Authored: Mon Aug 14 10:32:55 2017 -0400
Committer: JamesBognar <[email protected]>
Committed: Mon Aug 14 10:32:55 2017 -0400

----------------------------------------------------------------------
 .../java/org/apache/juneau/rest/RestConfig.java |  1 +
 .../org/apache/juneau/rest/RestContext.java     | 35 ++++++++++++--------
 .../juneau/rest/annotation/HookEvent.java       | 32 +++++++++++++-----
 3 files changed, 46 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9f059be9/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java 
b/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java
index 59702d2..b452a53 100644
--- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java
@@ -281,6 +281,7 @@ public class RestConfig implements ServletConfig {
                Map<String,Method> map = new LinkedHashMap<String,Method>();
                for (Method m : ClassUtils.getAllMethods(this.resourceClass, 
true)) {
                        if (m.isAnnotationPresent(RestHook.class) && 
m.getAnnotation(RestHook.class).value() == HookEvent.INIT) {
+                               Visibility.setAccessible(m);
                                String sig = ClassUtils.getMethodSignature(m);
                                if (! map.containsKey(sig))
                                        map.put(sig, m);

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9f059be9/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java 
b/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java
index 2a77eb6..b0b950e 100644
--- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -314,22 +314,22 @@ public final class RestContext extends Context {
        private final RestResourceResolver resourceResolver;
 
        // Lifecycle methods
-       private final Method[] 
-               postInitMethods, 
-               postInitChildFirstMethods, 
-               preCallMethods, 
-               postCallMethods, 
-               startCallMethods, 
-               endCallMethods, 
+       private final Method[]
+               postInitMethods,
+               postInitChildFirstMethods,
+               preCallMethods,
+               postCallMethods,
+               startCallMethods,
+               endCallMethods,
                destroyMethods;
-       private final RestParam[][] 
-               preCallMethodParams, 
+       private final RestParam[][]
+               preCallMethodParams,
                postCallMethodParams;
-       private final Class<?>[][] 
-               postInitMethodParams, 
-               postInitChildFirstMethodParams, 
-               startCallMethodParams, 
-               endCallMethodParams, 
+       private final Class<?>[][]
+               postInitMethodParams,
+               postInitChildFirstMethodParams,
+               startCallMethodParams,
+               endCallMethodParams,
                destroyMethodParams;
 
        // In-memory cache of images and stylesheets in the 
org.apache.juneau.rest.htdocs package.
@@ -513,6 +513,7 @@ public final class RestContext extends Context {
                                        switch(he) {
                                                case PRE_CALL: {
                                                        if (! 
_preCallMethods.containsKey(sig)) {
+                                                               
Visibility.setAccessible(m);
                                                                
_preCallMethods.put(sig, m);
                                                                
_preCallMethodParams.add(findParams(m, false, null, true));
                                                        }
@@ -520,6 +521,7 @@ public final class RestContext extends Context {
                                                }
                                                case POST_CALL: {
                                                        if (! 
_postCallMethods.containsKey(sig)) {
+                                                               
Visibility.setAccessible(m);
                                                                
_postCallMethods.put(sig, m);
                                                                
_postCallMethodParams.add(findParams(m, false, null, true));
                                                        }
@@ -527,6 +529,7 @@ public final class RestContext extends Context {
                                                }
                                                case START_CALL: {
                                                        if (! 
_startCallMethods.containsKey(sig)) {
+                                                               
Visibility.setAccessible(m);
                                                                
_startCallMethods.put(sig, m);
                                                                
_startCallMethodParams.add(m.getParameterTypes());
                                                                
ClassUtils.assertArgsOfType(m, HttpServletRequest.class, 
HttpServletResponse.class);
@@ -535,6 +538,7 @@ public final class RestContext extends Context {
                                                }
                                                case END_CALL: {
                                                        if (! 
_endCallMethods.containsKey(sig)) {
+                                                               
Visibility.setAccessible(m);
                                                                
_endCallMethods.put(sig, m);
                                                                
_endCallMethodParams.add(m.getParameterTypes());
                                                                
ClassUtils.assertArgsOfType(m, HttpServletRequest.class, 
HttpServletResponse.class);
@@ -543,6 +547,7 @@ public final class RestContext extends Context {
                                                }
                                                case POST_INIT: {
                                                        if (! 
_postInitMethods.containsKey(sig)) {
+                                                               
Visibility.setAccessible(m);
                                                                
_postInitMethods.put(sig, m);
                                                                
_postInitMethodParams.add(m.getParameterTypes());
                                                                
ClassUtils.assertArgsOfType(m, RestContext.class);
@@ -551,6 +556,7 @@ public final class RestContext extends Context {
                                                }
                                                case POST_INIT_CHILD_FIRST: {
                                                        if (! 
_postInitChildFirstMethods.containsKey(sig)) {
+                                                               
Visibility.setAccessible(m);
                                                                
_postInitChildFirstMethods.put(sig, m);
                                                                
_postInitChildFirstMethodParams.add(m.getParameterTypes());
                                                                
ClassUtils.assertArgsOfType(m, RestContext.class);
@@ -559,6 +565,7 @@ public final class RestContext extends Context {
                                                }
                                                case DESTROY: {
                                                        if (! 
_destroyMethods.containsKey(sig)) {
+                                                               
Visibility.setAccessible(m);
                                                                
_destroyMethods.put(sig, m);
                                                                
_destroyMethodParams.add(m.getParameterTypes());
                                                                
ClassUtils.assertArgsOfType(m, RestContext.class);

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9f059be9/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HookEvent.java
----------------------------------------------------------------------
diff --git 
a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HookEvent.java 
b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HookEvent.java
index 74684e8..98489f3 100644
--- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HookEvent.java
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HookEvent.java
@@ -65,7 +65,9 @@ public enum HookEvent {
         *
         * <h5 class='section'>Notes:</h5>
         * <ul class='spaced-list'>
-        *      <li>If the method returns any value, it is ignored.
+        *      <li>The method should return <jk>void</jk> although if it does 
return any value, the value will be ignored.
+        *      <li>The method should be <jk>public</jk> although other 
visibilities are valid if the security manager allows it.
+        *      <li>Static methods can be used.
         *      <li>Multiple START_CALL methods can be defined on a class.
         *              <br>START_CALL methods on parent classes are invoked 
before START_CALL methods on child classes.
         *              <br>The order of START_CALL method invocations within a 
class is alphabetical, then by parameter count, then by parameter types.
@@ -174,7 +176,9 @@ public enum HookEvent {
         *
         * <h5 class='section'>Notes:</h5>
         * <ul class='spaced-list'>
-        *      <li>If the method returns any value, it is ignored.
+        *      <li>The method should return <jk>void</jk> although if it does 
return any value, the value will be ignored.
+        *      <li>The method should be <jk>public</jk> although other 
visibilities are valid if the security manager allows it.
+        *      <li>Static methods can be used.
         *      <li>Multiple PRE_CALL methods can be defined on a class.
         *              <br>PRE_CALL methods on parent classes are invoked 
before PRE_CALL methods on child classes.
         *              <br>The order of PRE_CALL method invocations within a 
class is alphabetical, then by parameter count, then by parameter types.
@@ -215,7 +219,9 @@ public enum HookEvent {
         *
         * <h5 class='section'>Notes:</h5>
         * <ul class='spaced-list'>
-        *      <li>If the method returns any value, it is ignored.
+        *      <li>The method should return <jk>void</jk> although if it does 
return any value, the value will be ignored.
+        *      <li>The method should be <jk>public</jk> although other 
visibilities are valid if the security manager allows it.
+        *      <li>Static methods can be used.
         *      <li>Multiple POST_CALL methods can be defined on a class.
         *              <br>POST_CALL methods on parent classes are invoked 
before POST_CALL methods on child classes.
         *              <br>The order of POST_CALL method invocations within a 
class is alphabetical, then by parameter count, then by parameter types.
@@ -270,7 +276,9 @@ public enum HookEvent {
         *
         * <h5 class='section'>Notes:</h5>
         * <ul class='spaced-list'>
-        *      <li>If the method returns any value, it is ignored.
+        *      <li>The method should return <jk>void</jk> although if it does 
return any value, the value will be ignored.
+        *      <li>The method should be <jk>public</jk> although other 
visibilities are valid if the security manager allows it.
+        *      <li>Static methods can be used.
         *      <li>Multiple END_CALL methods can be defined on a class.
         *              <br>END_CALL methods on parent classes are invoked 
before END_CALL methods on child classes.
         *              <br>The order of END_CALL method invocations within a 
class is alphabetical, then by parameter count, then by parameter types.
@@ -315,7 +323,9 @@ public enum HookEvent {
         *
         * <h5 class='section'>Notes:</h5>
         * <ul class='spaced-list'>
-        *      <li>If the method returns any value, it is ignored.
+        *      <li>The method should return <jk>void</jk> although if it does 
return any value, the value will be ignored.
+        *      <li>The method should be <jk>public</jk> although other 
visibilities are valid if the security manager allows it.
+        *      <li>Static methods can be used.
         *      <li>Multiple INIT methods can be defined on a class.
         *              <br>INIT methods on parent classes are invoked before 
INIT methods on child classes.
         *              <br>The order of INIT method invocations within a class 
is alphabetical, then by parameter count, then by parameter types.
@@ -340,7 +350,9 @@ public enum HookEvent {
         *
         * <h5 class='section'>Notes:</h5>
         * <ul class='spaced-list'>
-        *      <li>If the method returns any value, it is ignored.
+        *      <li>The method should return <jk>void</jk> although if it does 
return any value, the value will be ignored.
+        *      <li>The method should be <jk>public</jk> although other 
visibilities are valid if the security manager allows it.
+        *      <li>Static methods can be used.
         *      <li>Multiple POST_INIT methods can be defined on a class.
         *              <br>POST_INIT methods on parent classes are invoked 
before POST_INIT methods on child classes.
         *              <br>The order of POST_INIT method invocations within a 
class is alphabetical, then by parameter count, then by parameter types.
@@ -368,7 +380,9 @@ public enum HookEvent {
         *
         * <h5 class='section'>Notes:</h5>
         * <ul class='spaced-list'>
-        *      <li>If the method returns any value, it is ignored.
+        *      <li>The method should return <jk>void</jk> although if it does 
return any value, the value will be ignored.
+        *      <li>The method should be <jk>public</jk> although other 
visibilities are valid if the security manager allows it.
+        *      <li>Static methods can be used.
         *      <li>Multiple POST_INIT_CHILD_FIRST methods can be defined on a 
class.
         *              <br>POST_INIT_CHILD_FIRST methods on parent classes are 
invoked before POST_INIT_CHILD_FIRST methods on child classes.
         *              <br>The order of POST_INIT_CHILD_FIRST method 
invocations within a class is alphabetical, then by parameter count, then by 
parameter types.
@@ -404,7 +418,9 @@ public enum HookEvent {
         *
         * <h5 class='section'>Notes:</h5>
         * <ul class='spaced-list'>
-        *      <li>If the method returns any value, it is ignored.
+        *      <li>The method should return <jk>void</jk> although if it does 
return any value, the value will be ignored.
+        *      <li>The method should be <jk>public</jk> although other 
visibilities are valid if the security manager allows it.
+        *      <li>Static methods can be used.
         *      <li>Multiple DESTROY methods can be defined on a class.
         *              <br>DESTROY methods on child classes are invoked before 
DESTROY methods on parent classes.
         *              <br>The order of DESTROY method invocations within a 
class is alphabetical, then by parameter count, then by parameter types.

Reply via email to