Coverage Report - org.seasar.uruma.binding.method.ListenerBinderFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ListenerBinderFactory
86%
18/21
70%
7/10
0
 
 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  4
         List<ListenerBinder> binderList = new ArrayList<ListenerBinder>();
 40  
 
 41  4
         binderList.add(new StructuredViewerListenerBinder());
 42  4
         binderList.add(new ViewerListenerBinder());
 43  4
         binderList.add(new UrumaApplicationWindowListenerBinder());
 44  4
         binderList.add(new WidgetListenerBinder());
 45  4
         binderList.add(new GenericActionListenerBinder());
 46  4
         binderList.add(new GenericHandlerListenerBinder());
 47  
 
 48  4
         binders = binderList.toArray(new ListenerBinder[binderList.size()]);
 49  4
     }
 50  
 
 51  0
     private ListenerBinderFactory() {
 52  
 
 53  0
     }
 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  1692
         for (int i = 0; i < binders.length; i++) {
 65  1692
             Class<?> clazz = binders[i].getTargetCLass();
 66  1692
             if (clazz.isAssignableFrom(handle.getWidgetClass())) {
 67  428
                 EventListenerType[] types = binders[i].getEventTypes();
 68  428
                 if (types == null) {
 69  416
                     return binders[i];
 70  
                 } else {
 71  12
                     for (int j = 0; j < types.length; j++) {
 72  12
                         if (types[j] == type) {
 73  12
                             return binders[i];
 74  
                         }
 75  
                     }
 76  
                 }
 77  
             }
 78  
         }
 79  0
         return null;
 80  
     }
 81  
 }