View Javadoc

1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 1.8.1,
3   // any modifications will be overwritten.
4   // ==============================================================
5   
6   package org.apache.maven.plugin.lifecycle.io.xpp3;
7   
8     //---------------------------------/
9    //- Imported classes and packages -/
10  //---------------------------------/
11  
12  import java.io.OutputStream;
13  import java.io.Writer;
14  import java.util.Iterator;
15  import org.apache.maven.plugin.lifecycle.Execution;
16  import org.apache.maven.plugin.lifecycle.Lifecycle;
17  import org.apache.maven.plugin.lifecycle.LifecycleConfiguration;
18  import org.apache.maven.plugin.lifecycle.Phase;
19  import org.codehaus.plexus.util.xml.Xpp3Dom;
20  import org.codehaus.plexus.util.xml.pull.MXSerializer;
21  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
22  
23  /**
24   * Class LifecycleMappingsXpp3Writer.
25   * 
26   * @version $Revision$ $Date$
27   */
28  @SuppressWarnings( "all" )
29  public class LifecycleMappingsXpp3Writer
30  {
31  
32        //--------------------------/
33       //- Class/Member Variables -/
34      //--------------------------/
35  
36      /**
37       * Field NAMESPACE.
38       */
39      private static final String NAMESPACE = null;
40  
41  
42        //-----------/
43       //- Methods -/
44      //-----------/
45  
46      /**
47       * Method write.
48       * 
49       * @param writer
50       * @param lifecycleConfiguration
51       * @throws java.io.IOException
52       */
53      public void write( Writer writer, LifecycleConfiguration lifecycleConfiguration )
54          throws java.io.IOException
55      {
56          XmlSerializer serializer = new MXSerializer();
57          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
58          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
59          serializer.setOutput( writer );
60          serializer.startDocument( lifecycleConfiguration.getModelEncoding(), null );
61          writeLifecycleConfiguration( lifecycleConfiguration, "lifecycles", serializer );
62          serializer.endDocument();
63      } //-- void write( Writer, LifecycleConfiguration )
64  
65      /**
66       * Method write.
67       * 
68       * @param stream
69       * @param lifecycleConfiguration
70       * @throws java.io.IOException
71       */
72      public void write( OutputStream stream, LifecycleConfiguration lifecycleConfiguration )
73          throws java.io.IOException
74      {
75          XmlSerializer serializer = new MXSerializer();
76          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
77          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
78          serializer.setOutput( stream, lifecycleConfiguration.getModelEncoding() );
79          serializer.startDocument( lifecycleConfiguration.getModelEncoding(), null );
80          writeLifecycleConfiguration( lifecycleConfiguration, "lifecycles", serializer );
81          serializer.endDocument();
82      } //-- void write( OutputStream, LifecycleConfiguration )
83  
84      /**
85       * Method writeExecution.
86       * 
87       * @param execution
88       * @param serializer
89       * @param tagName
90       * @throws java.io.IOException
91       */
92      private void writeExecution( Execution execution, String tagName, XmlSerializer serializer )
93          throws java.io.IOException
94      {
95          serializer.startTag( NAMESPACE, tagName );
96          if ( execution.getConfiguration() != null )
97          {
98              ((Xpp3Dom) execution.getConfiguration()).writeToSerializer( NAMESPACE, serializer );
99          }
100         if ( ( execution.getGoals() != null ) && ( execution.getGoals().size() > 0 ) )
101         {
102             serializer.startTag( NAMESPACE, "goals" );
103             for ( Iterator iter = execution.getGoals().iterator(); iter.hasNext(); )
104             {
105                 String goal = (String) iter.next();
106                 serializer.startTag( NAMESPACE, "goal" ).text( goal ).endTag( NAMESPACE, "goal" );
107             }
108             serializer.endTag( NAMESPACE, "goals" );
109         }
110         serializer.endTag( NAMESPACE, tagName );
111     } //-- void writeExecution( Execution, String, XmlSerializer )
112 
113     /**
114      * Method writeLifecycle.
115      * 
116      * @param lifecycle
117      * @param serializer
118      * @param tagName
119      * @throws java.io.IOException
120      */
121     private void writeLifecycle( Lifecycle lifecycle, String tagName, XmlSerializer serializer )
122         throws java.io.IOException
123     {
124         serializer.startTag( NAMESPACE, tagName );
125         if ( lifecycle.getId() != null )
126         {
127             serializer.startTag( NAMESPACE, "id" ).text( lifecycle.getId() ).endTag( NAMESPACE, "id" );
128         }
129         if ( ( lifecycle.getPhases() != null ) && ( lifecycle.getPhases().size() > 0 ) )
130         {
131             serializer.startTag( NAMESPACE, "phases" );
132             for ( Iterator iter = lifecycle.getPhases().iterator(); iter.hasNext(); )
133             {
134                 Phase o = (Phase) iter.next();
135                 writePhase( o, "phase", serializer );
136             }
137             serializer.endTag( NAMESPACE, "phases" );
138         }
139         serializer.endTag( NAMESPACE, tagName );
140     } //-- void writeLifecycle( Lifecycle, String, XmlSerializer )
141 
142     /**
143      * Method writeLifecycleConfiguration.
144      * 
145      * @param lifecycleConfiguration
146      * @param serializer
147      * @param tagName
148      * @throws java.io.IOException
149      */
150     private void writeLifecycleConfiguration( LifecycleConfiguration lifecycleConfiguration, String tagName, XmlSerializer serializer )
151         throws java.io.IOException
152     {
153         serializer.setPrefix( "", "http://maven.apache.org/LIFECYCLE/1.0.0" );
154         serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
155         serializer.startTag( NAMESPACE, tagName );
156         serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/LIFECYCLE/1.0.0 http://maven.apache.org/xsd/lifecycle-1.0.0.xsd" );
157         if ( ( lifecycleConfiguration.getLifecycles() != null ) && ( lifecycleConfiguration.getLifecycles().size() > 0 ) )
158         {
159             for ( Iterator iter = lifecycleConfiguration.getLifecycles().iterator(); iter.hasNext(); )
160             {
161                 Lifecycle o = (Lifecycle) iter.next();
162                 writeLifecycle( o, "lifecycle", serializer );
163             }
164         }
165         serializer.endTag( NAMESPACE, tagName );
166     } //-- void writeLifecycleConfiguration( LifecycleConfiguration, String, XmlSerializer )
167 
168     /**
169      * Method writePhase.
170      * 
171      * @param phase
172      * @param serializer
173      * @param tagName
174      * @throws java.io.IOException
175      */
176     private void writePhase( Phase phase, String tagName, XmlSerializer serializer )
177         throws java.io.IOException
178     {
179         serializer.startTag( NAMESPACE, tagName );
180         if ( phase.getId() != null )
181         {
182             serializer.startTag( NAMESPACE, "id" ).text( phase.getId() ).endTag( NAMESPACE, "id" );
183         }
184         if ( ( phase.getExecutions() != null ) && ( phase.getExecutions().size() > 0 ) )
185         {
186             serializer.startTag( NAMESPACE, "executions" );
187             for ( Iterator iter = phase.getExecutions().iterator(); iter.hasNext(); )
188             {
189                 Execution o = (Execution) iter.next();
190                 writeExecution( o, "execution", serializer );
191             }
192             serializer.endTag( NAMESPACE, "executions" );
193         }
194         if ( phase.getConfiguration() != null )
195         {
196             ((Xpp3Dom) phase.getConfiguration()).writeToSerializer( NAMESPACE, serializer );
197         }
198         serializer.endTag( NAMESPACE, tagName );
199     } //-- void writePhase( Phase, String, XmlSerializer )
200 
201 }