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.toolchain.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.toolchain.model.PersistedToolchains;
17  import org.apache.maven.toolchain.model.ToolchainModel;
18  import org.apache.maven.toolchain.model.TrackableBase;
19  import org.codehaus.plexus.util.ReaderFactory;
20  import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
21  import org.codehaus.plexus.util.xml.pull.MXParser;
22  import org.codehaus.plexus.util.xml.pull.XmlPullParser;
23  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
24  
25  /**
26   * Class MavenToolchainsXpp3Reader.
27   * 
28   * @version $Revision$ $Date$
29   */
30  @SuppressWarnings( "all" )
31  public class MavenToolchainsXpp3Reader
32  {
33  
34        //--------------------------/
35       //- Class/Member Variables -/
36      //--------------------------/
37  
38      /**
39       * If set the parser will be loaded with all single characters
40       * from the XHTML specification.
41       * The entities used:
42       * <ul>
43       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</li>
44       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</li>
45       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</li>
46       * </ul>
47       */
48      private boolean addDefaultEntities = true;
49  
50      /**
51       * Field contentTransformer.
52       */
53      public final ContentTransformer contentTransformer;
54  
55  
56        //----------------/
57       //- Constructors -/
58      //----------------/
59  
60      public MavenToolchainsXpp3Reader()
61      {
62          this( new ContentTransformer()
63          {
64              public String transform( String source, String fieldName )
65              {
66                  return source;
67              }
68          } );
69      } //-- org.apache.maven.toolchain.model.io.xpp3.MavenToolchainsXpp3Reader()
70  
71      public MavenToolchainsXpp3Reader(ContentTransformer contentTransformer)
72      {
73          this.contentTransformer = contentTransformer;
74      } //-- org.apache.maven.toolchain.model.io.xpp3.MavenToolchainsXpp3Reader(ContentTransformer)
75  
76  
77        //-----------/
78       //- Methods -/
79      //-----------/
80  
81      /**
82       * Method checkFieldWithDuplicate.
83       * 
84       * @param parser a parser object.
85       * @param parsed a parsed object.
86       * @param alias a alias object.
87       * @param tagName a tagName object.
88       * @throws XmlPullParserException XmlPullParserException if
89       * any.
90       * @return boolean
91       */
92      private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed )
93          throws XmlPullParserException
94      {
95          if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
96          {
97              return false;
98          }
99          if ( !parsed.add( tagName ) )
100         {
101             throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
102         }
103         return true;
104     } //-- boolean checkFieldWithDuplicate( XmlPullParser, String, String, java.util.Set )
105 
106     /**
107      * Method checkUnknownAttribute.
108      * 
109      * @param parser a parser object.
110      * @param strict a strict object.
111      * @param tagName a tagName object.
112      * @param attribute a attribute object.
113      * @throws XmlPullParserException XmlPullParserException if
114      * any.
115      * @throws IOException IOException if any.
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 a parser object.
131      * @param strict a strict object.
132      * @throws XmlPullParserException XmlPullParserException if
133      * any.
134      * @throws IOException IOException if any.
135      */
136     private void checkUnknownElement( XmlPullParser parser, boolean strict )
137         throws XmlPullParserException, IOException
138     {
139         if ( strict )
140         {
141             throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
142         }
143 
144         for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
145         {
146             int eventType = parser.next();
147             if ( eventType == XmlPullParser.START_TAG )
148             {
149                 unrecognizedTagCount++;
150             }
151             else if ( eventType == XmlPullParser.END_TAG )
152             {
153                 unrecognizedTagCount--;
154             }
155         }
156     } //-- void checkUnknownElement( XmlPullParser, boolean )
157 
158     /**
159      * Returns the state of the "add default entities" flag.
160      * 
161      * @return boolean
162      */
163     public boolean getAddDefaultEntities()
164     {
165         return addDefaultEntities;
166     } //-- boolean getAddDefaultEntities()
167 
168     /**
169      * Method getBooleanValue.
170      * 
171      * @param s a s object.
172      * @param parser a parser object.
173      * @param attribute a attribute object.
174      * @throws XmlPullParserException XmlPullParserException if
175      * any.
176      * @return boolean
177      */
178     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser )
179         throws XmlPullParserException
180     {
181         return getBooleanValue( s, attribute, parser, null );
182     } //-- boolean getBooleanValue( String, String, XmlPullParser )
183 
184     /**
185      * Method getBooleanValue.
186      * 
187      * @param s a s object.
188      * @param defaultValue a defaultValue object.
189      * @param parser a parser object.
190      * @param attribute a attribute object.
191      * @throws XmlPullParserException XmlPullParserException if
192      * any.
193      * @return boolean
194      */
195     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue )
196         throws XmlPullParserException
197     {
198         if ( s != null && s.length() != 0 )
199         {
200             return Boolean.valueOf( s ).booleanValue();
201         }
202         if ( defaultValue != null )
203         {
204             return Boolean.valueOf( defaultValue ).booleanValue();
205         }
206         return false;
207     } //-- boolean getBooleanValue( String, String, XmlPullParser, String )
208 
209     /**
210      * Method getByteValue.
211      * 
212      * @param s a s object.
213      * @param strict a strict object.
214      * @param parser a parser object.
215      * @param attribute a attribute object.
216      * @throws XmlPullParserException XmlPullParserException if
217      * any.
218      * @return byte
219      */
220     private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict )
221         throws XmlPullParserException
222     {
223         if ( s != null )
224         {
225             try
226             {
227                 return Byte.valueOf( s ).byteValue();
228             }
229             catch ( NumberFormatException nfe )
230             {
231                 if ( strict )
232                 {
233                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe );
234                 }
235             }
236         }
237         return 0;
238     } //-- byte getByteValue( String, String, XmlPullParser, boolean )
239 
240     /**
241      * Method getCharacterValue.
242      * 
243      * @param s a s object.
244      * @param parser a parser object.
245      * @param attribute a attribute object.
246      * @throws XmlPullParserException XmlPullParserException if
247      * any.
248      * @return char
249      */
250     private char getCharacterValue( String s, String attribute, XmlPullParser parser )
251         throws XmlPullParserException
252     {
253         if ( s != null )
254         {
255             return s.charAt( 0 );
256         }
257         return 0;
258     } //-- char getCharacterValue( String, String, XmlPullParser )
259 
260     /**
261      * Method getDateValue.
262      * 
263      * @param s a s object.
264      * @param parser a parser object.
265      * @param attribute a attribute object.
266      * @throws XmlPullParserException XmlPullParserException if
267      * any.
268      * @return Date
269      */
270     private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser )
271         throws XmlPullParserException
272     {
273         return getDateValue( s, attribute, null, parser );
274     } //-- java.util.Date getDateValue( String, String, XmlPullParser )
275 
276     /**
277      * Method getDateValue.
278      * 
279      * @param s a s object.
280      * @param parser a parser object.
281      * @param dateFormat a dateFormat object.
282      * @param attribute a attribute object.
283      * @throws XmlPullParserException XmlPullParserException if
284      * any.
285      * @return Date
286      */
287     private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser )
288         throws XmlPullParserException
289     {
290         if ( s != null )
291         {
292             String effectiveDateFormat = dateFormat;
293             if ( dateFormat == null )
294             {
295                 effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
296             }
297             if ( "long".equals( effectiveDateFormat ) )
298             {
299                 try
300                 {
301                     return new java.util.Date( Long.parseLong( s ) );
302                 }
303                 catch ( NumberFormatException e )
304                 {
305                     throw new XmlPullParserException( e.getMessage(), parser, e );
306                 }
307             }
308             else
309             {
310                 try
311                 {
312                     DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US );
313                     return dateParser.parse( s );
314                 }
315                 catch ( java.text.ParseException e )
316                 {
317                     throw new XmlPullParserException( e.getMessage(), parser, e );
318                 }
319             }
320         }
321         return null;
322     } //-- java.util.Date getDateValue( String, String, String, XmlPullParser )
323 
324     /**
325      * Method getDoubleValue.
326      * 
327      * @param s a s object.
328      * @param strict a strict object.
329      * @param parser a parser object.
330      * @param attribute a attribute object.
331      * @throws XmlPullParserException XmlPullParserException if
332      * any.
333      * @return double
334      */
335     private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict )
336         throws XmlPullParserException
337     {
338         if ( s != null )
339         {
340             try
341             {
342                 return Double.valueOf( s ).doubleValue();
343             }
344             catch ( NumberFormatException nfe )
345             {
346                 if ( strict )
347                 {
348                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
349                 }
350             }
351         }
352         return 0;
353     } //-- double getDoubleValue( String, String, XmlPullParser, boolean )
354 
355     /**
356      * Method getFloatValue.
357      * 
358      * @param s a s object.
359      * @param strict a strict object.
360      * @param parser a parser object.
361      * @param attribute a attribute object.
362      * @throws XmlPullParserException XmlPullParserException if
363      * any.
364      * @return float
365      */
366     private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict )
367         throws XmlPullParserException
368     {
369         if ( s != null )
370         {
371             try
372             {
373                 return Float.valueOf( s ).floatValue();
374             }
375             catch ( NumberFormatException nfe )
376             {
377                 if ( strict )
378                 {
379                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
380                 }
381             }
382         }
383         return 0;
384     } //-- float getFloatValue( String, String, XmlPullParser, boolean )
385 
386     /**
387      * Method getIntegerValue.
388      * 
389      * @param s a s object.
390      * @param strict a strict object.
391      * @param parser a parser object.
392      * @param attribute a attribute object.
393      * @throws XmlPullParserException XmlPullParserException if
394      * any.
395      * @return int
396      */
397     private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict )
398         throws XmlPullParserException
399     {
400         if ( s != null )
401         {
402             try
403             {
404                 return Integer.valueOf( s ).intValue();
405             }
406             catch ( NumberFormatException nfe )
407             {
408                 if ( strict )
409                 {
410                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
411                 }
412             }
413         }
414         return 0;
415     } //-- int getIntegerValue( String, String, XmlPullParser, boolean )
416 
417     /**
418      * Method getLongValue.
419      * 
420      * @param s a s object.
421      * @param strict a strict object.
422      * @param parser a parser object.
423      * @param attribute a attribute object.
424      * @throws XmlPullParserException XmlPullParserException if
425      * any.
426      * @return long
427      */
428     private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict )
429         throws XmlPullParserException
430     {
431         if ( s != null )
432         {
433             try
434             {
435                 return Long.valueOf( s ).longValue();
436             }
437             catch ( NumberFormatException nfe )
438             {
439                 if ( strict )
440                 {
441                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe );
442                 }
443             }
444         }
445         return 0;
446     } //-- long getLongValue( String, String, XmlPullParser, boolean )
447 
448     /**
449      * Method getRequiredAttributeValue.
450      * 
451      * @param s a s object.
452      * @param strict a strict object.
453      * @param parser a parser object.
454      * @param attribute a attribute object.
455      * @throws XmlPullParserException XmlPullParserException if
456      * any.
457      * @return String
458      */
459     private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict )
460         throws XmlPullParserException
461     {
462         if ( s == null )
463         {
464             if ( strict )
465             {
466                 throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null );
467             }
468         }
469         return s;
470     } //-- String getRequiredAttributeValue( String, String, XmlPullParser, boolean )
471 
472     /**
473      * Method getShortValue.
474      * 
475      * @param s a s object.
476      * @param strict a strict object.
477      * @param parser a parser object.
478      * @param attribute a attribute object.
479      * @throws XmlPullParserException XmlPullParserException if
480      * any.
481      * @return short
482      */
483     private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict )
484         throws XmlPullParserException
485     {
486         if ( s != null )
487         {
488             try
489             {
490                 return Short.valueOf( s ).shortValue();
491             }
492             catch ( NumberFormatException nfe )
493             {
494                 if ( strict )
495                 {
496                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe );
497                 }
498             }
499         }
500         return 0;
501     } //-- short getShortValue( String, String, XmlPullParser, boolean )
502 
503     /**
504      * Method getTrimmedValue.
505      * 
506      * @param s a s object.
507      * @return String
508      */
509     private String getTrimmedValue( String s )
510     {
511         if ( s != null )
512         {
513             s = s.trim();
514         }
515         return s;
516     } //-- String getTrimmedValue( String )
517 
518     /**
519      * Method interpolatedTrimmed.
520      * 
521      * @param value a value object.
522      * @param context a context object.
523      * @return String
524      */
525     private String interpolatedTrimmed( String value, String context )
526     {
527         return getTrimmedValue( contentTransformer.transform( value, context ) );
528     } //-- String interpolatedTrimmed( String, String )
529 
530     /**
531      * Method nextTag.
532      * 
533      * @param parser a parser object.
534      * @throws IOException IOException if any.
535      * @throws XmlPullParserException XmlPullParserException if
536      * any.
537      * @return int
538      */
539     private int nextTag( XmlPullParser parser )
540         throws IOException, XmlPullParserException
541     {
542         int eventType = parser.next();
543         if ( eventType == XmlPullParser.TEXT )
544         {
545             eventType = parser.next();
546         }
547         if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
548         {
549             throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
550         }
551         return eventType;
552     } //-- int nextTag( XmlPullParser )
553 
554     /**
555      * @see ReaderFactory#newXmlReader
556      * 
557      * @param reader a reader object.
558      * @param strict a strict object.
559      * @throws IOException IOException if any.
560      * @throws XmlPullParserException XmlPullParserException if
561      * any.
562      * @return PersistedToolchains
563      */
564     public PersistedToolchains read( Reader reader, boolean strict )
565         throws IOException, XmlPullParserException
566     {
567         XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
568 
569         parser.setInput( reader );
570 
571 
572         return read( parser, strict );
573     } //-- PersistedToolchains read( Reader, boolean )
574 
575     /**
576      * @see ReaderFactory#newXmlReader
577      * 
578      * @param reader a reader object.
579      * @throws IOException IOException if any.
580      * @throws XmlPullParserException XmlPullParserException if
581      * any.
582      * @return PersistedToolchains
583      */
584     public PersistedToolchains read( Reader reader )
585         throws IOException, XmlPullParserException
586     {
587         return read( reader, true );
588     } //-- PersistedToolchains read( Reader )
589 
590     /**
591      * Method read.
592      * 
593      * @param in a in object.
594      * @param strict a strict object.
595      * @throws IOException IOException if any.
596      * @throws XmlPullParserException XmlPullParserException if
597      * any.
598      * @return PersistedToolchains
599      */
600     public PersistedToolchains read( InputStream in, boolean strict )
601         throws IOException, XmlPullParserException
602     {
603         return read( ReaderFactory.newXmlReader( in ), strict );
604     } //-- PersistedToolchains read( InputStream, boolean )
605 
606     /**
607      * Method read.
608      * 
609      * @param in a in object.
610      * @throws IOException IOException if any.
611      * @throws XmlPullParserException XmlPullParserException if
612      * any.
613      * @return PersistedToolchains
614      */
615     public PersistedToolchains read( InputStream in )
616         throws IOException, XmlPullParserException
617     {
618         return read( ReaderFactory.newXmlReader( in ) );
619     } //-- PersistedToolchains read( InputStream )
620 
621     /**
622      * Method parsePersistedToolchains.
623      * 
624      * @param parser a parser object.
625      * @param strict a strict object.
626      * @throws IOException IOException if any.
627      * @throws XmlPullParserException XmlPullParserException if
628      * any.
629      * @return PersistedToolchains
630      */
631     private PersistedToolchains parsePersistedToolchains( XmlPullParser parser, boolean strict )
632         throws IOException, XmlPullParserException
633     {
634         String tagName = parser.getName();
635         PersistedToolchains persistedToolchains = new PersistedToolchains();
636         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
637         {
638             String name = parser.getAttributeName( i );
639             String value = parser.getAttributeValue( i );
640 
641             if ( name.indexOf( ':' ) >= 0 )
642             {
643                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
644             }
645             else if ( "xmlns".equals( name ) )
646             {
647                 // ignore xmlns attribute in root class, which is a reserved attribute name
648             }
649             else
650             {
651                 checkUnknownAttribute( parser, name, tagName, strict );
652             }
653         }
654         java.util.Set parsed = new java.util.HashSet();
655         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
656         {
657             if ( "toolchain".equals( parser.getName() ) )
658             {
659                 java.util.List<ToolchainModel> toolchains = persistedToolchains.getToolchains();
660                 if ( toolchains == null )
661                 {
662                     toolchains = new java.util.ArrayList<ToolchainModel>();
663                     persistedToolchains.setToolchains( toolchains );
664                 }
665                 toolchains.add( parseToolchainModel( parser, strict ) );
666             }
667             else
668             {
669                 checkUnknownElement( parser, strict );
670             }
671         }
672         return persistedToolchains;
673     } //-- PersistedToolchains parsePersistedToolchains( XmlPullParser, boolean )
674 
675     /**
676      * Method parseToolchainModel.
677      * 
678      * @param parser a parser object.
679      * @param strict a strict object.
680      * @throws IOException IOException if any.
681      * @throws XmlPullParserException XmlPullParserException if
682      * any.
683      * @return ToolchainModel
684      */
685     private ToolchainModel parseToolchainModel( XmlPullParser parser, boolean strict )
686         throws IOException, XmlPullParserException
687     {
688         String tagName = parser.getName();
689         ToolchainModel toolchainModel = new ToolchainModel();
690         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
691         {
692             String name = parser.getAttributeName( i );
693             String value = parser.getAttributeValue( i );
694 
695             if ( name.indexOf( ':' ) >= 0 )
696             {
697                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
698             }
699             else
700             {
701                 checkUnknownAttribute( parser, name, tagName, strict );
702             }
703         }
704         java.util.Set parsed = new java.util.HashSet();
705         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
706         {
707             if ( checkFieldWithDuplicate( parser, "type", null, parsed ) )
708             {
709                 toolchainModel.setType( interpolatedTrimmed( parser.nextText(), "type" ) );
710             }
711             else if ( checkFieldWithDuplicate( parser, "provides", null, parsed ) )
712             {
713                 while ( parser.nextTag() == XmlPullParser.START_TAG )
714                 {
715                     String key = parser.getName();
716                     String value = parser.nextText().trim();
717                     toolchainModel.addProvide( key, value );
718                 }
719             }
720             else if ( checkFieldWithDuplicate( parser, "configuration", null, parsed ) )
721             {
722                 toolchainModel.setConfiguration( org.codehaus.plexus.util.xml.Xpp3DomBuilder.build( parser, true ) );
723             }
724             else
725             {
726                 checkUnknownElement( parser, strict );
727             }
728         }
729         return toolchainModel;
730     } //-- ToolchainModel parseToolchainModel( XmlPullParser, boolean )
731 
732     /**
733      * Method parseTrackableBase.
734      * 
735      * @param parser a parser object.
736      * @param strict a strict object.
737      * @throws IOException IOException if any.
738      * @throws XmlPullParserException XmlPullParserException if
739      * any.
740      * @return TrackableBase
741      */
742     private TrackableBase parseTrackableBase( XmlPullParser parser, boolean strict )
743         throws IOException, XmlPullParserException
744     {
745         String tagName = parser.getName();
746         TrackableBase trackableBase = new TrackableBase();
747         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
748         {
749             String name = parser.getAttributeName( i );
750             String value = parser.getAttributeValue( i );
751 
752             if ( name.indexOf( ':' ) >= 0 )
753             {
754                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
755             }
756             else
757             {
758                 checkUnknownAttribute( parser, name, tagName, strict );
759             }
760         }
761         java.util.Set parsed = new java.util.HashSet();
762         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
763         {
764             checkUnknownElement( parser, strict );
765         }
766         return trackableBase;
767     } //-- TrackableBase parseTrackableBase( XmlPullParser, boolean )
768 
769     /**
770      * Method read.
771      * 
772      * @param parser a parser object.
773      * @param strict a strict object.
774      * @throws IOException IOException if any.
775      * @throws XmlPullParserException XmlPullParserException if
776      * any.
777      * @return PersistedToolchains
778      */
779     private PersistedToolchains read( XmlPullParser parser, boolean strict )
780         throws IOException, XmlPullParserException
781     {
782         PersistedToolchains persistedToolchains = null;
783         int eventType = parser.getEventType();
784         boolean parsed = false;
785         while ( eventType != XmlPullParser.END_DOCUMENT )
786         {
787             if ( eventType == XmlPullParser.START_TAG )
788             {
789                 if ( strict && ! "toolchains".equals( parser.getName() ) )
790                 {
791                     throw new XmlPullParserException( "Expected root element 'toolchains' but found '" + parser.getName() + "'", parser, null );
792                 }
793                 else if ( parsed )
794                 {
795                     // fallback, already expected a XmlPullParserException due to invalid XML
796                     throw new XmlPullParserException( "Duplicated tag: 'toolchains'", parser, null );
797                 }
798                 persistedToolchains = parsePersistedToolchains( parser, strict );
799                 persistedToolchains.setModelEncoding( parser.getInputEncoding() );
800                 parsed = true;
801             }
802             eventType = parser.next();
803         }
804         if ( parsed )
805         {
806             return persistedToolchains;
807         }
808         throw new XmlPullParserException( "Expected root element 'toolchains' but found no element at all: invalid XML document", parser, null );
809     } //-- PersistedToolchains read( XmlPullParser, boolean )
810 
811     /**
812      * Sets the state of the "add default entities" flag.
813      * 
814      * @param addDefaultEntities a addDefaultEntities object.
815      */
816     public void setAddDefaultEntities( boolean addDefaultEntities )
817     {
818         this.addDefaultEntities = addDefaultEntities;
819     } //-- void setAddDefaultEntities( boolean )
820 
821     public static interface ContentTransformer
822 {
823     /**
824      * Interpolate the value read from the xpp3 document
825      * @param source The source value
826      * @param fieldName A description of the field being interpolated. The implementation may use this to
827      *                           log stuff.
828      * @return The interpolated value.
829      */
830     String transform( String source, String fieldName );
831 }
832 
833 }