001    /*
002     =================== DO NOT EDIT THIS FILE ====================
003     Generated by Modello 1.4.1 on 2012-05-28 13:00:08,
004     any modifications will be overwritten.
005     ==============================================================
006     */
007    
008    package org.apache.maven.plugin.tools.model.io.xpp3;
009    
010      //---------------------------------/
011     //- Imported classes and packages -/
012    //---------------------------------/
013    
014    import java.io.OutputStream;
015    import java.io.Writer;
016    import java.text.DateFormat;
017    import java.util.Iterator;
018    import java.util.Locale;
019    import org.apache.maven.plugin.tools.model.Component;
020    import org.apache.maven.plugin.tools.model.LifecycleExecution;
021    import org.apache.maven.plugin.tools.model.Mojo;
022    import org.apache.maven.plugin.tools.model.Parameter;
023    import org.apache.maven.plugin.tools.model.PluginMetadata;
024    import org.codehaus.plexus.util.xml.pull.MXSerializer;
025    import org.codehaus.plexus.util.xml.pull.XmlSerializer;
026    
027    /**
028     * Class PluginMetadataXpp3Writer.
029     * 
030     * @version $Revision$ $Date$
031     */
032    @SuppressWarnings( "all" )
033    public class PluginMetadataXpp3Writer
034    {
035    
036          //--------------------------/
037         //- Class/Member Variables -/
038        //--------------------------/
039    
040        /**
041         * Field NAMESPACE.
042         */
043        private static final String NAMESPACE = null;
044    
045    
046          //-----------/
047         //- Methods -/
048        //-----------/
049    
050        /**
051         * Method write.
052         * 
053         * @param writer
054         * @param pluginMetadata
055         * @throws java.io.IOException
056         */
057        public void write( Writer writer, PluginMetadata pluginMetadata )
058            throws java.io.IOException
059        {
060            XmlSerializer serializer = new MXSerializer();
061            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
062            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
063            serializer.setOutput( writer );
064            serializer.startDocument( pluginMetadata.getModelEncoding(), null );
065            writePluginMetadata( pluginMetadata, "pluginMetadata", serializer );
066            serializer.endDocument();
067        } //-- void write( Writer, PluginMetadata )
068    
069        /**
070         * Method write.
071         * 
072         * @param stream
073         * @param pluginMetadata
074         * @throws java.io.IOException
075         */
076        public void write( OutputStream stream, PluginMetadata pluginMetadata )
077            throws java.io.IOException
078        {
079            XmlSerializer serializer = new MXSerializer();
080            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
081            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
082            serializer.setOutput( stream, pluginMetadata.getModelEncoding() );
083            serializer.startDocument( pluginMetadata.getModelEncoding(), null );
084            writePluginMetadata( pluginMetadata, "pluginMetadata", serializer );
085            serializer.endDocument();
086        } //-- void write( OutputStream, PluginMetadata )
087    
088        /**
089         * Method writeComponent.
090         * 
091         * @param component
092         * @param serializer
093         * @param tagName
094         * @throws java.io.IOException
095         */
096        private void writeComponent( Component component, String tagName, XmlSerializer serializer )
097            throws java.io.IOException
098        {
099            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.getCall() != null )
219            {
220                serializer.startTag( NAMESPACE, "call" ).text( mojo.getCall() ).endTag( NAMESPACE, "call" );
221            }
222            serializer.endTag( NAMESPACE, tagName );
223        } //-- void writeMojo( Mojo, String, XmlSerializer )
224    
225        /**
226         * Method writeParameter.
227         * 
228         * @param parameter
229         * @param serializer
230         * @param tagName
231         * @throws java.io.IOException
232         */
233        private void writeParameter( Parameter parameter, String tagName, XmlSerializer serializer )
234            throws java.io.IOException
235        {
236            serializer.startTag( NAMESPACE, tagName );
237            if ( parameter.getName() != null )
238            {
239                serializer.startTag( NAMESPACE, "name" ).text( parameter.getName() ).endTag( NAMESPACE, "name" );
240            }
241            if ( parameter.getAlias() != null )
242            {
243                serializer.startTag( NAMESPACE, "alias" ).text( parameter.getAlias() ).endTag( NAMESPACE, "alias" );
244            }
245            if ( parameter.getProperty() != null )
246            {
247                serializer.startTag( NAMESPACE, "property" ).text( parameter.getProperty() ).endTag( NAMESPACE, "property" );
248            }
249            if ( parameter.isRequired() != false )
250            {
251                serializer.startTag( NAMESPACE, "required" ).text( String.valueOf( parameter.isRequired() ) ).endTag( NAMESPACE, "required" );
252            }
253            if ( parameter.isReadonly() != false )
254            {
255                serializer.startTag( NAMESPACE, "readonly" ).text( String.valueOf( parameter.isReadonly() ) ).endTag( NAMESPACE, "readonly" );
256            }
257            if ( parameter.getExpression() != null )
258            {
259                serializer.startTag( NAMESPACE, "expression" ).text( parameter.getExpression() ).endTag( NAMESPACE, "expression" );
260            }
261            if ( parameter.getDefaultValue() != null )
262            {
263                serializer.startTag( NAMESPACE, "defaultValue" ).text( parameter.getDefaultValue() ).endTag( NAMESPACE, "defaultValue" );
264            }
265            if ( parameter.getType() != null )
266            {
267                serializer.startTag( NAMESPACE, "type" ).text( parameter.getType() ).endTag( NAMESPACE, "type" );
268            }
269            if ( parameter.getDescription() != null )
270            {
271                serializer.startTag( NAMESPACE, "description" ).text( parameter.getDescription() ).endTag( NAMESPACE, "description" );
272            }
273            if ( parameter.getDeprecation() != null )
274            {
275                serializer.startTag( NAMESPACE, "deprecated" ).text( parameter.getDeprecation() ).endTag( NAMESPACE, "deprecated" );
276            }
277            serializer.endTag( NAMESPACE, tagName );
278        } //-- void writeParameter( Parameter, String, XmlSerializer )
279    
280        /**
281         * Method writePluginMetadata.
282         * 
283         * @param pluginMetadata
284         * @param serializer
285         * @param tagName
286         * @throws java.io.IOException
287         */
288        private void writePluginMetadata( PluginMetadata pluginMetadata, String tagName, XmlSerializer serializer )
289            throws java.io.IOException
290        {
291            serializer.startTag( NAMESPACE, tagName );
292            if ( ( pluginMetadata.getMojos() != null ) && ( pluginMetadata.getMojos().size() > 0 ) )
293            {
294                serializer.startTag( NAMESPACE, "mojos" );
295                for ( Iterator iter = pluginMetadata.getMojos().iterator(); iter.hasNext(); )
296                {
297                    Mojo o = (Mojo) iter.next();
298                    writeMojo( o, "mojo", serializer );
299                }
300                serializer.endTag( NAMESPACE, "mojos" );
301            }
302            serializer.endTag( NAMESPACE, tagName );
303        } //-- void writePluginMetadata( PluginMetadata, String, XmlSerializer )
304    
305    }