001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.instrument.classloading; 018 019import java.lang.instrument.ClassFileTransformer; 020 021/** 022 * Defines the contract for adding one or more 023 * {@link ClassFileTransformer ClassFileTransformers} to a {@link ClassLoader}. 024 * 025 * <p>Implementations may operate on the current context {@code ClassLoader} 026 * or expose their own instrumentable {@code ClassLoader}. 027 * 028 * @author Rod Johnson 029 * @author Costin Leau 030 * @since 2.0 031 * @see java.lang.instrument.ClassFileTransformer 032 */ 033public interface LoadTimeWeaver { 034 035 /** 036 * Add a {@code ClassFileTransformer} to be applied by this 037 * {@code LoadTimeWeaver}. 038 * @param transformer the {@code ClassFileTransformer} to add 039 */ 040 void addTransformer(ClassFileTransformer transformer); 041 042 /** 043 * Return a {@code ClassLoader} that supports instrumentation 044 * through AspectJ-style load-time weaving based on user-defined 045 * {@link ClassFileTransformer ClassFileTransformers}. 046 * <p>May be the current {@code ClassLoader}, or a {@code ClassLoader} 047 * created by this {@link LoadTimeWeaver} instance. 048 * @return the {@code ClassLoader} which will expose 049 * instrumented classes according to the registered transformers 050 */ 051 ClassLoader getInstrumentableClassLoader(); 052 053 /** 054 * Return a throwaway {@code ClassLoader}, enabling classes to be 055 * loaded and inspected without affecting the parent {@code ClassLoader}. 056 * <p>Should <i>not</i> return the same instance of the {@link ClassLoader} 057 * returned from an invocation of {@link #getInstrumentableClassLoader()}. 058 * @return a temporary throwaway {@code ClassLoader}; should return 059 * a new instance for each call, with no existing state 060 */ 061 ClassLoader getThrowawayClassLoader(); 062 063}