1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 package org.exolab.castor.builder.factory;
46
47 import java.security.InvalidParameterException;
48
49 import org.castor.xml.JavaNaming;
50 import org.castor.xml.JavaNamingImpl;
51 import org.castor.xml.JavaNamingNGImpl;
52 import org.exolab.castor.builder.SourceGeneratorConstants;
53 import org.exolab.castor.builder.info.CollectionInfo;
54 import org.exolab.castor.builder.info.CollectionInfoJ2;
55 import org.exolab.castor.builder.info.CollectionInfoJ2Collection;
56 import org.exolab.castor.builder.info.CollectionInfoJ2Set;
57 import org.exolab.castor.builder.info.CollectionInfoJ2SortedSet;
58 import org.exolab.castor.builder.info.CollectionInfoODMG30;
59 import org.exolab.castor.builder.info.FieldInfo;
60 import org.exolab.castor.builder.info.IdentityInfo;
61 import org.exolab.castor.builder.types.XSType;
62
63
64
65
66
67
68
69
70
71
72
73 public class FieldInfoFactory {
74
75 private String _default = null;
76
77
78
79
80
81 private boolean _extraMethods = false;
82
83
84 private String _referenceSuffix = null;
85
86
87 private boolean _bound = false;
88
89
90 private FieldMemberAndAccessorFactory _fieldMemberAndAccessorFactory;
91 private CollectionMemberAndAccessorFactory _collectionMemberAndAccessorFactory;
92 private CollectionJ2MemberAndAccessorFactory _collectionJ2MemberAndAccessorFactory;
93 private CollectionJ2NoIndexMemberAndAccessorFactory _collectionJ2NoIndexMemberAndAccessorFactory;
94 private CollectionODMG30MemberAndAccessorFactory _collectionODMG30MemberAndAccessorFactory;
95 private IdentityMemberAndAccessorFactory _identityMemberAndAccessorFactory;
96
97
98
99
100
101
102 private JavaNaming _javaNaming;
103
104
105
106
107
108 public FieldInfoFactory() {
109 this("vector");
110 }
111
112
113
114
115
116
117
118
119
120 public FieldInfoFactory(boolean useOldFieldNaming) {
121 this("vector", useOldFieldNaming);
122 }
123
124
125
126
127
128
129
130 public FieldInfoFactory(final String collectionName) {
131 this(collectionName, true);
132 }
133
134
135
136
137
138
139
140
141
142
143 public FieldInfoFactory(final String collectionName, boolean useOldFieldNaming) {
144 super();
145 if (!(collectionName.equals(SourceGeneratorConstants.FIELD_INFO_VECTOR)
146 || collectionName.equals(SourceGeneratorConstants.FIELD_INFO_ARRAY_LIST) || collectionName
147 .equals(SourceGeneratorConstants.FIELD_INFO_ODMG))) {
148 throw new IllegalArgumentException(collectionName + " is currently not a supported Java collection type.");
149 }
150 _default = collectionName;
151
152 if (useOldFieldNaming) {
153 _javaNaming = new JavaNamingImpl();
154 } else {
155 _javaNaming = new JavaNamingNGImpl();
156 }
157
158 this._fieldMemberAndAccessorFactory = new FieldMemberAndAccessorFactory(_javaNaming, useOldFieldNaming);
159 this._collectionMemberAndAccessorFactory = new CollectionMemberAndAccessorFactory(_javaNaming);
160 this._collectionJ2MemberAndAccessorFactory = new CollectionJ2MemberAndAccessorFactory(_javaNaming);
161 this._collectionJ2NoIndexMemberAndAccessorFactory = new CollectionJ2NoIndexMemberAndAccessorFactory(_javaNaming);
162 this._collectionODMG30MemberAndAccessorFactory = new CollectionODMG30MemberAndAccessorFactory(_javaNaming);
163 this._identityMemberAndAccessorFactory = new IdentityMemberAndAccessorFactory(_javaNaming);
164
165 }
166
167
168
169
170
171
172
173
174 public IdentityInfo createIdentity(final String name) {
175 IdentityInfo idInfo = new IdentityInfo(name, this._identityMemberAndAccessorFactory);
176 if (_bound) {
177 idInfo.setBound(_bound);
178 }
179 return idInfo;
180 }
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200 public CollectionInfo createCollection(final XSType contentType, final String name, final String elementName,
201 final JavaNaming javaNaming, final boolean usejava50) {
202 return createCollection(contentType, name, elementName, _default, javaNaming, usejava50);
203 }
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224 public CollectionInfo createCollection(final XSType contentType, final String name, final String elementName,
225 final String collectionName, final JavaNaming javaNaming, final boolean useJava50) {
226 String temp = collectionName;
227 if (temp == null || temp.length() == 0) {
228 temp = _default;
229 }
230
231 final CollectionInfo cInfo;
232 if (temp.equalsIgnoreCase(SourceGeneratorConstants.FIELD_INFO_VECTOR)) {
233 cInfo = new CollectionInfo(contentType, name, elementName, useJava50,
234 this._collectionMemberAndAccessorFactory, this._fieldMemberAndAccessorFactory);
235 } else if (temp.equalsIgnoreCase(SourceGeneratorConstants.FIELD_INFO_ARRAY_LIST)) {
236 cInfo = new CollectionInfoJ2(contentType, name, elementName, "arraylist", useJava50,
237 this._collectionJ2MemberAndAccessorFactory, this._fieldMemberAndAccessorFactory);
238 } else if (temp.equalsIgnoreCase(SourceGeneratorConstants.FIELD_INFO_ODMG)) {
239 cInfo = new CollectionInfoODMG30(contentType, name, elementName, useJava50,
240 this._collectionODMG30MemberAndAccessorFactory, this._fieldMemberAndAccessorFactory);
241 } else if (temp.equalsIgnoreCase(SourceGeneratorConstants.FIELD_INFO_COLLECTION)) {
242 cInfo = new CollectionInfoJ2Collection(contentType, name, elementName, useJava50,
243 this._collectionJ2NoIndexMemberAndAccessorFactory, this._fieldMemberAndAccessorFactory);
244 } else if (temp.equalsIgnoreCase(SourceGeneratorConstants.FIELD_INFO_SET)) {
245 cInfo = new CollectionInfoJ2Set(contentType, name, elementName, useJava50,
246 this._collectionJ2NoIndexMemberAndAccessorFactory, this._fieldMemberAndAccessorFactory);
247 } else if (temp.equalsIgnoreCase(SourceGeneratorConstants.FIELD_INFO_SORTED_SET)) {
248 cInfo = new CollectionInfoJ2SortedSet(contentType, name, elementName, useJava50,
249 this._collectionJ2NoIndexMemberAndAccessorFactory, this._fieldMemberAndAccessorFactory);
250 } else {
251 throw new InvalidParameterException("Unrecognized collection type: " + temp);
252 }
253
254
255
256
257 cInfo.setCreateExtraMethods(_extraMethods);
258 if (_referenceSuffix != null) {
259 cInfo.setReferenceMethodSuffix(_referenceSuffix);
260 }
261 if (_bound) {
262 cInfo.setBound(true);
263 }
264 return cInfo;
265 }
266
267
268
269
270
271
272
273
274
275
276
277 public FieldInfo createFieldInfo(final XSType type, final String name) {
278 FieldInfo fieldInfo = new FieldInfo(type, name, this._fieldMemberAndAccessorFactory);
279 if (_bound) {
280 fieldInfo.setBound(true);
281 }
282 return fieldInfo;
283 }
284
285
286
287
288
289
290
291
292 public final void setBoundProperties(final boolean bound) {
293 _bound = bound;
294 }
295
296
297
298
299
300
301
302
303
304
305 public final void setCreateExtraMethods(final boolean extraMethods) {
306 _extraMethods = extraMethods;
307 }
308
309
310
311
312
313
314
315
316
317
318
319 public final void setReferenceMethodSuffix(final String suffix) {
320 _referenceSuffix = suffix;
321 }
322 }