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 import org.eclipse.jetty.util.log.Logger;
22
23 /**
24 * ClassInheritanceHandler
25 *
26 * As asm scans for classes, remember the type hierarchy.
27 */
28 public class ClassInheritanceHandler implements ClassHandler
29 {
30 private static final Logger LOG = Log.getLogger(ClassInheritanceHandler.class);
31
32
33 MultiMap _inheritanceMap = new MultiMap();
34
35 public ClassInheritanceHandler()
36 {
37 }
38
39 public void handle(String className, int version, int access, String signature, String superName, String[] interfaces)
40 {
41 try
42 {
43 for (int i=0; interfaces != null && i<interfaces.length;i++)
44 {
45 _inheritanceMap.add (interfaces[i], className);
46 }
47 //To save memory, we don't record classes that only extend Object, as that can be assumed
48 if (!"java.lang.Object".equals(superName))
49 _inheritanceMap.add(superName, className);
50 }
51 catch (Exception e)
52 {
53 LOG.warn(e);
54 }
55 }
56
57 public List getClassNamesExtendingOrImplementing (String className)
58 {
59 return _inheritanceMap.getValues(className);
60 }
61
62 public MultiMap getMap ()
63 {
64 return _inheritanceMap;
65 }
66 }