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