Clover coverage report - MetaClass - 1.1
Coverage timestamp: Tue Apr 27 2004 10:46:24 EST
file stats: LOC: 134   Methods: 5
NCLOC: 77   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
PluginSet.java 100% 100% 100% 100%
coverage
 1   
 /*
 2   
  * Copyright (C) The MetaClass Group. All rights reserved.
 3   
  *
 4   
  * This software is published under the terms of the Spice
 5   
  * Software License version 1.1, a copy of which has been included
 6   
  * with this distribution in the LICENSE.txt file.
 7   
  */
 8   
 package org.codehaus.metaclass.tools.tasks;
 9   
 
 10   
 import java.util.ArrayList;
 11   
 import java.util.Collection;
 12   
 import java.util.Iterator;
 13   
 import org.apache.tools.ant.BuildException;
 14   
 import org.apache.tools.ant.Project;
 15   
 import org.apache.tools.ant.types.DataType;
 16   
 import org.apache.tools.ant.types.Reference;
 17   
 
 18   
 /**
 19   
  * An Ant type that represents a set of Plugins.
 20   
  *
 21   
  * @author Peter Donald
 22   
  * @version $Revision: 1.3 $ $Date: 2003/11/29 09:28:02 $
 23   
  */
 24   
 public abstract class PluginSet
 25   
     extends DataType
 26   
 {
 27   
     /** Name for type of elements in set. */
 28   
     private final String m_type;
 29   
 
 30   
     /** Set of PluginElement objects. */
 31   
     private final ArrayList m_plugins = new ArrayList();
 32   
 
 33   
     /** Set of PluginSet objects. */
 34   
     private final ArrayList m_sets = new ArrayList();
 35   
 
 36   
     /**
 37   
      * Create plugin set for specified type.
 38   
      *
 39   
      * @param type the type
 40   
      */
 41  128
     protected PluginSet( final String type )
 42   
     {
 43  128
         if( null == type )
 44   
         {
 45  2
             throw new NullPointerException( "type" );
 46   
         }
 47  126
         m_type = type;
 48   
     }
 49   
 
 50   
     /**
 51   
      * Add a plugin to set.
 52   
      *
 53   
      * @param element the interceptor definition
 54   
      */
 55  18
     void addPlugin( final PluginElement element )
 56   
     {
 57  18
         m_plugins.add( element );
 58   
     }
 59   
 
 60   
     /**
 61   
      * Add a plugin to set.
 62   
      *
 63   
      * @param set the set
 64   
      */
 65  14
     void addPluginSet( final PluginSet set )
 66   
     {
 67  14
         m_sets.add( set );
 68   
     }
 69   
 
 70   
     /**
 71   
      * Convert PluginSet to a collection of plugins.
 72   
      *
 73   
      * @return the collection of Plugins
 74   
      */
 75  70
     Collection toPlugins()
 76   
     {
 77  70
         final Collection result = new ArrayList();
 78  70
         final Iterator elements = m_plugins.iterator();
 79  70
         while( elements.hasNext() )
 80   
         {
 81  16
             final PluginElement element = (PluginElement)elements.next();
 82  16
             if( null == element.getName() )
 83   
             {
 84  2
                 throw new BuildException( m_type + " must have a name" );
 85   
             }
 86   
         }
 87  68
         result.addAll( m_plugins );
 88  68
         final Iterator iterator = m_sets.iterator();
 89  68
         while( iterator.hasNext() )
 90   
         {
 91  12
             final PluginSet set = (PluginSet)iterator.next();
 92  12
             result.addAll( set.toPlugins() );
 93   
         }
 94  68
         return result;
 95   
     }
 96   
 
 97   
     /**
 98   
      * Makes this instance in effect a reference to another PluginSet instance.
 99   
      *
 100   
      * <p>You must not set another attribute or nest elements inside this
 101   
      * element if you make it a reference.</p>
 102   
      *
 103   
      * @param reference the reference to which this instance is associated
 104   
      * @throws BuildException if this instance already has been configured.
 105   
      */
 106  8
     public void setRefid( final Reference reference )
 107   
         throws BuildException
 108   
     {
 109  8
         if( !m_plugins.isEmpty() || !m_sets.isEmpty() )
 110   
         {
 111  2
             throw tooManyAttributes();
 112   
         }
 113   
         // change this to get the objects from the other reference
 114  6
         final Object object =
 115   
             reference.getReferencedObject( getProject() );
 116  6
         log( "Referencing " + object, Project.MSG_DEBUG );
 117  6
         final Class clazz = getClass();
 118  6
         if( clazz.isInstance( object ) )
 119   
         {
 120  4
             final PluginSet other = (PluginSet)object;
 121  4
             m_plugins.addAll( other.m_plugins );
 122  4
             m_sets.addAll( other.m_sets );
 123   
         }
 124   
         else
 125   
         {
 126  2
             final String message = reference.getRefId() +
 127   
                 " doesn\'t refer to a " + clazz.getName();
 128  2
             throw new BuildException( message );
 129   
         }
 130   
 
 131  4
         super.setRefid( reference );
 132   
     }
 133   
 }
 134