169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal/*
269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Javassist, a Java-bytecode translator toolkit.
369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Copyright (C) 1999-2007 Shigeru Chiba. All Rights Reserved.
469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal *
569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * The contents of this file are subject to the Mozilla Public License Version
669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 1.1 (the "License"); you may not use this file except in compliance with
769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the License.  Alternatively, the contents of this file may be used under
869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the terms of the GNU Lesser General Public License Version 2.1 or later.
969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal *
1069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Software distributed under the License is distributed on an "AS IS" basis,
1169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
1269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * for the specific language governing rights and limitations under the
1369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * License.
1469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */
1569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
1669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpackage javassist;
1769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
1869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal/**
1969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * An observer of <code>Loader</code>.
2069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * The users can define a class implementing this
2169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * interface and attach an instance of that class to a
2269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * <code>Loader</code> object so that it can translate a class file
2369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * when the class file is loaded into the JVM.
2469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal *
2569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * @see Loader#addTranslator(ClassPool, Translator)
2669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */
2769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpublic interface Translator {
2869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    /**
2969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Is invoked by a <code>Loader</code> for initialization
3069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * when the object is attached to the <code>Loader</code> object.
3169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * This method can be used for getting (for caching) some
3269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * <code>CtClass</code> objects that will be accessed
3369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * in <code>onLoad()</code> in <code>Translator</code>.
3469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     *
3569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * @param pool      the <code>ClassPool</code> that this translator
3669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     *                          should use.
3769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * @see Loader
3869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * @throws NotFoundException    if a <code>CtClass</code> cannot be found.
3969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * @throws CannotCompileException   if the initialization by this method
4069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     *                                  fails.
4169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     */
4269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    void start(ClassPool pool)
4369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        throws NotFoundException, CannotCompileException;
4469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
4569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    /**
4669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Is invoked by a <code>Loader</code> for notifying that
4769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * a class is loaded.  The <code>Loader</code> calls
4869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     *
4969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * <ul><pre>
5069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * pool.get(classname).toBytecode()</pre></ul>
5169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     *
5269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * to read the class file after <code>onLoad()</code> returns.
5369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     *
5469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * <p><code>classname</code> may be the name of a class
5569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * that has not been created yet.
5669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * If so, <code>onLoad()</code> must create that class so that
5769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * the <code>Loader</code> can read it after <code>onLoad()</code>
5869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * returns.
5969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     *
6069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * @param pool      the <code>ClassPool</code> that this translator
6169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     *                          should use.
6269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * @param classname     the name of the class being loaded.
6369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * @see Loader
6469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * @throws NotFoundException    if a <code>CtClass</code> cannot be found.
6569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * @throws CannotCompileException   if the code transformation
6669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     *                                  by this method fails.
6769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     */
6869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    void onLoad(ClassPool pool, String classname)
6969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        throws NotFoundException, CannotCompileException;
7069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal}
71