View Javadoc

1   package com.atlassian.plugin.event.impl;
2   
3   import org.apache.commons.lang.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  {
12      private final String methodName;
13  
14      public MethodNameListenerMethodSelector()
15      {
16          this("channel");
17      }
18  
19      public MethodNameListenerMethodSelector(String s)
20      {
21          if (StringUtils.isEmpty(s))
22              throw new IllegalArgumentException("Method name for the listener must be a valid method name");
23          this.methodName = s;
24      }
25  
26  
27      /**
28       * Determines if the listener method has the name as the one configured
29       * @param method The method to test
30       * @return True if the method name matches the configured method name, false otherwise
31       */
32      public boolean isListenerMethod(Method method)
33      {
34          if (method == null)
35              throw new IllegalArgumentException("Method cannot be null");
36  
37          return methodName.equals(method.getName());
38      }
39  }