View Javadoc

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