View Javadoc

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