KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > util > loading > Translator


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.util.loading;
23
24 import java.security.ProtectionDomain JavaDoc;
25
26 /** An interface for transforming byte code before Class creation. This is
27  * compatible with the JDK1.5 java.lang.instrument.ClassFileTransformer
28  * proposal.
29  *
30  * @author Scott.Stark@jboss.org
31  * @version $Revision: 1958 $
32  */

33 public interface Translator
34 {
35    /** Optionally transform the supplied class file and return a new replacement
36     * class file.
37     *
38     * <P> If a transformer has been registered with the class loading layer,
39     * the transformer will be called for every new class definition.
40     * The request for a new class definition is made with
41     * {@link java.lang.ClassLoader#defineClass ClassLoader.defineClass}.
42     * The transformer is called during the processing of the request, before
43     * the class file bytes have been verified or applied.
44     *
45     * <P>
46     * If the implementing method determines that no transformations are needed,
47     * it should return <code>null</code>. Otherwise, it should create a new
48     * byte[] array and copy the input <code>classfileBuffer</code> into it,
49     * along with all desired transformations. The input <code>classfileBuffer</code>
50     * must not be modified.
51     *
52     * @param loader - the defining loader of the class to be transformed, may
53     * be <code>null</code> if the bootstrap loader
54     * @param className - the fully-qualified name of the class
55     * @param classBeingRedefined - if this is a redefine, the class being
56     * redefined, otherwise <code>null</code>
57     * @param protectionDomain - the protection domain of the class being
58     * defined or redefined
59     * @param classfileBuffer - the input byte buffer in class file format - must
60     * not be modified
61     *
62     * @throws Exception - if the input does not represent a well-formed class file
63     * @return a well-formed class file buffer (the result of the transform),
64     * or <code>null</code> if no transform is performed.
65     */

66    public byte[] transform(ClassLoader JavaDoc loader,
67       String JavaDoc className,
68       Class JavaDoc classBeingRedefined,
69       ProtectionDomain JavaDoc protectionDomain,
70       byte[] classfileBuffer)
71       throws Exception JavaDoc;
72
73    /** Called to indicate that the ClassLoader is being discarded by the server.
74     *
75     * @param loader - a class loader that has possibly been used previously
76     * as an argument to transform.
77     */

78    public void unregisterClassLoader(ClassLoader JavaDoc loader);
79 }
80
Popular Tags