View Javadoc

1   package org.apache.maven.plugins.shade.pom;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  //package org.apache.maven.model.io.jdom;
23  
24  //---------------------------------/
25  //- Imported classes and packages -/
26  //---------------------------------/
27  
28  import org.apache.maven.model.ActivationFile;
29  import org.apache.maven.model.ActivationOS;
30  import org.apache.maven.model.ActivationProperty;
31  import org.apache.maven.model.Build;
32  import org.apache.maven.model.BuildBase;
33  import org.apache.maven.model.CiManagement;
34  import org.apache.maven.model.ConfigurationContainer;
35  import org.apache.maven.model.Contributor;
36  import org.apache.maven.model.Dependency;
37  import org.apache.maven.model.DependencyManagement;
38  import org.apache.maven.model.DeploymentRepository;
39  import org.apache.maven.model.Developer;
40  import org.apache.maven.model.DistributionManagement;
41  import org.apache.maven.model.Exclusion;
42  import org.apache.maven.model.Extension;
43  import org.apache.maven.model.FileSet;
44  import org.apache.maven.model.IssueManagement;
45  import org.apache.maven.model.License;
46  import org.apache.maven.model.MailingList;
47  import org.apache.maven.model.Model;
48  import org.apache.maven.model.ModelBase;
49  import org.apache.maven.model.Notifier;
50  import org.apache.maven.model.Organization;
51  import org.apache.maven.model.Parent;
52  import org.apache.maven.model.PatternSet;
53  import org.apache.maven.model.Plugin;
54  import org.apache.maven.model.PluginConfiguration;
55  import org.apache.maven.model.PluginContainer;
56  import org.apache.maven.model.PluginExecution;
57  import org.apache.maven.model.PluginManagement;
58  import org.apache.maven.model.Prerequisites;
59  import org.apache.maven.model.Profile;
60  import org.apache.maven.model.Relocation;
61  import org.apache.maven.model.ReportPlugin;
62  import org.apache.maven.model.ReportSet;
63  import org.apache.maven.model.Reporting;
64  import org.apache.maven.model.Repository;
65  import org.apache.maven.model.RepositoryBase;
66  import org.apache.maven.model.RepositoryPolicy;
67  import org.apache.maven.model.Resource;
68  import org.apache.maven.model.Scm;
69  import org.apache.maven.model.Site;
70  import org.codehaus.plexus.util.xml.Xpp3Dom;
71  import org.jdom.Content;
72  import org.jdom.DefaultJDOMFactory;
73  import org.jdom.Document;
74  import org.jdom.Element;
75  import org.jdom.Text;
76  import org.jdom.output.Format;
77  import org.jdom.output.XMLOutputter;
78  
79  import java.io.OutputStream;
80  import java.io.OutputStreamWriter;
81  import java.io.Writer;
82  import java.util.ArrayList;
83  import java.util.Collection;
84  import java.util.Iterator;
85  import java.util.ListIterator;
86  import java.util.Map;
87  
88  /**
89   * Class MavenJDOMWriter.
90   *
91   * @version $Revision: 1384332 $ $Date: 2012-09-13 15:48:42 +0200 (Thu, 13 Sep 2012) $
92   */
93  public class MavenJDOMWriter
94  {
95  
96      // --------------------------/
97      // - Class/Member Variables -/
98      // --------------------------/
99  
100     /**
101      * Field factory
102      */
103     private DefaultJDOMFactory factory;
104 
105     /**
106      * Field lineSeparator
107      */
108     private String lineSeparator;
109 
110     // ----------------/
111     // - Constructors -/
112     // ----------------/
113 
114     public MavenJDOMWriter()
115     {
116         factory = new DefaultJDOMFactory();
117         lineSeparator = "\n";
118     } // -- org.apache.maven.model.io.jdom.MavenJDOMWriter()
119 
120     // -----------/
121     // - Methods -/
122     // -----------/
123 
124     /**
125      * Method findAndReplaceProperties
126      *
127      * @param counter
128      * @param props
129      * @param name
130      * @param parent
131      */
132     protected Element findAndReplaceProperties( Counter counter, Element parent, String name, Map props )
133     {
134         boolean shouldExist = props != null && !props.isEmpty();
135         Element element = updateElement( counter, parent, name, shouldExist );
136         if ( shouldExist )
137         {
138 
139             Counter innerCounter = new Counter( counter.getDepth() + 1 );
140             //while ( it.hasNext() )
141             for ( Map.Entry<String, String> entry : ( (Map<String, String>) props ).entrySet() )
142             {
143                 String key = entry.getKey();
144                 findAndReplaceSimpleElement( innerCounter, element, key, entry.getValue(), null );
145             }
146             ArrayList lst = new ArrayList( props.keySet() );
147             Iterator it = element.getChildren().iterator();
148             while ( it.hasNext() )
149             {
150                 Element elem = (Element) it.next();
151                 String key = elem.getName();
152                 if ( !lst.contains( key ) )
153                 {
154                     it.remove();
155                 }
156             }
157         }
158         return element;
159     } // -- Element findAndReplaceProperties(Counter, Element, String, Map)
160 
161     /**
162      * Method findAndReplaceSimpleElement
163      *
164      * @param counter
165      * @param defaultValue
166      * @param text
167      * @param name
168      * @param parent
169      */
170     protected Element findAndReplaceSimpleElement( Counter counter, Element parent, String name, String text,
171                                                    String defaultValue )
172     {
173         if ( defaultValue != null && text != null && defaultValue.equals( text ) )
174         {
175             Element element = parent.getChild( name, parent.getNamespace() );
176             // if exist and is default value or if doesn't exist.. just keep the way it is..
177             if ( ( element != null && defaultValue.equals( element.getText() ) ) || element == null )
178             {
179                 return element;
180             }
181         }
182         boolean shouldExist = text != null && text.trim().length() > 0;
183         Element element = updateElement( counter, parent, name, shouldExist );
184         if ( shouldExist )
185         {
186             element.setText( text );
187         }
188         return element;
189     } // -- Element findAndReplaceSimpleElement(Counter, Element, String, String, String)
190 
191     /**
192      * Method findAndReplaceSimpleLists
193      *
194      * @param counter
195      * @param childName
196      * @param parentName
197      * @param list
198      * @param parent
199      */
200     protected Element findAndReplaceSimpleLists( Counter counter, Element parent, java.util.Collection list,
201                                                  String parentName, String childName )
202     {
203         boolean shouldExist = list != null && list.size() > 0;
204         Element element = updateElement( counter, parent, parentName, shouldExist );
205         if ( shouldExist )
206         {
207             Iterator it = list.iterator();
208             Iterator elIt = element.getChildren( childName, element.getNamespace() ).iterator();
209             if ( !elIt.hasNext() )
210             {
211                 elIt = null;
212             }
213             Counter innerCount = new Counter( counter.getDepth() + 1 );
214             while ( it.hasNext() )
215             {
216                 String value = (String) it.next();
217                 Element el;
218                 if ( elIt != null && elIt.hasNext() )
219                 {
220                     el = (Element) elIt.next();
221                     if ( !elIt.hasNext() )
222                     {
223                         elIt = null;
224                     }
225                 }
226                 else
227                 {
228                     el = factory.element( childName, element.getNamespace() );
229                     insertAtPreferredLocation( element, el, innerCount );
230                 }
231                 el.setText( value );
232                 innerCount.increaseCount();
233             }
234             if ( elIt != null )
235             {
236                 while ( elIt.hasNext() )
237                 {
238                     elIt.next();
239                     elIt.remove();
240                 }
241             }
242         }
243         return element;
244     } // -- Element findAndReplaceSimpleLists(Counter, Element, java.util.Collection, String, String)
245 
246     /**
247      * Method findAndReplaceXpp3DOM
248      *
249      * @param counter
250      * @param dom
251      * @param name
252      * @param parent
253      */
254     protected Element findAndReplaceXpp3DOM( Counter counter, Element parent, String name, Xpp3Dom dom )
255     {
256         boolean shouldExist = dom != null && ( dom.getChildCount() > 0 || dom.getValue() != null );
257         Element element = updateElement( counter, parent, name, shouldExist );
258         if ( shouldExist )
259         {
260             replaceXpp3DOM( element, dom, new Counter( counter.getDepth() + 1 ) );
261         }
262         return element;
263     } // -- Element findAndReplaceXpp3DOM(Counter, Element, String, Xpp3Dom)
264 
265     /**
266      * Method insertAtPreferredLocation
267      *
268      * @param parent
269      * @param counter
270      * @param child
271      */
272     protected void insertAtPreferredLocation( Element parent, Element child, Counter counter )
273     {
274         int contentIndex = 0;
275         int elementCounter = 0;
276         Iterator it = parent.getContent().iterator();
277         Text lastText = null;
278         int offset = 0;
279         while ( it.hasNext() && elementCounter <= counter.getCurrentIndex() )
280         {
281             Object next = it.next();
282             offset = offset + 1;
283             if ( next instanceof Element )
284             {
285                 elementCounter = elementCounter + 1;
286                 contentIndex = contentIndex + offset;
287                 offset = 0;
288             }
289             if ( next instanceof Text && it.hasNext() )
290             {
291                 lastText = (Text) next;
292             }
293         }
294         if ( lastText != null && lastText.getTextTrim().length() == 0 )
295         {
296             lastText = (Text) lastText.clone();
297         }
298         else
299         {
300             String starter = lineSeparator;
301             for ( int i = 0; i < counter.getDepth(); i++ )
302             {
303                 starter = starter + "    "; // TODO make settable?
304             }
305             lastText = factory.text( starter );
306         }
307         if ( parent.getContentSize() == 0 )
308         {
309             Text finalText = (Text) lastText.clone();
310             finalText.setText( finalText.getText().substring( 0, finalText.getText().length() - "    ".length() ) );
311             parent.addContent( contentIndex, finalText );
312         }
313         parent.addContent( contentIndex, child );
314         parent.addContent( contentIndex, lastText );
315     } // -- void insertAtPreferredLocation(Element, Element, Counter)
316 
317     /**
318      * Method iterateContributor
319      *
320      * @param counter
321      * @param childTag
322      * @param parentTag
323      * @param list
324      * @param parent
325      */
326     protected void iterateContributor( Counter counter, Element parent, java.util.Collection list,
327                                        java.lang.String parentTag, java.lang.String childTag )
328     {
329         boolean shouldExist = list != null && list.size() > 0;
330         Element element = updateElement( counter, parent, parentTag, shouldExist );
331         if ( shouldExist )
332         {
333             Iterator it = list.iterator();
334             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
335             if ( !elIt.hasNext() )
336             {
337                 elIt = null;
338             }
339             Counter innerCount = new Counter( counter.getDepth() + 1 );
340             while ( it.hasNext() )
341             {
342                 Contributor value = (Contributor) it.next();
343                 Element el;
344                 if ( elIt != null && elIt.hasNext() )
345                 {
346                     el = (Element) elIt.next();
347                     if ( !elIt.hasNext() )
348                     {
349                         elIt = null;
350                     }
351                 }
352                 else
353                 {
354                     el = factory.element( childTag, element.getNamespace() );
355                     insertAtPreferredLocation( element, el, innerCount );
356                 }
357                 updateContributor( value, childTag, innerCount, el );
358                 innerCount.increaseCount();
359             }
360             if ( elIt != null )
361             {
362                 while ( elIt.hasNext() )
363                 {
364                     elIt.next();
365                     elIt.remove();
366                 }
367             }
368         }
369     } // -- void iterateContributor(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
370 
371     /**
372      * Method iterateDependency
373      *
374      * @param counter
375      * @param childTag
376      * @param parentTag
377      * @param list
378      * @param parent
379      */
380     protected void iterateDependency( Counter counter, Element parent, java.util.Collection list,
381                                       java.lang.String parentTag, java.lang.String childTag )
382     {
383         boolean shouldExist = list != null && list.size() > 0;
384         Element element = updateElement( counter, parent, parentTag, shouldExist );
385         if ( shouldExist )
386         {
387             Iterator it = list.iterator();
388             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
389             if ( !elIt.hasNext() )
390             {
391                 elIt = null;
392             }
393             Counter innerCount = new Counter( counter.getDepth() + 1 );
394             while ( it.hasNext() )
395             {
396                 Dependency value = (Dependency) it.next();
397                 Element el;
398                 if ( elIt != null && elIt.hasNext() )
399                 {
400                     el = (Element) elIt.next();
401                     if ( !elIt.hasNext() )
402                     {
403                         elIt = null;
404                     }
405                 }
406                 else
407                 {
408                     el = factory.element( childTag, element.getNamespace() );
409                     insertAtPreferredLocation( element, el, innerCount );
410                 }
411                 updateDependency( value, childTag, innerCount, el );
412                 innerCount.increaseCount();
413             }
414             if ( elIt != null )
415             {
416                 while ( elIt.hasNext() )
417                 {
418                     elIt.next();
419                     elIt.remove();
420                 }
421             }
422         }
423     } // -- void iterateDependency(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
424 
425     /**
426      * Method iterateDeveloper
427      *
428      * @param counter
429      * @param childTag
430      * @param parentTag
431      * @param list
432      * @param parent
433      */
434     protected void iterateDeveloper( Counter counter, Element parent, java.util.Collection list,
435                                      java.lang.String parentTag, java.lang.String childTag )
436     {
437         boolean shouldExist = list != null && list.size() > 0;
438         Element element = updateElement( counter, parent, parentTag, shouldExist );
439         if ( shouldExist )
440         {
441             Iterator it = list.iterator();
442             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
443             if ( !elIt.hasNext() )
444             {
445                 elIt = null;
446             }
447             Counter innerCount = new Counter( counter.getDepth() + 1 );
448             while ( it.hasNext() )
449             {
450                 Developer value = (Developer) it.next();
451                 Element el;
452                 if ( elIt != null && elIt.hasNext() )
453                 {
454                     el = (Element) elIt.next();
455                     if ( !elIt.hasNext() )
456                     {
457                         elIt = null;
458                     }
459                 }
460                 else
461                 {
462                     el = factory.element( childTag, element.getNamespace() );
463                     insertAtPreferredLocation( element, el, innerCount );
464                 }
465                 updateDeveloper( value, childTag, innerCount, el );
466                 innerCount.increaseCount();
467             }
468             if ( elIt != null )
469             {
470                 while ( elIt.hasNext() )
471                 {
472                     elIt.next();
473                     elIt.remove();
474                 }
475             }
476         }
477     } // -- void iterateDeveloper(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
478 
479     /**
480      * Method iterateExclusion
481      *
482      * @param counter
483      * @param childTag
484      * @param parentTag
485      * @param list
486      * @param parent
487      */
488     protected void iterateExclusion( Counter counter, Element parent, java.util.Collection list,
489                                      java.lang.String parentTag, java.lang.String childTag )
490     {
491         boolean shouldExist = list != null && list.size() > 0;
492         Element element = updateElement( counter, parent, parentTag, shouldExist );
493         if ( shouldExist )
494         {
495             Iterator it = list.iterator();
496             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
497             if ( !elIt.hasNext() )
498             {
499                 elIt = null;
500             }
501             Counter innerCount = new Counter( counter.getDepth() + 1 );
502             while ( it.hasNext() )
503             {
504                 Exclusion value = (Exclusion) it.next();
505                 Element el;
506                 if ( elIt != null && elIt.hasNext() )
507                 {
508                     el = (Element) elIt.next();
509                     if ( !elIt.hasNext() )
510                     {
511                         elIt = null;
512                     }
513                 }
514                 else
515                 {
516                     el = factory.element( childTag, element.getNamespace() );
517                     insertAtPreferredLocation( element, el, innerCount );
518                 }
519                 updateExclusion( value, childTag, innerCount, el );
520                 innerCount.increaseCount();
521             }
522             if ( elIt != null )
523             {
524                 while ( elIt.hasNext() )
525                 {
526                     elIt.next();
527                     elIt.remove();
528                 }
529             }
530         }
531     } // -- void iterateExclusion(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
532 
533     /**
534      * Method iterateExtension
535      *
536      * @param counter
537      * @param childTag
538      * @param parentTag
539      * @param list
540      * @param parent
541      */
542     protected void iterateExtension( Counter counter, Element parent, java.util.Collection list,
543                                      java.lang.String parentTag, java.lang.String childTag )
544     {
545         boolean shouldExist = list != null && list.size() > 0;
546         Element element = updateElement( counter, parent, parentTag, shouldExist );
547         if ( shouldExist )
548         {
549             Iterator it = list.iterator();
550             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
551             if ( !elIt.hasNext() )
552             {
553                 elIt = null;
554             }
555             Counter innerCount = new Counter( counter.getDepth() + 1 );
556             while ( it.hasNext() )
557             {
558                 Extension value = (Extension) it.next();
559                 Element el;
560                 if ( elIt != null && elIt.hasNext() )
561                 {
562                     el = (Element) elIt.next();
563                     if ( !elIt.hasNext() )
564                     {
565                         elIt = null;
566                     }
567                 }
568                 else
569                 {
570                     el = factory.element( childTag, element.getNamespace() );
571                     insertAtPreferredLocation( element, el, innerCount );
572                 }
573                 updateExtension( value, childTag, innerCount, el );
574                 innerCount.increaseCount();
575             }
576             if ( elIt != null )
577             {
578                 while ( elIt.hasNext() )
579                 {
580                     elIt.next();
581                     elIt.remove();
582                 }
583             }
584         }
585     } // -- void iterateExtension(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
586 
587     /**
588      * Method iterateLicense
589      *
590      * @param counter
591      * @param childTag
592      * @param parentTag
593      * @param list
594      * @param parent
595      */
596     protected void iterateLicense( Counter counter, Element parent, java.util.Collection list,
597                                    java.lang.String parentTag, java.lang.String childTag )
598     {
599         boolean shouldExist = list != null && list.size() > 0;
600         Element element = updateElement( counter, parent, parentTag, shouldExist );
601         if ( shouldExist )
602         {
603             Iterator it = list.iterator();
604             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
605             if ( !elIt.hasNext() )
606             {
607                 elIt = null;
608             }
609             Counter innerCount = new Counter( counter.getDepth() + 1 );
610             while ( it.hasNext() )
611             {
612                 License value = (License) it.next();
613                 Element el;
614                 if ( elIt != null && elIt.hasNext() )
615                 {
616                     el = (Element) elIt.next();
617                     if ( !elIt.hasNext() )
618                     {
619                         elIt = null;
620                     }
621                 }
622                 else
623                 {
624                     el = factory.element( childTag, element.getNamespace() );
625                     insertAtPreferredLocation( element, el, innerCount );
626                 }
627                 updateLicense( value, childTag, innerCount, el );
628                 innerCount.increaseCount();
629             }
630             if ( elIt != null )
631             {
632                 while ( elIt.hasNext() )
633                 {
634                     elIt.next();
635                     elIt.remove();
636                 }
637             }
638         }
639     } // -- void iterateLicense(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
640 
641     /**
642      * Method iterateMailingList
643      *
644      * @param counter
645      * @param childTag
646      * @param parentTag
647      * @param list
648      * @param parent
649      */
650     protected void iterateMailingList( Counter counter, Element parent, java.util.Collection list,
651                                        java.lang.String parentTag, java.lang.String childTag )
652     {
653         boolean shouldExist = list != null && list.size() > 0;
654         Element element = updateElement( counter, parent, parentTag, shouldExist );
655         if ( shouldExist )
656         {
657             Iterator it = list.iterator();
658             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
659             if ( !elIt.hasNext() )
660             {
661                 elIt = null;
662             }
663             Counter innerCount = new Counter( counter.getDepth() + 1 );
664             while ( it.hasNext() )
665             {
666                 MailingList value = (MailingList) it.next();
667                 Element el;
668                 if ( elIt != null && elIt.hasNext() )
669                 {
670                     el = (Element) elIt.next();
671                     if ( !elIt.hasNext() )
672                     {
673                         elIt = null;
674                     }
675                 }
676                 else
677                 {
678                     el = factory.element( childTag, element.getNamespace() );
679                     insertAtPreferredLocation( element, el, innerCount );
680                 }
681                 updateMailingList( value, childTag, innerCount, el );
682                 innerCount.increaseCount();
683             }
684             if ( elIt != null )
685             {
686                 while ( elIt.hasNext() )
687                 {
688                     elIt.next();
689                     elIt.remove();
690                 }
691             }
692         }
693     } // -- void iterateMailingList(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
694 
695     /**
696      * Method iterateNotifier
697      *
698      * @param counter
699      * @param childTag
700      * @param parentTag
701      * @param list
702      * @param parent
703      */
704     protected void iterateNotifier( Counter counter, Element parent, java.util.Collection list,
705                                     java.lang.String parentTag, java.lang.String childTag )
706     {
707         boolean shouldExist = list != null && list.size() > 0;
708         Element element = updateElement( counter, parent, parentTag, shouldExist );
709         if ( shouldExist )
710         {
711             Iterator it = list.iterator();
712             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
713             if ( !elIt.hasNext() )
714             {
715                 elIt = null;
716             }
717             Counter innerCount = new Counter( counter.getDepth() + 1 );
718             while ( it.hasNext() )
719             {
720                 Notifier value = (Notifier) it.next();
721                 Element el;
722                 if ( elIt != null && elIt.hasNext() )
723                 {
724                     el = (Element) elIt.next();
725                     if ( !elIt.hasNext() )
726                     {
727                         elIt = null;
728                     }
729                 }
730                 else
731                 {
732                     el = factory.element( childTag, element.getNamespace() );
733                     insertAtPreferredLocation( element, el, innerCount );
734                 }
735                 updateNotifier( value, childTag, innerCount, el );
736                 innerCount.increaseCount();
737             }
738             if ( elIt != null )
739             {
740                 while ( elIt.hasNext() )
741                 {
742                     elIt.next();
743                     elIt.remove();
744                 }
745             }
746         }
747     } // -- void iterateNotifier(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
748 
749     /**
750      * Method iteratePlugin
751      *
752      * @param counter
753      * @param childTag
754      * @param parentTag
755      * @param list
756      * @param parent
757      */
758     protected void iteratePlugin( Counter counter, Element parent, java.util.Collection list,
759                                   java.lang.String parentTag, java.lang.String childTag )
760     {
761         boolean shouldExist = list != null && list.size() > 0;
762         Element element = updateElement( counter, parent, parentTag, shouldExist );
763         if ( shouldExist )
764         {
765             Iterator it = list.iterator();
766             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
767             if ( !elIt.hasNext() )
768             {
769                 elIt = null;
770             }
771             Counter innerCount = new Counter( counter.getDepth() + 1 );
772             while ( it.hasNext() )
773             {
774                 Plugin value = (Plugin) it.next();
775                 Element el;
776                 if ( elIt != null && elIt.hasNext() )
777                 {
778                     el = (Element) elIt.next();
779                     if ( !elIt.hasNext() )
780                     {
781                         elIt = null;
782                     }
783                 }
784                 else
785                 {
786                     el = factory.element( childTag, element.getNamespace() );
787                     insertAtPreferredLocation( element, el, innerCount );
788                 }
789                 updatePlugin( value, childTag, innerCount, el );
790                 innerCount.increaseCount();
791             }
792             if ( elIt != null )
793             {
794                 while ( elIt.hasNext() )
795                 {
796                     elIt.next();
797                     elIt.remove();
798                 }
799             }
800         }
801     } // -- void iteratePlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
802 
803     /**
804      * Method iteratePluginExecution
805      *
806      * @param counter
807      * @param childTag
808      * @param parentTag
809      * @param list
810      * @param parent
811      */
812     protected void iteratePluginExecution( Counter counter, Element parent, java.util.Collection list,
813                                            java.lang.String parentTag, java.lang.String childTag )
814     {
815         boolean shouldExist = list != null && list.size() > 0;
816         Element element = updateElement( counter, parent, parentTag, shouldExist );
817         if ( shouldExist )
818         {
819             Iterator it = list.iterator();
820             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
821             if ( !elIt.hasNext() )
822             {
823                 elIt = null;
824             }
825             Counter innerCount = new Counter( counter.getDepth() + 1 );
826             while ( it.hasNext() )
827             {
828                 PluginExecution value = (PluginExecution) it.next();
829                 Element el;
830                 if ( elIt != null && elIt.hasNext() )
831                 {
832                     el = (Element) elIt.next();
833                     if ( !elIt.hasNext() )
834                     {
835                         elIt = null;
836                     }
837                 }
838                 else
839                 {
840                     el = factory.element( childTag, element.getNamespace() );
841                     insertAtPreferredLocation( element, el, innerCount );
842                 }
843                 updatePluginExecution( value, childTag, innerCount, el );
844                 innerCount.increaseCount();
845             }
846             if ( elIt != null )
847             {
848                 while ( elIt.hasNext() )
849                 {
850                     elIt.next();
851                     elIt.remove();
852                 }
853             }
854         }
855     } // -- void iteratePluginExecution(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
856 
857     /**
858      * Method iterateProfile
859      *
860      * @param counter
861      * @param childTag
862      * @param parentTag
863      * @param list
864      * @param parent
865      */
866     protected void iterateProfile( Counter counter, Element parent, java.util.Collection list,
867                                    java.lang.String parentTag, java.lang.String childTag )
868     {
869         boolean shouldExist = list != null && list.size() > 0;
870         Element element = updateElement( counter, parent, parentTag, shouldExist );
871         if ( shouldExist )
872         {
873             Iterator it = list.iterator();
874             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
875             if ( !elIt.hasNext() )
876             {
877                 elIt = null;
878             }
879             Counter innerCount = new Counter( counter.getDepth() + 1 );
880             while ( it.hasNext() )
881             {
882                 Profile value = (Profile) it.next();
883                 Element el;
884                 if ( elIt != null && elIt.hasNext() )
885                 {
886                     el = (Element) elIt.next();
887                     if ( !elIt.hasNext() )
888                     {
889                         elIt = null;
890                     }
891                 }
892                 else
893                 {
894                     el = factory.element( childTag, element.getNamespace() );
895                     insertAtPreferredLocation( element, el, innerCount );
896                 }
897                 updateProfile( value, childTag, innerCount, el );
898                 innerCount.increaseCount();
899             }
900             if ( elIt != null )
901             {
902                 while ( elIt.hasNext() )
903                 {
904                     elIt.next();
905                     elIt.remove();
906                 }
907             }
908         }
909     } // -- void iterateProfile(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
910 
911     /**
912      * Method iterateReportPlugin
913      *
914      * @param counter
915      * @param childTag
916      * @param parentTag
917      * @param list
918      * @param parent
919      */
920     protected void iterateReportPlugin( Counter counter, Element parent, java.util.Collection list,
921                                         java.lang.String parentTag, java.lang.String childTag )
922     {
923         boolean shouldExist = list != null && list.size() > 0;
924         Element element = updateElement( counter, parent, parentTag, shouldExist );
925         if ( shouldExist )
926         {
927             Iterator it = list.iterator();
928             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
929             if ( !elIt.hasNext() )
930             {
931                 elIt = null;
932             }
933             Counter innerCount = new Counter( counter.getDepth() + 1 );
934             while ( it.hasNext() )
935             {
936                 ReportPlugin value = (ReportPlugin) it.next();
937                 Element el;
938                 if ( elIt != null && elIt.hasNext() )
939                 {
940                     el = (Element) elIt.next();
941                     if ( !elIt.hasNext() )
942                     {
943                         elIt = null;
944                     }
945                 }
946                 else
947                 {
948                     el = factory.element( childTag, element.getNamespace() );
949                     insertAtPreferredLocation( element, el, innerCount );
950                 }
951                 updateReportPlugin( value, childTag, innerCount, el );
952                 innerCount.increaseCount();
953             }
954             if ( elIt != null )
955             {
956                 while ( elIt.hasNext() )
957                 {
958                     elIt.next();
959                     elIt.remove();
960                 }
961             }
962         }
963     } // -- void iterateReportPlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
964 
965     /**
966      * Method iterateReportSet
967      *
968      * @param counter
969      * @param childTag
970      * @param parentTag
971      * @param list
972      * @param parent
973      */
974     protected void iterateReportSet( Counter counter, Element parent, java.util.Collection list,
975                                      java.lang.String parentTag, java.lang.String childTag )
976     {
977         boolean shouldExist = list != null && list.size() > 0;
978         Element element = updateElement( counter, parent, parentTag, shouldExist );
979         if ( shouldExist )
980         {
981             Iterator it = list.iterator();
982             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
983             if ( !elIt.hasNext() )
984             {
985                 elIt = null;
986             }
987             Counter innerCount = new Counter( counter.getDepth() + 1 );
988             while ( it.hasNext() )
989             {
990                 ReportSet value = (ReportSet) it.next();
991                 Element el;
992                 if ( elIt != null && elIt.hasNext() )
993                 {
994                     el = (Element) elIt.next();
995                     if ( !elIt.hasNext() )
996                     {
997                         elIt = null;
998                     }
999                 }
1000                 else
1001                 {
1002                     el = factory.element( childTag, element.getNamespace() );
1003                     insertAtPreferredLocation( element, el, innerCount );
1004                 }
1005                 updateReportSet( value, childTag, innerCount, el );
1006                 innerCount.increaseCount();
1007             }
1008             if ( elIt != null )
1009             {
1010                 while ( elIt.hasNext() )
1011                 {
1012                     elIt.next();
1013                     elIt.remove();
1014                 }
1015             }
1016         }
1017     } // -- void iterateReportSet(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
1018 
1019     /**
1020      * Method iterateRepository
1021      *
1022      * @param counter
1023      * @param childTag
1024      * @param parentTag
1025      * @param list
1026      * @param parent
1027      */
1028     protected void iterateRepository( Counter counter, Element parent, java.util.Collection list,
1029                                       java.lang.String parentTag, java.lang.String childTag )
1030     {
1031         boolean shouldExist = list != null && list.size() > 0;
1032         Element element = updateElement( counter, parent, parentTag, shouldExist );
1033         if ( shouldExist )
1034         {
1035             Iterator it = list.iterator();
1036             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
1037             if ( !elIt.hasNext() )
1038             {
1039                 elIt = null;
1040             }
1041             Counter innerCount = new Counter( counter.getDepth() + 1 );
1042             while ( it.hasNext() )
1043             {
1044                 Repository value = (Repository) it.next();
1045                 Element el;
1046                 if ( elIt != null && elIt.hasNext() )
1047                 {
1048                     el = (Element) elIt.next();
1049                     if ( !elIt.hasNext() )
1050                     {
1051                         elIt = null;
1052                     }
1053                 }
1054                 else
1055                 {
1056                     el = factory.element( childTag, element.getNamespace() );
1057                     insertAtPreferredLocation( element, el, innerCount );
1058                 }
1059                 updateRepository( value, childTag, innerCount, el );
1060                 innerCount.increaseCount();
1061             }
1062             if ( elIt != null )
1063             {
1064                 while ( elIt.hasNext() )
1065                 {
1066                     elIt.next();
1067                     elIt.remove();
1068                 }
1069             }
1070         }
1071     } // -- void iterateRepository(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
1072 
1073     /**
1074      * Method iterateResource
1075      *
1076      * @param counter
1077      * @param childTag
1078      * @param parentTag
1079      * @param list
1080      * @param parent
1081      */
1082     protected void iterateResource( Counter counter, Element parent, java.util.Collection list,
1083                                     java.lang.String parentTag, java.lang.String childTag )
1084     {
1085         boolean shouldExist = list != null && list.size() > 0;
1086         Element element = updateElement( counter, parent, parentTag, shouldExist );
1087         if ( shouldExist )
1088         {
1089             Iterator it = list.iterator();
1090             Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
1091             if ( !elIt.hasNext() )
1092             {
1093                 elIt = null;
1094             }
1095             Counter innerCount = new Counter( counter.getDepth() + 1 );
1096             while ( it.hasNext() )
1097             {
1098                 Resource value = (Resource) it.next();
1099                 Element el;
1100                 if ( elIt != null && elIt.hasNext() )
1101                 {
1102                     el = (Element) elIt.next();
1103                     if ( !elIt.hasNext() )
1104                     {
1105                         elIt = null;
1106                     }
1107                 }
1108                 else
1109                 {
1110                     el = factory.element( childTag, element.getNamespace() );
1111                     insertAtPreferredLocation( element, el, innerCount );
1112                 }
1113                 updateResource( value, childTag, innerCount, el );
1114                 innerCount.increaseCount();
1115             }
1116             if ( elIt != null )
1117             {
1118                 while ( elIt.hasNext() )
1119                 {
1120                     elIt.next();
1121                     elIt.remove();
1122                 }
1123             }
1124         }
1125     } // -- void iterateResource(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
1126 
1127     /**
1128      * Method replaceXpp3DOM
1129      *
1130      * @param parent
1131      * @param counter
1132      * @param parentDom
1133      */
1134     protected void replaceXpp3DOM( Element parent, Xpp3Dom parentDom, Counter counter )
1135     {
1136         if ( parentDom.getChildCount() > 0 )
1137         {
1138             Xpp3Dom[] childs = parentDom.getChildren();
1139             Collection domChilds = new ArrayList();
1140             for ( int i = 0; i < childs.length; i++ )
1141             {
1142                 domChilds.add( childs[i] );
1143             }
1144             // int domIndex = 0;
1145             ListIterator it = parent.getChildren().listIterator();
1146             while ( it.hasNext() )
1147             {
1148                 Element elem = (Element) it.next();
1149                 Iterator it2 = domChilds.iterator();
1150                 Xpp3Dom corrDom = null;
1151                 while ( it2.hasNext() )
1152                 {
1153                     Xpp3Dom dm = (Xpp3Dom) it2.next();
1154                     if ( dm.getName().equals( elem.getName() ) )
1155                     {
1156                         corrDom = dm;
1157                         break;
1158                     }
1159                 }
1160                 if ( corrDom != null )
1161                 {
1162                     domChilds.remove( corrDom );
1163                     replaceXpp3DOM( elem, corrDom, new Counter( counter.getDepth() + 1 ) );
1164                     counter.increaseCount();
1165                 }
1166                 else
1167                 {
1168                     parent.removeContent( elem );
1169                 }
1170             }
1171             Iterator it2 = domChilds.iterator();
1172             while ( it2.hasNext() )
1173             {
1174                 Xpp3Dom dm = (Xpp3Dom) it2.next();
1175                 Element elem = factory.element( dm.getName(), parent.getNamespace() );
1176                 insertAtPreferredLocation( parent, elem, counter );
1177                 counter.increaseCount();
1178                 replaceXpp3DOM( elem, dm, new Counter( counter.getDepth() + 1 ) );
1179             }
1180         }
1181         else if ( parentDom.getValue() != null )
1182         {
1183             parent.setText( parentDom.getValue() );
1184         }
1185     } // -- void replaceXpp3DOM(Element, Xpp3Dom, Counter)
1186 
1187     /**
1188      * Method updateActivation
1189      *
1190      * @param value
1191      * @param element
1192      * @param counter
1193      * @param xmlTag
1194      */
1195     /*
1196      * protected void updateActivation(Activation value, String xmlTag, Counter counter, Element element) { boolean
1197      * shouldExist = value != null; Element root = updateElement(counter, element, xmlTag, shouldExist); if
1198      * (shouldExist) { Counter innerCount = new Counter(counter.getDepth() + 1); findAndReplaceSimpleElement(innerCount,
1199      * root, "activeByDefault", !value.isActiveByDefault() ? null : String.valueOf( value.isActiveByDefault() ),
1200      * "false"); findAndReplaceSimpleElement(innerCount, root, "jdk", value.getJdk(), null); updateActivationOS(
1201      * value.getOs(), "os", innerCount, root); updateActivationProperty( value.getProperty(), "property", innerCount,
1202      * root); updateActivationFile( value.getFile(), "file", innerCount, root); updateActivationCustom(
1203      * value.getCustom(), "custom", innerCount, root); } } //-- void updateActivation(Activation, String, Counter,
1204      * Element)
1205      */
1206 
1207     /**
1208      * Method updateActivationCustom
1209      *
1210      * @param value
1211      * @param element
1212      * @param counter
1213      * @param xmlTag
1214      */
1215     /*
1216      * protected void updateActivationCustom(ActivationCustom value, String xmlTag, Counter counter, Element element) {
1217      * boolean shouldExist = value != null; Element root = updateElement(counter, element, xmlTag, shouldExist); if
1218      * (shouldExist) { Counter innerCount = new Counter(counter.getDepth() + 1); findAndReplaceXpp3DOM(innerCount, root,
1219      * "configuration", (Xpp3Dom)value.getConfiguration()); findAndReplaceSimpleElement(innerCount, root, "type",
1220      * value.getType(), null); } } //-- void updateActivationCustom(ActivationCustom, String, Counter, Element)
1221      */
1222 
1223     /**
1224      * Method updateActivationFile
1225      *
1226      * @param value
1227      * @param element
1228      * @param counter
1229      * @param xmlTag
1230      */
1231     protected void updateActivationFile( ActivationFile value, String xmlTag, Counter counter, Element element )
1232     {
1233         boolean shouldExist = value != null;
1234         Element root = updateElement( counter, element, xmlTag, shouldExist );
1235         if ( shouldExist )
1236         {
1237             Counter innerCount = new Counter( counter.getDepth() + 1 );
1238             findAndReplaceSimpleElement( innerCount, root, "missing", value.getMissing(), null );
1239             findAndReplaceSimpleElement( innerCount, root, "exists", value.getExists(), null );
1240         }
1241     } // -- void updateActivationFile(ActivationFile, String, Counter, Element)
1242 
1243     /**
1244      * Method updateActivationOS
1245      *
1246      * @param value
1247      * @param element
1248      * @param counter
1249      * @param xmlTag
1250      */
1251     protected void updateActivationOS( ActivationOS value, String xmlTag, Counter counter, Element element )
1252     {
1253         boolean shouldExist = value != null;
1254         Element root = updateElement( counter, element, xmlTag, shouldExist );
1255         if ( shouldExist )
1256         {
1257             Counter innerCount = new Counter( counter.getDepth() + 1 );
1258             findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1259             findAndReplaceSimpleElement( innerCount, root, "family", value.getFamily(), null );
1260             findAndReplaceSimpleElement( innerCount, root, "arch", value.getArch(), null );
1261             findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
1262         }
1263     } // -- void updateActivationOS(ActivationOS, String, Counter, Element)
1264 
1265     /**
1266      * Method updateActivationProperty
1267      *
1268      * @param value
1269      * @param element
1270      * @param counter
1271      * @param xmlTag
1272      */
1273     protected void updateActivationProperty( ActivationProperty value, String xmlTag, Counter counter, Element element )
1274     {
1275         boolean shouldExist = value != null;
1276         Element root = updateElement( counter, element, xmlTag, shouldExist );
1277         if ( shouldExist )
1278         {
1279             Counter innerCount = new Counter( counter.getDepth() + 1 );
1280             findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1281             findAndReplaceSimpleElement( innerCount, root, "value", value.getValue(), null );
1282         }
1283     } // -- void updateActivationProperty(ActivationProperty, String, Counter, Element)
1284 
1285     /**
1286      * Method updateBuild
1287      *
1288      * @param value
1289      * @param element
1290      * @param counter
1291      * @param xmlTag
1292      */
1293     protected void updateBuild( Build value, String xmlTag, Counter counter, Element element )
1294     {
1295         boolean shouldExist = value != null;
1296         Element root = updateElement( counter, element, xmlTag, shouldExist );
1297         if ( shouldExist )
1298         {
1299             Counter innerCount = new Counter( counter.getDepth() + 1 );
1300             findAndReplaceSimpleElement( innerCount, root, "sourceDirectory", value.getSourceDirectory(), null );
1301             findAndReplaceSimpleElement( innerCount, root, "scriptSourceDirectory", value.getScriptSourceDirectory(),
1302                                          null );
1303             findAndReplaceSimpleElement( innerCount, root, "testSourceDirectory", value.getTestSourceDirectory(),
1304                                          null );
1305             findAndReplaceSimpleElement( innerCount, root, "outputDirectory", value.getOutputDirectory(), null );
1306             findAndReplaceSimpleElement( innerCount, root, "testOutputDirectory", value.getTestOutputDirectory(),
1307                                          null );
1308             iterateExtension( innerCount, root, value.getExtensions(), "extensions", "extension" );
1309             findAndReplaceSimpleElement( innerCount, root, "defaultGoal", value.getDefaultGoal(), null );
1310             iterateResource( innerCount, root, value.getResources(), "resources", "resource" );
1311             iterateResource( innerCount, root, value.getTestResources(), "testResources", "testResource" );
1312             findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
1313             findAndReplaceSimpleElement( innerCount, root, "finalName", value.getFinalName(), null );
1314             findAndReplaceSimpleLists( innerCount, root, value.getFilters(), "filters", "filter" );
1315             updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
1316             iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
1317         }
1318     } // -- void updateBuild(Build, String, Counter, Element)
1319 
1320     /**
1321      * Method updateBuildBase
1322      *
1323      * @param value
1324      * @param element
1325      * @param counter
1326      * @param xmlTag
1327      */
1328     protected void updateBuildBase( BuildBase value, String xmlTag, Counter counter, Element element )
1329     {
1330         boolean shouldExist = value != null;
1331         Element root = updateElement( counter, element, xmlTag, shouldExist );
1332         if ( shouldExist )
1333         {
1334             Counter innerCount = new Counter( counter.getDepth() + 1 );
1335             findAndReplaceSimpleElement( innerCount, root, "defaultGoal", value.getDefaultGoal(), null );
1336             iterateResource( innerCount, root, value.getResources(), "resources", "resource" );
1337             iterateResource( innerCount, root, value.getTestResources(), "testResources", "testResource" );
1338             findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
1339             findAndReplaceSimpleElement( innerCount, root, "finalName", value.getFinalName(), null );
1340             findAndReplaceSimpleLists( innerCount, root, value.getFilters(), "filters", "filter" );
1341             updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
1342             iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
1343         }
1344     } // -- void updateBuildBase(BuildBase, String, Counter, Element)
1345 
1346     /**
1347      * Method updateCiManagement
1348      *
1349      * @param value
1350      * @param element
1351      * @param counter
1352      * @param xmlTag
1353      */
1354     protected void updateCiManagement( CiManagement value, String xmlTag, Counter counter, Element element )
1355     {
1356         boolean shouldExist = value != null;
1357         Element root = updateElement( counter, element, xmlTag, shouldExist );
1358         if ( shouldExist )
1359         {
1360             Counter innerCount = new Counter( counter.getDepth() + 1 );
1361             findAndReplaceSimpleElement( innerCount, root, "system", value.getSystem(), null );
1362             findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1363             iterateNotifier( innerCount, root, value.getNotifiers(), "notifiers", "notifier" );
1364         }
1365     } // -- void updateCiManagement(CiManagement, String, Counter, Element)
1366 
1367     /**
1368      * Method updateConfigurationContainer
1369      *
1370      * @param value
1371      * @param element
1372      * @param counter
1373      * @param xmlTag
1374      */
1375     protected void updateConfigurationContainer( ConfigurationContainer value, String xmlTag, Counter counter,
1376                                                  Element element )
1377     {
1378         boolean shouldExist = value != null;
1379         Element root = updateElement( counter, element, xmlTag, shouldExist );
1380         if ( shouldExist )
1381         {
1382             Counter innerCount = new Counter( counter.getDepth() + 1 );
1383             findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
1384             findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
1385         }
1386     } // -- void updateConfigurationContainer(ConfigurationContainer, String, Counter, Element)
1387 
1388     /**
1389      * Method updateContributor
1390      *
1391      * @param value
1392      * @param element
1393      * @param counter
1394      * @param xmlTag
1395      */
1396     protected void updateContributor( Contributor value, String xmlTag, Counter counter, Element element )
1397     {
1398         Element root = element;
1399         Counter innerCount = new Counter( counter.getDepth() + 1 );
1400         findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1401         findAndReplaceSimpleElement( innerCount, root, "email", value.getEmail(), null );
1402         findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1403         findAndReplaceSimpleElement( innerCount, root, "organization", value.getOrganization(), null );
1404         findAndReplaceSimpleElement( innerCount, root, "organizationUrl", value.getOrganizationUrl(), null );
1405         findAndReplaceSimpleLists( innerCount, root, value.getRoles(), "roles", "role" );
1406         findAndReplaceSimpleElement( innerCount, root, "timezone", value.getTimezone(), null );
1407         findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
1408     } // -- void updateContributor(Contributor, String, Counter, Element)
1409 
1410     /**
1411      * Method updateDependency
1412      *
1413      * @param value
1414      * @param element
1415      * @param counter
1416      * @param xmlTag
1417      */
1418     protected void updateDependency( Dependency value, String xmlTag, Counter counter, Element element )
1419     {
1420         Element root = element;
1421         Counter innerCount = new Counter( counter.getDepth() + 1 );
1422         findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
1423         findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
1424         findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
1425         findAndReplaceSimpleElement( innerCount, root, "type", value.getType(), "jar" );
1426         findAndReplaceSimpleElement( innerCount, root, "classifier", value.getClassifier(), null );
1427         findAndReplaceSimpleElement( innerCount, root, "scope", value.getScope(), null );
1428         findAndReplaceSimpleElement( innerCount, root, "systemPath", value.getSystemPath(), null );
1429         iterateExclusion( innerCount, root, value.getExclusions(), "exclusions", "exclusion" );
1430         findAndReplaceSimpleElement( innerCount, root, "optional",
1431                                      !value.isOptional() ? null : String.valueOf( value.isOptional() ), "false" );
1432     } // -- void updateDependency(Dependency, String, Counter, Element)
1433 
1434     /**
1435      * Method updateDependencyManagement
1436      *
1437      * @param value
1438      * @param element
1439      * @param counter
1440      * @param xmlTag
1441      */
1442     protected void updateDependencyManagement( DependencyManagement value, String xmlTag, Counter counter,
1443                                                Element element )
1444     {
1445         boolean shouldExist = value != null;
1446         Element root = updateElement( counter, element, xmlTag, shouldExist );
1447         if ( shouldExist )
1448         {
1449             Counter innerCount = new Counter( counter.getDepth() + 1 );
1450             iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
1451         }
1452     } // -- void updateDependencyManagement(DependencyManagement, String, Counter, Element)
1453 
1454     /**
1455      * Method updateDeploymentRepository
1456      *
1457      * @param value
1458      * @param element
1459      * @param counter
1460      * @param xmlTag
1461      */
1462     protected void updateDeploymentRepository( DeploymentRepository value, String xmlTag, Counter counter,
1463                                                Element element )
1464     {
1465         boolean shouldExist = value != null;
1466         Element root = updateElement( counter, element, xmlTag, shouldExist );
1467         if ( shouldExist )
1468         {
1469             Counter innerCount = new Counter( counter.getDepth() + 1 );
1470             findAndReplaceSimpleElement( innerCount, root, "uniqueVersion",
1471                                          value.isUniqueVersion() ? null : String.valueOf( value.isUniqueVersion() ),
1472                                          "true" );
1473             findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
1474             findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1475             findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1476             findAndReplaceSimpleElement( innerCount, root, "layout", value.getLayout(), "default" );
1477         }
1478     } // -- void updateDeploymentRepository(DeploymentRepository, String, Counter, Element)
1479 
1480     /**
1481      * Method updateDeveloper
1482      *
1483      * @param value
1484      * @param element
1485      * @param counter
1486      * @param xmlTag
1487      */
1488     protected void updateDeveloper( Developer value, String xmlTag, Counter counter, Element element )
1489     {
1490         Element root = element;
1491         Counter innerCount = new Counter( counter.getDepth() + 1 );
1492         findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
1493         findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1494         findAndReplaceSimpleElement( innerCount, root, "email", value.getEmail(), null );
1495         findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1496         findAndReplaceSimpleElement( innerCount, root, "organization", value.getOrganization(), null );
1497         findAndReplaceSimpleElement( innerCount, root, "organizationUrl", value.getOrganizationUrl(), null );
1498         findAndReplaceSimpleLists( innerCount, root, value.getRoles(), "roles", "role" );
1499         findAndReplaceSimpleElement( innerCount, root, "timezone", value.getTimezone(), null );
1500         findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
1501     } // -- void updateDeveloper(Developer, String, Counter, Element)
1502 
1503     /**
1504      * Method updateDistributionManagement
1505      *
1506      * @param value
1507      * @param element
1508      * @param counter
1509      * @param xmlTag
1510      */
1511     protected void updateDistributionManagement( DistributionManagement value, String xmlTag, Counter counter,
1512                                                  Element element )
1513     {
1514         boolean shouldExist = value != null;
1515         Element root = updateElement( counter, element, xmlTag, shouldExist );
1516         if ( shouldExist )
1517         {
1518             Counter innerCount = new Counter( counter.getDepth() + 1 );
1519             updateDeploymentRepository( value.getRepository(), "repository", innerCount, root );
1520             updateDeploymentRepository( value.getSnapshotRepository(), "snapshotRepository", innerCount, root );
1521             updateSite( value.getSite(), "site", innerCount, root );
1522             findAndReplaceSimpleElement( innerCount, root, "downloadUrl", value.getDownloadUrl(), null );
1523             updateRelocation( value.getRelocation(), "relocation", innerCount, root );
1524             findAndReplaceSimpleElement( innerCount, root, "status", value.getStatus(), null );
1525         }
1526     } // -- void updateDistributionManagement(DistributionManagement, String, Counter, Element)
1527 
1528     /**
1529      * Method updateElement
1530      *
1531      * @param counter
1532      * @param shouldExist
1533      * @param name
1534      * @param parent
1535      */
1536     protected Element updateElement( Counter counter, Element parent, String name, boolean shouldExist )
1537     {
1538         Element element = parent.getChild( name, parent.getNamespace() );
1539         if ( element != null && shouldExist )
1540         {
1541             counter.increaseCount();
1542         }
1543         if ( element == null && shouldExist )
1544         {
1545             element = factory.element( name, parent.getNamespace() );
1546             insertAtPreferredLocation( parent, element, counter );
1547             counter.increaseCount();
1548         }
1549         if ( !shouldExist && element != null )
1550         {
1551             int index = parent.indexOf( element );
1552             if ( index > 0 )
1553             {
1554                 Content previous = parent.getContent( index - 1 );
1555                 if ( previous instanceof Text )
1556                 {
1557                     Text txt = (Text) previous;
1558                     if ( txt.getTextTrim().length() == 0 )
1559                     {
1560                         parent.removeContent( txt );
1561                     }
1562                 }
1563             }
1564             parent.removeContent( element );
1565         }
1566         return element;
1567     } // -- Element updateElement(Counter, Element, String, boolean)
1568 
1569     /**
1570      * Method updateExclusion
1571      *
1572      * @param value
1573      * @param element
1574      * @param counter
1575      * @param xmlTag
1576      */
1577     protected void updateExclusion( Exclusion value, String xmlTag, Counter counter, Element element )
1578     {
1579         Element root = element;
1580         Counter innerCount = new Counter( counter.getDepth() + 1 );
1581         findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
1582         findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
1583     } // -- void updateExclusion(Exclusion, String, Counter, Element)
1584 
1585     /**
1586      * Method updateExtension
1587      *
1588      * @param value
1589      * @param element
1590      * @param counter
1591      * @param xmlTag
1592      */
1593     protected void updateExtension( Extension value, String xmlTag, Counter counter, Element element )
1594     {
1595         Element root = element;
1596         Counter innerCount = new Counter( counter.getDepth() + 1 );
1597         findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
1598         findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
1599         findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
1600     } // -- void updateExtension(Extension, String, Counter, Element)
1601 
1602     /**
1603      * Method updateFileSet
1604      *
1605      * @param value
1606      * @param element
1607      * @param counter
1608      * @param xmlTag
1609      */
1610     protected void updateFileSet( FileSet value, String xmlTag, Counter counter, Element element )
1611     {
1612         boolean shouldExist = value != null;
1613         Element root = updateElement( counter, element, xmlTag, shouldExist );
1614         if ( shouldExist )
1615         {
1616             Counter innerCount = new Counter( counter.getDepth() + 1 );
1617             findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
1618             findAndReplaceSimpleLists( innerCount, root, value.getIncludes(), "includes", "include" );
1619             findAndReplaceSimpleLists( innerCount, root, value.getExcludes(), "excludes", "exclude" );
1620         }
1621     } // -- void updateFileSet(FileSet, String, Counter, Element)
1622 
1623     /**
1624      * Method updateIssueManagement
1625      *
1626      * @param value
1627      * @param element
1628      * @param counter
1629      * @param xmlTag
1630      */
1631     protected void updateIssueManagement( IssueManagement value, String xmlTag, Counter counter, Element element )
1632     {
1633         boolean shouldExist = value != null;
1634         Element root = updateElement( counter, element, xmlTag, shouldExist );
1635         if ( shouldExist )
1636         {
1637             Counter innerCount = new Counter( counter.getDepth() + 1 );
1638             findAndReplaceSimpleElement( innerCount, root, "system", value.getSystem(), null );
1639             findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1640         }
1641     } // -- void updateIssueManagement(IssueManagement, String, Counter, Element)
1642 
1643     /**
1644      * Method updateLicense
1645      *
1646      * @param value
1647      * @param element
1648      * @param counter
1649      * @param xmlTag
1650      */
1651     protected void updateLicense( License value, String xmlTag, Counter counter, Element element )
1652     {
1653         Element root = element;
1654         Counter innerCount = new Counter( counter.getDepth() + 1 );
1655         findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1656         findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1657         findAndReplaceSimpleElement( innerCount, root, "distribution", value.getDistribution(), null );
1658         findAndReplaceSimpleElement( innerCount, root, "comments", value.getComments(), null );
1659     } // -- void updateLicense(License, String, Counter, Element)
1660 
1661     /**
1662      * Method updateMailingList
1663      *
1664      * @param value
1665      * @param element
1666      * @param counter
1667      * @param xmlTag
1668      */
1669     protected void updateMailingList( MailingList value, String xmlTag, Counter counter, Element element )
1670     {
1671         Element root = element;
1672         Counter innerCount = new Counter( counter.getDepth() + 1 );
1673         findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1674         findAndReplaceSimpleElement( innerCount, root, "subscribe", value.getSubscribe(), null );
1675         findAndReplaceSimpleElement( innerCount, root, "unsubscribe", value.getUnsubscribe(), null );
1676         findAndReplaceSimpleElement( innerCount, root, "post", value.getPost(), null );
1677         findAndReplaceSimpleElement( innerCount, root, "archive", value.getArchive(), null );
1678         findAndReplaceSimpleLists( innerCount, root, value.getOtherArchives(), "otherArchives", "otherArchive" );
1679     } // -- void updateMailingList(MailingList, String, Counter, Element)
1680 
1681     /**
1682      * Method updateModel
1683      *
1684      * @param value
1685      * @param element
1686      * @param counter
1687      * @param xmlTag
1688      */
1689     protected void updateModel( Model value, String xmlTag, Counter counter, Element element )
1690     {
1691         Element root = element;
1692         Counter innerCount = new Counter( counter.getDepth() + 1 );
1693         updateParent( value.getParent(), "parent", innerCount, root );
1694         findAndReplaceSimpleElement( innerCount, root, "modelVersion", value.getModelVersion(), null );
1695         findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
1696         findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
1697         findAndReplaceSimpleElement( innerCount, root, "packaging", value.getPackaging(), "jar" );
1698         findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1699         findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
1700         findAndReplaceSimpleElement( innerCount, root, "description", value.getDescription(), null );
1701         findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1702         updatePrerequisites( value.getPrerequisites(), "prerequisites", innerCount, root );
1703         updateIssueManagement( value.getIssueManagement(), "issueManagement", innerCount, root );
1704         updateCiManagement( value.getCiManagement(), "ciManagement", innerCount, root );
1705         findAndReplaceSimpleElement( innerCount, root, "inceptionYear", value.getInceptionYear(), null );
1706         iterateMailingList( innerCount, root, value.getMailingLists(), "mailingLists", "mailingList" );
1707         iterateDeveloper( innerCount, root, value.getDevelopers(), "developers", "developer" );
1708         iterateContributor( innerCount, root, value.getContributors(), "contributors", "contributor" );
1709         iterateLicense( innerCount, root, value.getLicenses(), "licenses", "license" );
1710         updateScm( value.getScm(), "scm", innerCount, root );
1711         updateOrganization( value.getOrganization(), "organization", innerCount, root );
1712         updateBuild( value.getBuild(), "build", innerCount, root );
1713         iterateProfile( innerCount, root, value.getProfiles(), "profiles", "profile" );
1714         findAndReplaceSimpleLists( innerCount, root, value.getModules(), "modules", "module" );
1715         iterateRepository( innerCount, root, value.getRepositories(), "repositories", "repository" );
1716         iterateRepository( innerCount, root, value.getPluginRepositories(), "pluginRepositories", "pluginRepository" );
1717         iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
1718         findAndReplaceXpp3DOM( innerCount, root, "reports", (Xpp3Dom) value.getReports() );
1719         updateReporting( value.getReporting(), "reporting", innerCount, root );
1720         updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root );
1721         updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root );
1722         findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
1723     } // -- void updateModel(Model, String, Counter, Element)
1724 
1725     /**
1726      * Method updateModelBase
1727      *
1728      * @param value
1729      * @param element
1730      * @param counter
1731      * @param xmlTag
1732      */
1733     protected void updateModelBase( ModelBase value, String xmlTag, Counter counter, Element element )
1734     {
1735         boolean shouldExist = value != null;
1736         Element root = updateElement( counter, element, xmlTag, shouldExist );
1737         if ( shouldExist )
1738         {
1739             Counter innerCount = new Counter( counter.getDepth() + 1 );
1740             findAndReplaceSimpleLists( innerCount, root, value.getModules(), "modules", "module" );
1741             iterateRepository( innerCount, root, value.getRepositories(), "repositories", "repository" );
1742             iterateRepository( innerCount, root, value.getPluginRepositories(), "pluginRepositories",
1743                                "pluginRepository" );
1744             iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
1745             findAndReplaceXpp3DOM( innerCount, root, "reports", (Xpp3Dom) value.getReports() );
1746             updateReporting( value.getReporting(), "reporting", innerCount, root );
1747             updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root );
1748             updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount,
1749                                           root );
1750             findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
1751         }
1752     } // -- void updateModelBase(ModelBase, String, Counter, Element)
1753 
1754     /**
1755      * Method updateNotifier
1756      *
1757      * @param value
1758      * @param element
1759      * @param counter
1760      * @param xmlTag
1761      */
1762     protected void updateNotifier( Notifier value, String xmlTag, Counter counter, Element element )
1763     {
1764         Element root = element;
1765         Counter innerCount = new Counter( counter.getDepth() + 1 );
1766         findAndReplaceSimpleElement( innerCount, root, "type", value.getType(), "mail" );
1767         findAndReplaceSimpleElement( innerCount, root, "sendOnError",
1768                                      value.isSendOnError() ? null : String.valueOf( value.isSendOnError() ), "true" );
1769         findAndReplaceSimpleElement( innerCount, root, "sendOnFailure",
1770                                      value.isSendOnFailure() ? null : String.valueOf( value.isSendOnFailure() ),
1771                                      "true" );
1772         findAndReplaceSimpleElement( innerCount, root, "sendOnSuccess",
1773                                      value.isSendOnSuccess() ? null : String.valueOf( value.isSendOnSuccess() ),
1774                                      "true" );
1775         findAndReplaceSimpleElement( innerCount, root, "sendOnWarning",
1776                                      value.isSendOnWarning() ? null : String.valueOf( value.isSendOnWarning() ),
1777                                      "true" );
1778         findAndReplaceSimpleElement( innerCount, root, "address", value.getAddress(), null );
1779         findAndReplaceProperties( innerCount, root, "configuration", value.getConfiguration() );
1780     } // -- void updateNotifier(Notifier, String, Counter, Element)
1781 
1782     /**
1783      * Method updateOrganization
1784      *
1785      * @param value
1786      * @param element
1787      * @param counter
1788      * @param xmlTag
1789      */
1790     protected void updateOrganization( Organization value, String xmlTag, Counter counter, Element element )
1791     {
1792         boolean shouldExist = value != null;
1793         Element root = updateElement( counter, element, xmlTag, shouldExist );
1794         if ( shouldExist )
1795         {
1796             Counter innerCount = new Counter( counter.getDepth() + 1 );
1797             findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1798             findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1799         }
1800     } // -- void updateOrganization(Organization, String, Counter, Element)
1801 
1802     /**
1803      * Method updateParent
1804      *
1805      * @param value
1806      * @param element
1807      * @param counter
1808      * @param xmlTag
1809      */
1810     protected void updateParent( Parent value, String xmlTag, Counter counter, Element element )
1811     {
1812         boolean shouldExist = value != null;
1813         Element root = updateElement( counter, element, xmlTag, shouldExist );
1814         if ( shouldExist )
1815         {
1816             Counter innerCount = new Counter( counter.getDepth() + 1 );
1817             findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
1818             findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
1819             findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
1820             findAndReplaceSimpleElement( innerCount, root, "relativePath", value.getRelativePath(), "../pom.xml" );
1821         }
1822     } // -- void updateParent(Parent, String, Counter, Element)
1823 
1824     /**
1825      * Method updatePatternSet
1826      *
1827      * @param value
1828      * @param element
1829      * @param counter
1830      * @param xmlTag
1831      */
1832     protected void updatePatternSet( PatternSet value, String xmlTag, Counter counter, Element element )
1833     {
1834         boolean shouldExist = value != null;
1835         Element root = updateElement( counter, element, xmlTag, shouldExist );
1836         if ( shouldExist )
1837         {
1838             Counter innerCount = new Counter( counter.getDepth() + 1 );
1839             findAndReplaceSimpleLists( innerCount, root, value.getIncludes(), "includes", "include" );
1840             findAndReplaceSimpleLists( innerCount, root, value.getExcludes(), "excludes", "exclude" );
1841         }
1842     } // -- void updatePatternSet(PatternSet, String, Counter, Element)
1843 
1844     /**
1845      * Method updatePlugin
1846      *
1847      * @param value
1848      * @param element
1849      * @param counter
1850      * @param xmlTag
1851      */
1852     protected void updatePlugin( Plugin value, String xmlTag, Counter counter, Element element )
1853     {
1854         Element root = element;
1855         Counter innerCount = new Counter( counter.getDepth() + 1 );
1856         findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), "org.apache.maven.plugins" );
1857         findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
1858         findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
1859         findAndReplaceSimpleElement( innerCount, root, "extensions",
1860                                      !value.isExtensions() ? null : String.valueOf( value.isExtensions() ), "false" );
1861         iteratePluginExecution( innerCount, root, value.getExecutions(), "executions", "execution" );
1862         iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
1863         findAndReplaceXpp3DOM( innerCount, root, "goals", (Xpp3Dom) value.getGoals() );
1864         findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
1865         findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
1866     } // -- void updatePlugin(Plugin, String, Counter, Element)
1867 
1868     /**
1869      * Method updatePluginConfiguration
1870      *
1871      * @param value
1872      * @param element
1873      * @param counter
1874      * @param xmlTag
1875      */
1876     protected void updatePluginConfiguration( PluginConfiguration value, String xmlTag, Counter counter,
1877                                               Element element )
1878     {
1879         boolean shouldExist = value != null;
1880         Element root = updateElement( counter, element, xmlTag, shouldExist );
1881         if ( shouldExist )
1882         {
1883             Counter innerCount = new Counter( counter.getDepth() + 1 );
1884             updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
1885             iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
1886         }
1887     } // -- void updatePluginConfiguration(PluginConfiguration, String, Counter, Element)
1888 
1889     /**
1890      * Method updatePluginContainer
1891      *
1892      * @param value
1893      * @param element
1894      * @param counter
1895      * @param xmlTag
1896      */
1897     protected void updatePluginContainer( PluginContainer value, String xmlTag, Counter counter, Element element )
1898     {
1899         boolean shouldExist = value != null;
1900         Element root = updateElement( counter, element, xmlTag, shouldExist );
1901         if ( shouldExist )
1902         {
1903             Counter innerCount = new Counter( counter.getDepth() + 1 );
1904             iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
1905         }
1906     } // -- void updatePluginContainer(PluginContainer, String, Counter, Element)
1907 
1908     /**
1909      * Method updatePluginExecution
1910      *
1911      * @param value
1912      * @param element
1913      * @param counter
1914      * @param xmlTag
1915      */
1916     protected void updatePluginExecution( PluginExecution value, String xmlTag, Counter counter, Element element )
1917     {
1918         Element root = element;
1919         Counter innerCount = new Counter( counter.getDepth() + 1 );
1920         findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), "default" );
1921         findAndReplaceSimpleElement( innerCount, root, "phase", value.getPhase(), null );
1922         findAndReplaceSimpleLists( innerCount, root, value.getGoals(), "goals", "goal" );
1923         findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
1924         findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
1925     } // -- void updatePluginExecution(PluginExecution, String, Counter, Element)
1926 
1927     /**
1928      * Method updatePluginManagement
1929      *
1930      * @param value
1931      * @param element
1932      * @param counter
1933      * @param xmlTag
1934      */
1935     protected void updatePluginManagement( PluginManagement value, String xmlTag, Counter counter, Element element )
1936     {
1937         boolean shouldExist = value != null;
1938         Element root = updateElement( counter, element, xmlTag, shouldExist );
1939         if ( shouldExist )
1940         {
1941             Counter innerCount = new Counter( counter.getDepth() + 1 );
1942             iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
1943         }
1944     } // -- void updatePluginManagement(PluginManagement, String, Counter, Element)
1945 
1946     /**
1947      * Method updatePrerequisites
1948      *
1949      * @param value
1950      * @param element
1951      * @param counter
1952      * @param xmlTag
1953      */
1954     protected void updatePrerequisites( Prerequisites value, String xmlTag, Counter counter, Element element )
1955     {
1956         boolean shouldExist = value != null;
1957         Element root = updateElement( counter, element, xmlTag, shouldExist );
1958         if ( shouldExist )
1959         {
1960             Counter innerCount = new Counter( counter.getDepth() + 1 );
1961             findAndReplaceSimpleElement( innerCount, root, "maven", value.getMaven(), "2.0" );
1962         }
1963     } // -- void updatePrerequisites(Prerequisites, String, Counter, Element)
1964 
1965     /**
1966      * Method updateProfile
1967      *
1968      * @param value
1969      * @param element
1970      * @param counter
1971      * @param xmlTag
1972      */
1973     protected void updateProfile( Profile value, String xmlTag, Counter counter, Element element )
1974     {
1975         Element root = element;
1976         Counter innerCount = new Counter( counter.getDepth() + 1 );
1977         findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), "default" );
1978         // updateActivation( value.getActivation(), "activation", innerCount, root);
1979         updateBuildBase( value.getBuild(), "build", innerCount, root );
1980         findAndReplaceSimpleLists( innerCount, root, value.getModules(), "modules", "module" );
1981         iterateRepository( innerCount, root, value.getRepositories(), "repositories", "repository" );
1982         iterateRepository( innerCount, root, value.getPluginRepositories(), "pluginRepositories", "pluginRepository" );
1983         iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
1984         findAndReplaceXpp3DOM( innerCount, root, "reports", (Xpp3Dom) value.getReports() );
1985         updateReporting( value.getReporting(), "reporting", innerCount, root );
1986         updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root );
1987         updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root );
1988         findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
1989     } // -- void updateProfile(Profile, String, Counter, Element)
1990 
1991     /**
1992      * Method updateRelocation
1993      *
1994      * @param value
1995      * @param element
1996      * @param counter
1997      * @param xmlTag
1998      */
1999     protected void updateRelocation( Relocation value, String xmlTag, Counter counter, Element element )
2000     {
2001         boolean shouldExist = value != null;
2002         Element root = updateElement( counter, element, xmlTag, shouldExist );
2003         if ( shouldExist )
2004         {
2005             Counter innerCount = new Counter( counter.getDepth() + 1 );
2006             findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
2007             findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
2008             findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
2009             findAndReplaceSimpleElement( innerCount, root, "message", value.getMessage(), null );
2010         }
2011     } // -- void updateRelocation(Relocation, String, Counter, Element)
2012 
2013     /**
2014      * Method updateReportPlugin
2015      *
2016      * @param value
2017      * @param element
2018      * @param counter
2019      * @param xmlTag
2020      */
2021     protected void updateReportPlugin( ReportPlugin value, String xmlTag, Counter counter, Element element )
2022     {
2023         Element root = element;
2024         Counter innerCount = new Counter( counter.getDepth() + 1 );
2025         findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), "org.apache.maven.plugins" );
2026         findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
2027         findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
2028         findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
2029         findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
2030         iterateReportSet( innerCount, root, value.getReportSets(), "reportSets", "reportSet" );
2031     } // -- void updateReportPlugin(ReportPlugin, String, Counter, Element)
2032 
2033     /**
2034      * Method updateReportSet
2035      *
2036      * @param value
2037      * @param element
2038      * @param counter
2039      * @param xmlTag
2040      */
2041     protected void updateReportSet( ReportSet value, String xmlTag, Counter counter, Element element )
2042     {
2043         Element root = element;
2044         Counter innerCount = new Counter( counter.getDepth() + 1 );
2045         findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), "default" );
2046         findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
2047         findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
2048         findAndReplaceSimpleLists( innerCount, root, value.getReports(), "reports", "report" );
2049     } // -- void updateReportSet(ReportSet, String, Counter, Element)
2050 
2051     /**
2052      * Method updateReporting
2053      *
2054      * @param value
2055      * @param element
2056      * @param counter
2057      * @param xmlTag
2058      */
2059     protected void updateReporting( Reporting value, String xmlTag, Counter counter, Element element )
2060     {
2061         boolean shouldExist = value != null;
2062         Element root = updateElement( counter, element, xmlTag, shouldExist );
2063         if ( shouldExist )
2064         {
2065             Counter innerCount = new Counter( counter.getDepth() + 1 );
2066             findAndReplaceSimpleElement( innerCount, root, "excludeDefaults", !value.isExcludeDefaults()
2067                 ? null
2068                 : String.valueOf( value.isExcludeDefaults() ), "false" );
2069             findAndReplaceSimpleElement( innerCount, root, "outputDirectory", value.getOutputDirectory(), null );
2070             iterateReportPlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
2071         }
2072     } // -- void updateReporting(Reporting, String, Counter, Element)
2073 
2074     /**
2075      * Method updateRepository
2076      *
2077      * @param value
2078      * @param element
2079      * @param counter
2080      * @param xmlTag
2081      */
2082     protected void updateRepository( Repository value, String xmlTag, Counter counter, Element element )
2083     {
2084         Element root = element;
2085         Counter innerCount = new Counter( counter.getDepth() + 1 );
2086         updateRepositoryPolicy( value.getReleases(), "releases", innerCount, root );
2087         updateRepositoryPolicy( value.getSnapshots(), "snapshots", innerCount, root );
2088         findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
2089         findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
2090         findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
2091         findAndReplaceSimpleElement( innerCount, root, "layout", value.getLayout(), "default" );
2092     } // -- void updateRepository(Repository, String, Counter, Element)
2093 
2094     /**
2095      * Method updateRepositoryBase
2096      *
2097      * @param value
2098      * @param element
2099      * @param counter
2100      * @param xmlTag
2101      */
2102     protected void updateRepositoryBase( RepositoryBase value, String xmlTag, Counter counter, Element element )
2103     {
2104         boolean shouldExist = value != null;
2105         Element root = updateElement( counter, element, xmlTag, shouldExist );
2106         if ( shouldExist )
2107         {
2108             Counter innerCount = new Counter( counter.getDepth() + 1 );
2109             findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
2110             findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
2111             findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
2112             findAndReplaceSimpleElement( innerCount, root, "layout", value.getLayout(), "default" );
2113         }
2114     } // -- void updateRepositoryBase(RepositoryBase, String, Counter, Element)
2115 
2116     /**
2117      * Method updateRepositoryPolicy
2118      *
2119      * @param value
2120      * @param element
2121      * @param counter
2122      * @param xmlTag
2123      */
2124     protected void updateRepositoryPolicy( RepositoryPolicy value, String xmlTag, Counter counter, Element element )
2125     {
2126         boolean shouldExist = value != null;
2127         Element root = updateElement( counter, element, xmlTag, shouldExist );
2128         if ( shouldExist )
2129         {
2130             Counter innerCount = new Counter( counter.getDepth() + 1 );
2131             findAndReplaceSimpleElement( innerCount, root, "enabled",
2132                                          value.isEnabled() ? null : String.valueOf( value.isEnabled() ), "true" );
2133             findAndReplaceSimpleElement( innerCount, root, "updatePolicy", value.getUpdatePolicy(), null );
2134             findAndReplaceSimpleElement( innerCount, root, "checksumPolicy", value.getChecksumPolicy(), null );
2135         }
2136     } // -- void updateRepositoryPolicy(RepositoryPolicy, String, Counter, Element)
2137 
2138     /**
2139      * Method updateResource
2140      *
2141      * @param value
2142      * @param element
2143      * @param counter
2144      * @param xmlTag
2145      */
2146     protected void updateResource( Resource value, String xmlTag, Counter counter, Element element )
2147     {
2148         Element root = element;
2149         Counter innerCount = new Counter( counter.getDepth() + 1 );
2150         findAndReplaceSimpleElement( innerCount, root, "targetPath", value.getTargetPath(), null );
2151         findAndReplaceSimpleElement( innerCount, root, "filtering",
2152                                      !value.isFiltering() ? null : String.valueOf( value.isFiltering() ), "false" );
2153         findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
2154         findAndReplaceSimpleLists( innerCount, root, value.getIncludes(), "includes", "include" );
2155         findAndReplaceSimpleLists( innerCount, root, value.getExcludes(), "excludes", "exclude" );
2156     } // -- void updateResource(Resource, String, Counter, Element)
2157 
2158     /**
2159      * Method updateScm
2160      *
2161      * @param value
2162      * @param element
2163      * @param counter
2164      * @param xmlTag
2165      */
2166     protected void updateScm( Scm value, String xmlTag, Counter counter, Element element )
2167     {
2168         boolean shouldExist = value != null;
2169         Element root = updateElement( counter, element, xmlTag, shouldExist );
2170         if ( shouldExist )
2171         {
2172             Counter innerCount = new Counter( counter.getDepth() + 1 );
2173             findAndReplaceSimpleElement( innerCount, root, "connection", value.getConnection(), null );
2174             findAndReplaceSimpleElement( innerCount, root, "developerConnection", value.getDeveloperConnection(),
2175                                          null );
2176             findAndReplaceSimpleElement( innerCount, root, "tag", value.getTag(), "HEAD" );
2177             findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
2178         }
2179     } // -- void updateScm(Scm, String, Counter, Element)
2180 
2181     /**
2182      * Method updateSite
2183      *
2184      * @param value
2185      * @param element
2186      * @param counter
2187      * @param xmlTag
2188      */
2189     protected void updateSite( Site value, String xmlTag, Counter counter, Element element )
2190     {
2191         boolean shouldExist = value != null;
2192         Element root = updateElement( counter, element, xmlTag, shouldExist );
2193         if ( shouldExist )
2194         {
2195             Counter innerCount = new Counter( counter.getDepth() + 1 );
2196             findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
2197             findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
2198             findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
2199         }
2200     } // -- void updateSite(Site, String, Counter, Element)
2201 
2202     /**
2203      * Method write
2204      *
2205      * @param project
2206      * @param stream
2207      * @param document
2208      * @deprecated
2209      */
2210     public void write( Model project, Document document, OutputStream stream )
2211         throws java.io.IOException
2212     {
2213         updateModel( project, "project", new Counter( 0 ), document.getRootElement() );
2214         XMLOutputter outputter = new XMLOutputter();
2215         Format format = Format.getPrettyFormat();
2216         format.setIndent( "    " ).setLineSeparator( System.getProperty( "line.separator" ) );
2217         outputter.setFormat( format );
2218         outputter.output( document, stream );
2219     } // -- void write(Model, Document, OutputStream)
2220 
2221     /**
2222      * Method write
2223      *
2224      * @param project
2225      * @param writer
2226      * @param document
2227      */
2228     public void write( Model project, Document document, OutputStreamWriter writer )
2229         throws java.io.IOException
2230     {
2231         Format format = Format.getRawFormat();
2232         format.setEncoding( writer.getEncoding() ).setLineSeparator( System.getProperty( "line.separator" ) );
2233         write( project, document, writer, format );
2234     } // -- void write(Model, Document, OutputStreamWriter)
2235 
2236     /**
2237      * Method write
2238      *
2239      * @param project
2240      * @param jdomFormat
2241      * @param writer
2242      * @param document
2243      */
2244     public void write( Model project, Document document, Writer writer, Format jdomFormat )
2245         throws java.io.IOException
2246     {
2247         updateModel( project, "project", new Counter( 0 ), document.getRootElement() );
2248         XMLOutputter outputter = new XMLOutputter();
2249         outputter.setFormat( jdomFormat );
2250         outputter.output( document, writer );
2251     } // -- void write(Model, Document, Writer, Format)
2252 
2253     // -----------------/
2254     // - Inner Classes -/
2255     // -----------------/
2256 
2257     /**
2258      * Class Counter.
2259      *
2260      * @version $Revision: 1384332 $ $Date: 2012-09-13 15:48:42 +0200 (Thu, 13 Sep 2012) $
2261      */
2262     public class Counter
2263     {
2264 
2265         // --------------------------/
2266         // - Class/Member Variables -/
2267         // --------------------------/
2268 
2269         /**
2270          * Field currentIndex
2271          */
2272         private int currentIndex = 0;
2273 
2274         /**
2275          * Field level
2276          */
2277         private int level;
2278 
2279         // ----------------/
2280         // - Constructors -/
2281         // ----------------/
2282 
2283         public Counter( int depthLevel )
2284         {
2285             level = depthLevel;
2286         } // -- org.apache.maven.model.io.jdom.Counter(int)
2287 
2288         // -----------/
2289         // - Methods -/
2290         // -----------/
2291 
2292         /**
2293          * Method getCurrentIndex
2294          */
2295         public int getCurrentIndex()
2296         {
2297             return currentIndex;
2298         } // -- int getCurrentIndex()
2299 
2300         /**
2301          * Method getDepth
2302          */
2303         public int getDepth()
2304         {
2305             return level;
2306         } // -- int getDepth()
2307 
2308         /**
2309          * Method increaseCount
2310          */
2311         public void increaseCount()
2312         {
2313             currentIndex = currentIndex + 1;
2314         } // -- void increaseCount()
2315 
2316     }
2317 
2318 }