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