1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.betwixt.strategy; 18 19 /** 20 * <p>Pluggable strategy determines whether introspection or bind time 21 * typing should be used when finding mappings. 22 * The type of a property is determined at introspection time but 23 * the actual type of the instance can differ at bind time (when the 24 * xml is actually being processed). This strategy is used to set 25 * (at a per-element level) whether the bind or introspection 26 * time type should be used to calculate the mapping to be used. 27 * </p> 28 * <p> 29 * <strong>Note:</strong> this strategy is intentionally course. 30 * Typically, the best approach is to use a custom strategy to set 31 * coursely grained rules (for example: all implemetations of 'IAnimal' 32 * use bind time type mapping) and then dot betwixt files to provide 33 * refinements. 34 * </p> 35 * @since 0.7 36 * @author <a href='http://commons.apache.org'>Apache Commons Team</a>, 37 * <a href='http://www.apache.org'>Apache Software Foundation</a> 38 */ 39 public abstract class MappingDerivationStrategy { 40 41 /** 42 * Implementation that always uses bind time type mapping 43 */ 44 public static final MappingDerivationStrategy USE_BIND_TIME_TYPE 45 = new MappingDerivationStrategy() { 46 public boolean useBindTimeTypeForMapping(Class propertyType, Class singluarPropertyType) { 47 return true; 48 } 49 }; 50 51 /** 52 * Implementation that always uses introspection time type mapping 53 */ 54 public static final MappingDerivationStrategy USE_INTROSPECTION_TIME_TYPE 55 = new MappingDerivationStrategy() { 56 public boolean useBindTimeTypeForMapping(Class propertyType, Class singluarPropertyType) { 57 return false; 58 } 59 }; 60 61 /** 62 * The default Betwixt strategy. 63 */ 64 public static final MappingDerivationStrategy DEFAULT = USE_BIND_TIME_TYPE; 65 66 /** 67 * Should bind time type be used for all elements of the given property type? 68 * @param propertyType <code>Class</code> typing the property, not null 69 * @param singluarPropertyType <code>Class</code> composing the collective 70 * or null if the property is not collective 71 * @return true if bind time type should be used for the mapping 72 */ 73 public abstract boolean useBindTimeTypeForMapping(Class propertyType, Class singluarPropertyType); 74 }