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 005 This file is part of GNU Classpath. 006 007 GNU Classpath is free software; you can redistribute it and/or modify 008 it under the terms of the GNU General Public License as published by 009 the Free Software Foundation; either version 2, or (at your option) 010 any later version. 011 012 GNU Classpath is distributed in the hope that it will be useful, but 013 WITHOUT ANY WARRANTY; without even the implied warranty of 014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 General Public License for more details. 016 017 You should have received a copy of the GNU General Public License 018 along with GNU Classpath; see the file COPYING. If not, write to the 019 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 020 02110-1301 USA. 021 022 Linking this library statically or dynamically with other modules is 023 making a combined work based on this library. Thus, the terms and 024 conditions of the GNU General Public License cover the whole 025 combination. 026 027 As a special exception, the copyright holders of this library give you 028 permission to link this library with independent modules to produce an 029 executable, regardless of the license terms of these independent 030 modules, and to copy and distribute the resulting executable under 031 terms of your choice, provided that you also meet, for each linked 032 independent module, the terms and conditions of the license of that 033 module. An independent module is a module which is not derived from 034 or based on this library. If you modify this library, you may extend 035 this exception to your version of the library, but you are not 036 obligated to do so. If you do not wish to do so, delete this 037 exception statement from your version. */ 038 039 040 package java.lang.instrument; 041 042 import 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 */ 054 public 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 }