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