KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > generation > enhancer > ClassInterfaceAdder


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  * Authors: S.Chassande-Barrioz.
25  *
26  */

27 package org.objectweb.speedo.generation.enhancer;
28
29 import org.objectweb.asm.ClassVisitor;
30 import org.objectweb.util.monolog.api.BasicLevel;
31 import org.objectweb.util.monolog.api.Logger;
32
33 import java.util.List JavaDoc;
34
35 public class ClassInterfaceAdder extends LoggedClassAdapter {
36
37     private List JavaDoc itfs;
38
39     public ClassInterfaceAdder(ClassVisitor classVisitor,
40                                List JavaDoc itfs,
41                                Logger logger) {
42         super(classVisitor, logger);
43         this.itfs = itfs;
44     }
45
46     public void visit(final int version, final int access,
47                       final String JavaDoc name,
48                       final String JavaDoc superName,
49                       final String JavaDoc[] interfaces,
50                       final String JavaDoc sourceFile) {
51         // just stores the interfaces implemented by the visited class
52
if (interfaces != null) {
53             for (int i = 0; i < interfaces.length; ++i) {
54                 if (!itfs.contains(interfaces[i])) {
55                     if (debug) {
56                         logger.log(BasicLevel.DEBUG,
57                                 "Add the interface '" + interfaces[i] + "'");
58                     }
59                     itfs.add(interfaces[i]);
60                 }
61             }
62         }
63         String JavaDoc[] newInterfaces = (String JavaDoc[]) itfs.toArray(new String JavaDoc[itfs.size()]);
64         cv.visit(version, access, name, superName, newInterfaces, sourceFile);
65     }
66 }
67
Popular Tags