Coverage Report - org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlPlexusConfiguration
85 %
17/20
100 %
4/4
1,6
 
 1  
 package org.codehaus.plexus.configuration.xml;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2006 Codehaus Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.io.IOException;
 20  
 import java.io.StringWriter;
 21  
 
 22  
 import org.codehaus.plexus.configuration.DefaultPlexusConfiguration;
 23  
 import org.codehaus.plexus.configuration.io.XmlPlexusConfigurationWriter;
 24  
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 25  
 
 26  
 /**
 27  
  * @version $Id$
 28  
  */
 29  
 public class XmlPlexusConfiguration
 30  
     extends DefaultPlexusConfiguration
 31  
 {
 32  
     public XmlPlexusConfiguration()
 33  
     {
 34  33192
         super();
 35  33194
     }
 36  
 
 37  
     public XmlPlexusConfiguration( String name )
 38  
     {
 39  116
         super( name );
 40  116
     }
 41  
     
 42  
     public XmlPlexusConfiguration( String name, String value )
 43  
     {
 44  0
         super( name, value );
 45  0
     }
 46  
 
 47  
     public XmlPlexusConfiguration( Xpp3Dom dom )
 48  
     {
 49  15127
         super( dom.getName(), dom.getValue() );
 50  
 
 51  
         // attrs
 52  15130
         String[] attributes = dom.getAttributeNames();
 53  
 
 54  15346
         for (String attribute : attributes) {
 55  216
             setAttribute(attribute, dom.getAttribute(attribute));
 56  
         }
 57  
 
 58  
         // children
 59  15128
         int childCount = dom.getChildCount();
 60  29647
         for ( int i = 0; i < childCount; i++ )
 61  
         {
 62  14517
             addChild( new XmlPlexusConfiguration( dom.getChild( i ) ) );
 63  
         }
 64  15134
     }
 65  
 
 66  
     // ----------------------------------------------------------------------
 67  
     //
 68  
     // ----------------------------------------------------------------------
 69  
 
 70  
     public String toString()
 71  
     {
 72  3
         StringWriter sw = new StringWriter();
 73  
 
 74  3
         XmlPlexusConfigurationWriter xw = new XmlPlexusConfigurationWriter();
 75  
 
 76  
         try
 77  
         {
 78  3
             xw.write( sw, this );
 79  
         }
 80  0
         catch ( IOException e )
 81  
         {
 82  
             // will not happen with StringWriter
 83  3
         }
 84  
 
 85  3
         return sw.toString();
 86  
     }
 87  
 }