diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/annotation/AbstractAnnotationHandlerCreator.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/annotation/AbstractAnnotationHandlerCreator.java new file mode 100644 index 0000000000..d477197d54 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/annotation/AbstractAnnotationHandlerCreator.java @@ -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); + +}