View Javadoc

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