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