View Javadoc

1   /*
2    =================== DO NOT EDIT THIS FILE ====================
3    Generated by Modello 1.4.1 on 2012-11-07 17:28:30,
4    any modifications will be overwritten.
5    ==============================================================
6    */
7   
8   package org.apache.maven.plugin.tools.model.io.xpp3;
9   
10    //---------------------------------/
11   //- Imported classes and packages -/
12  //---------------------------------/
13  
14  import java.io.OutputStream;
15  import java.io.Writer;
16  import java.text.DateFormat;
17  import java.util.Iterator;
18  import java.util.Locale;
19  import org.apache.maven.plugin.tools.model.Component;
20  import org.apache.maven.plugin.tools.model.LifecycleExecution;
21  import org.apache.maven.plugin.tools.model.Mojo;
22  import org.apache.maven.plugin.tools.model.Parameter;
23  import org.apache.maven.plugin.tools.model.PluginMetadata;
24  import org.codehaus.plexus.util.xml.pull.MXSerializer;
25  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
26  
27  /**
28   * Class PluginMetadataXpp3Writer.
29   * 
30   * @version $Revision$ $Date$
31   */
32  @SuppressWarnings( "all" )
33  public class PluginMetadataXpp3Writer
34  {
35  
36        //--------------------------/
37       //- Class/Member Variables -/
38      //--------------------------/
39  
40      /**
41       * Field NAMESPACE.
42       */
43      private static final String NAMESPACE = null;
44  
45  
46        //-----------/
47       //- Methods -/
48      //-----------/
49  
50      /**
51       * Method write.
52       * 
53       * @param writer
54       * @param pluginMetadata
55       * @throws java.io.IOException
56       */
57      public void write( Writer writer, PluginMetadata pluginMetadata )
58          throws java.io.IOException
59      {
60          XmlSerializer serializer = new MXSerializer();
61          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
62          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
63          serializer.setOutput( writer );
64          serializer.startDocument( pluginMetadata.getModelEncoding(), null );
65          writePluginMetadata( pluginMetadata, "pluginMetadata", serializer );
66          serializer.endDocument();
67      } //-- void write( Writer, PluginMetadata )
68  
69      /**
70       * Method write.
71       * 
72       * @param stream
73       * @param pluginMetadata
74       * @throws java.io.IOException
75       */
76      public void write( OutputStream stream, PluginMetadata pluginMetadata )
77          throws java.io.IOException
78      {
79          XmlSerializer serializer = new MXSerializer();
80          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
81          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
82          serializer.setOutput( stream, pluginMetadata.getModelEncoding() );
83          serializer.startDocument( pluginMetadata.getModelEncoding(), null );
84          writePluginMetadata( pluginMetadata, "pluginMetadata", serializer );
85          serializer.endDocument();
86      } //-- void write( OutputStream, PluginMetadata )
87  
88      /**
89       * Method writeComponent.
90       * 
91       * @param component
92       * @param serializer
93       * @param tagName
94       * @throws java.io.IOException
95       */
96      private void writeComponent( Component component, String tagName, XmlSerializer serializer )
97          throws java.io.IOException
98      {
99          serializer.startTag( NAMESPACE, tagName );
100         if ( component.getRole() != null )
101         {
102             serializer.startTag( NAMESPACE, "role" ).text( component.getRole() ).endTag( NAMESPACE, "role" );
103         }
104         if ( component.getHint() != null )
105         {
106             serializer.startTag( NAMESPACE, "hint" ).text( component.getHint() ).endTag( NAMESPACE, "hint" );
107         }
108         serializer.endTag( NAMESPACE, tagName );
109     } //-- void writeComponent( Component, String, XmlSerializer )
110 
111     /**
112      * Method writeLifecycleExecution.
113      * 
114      * @param lifecycleExecution
115      * @param serializer
116      * @param tagName
117      * @throws java.io.IOException
118      */
119     private void writeLifecycleExecution( LifecycleExecution lifecycleExecution, String tagName, XmlSerializer serializer )
120         throws java.io.IOException
121     {
122         serializer.startTag( NAMESPACE, tagName );
123         if ( lifecycleExecution.getLifecycle() != null )
124         {
125             serializer.startTag( NAMESPACE, "lifecycle" ).text( lifecycleExecution.getLifecycle() ).endTag( NAMESPACE, "lifecycle" );
126         }
127         if ( lifecycleExecution.getPhase() != null )
128         {
129             serializer.startTag( NAMESPACE, "phase" ).text( lifecycleExecution.getPhase() ).endTag( NAMESPACE, "phase" );
130         }
131         if ( lifecycleExecution.getGoal() != null )
132         {
133             serializer.startTag( NAMESPACE, "goal" ).text( lifecycleExecution.getGoal() ).endTag( NAMESPACE, "goal" );
134         }
135         serializer.endTag( NAMESPACE, tagName );
136     } //-- void writeLifecycleExecution( LifecycleExecution, String, XmlSerializer )
137 
138     /**
139      * Method writeMojo.
140      * 
141      * @param mojo
142      * @param serializer
143      * @param tagName
144      * @throws java.io.IOException
145      */
146     private void writeMojo( Mojo mojo, String tagName, XmlSerializer serializer )
147         throws java.io.IOException
148     {
149         serializer.startTag( NAMESPACE, tagName );
150         if ( mojo.getGoal() != null )
151         {
152             serializer.startTag( NAMESPACE, "goal" ).text( mojo.getGoal() ).endTag( NAMESPACE, "goal" );
153         }
154         if ( mojo.getPhase() != null )
155         {
156             serializer.startTag( NAMESPACE, "phase" ).text( mojo.getPhase() ).endTag( NAMESPACE, "phase" );
157         }
158         if ( mojo.isAggregator() != false )
159         {
160             serializer.startTag( NAMESPACE, "aggregator" ).text( String.valueOf( mojo.isAggregator() ) ).endTag( NAMESPACE, "aggregator" );
161         }
162         if ( mojo.getRequiresDependencyResolution() != null )
163         {
164             serializer.startTag( NAMESPACE, "requiresDependencyResolution" ).text( mojo.getRequiresDependencyResolution() ).endTag( NAMESPACE, "requiresDependencyResolution" );
165         }
166         if ( mojo.isRequiresProject() != false )
167         {
168             serializer.startTag( NAMESPACE, "requiresProject" ).text( String.valueOf( mojo.isRequiresProject() ) ).endTag( NAMESPACE, "requiresProject" );
169         }
170         if ( mojo.isRequiresReports() != false )
171         {
172             serializer.startTag( NAMESPACE, "requiresReports" ).text( String.valueOf( mojo.isRequiresReports() ) ).endTag( NAMESPACE, "requiresReports" );
173         }
174         if ( mojo.isRequiresOnline() != false )
175         {
176             serializer.startTag( NAMESPACE, "requiresOnline" ).text( String.valueOf( mojo.isRequiresOnline() ) ).endTag( NAMESPACE, "requiresOnline" );
177         }
178         if ( mojo.isInheritByDefault() != false )
179         {
180             serializer.startTag( NAMESPACE, "inheritByDefault" ).text( String.valueOf( mojo.isInheritByDefault() ) ).endTag( NAMESPACE, "inheritByDefault" );
181         }
182         if ( mojo.isRequiresDirectInvocation() != false )
183         {
184             serializer.startTag( NAMESPACE, "requiresDirectInvocation" ).text( String.valueOf( mojo.isRequiresDirectInvocation() ) ).endTag( NAMESPACE, "requiresDirectInvocation" );
185         }
186         if ( mojo.getExecution() != null )
187         {
188             writeLifecycleExecution( (LifecycleExecution) mojo.getExecution(), "execution", serializer );
189         }
190         if ( ( mojo.getComponents() != null ) && ( mojo.getComponents().size() > 0 ) )
191         {
192             serializer.startTag( NAMESPACE, "components" );
193             for ( Iterator iter = mojo.getComponents().iterator(); iter.hasNext(); )
194             {
195                 Component o = (Component) iter.next();
196                 writeComponent( o, "component", serializer );
197             }
198             serializer.endTag( NAMESPACE, "components" );
199         }
200         if ( ( mojo.getParameters() != null ) && ( mojo.getParameters().size() > 0 ) )
201         {
202             serializer.startTag( NAMESPACE, "parameters" );
203             for ( Iterator iter = mojo.getParameters().iterator(); iter.hasNext(); )
204             {
205                 Parameter o = (Parameter) iter.next();
206                 writeParameter( o, "parameter", serializer );
207             }
208             serializer.endTag( NAMESPACE, "parameters" );
209         }
210         if ( mojo.getDescription() != null )
211         {
212             serializer.startTag( NAMESPACE, "description" ).text( mojo.getDescription() ).endTag( NAMESPACE, "description" );
213         }
214         if ( mojo.getDeprecation() != null )
215         {
216             serializer.startTag( NAMESPACE, "deprecated" ).text( mojo.getDeprecation() ).endTag( NAMESPACE, "deprecated" );
217         }
218         if ( mojo.getSince() != null )
219         {
220             serializer.startTag( NAMESPACE, "since" ).text( mojo.getSince() ).endTag( NAMESPACE, "since" );
221         }
222         if ( mojo.getCall() != null )
223         {
224             serializer.startTag( NAMESPACE, "call" ).text( mojo.getCall() ).endTag( NAMESPACE, "call" );
225         }
226         serializer.endTag( NAMESPACE, tagName );
227     } //-- void writeMojo( Mojo, String, XmlSerializer )
228 
229     /**
230      * Method writeParameter.
231      * 
232      * @param parameter
233      * @param serializer
234      * @param tagName
235      * @throws java.io.IOException
236      */
237     private void writeParameter( Parameter parameter, String tagName, XmlSerializer serializer )
238         throws java.io.IOException
239     {
240         serializer.startTag( NAMESPACE, tagName );
241         if ( parameter.getName() != null )
242         {
243             serializer.startTag( NAMESPACE, "name" ).text( parameter.getName() ).endTag( NAMESPACE, "name" );
244         }
245         if ( parameter.getAlias() != null )
246         {
247             serializer.startTag( NAMESPACE, "alias" ).text( parameter.getAlias() ).endTag( NAMESPACE, "alias" );
248         }
249         if ( parameter.getProperty() != null )
250         {
251             serializer.startTag( NAMESPACE, "property" ).text( parameter.getProperty() ).endTag( NAMESPACE, "property" );
252         }
253         if ( parameter.isRequired() != false )
254         {
255             serializer.startTag( NAMESPACE, "required" ).text( String.valueOf( parameter.isRequired() ) ).endTag( NAMESPACE, "required" );
256         }
257         if ( parameter.isReadonly() != false )
258         {
259             serializer.startTag( NAMESPACE, "readonly" ).text( String.valueOf( parameter.isReadonly() ) ).endTag( NAMESPACE, "readonly" );
260         }
261         if ( parameter.getExpression() != null )
262         {
263             serializer.startTag( NAMESPACE, "expression" ).text( parameter.getExpression() ).endTag( NAMESPACE, "expression" );
264         }
265         if ( parameter.getDefaultValue() != null )
266         {
267             serializer.startTag( NAMESPACE, "defaultValue" ).text( parameter.getDefaultValue() ).endTag( NAMESPACE, "defaultValue" );
268         }
269         if ( parameter.getType() != null )
270         {
271             serializer.startTag( NAMESPACE, "type" ).text( parameter.getType() ).endTag( NAMESPACE, "type" );
272         }
273         if ( parameter.getDescription() != null )
274         {
275             serializer.startTag( NAMESPACE, "description" ).text( parameter.getDescription() ).endTag( NAMESPACE, "description" );
276         }
277         if ( parameter.getDeprecation() != null )
278         {
279             serializer.startTag( NAMESPACE, "deprecated" ).text( parameter.getDeprecation() ).endTag( NAMESPACE, "deprecated" );
280         }
281         if ( parameter.getSince() != null )
282         {
283             serializer.startTag( NAMESPACE, "since" ).text( parameter.getSince() ).endTag( NAMESPACE, "since" );
284         }
285         serializer.endTag( NAMESPACE, tagName );
286     } //-- void writeParameter( Parameter, String, XmlSerializer )
287 
288     /**
289      * Method writePluginMetadata.
290      * 
291      * @param pluginMetadata
292      * @param serializer
293      * @param tagName
294      * @throws java.io.IOException
295      */
296     private void writePluginMetadata( PluginMetadata pluginMetadata, String tagName, XmlSerializer serializer )
297         throws java.io.IOException
298     {
299         serializer.startTag( NAMESPACE, tagName );
300         if ( ( pluginMetadata.getMojos() != null ) && ( pluginMetadata.getMojos().size() > 0 ) )
301         {
302             serializer.startTag( NAMESPACE, "mojos" );
303             for ( Iterator iter = pluginMetadata.getMojos().iterator(); iter.hasNext(); )
304             {
305                 Mojo o = (Mojo) iter.next();
306                 writeMojo( o, "mojo", serializer );
307             }
308             serializer.endTag( NAMESPACE, "mojos" );
309         }
310         serializer.endTag( NAMESPACE, tagName );
311     } //-- void writePluginMetadata( PluginMetadata, String, XmlSerializer )
312 
313 }