View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.binding.method;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.seasar.uruma.annotation.EventListenerType;
22  import org.seasar.uruma.binding.method.impl.GenericActionListenerBinder;
23  import org.seasar.uruma.binding.method.impl.GenericHandlerListenerBinder;
24  import org.seasar.uruma.binding.method.impl.StructuredViewerListenerBinder;
25  import org.seasar.uruma.binding.method.impl.UrumaApplicationWindowListenerBinder;
26  import org.seasar.uruma.binding.method.impl.ViewerListenerBinder;
27  import org.seasar.uruma.binding.method.impl.WidgetListenerBinder;
28  import org.seasar.uruma.context.WidgetHandle;
29  
30  /**
31   * {@link ListenerBinder} のためのファクトリクラスです。<br />
32   * 
33   * @author y-komori
34   */
35  public class ListenerBinderFactory {
36      private static ListenerBinder[] binders;
37  
38      static {
39          List<ListenerBinder> binderList = new ArrayList<ListenerBinder>();
40  
41          binderList.add(new StructuredViewerListenerBinder());
42          binderList.add(new ViewerListenerBinder());
43          binderList.add(new UrumaApplicationWindowListenerBinder());
44          binderList.add(new WidgetListenerBinder());
45          binderList.add(new GenericActionListenerBinder());
46          binderList.add(new GenericHandlerListenerBinder());
47  
48          binders = binderList.toArray(new ListenerBinder[binderList.size()]);
49      }
50  
51      private ListenerBinderFactory() {
52  
53      }
54  
55      /**
56       * {@link WidgetHandle} に対応する {@link ListenerBinder} を取得します。<br />
57       * 
58       * @param handle
59       *            {@link WidgetHandle} オブジェクト
60       * @return {@link ListenerBinder} オブジェクト
61       */
62      public static ListenerBinder getListenerBinder(final WidgetHandle handle,
63              final EventListenerType type) {
64          for (int i = 0; i < binders.length; i++) {
65              Class<?> clazz = binders[i].getTargetCLass();
66              if (clazz.isAssignableFrom(handle.getWidgetClass())) {
67                  EventListenerType[] types = binders[i].getEventTypes();
68                  if (types == null) {
69                      return binders[i];
70                  } else {
71                      for (int j = 0; j < types.length; j++) {
72                          if (types[j] == type) {
73                              return binders[i];
74                          }
75                      }
76                  }
77              }
78          }
79          return null;
80      }
81  }