001    /*
002     =================== DO NOT EDIT THIS FILE ====================
003     Generated by Modello 1.4.1 on 2013-02-24 03:34:48,
004     any modifications will be overwritten.
005     ==============================================================
006     */
007    
008    package org.apache.maven.plugin.lifecycle.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.lifecycle.Execution;
020    import org.apache.maven.plugin.lifecycle.Lifecycle;
021    import org.apache.maven.plugin.lifecycle.LifecycleConfiguration;
022    import org.apache.maven.plugin.lifecycle.Phase;
023    import org.codehaus.plexus.util.xml.Xpp3Dom;
024    import org.codehaus.plexus.util.xml.pull.MXSerializer;
025    import org.codehaus.plexus.util.xml.pull.XmlSerializer;
026    
027    /**
028     * Class LifecycleMappingsXpp3Writer.
029     * 
030     * @version $Revision$ $Date$
031     */
032    @SuppressWarnings( "all" )
033    public class LifecycleMappingsXpp3Writer
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 lifecycleConfiguration
055         * @throws java.io.IOException
056         */
057        public void write( Writer writer, LifecycleConfiguration lifecycleConfiguration )
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( lifecycleConfiguration.getModelEncoding(), null );
065            writeLifecycleConfiguration( lifecycleConfiguration, "lifecycles", serializer );
066            serializer.endDocument();
067        } //-- void write( Writer, LifecycleConfiguration )
068    
069        /**
070         * Method write.
071         * 
072         * @param stream
073         * @param lifecycleConfiguration
074         * @throws java.io.IOException
075         */
076        public void write( OutputStream stream, LifecycleConfiguration lifecycleConfiguration )
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, lifecycleConfiguration.getModelEncoding() );
083            serializer.startDocument( lifecycleConfiguration.getModelEncoding(), null );
084            writeLifecycleConfiguration( lifecycleConfiguration, "lifecycles", serializer );
085            serializer.endDocument();
086        } //-- void write( OutputStream, LifecycleConfiguration )
087    
088        /**
089         * Method writeExecution.
090         * 
091         * @param execution
092         * @param serializer
093         * @param tagName
094         * @throws java.io.IOException
095         */
096        private void writeExecution( Execution execution, String tagName, XmlSerializer serializer )
097            throws java.io.IOException
098        {
099            serializer.startTag( NAMESPACE, tagName );
100            if ( execution.getConfiguration() != null )
101            {
102                ((Xpp3Dom) execution.getConfiguration()).writeToSerializer( NAMESPACE, serializer );
103            }
104            if ( ( execution.getGoals() != null ) && ( execution.getGoals().size() > 0 ) )
105            {
106                serializer.startTag( NAMESPACE, "goals" );
107                for ( Iterator iter = execution.getGoals().iterator(); iter.hasNext(); )
108                {
109                    String goal = (String) iter.next();
110                    serializer.startTag( NAMESPACE, "goal" ).text( goal ).endTag( NAMESPACE, "goal" );
111                }
112                serializer.endTag( NAMESPACE, "goals" );
113            }
114            serializer.endTag( NAMESPACE, tagName );
115        } //-- void writeExecution( Execution, String, XmlSerializer )
116    
117        /**
118         * Method writeLifecycle.
119         * 
120         * @param lifecycle
121         * @param serializer
122         * @param tagName
123         * @throws java.io.IOException
124         */
125        private void writeLifecycle( Lifecycle lifecycle, String tagName, XmlSerializer serializer )
126            throws java.io.IOException
127        {
128            serializer.startTag( NAMESPACE, tagName );
129            if ( lifecycle.getId() != null )
130            {
131                serializer.startTag( NAMESPACE, "id" ).text( lifecycle.getId() ).endTag( NAMESPACE, "id" );
132            }
133            if ( ( lifecycle.getPhases() != null ) && ( lifecycle.getPhases().size() > 0 ) )
134            {
135                serializer.startTag( NAMESPACE, "phases" );
136                for ( Iterator iter = lifecycle.getPhases().iterator(); iter.hasNext(); )
137                {
138                    Phase o = (Phase) iter.next();
139                    writePhase( o, "phase", serializer );
140                }
141                serializer.endTag( NAMESPACE, "phases" );
142            }
143            serializer.endTag( NAMESPACE, tagName );
144        } //-- void writeLifecycle( Lifecycle, String, XmlSerializer )
145    
146        /**
147         * Method writeLifecycleConfiguration.
148         * 
149         * @param lifecycleConfiguration
150         * @param serializer
151         * @param tagName
152         * @throws java.io.IOException
153         */
154        private void writeLifecycleConfiguration( LifecycleConfiguration lifecycleConfiguration, String tagName, XmlSerializer serializer )
155            throws java.io.IOException
156        {
157            serializer.setPrefix( "", "http://maven.apache.org/LIFECYCLE/1.0.0" );
158            serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
159            serializer.startTag( NAMESPACE, tagName );
160            serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/LIFECYCLE/1.0.0 http://maven.apache.org/xsd/lifecycle-1.0.0.xsd" );
161            if ( ( lifecycleConfiguration.getLifecycles() != null ) && ( lifecycleConfiguration.getLifecycles().size() > 0 ) )
162            {
163                for ( Iterator iter = lifecycleConfiguration.getLifecycles().iterator(); iter.hasNext(); )
164                {
165                    Lifecycle o = (Lifecycle) iter.next();
166                    writeLifecycle( o, "lifecycle", serializer );
167                }
168            }
169            serializer.endTag( NAMESPACE, tagName );
170        } //-- void writeLifecycleConfiguration( LifecycleConfiguration, String, XmlSerializer )
171    
172        /**
173         * Method writePhase.
174         * 
175         * @param phase
176         * @param serializer
177         * @param tagName
178         * @throws java.io.IOException
179         */
180        private void writePhase( Phase phase, String tagName, XmlSerializer serializer )
181            throws java.io.IOException
182        {
183            serializer.startTag( NAMESPACE, tagName );
184            if ( phase.getId() != null )
185            {
186                serializer.startTag( NAMESPACE, "id" ).text( phase.getId() ).endTag( NAMESPACE, "id" );
187            }
188            if ( ( phase.getExecutions() != null ) && ( phase.getExecutions().size() > 0 ) )
189            {
190                serializer.startTag( NAMESPACE, "executions" );
191                for ( Iterator iter = phase.getExecutions().iterator(); iter.hasNext(); )
192                {
193                    Execution o = (Execution) iter.next();
194                    writeExecution( o, "execution", serializer );
195                }
196                serializer.endTag( NAMESPACE, "executions" );
197            }
198            if ( phase.getConfiguration() != null )
199            {
200                ((Xpp3Dom) phase.getConfiguration()).writeToSerializer( NAMESPACE, serializer );
201            }
202            serializer.endTag( NAMESPACE, tagName );
203        } //-- void writePhase( Phase, String, XmlSerializer )
204    
205    }