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