1 package org.apache.fulcrum.intake.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.Serializable;
23 import java.lang.reflect.Constructor;
24
25 import javax.xml.bind.annotation.XmlEnum;
26 import javax.xml.bind.annotation.XmlEnumValue;
27
28 import org.apache.fulcrum.intake.IntakeException;
29
30
31
32
33
34
35 @XmlEnum(String.class)
36 public enum FieldType implements Serializable
37 {
38 @XmlEnumValue("boolean") FIELD_BOOLEAN("boolean")
39 {
40 @Override
41 public Field<?> getInstance(XmlField f, Group g) throws IntakeException
42 {
43 return new BooleanField(f, g);
44 }
45 },
46 @XmlEnumValue("BigDecimal") FIELD_BIGDECIMAL("BigDecimal")
47 {
48 @Override
49 public Field<?> getInstance(XmlField f, Group g) throws IntakeException
50 {
51 return new BigDecimalField(f, g);
52 }
53 },
54 @XmlEnumValue("int") FIELD_INT("int")
55 {
56 @Override
57 public Field<?> getInstance(XmlField f, Group g) throws IntakeException
58 {
59 return new IntegerField(f, g);
60 }
61 },
62 @XmlEnumValue("float") FIELD_FLOAT("float")
63 {
64 @Override
65 public Field<?> getInstance(XmlField f, Group g) throws IntakeException
66 {
67 return new FloatField(f, g);
68 }
69 },
70 @Deprecated
71 @XmlEnumValue("FileItem") FIELD_FILEITEM("FileItem")
72 {
73 @Override
74 public Field<?> getInstance(XmlField f, Group g) throws IntakeException
75 {
76 return new UploadPartField(f, g);
77 }
78 },
79 @XmlEnumValue("UploadPart") FIELD_UPLOADPART("UploadPart")
80 {
81 @Override
82 public Field<?> getInstance(XmlField f, Group g) throws IntakeException
83 {
84 return new UploadPartField(f, g);
85 }
86 },
87 @XmlEnumValue("String") FIELD_STRING("String")
88 {
89 @Override
90 public Field<?> getInstance(XmlField f, Group g) throws IntakeException
91 {
92 return new StringField(f, g);
93 }
94 },
95 @XmlEnumValue("DateString") FIELD_DATESTRING("DateString")
96 {
97 @Override
98 public Field<?> getInstance(XmlField f, Group g) throws IntakeException
99 {
100 return new DateStringField(f, g);
101 }
102 },
103 @XmlEnumValue("ComboKey") FIELD_COMBOKEY("ComboKey")
104 {
105 @Override
106 public Field<?> getInstance(XmlField f, Group g) throws IntakeException
107 {
108 throw new IntakeException("An unsupported type has been specified for " +
109 f.getName() + " in group " + g.getIntakeGroupName() + " type = " + value());
110 }
111 },
112 @XmlEnumValue("double") FIELD_DOUBLE("double")
113 {
114 @Override
115 public Field<?> getInstance(XmlField f, Group g) throws IntakeException
116 {
117 return new DoubleField(f, g);
118 }
119 },
120 @XmlEnumValue("short") FIELD_SHORT("short")
121 {
122 @Override
123 public Field<?> getInstance(XmlField f, Group g) throws IntakeException
124 {
125 return new ShortField(f, g);
126 }
127 },
128 @XmlEnumValue("long") FIELD_LONG("long")
129 {
130 @Override
131 public Field<?> getInstance(XmlField f, Group g) throws IntakeException
132 {
133 return new LongField(f, g);
134 }
135 },
136 @XmlEnumValue("custom") FIELD_CUSTOM("custom")
137 {
138 @Override
139 public Field<?> getInstance(XmlField f, Group g) throws IntakeException
140 {
141 String fieldClass = f.getFieldClass();
142
143 if (fieldClass != null
144 && fieldClass.indexOf('.') == -1)
145 {
146 fieldClass = Field.defaultFieldPackage + fieldClass;
147 }
148
149 if (fieldClass != null)
150 {
151 Class<?> field;
152
153 try
154 {
155 field = Class.forName(fieldClass);
156 Constructor<?> constructor = field.getConstructor(XmlField.class, Group.class);
157
158 return (Field<?>) constructor.newInstance(f, g);
159 }
160 catch (ClassNotFoundException e)
161 {
162 throw new IntakeException(
163 "Could not load Field class("
164 + fieldClass + ")",
165 e);
166 }
167 catch (Exception e)
168 {
169 throw new IntakeException(
170 "Could not create new instance of Field("
171 + fieldClass + ")",
172 e);
173 }
174 }
175 else
176 {
177 throw new IntakeException(
178 "Custom field types must define a fieldClass");
179 }
180 }
181 };
182
183
184 private static final long serialVersionUID = -8563326491799622016L;
185
186
187 private String stringValue;
188
189
190
191
192
193
194 FieldType(String stringValue)
195 {
196 this.stringValue = stringValue;
197 }
198
199
200
201
202
203
204 public String value()
205 {
206 return stringValue;
207 }
208
209
210
211
212
213
214
215
216
217
218 public abstract Field<?> getInstance(XmlField f, Group g) throws IntakeException;
219 }