View Javadoc
1   package com.atlassian.plugin.event.impl;
2   
3   import org.apache.commons.lang3.StringUtils;
4   
5   import java.lang.reflect.Method;
6   
7   /**
8    * Listener method selector that makes its determination by matching the method name
9    */
10  public class MethodNameListenerMethodSelector implements ListenerMethodSelector {
11      private final String methodName;
12  
13      public MethodNameListenerMethodSelector() {
14          this("channel");
15      }
16  
17      public MethodNameListenerMethodSelector(String s) {
18          if (StringUtils.isEmpty(s))
19              throw new IllegalArgumentException("Method name for the listener must be a valid method name");
20          this.methodName = s;
21      }
22  
23  
24      /**
25       * Determines if the listener method has the name as the one configured
26       *
27       * @param method The method to test
28       * @return True if the method name matches the configured method name, false otherwise
29       */
30      public boolean isListenerMethod(Method method) {
31          if (method == null)
32              throw new IllegalArgumentException("Method cannot be null");
33  
34          return methodName.equals(method.getName());
35      }
36  }