View Javadoc

1   // ========================================================================
2   // Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.annotations;
15  
16  import java.util.List;
17  
18  import org.eclipse.jetty.annotations.AnnotationParser.ClassHandler;
19  import org.eclipse.jetty.util.MultiMap;
20  import org.eclipse.jetty.util.log.Log;
21  
22  /**
23   * ClassInheritanceHandler
24   *
25   * As asm scans for classes, remember the type hierarchy.
26   */
27  public class ClassInheritanceHandler implements ClassHandler
28  {
29      
30      MultiMap _inheritanceMap = new MultiMap();
31      
32      public ClassInheritanceHandler()
33      {
34      }
35  
36      public void handle(String className, int version, int access, String signature, String superName, String[] interfaces)
37      {
38          try
39          {
40              for (int i=0; interfaces != null && i<interfaces.length;i++)
41              {
42                  _inheritanceMap.add (interfaces[i], className);
43              }
44              //To save memory, we don't record classes that only extend Object, as that can be assumed
45              if (!"java.lang.Object".equals(superName))
46                  _inheritanceMap.add(superName, className);
47          }
48          catch (Exception e)
49          {
50              Log.warn(e);
51          }  
52      }
53      
54      public List getClassNamesExtendingOrImplementing (String className)
55      {
56          return _inheritanceMap.getValues(className);
57      }
58      
59      public MultiMap getMap ()
60      {
61          return _inheritanceMap;
62      }
63  }