Package alt.jiapi.instrumentor

Source Code of alt.jiapi.instrumentor.CopyInstrumentor

/*
* Copyright (C) 2001 Mika Riekkinen, Joni Suominen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package alt.jiapi.instrumentor;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import org.apache.log4j.Category;

import alt.jiapi.Runtime;

import alt.jiapi.reflect.InstructionFactory;
import alt.jiapi.reflect.InstructionList;
import alt.jiapi.reflect.Loader;
import alt.jiapi.reflect.JiapiClass;
import alt.jiapi.reflect.JiapiField;
import alt.jiapi.reflect.JiapiMethod;

/**
* This patch can be used to copy instructions from one class
* to another.
*
* @author Mika Riekkinen
* @author Joni Suominen
* @version $Revision: 1.8 $ $Date: 2004/03/15 14:47:53 $
*/
public class CopyInstrumentor extends AbstractInstrumentor {
    private InstructionList source;

    /**
     * Construct a CopyInstrumentor from a given method.
     * The given method's instructions can then be copied elsewhere.
     * <p>
     * One may first wonder why this method can throw ClassNotFoundException
     * and NoSuchMethodException. The reason is that in some (rare) cases
     * Jiapi runtime might use different CLASSPATH or class loading
     * mechanism than calling client.
     *
     * @param sourceMethod a method for source instructions
     * @exception ClassNotFoundException thrown if the declaring class
     *            is not found
     * @exception NoSuchMethodException thrown if the class son't contain
     *            the requested method
     */
    public CopyInstrumentor(Method sourceMethod, Loader loader)
            throws ClassNotFoundException, NoSuchMethodException {

        // Load sourceMethod's instructions.
        //        Loader loader = getContext().getLoader();
        JiapiClass clazz = null;
        try {
            clazz=loader.loadClass(sourceMethod.getDeclaringClass().getName());
        }
        catch(java.io.IOException ioe) {
            ioe.printStackTrace();
            throw new ClassNotFoundException(sourceMethod.getDeclaringClass().getName());
        }

        Class[] parameterTypes = sourceMethod.getParameterTypes();
        String[] parameterTypeNames = new String[parameterTypes.length];
        for (int i = 0; i < parameterTypes.length; i++) {
            parameterTypeNames[i] = parameterTypes[i].getName();
        }

        JiapiMethod method = clazz.getMethod(sourceMethod.getName(),
                                             parameterTypeNames);
        source = method.getInstructionList();
    }

    /**
     * Construct a CopyInstrumentor from given instructions.
     * The given instructions can then be copied elsewhere.
     *
     * @param source source instructions
     */
    public CopyInstrumentor(InstructionList source) {
        this.source = source;
    }

    public void instrument(InstructionList il) {
        InstructionFactory factory =
            il.getDeclaringMethod().getInstructionFactory();

        if (true)
            throw new RuntimeException("NOT IMPLEMENTED");
//         il.add(factory.copy(source));
        forward(il);
    }
}
TOP

Related Classes of alt.jiapi.instrumentor.CopyInstrumentor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.