001/* 002 =================== DO NOT EDIT THIS FILE ==================== 003 004 Generated by Modello 2.4.0, 005 006 any modifications will be overwritten. 007 008 ============================================================== 009 */ 010 011package org.apache.maven.tools.plugin.extractor.model.io.xpp3; 012 013 //---------------------------------/ 014 //- Imported classes and packages -/ 015//---------------------------------/ 016 017import java.io.OutputStream; 018import java.io.Writer; 019import java.util.Iterator; 020import org.apache.maven.tools.plugin.extractor.model.Component; 021import org.apache.maven.tools.plugin.extractor.model.LifecycleExecution; 022import org.apache.maven.tools.plugin.extractor.model.Mojo; 023import org.apache.maven.tools.plugin.extractor.model.Parameter; 024import org.apache.maven.tools.plugin.extractor.model.PluginMetadata; 025import org.codehaus.plexus.util.xml.pull.MXSerializer; 026import org.codehaus.plexus.util.xml.pull.XmlSerializer; 027 028/** 029 * Class PluginMetadataXpp3Writer. 030 * 031 * @version $Revision$ $Date$ 032 */ 033@SuppressWarnings( "all" ) 034public class PluginMetadataXpp3Writer 035{ 036 037 //--------------------------/ 038 //- Class/Member Variables -/ 039 //--------------------------/ 040 041 /** 042 * Field NAMESPACE. 043 */ 044 private static final String NAMESPACE = null; 045 046 /** 047 * Field fileComment. 048 */ 049 private String fileComment = null; 050 051 052 //-----------/ 053 //- Methods -/ 054 //-----------/ 055 056 /** 057 * Method setFileComment. 058 * 059 * @param fileComment a fileComment object. 060 */ 061 public void setFileComment( String fileComment ) 062 { 063 this.fileComment = fileComment; 064 } //-- void setFileComment( String ) 065 066 /** 067 * Method write. 068 * 069 * @param writer a writer object. 070 * @param pluginMetadata a pluginMetadata object. 071 * @throws java.io.IOException java.io.IOException if any. 072 */ 073 public void write( Writer writer, PluginMetadata pluginMetadata ) 074 throws java.io.IOException 075 { 076 XmlSerializer serializer = new MXSerializer(); 077 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); 078 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); 079 serializer.setOutput( writer ); 080 serializer.startDocument( pluginMetadata.getModelEncoding(), null ); 081 writePluginMetadata( pluginMetadata, "pluginMetadata", serializer ); 082 serializer.endDocument(); 083 } //-- void write( Writer, PluginMetadata ) 084 085 /** 086 * Method write. 087 * 088 * @param stream a stream object. 089 * @param pluginMetadata a pluginMetadata object. 090 * @throws java.io.IOException java.io.IOException if any. 091 */ 092 public void write( OutputStream stream, PluginMetadata pluginMetadata ) 093 throws java.io.IOException 094 { 095 XmlSerializer serializer = new MXSerializer(); 096 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); 097 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); 098 serializer.setOutput( stream, pluginMetadata.getModelEncoding() ); 099 serializer.startDocument( pluginMetadata.getModelEncoding(), null ); 100 writePluginMetadata( pluginMetadata, "pluginMetadata", serializer ); 101 serializer.endDocument(); 102 } //-- void write( OutputStream, PluginMetadata ) 103 104 /** 105 * Method writeComponent. 106 * 107 * @param component a component object. 108 * @param serializer a serializer object. 109 * @param tagName a tagName object. 110 * @throws java.io.IOException java.io.IOException if any. 111 */ 112 private void writeComponent( Component component, String tagName, XmlSerializer serializer ) 113 throws java.io.IOException 114 { 115 serializer.startTag( NAMESPACE, tagName ); 116 if ( component.getRole() != null ) 117 { 118 serializer.startTag( NAMESPACE, "role" ).text( component.getRole() ).endTag( NAMESPACE, "role" ); 119 } 120 if ( component.getHint() != null ) 121 { 122 serializer.startTag( NAMESPACE, "hint" ).text( component.getHint() ).endTag( NAMESPACE, "hint" ); 123 } 124 serializer.endTag( NAMESPACE, tagName ); 125 } //-- void writeComponent( Component, String, XmlSerializer ) 126 127 /** 128 * Method writeLifecycleExecution. 129 * 130 * @param lifecycleExecution a lifecycleExecution object. 131 * @param serializer a serializer object. 132 * @param tagName a tagName object. 133 * @throws java.io.IOException java.io.IOException if any. 134 */ 135 private void writeLifecycleExecution( LifecycleExecution lifecycleExecution, String tagName, XmlSerializer serializer ) 136 throws java.io.IOException 137 { 138 serializer.startTag( NAMESPACE, tagName ); 139 if ( lifecycleExecution.getLifecycle() != null ) 140 { 141 serializer.startTag( NAMESPACE, "lifecycle" ).text( lifecycleExecution.getLifecycle() ).endTag( NAMESPACE, "lifecycle" ); 142 } 143 if ( lifecycleExecution.getPhase() != null ) 144 { 145 serializer.startTag( NAMESPACE, "phase" ).text( lifecycleExecution.getPhase() ).endTag( NAMESPACE, "phase" ); 146 } 147 if ( lifecycleExecution.getGoal() != null ) 148 { 149 serializer.startTag( NAMESPACE, "goal" ).text( lifecycleExecution.getGoal() ).endTag( NAMESPACE, "goal" ); 150 } 151 serializer.endTag( NAMESPACE, tagName ); 152 } //-- void writeLifecycleExecution( LifecycleExecution, String, XmlSerializer ) 153 154 /** 155 * Method writeMojo. 156 * 157 * @param mojo a mojo object. 158 * @param serializer a serializer object. 159 * @param tagName a tagName object. 160 * @throws java.io.IOException java.io.IOException if any. 161 */ 162 private void writeMojo( Mojo mojo, String tagName, XmlSerializer serializer ) 163 throws java.io.IOException 164 { 165 serializer.startTag( NAMESPACE, tagName ); 166 if ( mojo.getGoal() != null ) 167 { 168 serializer.startTag( NAMESPACE, "goal" ).text( mojo.getGoal() ).endTag( NAMESPACE, "goal" ); 169 } 170 if ( mojo.getPhase() != null ) 171 { 172 serializer.startTag( NAMESPACE, "phase" ).text( mojo.getPhase() ).endTag( NAMESPACE, "phase" ); 173 } 174 if ( mojo.isAggregator() != false ) 175 { 176 serializer.startTag( NAMESPACE, "aggregator" ).text( String.valueOf( mojo.isAggregator() ) ).endTag( NAMESPACE, "aggregator" ); 177 } 178 if ( mojo.getRequiresDependencyResolution() != null ) 179 { 180 serializer.startTag( NAMESPACE, "requiresDependencyResolution" ).text( mojo.getRequiresDependencyResolution() ).endTag( NAMESPACE, "requiresDependencyResolution" ); 181 } 182 if ( mojo.isRequiresProject() != false ) 183 { 184 serializer.startTag( NAMESPACE, "requiresProject" ).text( String.valueOf( mojo.isRequiresProject() ) ).endTag( NAMESPACE, "requiresProject" ); 185 } 186 if ( mojo.isRequiresReports() != false ) 187 { 188 serializer.startTag( NAMESPACE, "requiresReports" ).text( String.valueOf( mojo.isRequiresReports() ) ).endTag( NAMESPACE, "requiresReports" ); 189 } 190 if ( mojo.isRequiresOnline() != false ) 191 { 192 serializer.startTag( NAMESPACE, "requiresOnline" ).text( String.valueOf( mojo.isRequiresOnline() ) ).endTag( NAMESPACE, "requiresOnline" ); 193 } 194 if ( mojo.isInheritByDefault() != false ) 195 { 196 serializer.startTag( NAMESPACE, "inheritByDefault" ).text( String.valueOf( mojo.isInheritByDefault() ) ).endTag( NAMESPACE, "inheritByDefault" ); 197 } 198 if ( mojo.isRequiresDirectInvocation() != false ) 199 { 200 serializer.startTag( NAMESPACE, "requiresDirectInvocation" ).text( String.valueOf( mojo.isRequiresDirectInvocation() ) ).endTag( NAMESPACE, "requiresDirectInvocation" ); 201 } 202 if ( mojo.getExecution() != null ) 203 { 204 writeLifecycleExecution( (LifecycleExecution) mojo.getExecution(), "execution", serializer ); 205 } 206 if ( ( mojo.getComponents() != null ) && ( mojo.getComponents().size() > 0 ) ) 207 { 208 serializer.startTag( NAMESPACE, "components" ); 209 for ( Iterator iter = mojo.getComponents().iterator(); iter.hasNext(); ) 210 { 211 Component o = (Component) iter.next(); 212 writeComponent( o, "component", serializer ); 213 } 214 serializer.endTag( NAMESPACE, "components" ); 215 } 216 if ( ( mojo.getParameters() != null ) && ( mojo.getParameters().size() > 0 ) ) 217 { 218 serializer.startTag( NAMESPACE, "parameters" ); 219 for ( Iterator iter = mojo.getParameters().iterator(); iter.hasNext(); ) 220 { 221 Parameter o = (Parameter) iter.next(); 222 writeParameter( o, "parameter", serializer ); 223 } 224 serializer.endTag( NAMESPACE, "parameters" ); 225 } 226 if ( mojo.getDescription() != null ) 227 { 228 serializer.startTag( NAMESPACE, "description" ).text( mojo.getDescription() ).endTag( NAMESPACE, "description" ); 229 } 230 if ( mojo.getDeprecation() != null ) 231 { 232 serializer.startTag( NAMESPACE, "deprecated" ).text( mojo.getDeprecation() ).endTag( NAMESPACE, "deprecated" ); 233 } 234 if ( mojo.getSince() != null ) 235 { 236 serializer.startTag( NAMESPACE, "since" ).text( mojo.getSince() ).endTag( NAMESPACE, "since" ); 237 } 238 if ( mojo.getCall() != null ) 239 { 240 serializer.startTag( NAMESPACE, "call" ).text( mojo.getCall() ).endTag( NAMESPACE, "call" ); 241 } 242 serializer.endTag( NAMESPACE, tagName ); 243 } //-- void writeMojo( Mojo, String, XmlSerializer ) 244 245 /** 246 * Method writeParameter. 247 * 248 * @param parameter a parameter object. 249 * @param serializer a serializer object. 250 * @param tagName a tagName object. 251 * @throws java.io.IOException java.io.IOException if any. 252 */ 253 private void writeParameter( Parameter parameter, String tagName, XmlSerializer serializer ) 254 throws java.io.IOException 255 { 256 serializer.startTag( NAMESPACE, tagName ); 257 if ( parameter.getName() != null ) 258 { 259 serializer.startTag( NAMESPACE, "name" ).text( parameter.getName() ).endTag( NAMESPACE, "name" ); 260 } 261 if ( parameter.getAlias() != null ) 262 { 263 serializer.startTag( NAMESPACE, "alias" ).text( parameter.getAlias() ).endTag( NAMESPACE, "alias" ); 264 } 265 if ( parameter.getProperty() != null ) 266 { 267 serializer.startTag( NAMESPACE, "property" ).text( parameter.getProperty() ).endTag( NAMESPACE, "property" ); 268 } 269 if ( parameter.isRequired() != false ) 270 { 271 serializer.startTag( NAMESPACE, "required" ).text( String.valueOf( parameter.isRequired() ) ).endTag( NAMESPACE, "required" ); 272 } 273 if ( parameter.isReadonly() != false ) 274 { 275 serializer.startTag( NAMESPACE, "readonly" ).text( String.valueOf( parameter.isReadonly() ) ).endTag( NAMESPACE, "readonly" ); 276 } 277 if ( parameter.getExpression() != null ) 278 { 279 serializer.startTag( NAMESPACE, "expression" ).text( parameter.getExpression() ).endTag( NAMESPACE, "expression" ); 280 } 281 if ( parameter.getDefaultValue() != null ) 282 { 283 serializer.startTag( NAMESPACE, "defaultValue" ).text( parameter.getDefaultValue() ).endTag( NAMESPACE, "defaultValue" ); 284 } 285 if ( parameter.getType() != null ) 286 { 287 serializer.startTag( NAMESPACE, "type" ).text( parameter.getType() ).endTag( NAMESPACE, "type" ); 288 } 289 if ( parameter.getDescription() != null ) 290 { 291 serializer.startTag( NAMESPACE, "description" ).text( parameter.getDescription() ).endTag( NAMESPACE, "description" ); 292 } 293 if ( parameter.getDeprecation() != null ) 294 { 295 serializer.startTag( NAMESPACE, "deprecated" ).text( parameter.getDeprecation() ).endTag( NAMESPACE, "deprecated" ); 296 } 297 if ( parameter.getSince() != null ) 298 { 299 serializer.startTag( NAMESPACE, "since" ).text( parameter.getSince() ).endTag( NAMESPACE, "since" ); 300 } 301 serializer.endTag( NAMESPACE, tagName ); 302 } //-- void writeParameter( Parameter, String, XmlSerializer ) 303 304 /** 305 * Method writePluginMetadata. 306 * 307 * @param pluginMetadata a pluginMetadata object. 308 * @param serializer a serializer object. 309 * @param tagName a tagName object. 310 * @throws java.io.IOException java.io.IOException if any. 311 */ 312 private void writePluginMetadata( PluginMetadata pluginMetadata, String tagName, XmlSerializer serializer ) 313 throws java.io.IOException 314 { 315 serializer.startTag( NAMESPACE, tagName ); 316 if ( ( pluginMetadata.getMojos() != null ) && ( pluginMetadata.getMojos().size() > 0 ) ) 317 { 318 serializer.startTag( NAMESPACE, "mojos" ); 319 for ( Iterator iter = pluginMetadata.getMojos().iterator(); iter.hasNext(); ) 320 { 321 Mojo o = (Mojo) iter.next(); 322 writeMojo( o, "mojo", serializer ); 323 } 324 serializer.endTag( NAMESPACE, "mojos" ); 325 } 326 serializer.endTag( NAMESPACE, tagName ); 327 } //-- void writePluginMetadata( PluginMetadata, String, XmlSerializer ) 328 329}