View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 2.0.0,
3   // any modifications will be overwritten.
4   // ==============================================================
5   
6   package org.apache.maven.tools.plugin.extractor.model.io.xpp3;
7   
8     //---------------------------------/
9    //- Imported classes and packages -/
10  //---------------------------------/
11  
12  import java.io.IOException;
13  import java.io.InputStream;
14  import java.io.Reader;
15  import java.text.DateFormat;
16  import org.apache.maven.tools.plugin.extractor.model.Component;
17  import org.apache.maven.tools.plugin.extractor.model.LifecycleExecution;
18  import org.apache.maven.tools.plugin.extractor.model.Mojo;
19  import org.apache.maven.tools.plugin.extractor.model.Parameter;
20  import org.apache.maven.tools.plugin.extractor.model.PluginMetadata;
21  import org.codehaus.plexus.util.ReaderFactory;
22  import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
23  import org.codehaus.plexus.util.xml.pull.MXParser;
24  import org.codehaus.plexus.util.xml.pull.XmlPullParser;
25  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
26  
27  /**
28   * Class PluginMetadataXpp3Reader.
29   * 
30   * @version $Revision$ $Date$
31   */
32  @SuppressWarnings( "all" )
33  public class PluginMetadataXpp3Reader
34  {
35  
36        //--------------------------/
37       //- Class/Member Variables -/
38      //--------------------------/
39  
40      /**
41       * If set the parser will be loaded with all single characters
42       * from the XHTML specification.
43       * The entities used:
44       * <ul>
45       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</li>
46       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</li>
47       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</li>
48       * </ul>
49       */
50      private boolean addDefaultEntities = true;
51  
52      /**
53       * Field contentTransformer.
54       */
55      public final ContentTransformer contentTransformer;
56  
57  
58        //----------------/
59       //- Constructors -/
60      //----------------/
61  
62      public PluginMetadataXpp3Reader()
63      {
64          this( new ContentTransformer()
65          {
66              public String transform( String source, String fieldName )
67              {
68                  return source;
69              }
70          } );
71      } //-- org.apache.maven.tools.plugin.extractor.model.io.xpp3.PluginMetadataXpp3Reader()
72  
73      public PluginMetadataXpp3Reader(ContentTransformer contentTransformer)
74      {
75          this.contentTransformer = contentTransformer;
76      } //-- org.apache.maven.tools.plugin.extractor.model.io.xpp3.PluginMetadataXpp3Reader(ContentTransformer)
77  
78  
79        //-----------/
80       //- Methods -/
81      //-----------/
82  
83      /**
84       * Method checkFieldWithDuplicate.
85       * 
86       * @param parser a parser object.
87       * @param parsed a parsed object.
88       * @param alias a alias object.
89       * @param tagName a tagName object.
90       * @throws XmlPullParserException XmlPullParserException if
91       * any.
92       * @return boolean
93       */
94      private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed )
95          throws XmlPullParserException
96      {
97          if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
98          {
99              return false;
100         }
101         if ( !parsed.add( tagName ) )
102         {
103             throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
104         }
105         return true;
106     } //-- boolean checkFieldWithDuplicate( XmlPullParser, String, String, java.util.Set )
107 
108     /**
109      * Method checkUnknownAttribute.
110      * 
111      * @param parser a parser object.
112      * @param strict a strict object.
113      * @param tagName a tagName object.
114      * @param attribute a attribute object.
115      * @throws XmlPullParserException XmlPullParserException if
116      * any.
117      * @throws IOException IOException if any.
118      */
119     private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
120         throws XmlPullParserException, IOException
121     {
122         // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
123         if ( strict )
124         {
125             throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
126         }
127     } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean )
128 
129     /**
130      * Method checkUnknownElement.
131      * 
132      * @param parser a parser object.
133      * @param strict a strict object.
134      * @throws XmlPullParserException XmlPullParserException if
135      * any.
136      * @throws IOException IOException if any.
137      */
138     private void checkUnknownElement( XmlPullParser parser, boolean strict )
139         throws XmlPullParserException, IOException
140     {
141         if ( strict )
142         {
143             throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
144         }
145 
146         for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
147         {
148             int eventType = parser.next();
149             if ( eventType == XmlPullParser.START_TAG )
150             {
151                 unrecognizedTagCount++;
152             }
153             else if ( eventType == XmlPullParser.END_TAG )
154             {
155                 unrecognizedTagCount--;
156             }
157         }
158     } //-- void checkUnknownElement( XmlPullParser, boolean )
159 
160     /**
161      * Returns the state of the "add default entities" flag.
162      * 
163      * @return boolean
164      */
165     public boolean getAddDefaultEntities()
166     {
167         return addDefaultEntities;
168     } //-- boolean getAddDefaultEntities()
169 
170     /**
171      * Method getBooleanValue.
172      * 
173      * @param s a s object.
174      * @param parser a parser object.
175      * @param attribute a attribute object.
176      * @throws XmlPullParserException XmlPullParserException if
177      * any.
178      * @return boolean
179      */
180     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser )
181         throws XmlPullParserException
182     {
183         return getBooleanValue( s, attribute, parser, null );
184     } //-- boolean getBooleanValue( String, String, XmlPullParser )
185 
186     /**
187      * Method getBooleanValue.
188      * 
189      * @param s a s object.
190      * @param defaultValue a defaultValue object.
191      * @param parser a parser object.
192      * @param attribute a attribute object.
193      * @throws XmlPullParserException XmlPullParserException if
194      * any.
195      * @return boolean
196      */
197     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue )
198         throws XmlPullParserException
199     {
200         if ( s != null && s.length() != 0 )
201         {
202             return Boolean.valueOf( s ).booleanValue();
203         }
204         if ( defaultValue != null )
205         {
206             return Boolean.valueOf( defaultValue ).booleanValue();
207         }
208         return false;
209     } //-- boolean getBooleanValue( String, String, XmlPullParser, String )
210 
211     /**
212      * Method getByteValue.
213      * 
214      * @param s a s object.
215      * @param strict a strict object.
216      * @param parser a parser object.
217      * @param attribute a attribute object.
218      * @throws XmlPullParserException XmlPullParserException if
219      * any.
220      * @return byte
221      */
222     private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict )
223         throws XmlPullParserException
224     {
225         if ( s != null )
226         {
227             try
228             {
229                 return Byte.valueOf( s ).byteValue();
230             }
231             catch ( NumberFormatException nfe )
232             {
233                 if ( strict )
234                 {
235                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe );
236                 }
237             }
238         }
239         return 0;
240     } //-- byte getByteValue( String, String, XmlPullParser, boolean )
241 
242     /**
243      * Method getCharacterValue.
244      * 
245      * @param s a s object.
246      * @param parser a parser object.
247      * @param attribute a attribute object.
248      * @throws XmlPullParserException XmlPullParserException if
249      * any.
250      * @return char
251      */
252     private char getCharacterValue( String s, String attribute, XmlPullParser parser )
253         throws XmlPullParserException
254     {
255         if ( s != null )
256         {
257             return s.charAt( 0 );
258         }
259         return 0;
260     } //-- char getCharacterValue( String, String, XmlPullParser )
261 
262     /**
263      * Method getDateValue.
264      * 
265      * @param s a s object.
266      * @param parser a parser object.
267      * @param attribute a attribute object.
268      * @throws XmlPullParserException XmlPullParserException if
269      * any.
270      * @return Date
271      */
272     private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser )
273         throws XmlPullParserException
274     {
275         return getDateValue( s, attribute, null, parser );
276     } //-- java.util.Date getDateValue( String, String, XmlPullParser )
277 
278     /**
279      * Method getDateValue.
280      * 
281      * @param s a s object.
282      * @param parser a parser object.
283      * @param dateFormat a dateFormat object.
284      * @param attribute a attribute object.
285      * @throws XmlPullParserException XmlPullParserException if
286      * any.
287      * @return Date
288      */
289     private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser )
290         throws XmlPullParserException
291     {
292         if ( s != null )
293         {
294             String effectiveDateFormat = dateFormat;
295             if ( dateFormat == null )
296             {
297                 effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
298             }
299             if ( "long".equals( effectiveDateFormat ) )
300             {
301                 try
302                 {
303                     return new java.util.Date( Long.parseLong( s ) );
304                 }
305                 catch ( NumberFormatException e )
306                 {
307                     throw new XmlPullParserException( e.getMessage(), parser, e );
308                 }
309             }
310             else
311             {
312                 try
313                 {
314                     DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US );
315                     return dateParser.parse( s );
316                 }
317                 catch ( java.text.ParseException e )
318                 {
319                     throw new XmlPullParserException( e.getMessage(), parser, e );
320                 }
321             }
322         }
323         return null;
324     } //-- java.util.Date getDateValue( String, String, String, XmlPullParser )
325 
326     /**
327      * Method getDoubleValue.
328      * 
329      * @param s a s object.
330      * @param strict a strict object.
331      * @param parser a parser object.
332      * @param attribute a attribute object.
333      * @throws XmlPullParserException XmlPullParserException if
334      * any.
335      * @return double
336      */
337     private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict )
338         throws XmlPullParserException
339     {
340         if ( s != null )
341         {
342             try
343             {
344                 return Double.valueOf( s ).doubleValue();
345             }
346             catch ( NumberFormatException nfe )
347             {
348                 if ( strict )
349                 {
350                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
351                 }
352             }
353         }
354         return 0;
355     } //-- double getDoubleValue( String, String, XmlPullParser, boolean )
356 
357     /**
358      * Method getFloatValue.
359      * 
360      * @param s a s object.
361      * @param strict a strict object.
362      * @param parser a parser object.
363      * @param attribute a attribute object.
364      * @throws XmlPullParserException XmlPullParserException if
365      * any.
366      * @return float
367      */
368     private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict )
369         throws XmlPullParserException
370     {
371         if ( s != null )
372         {
373             try
374             {
375                 return Float.valueOf( s ).floatValue();
376             }
377             catch ( NumberFormatException nfe )
378             {
379                 if ( strict )
380                 {
381                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
382                 }
383             }
384         }
385         return 0;
386     } //-- float getFloatValue( String, String, XmlPullParser, boolean )
387 
388     /**
389      * Method getIntegerValue.
390      * 
391      * @param s a s object.
392      * @param strict a strict object.
393      * @param parser a parser object.
394      * @param attribute a attribute object.
395      * @throws XmlPullParserException XmlPullParserException if
396      * any.
397      * @return int
398      */
399     private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict )
400         throws XmlPullParserException
401     {
402         if ( s != null )
403         {
404             try
405             {
406                 return Integer.valueOf( s ).intValue();
407             }
408             catch ( NumberFormatException nfe )
409             {
410                 if ( strict )
411                 {
412                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
413                 }
414             }
415         }
416         return 0;
417     } //-- int getIntegerValue( String, String, XmlPullParser, boolean )
418 
419     /**
420      * Method getLongValue.
421      * 
422      * @param s a s object.
423      * @param strict a strict object.
424      * @param parser a parser object.
425      * @param attribute a attribute object.
426      * @throws XmlPullParserException XmlPullParserException if
427      * any.
428      * @return long
429      */
430     private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict )
431         throws XmlPullParserException
432     {
433         if ( s != null )
434         {
435             try
436             {
437                 return Long.valueOf( s ).longValue();
438             }
439             catch ( NumberFormatException nfe )
440             {
441                 if ( strict )
442                 {
443                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe );
444                 }
445             }
446         }
447         return 0;
448     } //-- long getLongValue( String, String, XmlPullParser, boolean )
449 
450     /**
451      * Method getRequiredAttributeValue.
452      * 
453      * @param s a s object.
454      * @param strict a strict object.
455      * @param parser a parser object.
456      * @param attribute a attribute object.
457      * @throws XmlPullParserException XmlPullParserException if
458      * any.
459      * @return String
460      */
461     private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict )
462         throws XmlPullParserException
463     {
464         if ( s == null )
465         {
466             if ( strict )
467             {
468                 throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null );
469             }
470         }
471         return s;
472     } //-- String getRequiredAttributeValue( String, String, XmlPullParser, boolean )
473 
474     /**
475      * Method getShortValue.
476      * 
477      * @param s a s object.
478      * @param strict a strict object.
479      * @param parser a parser object.
480      * @param attribute a attribute object.
481      * @throws XmlPullParserException XmlPullParserException if
482      * any.
483      * @return short
484      */
485     private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict )
486         throws XmlPullParserException
487     {
488         if ( s != null )
489         {
490             try
491             {
492                 return Short.valueOf( s ).shortValue();
493             }
494             catch ( NumberFormatException nfe )
495             {
496                 if ( strict )
497                 {
498                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe );
499                 }
500             }
501         }
502         return 0;
503     } //-- short getShortValue( String, String, XmlPullParser, boolean )
504 
505     /**
506      * Method getTrimmedValue.
507      * 
508      * @param s a s object.
509      * @return String
510      */
511     private String getTrimmedValue( String s )
512     {
513         if ( s != null )
514         {
515             s = s.trim();
516         }
517         return s;
518     } //-- String getTrimmedValue( String )
519 
520     /**
521      * Method interpolatedTrimmed.
522      * 
523      * @param value a value object.
524      * @param context a context object.
525      * @return String
526      */
527     private String interpolatedTrimmed( String value, String context )
528     {
529         return getTrimmedValue( contentTransformer.transform( value, context ) );
530     } //-- String interpolatedTrimmed( String, String )
531 
532     /**
533      * Method nextTag.
534      * 
535      * @param parser a parser object.
536      * @throws IOException IOException if any.
537      * @throws XmlPullParserException XmlPullParserException if
538      * any.
539      * @return int
540      */
541     private int nextTag( XmlPullParser parser )
542         throws IOException, XmlPullParserException
543     {
544         int eventType = parser.next();
545         if ( eventType == XmlPullParser.TEXT )
546         {
547             eventType = parser.next();
548         }
549         if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
550         {
551             throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
552         }
553         return eventType;
554     } //-- int nextTag( XmlPullParser )
555 
556     /**
557      * @see ReaderFactory#newXmlReader
558      * 
559      * @param reader a reader object.
560      * @param strict a strict object.
561      * @throws IOException IOException if any.
562      * @throws XmlPullParserException XmlPullParserException if
563      * any.
564      * @return PluginMetadata
565      */
566     public PluginMetadata read( Reader reader, boolean strict )
567         throws IOException, XmlPullParserException
568     {
569         XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
570 
571         parser.setInput( reader );
572 
573 
574         return read( parser, strict );
575     } //-- PluginMetadata read( Reader, boolean )
576 
577     /**
578      * @see ReaderFactory#newXmlReader
579      * 
580      * @param reader a reader object.
581      * @throws IOException IOException if any.
582      * @throws XmlPullParserException XmlPullParserException if
583      * any.
584      * @return PluginMetadata
585      */
586     public PluginMetadata read( Reader reader )
587         throws IOException, XmlPullParserException
588     {
589         return read( reader, true );
590     } //-- PluginMetadata read( Reader )
591 
592     /**
593      * Method read.
594      * 
595      * @param in a in object.
596      * @param strict a strict object.
597      * @throws IOException IOException if any.
598      * @throws XmlPullParserException XmlPullParserException if
599      * any.
600      * @return PluginMetadata
601      */
602     public PluginMetadata read( InputStream in, boolean strict )
603         throws IOException, XmlPullParserException
604     {
605         return read( ReaderFactory.newXmlReader( in ), strict );
606     } //-- PluginMetadata read( InputStream, boolean )
607 
608     /**
609      * Method read.
610      * 
611      * @param in a in object.
612      * @throws IOException IOException if any.
613      * @throws XmlPullParserException XmlPullParserException if
614      * any.
615      * @return PluginMetadata
616      */
617     public PluginMetadata read( InputStream in )
618         throws IOException, XmlPullParserException
619     {
620         return read( ReaderFactory.newXmlReader( in ) );
621     } //-- PluginMetadata read( InputStream )
622 
623     /**
624      * Method parseComponent.
625      * 
626      * @param parser a parser object.
627      * @param strict a strict object.
628      * @throws IOException IOException if any.
629      * @throws XmlPullParserException XmlPullParserException if
630      * any.
631      * @return Component
632      */
633     private Component parseComponent( XmlPullParser parser, boolean strict )
634         throws IOException, XmlPullParserException
635     {
636         String tagName = parser.getName();
637         Component component = new Component();
638         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
639         {
640             String name = parser.getAttributeName( i );
641             String value = parser.getAttributeValue( i );
642 
643             if ( name.indexOf( ':' ) >= 0 )
644             {
645                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
646             }
647             else
648             {
649                 checkUnknownAttribute( parser, name, tagName, strict );
650             }
651         }
652         java.util.Set parsed = new java.util.HashSet();
653         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
654         {
655             if ( checkFieldWithDuplicate( parser, "role", null, parsed ) )
656             {
657                 component.setRole( interpolatedTrimmed( parser.nextText(), "role" ) );
658             }
659             else if ( checkFieldWithDuplicate( parser, "hint", null, parsed ) )
660             {
661                 component.setHint( interpolatedTrimmed( parser.nextText(), "hint" ) );
662             }
663             else
664             {
665                 checkUnknownElement( parser, strict );
666             }
667         }
668         return component;
669     } //-- Component parseComponent( XmlPullParser, boolean )
670 
671     /**
672      * Method parseLifecycleExecution.
673      * 
674      * @param parser a parser object.
675      * @param strict a strict object.
676      * @throws IOException IOException if any.
677      * @throws XmlPullParserException XmlPullParserException if
678      * any.
679      * @return LifecycleExecution
680      */
681     private LifecycleExecution parseLifecycleExecution( XmlPullParser parser, boolean strict )
682         throws IOException, XmlPullParserException
683     {
684         String tagName = parser.getName();
685         LifecycleExecution lifecycleExecution = new LifecycleExecution();
686         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
687         {
688             String name = parser.getAttributeName( i );
689             String value = parser.getAttributeValue( i );
690 
691             if ( name.indexOf( ':' ) >= 0 )
692             {
693                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
694             }
695             else
696             {
697                 checkUnknownAttribute( parser, name, tagName, strict );
698             }
699         }
700         java.util.Set parsed = new java.util.HashSet();
701         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
702         {
703             if ( checkFieldWithDuplicate( parser, "lifecycle", null, parsed ) )
704             {
705                 lifecycleExecution.setLifecycle( interpolatedTrimmed( parser.nextText(), "lifecycle" ) );
706             }
707             else if ( checkFieldWithDuplicate( parser, "phase", null, parsed ) )
708             {
709                 lifecycleExecution.setPhase( interpolatedTrimmed( parser.nextText(), "phase" ) );
710             }
711             else if ( checkFieldWithDuplicate( parser, "goal", null, parsed ) )
712             {
713                 lifecycleExecution.setGoal( interpolatedTrimmed( parser.nextText(), "goal" ) );
714             }
715             else
716             {
717                 checkUnknownElement( parser, strict );
718             }
719         }
720         return lifecycleExecution;
721     } //-- LifecycleExecution parseLifecycleExecution( XmlPullParser, boolean )
722 
723     /**
724      * Method parseMojo.
725      * 
726      * @param parser a parser object.
727      * @param strict a strict object.
728      * @throws IOException IOException if any.
729      * @throws XmlPullParserException XmlPullParserException if
730      * any.
731      * @return Mojo
732      */
733     private Mojo parseMojo( XmlPullParser parser, boolean strict )
734         throws IOException, XmlPullParserException
735     {
736         String tagName = parser.getName();
737         Mojo mojo = new Mojo();
738         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
739         {
740             String name = parser.getAttributeName( i );
741             String value = parser.getAttributeValue( i );
742 
743             if ( name.indexOf( ':' ) >= 0 )
744             {
745                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
746             }
747             else
748             {
749                 checkUnknownAttribute( parser, name, tagName, strict );
750             }
751         }
752         java.util.Set parsed = new java.util.HashSet();
753         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
754         {
755             if ( checkFieldWithDuplicate( parser, "goal", null, parsed ) )
756             {
757                 mojo.setGoal( interpolatedTrimmed( parser.nextText(), "goal" ) );
758             }
759             else if ( checkFieldWithDuplicate( parser, "phase", null, parsed ) )
760             {
761                 mojo.setPhase( interpolatedTrimmed( parser.nextText(), "phase" ) );
762             }
763             else if ( checkFieldWithDuplicate( parser, "aggregator", null, parsed ) )
764             {
765                 mojo.setAggregator( getBooleanValue( interpolatedTrimmed( parser.nextText(), "aggregator" ), "aggregator", parser, "false" ) );
766             }
767             else if ( checkFieldWithDuplicate( parser, "requiresDependencyResolution", null, parsed ) )
768             {
769                 mojo.setRequiresDependencyResolution( interpolatedTrimmed( parser.nextText(), "requiresDependencyResolution" ) );
770             }
771             else if ( checkFieldWithDuplicate( parser, "requiresProject", null, parsed ) )
772             {
773                 mojo.setRequiresProject( getBooleanValue( interpolatedTrimmed( parser.nextText(), "requiresProject" ), "requiresProject", parser, "false" ) );
774             }
775             else if ( checkFieldWithDuplicate( parser, "requiresReports", null, parsed ) )
776             {
777                 mojo.setRequiresReports( getBooleanValue( interpolatedTrimmed( parser.nextText(), "requiresReports" ), "requiresReports", parser, "false" ) );
778             }
779             else if ( checkFieldWithDuplicate( parser, "requiresOnline", null, parsed ) )
780             {
781                 mojo.setRequiresOnline( getBooleanValue( interpolatedTrimmed( parser.nextText(), "requiresOnline" ), "requiresOnline", parser, "false" ) );
782             }
783             else if ( checkFieldWithDuplicate( parser, "inheritByDefault", null, parsed ) )
784             {
785                 mojo.setInheritByDefault( getBooleanValue( interpolatedTrimmed( parser.nextText(), "inheritByDefault" ), "inheritByDefault", parser, "false" ) );
786             }
787             else if ( checkFieldWithDuplicate( parser, "requiresDirectInvocation", null, parsed ) )
788             {
789                 mojo.setRequiresDirectInvocation( getBooleanValue( interpolatedTrimmed( parser.nextText(), "requiresDirectInvocation" ), "requiresDirectInvocation", parser, "false" ) );
790             }
791             else if ( checkFieldWithDuplicate( parser, "execution", null, parsed ) )
792             {
793                 mojo.setExecution( parseLifecycleExecution( parser, strict ) );
794             }
795             else if ( checkFieldWithDuplicate( parser, "components", null, parsed ) )
796             {
797                 java.util.List<Component> components = new java.util.ArrayList<Component>();
798                 mojo.setComponents( components );
799                 while ( parser.nextTag() == XmlPullParser.START_TAG )
800                 {
801                     if ( "component".equals( parser.getName() ) )
802                     {
803                         components.add( parseComponent( parser, strict ) );
804                     }
805                     else
806                     {
807                         checkUnknownElement( parser, strict );
808                     }
809                 }
810             }
811             else if ( checkFieldWithDuplicate( parser, "parameters", null, parsed ) )
812             {
813                 java.util.List<Parameter> parameters = new java.util.ArrayList<Parameter>();
814                 mojo.setParameters( parameters );
815                 while ( parser.nextTag() == XmlPullParser.START_TAG )
816                 {
817                     if ( "parameter".equals( parser.getName() ) )
818                     {
819                         parameters.add( parseParameter( parser, strict ) );
820                     }
821                     else
822                     {
823                         checkUnknownElement( parser, strict );
824                     }
825                 }
826             }
827             else if ( checkFieldWithDuplicate( parser, "description", null, parsed ) )
828             {
829                 mojo.setDescription( interpolatedTrimmed( parser.nextText(), "description" ) );
830             }
831             else if ( checkFieldWithDuplicate( parser, "deprecated", null, parsed ) )
832             {
833                 mojo.setDeprecation( interpolatedTrimmed( parser.nextText(), "deprecated" ) );
834             }
835             else if ( checkFieldWithDuplicate( parser, "since", null, parsed ) )
836             {
837                 mojo.setSince( interpolatedTrimmed( parser.nextText(), "since" ) );
838             }
839             else if ( checkFieldWithDuplicate( parser, "call", null, parsed ) )
840             {
841                 mojo.setCall( interpolatedTrimmed( parser.nextText(), "call" ) );
842             }
843             else
844             {
845                 checkUnknownElement( parser, strict );
846             }
847         }
848         return mojo;
849     } //-- Mojo parseMojo( XmlPullParser, boolean )
850 
851     /**
852      * Method parseParameter.
853      * 
854      * @param parser a parser object.
855      * @param strict a strict object.
856      * @throws IOException IOException if any.
857      * @throws XmlPullParserException XmlPullParserException if
858      * any.
859      * @return Parameter
860      */
861     private Parameter parseParameter( XmlPullParser parser, boolean strict )
862         throws IOException, XmlPullParserException
863     {
864         String tagName = parser.getName();
865         Parameter parameter = new Parameter();
866         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
867         {
868             String name = parser.getAttributeName( i );
869             String value = parser.getAttributeValue( i );
870 
871             if ( name.indexOf( ':' ) >= 0 )
872             {
873                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
874             }
875             else
876             {
877                 checkUnknownAttribute( parser, name, tagName, strict );
878             }
879         }
880         java.util.Set parsed = new java.util.HashSet();
881         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
882         {
883             if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
884             {
885                 parameter.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
886             }
887             else if ( checkFieldWithDuplicate( parser, "alias", null, parsed ) )
888             {
889                 parameter.setAlias( interpolatedTrimmed( parser.nextText(), "alias" ) );
890             }
891             else if ( checkFieldWithDuplicate( parser, "property", null, parsed ) )
892             {
893                 parameter.setProperty( interpolatedTrimmed( parser.nextText(), "property" ) );
894             }
895             else if ( checkFieldWithDuplicate( parser, "required", null, parsed ) )
896             {
897                 parameter.setRequired( getBooleanValue( interpolatedTrimmed( parser.nextText(), "required" ), "required", parser, "false" ) );
898             }
899             else if ( checkFieldWithDuplicate( parser, "readonly", null, parsed ) )
900             {
901                 parameter.setReadonly( getBooleanValue( interpolatedTrimmed( parser.nextText(), "readonly" ), "readonly", parser, "false" ) );
902             }
903             else if ( checkFieldWithDuplicate( parser, "expression", null, parsed ) )
904             {
905                 parameter.setExpression( interpolatedTrimmed( parser.nextText(), "expression" ) );
906             }
907             else if ( checkFieldWithDuplicate( parser, "defaultValue", null, parsed ) )
908             {
909                 parameter.setDefaultValue( interpolatedTrimmed( parser.nextText(), "defaultValue" ) );
910             }
911             else if ( checkFieldWithDuplicate( parser, "type", null, parsed ) )
912             {
913                 parameter.setType( interpolatedTrimmed( parser.nextText(), "type" ) );
914             }
915             else if ( checkFieldWithDuplicate( parser, "description", null, parsed ) )
916             {
917                 parameter.setDescription( interpolatedTrimmed( parser.nextText(), "description" ) );
918             }
919             else if ( checkFieldWithDuplicate( parser, "deprecated", null, parsed ) )
920             {
921                 parameter.setDeprecation( interpolatedTrimmed( parser.nextText(), "deprecated" ) );
922             }
923             else if ( checkFieldWithDuplicate( parser, "since", null, parsed ) )
924             {
925                 parameter.setSince( interpolatedTrimmed( parser.nextText(), "since" ) );
926             }
927             else
928             {
929                 checkUnknownElement( parser, strict );
930             }
931         }
932         return parameter;
933     } //-- Parameter parseParameter( XmlPullParser, boolean )
934 
935     /**
936      * Method parsePluginMetadata.
937      * 
938      * @param parser a parser object.
939      * @param strict a strict object.
940      * @throws IOException IOException if any.
941      * @throws XmlPullParserException XmlPullParserException if
942      * any.
943      * @return PluginMetadata
944      */
945     private PluginMetadata parsePluginMetadata( XmlPullParser parser, boolean strict )
946         throws IOException, XmlPullParserException
947     {
948         String tagName = parser.getName();
949         PluginMetadata pluginMetadata = new PluginMetadata();
950         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
951         {
952             String name = parser.getAttributeName( i );
953             String value = parser.getAttributeValue( i );
954 
955             if ( name.indexOf( ':' ) >= 0 )
956             {
957                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
958             }
959             else if ( "xmlns".equals( name ) )
960             {
961                 // ignore xmlns attribute in root class, which is a reserved attribute name
962             }
963             else
964             {
965                 checkUnknownAttribute( parser, name, tagName, strict );
966             }
967         }
968         java.util.Set parsed = new java.util.HashSet();
969         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
970         {
971             if ( checkFieldWithDuplicate( parser, "mojos", null, parsed ) )
972             {
973                 java.util.List<Mojo> mojos = new java.util.ArrayList<Mojo>();
974                 pluginMetadata.setMojos( mojos );
975                 while ( parser.nextTag() == XmlPullParser.START_TAG )
976                 {
977                     if ( "mojo".equals( parser.getName() ) )
978                     {
979                         mojos.add( parseMojo( parser, strict ) );
980                     }
981                     else
982                     {
983                         checkUnknownElement( parser, strict );
984                     }
985                 }
986             }
987             else
988             {
989                 checkUnknownElement( parser, strict );
990             }
991         }
992         return pluginMetadata;
993     } //-- PluginMetadata parsePluginMetadata( XmlPullParser, boolean )
994 
995     /**
996      * Method read.
997      * 
998      * @param parser a parser object.
999      * @param strict a strict object.
1000      * @throws IOException IOException if any.
1001      * @throws XmlPullParserException XmlPullParserException if
1002      * any.
1003      * @return PluginMetadata
1004      */
1005     private PluginMetadata read( XmlPullParser parser, boolean strict )
1006         throws IOException, XmlPullParserException
1007     {
1008         PluginMetadata pluginMetadata = null;
1009         int eventType = parser.getEventType();
1010         boolean parsed = false;
1011         while ( eventType != XmlPullParser.END_DOCUMENT )
1012         {
1013             if ( eventType == XmlPullParser.START_TAG )
1014             {
1015                 if ( strict && ! "pluginMetadata".equals( parser.getName() ) )
1016                 {
1017                     throw new XmlPullParserException( "Expected root element 'pluginMetadata' but found '" + parser.getName() + "'", parser, null );
1018                 }
1019                 else if ( parsed )
1020                 {
1021                     // fallback, already expected a XmlPullParserException due to invalid XML
1022                     throw new XmlPullParserException( "Duplicated tag: 'pluginMetadata'", parser, null );
1023                 }
1024                 pluginMetadata = parsePluginMetadata( parser, strict );
1025                 pluginMetadata.setModelEncoding( parser.getInputEncoding() );
1026                 parsed = true;
1027             }
1028             eventType = parser.next();
1029         }
1030         if ( parsed )
1031         {
1032             return pluginMetadata;
1033         }
1034         throw new XmlPullParserException( "Expected root element 'pluginMetadata' but found no element at all: invalid XML document", parser, null );
1035     } //-- PluginMetadata read( XmlPullParser, boolean )
1036 
1037     /**
1038      * Sets the state of the "add default entities" flag.
1039      * 
1040      * @param addDefaultEntities a addDefaultEntities object.
1041      */
1042     public void setAddDefaultEntities( boolean addDefaultEntities )
1043     {
1044         this.addDefaultEntities = addDefaultEntities;
1045     } //-- void setAddDefaultEntities( boolean )
1046 
1047     public static interface ContentTransformer
1048 {
1049     /**
1050      * Interpolate the value read from the xpp3 document
1051      * @param source The source value
1052      * @param fieldName A description of the field being interpolated. The implementation may use this to
1053      *                           log stuff.
1054      * @return The interpolated value.
1055      */
1056     String transform( String source, String fieldName );
1057 }
1058 
1059 }