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