001// =================== DO NOT EDIT THIS FILE ====================
002// Generated by Modello 1.8.3,
003// any modifications will be overwritten.
004// ==============================================================
005
006package org.apache.maven.plugin.lifecycle.io.xpp3;
007
008  //---------------------------------/
009 //- Imported classes and packages -/
010//---------------------------------/
011
012import java.io.OutputStream;
013import java.io.Writer;
014import java.util.Iterator;
015import org.apache.maven.plugin.lifecycle.Execution;
016import org.apache.maven.plugin.lifecycle.Lifecycle;
017import org.apache.maven.plugin.lifecycle.LifecycleConfiguration;
018import org.apache.maven.plugin.lifecycle.Phase;
019import org.codehaus.plexus.util.xml.Xpp3Dom;
020import org.codehaus.plexus.util.xml.pull.MXSerializer;
021import org.codehaus.plexus.util.xml.pull.XmlSerializer;
022
023/**
024 * Class LifecycleMappingsXpp3Writer.
025 * 
026 * @version $Revision$ $Date$
027 */
028@SuppressWarnings( "all" )
029public class LifecycleMappingsXpp3Writer
030{
031
032      //--------------------------/
033     //- Class/Member Variables -/
034    //--------------------------/
035
036    /**
037     * Field NAMESPACE.
038     */
039    private static final String NAMESPACE = null;
040
041
042      //-----------/
043     //- Methods -/
044    //-----------/
045
046    /**
047     * Method write.
048     * 
049     * @param writer
050     * @param lifecycleConfiguration
051     * @throws java.io.IOException
052     */
053    public void write( Writer writer, LifecycleConfiguration lifecycleConfiguration )
054        throws java.io.IOException
055    {
056        XmlSerializer serializer = new MXSerializer();
057        serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
058        serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
059        serializer.setOutput( writer );
060        serializer.startDocument( lifecycleConfiguration.getModelEncoding(), null );
061        writeLifecycleConfiguration( lifecycleConfiguration, "lifecycles", serializer );
062        serializer.endDocument();
063    } //-- void write( Writer, LifecycleConfiguration )
064
065    /**
066     * Method write.
067     * 
068     * @param stream
069     * @param lifecycleConfiguration
070     * @throws java.io.IOException
071     */
072    public void write( OutputStream stream, LifecycleConfiguration lifecycleConfiguration )
073        throws java.io.IOException
074    {
075        XmlSerializer serializer = new MXSerializer();
076        serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
077        serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
078        serializer.setOutput( stream, lifecycleConfiguration.getModelEncoding() );
079        serializer.startDocument( lifecycleConfiguration.getModelEncoding(), null );
080        writeLifecycleConfiguration( lifecycleConfiguration, "lifecycles", serializer );
081        serializer.endDocument();
082    } //-- void write( OutputStream, LifecycleConfiguration )
083
084    /**
085     * Method writeExecution.
086     * 
087     * @param execution
088     * @param serializer
089     * @param tagName
090     * @throws java.io.IOException
091     */
092    private void writeExecution( Execution execution, String tagName, XmlSerializer serializer )
093        throws java.io.IOException
094    {
095        serializer.startTag( NAMESPACE, tagName );
096        if ( execution.getConfiguration() != null )
097        {
098            ((Xpp3Dom) execution.getConfiguration()).writeToSerializer( NAMESPACE, serializer );
099        }
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}