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