1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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://jakarta.apache.org/commons'>Jakarta 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 }