1
|
|
/*
|
2
|
|
* JBind
|
3
|
|
*
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
5
|
|
*
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
8
|
|
* 'Apache Software License V 1.1'.
|
9
|
|
*/
|
10
|
|
package org.jbind.xml.schema.compiler;
|
11
|
|
|
12
|
|
import java.util.ListIterator;
|
13
|
|
|
14
|
|
import org.jbind.util.collection.TransformingIterator;
|
15
|
|
import org.jbind.util.collection.TransformingListIterator;
|
16
|
|
import org.jbind.util.reflect.ReflectUtil;
|
17
|
|
import org.jbind.xml.Config;
|
18
|
|
import org.jbind.xml.base.IBindingAttributes;
|
19
|
|
import org.jbind.xml.base.IRef;
|
20
|
|
import org.jbind.xml.core.base.ITextContentProvider;
|
21
|
|
import org.jbind.xml.core.bridge.IXPathMethod;
|
22
|
|
import org.jbind.xml.core.cmp.IBinding;
|
23
|
|
import org.jbind.xml.core.cmp.IComponent;
|
24
|
|
import org.jbind.xml.core.content.IAttrRefOrDecl;
|
25
|
|
import org.jbind.xml.core.content.IElemRefOrDecl;
|
26
|
|
import org.jbind.xml.core.data.IAnyListTypeData;
|
27
|
|
import org.jbind.xml.core.data.IAnyTypeData;
|
28
|
|
import org.jbind.xml.core.data.IDataCreator;
|
29
|
|
import org.jbind.xml.core.data.IDataVisitor;
|
30
|
|
import org.jbind.xml.core.data.ISimpleData;
|
31
|
|
import org.jbind.xml.core.type.IAnyType;
|
32
|
|
import org.jbind.xml.core.type.IListType;
|
33
|
|
import org.jbind.xml.instance.data.AnyTypeData;
|
34
|
|
import org.jbind.xml.msg.XmlException;
|
35
|
|
import org.jbind.xml.msg.XmlMessages;
|
36
|
|
import org.jbind.xml.schema.cmp.W3CTypes;
|
37
|
|
|
38
|
|
public final class DataClassCartridge extends DataCartridge {
|
39
|
|
|
40
|
|
private static final String DATA_CREATOR = "DataCreator_";
|
41
|
|
|
42
|
3
|
public DataClassCartridge() {
|
43
|
3
|
super("dataClass", "", "Data");
|
44
|
|
}
|
45
|
|
|
46
|
466
|
public IBinding createGlobalAnyTypeBinding(IComponent aComponent, String aRootPackage, boolean aUseBuiltInClassesOnly) throws XmlException {
|
47
|
466
|
MyGlobalBinding b = new MyGlobalBinding(aRootPackage, this, aComponent);
|
48
|
466
|
initDataCreation(aComponent, b, aUseBuiltInClassesOnly);
|
49
|
466
|
return b;
|
50
|
|
}
|
51
|
235
|
public IBinding createInnerAnyTypeBinding(IComponent aComponent, IBinding aParentBinding, boolean aUseBuiltInClassesOnly) throws XmlException {
|
52
|
235
|
String typeName = aComponent.getLocalStringBindingAttribute(IBindingAttributes.NAME);
|
53
|
235
|
if (null == typeName) {
|
54
|
233
|
typeName = ((IAnyType)aComponent).getRoleName();
|
55
|
|
}
|
56
|
235
|
MyInnerBinding b = new MyInnerBinding(aParentBinding, this, aComponent, typeName);
|
57
|
235
|
initDataCreation(aComponent, b, aUseBuiltInClassesOnly);
|
58
|
235
|
return b;
|
59
|
|
}
|
60
|
|
|
61
|
701
|
private void initDataCreation(IComponent aComponent, IMyBinding aBinding, boolean aUseBuiltInClassesOnly) throws XmlException {
|
62
|
701
|
IAnyType type = (IAnyType)aComponent;
|
63
|
701
|
if (type.isAbstract()) {
|
64
|
14
|
return;
|
65
|
|
}
|
66
|
687
|
if (aUseBuiltInClassesOnly) {
|
67
|
446
|
for (IAnyType t = type; true; t = t.getBaseType()) {
|
68
|
1054
|
IDataCreator creator = t.getDataCreator();
|
69
|
1054
|
if (null != creator) {
|
70
|
446
|
aBinding.setDataCreator(creator);
|
71
|
446
|
type.setDataCreator(creator);
|
72
|
446
|
break;
|
73
|
|
}
|
74
|
|
}
|
75
|
|
} else {
|
76
|
241
|
String pckg = aBinding.getPackage();
|
77
|
241
|
String className = (null != pckg) ? pckg + "." + aBinding.getName('$') : aBinding.getName('$');
|
78
|
241
|
try {
|
79
|
241
|
Class clazz = null;
|
80
|
241
|
if (Config.instance.useContextClassLoader()) {
|
81
|
0
|
try {
|
82
|
0
|
clazz = Class.forName(className + "$" + DATA_CREATOR, true, Thread.currentThread().getContextClassLoader());
|
83
|
|
} catch (ClassNotFoundException e) {
|
84
|
0
|
clazz = Class.forName(className + "$" + DATA_CREATOR);
|
85
|
|
}
|
86
|
|
} else {
|
87
|
241
|
try {
|
88
|
241
|
clazz = Class.forName(className + "$" + DATA_CREATOR);
|
89
|
|
} catch (ClassNotFoundException e) {
|
90
|
0
|
clazz = Class.forName(className + "$" + DATA_CREATOR, true, Thread.currentThread().getContextClassLoader());
|
91
|
|
}
|
92
|
|
}
|
93
|
241
|
IDataCreator creator = (IDataCreator)clazz.newInstance();
|
94
|
241
|
aBinding.setDataCreator(creator);
|
95
|
241
|
type.setDataCreator(creator);
|
96
|
|
} catch (ClassNotFoundException e) {
|
97
|
0
|
throw new XmlException(XmlMessages.bindingClassNotFound(className, aComponent));
|
98
|
|
} catch (InstantiationException e) {
|
99
|
0
|
throw new XmlException(XmlMessages.bindingInstantiation(className, aComponent));
|
100
|
|
} catch (IllegalAccessException e) {
|
101
|
0
|
throw new XmlException(XmlMessages.bindingIllegalAccess(className, aComponent));
|
102
|
|
}
|
103
|
|
}
|
104
|
|
}
|
105
|
|
|
106
|
|
private static interface IMyBinding extends IBinding {
|
107
|
|
IDataCreator getDataCreator();
|
108
|
|
void setDataCreator(IDataCreator aCreator);
|
109
|
|
}
|
110
|
|
|
111
|
|
private static class MyInnerBinding extends InnerBinding implements IMyBinding {
|
112
|
|
|
113
|
|
private IDataCreator myDataCreator = null;
|
114
|
235
|
MyInnerBinding(IBinding aParentBinding, ICartridge aCartridge, IComponent aComponent, String aBindingName) {
|
115
|
235
|
super(aParentBinding, aCartridge, aComponent, aBindingName);
|
116
|
|
}
|
117
|
0
|
public IDataCreator getDataCreator() {
|
118
|
0
|
return myDataCreator;
|
119
|
|
}
|
120
|
235
|
public void setDataCreator(IDataCreator aCreator) {
|
121
|
235
|
myDataCreator = aCreator;
|
122
|
|
}
|
123
|
|
}
|
124
|
|
|
125
|
|
private static class MyGlobalBinding extends GlobalBinding implements IMyBinding {
|
126
|
|
|
127
|
|
private IDataCreator myDataCreator = null;
|
128
|
466
|
MyGlobalBinding(String aRootPackage, ICartridge aCartridge, IComponent aComponent) throws XmlException {
|
129
|
466
|
super(aRootPackage, aCartridge, aComponent);
|
130
|
|
}
|
131
|
0
|
public IDataCreator getDataCreator() {
|
132
|
0
|
return myDataCreator;
|
133
|
|
}
|
134
|
452
|
public void setDataCreator(IDataCreator aCreator) {
|
135
|
452
|
myDataCreator = aCreator;
|
136
|
|
}
|
137
|
|
}
|
138
|
|
|
139
|
|
private static String ourBuiltInPackage = null;
|
140
|
|
static {
|
141
|
3
|
String s = AnyTypeData.class.getName();
|
142
|
3
|
ourBuiltInPackage = s.substring(0, s.lastIndexOf('.'));
|
143
|
|
}
|
144
|
|
|
145
|
282
|
protected String doGetBuiltInPackage() {
|
146
|
282
|
return ourBuiltInPackage;
|
147
|
|
}
|
148
|
51
|
protected String interfaceOrClass() {
|
149
|
51
|
return "class";
|
150
|
|
}
|
151
|
437
|
protected boolean treatMethods(IAnyType aType) {
|
152
|
437
|
return !aType.isAbstract();
|
153
|
|
}
|
154
|
877
|
protected boolean treatInherited() {
|
155
|
877
|
return true;
|
156
|
|
}
|
157
|
|
|
158
|
437
|
protected String declaration(IAnyType aType) {
|
159
|
437
|
String stringPackage = getBinding(aType).getPackage();
|
160
|
437
|
return new StringBuffer().append(aType.isAbstract() ? "abstract " : "").append(staticOrPublic()).append(" class ").append(getInnerName(aType)).append(" extends ").append(behaviourBaseClass(aType, stringPackage)).append((null != aType.getBindings()[getBehaviourClassCartridge().getCartridgeNo()]) ? "" : (" implements " + getDataInterfaceCartridge().getUsableFqName(aType))).toString();
|
161
|
|
}
|
162
|
|
|
163
|
437
|
public String begin(IAnyType aType) {
|
164
|
437
|
String res = null;
|
165
|
437
|
if (!aType.isAbstract()) {
|
166
|
431
|
StringBuffer sb = new StringBuffer().append("public static class ").append(DATA_CREATOR).append(" implements ").append(IDataCreator.class.getName()).append(" {\n").append("\tpublic ").append(IAnyTypeData.class.getName()).append(" newData() { return new ").append(getInnerName(aType)).append("(); }\n").append("}\n");
|
167
|
431
|
if (aType.isComplex()) {
|
168
|
297
|
sb.append("protected void doAcceptStarts_(").append(IDataVisitor.class.getName()).append(" aVisitor) {\n").append("\taVisitor.visitAnyComplex").append(aType.isSimple() ? "SC" : "CC").append("DataStarts(this);\n").append("}\n");
|
169
|
297
|
sb.append("protected void doAcceptEnds_(").append(IDataVisitor.class.getName()).append(" aVisitor) {\n").append("\taVisitor.visitAnyComplex").append(aType.isSimple() ? "SC" : "CC").append("DataEnds(this);\n").append("}\n");
|
170
|
|
}
|
171
|
431
|
if ((aType.getBaseType() == W3CTypes.anyListType) && ((IListType)aType.getSimpleContentType()).getItemType().isInstanceType(W3CTypes.idRef)) {
|
172
|
2
|
sb.append("public java.util.Iterator iterReferencedData() {\n").append("\treturn iterReferencedData_(\"cnt:\");\n").append("}\n");
|
173
|
|
}
|
174
|
431
|
res = sb.toString();
|
175
|
|
}
|
176
|
437
|
return res;
|
177
|
|
}
|
178
|
|
|
179
|
254
|
protected String elementGetter(IAnyType aType, IElemRefOrDecl aRefOrDecl, MethodVariant aPropertyVariant, boolean aUseDataClass) {
|
180
|
254
|
IRef ref = aRefOrDecl.getGlobalRef();
|
181
|
254
|
String propertyTypeName = simpleTypeName(aRefOrDecl.getType(), aUseDataClass);
|
182
|
254
|
StringBuffer sb = new StringBuffer().append("// element getter\n").append(aPropertyVariant.method(propertyTypeName, "get", propertyName(aRefOrDecl))).append("() {\n").append("\tjava.util.Iterator i = getImpl_().iterElementData(\"").append(ref.getNamespace()).append("\", \"").append(ref.getLocalPart()).append("\");\n").append("\tObject o = i.hasNext() ? i.next() : null;\n");
|
183
|
254
|
if (!aUseDataClass && (null != aRefOrDecl.getType().getSimpleStorageType())) {
|
184
|
23
|
String dataTypeName = interfaceName(aRefOrDecl.getType());
|
185
|
23
|
sb.append("\treturn ((").append(dataTypeName).append(")o).get").append(ssoAccessor(aRefOrDecl.getType().getSimpleStorageType())).append("();\n");
|
186
|
|
} else {
|
187
|
231
|
sb.append("\treturn (").append(propertyTypeName).append(")o;\n");
|
188
|
|
}
|
189
|
254
|
sb.append("}");
|
190
|
254
|
return sb.toString();
|
191
|
|
}
|
192
|
|
|
193
|
360
|
protected String attributeGetter(IAnyType aType, IAttrRefOrDecl aRefOrDecl, MethodVariant aPropertyVariant, boolean aUseDataClass) {
|
194
|
360
|
IRef ref = aRefOrDecl.getGlobalRef();
|
195
|
360
|
String propertyTypeName = simpleTypeName(aRefOrDecl.getType(), aUseDataClass);
|
196
|
360
|
StringBuffer sb = new StringBuffer().append("// attribute getter\n").append(aPropertyVariant.method(propertyTypeName, "get", propertyName(aRefOrDecl))).append("() {\n").append("\tObject o = getImpl_().getAttributeData(\"").append(ref.getNamespace()).append("\", \"").append(ref.getLocalPart()).append("\");\n");
|
197
|
360
|
if (!aUseDataClass && (null != aRefOrDecl.getType().getSimpleStorageType())) {
|
198
|
360
|
if (!aRefOrDecl.getType().getSimpleStorageType().isPrimitive()) {
|
199
|
325
|
sb.append("\tif (o == null) return null;\n");
|
200
|
|
}
|
201
|
360
|
String dataTypeName = interfaceName(aRefOrDecl.getType());
|
202
|
360
|
sb.append("\treturn ((").append(dataTypeName).append(")o).get").append(ssoAccessor(aRefOrDecl.getType().getSimpleStorageType())).append("();\n");
|
203
|
|
} else {
|
204
|
0
|
sb.append("\treturn (").append(propertyTypeName).append(")o;\n");
|
205
|
|
}
|
206
|
360
|
sb.append("}");
|
207
|
360
|
return sb.toString();
|
208
|
|
}
|
209
|
|
|
210
|
24
|
protected String elementChecker(IAnyType aType, IElemRefOrDecl aRefOrDecl, MethodVariant aPropertyVariant) {
|
211
|
24
|
IRef ref = aRefOrDecl.getGlobalRef();
|
212
|
24
|
return new StringBuffer().append("// element checker\n").append(aPropertyVariant.method("boolean", "has", propertyName(aRefOrDecl))).append("() {\n").append("\tjava.util.Iterator i = getImpl_().iterElementData(\"").append(ref.getNamespace()).append("\", \"").append(ref.getLocalPart()).append("\");\n").append("\treturn i.hasNext();\n").append("}").toString();
|
213
|
|
}
|
214
|
|
|
215
|
106
|
protected String attributeChecker(IAnyType aType, IAttrRefOrDecl aRefOrDecl, MethodVariant aPropertyVariant) {
|
216
|
106
|
IRef ref = aRefOrDecl.getGlobalRef();
|
217
|
106
|
return new StringBuffer().append("// attribute checker\n").append(aPropertyVariant.method("boolean", "has", propertyName(aRefOrDecl))).append("() {\n").append("\treturn null != getImpl_().getAttributeData(\"").append(ref.getNamespace()).append("\", \"").append(ref.getLocalPart()).append("\");\n").append("}").toString();
|
218
|
|
}
|
219
|
|
|
220
|
12
|
protected String elementRemover(IAnyType aType, IElemRefOrDecl aRefOrDecl, MethodVariant aPropertyVariant) {
|
221
|
12
|
IRef ref = aRefOrDecl.getGlobalRef();
|
222
|
12
|
StringBuffer sb = new StringBuffer().append("// element remover\n").append(aPropertyVariant.method("void", "remove", propertyName(aRefOrDecl))).append("() {\n").append("\tjava.util.Iterator i = getImpl_().iterElementData(\"").append(ref.getNamespace()).append("\", \"").append(ref.getLocalPart()).append("\");\n").append("\tif (i.hasNext()) { i.next(); i.remove(); }\n").append("}\n");
|
223
|
12
|
return sb.toString();
|
224
|
|
}
|
225
|
|
|
226
|
57
|
protected String attributeRemover(IAnyType aType, IAttrRefOrDecl aRefOrDecl, MethodVariant aPropertyVariant) {
|
227
|
57
|
IRef ref = aRefOrDecl.getGlobalRef();
|
228
|
57
|
StringBuffer sb = new StringBuffer().append("// attribute remover\n").append(aPropertyVariant.method("void", "remove", propertyName(aRefOrDecl))).append("() throws ").append(XmlException.class.getName()).append(" {\n").append("\tremoveAttributeData_(\"").append(ref.getNamespace()).append("\", \"").append(ref.getLocalPart()).append("\");\n").append("}\n");
|
229
|
57
|
return sb.toString();
|
230
|
|
}
|
231
|
|
|
232
|
15
|
protected String elementCreatorWithType(IAnyType aType, IElemRefOrDecl aRefOrDecl, MethodVariant aPropertyVariant) {
|
233
|
15
|
IRef ref = aRefOrDecl.getGlobalRef();
|
234
|
15
|
String dataTypeName = interfaceName(aRefOrDecl.getType());
|
235
|
15
|
String ssoTypeName = null;
|
236
|
15
|
if (null != aRefOrDecl.getType().getSimpleContentType()) {
|
237
|
8
|
ssoTypeName = aRefOrDecl.getType().getSimpleContentType().getSimpleStorageType().getName();
|
238
|
|
}
|
239
|
15
|
StringBuffer sb = new StringBuffer().append("// element creator\n").append(aPropertyVariant.method(dataTypeName, "create", propertyName(aRefOrDecl))).append((null != ssoTypeName) ? "(final " + ssoTypeName + " aValue, " : "(").append(IAnyType.class.getName()).append(" anOverloadingType) throws ").append(XmlException.class.getName()).append(" {\n");
|
240
|
15
|
String provider = "null";
|
241
|
15
|
if (null != ssoTypeName) {
|
242
|
8
|
provider = "provider";
|
243
|
8
|
sb.append("\t").append(ITextContentProvider.class.getName()).append(" provider = new ").append(ITextContentProvider.class.getName()).append(" () {\n").append("\t\tpublic String getTextContent_() { return String.valueOf(aValue); }\n").append("\t};\n");
|
244
|
|
}
|
245
|
15
|
sb.append("\t").append(dataTypeName).append(" data = (").append(dataTypeName).append(")newElementData_(\"").append(ref.getNamespace()).append("\", \"").append(ref.getLocalPart()).append("\", anOverloadingType, ").append(provider).append(");\n");
|
246
|
15
|
if (null != ssoTypeName) {
|
247
|
8
|
sb.append("\tdata.set").append(ssoAccessor(aRefOrDecl.getType().getSimpleContentType().getSimpleStorageType())).append("(aValue);\n");
|
248
|
|
}
|
249
|
15
|
sb.append("\treturn data;\n").append("}\n");
|
250
|
15
|
return sb.toString();
|
251
|
|
}
|
252
|
|
|
253
|
5
|
protected String elementCreator(IAnyType aType, IElemRefOrDecl aRefOrDecl, MethodVariant aPropertyVariant) {
|
254
|
5
|
IRef ref = aRefOrDecl.getGlobalRef();
|
255
|
5
|
String dataTypeName = interfaceName(aRefOrDecl.getType());
|
256
|
5
|
String ssoTypeName = null;
|
257
|
5
|
if (null != aRefOrDecl.getType().getSimpleContentType()) {
|
258
|
4
|
ssoTypeName = aRefOrDecl.getType().getSimpleContentType().getSimpleStorageType().getName();
|
259
|
|
}
|
260
|
5
|
StringBuffer sb = new StringBuffer().append("// element creator\n").append(aPropertyVariant.method(dataTypeName, "create", propertyName(aRefOrDecl))).append("(").append((null != ssoTypeName) ? "final " + ssoTypeName + " aValue" : "").append(") throws ").append(XmlException.class.getName()).append(" {\n");
|
261
|
5
|
String provider = "null";
|
262
|
5
|
if (null != ssoTypeName) {
|
263
|
4
|
provider = "provider";
|
264
|
4
|
sb.append("\t").append(ITextContentProvider.class.getName()).append(" provider = new ").append(ITextContentProvider.class.getName()).append(" () {\n").append("\t\tpublic String getTextContent_() { return String.valueOf(aValue); }\n").append("\t};\n");
|
265
|
|
}
|
266
|
5
|
sb.append("\t").append(dataTypeName).append(" data = (").append(dataTypeName).append(")newElementData_(\"").append(ref.getNamespace()).append("\", \"").append(ref.getLocalPart()).append("\", null, ").append(provider).append(");\n");
|
267
|
5
|
if (null != ssoTypeName) {
|
268
|
4
|
sb.append("\tdata.set").append(ssoAccessor(aRefOrDecl.getType().getSimpleContentType().getSimpleStorageType())).append("(aValue);\n");
|
269
|
|
}
|
270
|
5
|
sb.append("\treturn data;\n").append("}\n");
|
271
|
5
|
return sb.toString();
|
272
|
|
}
|
273
|
|
|
274
|
290
|
protected String elementIterator(IAnyType aType, IElemRefOrDecl aRefOrDecl, MethodVariant aPropertyVariant, boolean aUseDataClass) {
|
275
|
290
|
IRef ref = aRefOrDecl.getGlobalRef();
|
276
|
290
|
StringBuffer sb = new StringBuffer().append("// element iterator\n").append(aPropertyVariant.method(ListIterator.class.getName(), "iter", pluralForm(propertyName(aRefOrDecl)))).append("() {\n").append("\tjava.util.ListIterator i = getImpl_().iterElementData(\"").append(ref.getNamespace()).append("\", \"").append(ref.getLocalPart()).append("\");\n");
|
277
|
290
|
if (aUseDataClass || (null == aRefOrDecl.getType().getSimpleStorageType())) {
|
278
|
271
|
sb.append("\treturn i;\n");
|
279
|
|
} else {
|
280
|
19
|
sb.append("\treturn new ").append(TransformingListIterator.class.getName()).append("(i, new ").append(ReflectUtil.getTypeName(TransformingIterator.ITransformation.class)).append("() {\n").append("\t\tpublic Object transform(Object anObject) { return ((").append(ISimpleData.class.getName()).append(")anObject).getSimpleStorageObject(); } });\n");
|
281
|
|
}
|
282
|
290
|
sb.append("}");
|
283
|
290
|
return sb.toString();
|
284
|
|
}
|
285
|
|
|
286
|
360
|
protected String attributeIterator(IAnyType aType, IAttrRefOrDecl aRefOrDecl, MethodVariant aPropertyVariant, boolean aUseDataClass) {
|
287
|
360
|
String res = null;
|
288
|
360
|
if (aRefOrDecl.getType() instanceof IListType) {
|
289
|
5
|
IListType t = (IListType)aRefOrDecl.getType();
|
290
|
5
|
IRef ref = aRefOrDecl.getGlobalRef();
|
291
|
5
|
StringBuffer sb = new StringBuffer().append("// attribute iterator\n").append(aPropertyVariant.method(ListIterator.class.getName(), "iter", propertyName(aRefOrDecl))).append("() {\n").append("\tObject o = getImpl_().getAttributeData(\"").append(ref.getNamespace()).append("\", \"").append(ref.getLocalPart()).append("\");\n").append("\tjava.util.ListIterator i = null != o ? ((").append(IAnyListTypeData.class.getName()).append(")o).iterItems() : java.util.Collections.EMPTY_LIST.listIterator();\n");
|
292
|
5
|
if (aUseDataClass) {
|
293
|
0
|
sb.append("\treturn i;\n");
|
294
|
|
} else {
|
295
|
5
|
sb.append("\treturn new ").append(TransformingListIterator.class.getName()).append("(i, new ").append(ReflectUtil.getTypeName(TransformingIterator.ITransformation.class)).append("() {\n").append("\t\tpublic Object transform(Object anObject) { return ((").append(ISimpleData.class.getName()).append(")anObject).getSimpleStorageObject(); } });\n");
|
296
|
|
}
|
297
|
5
|
sb.append("}");
|
298
|
5
|
res = sb.toString();
|
299
|
|
}
|
300
|
360
|
return res;
|
301
|
|
}
|
302
|
|
|
303
|
57
|
protected String attributeSetter(IAnyType aType, IAttrRefOrDecl aRefOrDecl, MethodVariant aPropertyVariant, boolean aUseDataClass) {
|
304
|
57
|
aUseDataClass = false;
|
305
|
57
|
IRef ref = aRefOrDecl.getGlobalRef();
|
306
|
57
|
String propertyTypeName = simpleTypeName(aRefOrDecl.getType(), aUseDataClass);
|
307
|
57
|
String dataTypeName = interfaceName(aRefOrDecl.getType());
|
308
|
57
|
Class ssoType = aRefOrDecl.getType().getSimpleStorageType();
|
309
|
57
|
StringBuffer sb = new StringBuffer().append("// attribute setter\n").append(aPropertyVariant.method("void", "set", propertyName(aRefOrDecl))).append("(final ").append(propertyTypeName).append(" aValue) throws ").append(XmlException.class.getName()).append(" {\n").append("\tremoveAttributeData_(\"").append(ref.getNamespace()).append("\", \"").append(ref.getLocalPart()).append("\");\n");
|
310
|
57
|
if (aUseDataClass || !aRefOrDecl.getType().getSimpleStorageType().isPrimitive()) {
|
311
|
|
// only non-primitive types can be checked for null.
|
312
|
40
|
sb.append("\tif (null != aValue) {\n");
|
313
|
|
}
|
314
|
57
|
sb.append("\t\t").append(dataTypeName).append(" data = null;\n").append("\t\t").append(ITextContentProvider.class.getName()).append(" provider = new ").append(ITextContentProvider.class.getName()).append(" () {\n").append("\t\t\tpublic String getTextContent_() { return String.valueOf(aValue").append(aUseDataClass ? ".get" + ssoAccessor(ssoType) + "()" : "").append("); }\n").append("\t\t};\n").append("\t\tdata = (").append(dataTypeName).append(")createUncheckedAttributeData_(\"").append(ref.getNamespace()).append("\", \"").append(ref.getLocalPart()).append("\", provider);\n").append("\t\tdata.set").append(ssoAccessor(ssoType)).append("(aValue").append(aUseDataClass ? ".get" + ssoAccessor(ssoType) + "()" : "").append(");\n");
|
315
|
57
|
if (aUseDataClass || !aRefOrDecl.getType().getSimpleStorageType().isPrimitive()) {
|
316
|
40
|
sb.append("\t}\n");
|
317
|
|
}
|
318
|
57
|
sb.append("}\n");
|
319
|
57
|
return sb.toString();
|
320
|
|
}
|
321
|
|
|
322
|
5
|
protected String referenceGetter(IAnyType aType, RefConstraintInfo aConstraintInfo, MethodVariant aPropertyVariant) {
|
323
|
5
|
StringBuffer sb = new StringBuffer();
|
324
|
5
|
sb.append("// reference getter\n").append(aPropertyVariant.method(interfaceName(aConstraintInfo.dataType), "ref", aConstraintInfo.propertyName)).append("() {\n").append("\tjava.util.Iterator i = ").append("iterReferencedData_(\"").append(aConstraintInfo.constraintKey).append("\");\n").append("\treturn i.hasNext() ? (").append(interfaceName(aConstraintInfo.dataType)).append(")i.next() : null;\n").append("}\n");
|
325
|
5
|
return sb.toString();
|
326
|
|
}
|
327
|
|
|
328
|
3
|
protected String referenceIterator(IAnyType aType, RefConstraintInfo aConstraintInfo, MethodVariant aPropertyVariant) {
|
329
|
3
|
StringBuffer sb = new StringBuffer().append("// reference iterator\n").append(aPropertyVariant.method("java.util.Iterator", "refs", aConstraintInfo.propertyName)).append("() {\n").append("\treturn ").append("iterReferencedData_(\"").append(aConstraintInfo.constraintKey).append("\");\n").append("}\n");
|
330
|
3
|
return sb.toString();
|
331
|
|
}
|
332
|
|
|
333
|
6
|
protected String xPathMethod(IAnyType aType, IXPathMethod aMethod, MethodVariant aVariant) {
|
334
|
6
|
String returnType = null;
|
335
|
6
|
boolean cast = false;
|
336
|
6
|
if (null != aMethod.getReferencedType()) {
|
337
|
0
|
returnType = interfaceName(aMethod.getReferencedType());
|
338
|
0
|
cast = true;
|
339
|
|
} else {
|
340
|
6
|
returnType = aMethod.getReturnType();
|
341
|
|
}
|
342
|
6
|
return new StringBuffer().append("// XPath method\n").append(aVariant.method(returnType, aMethod.getPrefix(), aMethod.getName())).append("() throws ").append(XmlException.class.getName()).append(" {\n").append("\treturn " + (cast ? "(" + returnType + ")" : "") + aMethod.getPrefix() + "ByXPath_(\"").append(aMethod.getName()).append("\");\n").append("}\n").toString();
|
343
|
|
}
|
344
|
|
|
345
|
437
|
protected String typeComment(IAnyType aType) {
|
346
|
437
|
return null;
|
347
|
|
}
|
348
|
|
|
349
|
|
}
|
350
|
|
|