Coverage Report - org.apache.commons.betwixt.strategy.MappingDerivationStrategy

Classes in this File Line Coverage Branch Coverage Complexity
MappingDerivationStrategy
100% 
N/A 
1

 1  1020
 /*
 2  
  * Copyright 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.strategy;
 17  
 
 18  
 /**
 19  
  * <p>Pluggable strategy determines whether introspection or bind time
 20  
  * typing should be used when finding mappings.
 21  
  * The type of a property is determined at introspection time but
 22  
  * the actual type of the instance can differ at bind time (when the 
 23  
  * xml is actually being processed). This strategy is used to set
 24  
  * (at a per-element level) whether the bind or introspection
 25  
  * time type should be used to calculate the mapping to be used.
 26  
  * </p>
 27  
  * <p>
 28  
  * <strong>Note:</strong> this strategy is intentionally course.
 29  
  * Typically, the best approach is to use a custom strategy to set
 30  
  * coursely grained rules (for example: all implemetations of 'IAnimal'
 31  
  * use bind time type mapping) and then dot betwixt files to provide
 32  
  * refinements.
 33  
  * </p>
 34  
  * @since 0.7
 35  
  * @author <a href='http://commons.apache.org'>Apache Commons Team</a>, 
 36  
  * <a href='http://www.apache.org'>Apache Software Foundation</a>
 37  
  */
 38  3060
 public abstract class MappingDerivationStrategy {
 39  
 
 40  
     /**
 41  
      * Implementation that always uses bind time type mapping
 42  
      */
 43  1020
     public static final MappingDerivationStrategy USE_BIND_TIME_TYPE 
 44  1020
                     = new MappingDerivationStrategy() {
 45  
         public boolean useBindTimeTypeForMapping(Class propertyType, Class singluarPropertyType) {
 46  21154
             return true;
 47  
         }
 48  
     };
 49  
 
 50  
     /**
 51  
      * Implementation that always uses introspection time type mapping
 52  
      */
 53  1020
     public static final MappingDerivationStrategy USE_INTROSPECTION_TIME_TYPE 
 54  1020
                     = new MappingDerivationStrategy() {
 55  
         public boolean useBindTimeTypeForMapping(Class propertyType, Class singluarPropertyType) {
 56  169
             return false;
 57  
         }
 58  
     };
 59  
     
 60  
     /**
 61  
      * The default Betwixt strategy.
 62  
      */
 63  1020
     public static final MappingDerivationStrategy DEFAULT = USE_BIND_TIME_TYPE;
 64  
     
 65  
     /**
 66  
      * Should bind time type be used for all elements of the given property type?
 67  
      * @param propertyType <code>Class</code> typing the property, not null
 68  
      * @param singluarPropertyType <code>Class</code> composing the collective
 69  
      * or null if the property is not collective
 70  
      * @return true if bind time type should be used for the mapping
 71  
      */
 72  
     public abstract boolean useBindTimeTypeForMapping(Class propertyType, Class singluarPropertyType);
 73  
 }