/*
 * Copyright (c) 2010-2018. Axon Framework
 *
 * 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.axonframework.deadline.annotation;

import org.axonframework.messaging.annotation.HandlerEnhancerDefinition;
import org.axonframework.messaging.annotation.MessageHandlingMember;
import org.axonframework.messaging.annotation.WrappedMessageHandlingMember;

/**
 * Implementation of a {@link HandlerEnhancerDefinition} that is used for {@link DeadlineHandler} annotated methods.
 *
 * @author Milan Savic
 * @since 3.3
 */
public class DeadlineMethodMessageHandlerDefinition implements HandlerEnhancerDefinition {

    @SuppressWarnings("unchecked")
    @Override
    public <T> MessageHandlingMember<T> wrapHandler(MessageHandlingMember<T> original) {
        return original.annotationAttributes(DeadlineHandler.class)
                       .map(attr -> (MessageHandlingMember<T>) new DeadlineMethodMessageHandlingMember(original))
                       .orElse(original);
    }

    private class DeadlineMethodMessageHandlingMember<T> extends WrappedMessageHandlingMember<T>
            implements DeadlineHandlingMember<T> {

        /**
         * Initializes the member using the given {@code delegate}.
         *
         * @param delegate the actual message handling member to delegate to
         */
        protected DeadlineMethodMessageHandlingMember(MessageHandlingMember<T> delegate) {
            super(delegate);
        }
    }
}

@@ -650,16 +650,168 @@
 ation;%0A%0A
+import org.axonframework.commandhandling.CommandMessage;%0Aimport org.axonframework.deadline.DeadlineMessage;%0Aimport org.axonframework.messaging.Message;%0A
 import o
@@ -875,16 +875,16 @@
 nition;%0A
-
 import o
@@ -1021,16 +1021,39 @@
 ember;%0A%0A
+import java.util.Map;%0A%0A
 /**%0A * I
@@ -1618,16 +1618,22 @@
 original
+, attr
 ))%0A     
@@ -1837,68 +1837,120 @@
     
-/**%0A         * Initializes the member using the given %7B@code
+private final String deadlineName;%0A%0A        private DeadlineMethodMessageHandlingMember(MessageHandlingMember%3CT%3E
  del
@@ -1958,10 +1958,9 @@
 gate
-%7D.
+,
 %0A   
@@ -1969,86 +1969,257 @@
     
-*%0A         * @param delegate the actual message handling member to delegate to
+                                           Map%3CString, Object%3E annotationAttributes) %7B%0A            super(delegate);%0A            deadlineName = %22%22.equals(annotationAttributes.get(%22deadlineName%22))%0A                    ? delegate.payloadType().getName()
 %0A   
@@ -2228,19 +2228,19 @@
     
-*/%0A
+   
         
 prot
@@ -2239,117 +2239,257 @@
     
-protected DeadlineMethodMessageHandlingMember(MessageHandlingMember%3CT%3E delegate) %7B%0A            super(delegate
+: (String) annotationAttributes.get(%22deadlineName%22);%0A        %7D%0A%0A        @Override%0A        public boolean canHandle(Message%3C?%3E message) %7B%0A            return super.canHandle(message) && deadlineName.equals(((DeadlineMessage) message).getDeadlineName()
 );%0A 

Add deadlineName to DeadlineMethodMessageHandlerDefinition