1
|
|
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
package org.apache.hivemind.ant;
|
16
|
|
|
17
|
|
import java.util.ArrayList;
|
18
|
|
import java.util.Collection;
|
19
|
|
import java.util.HashSet;
|
20
|
|
import java.util.Iterator;
|
21
|
|
import java.util.List;
|
22
|
|
import java.util.Set;
|
23
|
|
|
24
|
|
import javax.xml.parsers.DocumentBuilder;
|
25
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
26
|
|
import javax.xml.parsers.ParserConfigurationException;
|
27
|
|
|
28
|
|
import org.apache.hivemind.ApplicationRuntimeException;
|
29
|
|
import org.apache.hivemind.Attribute;
|
30
|
|
import org.apache.hivemind.ClassResolver;
|
31
|
|
import org.apache.hivemind.ErrorHandler;
|
32
|
|
import org.apache.hivemind.ModuleDescriptorProvider;
|
33
|
|
import org.apache.hivemind.Occurances;
|
34
|
|
import org.apache.hivemind.impl.DefaultClassResolver;
|
35
|
|
import org.apache.hivemind.impl.DefaultErrorHandler;
|
36
|
|
import org.apache.hivemind.impl.XmlModuleDescriptorProvider;
|
37
|
|
import org.apache.hivemind.internal.Visibility;
|
38
|
|
import org.apache.hivemind.parse.AttributeMappingDescriptor;
|
39
|
|
import org.apache.hivemind.parse.ConfigurationPointDescriptor;
|
40
|
|
import org.apache.hivemind.parse.ContributionDescriptor;
|
41
|
|
import org.apache.hivemind.parse.ConversionDescriptor;
|
42
|
|
import org.apache.hivemind.parse.CreateInstanceDescriptor;
|
43
|
|
import org.apache.hivemind.parse.DependencyDescriptor;
|
44
|
|
import org.apache.hivemind.parse.ImplementationDescriptor;
|
45
|
|
import org.apache.hivemind.parse.InstanceBuilder;
|
46
|
|
import org.apache.hivemind.parse.InterceptorDescriptor;
|
47
|
|
import org.apache.hivemind.parse.InvokeFactoryDescriptor;
|
48
|
|
import org.apache.hivemind.parse.ModuleDescriptor;
|
49
|
|
import org.apache.hivemind.parse.ServicePointDescriptor;
|
50
|
|
import org.apache.hivemind.parse.SubModuleDescriptor;
|
51
|
|
import org.apache.hivemind.schema.AttributeModel;
|
52
|
|
import org.apache.hivemind.schema.ElementModel;
|
53
|
|
import org.apache.hivemind.schema.Rule;
|
54
|
|
import org.apache.hivemind.schema.impl.SchemaImpl;
|
55
|
|
import org.apache.hivemind.schema.rules.CreateObjectRule;
|
56
|
|
import org.apache.hivemind.schema.rules.InvokeParentRule;
|
57
|
|
import org.apache.hivemind.schema.rules.PushAttributeRule;
|
58
|
|
import org.apache.hivemind.schema.rules.ReadAttributeRule;
|
59
|
|
import org.apache.hivemind.schema.rules.ReadContentRule;
|
60
|
|
import org.apache.hivemind.schema.rules.SetModuleRule;
|
61
|
|
import org.apache.hivemind.schema.rules.SetParentRule;
|
62
|
|
import org.apache.hivemind.schema.rules.SetPropertyRule;
|
63
|
|
import org.apache.hivemind.util.IdUtils;
|
64
|
|
import org.w3c.dom.Document;
|
65
|
|
import org.w3c.dom.Element;
|
66
|
|
|
67
|
|
|
68
|
|
|
69
|
|
|
70
|
|
|
71
|
|
|
72
|
|
|
73
|
|
|
74
|
|
|
75
|
|
|
76
|
|
|
77
|
|
|
78
|
|
|
79
|
|
|
80
|
|
|
81
|
|
|
82
|
|
|
83
|
|
|
84
|
|
|
85
|
|
|
86
|
|
|
87
|
|
|
88
|
|
|
89
|
|
public class RegistrySerializer
|
90
|
|
{
|
91
|
|
private Set _processedSchemas = new HashSet();
|
92
|
|
|
93
|
|
private List _providers = new ArrayList();
|
94
|
|
|
95
|
|
private ErrorHandler _handler;
|
96
|
|
|
97
|
|
private Document _document;
|
98
|
|
|
99
|
|
private ModuleDescriptor _md;
|
100
|
|
|
101
|
4
|
public RegistrySerializer()
|
102
|
|
{
|
103
|
4
|
_handler = new DefaultErrorHandler();
|
104
|
|
}
|
105
|
|
|
106
|
4
|
public void addModuleDescriptorProvider(ModuleDescriptorProvider provider)
|
107
|
|
{
|
108
|
4
|
_providers.add(provider);
|
109
|
|
}
|
110
|
|
|
111
|
4
|
public Document createRegistryDocument()
|
112
|
|
{
|
113
|
4
|
DocumentBuilder builder = getBuilder();
|
114
|
|
|
115
|
4
|
_document = builder.newDocument();
|
116
|
|
|
117
|
4
|
Element registry = _document.createElement("registry");
|
118
|
|
|
119
|
4
|
_document.appendChild(registry);
|
120
|
|
|
121
|
4
|
for (Iterator i = _providers.iterator(); i.hasNext();)
|
122
|
|
{
|
123
|
4
|
ModuleDescriptorProvider provider = (ModuleDescriptorProvider) i.next();
|
124
|
|
|
125
|
4
|
processModuleDescriptorProvider(registry, provider);
|
126
|
|
}
|
127
|
|
|
128
|
4
|
return _document;
|
129
|
|
}
|
130
|
|
|
131
|
4
|
private void processModuleDescriptorProvider(Element registry, ModuleDescriptorProvider provider)
|
132
|
|
{
|
133
|
4
|
for (Iterator j = provider.getModuleDescriptors(_handler).iterator(); j.hasNext();)
|
134
|
|
{
|
135
|
7
|
_md = (ModuleDescriptor) j.next();
|
136
|
|
|
137
|
7
|
Element module = getModuleElement(_md);
|
138
|
|
|
139
|
7
|
registry.appendChild(module);
|
140
|
|
}
|
141
|
|
}
|
142
|
|
|
143
|
7
|
private Element getModuleElement(ModuleDescriptor md)
|
144
|
|
{
|
145
|
7
|
Element module = _document.createElement("module");
|
146
|
|
|
147
|
7
|
module.setAttribute("id", md.getModuleId());
|
148
|
7
|
module.setAttribute("version", md.getVersion());
|
149
|
7
|
module.setAttribute("package", md.getPackageName());
|
150
|
|
|
151
|
7
|
module.appendChild(_document.createTextNode(md.getAnnotation()));
|
152
|
|
|
153
|
7
|
addDependencies(module);
|
154
|
|
|
155
|
7
|
addServicePoints(module);
|
156
|
|
|
157
|
7
|
addConfigurationPoints(module);
|
158
|
|
|
159
|
7
|
addContributions(module);
|
160
|
|
|
161
|
7
|
addImplementations(module);
|
162
|
|
|
163
|
7
|
addSchemas(module);
|
164
|
|
|
165
|
7
|
addSubModules(module);
|
166
|
|
|
167
|
7
|
return module;
|
168
|
|
}
|
169
|
|
|
170
|
7
|
private void addDependencies(Element module)
|
171
|
|
{
|
172
|
7
|
List dependencies = _md.getDependencies();
|
173
|
|
|
174
|
7
|
if (dependencies != null)
|
175
|
|
{
|
176
|
0
|
for (Iterator i = dependencies.iterator(); i.hasNext();)
|
177
|
|
{
|
178
|
0
|
DependencyDescriptor dd = (DependencyDescriptor) i.next();
|
179
|
|
|
180
|
0
|
Element dependency = getDependencyElement(dd);
|
181
|
|
|
182
|
0
|
module.appendChild(dependency);
|
183
|
|
}
|
184
|
|
}
|
185
|
|
}
|
186
|
|
|
187
|
7
|
private void addServicePoints(Element module)
|
188
|
|
{
|
189
|
7
|
List servicePoints = _md.getServicePoints();
|
190
|
|
|
191
|
7
|
if (servicePoints != null)
|
192
|
|
{
|
193
|
5
|
for (Iterator i = servicePoints.iterator(); i.hasNext();)
|
194
|
|
{
|
195
|
47
|
ServicePointDescriptor spd = (ServicePointDescriptor) i.next();
|
196
|
|
|
197
|
47
|
Element servicePoint = getServicePointElement(spd);
|
198
|
|
|
199
|
47
|
module.appendChild(servicePoint);
|
200
|
|
|
201
|
47
|
SchemaImpl s = (SchemaImpl) spd.getParametersSchema();
|
202
|
|
|
203
|
47
|
if (s != null && s.getId() != null)
|
204
|
0
|
addSchema(module, s, "schema");
|
205
|
|
}
|
206
|
|
}
|
207
|
|
}
|
208
|
|
|
209
|
7
|
private void addConfigurationPoints(Element module)
|
210
|
|
{
|
211
|
7
|
List configurationPoints = _md.getConfigurationPoints();
|
212
|
|
|
213
|
7
|
if (configurationPoints != null)
|
214
|
|
{
|
215
|
5
|
for (Iterator i = configurationPoints.iterator(); i.hasNext();)
|
216
|
|
{
|
217
|
26
|
ConfigurationPointDescriptor cpd = (ConfigurationPointDescriptor) i.next();
|
218
|
|
|
219
|
26
|
Element configurationPoint = getConfigurationPointElement(cpd);
|
220
|
|
|
221
|
26
|
module.appendChild(configurationPoint);
|
222
|
|
|
223
|
26
|
SchemaImpl s = (SchemaImpl) cpd.getContributionsSchema();
|
224
|
|
|
225
|
26
|
if (s != null && s.getId() != null)
|
226
|
0
|
addSchema(module, s, "schema");
|
227
|
|
}
|
228
|
|
}
|
229
|
|
}
|
230
|
|
|
231
|
7
|
private void addContributions(Element module)
|
232
|
|
{
|
233
|
7
|
List contributions = _md.getContributions();
|
234
|
|
|
235
|
7
|
if (contributions != null)
|
236
|
|
{
|
237
|
5
|
for (Iterator i = contributions.iterator(); i.hasNext();)
|
238
|
|
{
|
239
|
17
|
ContributionDescriptor cd = (ContributionDescriptor) i.next();
|
240
|
|
|
241
|
17
|
Element contribution = getContributionElement(cd);
|
242
|
|
|
243
|
17
|
module.appendChild(contribution);
|
244
|
|
}
|
245
|
|
}
|
246
|
|
}
|
247
|
|
|
248
|
7
|
private void addImplementations(Element module)
|
249
|
|
{
|
250
|
7
|
List implementations = _md.getImplementations();
|
251
|
|
|
252
|
7
|
if (implementations != null)
|
253
|
|
{
|
254
|
0
|
for (Iterator i = implementations.iterator(); i.hasNext();)
|
255
|
|
{
|
256
|
0
|
ImplementationDescriptor id = (ImplementationDescriptor) i.next();
|
257
|
|
|
258
|
0
|
Element implementation = getImplementationElement(id);
|
259
|
|
|
260
|
0
|
module.appendChild(implementation);
|
261
|
|
}
|
262
|
|
}
|
263
|
|
}
|
264
|
|
|
265
|
7
|
private void addSchemas(Element module)
|
266
|
|
{
|
267
|
7
|
Collection schemas = _md.getSchemas();
|
268
|
|
|
269
|
7
|
for (Iterator i = schemas.iterator(); i.hasNext();)
|
270
|
|
{
|
271
|
8
|
SchemaImpl s = (SchemaImpl) i.next();
|
272
|
|
|
273
|
8
|
addSchema(module, s, "schema");
|
274
|
|
}
|
275
|
|
}
|
276
|
|
|
277
|
7
|
private void addSubModules(Element module)
|
278
|
|
{
|
279
|
7
|
List subModules = _md.getSubModules();
|
280
|
|
|
281
|
7
|
if (subModules != null)
|
282
|
|
{
|
283
|
0
|
for (Iterator i = subModules.iterator(); i.hasNext();)
|
284
|
|
{
|
285
|
0
|
SubModuleDescriptor smd = (SubModuleDescriptor) i.next();
|
286
|
|
|
287
|
0
|
Element subModule = getSubModuleElement(smd);
|
288
|
|
|
289
|
0
|
module.appendChild(subModule);
|
290
|
|
}
|
291
|
|
}
|
292
|
|
}
|
293
|
|
|
294
|
0
|
private Element getDependencyElement(DependencyDescriptor dd)
|
295
|
|
{
|
296
|
0
|
Element dependency = _document.createElement("dependency");
|
297
|
|
|
298
|
0
|
dependency.setAttribute("module-id", dd.getModuleId());
|
299
|
0
|
dependency.setAttribute("version", dd.getVersion());
|
300
|
|
|
301
|
0
|
return dependency;
|
302
|
|
}
|
303
|
|
|
304
|
47
|
private Element getServicePointElement(ServicePointDescriptor spd)
|
305
|
|
{
|
306
|
47
|
Element servicePoint = _document.createElement("service-point");
|
307
|
|
|
308
|
47
|
servicePoint.setAttribute("id", qualify(spd.getId()));
|
309
|
47
|
servicePoint.setAttribute("interface", spd.getInterfaceClassName());
|
310
|
47
|
if (spd.getVisibility() == Visibility.PRIVATE)
|
311
|
0
|
servicePoint.setAttribute("visibility", "private");
|
312
|
47
|
if (spd.getParametersCount() != Occurances.REQUIRED)
|
313
|
0
|
servicePoint.setAttribute("parameters-occurs", spd.getParametersCount().getName()
|
314
|
|
.toLowerCase());
|
315
|
|
|
316
|
47
|
servicePoint.appendChild(_document.createTextNode(spd.getAnnotation()));
|
317
|
|
|
318
|
47
|
if (spd.getParametersSchema() != null)
|
319
|
3
|
addSchema(servicePoint, (SchemaImpl) spd.getParametersSchema(), "parameters-schema");
|
320
|
44
|
else if (spd.getParametersSchemaId() != null)
|
321
|
3
|
servicePoint.setAttribute("parameters-schema-id", qualify(spd.getParametersSchemaId()));
|
322
|
|
|
323
|
47
|
InstanceBuilder ib = spd.getInstanceBuilder();
|
324
|
|
|
325
|
47
|
if (ib != null)
|
326
|
|
{
|
327
|
47
|
Element instanceBuilder = getInstanceBuilderElement(ib);
|
328
|
|
|
329
|
47
|
servicePoint.appendChild(instanceBuilder);
|
330
|
|
}
|
331
|
|
|
332
|
47
|
List interceptors = spd.getInterceptors();
|
333
|
|
|
334
|
47
|
if (interceptors != null)
|
335
|
|
{
|
336
|
1
|
for (Iterator i = interceptors.iterator(); i.hasNext();)
|
337
|
|
{
|
338
|
1
|
InterceptorDescriptor icd = (InterceptorDescriptor) i.next();
|
339
|
|
|
340
|
1
|
Element interceptor = getInterceptorElement(icd);
|
341
|
|
|
342
|
1
|
servicePoint.appendChild(interceptor);
|
343
|
|
}
|
344
|
|
}
|
345
|
|
|
346
|
47
|
return servicePoint;
|
347
|
|
}
|
348
|
|
|
349
|
26
|
private Element getConfigurationPointElement(ConfigurationPointDescriptor cpd)
|
350
|
|
{
|
351
|
26
|
Element configurationPoint = _document.createElement("configuration-point");
|
352
|
|
|
353
|
26
|
configurationPoint.setAttribute("id", qualify(cpd.getId()));
|
354
|
26
|
if (cpd.getVisibility() == Visibility.PRIVATE)
|
355
|
0
|
configurationPoint.setAttribute("visibility", "private");
|
356
|
|
|
357
|
26
|
configurationPoint.appendChild(_document.createTextNode(cpd.getAnnotation()));
|
358
|
|
|
359
|
26
|
if (cpd.getContributionsSchema() != null)
|
360
|
18
|
addSchema(configurationPoint, (SchemaImpl) cpd.getContributionsSchema(), "schema");
|
361
|
8
|
else if (cpd.getContributionsSchemaId() != null)
|
362
|
8
|
configurationPoint.setAttribute("schema-id", qualify(cpd.getContributionsSchemaId()));
|
363
|
|
|
364
|
26
|
return configurationPoint;
|
365
|
|
}
|
366
|
|
|
367
|
17
|
private Element getContributionElement(ContributionDescriptor cd)
|
368
|
|
{
|
369
|
17
|
Element contribution = _document.createElement("contribution");
|
370
|
|
|
371
|
17
|
contribution.setAttribute("configuration-id", qualify(cd.getConfigurationId()));
|
372
|
|
|
373
|
17
|
if (cd.getConditionalExpression() != null)
|
374
|
0
|
contribution.setAttribute("if", cd.getConditionalExpression());
|
375
|
|
|
376
|
17
|
List parameters = cd.getElements();
|
377
|
|
|
378
|
17
|
if (parameters != null)
|
379
|
|
{
|
380
|
17
|
for (Iterator i = parameters.iterator(); i.hasNext();)
|
381
|
|
{
|
382
|
72
|
org.apache.hivemind.Element parameter = (org.apache.hivemind.Element) i.next();
|
383
|
|
|
384
|
72
|
Element element = getParamterElement(parameter);
|
385
|
|
|
386
|
72
|
contribution.appendChild(element);
|
387
|
|
}
|
388
|
|
}
|
389
|
|
|
390
|
17
|
contribution.appendChild(_document.createTextNode(cd.getAnnotation()));
|
391
|
|
|
392
|
17
|
return contribution;
|
393
|
|
}
|
394
|
|
|
395
|
0
|
private Element getImplementationElement(ImplementationDescriptor id)
|
396
|
|
{
|
397
|
0
|
Element implementation = _document.createElement("implementation");
|
398
|
|
|
399
|
0
|
implementation.setAttribute("service-id", qualify(id.getServiceId()));
|
400
|
|
|
401
|
0
|
if (id.getConditionalExpression() != null)
|
402
|
0
|
implementation.setAttribute("if", id.getConditionalExpression());
|
403
|
|
|
404
|
0
|
implementation.appendChild(_document.createTextNode(id.getAnnotation()));
|
405
|
|
|
406
|
0
|
InstanceBuilder ib = id.getInstanceBuilder();
|
407
|
|
|
408
|
0
|
if (ib != null)
|
409
|
|
{
|
410
|
0
|
Element instanceBuilder = getInstanceBuilderElement(ib);
|
411
|
|
|
412
|
0
|
implementation.appendChild(instanceBuilder);
|
413
|
|
}
|
414
|
|
|
415
|
0
|
List interceptors = id.getInterceptors();
|
416
|
|
|
417
|
0
|
if (interceptors != null)
|
418
|
|
{
|
419
|
0
|
for (Iterator i = interceptors.iterator(); i.hasNext();)
|
420
|
|
{
|
421
|
0
|
InterceptorDescriptor icd = (InterceptorDescriptor) i.next();
|
422
|
|
|
423
|
0
|
Element interceptor = getInterceptorElement(icd);
|
424
|
|
|
425
|
0
|
implementation.appendChild(interceptor);
|
426
|
|
}
|
427
|
|
}
|
428
|
|
|
429
|
0
|
return implementation;
|
430
|
|
}
|
431
|
|
|
432
|
0
|
private Element getSubModuleElement(SubModuleDescriptor smd)
|
433
|
|
{
|
434
|
0
|
Element subModule = _document.createElement("sub-module");
|
435
|
|
|
436
|
0
|
subModule.setAttribute("descriptor", smd.getDescriptor().getPath());
|
437
|
|
|
438
|
0
|
return subModule;
|
439
|
|
}
|
440
|
|
|
441
|
47
|
private Element getInstanceBuilderElement(InstanceBuilder ib)
|
442
|
|
{
|
443
|
47
|
Element instanceBuilder;
|
444
|
|
|
445
|
47
|
if (ib instanceof CreateInstanceDescriptor)
|
446
|
|
{
|
447
|
22
|
CreateInstanceDescriptor cid = (CreateInstanceDescriptor) ib;
|
448
|
22
|
instanceBuilder = _document.createElement("create-instance");
|
449
|
|
|
450
|
22
|
instanceBuilder.setAttribute("class", cid.getInstanceClassName());
|
451
|
22
|
if (!cid.getServiceModel().equals("singleton"))
|
452
|
6
|
instanceBuilder.setAttribute("model", cid.getServiceModel());
|
453
|
|
}
|
454
|
|
else
|
455
|
|
{
|
456
|
25
|
InvokeFactoryDescriptor ifd = (InvokeFactoryDescriptor) ib;
|
457
|
25
|
instanceBuilder = _document.createElement("invoke-factory");
|
458
|
|
|
459
|
25
|
if (!ifd.getFactoryServiceId().equals("hivemind.BuilderFactory"))
|
460
|
25
|
instanceBuilder.setAttribute("service-id", qualify(ifd.getFactoryServiceId()));
|
461
|
25
|
if (ifd.getServiceModel() != null)
|
462
|
25
|
instanceBuilder.setAttribute("model", ifd.getServiceModel());
|
463
|
|
|
464
|
25
|
List parameters = ifd.getParameters();
|
465
|
|
|
466
|
25
|
if (parameters != null)
|
467
|
|
{
|
468
|
24
|
for (Iterator i = parameters.iterator(); i.hasNext();)
|
469
|
|
{
|
470
|
24
|
org.apache.hivemind.Element parameter = (org.apache.hivemind.Element) i.next();
|
471
|
|
|
472
|
24
|
Element element = getParamterElement(parameter);
|
473
|
|
|
474
|
24
|
instanceBuilder.appendChild(element);
|
475
|
|
}
|
476
|
|
}
|
477
|
|
}
|
478
|
|
|
479
|
47
|
return instanceBuilder;
|
480
|
|
}
|
481
|
|
|
482
|
1
|
private Element getInterceptorElement(InterceptorDescriptor icd)
|
483
|
|
{
|
484
|
1
|
Element interceptor = _document.createElement("interceptor");
|
485
|
|
|
486
|
1
|
interceptor.setAttribute("service-id", qualify(icd.getFactoryServiceId()));
|
487
|
1
|
if (icd.getBefore() != null)
|
488
|
0
|
interceptor.setAttribute("before", icd.getBefore());
|
489
|
1
|
if (icd.getAfter() != null)
|
490
|
0
|
interceptor.setAttribute("after", icd.getAfter());
|
491
|
1
|
return interceptor;
|
492
|
|
}
|
493
|
|
|
494
|
120
|
private Element getParamterElement(org.apache.hivemind.Element parameter)
|
495
|
|
{
|
496
|
120
|
Element element = _document.createElement(parameter.getElementName());
|
497
|
|
|
498
|
120
|
List attributes = parameter.getAttributes();
|
499
|
|
|
500
|
120
|
for (Iterator i = attributes.iterator(); i.hasNext();)
|
501
|
|
{
|
502
|
213
|
Attribute attribute = (Attribute) i.next();
|
503
|
|
|
504
|
213
|
element.setAttribute(attribute.getName(), attribute.getValue());
|
505
|
|
}
|
506
|
|
|
507
|
120
|
List elements = parameter.getElements();
|
508
|
|
|
509
|
120
|
for (Iterator i = elements.iterator(); i.hasNext();)
|
510
|
|
{
|
511
|
24
|
org.apache.hivemind.Element nestedParameter = (org.apache.hivemind.Element) i.next();
|
512
|
|
|
513
|
24
|
element.appendChild(getParamterElement(nestedParameter));
|
514
|
|
}
|
515
|
|
|
516
|
120
|
return element;
|
517
|
|
}
|
518
|
|
|
519
|
29
|
private void addSchema(Element container, SchemaImpl s, String elementName)
|
520
|
|
{
|
521
|
29
|
if (_processedSchemas.contains(s))
|
522
|
0
|
return;
|
523
|
|
|
524
|
29
|
Element schema = _document.createElement(elementName);
|
525
|
|
|
526
|
29
|
if (s.getId() != null)
|
527
|
8
|
schema.setAttribute("id", qualify(s.getId()));
|
528
|
|
|
529
|
29
|
if (s.getVisibility() == Visibility.PRIVATE)
|
530
|
0
|
schema.setAttribute("visibility", "private");
|
531
|
|
|
532
|
29
|
schema.appendChild(_document.createTextNode(s.getAnnotation()));
|
533
|
|
|
534
|
29
|
for (Iterator j = s.getElementModel().iterator(); j.hasNext();)
|
535
|
|
{
|
536
|
35
|
ElementModel em = (ElementModel) j.next();
|
537
|
|
|
538
|
35
|
Element element = getElementElement(em);
|
539
|
|
|
540
|
35
|
schema.appendChild(element);
|
541
|
|
}
|
542
|
|
|
543
|
29
|
container.appendChild(schema);
|
544
|
|
|
545
|
29
|
_processedSchemas.add(s);
|
546
|
|
}
|
547
|
|
|
548
|
92
|
private Element getRulesElement(ElementModel em)
|
549
|
|
{
|
550
|
92
|
Element rules = _document.createElement("rules");
|
551
|
|
|
552
|
92
|
for (Iterator i = em.getRules().iterator(); i.hasNext();)
|
553
|
|
{
|
554
|
293
|
Rule r = (Rule) i.next();
|
555
|
|
|
556
|
293
|
Element rule = null;
|
557
|
|
|
558
|
293
|
if (r instanceof CreateObjectRule)
|
559
|
|
{
|
560
|
81
|
CreateObjectRule cor = (CreateObjectRule) r;
|
561
|
81
|
rule = _document.createElement("create-object");
|
562
|
|
|
563
|
81
|
rule.setAttribute("class", cor.getClassName());
|
564
|
|
}
|
565
|
212
|
else if (r instanceof InvokeParentRule)
|
566
|
|
{
|
567
|
90
|
InvokeParentRule ipr = (InvokeParentRule) r;
|
568
|
90
|
rule = _document.createElement("invoke-parent");
|
569
|
|
|
570
|
90
|
rule.setAttribute("method", ipr.getMethodName());
|
571
|
90
|
if (ipr.getDepth() != 1)
|
572
|
69
|
rule.setAttribute("depth", Integer.toString(ipr.getDepth()));
|
573
|
|
}
|
574
|
122
|
else if (r instanceof PushAttributeRule)
|
575
|
|
{
|
576
|
9
|
PushAttributeRule par = (PushAttributeRule) r;
|
577
|
9
|
rule = _document.createElement("push-attribute");
|
578
|
|
|
579
|
9
|
rule.setAttribute("attribute", par.getAttributeName());
|
580
|
|
}
|
581
|
113
|
else if (r instanceof ReadAttributeRule)
|
582
|
|
{
|
583
|
66
|
ReadAttributeRule rar = (ReadAttributeRule) r;
|
584
|
66
|
rule = _document.createElement("read-attribute");
|
585
|
|
|
586
|
66
|
rule.setAttribute("property", rar.getPropertyName());
|
587
|
66
|
rule.setAttribute("attribute", rar.getAttributeName());
|
588
|
66
|
if (!rar.getSkipIfNull())
|
589
|
3
|
rule.setAttribute("skip-if-null", "false");
|
590
|
66
|
if (rar.getTranslator() != null)
|
591
|
0
|
rule.setAttribute("translator", rar.getTranslator());
|
592
|
|
}
|
593
|
47
|
else if (r instanceof ReadContentRule)
|
594
|
|
{
|
595
|
24
|
ReadContentRule rcr = (ReadContentRule) r;
|
596
|
24
|
rule = _document.createElement("read-content");
|
597
|
|
|
598
|
24
|
rule.setAttribute("property", rcr.getPropertyName());
|
599
|
|
}
|
600
|
23
|
else if (r instanceof SetModuleRule)
|
601
|
|
{
|
602
|
0
|
SetModuleRule smr = (SetModuleRule) r;
|
603
|
0
|
rule = _document.createElement("set-module");
|
604
|
|
|
605
|
0
|
rule.setAttribute("property", smr.getPropertyName());
|
606
|
|
}
|
607
|
23
|
else if (r instanceof SetParentRule)
|
608
|
|
{
|
609
|
0
|
SetParentRule spr = (SetParentRule) r;
|
610
|
0
|
rule = _document.createElement("set-parent");
|
611
|
|
|
612
|
0
|
rule.setAttribute("property", spr.getPropertyName());
|
613
|
|
}
|
614
|
23
|
else if (r instanceof SetPropertyRule)
|
615
|
|
{
|
616
|
6
|
SetPropertyRule spr = (SetPropertyRule) r;
|
617
|
6
|
rule = _document.createElement("set-property");
|
618
|
|
|
619
|
6
|
rule.setAttribute("property", spr.getPropertyName());
|
620
|
6
|
rule.setAttribute("value", spr.getValue());
|
621
|
|
}
|
622
|
17
|
else if (r instanceof ConversionDescriptor)
|
623
|
|
{
|
624
|
17
|
ConversionDescriptor cd = (ConversionDescriptor) r;
|
625
|
17
|
rule = _document.createElement("conversion");
|
626
|
|
|
627
|
17
|
rule.setAttribute("class", cd.getClassName());
|
628
|
17
|
if (!cd.getParentMethodName().equals("addElement"))
|
629
|
0
|
rule.setAttribute("parent-method", cd.getParentMethodName());
|
630
|
|
|
631
|
17
|
for (Iterator j = cd.getAttributeMappings().iterator(); j.hasNext();)
|
632
|
|
{
|
633
|
24
|
AttributeMappingDescriptor amd = (AttributeMappingDescriptor) j.next();
|
634
|
|
|
635
|
24
|
Element map = _document.createElement("map");
|
636
|
|
|
637
|
24
|
map.setAttribute("attribute", amd.getAttributeName());
|
638
|
24
|
map.setAttribute("property", amd.getPropertyName());
|
639
|
|
|
640
|
24
|
rule.appendChild(map);
|
641
|
|
}
|
642
|
|
}
|
643
|
|
else
|
644
|
|
{
|
645
|
0
|
rule = _document.createElement("custom");
|
646
|
|
|
647
|
0
|
rule.setAttribute("class", r.getClass().getName());
|
648
|
|
}
|
649
|
|
|
650
|
293
|
if (rule != null)
|
651
|
293
|
rules.appendChild(rule);
|
652
|
|
}
|
653
|
92
|
return rules;
|
654
|
|
}
|
655
|
|
|
656
|
92
|
private Element getElementElement(ElementModel em)
|
657
|
|
{
|
658
|
92
|
Element element = _document.createElement("element");
|
659
|
92
|
element.setAttribute("name", em.getElementName());
|
660
|
|
|
661
|
92
|
element.appendChild(_document.createTextNode(em.getAnnotation()));
|
662
|
|
|
663
|
92
|
for (Iterator i = em.getAttributeModels().iterator(); i.hasNext();)
|
664
|
|
{
|
665
|
121
|
AttributeModel am = (AttributeModel) i.next();
|
666
|
|
|
667
|
121
|
Element attribute = getAttributeElement(am);
|
668
|
|
|
669
|
121
|
element.appendChild(attribute);
|
670
|
|
}
|
671
|
|
|
672
|
92
|
for (Iterator i = em.getElementModel().iterator(); i.hasNext();)
|
673
|
|
{
|
674
|
57
|
ElementModel nestedEm = (ElementModel) i.next();
|
675
|
|
|
676
|
57
|
Element nestedElement = getElementElement(nestedEm);
|
677
|
|
|
678
|
57
|
element.appendChild(nestedElement);
|
679
|
|
}
|
680
|
|
|
681
|
92
|
if (!em.getRules().isEmpty())
|
682
|
|
{
|
683
|
92
|
Element rules = getRulesElement(em);
|
684
|
|
|
685
|
92
|
element.appendChild(rules);
|
686
|
|
}
|
687
|
|
|
688
|
92
|
return element;
|
689
|
|
}
|
690
|
|
|
691
|
121
|
private Element getAttributeElement(AttributeModel am)
|
692
|
|
{
|
693
|
121
|
Element attribute = _document.createElement("attribute");
|
694
|
|
|
695
|
121
|
attribute.setAttribute("name", am.getName());
|
696
|
121
|
if (am.isRequired())
|
697
|
70
|
attribute.setAttribute("required", "true");
|
698
|
121
|
if (am.isUnique())
|
699
|
0
|
attribute.setAttribute("unique", "true");
|
700
|
121
|
if (!am.getTranslator().equals("smart"))
|
701
|
45
|
attribute.setAttribute("translator", am.getTranslator());
|
702
|
|
|
703
|
121
|
attribute.appendChild(_document.createTextNode(am.getAnnotation()));
|
704
|
|
|
705
|
121
|
return attribute;
|
706
|
|
}
|
707
|
|
|
708
|
135
|
private String qualify(String id)
|
709
|
|
{
|
710
|
135
|
return IdUtils.qualify(_md.getModuleId(), id);
|
711
|
|
}
|
712
|
|
|
713
|
4
|
private DocumentBuilder getBuilder()
|
714
|
|
{
|
715
|
4
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
716
|
|
|
717
|
4
|
factory.setIgnoringComments(true);
|
718
|
|
|
719
|
4
|
try
|
720
|
|
{
|
721
|
4
|
return factory.newDocumentBuilder();
|
722
|
|
}
|
723
|
|
catch (ParserConfigurationException e)
|
724
|
|
{
|
725
|
0
|
throw new ApplicationRuntimeException(e);
|
726
|
|
}
|
727
|
|
}
|
728
|
|
|
729
|
0
|
public static Document createDefaultRegistryDocument()
|
730
|
|
{
|
731
|
0
|
ClassResolver resolver = new DefaultClassResolver();
|
732
|
0
|
ModuleDescriptorProvider provider = new XmlModuleDescriptorProvider(resolver);
|
733
|
|
|
734
|
0
|
RegistrySerializer serializer = new RegistrySerializer();
|
735
|
|
|
736
|
0
|
serializer.addModuleDescriptorProvider(provider);
|
737
|
|
|
738
|
0
|
return serializer.createRegistryDocument();
|
739
|
|
}
|
740
|
|
}
|