Coverage Report - org.apache.commons.betwixt.BindingConfiguration

Classes in this File Line Coverage Branch Coverage Complexity
BindingConfiguration
92% 
N/A 
1

 1  
 /*
 2  
  * Copyright 2001-2004 The Apache Software Foundation.
 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, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */ 
 16  
 package org.apache.commons.betwixt;
 17  
 
 18  
 import java.io.Serializable;
 19  
 
 20  
 import org.apache.commons.betwixt.strategy.DefaultObjectStringConverter;
 21  
 import org.apache.commons.betwixt.strategy.IdStoringStrategy;
 22  
 import org.apache.commons.betwixt.strategy.ObjectStringConverter;
 23  
 import org.apache.commons.betwixt.strategy.ValueSuppressionStrategy;
 24  
 
 25  
 /** <p>Stores mapping phase binding configuration.</p>
 26  
   *
 27  
   * <p>There are two phase in Betwixt's processing.
 28  
   * The first phase is the introspection of the bean.
 29  
   * Strutural configuration settings effect this phase.
 30  
   * The second phase comes when Betwixt dynamically uses
 31  
   * reflection to execute the mapping.
 32  
   * This object stores configuration settings pertaining 
 33  
   * to the second phase.</p>
 34  
   *
 35  
   * <p>These common settings have been collected into one class
 36  
   * to make round tripping easier since the same <code>BindingConfiguration</code>
 37  
   * can be shared.</p> 
 38  
   *
 39  
   * @author <a href="mailto:rdonkin@apache.org">Robert Burrell Donkin</a>
 40  
   * @since 0.5
 41  
   */
 42  
 public class BindingConfiguration implements Serializable {
 43  
 
 44  
     /** Should <code>ID</code>'s and <code>IDREF</code> be used cross-reference matching objects? */
 45  3597
     private boolean mapIDs = true;
 46  
     /** Converts objects &lt-&gt; strings */
 47  
     private ObjectStringConverter objectStringConverter;
 48  
     /** The name of the classname attribute used when creating derived beans */
 49  3597
     private String classNameAttribute = "className";
 50  
     /** Strategy for suppressing attributes with certain values when writing */
 51  3597
     private ValueSuppressionStrategy valueSuppressionStrategy  = ValueSuppressionStrategy.DEFAULT;
 52  
     /** Strategy for storing and accessing ID values */
 53  3597
     private IdStoringStrategy idStoringStrategy = IdStoringStrategy.createDefault();
 54  
     
 55  
     /**
 56  
      * Constructs a BindingConfiguration with default properties.
 57  
      */
 58  
     public BindingConfiguration() {
 59  3584
         this(new DefaultObjectStringConverter(), true);
 60  3584
     }
 61  
     
 62  
     /** 
 63  
      * Constructs a BindingConfiguration
 64  
      * @param objectStringConverter the <code>ObjectStringConverter</code>
 65  
      * to be used to convert Objects &lt;-&gt; Strings
 66  
      * @param mapIDs should <code>ID</code>'s and <code>IDREF</code> be used to cross-reference
 67  
      */ 
 68  3597
     public BindingConfiguration(ObjectStringConverter objectStringConverter, boolean mapIDs) {
 69  3597
         setObjectStringConverter(objectStringConverter);
 70  3597
         setMapIDs(mapIDs);
 71  3597
     }
 72  
     
 73  
     /**
 74  
       * Gets the Object &lt;-&gt; String converter.
 75  
       * @return the ObjectStringConverter to use, not null
 76  
       */
 77  
     public ObjectStringConverter getObjectStringConverter() {
 78  20878
         return objectStringConverter;
 79  
     }
 80  
     
 81  
     /**
 82  
       * Sets the Object &lt;-&gt; String converter.
 83  
       * @param objectStringConverter the ObjectStringConverter to be used, not null
 84  
       */
 85  
     public void setObjectStringConverter(ObjectStringConverter objectStringConverter) {
 86  3623
         this.objectStringConverter = objectStringConverter;
 87  3623
     }
 88  
     
 89  
     /** 
 90  
      * Should <code>ID</code>'s and <code>IDREF</code> attributes 
 91  
      * be used to cross-reference matching objects? 
 92  
      *
 93  
      * @return true if <code>ID</code> and <code>IDREF</code> 
 94  
      * attributes should be used to cross-reference instances
 95  
      */
 96  
     public boolean getMapIDs() {
 97  30687
         return mapIDs;
 98  
     }
 99  
     
 100  
     /**
 101  
      *Should <code>ID</code>'s and <code>IDREF</code> attributes 
 102  
      * be used to cross-reference matching objects? 
 103  
      *
 104  
      * @param mapIDs pass true if <code>ID</code>'s should be used to cross-reference
 105  
      */
 106  
     public void setMapIDs(boolean mapIDs) {
 107  5416
         this.mapIDs = mapIDs;
 108  5416
     }        
 109  
     
 110  
     /**
 111  
      * The name of the attribute which can be specified in the XML to override the
 112  
      * type of a bean used at a certain point in the schema.
 113  
      *
 114  
      * <p>The default value is 'className'.</p>
 115  
      * 
 116  
      * @return The name of the attribute used to overload the class name of a bean
 117  
      */
 118  
     public String getClassNameAttribute() {
 119  3572
         return classNameAttribute;
 120  
     }
 121  
 
 122  
     /**
 123  
      * Sets the name of the attribute which can be specified in 
 124  
      * the XML to override the type of a bean used at a certain 
 125  
      * point in the schema.
 126  
      *
 127  
      * <p>The default value is 'className'.</p>
 128  
      * 
 129  
      * @param classNameAttribute The name of the attribute used to overload the class name of a bean
 130  
      */
 131  
     public void setClassNameAttribute(String classNameAttribute) {
 132  0
         this.classNameAttribute = classNameAttribute;
 133  0
     }
 134  
     
 135  
     
 136  
     /**
 137  
      * Gets the <code>ValueSuppressionStrategy</code>.
 138  
      * This is used to control the expression of attributes with certain values.
 139  
      * @since 0.7
 140  
      * @return <code>ValueSuppressionStrategy</code>, not null
 141  
      */
 142  
     public ValueSuppressionStrategy getValueSuppressionStrategy() {
 143  24913
         return valueSuppressionStrategy;
 144  
     }
 145  
     
 146  
     /**
 147  
      * Sets the <code>ValueSuppressionStrategy</code>.
 148  
      * This is used to control the expression of attributes with certain values.
 149  
      * @since 0.7
 150  
      * @param valueSuppressionStrategy <code>ValueSuppressionStrategy</code>, not null
 151  
      */
 152  
     public void setValueSuppressionStrategy(
 153  
             ValueSuppressionStrategy valueSuppressionStrategy) {
 154  52
         this.valueSuppressionStrategy = valueSuppressionStrategy;
 155  52
     }
 156  
     
 157  
     /**
 158  
      * Gets the strategy used to manage storage and retrieval of id's.
 159  
      * 
 160  
      * @since 0.7
 161  
      * @return Returns the <code>IdStoringStrategy</code>, not null
 162  
      */
 163  
     public IdStoringStrategy getIdMappingStrategy() {
 164  10775
         return idStoringStrategy;
 165  
     }
 166  
 
 167  
     /**
 168  
      * Sets the strategy used to manage storage and retrieval of id's.
 169  
      * 
 170  
      * @since 0.7
 171  
      * @param idMappingStrategy
 172  
      *            <code>IdStoringStrategy</code> to be set, not null
 173  
      */
 174  
     public void setIdMappingStrategy(IdStoringStrategy idMappingStrategy) {
 175  78
         this.idStoringStrategy = idMappingStrategy;
 176  78
     }
 177  
 }