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