Coverage Report - org.seasar.uruma.binding.value.ValueBinderFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ValueBinderFactory
96%
23/24
100%
2/2
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.value;
 17  
 
 18  
 import java.util.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.eclipse.swt.widgets.Button;
 22  
 import org.eclipse.swt.widgets.Label;
 23  
 import org.eclipse.swt.widgets.Spinner;
 24  
 import org.eclipse.swt.widgets.Text;
 25  
 import org.seasar.uruma.binding.value.binder.BrowserValueBinder;
 26  
 import org.seasar.uruma.binding.value.binder.ComboViewerValueBinder;
 27  
 import org.seasar.uruma.binding.value.binder.DateTimeValueBinder;
 28  
 import org.seasar.uruma.binding.value.binder.GenericValueBinder;
 29  
 import org.seasar.uruma.binding.value.binder.StatusLineManagerValueBinder;
 30  
 import org.seasar.uruma.binding.value.binder.TableValueBinder;
 31  
 import org.seasar.uruma.binding.value.binder.TableViewerValueBinder;
 32  
 import org.seasar.uruma.binding.value.binder.TreeViewerValueBinder;
 33  
 import org.seasar.uruma.core.UrumaMessageCodes;
 34  
 import org.seasar.uruma.log.UrumaLogger;
 35  
 import org.seasar.uruma.util.AssertionUtil;
 36  
 
 37  
 /**
 38  
  * {@link ValueBinder} を取得するためのファクトリクラスです。<br />
 39  
  * 
 40  
  * @author y-komori
 41  
  */
 42  0
 public class ValueBinderFactory implements UrumaMessageCodes {
 43  4
     private static final UrumaLogger logger = UrumaLogger
 44  
             .getLogger(ValueBinderFactory.class);
 45  
 
 46  4
     private static final Map<Class<?>, ValueBinder> binderMap = new HashMap<Class<?>, ValueBinder>();
 47  
 
 48  
     static {
 49  4
         addValueBinder(new GenericValueBinder<Label>(Label.class, "text"));
 50  4
         addValueBinder(new GenericValueBinder<Text>(Text.class, "text"));
 51  4
         addValueBinder(new GenericValueBinder<Spinner>(Spinner.class,
 52  
                 "selection"));
 53  4
         addValueBinder(new GenericValueBinder<Button>(Button.class, "selection"));
 54  4
         addValueBinder(new ComboViewerValueBinder());
 55  4
         addValueBinder(new TableViewerValueBinder());
 56  4
         addValueBinder(new TableValueBinder());
 57  4
         addValueBinder(new TreeViewerValueBinder());
 58  4
         addValueBinder(new StatusLineManagerValueBinder());
 59  4
         addValueBinder(new BrowserValueBinder());
 60  4
         addValueBinder(new DateTimeValueBinder());
 61  4
     }
 62  
 
 63  
     /**
 64  
      * <code>widgetClass</code> に対応する {@link ValueBinder} を取得します。<br />
 65  
      * 
 66  
      * @param widgetClass
 67  
      *            対応する {@link ValueBinder} を取得するための {@link Class} オブジェクト
 68  
      * @return <code>widgetClass</code> に対応する {@link ValueBinder}。見つからなかった場合は
 69  
      *         <code>null</code>
 70  
      */
 71  
     public static ValueBinder getValueBinder(final Class<?> widgetClass) {
 72  44
         ValueBinder binder = binderMap.get(widgetClass);
 73  44
         if (binder == null) {
 74  4
             logger.log(VALUE_BINDER_NOT_FOUND, widgetClass.getName());
 75  
         }
 76  44
         return binder;
 77  
     }
 78  
 
 79  
     /**
 80  
      * {@link ValueBinder} を登録します。<br />
 81  
      * 
 82  
      * @param valueBinder
 83  
      *            {@link ValueBinder} オブジェクト
 84  
      */
 85  
     public static void addValueBinder(final ValueBinder valueBinder) {
 86  48
         AssertionUtil.assertNotNull("valueBinder", valueBinder);
 87  48
         Class<?> widgetClass = valueBinder.getWidgetType();
 88  48
         AssertionUtil.assertNotNull("widgetClass", widgetClass);
 89  
 
 90  48
         binderMap.put(widgetClass, valueBinder);
 91  48
     }
 92  
 }