001    /*
002     =================== DO NOT EDIT THIS FILE ====================
003     Generated by Modello 1.4.1 on 2013-02-24 03:31:05,
004     any modifications will be overwritten.
005     ==============================================================
006     */
007    
008    package org.apache.maven.toolchain.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.toolchain.model.PersistedToolchains;
020    import org.apache.maven.toolchain.model.ToolchainModel;
021    import org.codehaus.plexus.util.xml.Xpp3Dom;
022    import org.codehaus.plexus.util.xml.pull.MXSerializer;
023    import org.codehaus.plexus.util.xml.pull.XmlSerializer;
024    
025    /**
026     * Class MavenToolchainsXpp3Writer.
027     * 
028     * @version $Revision$ $Date$
029     */
030    @SuppressWarnings( "all" )
031    public class MavenToolchainsXpp3Writer
032    {
033    
034          //--------------------------/
035         //- Class/Member Variables -/
036        //--------------------------/
037    
038        /**
039         * Field NAMESPACE.
040         */
041        private static final String NAMESPACE = null;
042    
043    
044          //-----------/
045         //- Methods -/
046        //-----------/
047    
048        /**
049         * Method write.
050         * 
051         * @param writer
052         * @param persistedToolchains
053         * @throws java.io.IOException
054         */
055        public void write( Writer writer, PersistedToolchains persistedToolchains )
056            throws java.io.IOException
057        {
058            XmlSerializer serializer = new MXSerializer();
059            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
060            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
061            serializer.setOutput( writer );
062            serializer.startDocument( persistedToolchains.getModelEncoding(), null );
063            writePersistedToolchains( persistedToolchains, "toolchains", serializer );
064            serializer.endDocument();
065        } //-- void write( Writer, PersistedToolchains )
066    
067        /**
068         * Method write.
069         * 
070         * @param stream
071         * @param persistedToolchains
072         * @throws java.io.IOException
073         */
074        public void write( OutputStream stream, PersistedToolchains persistedToolchains )
075            throws java.io.IOException
076        {
077            XmlSerializer serializer = new MXSerializer();
078            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
079            serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
080            serializer.setOutput( stream, persistedToolchains.getModelEncoding() );
081            serializer.startDocument( persistedToolchains.getModelEncoding(), null );
082            writePersistedToolchains( persistedToolchains, "toolchains", serializer );
083            serializer.endDocument();
084        } //-- void write( OutputStream, PersistedToolchains )
085    
086        /**
087         * Method writePersistedToolchains.
088         * 
089         * @param persistedToolchains
090         * @param serializer
091         * @param tagName
092         * @throws java.io.IOException
093         */
094        private void writePersistedToolchains( PersistedToolchains persistedToolchains, String tagName, XmlSerializer serializer )
095            throws java.io.IOException
096        {
097            serializer.setPrefix( "", "http://maven.apache.org/TOOLCHAINS/1.0.0" );
098            serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
099            serializer.startTag( NAMESPACE, tagName );
100            serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/TOOLCHAINS/1.0.0 http://maven.apache.org/xsd/toolchains-1.0.0.xsd" );
101            if ( ( persistedToolchains.getToolchains() != null ) && ( persistedToolchains.getToolchains().size() > 0 ) )
102            {
103                for ( Iterator iter = persistedToolchains.getToolchains().iterator(); iter.hasNext(); )
104                {
105                    ToolchainModel o = (ToolchainModel) iter.next();
106                    writeToolchainModel( o, "toolchain", serializer );
107                }
108            }
109            serializer.endTag( NAMESPACE, tagName );
110        } //-- void writePersistedToolchains( PersistedToolchains, String, XmlSerializer )
111    
112        /**
113         * Method writeToolchainModel.
114         * 
115         * @param toolchainModel
116         * @param serializer
117         * @param tagName
118         * @throws java.io.IOException
119         */
120        private void writeToolchainModel( ToolchainModel toolchainModel, String tagName, XmlSerializer serializer )
121            throws java.io.IOException
122        {
123            serializer.startTag( NAMESPACE, tagName );
124            if ( toolchainModel.getType() != null )
125            {
126                serializer.startTag( NAMESPACE, "type" ).text( toolchainModel.getType() ).endTag( NAMESPACE, "type" );
127            }
128            if ( toolchainModel.getProvides() != null )
129            {
130                ((Xpp3Dom) toolchainModel.getProvides()).writeToSerializer( NAMESPACE, serializer );
131            }
132            if ( toolchainModel.getConfiguration() != null )
133            {
134                ((Xpp3Dom) toolchainModel.getConfiguration()).writeToSerializer( NAMESPACE, serializer );
135            }
136            serializer.endTag( NAMESPACE, tagName );
137        } //-- void writeToolchainModel( ToolchainModel, String, XmlSerializer )
138    
139    }