• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Javassist, a Java-bytecode translator toolkit.
3  * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License.  Alternatively, the contents of this file may be used under
8  * the terms of the GNU Lesser General Public License Version 2.1 or later,
9  * or the Apache License Version 2.0.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  */
16 
17 package javassist;
18 
19 /**
20  * An observer of <code>Loader</code>.
21  * The users can define a class implementing this
22  * interface and attach an instance of that class to a
23  * <code>Loader</code> object so that it can translate a class file
24  * when the class file is loaded into the JVM.
25  *
26  * @see Loader#addTranslator(ClassPool, Translator)
27  */
28 public interface Translator {
29     /**
30      * Is invoked by a <code>Loader</code> for initialization
31      * when the object is attached to the <code>Loader</code> object.
32      * This method can be used for getting (for caching) some
33      * <code>CtClass</code> objects that will be accessed
34      * in <code>onLoad()</code> in <code>Translator</code>.
35      *
36      * @param pool      the <code>ClassPool</code> that this translator
37      *                          should use.
38      * @see Loader
39      * @throws NotFoundException    if a <code>CtClass</code> cannot be found.
40      * @throws CannotCompileException   if the initialization by this method
41      *                                  fails.
42      */
start(ClassPool pool)43     void start(ClassPool pool)
44         throws NotFoundException, CannotCompileException;
45 
46     /**
47      * Is invoked by a <code>Loader</code> for notifying that
48      * a class is loaded.  The <code>Loader</code> calls
49      *
50      * <pre>
51      * pool.get(classname).toBytecode()</pre>
52      *
53      * to read the class file after <code>onLoad()</code> returns.
54      *
55      * <p><code>classname</code> may be the name of a class
56      * that has not been created yet.
57      * If so, <code>onLoad()</code> must create that class so that
58      * the <code>Loader</code> can read it after <code>onLoad()</code>
59      * returns.
60      *
61      * @param pool      the <code>ClassPool</code> that this translator
62      *                          should use.
63      * @param classname     the name of the class being loaded.
64      * @see Loader
65      * @throws NotFoundException    if a <code>CtClass</code> cannot be found.
66      * @throws CannotCompileException   if the code transformation
67      *                                  by this method fails.
68      */
onLoad(ClassPool pool, String classname)69     void onLoad(ClassPool pool, String classname)
70         throws NotFoundException, CannotCompileException;
71 }
72