Interceptor API tweak
This commit is contained in:
parent
c22aeaa2e5
commit
af9153d64e
|
@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.model.interceptor.api;
|
|||
* Licensed 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.
|
||||
|
@ -35,6 +35,14 @@ public interface IInterceptorRegistry {
|
|||
@VisibleForTesting
|
||||
void clearAnonymousHookForUnitTest();
|
||||
|
||||
/**
|
||||
* Register an interceptor
|
||||
*
|
||||
* @param theInterceptor The interceptor to register
|
||||
* @return Returns <code>true</code> if at least one valid hook method was found on this interceptor
|
||||
*/
|
||||
boolean registerGlobalInterceptor(Object theInterceptor);
|
||||
|
||||
/**
|
||||
* Invoke the interceptor methods
|
||||
*/
|
||||
|
|
|
@ -95,14 +95,17 @@ public class InterceptorRegistry implements IInterceptorRegistry, ApplicationCon
|
|||
|
||||
}
|
||||
|
||||
private void registerGlobalInterceptor(Object theNextInterceptor) {
|
||||
@Override
|
||||
public boolean registerGlobalInterceptor(Object theInterceptor) {
|
||||
boolean retVal = false;
|
||||
|
||||
int typeOrder = DEFAULT_ORDER;
|
||||
Order typeOrderAnnotation = AnnotationUtils.findAnnotation(theNextInterceptor.getClass(), Order.class);
|
||||
Order typeOrderAnnotation = AnnotationUtils.findAnnotation(theInterceptor.getClass(), Order.class);
|
||||
if (typeOrderAnnotation != null) {
|
||||
typeOrder = typeOrderAnnotation.value();
|
||||
}
|
||||
|
||||
for (Method nextMethod : theNextInterceptor.getClass().getDeclaredMethods()) {
|
||||
for (Method nextMethod : theInterceptor.getClass().getDeclaredMethods()) {
|
||||
Hook hook = AnnotationUtils.findAnnotation(nextMethod, Hook.class);
|
||||
|
||||
if (hook != null) {
|
||||
|
@ -113,14 +116,16 @@ public class InterceptorRegistry implements IInterceptorRegistry, ApplicationCon
|
|||
methodOrder = methodOrderAnnotation.value();
|
||||
}
|
||||
|
||||
HookInvoker invoker = new HookInvoker(hook, theNextInterceptor, nextMethod, methodOrder);
|
||||
HookInvoker invoker = new HookInvoker(hook, theInterceptor, nextMethod, methodOrder);
|
||||
for (Pointcut nextPointcut : hook.value()) {
|
||||
myInvokers.put(nextPointcut, invoker);
|
||||
}
|
||||
|
||||
retVal = true;
|
||||
}
|
||||
}
|
||||
|
||||
myGlobalInterceptors.add(theNextInterceptor);
|
||||
myGlobalInterceptors.add(theInterceptor);
|
||||
|
||||
// Make sure we're always sorted according to the order declared in
|
||||
// @Order
|
||||
|
@ -129,6 +134,8 @@ public class InterceptorRegistry implements IInterceptorRegistry, ApplicationCon
|
|||
List<BaseInvoker> nextInvokerList = myInvokers.get(nextPointcut);
|
||||
nextInvokerList.sort(Comparator.naturalOrder());
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private void sortByOrderAnnotation(List<Object> theObjects) {
|
||||
|
|
Loading…
Reference in New Issue