refactored common logic into abstract base class for annotation-based handler creators

This commit is contained in:
Mark Fisher
2007-12-16 18:29:35 +00:00
parent 787307bb0c
commit e28a5fcd57

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2002-2007 the original author or authors.
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.handler.annotation;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.Order;
import org.springframework.integration.handler.AbstractMessageHandlerAdapter;
import org.springframework.integration.handler.MessageHandler;
/**
* Base class for handler creators for the provided object and method.
*
* @author Mark Fisher
*/
public abstract class AbstractAnnotationHandlerCreator implements AnnotationHandlerCreator {
public final MessageHandler createHandler(Object object, Method method, Annotation annotation) {
MessageHandler handler = this.doCreateHandler(object, method, annotation);
if (handler instanceof AbstractMessageHandlerAdapter<?>) {
AbstractMessageHandlerAdapter adapter = ((AbstractMessageHandlerAdapter) handler);
adapter.setObject(object);
adapter.setMethodName(method.getName());
Order orderAnnotation = (Order) AnnotationUtils.getAnnotation(method, Order.class);
if (orderAnnotation != null) {
adapter.setOrder(orderAnnotation.value());
}
}
return handler;
}
protected abstract MessageHandler doCreateHandler(Object object, Method method, Annotation annotation);
}