Coverage Report - org.seasar.uruma.binding.value.ValueBindingSupport
 
Classes in this File Line Coverage Branch Coverage Complexity
ValueBindingSupport
89%
25/28
62%
5/8
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.List;
 19  
 
 20  
 import org.seasar.framework.beans.PropertyDesc;
 21  
 import org.seasar.uruma.binding.value.command.ExportSelectionCommand;
 22  
 import org.seasar.uruma.binding.value.command.ExportValueCommand;
 23  
 import org.seasar.uruma.binding.value.command.ImportSelectionCommand;
 24  
 import org.seasar.uruma.binding.value.command.ImportValueCommand;
 25  
 import org.seasar.uruma.context.PartContext;
 26  
 import org.seasar.uruma.context.WidgetHandle;
 27  
 import org.seasar.uruma.core.UrumaMessageCodes;
 28  
 import org.seasar.uruma.desc.FormDesc;
 29  
 import org.seasar.uruma.exception.BindingException;
 30  
 
 31  
 /**
 32  
  * ValueBinding を実現するためのクラスです。<br />
 33  
  * 
 34  
  * @author y-komori
 35  
  */
 36  0
 public class ValueBindingSupport {
 37  4
     private static final ImportValueCommand IMPORT_VALUE_COMMAND = new ImportValueCommand();
 38  
 
 39  4
     private static final ExportValueCommand EXPORT_VALUE_COMMAND = new ExportValueCommand();
 40  
 
 41  4
     private static final ImportSelectionCommand IMPORT_SELECTION_COMMAND = new ImportSelectionCommand();
 42  
 
 43  4
     private static final ExportSelectionCommand EXPORT_SELECTION_COMMAND = new ExportSelectionCommand();
 44  
 
 45  
     /**
 46  
      * ウィジットから {@link PartContext} の保持するアクションコンポーネントに対して、バリュー・バインディングを行います。<br />
 47  
      * 
 48  
      * @param context
 49  
      *            {@link PartContext} オブジェクト
 50  
      */
 51  
     public static void importValue(final PartContext context) {
 52  44
         dealFields(context, IMPORT_VALUE_COMMAND);
 53  44
     }
 54  
 
 55  
     /**
 56  
      * {@link PartContext} の保持するアクションコンポーネントから、ウィジットへバリュー・バインディングを行います。<br />
 57  
      * 
 58  
      * @param context
 59  
      *            {@link PartContext} オブジェクト
 60  
      */
 61  
     public static void exportValue(final PartContext context) {
 62  148
         dealFields(context, EXPORT_VALUE_COMMAND);
 63  148
     }
 64  
 
 65  
     /**
 66  
      * ウィジットから {@link PartContext} の保持するアクションコンポーネントに対して、セレクション・バインディングを行います。<br />
 67  
      * 
 68  
      * @param context
 69  
      *            {@link PartContext} オブジェクト
 70  
      */
 71  
     public static void importSelection(final PartContext context) {
 72  44
         dealFields(context, IMPORT_SELECTION_COMMAND);
 73  44
     }
 74  
 
 75  
     /**
 76  
      * {@link PartContext} の保持するアクションコンポーネントから、ウィジットへセレクション・バインディングを行います。<br />
 77  
      * 
 78  
      * @param context
 79  
      *            {@link PartContext} オブジェクト
 80  
      */
 81  
     public static void exportSelection(final PartContext context) {
 82  148
         dealFields(context, EXPORT_SELECTION_COMMAND);
 83  148
     }
 84  
 
 85  
     private static void dealFields(final PartContext context,
 86  
             final BindingCommand command) {
 87  384
         Object form = context.getFormObject();
 88  384
         FormDesc formDesc = context.getFormDesc();
 89  384
         if (form == null || formDesc == null) {
 90  0
             return;
 91  
         }
 92  
 
 93  384
         List<PropertyDesc> targetProperties = command
 94  
                 .getTargetPropertyDescs(formDesc);
 95  384
         for (PropertyDesc pd : targetProperties) {
 96  36
             String id = command.getId(pd.getField());
 97  
 
 98  36
             WidgetHandle handle = context.getWidgetHandle(id);
 99  36
             if (handle != null) {
 100  36
                 Object widget = handle.getWidget();
 101  36
                 command.doBind(widget, form, pd, handle.getUiComponent());
 102  36
             } else {
 103  0
                 throw new BindingException(UrumaMessageCodes.WIDGET_NOT_FOUND,
 104  
                         id, form.getClass(), pd.getField());
 105  
             }
 106  36
         }
 107  384
     }
 108  
 }