001/* ClassFileTransformer.java -- Implementation of this interface is used by an agent to 002 transform class files. 003 Copyright (C) 2005 Free Software Foundation, Inc. 004 005This file is part of GNU Classpath. 006 007GNU Classpath is free software; you can redistribute it and/or modify 008it under the terms of the GNU General Public License as published by 009the Free Software Foundation; either version 2, or (at your option) 010any later version. 011 012GNU Classpath is distributed in the hope that it will be useful, but 013WITHOUT ANY WARRANTY; without even the implied warranty of 014MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015General Public License for more details. 016 017You should have received a copy of the GNU General Public License 018along with GNU Classpath; see the file COPYING. If not, write to the 019Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02002110-1301 USA. 021 022Linking this library statically or dynamically with other modules is 023making a combined work based on this library. Thus, the terms and 024conditions of the GNU General Public License cover the whole 025combination. 026 027As a special exception, the copyright holders of this library give you 028permission to link this library with independent modules to produce an 029executable, regardless of the license terms of these independent 030modules, and to copy and distribute the resulting executable under 031terms of your choice, provided that you also meet, for each linked 032independent module, the terms and conditions of the license of that 033module. An independent module is a module which is not derived from 034or based on this library. If you modify this library, you may extend 035this exception to your version of the library, but you are not 036obligated to do so. If you do not wish to do so, delete this 037exception statement from your version. */ 038 039 040package java.lang.instrument; 041 042import java.security.ProtectionDomain; 043 044/** 045 * This interface should be implemented by classes wishing to transform 046 * classes bytecode when defining or redefining classes. 047 * 048 * @author Nicolas Geoffray (nicolas.geoffray@menlina.com) 049 * @see Instrumentation 050 * @see Instrumentation#addTransformer(java.lang.instrument.ClassFileTransformer) 051 * @see Instrumentation#removeTransformer(java.lang.instrument.ClassFileTransformer) 052 * @since 1.5 053 */ 054public interface ClassFileTransformer 055{ 056 057 /** 058 * Implementation of this method transforms a class by redefining its 059 * bytecodes. Once a ClassFileTransformer object registers itself to the 060 * Instrumentation object, this method will be called each time a class is 061 * defined (<code>ClassLoader.defineClass</code>) or redefined 062 * (<code>Instrumentation.redefineClasses</code>) 063 * @param loader the loader of the class 064 * @param className the name of the class with packages separated with "/" 065 * @param classBeingRedefined the class being redefined if it's the case, 066 * null otherwise 067 * @param protectionDomain the protection domain of the class being defined or 068 * redefined 069 * @param classfileBuffer the input byte buffer in class file format 070 * 071 * @return a class file buffer or null when no transformation has been performed 072 * 073 * @throws IllegalClassFormatException if the byte buffer does not represent 074 * a well-formed class file 075 * @see Instrumentation#redefineClasses(java.lang.instrument.ClassDefinition[]) 076 * 077 */ 078 byte[] transform(ClassLoader loader, 079 String className, 080 Class<?> classBeingRedefined, 081 ProtectionDomain protectionDomain, 082 byte[] classfileBuffer) 083 throws IllegalClassFormatException; 084} 085