1
2
3
4
5
6 package org.codehaus.modello.test.features.io.jdom;
7
8
9
10
11
12 import java.io.OutputStream;
13 import java.io.OutputStreamWriter;
14 import java.io.Writer;
15 import java.text.DateFormat;
16 import java.util.ArrayList;
17 import java.util.Arrays;
18 import java.util.Collection;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.ListIterator;
22 import java.util.Locale;
23 import java.util.Map;
24 import java.util.Properties;
25 import org.codehaus.modello.test.features.Action;
26 import org.codehaus.modello.test.features.AnnotationTest;
27 import org.codehaus.modello.test.features.ArrayFeatures;
28 import org.codehaus.modello.test.features.AssociationFeatures;
29 import org.codehaus.modello.test.features.BaseClass;
30 import org.codehaus.modello.test.features.BidiInList;
31 import org.codehaus.modello.test.features.BidiInSet;
32 import org.codehaus.modello.test.features.Bidirectional;
33 import org.codehaus.modello.test.features.ContentTest;
34 import org.codehaus.modello.test.features.DueTo;
35 import org.codehaus.modello.test.features.Features;
36 import org.codehaus.modello.test.features.File;
37 import org.codehaus.modello.test.features.InterfacesFeature;
38 import org.codehaus.modello.test.features.JavaFeatures;
39 import org.codehaus.modello.test.features.NodeItem;
40 import org.codehaus.modello.test.features.Reference;
41 import org.codehaus.modello.test.features.SimpleInterface;
42 import org.codehaus.modello.test.features.SimpleTypes;
43 import org.codehaus.modello.test.features.SubClassLevel1;
44 import org.codehaus.modello.test.features.SubClassLevel2;
45 import org.codehaus.modello.test.features.SubClassLevel3;
46 import org.codehaus.modello.test.features.SubInterface;
47 import org.codehaus.modello.test.features.SuperThing;
48 import org.codehaus.modello.test.features.Thing;
49 import org.codehaus.modello.test.features.Thingy;
50 import org.codehaus.modello.test.features.XdocFeatures;
51 import org.codehaus.modello.test.features.XmlAttributes;
52 import org.codehaus.modello.test.features.XmlContent;
53 import org.codehaus.modello.test.features.XmlContentLong;
54 import org.codehaus.modello.test.features.XmlContentLongWithAttributes;
55 import org.codehaus.modello.test.features.XmlFeatures;
56 import org.codehaus.modello.test.features.XmlFieldsOrder;
57 import org.codehaus.modello.test.features.XmlFieldsOrderParent;
58 import org.codehaus.modello.test.features.XmlFieldsOrderParent2;
59 import org.codehaus.modello.test.features.XmlTransientFields;
60 import org.codehaus.modello.test.features.XsdFeatures;
61 import org.codehaus.modello.test.features.other.PackageNameFeature;
62 import org.codehaus.modello.test.features.other.SubInterfaceInPackage;
63 import org.codehaus.plexus.util.xml.Xpp3Dom;
64 import org.jdom2.Content;
65 import org.jdom2.DefaultJDOMFactory;
66 import org.jdom2.Document;
67 import org.jdom2.Element;
68 import org.jdom2.JDOMFactory;
69 import org.jdom2.Namespace;
70 import org.jdom2.Parent;
71 import org.jdom2.Text;
72 import org.jdom2.output.Format;
73 import org.jdom2.output.XMLOutputter;
74
75
76
77
78
79
80 @SuppressWarnings( "all" )
81 public class ModelloFeaturesTestJDOMWriter
82 {
83
84
85
86
87
88
89
90
91 private final JDOMFactory factory;
92
93
94
95
96 private final String lineSeparator;
97
98
99
100
101
102
103 public ModelloFeaturesTestJDOMWriter()
104 {
105 this( new DefaultJDOMFactory() );
106 }
107
108 public ModelloFeaturesTestJDOMWriter(JDOMFactory factory)
109 {
110 this.factory = factory;
111 this.lineSeparator = "\n";
112 }
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 protected Element findAndReplaceSimpleElement( Counter counter, Element parent, String name, String text, String defaultValue )
130 {
131 if ( ( defaultValue != null ) && ( text != null ) && defaultValue.equals( text ) )
132 {
133 Element element = parent.getChild( name, parent.getNamespace() );
134
135 if ( ( element != null && defaultValue.equals( element.getText() ) ) || element == null )
136 {
137 return element;
138 }
139 }
140 boolean shouldExist = ( text != null ) && ( text.trim().length() > 0 );
141 Element element = updateElement( counter, parent, name );
142 if ( shouldExist )
143 {
144 element.setText( text );
145 }
146 return element;
147 }
148
149
150
151
152
153
154
155
156
157
158
159 protected Element findAndReplaceSimpleLists( Counter counter, Element parent, java.util.Collection list, String parentName, String childName )
160 {
161 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
162 Element element = updateElement( counter, parent, parentName );
163 if ( shouldExist )
164 {
165 Iterator it = list.iterator();
166 Counter innerCount = new Counter( counter.getDepth() + 1 );
167 while ( it.hasNext() )
168 {
169 String value = (String) it.next();
170 Element el = factory.element( childName, element.getNamespace() );
171 insertAtPreferredLocation( element, el, innerCount );
172 el.setText( value );
173 innerCount.increaseCount();
174 }
175 }
176 return element;
177 }
178
179
180
181
182
183
184
185
186
187
188 protected Element findAndReplaceXpp3DOM( Counter counter, Element parent, String name, Xpp3Dom dom )
189 {
190 boolean shouldExist = ( dom != null ) && ( dom.getChildCount() > 0 || dom.getValue() != null );
191 Element element = updateElement( counter, parent, name );
192 if ( shouldExist )
193 {
194 replaceXpp3DOM( element, dom, new Counter( counter.getDepth() + 1 ) );
195 }
196 return element;
197 }
198
199
200
201
202
203
204
205
206 protected void insertAtPreferredLocation( Element parent, Element child, Counter counter )
207 {
208 int contentIndex = 0;
209 int elementCounter = 0;
210 Iterator it = parent.getContent().iterator();
211 Text lastText = null;
212 int offset = 0;
213 while ( it.hasNext() && elementCounter <= counter.getCurrentIndex() )
214 {
215 Object next = it.next();
216 offset = offset + 1;
217 if ( next instanceof Element )
218 {
219 elementCounter = elementCounter + 1;
220 contentIndex = contentIndex + offset;
221 offset = 0;
222 }
223 if ( next instanceof Text && it.hasNext() )
224 {
225 lastText = (Text) next;
226 }
227 }
228 if ( lastText != null && lastText.getTextTrim().length() == 0 )
229 {
230 lastText = (Text) lastText.clone();
231 }
232 else
233 {
234 String starter = lineSeparator;
235 for ( int i = 0; i < counter.getDepth(); i++ )
236 {
237 starter = starter + " ";
238 }
239 lastText = factory.text( starter );
240 }
241 if ( parent.getContentSize() == 0 )
242 {
243 Text finalText = (Text) lastText.clone();
244 finalText.setText( finalText.getText().substring( 0, finalText.getText().length() - " ".length() ) );
245 parent.addContent( contentIndex, finalText );
246 }
247 parent.addContent( contentIndex, child );
248 parent.addContent( contentIndex, lastText );
249 }
250
251
252
253
254
255
256
257
258
259 protected void iterate2Reference( Counter counter, Element parent, java.util.Collection list, java.lang.String childTag )
260 {
261 Iterator it = list.iterator();
262 while ( it.hasNext() )
263 {
264 Reference/../../../../../../org/codehaus/modello/test/features/Reference.html#Reference">Reference value = (Reference) it.next();
265 updateReference( value, childTag, counter, parent );
266 }
267 }
268
269
270
271
272
273
274
275
276
277
278 protected void iterateBidiInList( Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag )
279 {
280 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
281 Element element = updateElement( counter, parent, parentTag );
282 if ( shouldExist )
283 {
284 Iterator it = list.iterator();
285 Counter innerCount = new Counter( counter.getDepth() + 1 );
286 while ( it.hasNext() )
287 {
288 BidiInList../../../../../../org/codehaus/modello/test/features/BidiInList.html#BidiInList">BidiInList value = (BidiInList) it.next();
289 updateBidiInList( value, childTag, innerCount, element );
290 innerCount.increaseCount();
291 }
292 }
293 }
294
295
296
297
298
299
300
301
302
303
304 protected void iterateBidiInSet( Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag )
305 {
306 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
307 Element element = updateElement( counter, parent, parentTag );
308 if ( shouldExist )
309 {
310 Iterator it = list.iterator();
311 Counter innerCount = new Counter( counter.getDepth() + 1 );
312 while ( it.hasNext() )
313 {
314 BidiInSet/../../../../../../org/codehaus/modello/test/features/BidiInSet.html#BidiInSet">BidiInSet value = (BidiInSet) it.next();
315 updateBidiInSet( value, childTag, innerCount, element );
316 innerCount.increaseCount();
317 }
318 }
319 }
320
321
322
323
324
325
326
327
328
329
330 protected void iterateReference( Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag )
331 {
332 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
333 Element element = updateElement( counter, parent, parentTag );
334 if ( shouldExist )
335 {
336 Iterator it = list.iterator();
337 Counter innerCount = new Counter( counter.getDepth() + 1 );
338 while ( it.hasNext() )
339 {
340 Reference/../../../../../../org/codehaus/modello/test/features/Reference.html#Reference">Reference value = (Reference) it.next();
341 updateReference( value, childTag, innerCount, element );
342 innerCount.increaseCount();
343 }
344 }
345 }
346
347
348
349
350
351
352
353
354
355
356 protected void iterateThingy( Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag )
357 {
358 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
359 Element element = updateElement( counter, parent, parentTag );
360 if ( shouldExist )
361 {
362 Iterator it = list.iterator();
363 Counter innerCount = new Counter( counter.getDepth() + 1 );
364 while ( it.hasNext() )
365 {
366 Thingy"../../../../../../../org/codehaus/modello/test/features/Thingy.html#Thingy">Thingy value = (Thingy) it.next();
367 updateThingy( value, childTag, innerCount, element );
368 innerCount.increaseCount();
369 }
370 }
371 }
372
373
374
375
376
377
378
379
380 protected void replaceXpp3DOM( Element parent, Xpp3Dom parentDom, Counter counter )
381 {
382 for( String attributeName : parentDom.getAttributeNames() )
383 {
384 String[] attrDetails = attributeName.split( ":", 2 );
385 if ( attrDetails.length == 2 )
386 {
387 parent.setAttribute( attrDetails[1], parentDom.getAttribute( attributeName ), parent.getNamespace( attrDetails[0] ) );
388 }
389 else
390 {
391 parent.setAttribute( attributeName, parentDom.getAttribute( attributeName ) );
392 }
393 }
394 if ( parentDom.getChildCount() > 0 )
395 {
396 Xpp3Dom[] childs = parentDom.getChildren();
397 Collection domChilds = new ArrayList();
398 for ( int i = 0; i < childs.length; i++ )
399 {
400 domChilds.add( childs[i] );
401 }
402 ListIterator it = parent.getChildren().listIterator();
403 while ( it.hasNext() )
404 {
405 Element elem = (Element) it.next();
406 Iterator it2 = domChilds.iterator();
407 Xpp3Dom corrDom = null;
408 while ( it2.hasNext() )
409 {
410 Xpp3Dom dm = (Xpp3Dom) it2.next();
411 if ( dm.getName().equals( elem.getName() ) )
412 {
413 corrDom = dm;
414 break;
415 }
416 }
417 if ( corrDom != null )
418 {
419 domChilds.remove( corrDom );
420 replaceXpp3DOM( elem, corrDom, new Counter( counter.getDepth() + 1 ) );
421 counter.increaseCount();
422 }
423 else
424 {
425 it.remove();
426 }
427 }
428 Iterator it2 = domChilds.iterator();
429 while ( it2.hasNext() )
430 {
431 Xpp3Dom dm = (Xpp3Dom) it2.next();
432 Element elem = factory.element( dm.getName(), parent.getNamespace() );
433 insertAtPreferredLocation( parent, elem, counter );
434 counter.increaseCount();
435 replaceXpp3DOM( elem, dm, new Counter( counter.getDepth() + 1 ) );
436 }
437 }
438 else if ( parentDom.getValue() != null )
439 {
440 parent.setText( parentDom.getValue() );
441 }
442 }
443
444
445
446
447
448
449
450
451
452 protected void updateAction( Action action, String xmlTag, Counter counter, Element element )
453 {
454 if ( action != null )
455 {
456 Element root = updateElement( counter, element, xmlTag );
457 Counter innerCount = new Counter( counter.getDepth() + 1 );
458 if ( action.getDev() != null )
459 {
460 root.setAttribute( "dev", action.getDev() );
461 }
462 root.setText( action.getAction() );
463 }
464 }
465
466
467
468
469
470
471
472
473
474 protected void updateAnnotationTest( AnnotationTest annotationTest, String xmlTag, Counter counter, Element element )
475 {
476 if ( annotationTest != null )
477 {
478 Element root = updateElement( counter, element, xmlTag );
479 Counter innerCount = new Counter( counter.getDepth() + 1 );
480 if ( annotationTest.getAnyField() != null )
481 {
482 updateElement( innerCount, root, "anyField" ).setText( annotationTest.getAnyField() );
483 }
484 }
485 }
486
487
488
489
490
491
492
493
494
495 protected void updateArrayFeatures( ArrayFeatures arrayFeatures, String xmlTag, Counter counter, Element element )
496 {
497 if ( arrayFeatures != null )
498 {
499 Element root = updateElement( counter, element, xmlTag );
500 Counter innerCount = new Counter( counter.getDepth() + 1 );
501 }
502 }
503
504
505
506
507
508
509
510
511
512 protected void updateAssociationFeatures( AssociationFeatures associationFeatures, String xmlTag, Counter counter, Element element )
513 {
514 if ( associationFeatures != null )
515 {
516 Element root = updateElement( counter, element, xmlTag );
517 Counter innerCount = new Counter( counter.getDepth() + 1 );
518 iterateReference( innerCount, root, associationFeatures.getListReferences(),"listReferences","listReference" );
519 iterateReference( innerCount, root, associationFeatures.getSetReferences(),"setReferences","setReference" );
520 findAndReplaceSimpleLists( innerCount, root, associationFeatures.getListStrings(), "listStrings", "listString" );
521 findAndReplaceSimpleLists( innerCount, root, associationFeatures.getSetStrings(), "setStrings", "setString" );
522 if ( ( associationFeatures.getProperties() != null ) && ( associationFeatures.getProperties().size() > 0 ) )
523 {
524 Element listElement = updateElement( innerCount, root, "properties" );
525 Iterator it = associationFeatures.getProperties().keySet().iterator();
526 Counter propertiesCounter = new Counter( innerCount.getDepth() + 1 );
527 while ( it.hasNext() )
528 {
529 String key = (String) it.next();
530 findAndReplaceSimpleElement( propertiesCounter, listElement, key, (String) associationFeatures.getProperties().get( key ), null );
531 }
532 }
533 if ( associationFeatures.getBidi() != null )
534 {
535 updateBidirectional( associationFeatures.getBidi(), "bidi", innerCount, root );
536 }
537 iterateBidiInList( innerCount, root, associationFeatures.getListOfBidis(),"listOfBidis","listOfBidi" );
538 iterateBidiInSet( innerCount, root, associationFeatures.getSetOfBidis(),"setOfBidis","setOfBidi" );
539 }
540 }
541
542
543
544
545
546
547
548
549
550 protected void updateBaseClass( BaseClass baseClass, String xmlTag, Counter counter, Element element )
551 {
552 if ( baseClass != null )
553 {
554 Element root = updateElement( counter, element, xmlTag );
555 Counter innerCount = new Counter( counter.getDepth() + 1 );
556 if ( baseClass.getBaseElement() != 0 )
557 {
558 updateElement( innerCount, root, "baseElement" ).setText( String.valueOf( baseClass.getBaseElement() ) );
559 }
560 if ( baseClass.getBaseAttribute() != 0 )
561 {
562 root.setAttribute( "baseAttribute", String.valueOf( baseClass.getBaseAttribute() ) );
563 }
564 }
565 }
566
567
568
569
570
571
572
573
574
575 protected void updateBidiInList( BidiInList bidiInList, String xmlTag, Counter counter, Element element )
576 {
577 if ( bidiInList != null )
578 {
579 Element root = updateElement( counter, element, xmlTag );
580 Counter innerCount = new Counter( counter.getDepth() + 1 );
581 if ( bidiInList.getParent() != null )
582 {
583 updateAssociationFeatures( bidiInList.getParent(), "parent", innerCount, root );
584 }
585 }
586 }
587
588
589
590
591
592
593
594
595
596 protected void updateBidiInSet( BidiInSet bidiInSet, String xmlTag, Counter counter, Element element )
597 {
598 if ( bidiInSet != null )
599 {
600 Element root = updateElement( counter, element, xmlTag );
601 Counter innerCount = new Counter( counter.getDepth() + 1 );
602 if ( bidiInSet.getParent() != null )
603 {
604 updateAssociationFeatures( bidiInSet.getParent(), "parent", innerCount, root );
605 }
606 }
607 }
608
609
610
611
612
613
614
615
616
617 protected void updateBidirectional( Bidirectional bidirectional, String xmlTag, Counter counter, Element element )
618 {
619 if ( bidirectional != null )
620 {
621 Element root = updateElement( counter, element, xmlTag );
622 Counter innerCount = new Counter( counter.getDepth() + 1 );
623 if ( bidirectional.getParent() != null )
624 {
625 updateAssociationFeatures( bidirectional.getParent(), "parent", innerCount, root );
626 }
627 }
628 }
629
630
631
632
633
634
635
636
637
638 protected void updateContentTest( ContentTest contentTest, String xmlTag, Counter counter, Element element )
639 {
640 if ( contentTest != null )
641 {
642 Element root = updateElement( counter, element, xmlTag );
643 Counter innerCount = new Counter( counter.getDepth() + 1 );
644 if ( contentTest.getAttr() != null )
645 {
646 root.setAttribute( "attr", contentTest.getAttr() );
647 }
648 if ( contentTest.getAttr2() != 0 )
649 {
650 root.setAttribute( "attr2", String.valueOf( contentTest.getAttr2() ) );
651 }
652 root.setText( contentTest.getContent() );
653 }
654 }
655
656
657
658
659
660
661
662
663
664 protected void updateDueTo( DueTo dueTo, String xmlTag, Counter counter, Element element )
665 {
666 if ( dueTo != null )
667 {
668 Element root = updateElement( counter, element, xmlTag );
669 Counter innerCount = new Counter( counter.getDepth() + 1 );
670 if ( dueTo.getName() != null )
671 {
672 root.setAttribute( "name", dueTo.getName() );
673 }
674 if ( dueTo.getEmail() != null )
675 {
676 root.setAttribute( "email", dueTo.getEmail() );
677 }
678 }
679 }
680
681
682
683
684
685
686
687
688
689 protected Element updateElement( Counter counter, Element parent, String name )
690 {
691 Element element = factory.element( name, parent.getNamespace() );
692 insertAtPreferredLocation( parent, element, counter );
693 counter.increaseCount();
694 return element;
695 }
696
697
698
699
700
701
702
703
704
705 protected void updateFeatures( Features features, String xmlTag, Counter counter, Document document )
706 {
707 if ( features != null )
708 {
709 Element root = factory.element( xmlTag, "http://codehaus-plexus.github.io/FEATURES/1.0.0" );
710 Namespace xsins = Namespace.getNamespace( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
711 root.setAttribute( "schemaLocation", "http://codehaus-plexus.github.io/FEATURES/1.0.0 http://codehaus-plexus.github.io/features-1.0.0.xsd", xsins );
712 document.setRootElement( root );
713 Counter innerCount = new Counter( counter.getDepth() + 1 );
714 if ( features.getVersionField() != null )
715 {
716 updateElement( innerCount, root, "versionField" ).setText( features.getVersionField() );
717 }
718 if ( features.getComment() != null )
719 {
720 updateElement( innerCount, root, "comment" ).setText( features.getComment() );
721 }
722 if ( features.getDescription() != null )
723 {
724 updateElement( innerCount, root, "description" ).setText( features.getDescription() );
725 }
726 if ( features.getRequired() != null )
727 {
728 updateElement( innerCount, root, "required" ).setText( features.getRequired() );
729 }
730 if ( features.getIdentifier() != null )
731 {
732 updateElement( innerCount, root, "identifier" ).setText( features.getIdentifier() );
733 }
734 if ( features.getIdentifierPart2() != null )
735 {
736 updateReference( features.getIdentifierPart2(), "identifierPart2", innerCount, root );
737 }
738 if ( features.getSimpleTypes() != null )
739 {
740 updateSimpleTypes( features.getSimpleTypes(), "simpleTypes", innerCount, root );
741 }
742 if ( features.getDefaultValues() != null )
743 {
744 updateSimpleTypes( features.getDefaultValues(), "defaultValues", innerCount, root );
745 }
746 if ( features.getArrays() != null )
747 {
748 updateArrayFeatures( features.getArrays(), "arrays", innerCount, root );
749 }
750 if ( features.getAssociationFeatures() != null )
751 {
752 updateAssociationFeatures( features.getAssociationFeatures(), "associationFeatures", innerCount, root );
753 }
754 if ( features.getJavaFeatures() != null )
755 {
756 updateJavaFeatures( features.getJavaFeatures(), "javaFeatures", innerCount, root );
757 }
758 if ( features.getXmlFeatures() != null )
759 {
760 updateXmlFeatures( features.getXmlFeatures(), "xmlFeatures", innerCount, root );
761 }
762 if ( features.getXdocFeatures() != null )
763 {
764 updateXdocFeatures( features.getXdocFeatures(), "xdocFeatures", innerCount, root );
765 }
766 if ( features.getNode() != null )
767 {
768 updateNodeItem( features.getNode(), "node", innerCount, root );
769 }
770 if ( features.getCloneable() != null )
771 {
772 updateThing( features.getCloneable(), "cloneable", innerCount, root );
773 }
774 if ( features.getFile() != null )
775 {
776 updateFile( features.getFile(), "file", innerCount, root );
777 }
778 if ( features.getAction() != null )
779 {
780 updateAction( features.getAction(), "action", innerCount, root );
781 }
782 }
783 }
784
785
786
787
788
789
790
791
792
793 protected void updateFile( File file, String xmlTag, Counter counter, Element element )
794 {
795 if ( file != null )
796 {
797 Element root = updateElement( counter, element, xmlTag );
798 Counter innerCount = new Counter( counter.getDepth() + 1 );
799 if ( file.getFile() != null )
800 {
801 updateElement( innerCount, root, "file" ).setText( file.getFile() );
802 }
803 }
804 }
805
806
807
808
809
810
811
812
813
814 protected void updateInterfacesFeature( InterfacesFeature interfacesFeature, String xmlTag, Counter counter, Element element )
815 {
816 if ( interfacesFeature != null )
817 {
818 Element root = updateElement( counter, element, xmlTag );
819 Counter innerCount = new Counter( counter.getDepth() + 1 );
820 if ( interfacesFeature.getId() != null )
821 {
822 updateElement( innerCount, root, "id" ).setText( interfacesFeature.getId() );
823 }
824 }
825 }
826
827
828
829
830
831
832
833
834
835 protected void updateJavaFeatures( JavaFeatures javaFeatures, String xmlTag, Counter counter, Element element )
836 {
837 if ( javaFeatures != null )
838 {
839 Element root = updateElement( counter, element, xmlTag );
840 Counter innerCount = new Counter( counter.getDepth() + 1 );
841 if ( javaFeatures.getInterfaces() != null )
842 {
843 updateInterfacesFeature( javaFeatures.getInterfaces(), "interfaces", innerCount, root );
844 }
845 if ( javaFeatures.getPackageName() != null )
846 {
847 updatePackageNameFeature( javaFeatures.getPackageName(), "packageName", innerCount, root );
848 }
849 if ( javaFeatures.getBase() != null )
850 {
851 updateBaseClass( javaFeatures.getBase(), "base", innerCount, root );
852 }
853 if ( javaFeatures.getSubClass() != null )
854 {
855 updateSubClassLevel1( javaFeatures.getSubClass(), "subClass", innerCount, root );
856 }
857 if ( javaFeatures.getSubClass2() != null )
858 {
859 updateSubClassLevel2( javaFeatures.getSubClass2(), "subClass2", innerCount, root );
860 }
861 if ( javaFeatures.getSubClass3() != null )
862 {
863 updateSubClassLevel3( javaFeatures.getSubClass3(), "subClass3", innerCount, root );
864 }
865 if ( javaFeatures.getAnnotation() != null )
866 {
867 updateAnnotationTest( javaFeatures.getAnnotation(), "annotation", innerCount, root );
868 }
869 }
870 }
871
872
873
874
875
876
877
878
879
880 protected void updateNodeItem( NodeItem nodeItem, String xmlTag, Counter counter, Element element )
881 {
882 if ( nodeItem != null )
883 {
884 Element root = updateElement( counter, element, xmlTag );
885 Counter innerCount = new Counter( counter.getDepth() + 1 );
886 if ( nodeItem.getValue() != null )
887 {
888 updateElement( innerCount, root, "value" ).setText( nodeItem.getValue() );
889 }
890 if ( nodeItem.getChild() != null )
891 {
892 updateNodeItem( nodeItem.getChild(), "child", innerCount, root );
893 }
894 }
895 }
896
897
898
899
900
901
902
903
904
905 protected void updatePackageNameFeature( PackageNameFeature packageNameFeature, String xmlTag, Counter counter, Element element )
906 {
907 if ( packageNameFeature != null )
908 {
909 Element root = updateElement( counter, element, xmlTag );
910 Counter innerCount = new Counter( counter.getDepth() + 1 );
911 if ( packageNameFeature.getReference() != null )
912 {
913 updateReference( packageNameFeature.getReference(), "reference", innerCount, root );
914 }
915 }
916 }
917
918
919
920
921
922
923
924
925
926 protected void updateReference( Reference reference, String xmlTag, Counter counter, Element element )
927 {
928 if ( reference != null )
929 {
930 Element root = updateElement( counter, element, xmlTag );
931 Counter innerCount = new Counter( counter.getDepth() + 1 );
932 if ( reference.getId() != null )
933 {
934 updateElement( innerCount, root, "id" ).setText( reference.getId() );
935 }
936 }
937 }
938
939
940
941
942
943
944
945
946
947 protected void updateSimpleTypes( SimpleTypes simpleTypes, String xmlTag, Counter counter, Element element )
948 {
949 if ( simpleTypes != null )
950 {
951 Element root = updateElement( counter, element, xmlTag );
952 Counter innerCount = new Counter( counter.getDepth() + 1 );
953 if ( simpleTypes.isPrimitiveBoolean() != true )
954 {
955 updateElement( innerCount, root, "primitiveBoolean" ).setText( String.valueOf( simpleTypes.isPrimitiveBoolean() ) );
956 }
957 if ( simpleTypes.getPrimitiveChar() != 'H' )
958 {
959 updateElement( innerCount, root, "primitiveChar" ).setText( String.valueOf( simpleTypes.getPrimitiveChar() ) );
960 }
961 if ( simpleTypes.getPrimitiveByte() != 12 )
962 {
963 updateElement( innerCount, root, "primitiveByte" ).setText( String.valueOf( simpleTypes.getPrimitiveByte() ) );
964 }
965 if ( simpleTypes.getPrimitiveShort() != 1212 )
966 {
967 updateElement( innerCount, root, "primitiveShort" ).setText( String.valueOf( simpleTypes.getPrimitiveShort() ) );
968 }
969 if ( simpleTypes.getPrimitiveInt() != 121212 )
970 {
971 updateElement( innerCount, root, "primitiveInt" ).setText( String.valueOf( simpleTypes.getPrimitiveInt() ) );
972 }
973 if ( simpleTypes.getPrimitiveLong() != 1234567890123L )
974 {
975 updateElement( innerCount, root, "primitiveLong" ).setText( String.valueOf( simpleTypes.getPrimitiveLong() ) );
976 }
977 if ( simpleTypes.getPrimitiveFloat() != 12.12f )
978 {
979 updateElement( innerCount, root, "primitiveFloat" ).setText( String.valueOf( simpleTypes.getPrimitiveFloat() ) );
980 }
981 if ( simpleTypes.getPrimitiveDouble() != 12.12 )
982 {
983 updateElement( innerCount, root, "primitiveDouble" ).setText( String.valueOf( simpleTypes.getPrimitiveDouble() ) );
984 }
985 if ( ( simpleTypes.getObjectString() != null ) && !simpleTypes.getObjectString().equals( "default value" ) )
986 {
987 updateElement( innerCount, root, "objectString" ).setText( simpleTypes.getObjectString() );
988 }
989 if ( ( simpleTypes.getObjectDate() != null ) && !simpleTypes.getObjectDate().equals( new java.util.Date( 1356383532012L ) ) )
990 {
991 updateElement( innerCount, root, "objectDate" ).setText( new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS", java.util.Locale.US ).format( simpleTypes.getObjectDate() ) );
992 }
993 if ( simpleTypes.isPrimitiveBooleanNoDefault() != false )
994 {
995 updateElement( innerCount, root, "primitiveBooleanNoDefault" ).setText( String.valueOf( simpleTypes.isPrimitiveBooleanNoDefault() ) );
996 }
997 if ( simpleTypes.getPrimitiveCharNoDefault() != '\0' )
998 {
999 updateElement( innerCount, root, "primitiveCharNoDefault" ).setText( String.valueOf( simpleTypes.getPrimitiveCharNoDefault() ) );
1000 }
1001 if ( simpleTypes.getPrimitiveByteNoDefault() != 0 )
1002 {
1003 updateElement( innerCount, root, "primitiveByteNoDefault" ).setText( String.valueOf( simpleTypes.getPrimitiveByteNoDefault() ) );
1004 }
1005 if ( simpleTypes.getPrimitiveShortNoDefault() != 0 )
1006 {
1007 updateElement( innerCount, root, "primitiveShortNoDefault" ).setText( String.valueOf( simpleTypes.getPrimitiveShortNoDefault() ) );
1008 }
1009 if ( simpleTypes.getPrimitiveIntNoDefault() != 0 )
1010 {
1011 updateElement( innerCount, root, "primitiveIntNoDefault" ).setText( String.valueOf( simpleTypes.getPrimitiveIntNoDefault() ) );
1012 }
1013 if ( simpleTypes.getPrimitiveLongNoDefault() != 0L )
1014 {
1015 updateElement( innerCount, root, "primitiveLongNoDefault" ).setText( String.valueOf( simpleTypes.getPrimitiveLongNoDefault() ) );
1016 }
1017 if ( simpleTypes.getPrimitiveFloatNoDefault() != 0.0f )
1018 {
1019 updateElement( innerCount, root, "primitiveFloatNoDefault" ).setText( String.valueOf( simpleTypes.getPrimitiveFloatNoDefault() ) );
1020 }
1021 if ( simpleTypes.getPrimitiveDoubleNoDefault() != 0.0 )
1022 {
1023 updateElement( innerCount, root, "primitiveDoubleNoDefault" ).setText( String.valueOf( simpleTypes.getPrimitiveDoubleNoDefault() ) );
1024 }
1025 if ( simpleTypes.getObjectStringNoDefault() != null )
1026 {
1027 updateElement( innerCount, root, "objectStringNoDefault" ).setText( simpleTypes.getObjectStringNoDefault() );
1028 }
1029 if ( simpleTypes.getObjectDateNoDefault() != null )
1030 {
1031 updateElement( innerCount, root, "objectDateNoDefault" ).setText( new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS", java.util.Locale.US ).format( simpleTypes.getObjectDateNoDefault() ) );
1032 }
1033 findAndReplaceXpp3DOM( innerCount, root, "dom", (Xpp3Dom) simpleTypes.getDom() );
1034 if ( simpleTypes.getContent() != null )
1035 {
1036 updateContentTest( simpleTypes.getContent(), "content", innerCount, root );
1037 }
1038 }
1039 }
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049 protected void updateSubClassLevel1( SubClassLevel1 subClassLevel1, String xmlTag, Counter counter, Element element )
1050 {
1051 if ( subClassLevel1 != null )
1052 {
1053 Element root = updateElement( counter, element, xmlTag );
1054 Counter innerCount = new Counter( counter.getDepth() + 1 );
1055 if ( subClassLevel1.getSubElement1() != 0L )
1056 {
1057 updateElement( innerCount, root, "subElement1" ).setText( String.valueOf( subClassLevel1.getSubElement1() ) );
1058 }
1059 if ( subClassLevel1.getSubAttribute1() != 0L )
1060 {
1061 root.setAttribute( "subAttribute1", String.valueOf( subClassLevel1.getSubAttribute1() ) );
1062 }
1063 if ( subClassLevel1.getBaseElement() != 0 )
1064 {
1065 updateElement( innerCount, root, "baseElement" ).setText( String.valueOf( subClassLevel1.getBaseElement() ) );
1066 }
1067 if ( subClassLevel1.getBaseAttribute() != 0 )
1068 {
1069 root.setAttribute( "baseAttribute", String.valueOf( subClassLevel1.getBaseAttribute() ) );
1070 }
1071 }
1072 }
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082 protected void updateSubClassLevel2( SubClassLevel2 subClassLevel2, String xmlTag, Counter counter, Element element )
1083 {
1084 if ( subClassLevel2 != null )
1085 {
1086 Element root = updateElement( counter, element, xmlTag );
1087 Counter innerCount = new Counter( counter.getDepth() + 1 );
1088 if ( subClassLevel2.getSubElement2() != 0.0f )
1089 {
1090 updateElement( innerCount, root, "subElement2" ).setText( String.valueOf( subClassLevel2.getSubElement2() ) );
1091 }
1092 if ( subClassLevel2.getSubAttribute2() != 0.0f )
1093 {
1094 root.setAttribute( "subAttribute2", String.valueOf( subClassLevel2.getSubAttribute2() ) );
1095 }
1096 if ( subClassLevel2.getSubElement1() != 0L )
1097 {
1098 updateElement( innerCount, root, "subElement1" ).setText( String.valueOf( subClassLevel2.getSubElement1() ) );
1099 }
1100 if ( subClassLevel2.getSubAttribute1() != 0L )
1101 {
1102 root.setAttribute( "subAttribute1", String.valueOf( subClassLevel2.getSubAttribute1() ) );
1103 }
1104 if ( subClassLevel2.getBaseElement() != 0 )
1105 {
1106 updateElement( innerCount, root, "baseElement" ).setText( String.valueOf( subClassLevel2.getBaseElement() ) );
1107 }
1108 if ( subClassLevel2.getBaseAttribute() != 0 )
1109 {
1110 root.setAttribute( "baseAttribute", String.valueOf( subClassLevel2.getBaseAttribute() ) );
1111 }
1112 }
1113 }
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123 protected void updateSubClassLevel3( SubClassLevel3 subClassLevel3, String xmlTag, Counter counter, Element element )
1124 {
1125 if ( subClassLevel3 != null )
1126 {
1127 Element root = updateElement( counter, element, xmlTag );
1128 Counter innerCount = new Counter( counter.getDepth() + 1 );
1129 if ( subClassLevel3.getSubElement3() != 0.0 )
1130 {
1131 updateElement( innerCount, root, "subElement3" ).setText( String.valueOf( subClassLevel3.getSubElement3() ) );
1132 }
1133 if ( subClassLevel3.getSubAttribute3() != 0.0 )
1134 {
1135 root.setAttribute( "subAttribute3", String.valueOf( subClassLevel3.getSubAttribute3() ) );
1136 }
1137 if ( subClassLevel3.getSubElement2() != 0.0f )
1138 {
1139 updateElement( innerCount, root, "subElement2" ).setText( String.valueOf( subClassLevel3.getSubElement2() ) );
1140 }
1141 if ( subClassLevel3.getSubAttribute2() != 0.0f )
1142 {
1143 root.setAttribute( "subAttribute2", String.valueOf( subClassLevel3.getSubAttribute2() ) );
1144 }
1145 if ( subClassLevel3.getSubElement1() != 0L )
1146 {
1147 updateElement( innerCount, root, "subElement1" ).setText( String.valueOf( subClassLevel3.getSubElement1() ) );
1148 }
1149 if ( subClassLevel3.getSubAttribute1() != 0L )
1150 {
1151 root.setAttribute( "subAttribute1", String.valueOf( subClassLevel3.getSubAttribute1() ) );
1152 }
1153 if ( subClassLevel3.getBaseElement() != 0 )
1154 {
1155 updateElement( innerCount, root, "baseElement" ).setText( String.valueOf( subClassLevel3.getBaseElement() ) );
1156 }
1157 if ( subClassLevel3.getBaseAttribute() != 0 )
1158 {
1159 root.setAttribute( "baseAttribute", String.valueOf( subClassLevel3.getBaseAttribute() ) );
1160 }
1161 }
1162 }
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172 protected void updateSuperThing( SuperThing superThing, String xmlTag, Counter counter, Element element )
1173 {
1174 if ( superThing != null )
1175 {
1176 Element root = updateElement( counter, element, xmlTag );
1177 Counter innerCount = new Counter( counter.getDepth() + 1 );
1178 }
1179 }
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189 protected void updateThing( Thing thing, String xmlTag, Counter counter, Element element )
1190 {
1191 if ( thing != null )
1192 {
1193 Element root = updateElement( counter, element, xmlTag );
1194 Counter innerCount = new Counter( counter.getDepth() + 1 );
1195 if ( thing.isSomeBoolean() != false )
1196 {
1197 updateElement( innerCount, root, "someBoolean" ).setText( String.valueOf( thing.isSomeBoolean() ) );
1198 }
1199 if ( thing.getSomeChar() != '\0' )
1200 {
1201 updateElement( innerCount, root, "someChar" ).setText( String.valueOf( thing.getSomeChar() ) );
1202 }
1203 if ( thing.getSomeByte() != 0 )
1204 {
1205 updateElement( innerCount, root, "someByte" ).setText( String.valueOf( thing.getSomeByte() ) );
1206 }
1207 if ( thing.getSomeShort() != 0 )
1208 {
1209 updateElement( innerCount, root, "someShort" ).setText( String.valueOf( thing.getSomeShort() ) );
1210 }
1211 if ( thing.getSomeInt() != 0 )
1212 {
1213 updateElement( innerCount, root, "someInt" ).setText( String.valueOf( thing.getSomeInt() ) );
1214 }
1215 if ( thing.getSomeLong() != 0L )
1216 {
1217 updateElement( innerCount, root, "someLong" ).setText( String.valueOf( thing.getSomeLong() ) );
1218 }
1219 if ( thing.getSomeFloat() != 0.0f )
1220 {
1221 updateElement( innerCount, root, "someFloat" ).setText( String.valueOf( thing.getSomeFloat() ) );
1222 }
1223 if ( thing.getSomeDouble() != 0.0 )
1224 {
1225 updateElement( innerCount, root, "someDouble" ).setText( String.valueOf( thing.getSomeDouble() ) );
1226 }
1227 if ( thing.getSomeString() != null )
1228 {
1229 updateElement( innerCount, root, "someString" ).setText( thing.getSomeString() );
1230 }
1231 if ( thing.getSomeDate() != null )
1232 {
1233 updateElement( innerCount, root, "someDate" ).setText( new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS", java.util.Locale.US ).format( thing.getSomeDate() ) );
1234 }
1235 findAndReplaceXpp3DOM( innerCount, root, "someDom", (Xpp3Dom) thing.getSomeDom() );
1236 if ( ( thing.getSomeProperties() != null ) && ( thing.getSomeProperties().size() > 0 ) )
1237 {
1238 Element listElement = updateElement( innerCount, root, "someProperties" );
1239 Iterator it = thing.getSomeProperties().keySet().iterator();
1240 Counter propertiesCounter = new Counter( innerCount.getDepth() + 1 );
1241 while ( it.hasNext() )
1242 {
1243 String key = (String) it.next();
1244 findAndReplaceSimpleElement( propertiesCounter, listElement, key, (String) thing.getSomeProperties().get( key ), null );
1245 }
1246 }
1247 findAndReplaceSimpleLists( innerCount, root, thing.getSomeStringList(), "someStringList", "someStringList" );
1248 findAndReplaceSimpleLists( innerCount, root, thing.getSomeStringSet(), "someStringSet", "someStringSet" );
1249 if ( thing.getDeepThingy() != null )
1250 {
1251 updateThingy( thing.getDeepThingy(), "deepThingy", innerCount, root );
1252 }
1253 iterateThingy( innerCount, root, thing.getDeepThingyList(),"deepThingyList","deepThingyList" );
1254 iterateThingy( innerCount, root, thing.getDeepThingySet(),"deepThingySet","deepThingySet" );
1255 if ( thing.getShallowThingy() != null )
1256 {
1257 updateThingy( thing.getShallowThingy(), "shallowThingy", innerCount, root );
1258 }
1259 iterateThingy( innerCount, root, thing.getShallowThingyList(),"shallowThingyList","shallowThingyList" );
1260 iterateThingy( innerCount, root, thing.getShallowThingySet(),"shallowThingySet","shallowThingySet" );
1261 }
1262 }
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272 protected void updateThingy( Thingy thingy, String xmlTag, Counter counter, Element element )
1273 {
1274 if ( thingy != null )
1275 {
1276 Element root = updateElement( counter, element, xmlTag );
1277 Counter innerCount = new Counter( counter.getDepth() + 1 );
1278 root.setText( thingy.getSomeContent() );
1279 }
1280 }
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290 protected void updateXdocFeatures( XdocFeatures xdocFeatures, String xmlTag, Counter counter, Element element )
1291 {
1292 if ( xdocFeatures != null )
1293 {
1294 Element root = updateElement( counter, element, xmlTag );
1295 Counter innerCount = new Counter( counter.getDepth() + 1 );
1296 if ( xdocFeatures.getField() != null )
1297 {
1298 updateElement( innerCount, root, "field" ).setText( xdocFeatures.getField() );
1299 }
1300 if ( xdocFeatures.getXdocSeparatorNone() != null )
1301 {
1302 updateElement( innerCount, root, "xdocSeparatorNone" ).setText( xdocFeatures.getXdocSeparatorNone() );
1303 }
1304 if ( xdocFeatures.getXdocSeparatorBlank() != null )
1305 {
1306 updateElement( innerCount, root, "xdocSeparatorBlank" ).setText( xdocFeatures.getXdocSeparatorBlank() );
1307 }
1308 }
1309 }
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319 protected void updateXmlAttributes( XmlAttributes xmlAttributes, String xmlTag, Counter counter, Element element )
1320 {
1321 if ( xmlAttributes != null )
1322 {
1323 Element root = updateElement( counter, element, xmlTag );
1324 Counter innerCount = new Counter( counter.getDepth() + 1 );
1325 if ( xmlAttributes.isPrimitiveBoolean() != true )
1326 {
1327 root.setAttribute( "primitiveBoolean", String.valueOf( xmlAttributes.isPrimitiveBoolean() ) );
1328 }
1329 if ( xmlAttributes.getPrimitiveChar() != 'H' )
1330 {
1331 root.setAttribute( "primitiveChar", String.valueOf( xmlAttributes.getPrimitiveChar() ) );
1332 }
1333 if ( xmlAttributes.getPrimitiveByte() != 12 )
1334 {
1335 root.setAttribute( "primitiveByte", String.valueOf( xmlAttributes.getPrimitiveByte() ) );
1336 }
1337 if ( xmlAttributes.getPrimitiveShort() != 1212 )
1338 {
1339 root.setAttribute( "primitiveShort", String.valueOf( xmlAttributes.getPrimitiveShort() ) );
1340 }
1341 if ( xmlAttributes.getPrimitiveInt() != 121212 )
1342 {
1343 root.setAttribute( "primitiveInt", String.valueOf( xmlAttributes.getPrimitiveInt() ) );
1344 }
1345 if ( xmlAttributes.getPrimitiveLong() != 1234567890123L )
1346 {
1347 root.setAttribute( "primitiveLong", String.valueOf( xmlAttributes.getPrimitiveLong() ) );
1348 }
1349 if ( xmlAttributes.getPrimitiveFloat() != 12.12f )
1350 {
1351 root.setAttribute( "primitiveFloat", String.valueOf( xmlAttributes.getPrimitiveFloat() ) );
1352 }
1353 if ( xmlAttributes.getPrimitiveDouble() != 12.12 )
1354 {
1355 root.setAttribute( "primitiveDouble", String.valueOf( xmlAttributes.getPrimitiveDouble() ) );
1356 }
1357 if ( ( xmlAttributes.getObjectString() != null ) && !xmlAttributes.getObjectString().equals( "default value" ) )
1358 {
1359 root.setAttribute( "objectString", xmlAttributes.getObjectString() );
1360 }
1361 if ( xmlAttributes.getObjectDate() != null )
1362 {
1363 root.setAttribute( "objectDate", new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS", java.util.Locale.US ).format( xmlAttributes.getObjectDate() ) );
1364 }
1365 if ( ( xmlAttributes.getAttribute() != null ) && !xmlAttributes.getAttribute().equals( "default" ) )
1366 {
1367 root.setAttribute( "tag-name", xmlAttributes.getAttribute() );
1368 }
1369 }
1370 }
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380 protected void updateXmlContent( XmlContent xmlContent, String xmlTag, Counter counter, Element element )
1381 {
1382 if ( xmlContent != null )
1383 {
1384 Element root = updateElement( counter, element, xmlTag );
1385 Counter innerCount = new Counter( counter.getDepth() + 1 );
1386 if ( xmlContent.getLongContent() != null )
1387 {
1388 updateXmlContentLong( xmlContent.getLongContent(), "content.long", innerCount, root );
1389 }
1390 if ( xmlContent.getLongContentWithAttributes() != null )
1391 {
1392 updateXmlContentLongWithAttributes( xmlContent.getLongContentWithAttributes(), "content.long-with-attributes", innerCount, root );
1393 }
1394 }
1395 }
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405 protected void updateXmlContentLong( XmlContentLong xmlContentLong, String xmlTag, Counter counter, Element element )
1406 {
1407 if ( xmlContentLong != null )
1408 {
1409 Element root = updateElement( counter, element, xmlTag );
1410 Counter innerCount = new Counter( counter.getDepth() + 1 );
1411 root.setText( String.valueOf( xmlContentLong.getContent() ) );
1412 }
1413 }
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424 protected void updateXmlContentLongWithAttributes( XmlContentLongWithAttributes xmlContentLongWithAttributes, String xmlTag, Counter counter, Element element )
1425 {
1426 if ( xmlContentLongWithAttributes != null )
1427 {
1428 Element root = updateElement( counter, element, xmlTag );
1429 Counter innerCount = new Counter( counter.getDepth() + 1 );
1430 if ( xmlContentLongWithAttributes.getAttr() != null )
1431 {
1432 root.setAttribute( "attr", xmlContentLongWithAttributes.getAttr() );
1433 }
1434 if ( xmlContentLongWithAttributes.getAttr2() != 0 )
1435 {
1436 root.setAttribute( "attr2", String.valueOf( xmlContentLongWithAttributes.getAttr2() ) );
1437 }
1438 root.setText( String.valueOf( xmlContentLongWithAttributes.getContent() ) );
1439 }
1440 }
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450 protected void updateXmlFeatures( XmlFeatures xmlFeatures, String xmlTag, Counter counter, Element element )
1451 {
1452 if ( xmlFeatures != null )
1453 {
1454 Element root = updateElement( counter, element, xmlTag );
1455 Counter innerCount = new Counter( counter.getDepth() + 1 );
1456 if ( xmlFeatures.getAttributes() != null )
1457 {
1458 updateXmlAttributes( xmlFeatures.getAttributes(), "attributes", innerCount, root );
1459 }
1460 if ( xmlFeatures.getAttributesDefault() != null )
1461 {
1462 updateXmlAttributes( xmlFeatures.getAttributesDefault(), "attributesDefault", innerCount, root );
1463 }
1464 if ( xmlFeatures.getContent() != null )
1465 {
1466 updateXmlContent( xmlFeatures.getContent(), "content", innerCount, root );
1467 }
1468 if ( xmlFeatures.getFieldTrim() != null )
1469 {
1470 updateElement( innerCount, root, "fieldTrim" ).setText( xmlFeatures.getFieldTrim() );
1471 }
1472 if ( xmlFeatures.getFieldNoTrim() != null )
1473 {
1474 updateElement( innerCount, root, "fieldNoTrim" ).setText( xmlFeatures.getFieldNoTrim() );
1475 }
1476 findAndReplaceXpp3DOM( innerCount, root, "dom", (Xpp3Dom) xmlFeatures.getDom() );
1477 findAndReplaceXpp3DOM( innerCount, root, "domNoTrim", (Xpp3Dom) xmlFeatures.getDomNoTrim() );
1478 if ( xmlFeatures.getFieldName() != null )
1479 {
1480 updateElement( innerCount, root, "tag-name" ).setText( xmlFeatures.getFieldName() );
1481 }
1482 if ( xmlFeatures.getFieldNameAttribute() != null )
1483 {
1484 root.setAttribute( "tag-name.attribute", xmlFeatures.getFieldNameAttribute() );
1485 }
1486 if ( xmlFeatures.getDateXmlFormat() != null )
1487 {
1488 updateElement( innerCount, root, "dateXmlFormat" ).setText( new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss", java.util.Locale.US ).format( xmlFeatures.getDateXmlFormat() ) );
1489 }
1490 if ( xmlFeatures.getDateLong() != null )
1491 {
1492 updateElement( innerCount, root, "dateLong" ).setText( String.valueOf( xmlFeatures.getDateLong().getTime() ) );
1493 }
1494 iterate2Reference( innerCount, root, xmlFeatures.getXmlItemsStyleFlats(), "xmlItemsStyleFlat" );
1495 iterateReference( innerCount, root, xmlFeatures.getXmlAssociationTagNames(),"xmlAssociationTagNames","association.tag-name" );
1496 iterateReference( innerCount, root, xmlFeatures.getXmlTagNameAssociation(),"field.tag-names","field.tag-name" );
1497 iterateReference( innerCount, root, xmlFeatures.getXmlTagNameAssociationTagNames(),"field.tag-name","association.tag-name" );
1498 iterate2Reference( innerCount, root, xmlFeatures.getXmlFlatAssociationTagNames(), "association.tag-name" );
1499 if ( ( xmlFeatures.getExplodeProperties() != null ) && ( xmlFeatures.getExplodeProperties().size() > 0 ) )
1500 {
1501 Element listElement = updateElement( innerCount, root, "explodeProperties" );
1502 Iterator it = xmlFeatures.getExplodeProperties().keySet().iterator();
1503 Counter propertiesCounter = new Counter( innerCount.getDepth() + 1 );
1504 while ( it.hasNext() )
1505 {
1506 String key = (String) it.next();
1507 Element propTag = updateElement( propertiesCounter, listElement, "explodeProperty" );
1508 Counter propertyCounter = new Counter( propertiesCounter.getDepth() + 1 );
1509 findAndReplaceSimpleElement( propertyCounter, propTag, "key", key, null );
1510 findAndReplaceSimpleElement( propertyCounter, propTag, "value", (String) xmlFeatures.getExplodeProperties().get( key ), null );
1511 }
1512 }
1513 if ( ( xmlFeatures.getInlineProperties() != null ) && ( xmlFeatures.getInlineProperties().size() > 0 ) )
1514 {
1515 Element listElement = updateElement( innerCount, root, "inlineProperties" );
1516 Iterator it = xmlFeatures.getInlineProperties().keySet().iterator();
1517 Counter propertiesCounter = new Counter( innerCount.getDepth() + 1 );
1518 while ( it.hasNext() )
1519 {
1520 String key = (String) it.next();
1521 findAndReplaceSimpleElement( propertiesCounter, listElement, key, (String) xmlFeatures.getInlineProperties().get( key ), null );
1522 }
1523 }
1524 if ( xmlFeatures.getXmlTransientFields() != null )
1525 {
1526 updateXmlTransientFields( xmlFeatures.getXmlTransientFields(), "xmlTransientFields", innerCount, root );
1527 }
1528 if ( xmlFeatures.getXmlFieldsOrder() != null )
1529 {
1530 updateXmlFieldsOrder( xmlFeatures.getXmlFieldsOrder(), "xmlFieldsOrder", innerCount, root );
1531 }
1532 if ( xmlFeatures.getXsdFeatures() != null )
1533 {
1534 updateXsdFeatures( xmlFeatures.getXsdFeatures(), "xsdFeatures", innerCount, root );
1535 }
1536 }
1537 }
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547 protected void updateXmlFieldsOrder( XmlFieldsOrder xmlFieldsOrder, String xmlTag, Counter counter, Element element )
1548 {
1549 if ( xmlFieldsOrder != null )
1550 {
1551 Element root = updateElement( counter, element, xmlTag );
1552 Counter innerCount = new Counter( counter.getDepth() + 1 );
1553 if ( xmlFieldsOrder.getField1() != null )
1554 {
1555 updateElement( innerCount, root, "field1" ).setText( xmlFieldsOrder.getField1() );
1556 }
1557 if ( xmlFieldsOrder.getField() != null )
1558 {
1559 updateElement( innerCount, root, "field-2" ).setText( xmlFieldsOrder.getField() );
1560 }
1561 if ( xmlFieldsOrder.getField3() != null )
1562 {
1563 updateElement( innerCount, root, "field3" ).setText( xmlFieldsOrder.getField3() );
1564 }
1565 if ( xmlFieldsOrder.getField4() != null )
1566 {
1567 updateElement( innerCount, root, "field4" ).setText( xmlFieldsOrder.getField4() );
1568 }
1569 if ( xmlFieldsOrder.getField5() != null )
1570 {
1571 updateElement( innerCount, root, "field5" ).setText( xmlFieldsOrder.getField5() );
1572 }
1573 if ( xmlFieldsOrder.getField6() != null )
1574 {
1575 updateElement( innerCount, root, "field6" ).setText( xmlFieldsOrder.getField6() );
1576 }
1577 if ( xmlFieldsOrder.getField7() != null )
1578 {
1579 updateElement( innerCount, root, "field7" ).setText( xmlFieldsOrder.getField7() );
1580 }
1581 }
1582 }
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592 protected void updateXmlFieldsOrderParent( XmlFieldsOrderParent xmlFieldsOrderParent, String xmlTag, Counter counter, Element element )
1593 {
1594 if ( xmlFieldsOrderParent != null )
1595 {
1596 Element root = updateElement( counter, element, xmlTag );
1597 Counter innerCount = new Counter( counter.getDepth() + 1 );
1598 if ( xmlFieldsOrderParent.getField() != null )
1599 {
1600 updateElement( innerCount, root, "field-2" ).setText( xmlFieldsOrderParent.getField() );
1601 }
1602 if ( xmlFieldsOrderParent.getField4() != null )
1603 {
1604 updateElement( innerCount, root, "field4" ).setText( xmlFieldsOrderParent.getField4() );
1605 }
1606 if ( xmlFieldsOrderParent.getField5() != null )
1607 {
1608 updateElement( innerCount, root, "field5" ).setText( xmlFieldsOrderParent.getField5() );
1609 }
1610 if ( xmlFieldsOrderParent.getField7() != null )
1611 {
1612 updateElement( innerCount, root, "field7" ).setText( xmlFieldsOrderParent.getField7() );
1613 }
1614 }
1615 }
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625 protected void updateXmlFieldsOrderParent2( XmlFieldsOrderParent2 xmlFieldsOrderParent2, String xmlTag, Counter counter, Element element )
1626 {
1627 if ( xmlFieldsOrderParent2 != null )
1628 {
1629 Element root = updateElement( counter, element, xmlTag );
1630 Counter innerCount = new Counter( counter.getDepth() + 1 );
1631 if ( xmlFieldsOrderParent2.getField() != null )
1632 {
1633 updateElement( innerCount, root, "field-2" ).setText( xmlFieldsOrderParent2.getField() );
1634 }
1635 }
1636 }
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646 protected void updateXmlTransientFields( XmlTransientFields xmlTransientFields, String xmlTag, Counter counter, Element element )
1647 {
1648 if ( xmlTransientFields != null )
1649 {
1650 Element root = updateElement( counter, element, xmlTag );
1651 Counter innerCount = new Counter( counter.getDepth() + 1 );
1652 if ( xmlTransientFields.getPersistentField() != null )
1653 {
1654 updateElement( innerCount, root, "persistentField" ).setText( xmlTransientFields.getPersistentField() );
1655 }
1656 }
1657 }
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667 protected void updateXsdFeatures( XsdFeatures xsdFeatures, String xmlTag, Counter counter, Element element )
1668 {
1669 if ( xsdFeatures != null )
1670 {
1671 Element root = updateElement( counter, element, xmlTag );
1672 Counter innerCount = new Counter( counter.getDepth() + 1 );
1673 if ( xsdFeatures.getAttribute() != null )
1674 {
1675 root.setAttribute( "attribute", xsdFeatures.getAttribute() );
1676 }
1677 }
1678 }
1679
1680
1681
1682
1683
1684
1685
1686
1687 public void write( Features features, OutputStreamWriter writer )
1688 throws java.io.IOException
1689 {
1690 Format format = Format.getRawFormat()
1691 .setEncoding( writer.getEncoding() )
1692 .setLineSeparator( System.getProperty( "line.separator" ) );
1693 write( features, writer, format );
1694 }
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704 public void write( Features features, Writer writer, Format jdomFormat )
1705 throws java.io.IOException
1706 {
1707 Document document = factory.document( null );
1708 updateFeatures( features, "features-demo", new Counter( 0 ), document );
1709 XMLOutputter outputter = new XMLOutputter();
1710 outputter.setFormat( jdomFormat );
1711 outputter.output( document, writer );
1712 }
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724 public static class Counter
1725 {
1726
1727
1728
1729
1730
1731
1732
1733
1734 private int currentIndex = 0;
1735
1736
1737
1738
1739 private int level;
1740
1741
1742
1743
1744
1745
1746 public Counter(int depthLevel)
1747 {
1748 level = depthLevel;
1749 }
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761 public int getCurrentIndex()
1762 {
1763 return currentIndex;
1764 }
1765
1766
1767
1768
1769
1770
1771 public int getDepth()
1772 {
1773 return level;
1774 }
1775
1776
1777
1778
1779 public void increaseCount()
1780 {
1781 currentIndex = currentIndex + 1;
1782 }
1783
1784 }
1785
1786 }