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