1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.betwixt.strategy;
20
21 import org.apache.commons.betwixt.IntrospectionConfiguration;
22
23 /***
24 * Strategy for binding simple types.
25 * Simple types (in xml) have no attributes or child elements.
26 * For Betwixt, these are converted to and from strings
27 * and these strings used to populate either attributes or element body's.
28 * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
29 * @version $Revision: 438373 $
30 */
31 public abstract class SimpleTypeMapper {
32
33 /***
34 * Enumerates binding options for simple types.
35 * Simple types (in xml) have no attributes or child elements.
36 * For Betwixt, these are converted to and from strings
37 * and these strings used to populate either attributes or element body's.
38 * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
39 * @version $Revision: 438373 $
40 */
41 public static class Binding {
42 public static final Binding ELEMENT = new Binding(1);
43 public static final Binding ATTRIBUTE = new Binding(2);
44
45 private static final int ELEMENT_CODE = 1;
46 private static final int ATTRIBUTE_CODE = 2;
47
48 private int code;
49 private Binding(int code) {
50 this.code = code;
51 }
52
53
54 /***
55 * Equals compatible with the enumeration.
56 */
57 public boolean equals( Object obj ) {
58 boolean result = false;
59 if ( obj == this ) {
60 result = true;
61 }
62 return result;
63 }
64
65 /***
66 * Implementation compatible with equals
67 */
68 public int hashCode() {
69 return code;
70 }
71
72 /***
73 * Generate something appropriate for logging.
74 */
75 public String toString() {
76 String result = "[Binding]";
77 switch (code) {
78 case ELEMENT_CODE:
79 result = "[Binding: ELEMENT]";
80 break;
81
82 case ATTRIBUTE_CODE:
83 result = "[Binding: ATTRIBUTE]";
84 break;
85 }
86 return result;
87 }
88 }
89
90 /***
91 * <p>Specifies the binding of a simple type.
92 * </p><p>
93 * <strong>Note:</strong> the xml name to which this property will be bound
94 * cannot be known at this stage (since it depends
95 * </p>
96 * @param propertyName the name of the property (to be bound)
97 * @param propertyType the type of the property (to be bound)
98 * @param configuration the current IntrospectionConfiguration
99 */
100 public abstract SimpleTypeMapper.Binding bind(
101 String propertyName,
102 Class propertyType,
103 IntrospectionConfiguration configuration);
104 }