1
2
3
4
5
6
7
8
9
10
11
12
13
14
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://jakarta.apache.org/commons'>Jakarta Commons Team</a>,
36 * <a href='http://www.apache.org'>Apache Software Foundation</a>
37 */
38 public abstract class MappingDerivationStrategy {
39
40 /***
41 * Implementation that always uses bind time type mapping
42 */
43 public static final MappingDerivationStrategy USE_BIND_TIME_TYPE
44 = new MappingDerivationStrategy() {
45 public boolean useBindTimeTypeForMapping(Class propertyType, Class singluarPropertyType) {
46 return true;
47 }
48 };
49
50 /***
51 * Implementation that always uses introspection time type mapping
52 */
53 public static final MappingDerivationStrategy USE_INTROSPECTION_TIME_TYPE
54 = new MappingDerivationStrategy() {
55 public boolean useBindTimeTypeForMapping(Class propertyType, Class singluarPropertyType) {
56 return false;
57 }
58 };
59
60 /***
61 * The default Betwixt strategy.
62 */
63 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 }