001// =================== DO NOT EDIT THIS FILE ====================
002// Generated by Modello 2.1.2,
003// any modifications will be overwritten.
004// ==============================================================
005
006package org.apache.maven.tools.plugin.extractor.model.io.xpp3;
007
008  //---------------------------------/
009 //- Imported classes and packages -/
010//---------------------------------/
011
012import java.io.IOException;
013import java.io.InputStream;
014import java.io.Reader;
015import java.text.DateFormat;
016import org.apache.maven.tools.plugin.extractor.model.Component;
017import org.apache.maven.tools.plugin.extractor.model.LifecycleExecution;
018import org.apache.maven.tools.plugin.extractor.model.Mojo;
019import org.apache.maven.tools.plugin.extractor.model.Parameter;
020import org.apache.maven.tools.plugin.extractor.model.PluginMetadata;
021import org.codehaus.plexus.util.ReaderFactory;
022import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
023import org.codehaus.plexus.util.xml.pull.MXParser;
024import org.codehaus.plexus.util.xml.pull.XmlPullParser;
025import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
026
027/**
028 * Class PluginMetadataXpp3Reader.
029 * 
030 * @version $Revision$ $Date$
031 */
032@SuppressWarnings( "all" )
033public class PluginMetadataXpp3Reader
034{
035
036      //--------------------------/
037     //- Class/Member Variables -/
038    //--------------------------/
039
040    /**
041     * If set the parser will be loaded with all single characters
042     * from the XHTML specification.
043     * The entities used:
044     * <ul>
045     * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</li>
046     * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</li>
047     * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</li>
048     * </ul>
049     */
050    private boolean addDefaultEntities = true;
051
052    /**
053     * Field contentTransformer.
054     */
055    public final ContentTransformer contentTransformer;
056
057
058      //----------------/
059     //- Constructors -/
060    //----------------/
061
062    public PluginMetadataXpp3Reader()
063    {
064        this( new ContentTransformer()
065        {
066            public String transform( String source, String fieldName )
067            {
068                return source;
069            }
070        } );
071    } //-- org.apache.maven.tools.plugin.extractor.model.io.xpp3.PluginMetadataXpp3Reader()
072
073    public PluginMetadataXpp3Reader(ContentTransformer contentTransformer)
074    {
075        this.contentTransformer = contentTransformer;
076    } //-- org.apache.maven.tools.plugin.extractor.model.io.xpp3.PluginMetadataXpp3Reader(ContentTransformer)
077
078
079      //-----------/
080     //- Methods -/
081    //-----------/
082
083    /**
084     * Method checkFieldWithDuplicate.
085     * 
086     * @param parser a parser object.
087     * @param parsed a parsed object.
088     * @param alias a alias object.
089     * @param tagName a tagName object.
090     * @throws XmlPullParserException XmlPullParserException if
091     * any.
092     * @return boolean
093     */
094    private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed )
095        throws XmlPullParserException
096    {
097        if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
098        {
099            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     * Method read.
558     * 
559     * @param parser a parser 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( XmlPullParser parser, boolean strict )
567        throws IOException, XmlPullParserException
568    {
569        PluginMetadata pluginMetadata = null;
570        int eventType = parser.getEventType();
571        boolean parsed = false;
572        while ( eventType != XmlPullParser.END_DOCUMENT )
573        {
574            if ( eventType == XmlPullParser.START_TAG )
575            {
576                if ( strict && ! "pluginMetadata".equals( parser.getName() ) )
577                {
578                    throw new XmlPullParserException( "Expected root element 'pluginMetadata' but found '" + parser.getName() + "'", parser, null );
579                }
580                else if ( parsed )
581                {
582                    // fallback, already expected a XmlPullParserException due to invalid XML
583                    throw new XmlPullParserException( "Duplicated tag: 'pluginMetadata'", parser, null );
584                }
585                pluginMetadata = parsePluginMetadata( parser, strict );
586                pluginMetadata.setModelEncoding( parser.getInputEncoding() );
587                parsed = true;
588            }
589            eventType = parser.next();
590        }
591        if ( parsed )
592        {
593            return pluginMetadata;
594        }
595        throw new XmlPullParserException( "Expected root element 'pluginMetadata' but found no element at all: invalid XML document", parser, null );
596    } //-- PluginMetadata read( XmlPullParser, boolean )
597
598    /**
599     * @see ReaderFactory#newXmlReader
600     * 
601     * @param reader a reader object.
602     * @param strict a strict object.
603     * @throws IOException IOException if any.
604     * @throws XmlPullParserException XmlPullParserException if
605     * any.
606     * @return PluginMetadata
607     */
608    public PluginMetadata read( Reader reader, boolean strict )
609        throws IOException, XmlPullParserException
610    {
611        XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
612
613        parser.setInput( reader );
614
615
616        return read( parser, strict );
617    } //-- PluginMetadata read( Reader, boolean )
618
619    /**
620     * @see ReaderFactory#newXmlReader
621     * 
622     * @param reader a reader object.
623     * @throws IOException IOException if any.
624     * @throws XmlPullParserException XmlPullParserException if
625     * any.
626     * @return PluginMetadata
627     */
628    public PluginMetadata read( Reader reader )
629        throws IOException, XmlPullParserException
630    {
631        return read( reader, true );
632    } //-- PluginMetadata read( Reader )
633
634    /**
635     * Method read.
636     * 
637     * @param in a in object.
638     * @param strict a strict object.
639     * @throws IOException IOException if any.
640     * @throws XmlPullParserException XmlPullParserException if
641     * any.
642     * @return PluginMetadata
643     */
644    public PluginMetadata read( InputStream in, boolean strict )
645        throws IOException, XmlPullParserException
646    {
647        return read( ReaderFactory.newXmlReader( in ), strict );
648    } //-- PluginMetadata read( InputStream, boolean )
649
650    /**
651     * Method read.
652     * 
653     * @param in a in object.
654     * @throws IOException IOException if any.
655     * @throws XmlPullParserException XmlPullParserException if
656     * any.
657     * @return PluginMetadata
658     */
659    public PluginMetadata read( InputStream in )
660        throws IOException, XmlPullParserException
661    {
662        return read( ReaderFactory.newXmlReader( in ) );
663    } //-- PluginMetadata read( InputStream )
664
665    /**
666     * Method parseComponent.
667     * 
668     * @param parser a parser object.
669     * @param strict a strict object.
670     * @throws IOException IOException if any.
671     * @throws XmlPullParserException XmlPullParserException if
672     * any.
673     * @return Component
674     */
675    private Component parseComponent( XmlPullParser parser, boolean strict )
676        throws IOException, XmlPullParserException
677    {
678        String tagName = parser.getName();
679        Component component = new Component();
680        for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
681        {
682            String name = parser.getAttributeName( i );
683            String value = parser.getAttributeValue( i );
684
685            if ( name.indexOf( ':' ) >= 0 )
686            {
687                // just ignore attributes with non-default namespace (for example: xmlns:xsi)
688            }
689            else
690            {
691                checkUnknownAttribute( parser, name, tagName, strict );
692            }
693        }
694        java.util.Set parsed = new java.util.HashSet();
695        while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
696        {
697            if ( checkFieldWithDuplicate( parser, "role", null, parsed ) )
698            {
699                component.setRole( interpolatedTrimmed( parser.nextText(), "role" ) );
700            }
701            else if ( checkFieldWithDuplicate( parser, "hint", null, parsed ) )
702            {
703                component.setHint( interpolatedTrimmed( parser.nextText(), "hint" ) );
704            }
705            else
706            {
707                checkUnknownElement( parser, strict );
708            }
709        }
710        return component;
711    } //-- Component parseComponent( XmlPullParser, boolean )
712
713    /**
714     * Method parseLifecycleExecution.
715     * 
716     * @param parser a parser object.
717     * @param strict a strict object.
718     * @throws IOException IOException if any.
719     * @throws XmlPullParserException XmlPullParserException if
720     * any.
721     * @return LifecycleExecution
722     */
723    private LifecycleExecution parseLifecycleExecution( XmlPullParser parser, boolean strict )
724        throws IOException, XmlPullParserException
725    {
726        String tagName = parser.getName();
727        LifecycleExecution lifecycleExecution = new LifecycleExecution();
728        for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
729        {
730            String name = parser.getAttributeName( i );
731            String value = parser.getAttributeValue( i );
732
733            if ( name.indexOf( ':' ) >= 0 )
734            {
735                // just ignore attributes with non-default namespace (for example: xmlns:xsi)
736            }
737            else
738            {
739                checkUnknownAttribute( parser, name, tagName, strict );
740            }
741        }
742        java.util.Set parsed = new java.util.HashSet();
743        while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
744        {
745            if ( checkFieldWithDuplicate( parser, "lifecycle", null, parsed ) )
746            {
747                lifecycleExecution.setLifecycle( interpolatedTrimmed( parser.nextText(), "lifecycle" ) );
748            }
749            else if ( checkFieldWithDuplicate( parser, "phase", null, parsed ) )
750            {
751                lifecycleExecution.setPhase( interpolatedTrimmed( parser.nextText(), "phase" ) );
752            }
753            else if ( checkFieldWithDuplicate( parser, "goal", null, parsed ) )
754            {
755                lifecycleExecution.setGoal( interpolatedTrimmed( parser.nextText(), "goal" ) );
756            }
757            else
758            {
759                checkUnknownElement( parser, strict );
760            }
761        }
762        return lifecycleExecution;
763    } //-- LifecycleExecution parseLifecycleExecution( XmlPullParser, boolean )
764
765    /**
766     * Method parseMojo.
767     * 
768     * @param parser a parser object.
769     * @param strict a strict object.
770     * @throws IOException IOException if any.
771     * @throws XmlPullParserException XmlPullParserException if
772     * any.
773     * @return Mojo
774     */
775    private Mojo parseMojo( XmlPullParser parser, boolean strict )
776        throws IOException, XmlPullParserException
777    {
778        String tagName = parser.getName();
779        Mojo mojo = new Mojo();
780        for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
781        {
782            String name = parser.getAttributeName( i );
783            String value = parser.getAttributeValue( i );
784
785            if ( name.indexOf( ':' ) >= 0 )
786            {
787                // just ignore attributes with non-default namespace (for example: xmlns:xsi)
788            }
789            else
790            {
791                checkUnknownAttribute( parser, name, tagName, strict );
792            }
793        }
794        java.util.Set parsed = new java.util.HashSet();
795        while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
796        {
797            if ( checkFieldWithDuplicate( parser, "goal", null, parsed ) )
798            {
799                mojo.setGoal( interpolatedTrimmed( parser.nextText(), "goal" ) );
800            }
801            else if ( checkFieldWithDuplicate( parser, "phase", null, parsed ) )
802            {
803                mojo.setPhase( interpolatedTrimmed( parser.nextText(), "phase" ) );
804            }
805            else if ( checkFieldWithDuplicate( parser, "aggregator", null, parsed ) )
806            {
807                mojo.setAggregator( getBooleanValue( interpolatedTrimmed( parser.nextText(), "aggregator" ), "aggregator", parser, "false" ) );
808            }
809            else if ( checkFieldWithDuplicate( parser, "requiresDependencyResolution", null, parsed ) )
810            {
811                mojo.setRequiresDependencyResolution( interpolatedTrimmed( parser.nextText(), "requiresDependencyResolution" ) );
812            }
813            else if ( checkFieldWithDuplicate( parser, "requiresProject", null, parsed ) )
814            {
815                mojo.setRequiresProject( getBooleanValue( interpolatedTrimmed( parser.nextText(), "requiresProject" ), "requiresProject", parser, "false" ) );
816            }
817            else if ( checkFieldWithDuplicate( parser, "requiresReports", null, parsed ) )
818            {
819                mojo.setRequiresReports( getBooleanValue( interpolatedTrimmed( parser.nextText(), "requiresReports" ), "requiresReports", parser, "false" ) );
820            }
821            else if ( checkFieldWithDuplicate( parser, "requiresOnline", null, parsed ) )
822            {
823                mojo.setRequiresOnline( getBooleanValue( interpolatedTrimmed( parser.nextText(), "requiresOnline" ), "requiresOnline", parser, "false" ) );
824            }
825            else if ( checkFieldWithDuplicate( parser, "inheritByDefault", null, parsed ) )
826            {
827                mojo.setInheritByDefault( getBooleanValue( interpolatedTrimmed( parser.nextText(), "inheritByDefault" ), "inheritByDefault", parser, "false" ) );
828            }
829            else if ( checkFieldWithDuplicate( parser, "requiresDirectInvocation", null, parsed ) )
830            {
831                mojo.setRequiresDirectInvocation( getBooleanValue( interpolatedTrimmed( parser.nextText(), "requiresDirectInvocation" ), "requiresDirectInvocation", parser, "false" ) );
832            }
833            else if ( checkFieldWithDuplicate( parser, "execution", null, parsed ) )
834            {
835                mojo.setExecution( parseLifecycleExecution( parser, strict ) );
836            }
837            else if ( checkFieldWithDuplicate( parser, "components", null, parsed ) )
838            {
839                java.util.List<Component> components = new java.util.ArrayList<Component>();
840                while ( parser.nextTag() == XmlPullParser.START_TAG )
841                {
842                    if ( "component".equals( parser.getName() ) )
843                    {
844                        components.add( parseComponent( parser, strict ) );
845                    }
846                    else
847                    {
848                        checkUnknownElement( parser, strict );
849                    }
850                }
851                mojo.setComponents( components );
852            }
853            else if ( checkFieldWithDuplicate( parser, "parameters", null, parsed ) )
854            {
855                java.util.List<Parameter> parameters = new java.util.ArrayList<Parameter>();
856                while ( parser.nextTag() == XmlPullParser.START_TAG )
857                {
858                    if ( "parameter".equals( parser.getName() ) )
859                    {
860                        parameters.add( parseParameter( parser, strict ) );
861                    }
862                    else
863                    {
864                        checkUnknownElement( parser, strict );
865                    }
866                }
867                mojo.setParameters( parameters );
868            }
869            else if ( checkFieldWithDuplicate( parser, "description", null, parsed ) )
870            {
871                mojo.setDescription( interpolatedTrimmed( parser.nextText(), "description" ) );
872            }
873            else if ( checkFieldWithDuplicate( parser, "deprecated", null, parsed ) )
874            {
875                mojo.setDeprecation( interpolatedTrimmed( parser.nextText(), "deprecated" ) );
876            }
877            else if ( checkFieldWithDuplicate( parser, "since", null, parsed ) )
878            {
879                mojo.setSince( interpolatedTrimmed( parser.nextText(), "since" ) );
880            }
881            else if ( checkFieldWithDuplicate( parser, "call", null, parsed ) )
882            {
883                mojo.setCall( interpolatedTrimmed( parser.nextText(), "call" ) );
884            }
885            else
886            {
887                checkUnknownElement( parser, strict );
888            }
889        }
890        return mojo;
891    } //-- Mojo parseMojo( XmlPullParser, boolean )
892
893    /**
894     * Method parseParameter.
895     * 
896     * @param parser a parser object.
897     * @param strict a strict object.
898     * @throws IOException IOException if any.
899     * @throws XmlPullParserException XmlPullParserException if
900     * any.
901     * @return Parameter
902     */
903    private Parameter parseParameter( XmlPullParser parser, boolean strict )
904        throws IOException, XmlPullParserException
905    {
906        String tagName = parser.getName();
907        Parameter parameter = new Parameter();
908        for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
909        {
910            String name = parser.getAttributeName( i );
911            String value = parser.getAttributeValue( i );
912
913            if ( name.indexOf( ':' ) >= 0 )
914            {
915                // just ignore attributes with non-default namespace (for example: xmlns:xsi)
916            }
917            else
918            {
919                checkUnknownAttribute( parser, name, tagName, strict );
920            }
921        }
922        java.util.Set parsed = new java.util.HashSet();
923        while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
924        {
925            if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
926            {
927                parameter.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
928            }
929            else if ( checkFieldWithDuplicate( parser, "alias", null, parsed ) )
930            {
931                parameter.setAlias( interpolatedTrimmed( parser.nextText(), "alias" ) );
932            }
933            else if ( checkFieldWithDuplicate( parser, "property", null, parsed ) )
934            {
935                parameter.setProperty( interpolatedTrimmed( parser.nextText(), "property" ) );
936            }
937            else if ( checkFieldWithDuplicate( parser, "required", null, parsed ) )
938            {
939                parameter.setRequired( getBooleanValue( interpolatedTrimmed( parser.nextText(), "required" ), "required", parser, "false" ) );
940            }
941            else if ( checkFieldWithDuplicate( parser, "readonly", null, parsed ) )
942            {
943                parameter.setReadonly( getBooleanValue( interpolatedTrimmed( parser.nextText(), "readonly" ), "readonly", parser, "false" ) );
944            }
945            else if ( checkFieldWithDuplicate( parser, "expression", null, parsed ) )
946            {
947                parameter.setExpression( interpolatedTrimmed( parser.nextText(), "expression" ) );
948            }
949            else if ( checkFieldWithDuplicate( parser, "defaultValue", null, parsed ) )
950            {
951                parameter.setDefaultValue( interpolatedTrimmed( parser.nextText(), "defaultValue" ) );
952            }
953            else if ( checkFieldWithDuplicate( parser, "type", null, parsed ) )
954            {
955                parameter.setType( interpolatedTrimmed( parser.nextText(), "type" ) );
956            }
957            else if ( checkFieldWithDuplicate( parser, "description", null, parsed ) )
958            {
959                parameter.setDescription( interpolatedTrimmed( parser.nextText(), "description" ) );
960            }
961            else if ( checkFieldWithDuplicate( parser, "deprecated", null, parsed ) )
962            {
963                parameter.setDeprecation( interpolatedTrimmed( parser.nextText(), "deprecated" ) );
964            }
965            else if ( checkFieldWithDuplicate( parser, "since", null, parsed ) )
966            {
967                parameter.setSince( interpolatedTrimmed( parser.nextText(), "since" ) );
968            }
969            else
970            {
971                checkUnknownElement( parser, strict );
972            }
973        }
974        return parameter;
975    } //-- Parameter parseParameter( XmlPullParser, boolean )
976
977    /**
978     * Method parsePluginMetadata.
979     * 
980     * @param parser a parser object.
981     * @param strict a strict object.
982     * @throws IOException IOException if any.
983     * @throws XmlPullParserException XmlPullParserException if
984     * any.
985     * @return PluginMetadata
986     */
987    private PluginMetadata parsePluginMetadata( XmlPullParser parser, boolean strict )
988        throws IOException, XmlPullParserException
989    {
990        String tagName = parser.getName();
991        PluginMetadata pluginMetadata = new PluginMetadata();
992        for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
993        {
994            String name = parser.getAttributeName( i );
995            String value = parser.getAttributeValue( i );
996
997            if ( name.indexOf( ':' ) >= 0 )
998            {
999                // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1000            }
1001            else if ( "xmlns".equals( name ) )
1002            {
1003                // ignore xmlns attribute in root class, which is a reserved attribute name
1004            }
1005            else
1006            {
1007                checkUnknownAttribute( parser, name, tagName, strict );
1008            }
1009        }
1010        java.util.Set parsed = new java.util.HashSet();
1011        while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1012        {
1013            if ( checkFieldWithDuplicate( parser, "mojos", null, parsed ) )
1014            {
1015                java.util.List<Mojo> mojos = new java.util.ArrayList<Mojo>();
1016                while ( parser.nextTag() == XmlPullParser.START_TAG )
1017                {
1018                    if ( "mojo".equals( parser.getName() ) )
1019                    {
1020                        mojos.add( parseMojo( parser, strict ) );
1021                    }
1022                    else
1023                    {
1024                        checkUnknownElement( parser, strict );
1025                    }
1026                }
1027                pluginMetadata.setMojos( mojos );
1028            }
1029            else
1030            {
1031                checkUnknownElement( parser, strict );
1032            }
1033        }
1034        return pluginMetadata;
1035    } //-- PluginMetadata parsePluginMetadata( 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}