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.toolchain.model.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.toolchain.model.PersistedToolchains; 016import org.apache.maven.toolchain.model.ToolchainModel; 017import org.apache.maven.toolchain.model.TrackableBase; 018import org.codehaus.plexus.util.xml.Xpp3Dom; 019import org.codehaus.plexus.util.xml.pull.MXSerializer; 020import org.codehaus.plexus.util.xml.pull.XmlSerializer; 021 022/** 023 * Class MavenToolchainsXpp3Writer. 024 * 025 * @version $Revision: 965443 $ $Date: 2015-09-14 22:18:52 +0000 (Mon, 14 Sep 2015) $ 026 */ 027@SuppressWarnings( "all" ) 028public class MavenToolchainsXpp3Writer 029{ 030 031 //--------------------------/ 032 //- Class/Member Variables -/ 033 //--------------------------/ 034 035 /** 036 * Field NAMESPACE. 037 */ 038 private static final String NAMESPACE = null; 039 040 041 //-----------/ 042 //- Methods -/ 043 //-----------/ 044 045 /** 046 * Method write. 047 * 048 * @param writer 049 * @param persistedToolchains 050 * @throws java.io.IOException 051 */ 052 public void write( Writer writer, PersistedToolchains persistedToolchains ) 053 throws java.io.IOException 054 { 055 XmlSerializer serializer = new MXSerializer(); 056 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); 057 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); 058 serializer.setOutput( writer ); 059 serializer.startDocument( persistedToolchains.getModelEncoding(), null ); 060 writePersistedToolchains( persistedToolchains, "toolchains", serializer ); 061 serializer.endDocument(); 062 } //-- void write( Writer, PersistedToolchains ) 063 064 /** 065 * Method write. 066 * 067 * @param stream 068 * @param persistedToolchains 069 * @throws java.io.IOException 070 */ 071 public void write( OutputStream stream, PersistedToolchains persistedToolchains ) 072 throws java.io.IOException 073 { 074 XmlSerializer serializer = new MXSerializer(); 075 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); 076 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); 077 serializer.setOutput( stream, persistedToolchains.getModelEncoding() ); 078 serializer.startDocument( persistedToolchains.getModelEncoding(), null ); 079 writePersistedToolchains( persistedToolchains, "toolchains", serializer ); 080 serializer.endDocument(); 081 } //-- void write( OutputStream, PersistedToolchains ) 082 083 /** 084 * Method writePersistedToolchains. 085 * 086 * @param persistedToolchains 087 * @param serializer 088 * @param tagName 089 * @throws java.io.IOException 090 */ 091 private void writePersistedToolchains( PersistedToolchains persistedToolchains, String tagName, XmlSerializer serializer ) 092 throws java.io.IOException 093 { 094 serializer.setPrefix( "", "http://maven.apache.org/TOOLCHAINS/1.1.0" ); 095 serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" ); 096 serializer.startTag( NAMESPACE, tagName ); 097 serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/TOOLCHAINS/1.1.0 http://maven.apache.org/xsd/toolchains-1.1.0.xsd" ); 098 if ( ( persistedToolchains.getToolchains() != null ) && ( persistedToolchains.getToolchains().size() > 0 ) ) 099 { 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}