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