View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 1.8.3,
3   // any modifications will be overwritten.
4   // ==============================================================
5   
6   package org.apache.maven.toolchain.model.io.xpp3;
7   
8     //---------------------------------/
9    //- Imported classes and packages -/
10  //---------------------------------/
11  
12  import java.io.OutputStream;
13  import java.io.Writer;
14  import java.util.Iterator;
15  import org.apache.maven.toolchain.model.PersistedToolchains;
16  import org.apache.maven.toolchain.model.ToolchainModel;
17  import org.apache.maven.toolchain.model.TrackableBase;
18  import org.codehaus.plexus.util.xml.Xpp3Dom;
19  import org.codehaus.plexus.util.xml.pull.MXSerializer;
20  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
21  
22  /**
23   * Class MavenToolchainsXpp3Writer.
24   * 
25   * @version $Revision: 965443 $ $Date: 2015-09-14 15:18:52 -0700 (Mon, 14 Sep 2015) $
26   */
27  @SuppressWarnings( "all" )
28  public class MavenToolchainsXpp3Writer
29  {
30  
31        //--------------------------/
32       //- Class/Member Variables -/
33      //--------------------------/
34  
35      /**
36       * Field NAMESPACE.
37       */
38      private static final String NAMESPACE = null;
39  
40  
41        //-----------/
42       //- Methods -/
43      //-----------/
44  
45      /**
46       * Method write.
47       * 
48       * @param writer
49       * @param persistedToolchains
50       * @throws java.io.IOException
51       */
52      public void write( Writer writer, PersistedToolchains persistedToolchains )
53          throws java.io.IOException
54      {
55          XmlSerializer serializer = new MXSerializer();
56          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
57          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
58          serializer.setOutput( writer );
59          serializer.startDocument( persistedToolchains.getModelEncoding(), null );
60          writePersistedToolchains( persistedToolchains, "toolchains", serializer );
61          serializer.endDocument();
62      } //-- void write( Writer, PersistedToolchains )
63  
64      /**
65       * Method write.
66       * 
67       * @param stream
68       * @param persistedToolchains
69       * @throws java.io.IOException
70       */
71      public void write( OutputStream stream, PersistedToolchains persistedToolchains )
72          throws java.io.IOException
73      {
74          XmlSerializer serializer = new MXSerializer();
75          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
76          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
77          serializer.setOutput( stream, persistedToolchains.getModelEncoding() );
78          serializer.startDocument( persistedToolchains.getModelEncoding(), null );
79          writePersistedToolchains( persistedToolchains, "toolchains", serializer );
80          serializer.endDocument();
81      } //-- void write( OutputStream, PersistedToolchains )
82  
83      /**
84       * Method writePersistedToolchains.
85       * 
86       * @param persistedToolchains
87       * @param serializer
88       * @param tagName
89       * @throws java.io.IOException
90       */
91      private void writePersistedToolchains( PersistedToolchains persistedToolchains, String tagName, XmlSerializer serializer )
92          throws java.io.IOException
93      {
94          serializer.setPrefix( "", "http://maven.apache.org/TOOLCHAINS/1.1.0" );
95          serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
96          serializer.startTag( NAMESPACE, tagName );
97          serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/TOOLCHAINS/1.1.0 http://maven.apache.org/xsd/toolchains-1.1.0.xsd" );
98          if ( ( persistedToolchains.getToolchains() != null ) && ( persistedToolchains.getToolchains().size() > 0 ) )
99          {
100             for ( Iterator iter = persistedToolchains.getToolchains().iterator(); iter.hasNext(); )
101             {
102                 ToolchainModel o = (ToolchainModel) iter.next();
103                 writeToolchainModel( o, "toolchain", serializer );
104             }
105         }
106         serializer.endTag( NAMESPACE, tagName );
107     } //-- void writePersistedToolchains( PersistedToolchains, String, XmlSerializer )
108 
109     /**
110      * Method writeToolchainModel.
111      * 
112      * @param toolchainModel
113      * @param serializer
114      * @param tagName
115      * @throws java.io.IOException
116      */
117     private void writeToolchainModel( ToolchainModel toolchainModel, String tagName, XmlSerializer serializer )
118         throws java.io.IOException
119     {
120         serializer.startTag( NAMESPACE, tagName );
121         if ( toolchainModel.getType() != null )
122         {
123             serializer.startTag( NAMESPACE, "type" ).text( toolchainModel.getType() ).endTag( NAMESPACE, "type" );
124         }
125         if ( ( toolchainModel.getProvides() != null ) && ( toolchainModel.getProvides().size() > 0 ) )
126         {
127             serializer.startTag( NAMESPACE, "provides" );
128             for ( Iterator iter = toolchainModel.getProvides().keySet().iterator(); iter.hasNext(); )
129             {
130                 String key = (String) iter.next();
131                 String value = (String) toolchainModel.getProvides().get( key );
132                 serializer.startTag( NAMESPACE, "" + key + "" ).text( value ).endTag( NAMESPACE, "" + key + "" );
133             }
134             serializer.endTag( NAMESPACE, "provides" );
135         }
136         if ( toolchainModel.getConfiguration() != null )
137         {
138             ((Xpp3Dom) toolchainModel.getConfiguration()).writeToSerializer( NAMESPACE, serializer );
139         }
140         serializer.endTag( NAMESPACE, tagName );
141     } //-- void writeToolchainModel( ToolchainModel, String, XmlSerializer )
142 
143     /**
144      * Method writeTrackableBase.
145      * 
146      * @param trackableBase
147      * @param serializer
148      * @param tagName
149      * @throws java.io.IOException
150      */
151     private void writeTrackableBase( TrackableBase trackableBase, String tagName, XmlSerializer serializer )
152         throws java.io.IOException
153     {
154         serializer.startTag( NAMESPACE, tagName );
155         serializer.endTag( NAMESPACE, tagName );
156     } //-- void writeTrackableBase( TrackableBase, String, XmlSerializer )
157 
158 }