Coverage Report - org.kuali.rice.kns.uif.core.BindingInfo
 
Classes in this File Line Coverage Branch Coverage Complexity
BindingInfo
0%
0/41
0%
0/18
1.714
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation Licensed under the Educational Community
 3  
  * License, Version 1.0 (the "License"); you may not use this file except in
 4  
  * compliance with the License. You may obtain a copy of the License at
 5  
  * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law
 6  
  * or agreed to in writing, software distributed under the License is
 7  
  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 8  
  * KIND, either express or implied. See the License for the specific language
 9  
  * governing permissions and limitations under the License.
 10  
  */
 11  
 package org.kuali.rice.kns.uif.core;
 12  
 
 13  
 import java.io.Serializable;
 14  
 
 15  
 import org.apache.commons.lang.StringUtils;
 16  
 import org.kuali.rice.kns.uif.container.View;
 17  
 
 18  
 /**
 19  
  * Provides binding configuration for an DataBinding component (attribute or
 20  
  * collection)
 21  
  * <p>
 22  
  * From the binding configuration the binding path is determined (if not
 23  
  * manually set) and used to set the path in the UI or to get the value from the
 24  
  * model
 25  
  * </p>
 26  
  * 
 27  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 28  
  */
 29  
 public class BindingInfo implements Serializable {
 30  
     private static final long serialVersionUID = -7389398061672136091L;
 31  
 
 32  
     private boolean bindToForm;
 33  
     private boolean bindToMap;
 34  
 
 35  
     private String bindingName;
 36  
     private String bindByNamePrefix;
 37  
     private String bindingObjectPath;
 38  
 
 39  
     private String bindingPath;
 40  
 
 41  0
     public BindingInfo() {
 42  0
         bindToForm = false;
 43  0
         bindToMap = false;
 44  0
     }
 45  
 
 46  
     /**
 47  
      * Sets up some default binding properties based on the view configuration
 48  
      * and the component's property name
 49  
      * <p>
 50  
      * Sets the bindingName (if not set) to the given property name, and if the
 51  
      * binding object path has not been set uses the default binding object path
 52  
      * setup for the view
 53  
      * </p>
 54  
      * 
 55  
      * @param view
 56  
      *            - the view instance the component belongs to
 57  
      * @param propertyName
 58  
      *            - name of the property (relative to the parent object) the
 59  
      *            component binds to
 60  
      */
 61  
     public void setDefaults(View view, String propertyName) {
 62  0
         if (StringUtils.isBlank(bindingName)) {
 63  0
             bindingName = propertyName;
 64  
         }
 65  
 
 66  0
         if (StringUtils.isBlank(bindingObjectPath)) {
 67  0
             bindingObjectPath = view.getDefaultBindingObjectPath();
 68  
         }
 69  0
     }
 70  
 
 71  
     /**
 72  
      * Path to the property on the model the component binds to. Uses standard
 73  
      * dot notation for nested properties. If the binding path was manually set
 74  
      * it will be returned as it is, otherwise the path will be formed by using
 75  
      * the binding object path and the bind prefix
 76  
      * <p>
 77  
      * e.g. Property name 'foo' on a model would have binding path "foo", while
 78  
      * property name 'name' of the nested model property 'account' would have
 79  
      * binding path "account.name"
 80  
      * </p>
 81  
      * 
 82  
      * @return String binding path
 83  
      */
 84  
     public String getBindingPath() {
 85  0
         if (StringUtils.isNotBlank(bindingPath)) {
 86  0
             return bindingPath;
 87  
         }
 88  
 
 89  0
         String formedBindingPath = "";
 90  
 
 91  0
         if (!bindToForm && StringUtils.isNotBlank(bindingObjectPath)) {
 92  0
             formedBindingPath = bindingObjectPath;
 93  
         }
 94  
 
 95  0
         if (StringUtils.isNotBlank(bindByNamePrefix)) {
 96  0
             if (StringUtils.isNotBlank(formedBindingPath)) {
 97  0
                 formedBindingPath += ".";
 98  
             }
 99  0
             formedBindingPath += bindByNamePrefix;
 100  
         }
 101  
 
 102  0
         if (bindToMap) {
 103  0
             formedBindingPath += "['" + bindingName + "']";
 104  
         }
 105  
         else {
 106  0
             if (StringUtils.isNotBlank(formedBindingPath)) {
 107  0
                 formedBindingPath += ".";
 108  
             }
 109  0
             formedBindingPath += bindingName;
 110  
         }
 111  
 
 112  0
         return formedBindingPath;
 113  
     }
 114  
 
 115  
     /**
 116  
      * Setter for the binding path. Can be left blank in which the path will be
 117  
      * determined from the binding configuration
 118  
      * 
 119  
      * @param bindingPath
 120  
      */
 121  
     public void setBindingPath(String bindingPath) {
 122  0
         this.bindingPath = bindingPath;
 123  0
     }
 124  
 
 125  
     /**
 126  
      * Indicates whether the component binds directly to the form (that is its
 127  
      * bindingName gives a property available through the form), or whether is
 128  
      * binds through a nested form object. If bindToForm is false, it is assumed
 129  
      * the component binds to the object given by the form property whose path
 130  
      * is configured by bindingObjectPath.
 131  
      * 
 132  
      * @return boolean true if component binds directly to form, false if it
 133  
      *         binds to a nested object
 134  
      */
 135  
     public boolean isBindToForm() {
 136  0
         return this.bindToForm;
 137  
     }
 138  
 
 139  
     /**
 140  
      * Setter for the bind to form indicator
 141  
      * 
 142  
      * @param bindToForm
 143  
      */
 144  
     public void setBindToForm(boolean bindToForm) {
 145  0
         this.bindToForm = bindToForm;
 146  0
     }
 147  
 
 148  
     /**
 149  
      * Gives the name of the property that the component binds to. The name can
 150  
      * be nested but not the full path, just from the parent object or in the
 151  
      * case of binding directly to the form from the form object
 152  
      * <p>
 153  
      * If blank this will be set from the name field of the component
 154  
      * </p>
 155  
      * 
 156  
      * @return String name of the bind property
 157  
      */
 158  
     public String getBindingName() {
 159  0
         return this.bindingName;
 160  
     }
 161  
 
 162  
     /**
 163  
      * Setter for the bind property name
 164  
      * 
 165  
      * @param bindingName
 166  
      */
 167  
     public void setBindingName(String bindingName) {
 168  0
         this.bindingName = bindingName;
 169  0
     }
 170  
 
 171  
     /**
 172  
      * Prefix that will be used to form the binding path from the component
 173  
      * name. Typically used for nested collection properties
 174  
      * 
 175  
      * @return String binding prefix
 176  
      */
 177  
     public String getBindByNamePrefix() {
 178  0
         return this.bindByNamePrefix;
 179  
     }
 180  
 
 181  
     /**
 182  
      * Setter for the prefix to use for forming the binding path by name
 183  
      * 
 184  
      * @param bindByNamePrefix
 185  
      */
 186  
     public void setBindByNamePrefix(String bindByNamePrefix) {
 187  0
         this.bindByNamePrefix = bindByNamePrefix;
 188  0
     }
 189  
 
 190  
     /**
 191  
      * For attribute fields that do not belong to the default form object (given
 192  
      * by the view), this field specifies the path to the object (on the form)
 193  
      * the attribute does belong to.
 194  
      * <p>
 195  
      * e.g. Say we have an attribute field with property name 'number', that
 196  
      * belongs to the object given by the 'account' property on the form. The
 197  
      * form object path would therefore be set to 'account'. If the property
 198  
      * belonged to the object given by the 'document.header' property of the
 199  
      * form, the binding object path would be set to 'document.header'. Note if
 200  
      * the binding object path is not set for an attribute field (or any
 201  
      * <code>DataBinding</code> component), the binding object path configured
 202  
      * on the <code>View</code> will be used (unless bindToForm is set to true,
 203  
      * where is assumed the property is directly available from the form).
 204  
      * </p>
 205  
      * 
 206  
      * @return String path to object from form
 207  
      */
 208  
     public String getBindingObjectPath() {
 209  0
         return this.bindingObjectPath;
 210  
     }
 211  
 
 212  
     /**
 213  
      * Setter for the object path on the form
 214  
      * 
 215  
      * @param bindingObjectPath
 216  
      */
 217  
     public void setBindingObjectPath(String bindingObjectPath) {
 218  0
         this.bindingObjectPath = bindingObjectPath;
 219  0
     }
 220  
 
 221  
     /**
 222  
      * Indicates whether the parent object for the property that we are binding
 223  
      * to is a Map. If true the binding path will be adjusted to use the map key
 224  
      * syntax
 225  
      * 
 226  
      * @return boolean true if the property binds to a map, false if it does not
 227  
      */
 228  
     public boolean isBindToMap() {
 229  0
         return this.bindToMap;
 230  
     }
 231  
 
 232  
     /**
 233  
      * Setter for the bind to map indicator
 234  
      * 
 235  
      * @param bindToMap
 236  
      */
 237  
     public void setBindToMap(boolean bindToMap) {
 238  0
         this.bindToMap = bindToMap;
 239  0
     }
 240  
 
 241  
 }