View Javadoc

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.compiler;
9   
10  import com.thoughtworks.qdox.model.JavaClass;
11  
12  /***
13   * Multicast filter for passing a JavaClass through multiple filters.
14   *
15   * @author Peter Donald
16   * @version $Revision: 1.4 $ $Date: 2003/11/27 08:09:53 $
17   */
18  class MulticastJavaClassFilter
19      implements JavaClassFilter
20  {
21      /***
22       * The filters to iterate over.
23       */
24      private final JavaClassFilter[] m_filters;
25  
26      /***
27       * Create a multicast filter for specified filters.
28       *
29       * @param filters the filters
30       */
31      public MulticastJavaClassFilter( final JavaClassFilter[] filters )
32      {
33          if( null == filters )
34          {
35              throw new NullPointerException( "filters" );
36          }
37          for( int i = 0; i < filters.length; i++ )
38          {
39              if( null == filters[ i ] )
40              {
41                  throw new NullPointerException( "filters[" + i + "]" );
42              }
43          }
44          m_filters = filters;
45      }
46  
47      /***
48       * This method provides an access point for subclasses to use custom filters
49       * on the list of classes parsed, i.e. to return null if the class has been filtered.
50       *
51       * @param javaClass the JavaClass
52       * @return javaClass or null
53       */
54      public JavaClass filterClass( final JavaClass javaClass )
55      {
56          JavaClass result = javaClass;
57          for( int i = 0; i < m_filters.length; i++ )
58          {
59              result = m_filters[ i ].filterClass( result );
60              if( null == result )
61              {
62                  return null;
63              }
64          }
65          return result;
66      }
67  }