01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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://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 = new MappingDerivationStrategy() {
45: public boolean useBindTimeTypeForMapping(Class propertyType,
46: 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 = new MappingDerivationStrategy() {
55: public boolean useBindTimeTypeForMapping(Class propertyType,
56: 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(
74: Class propertyType, Class singluarPropertyType);
75: }
|