1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * %W% %E%
 *
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package sun.misc;

import java.util.ArrayList;

/**
 * This is an abstract base class which is called by java.lang.ClassLoader
 * when ClassFormatError is thrown inside defineClass(). 
 *
 * The purpose of this class is to allow applications (e.g. Java Plug-in)
 * to have a chance to transform the byte code from one form to another
 * if necessary. 
 *
 * One application of this class is used by Java Plug-in to transform
 * malformed JDK 1.1 class file into a well-formed Java 2 class file
 * on-the-fly, so JDK 1.1 applets with malformed class file in the 
 * Internet may run in Java 2 after transformation.
 *
 * @author  Stanley Man-Kit Ho
 */

public abstract class ClassFileTransformer 
{
    // Singleton of ClassFileTransformer
    //
    private static ArrayList transformerList = new ArrayList();
    private static Object[] transformers = new Object[0];

    /**
     * Add the class file transformer object.
     *
     * @param t Class file transformer instance
     */
    public static void add(ClassFileTransformer t)
    {
    synchronized(transformerList)
    {
        transformerList.add(t);
        transformers = transformerList.toArray();
    }
    }

    /**
     * Get the array of ClassFileTransformer object.
     *
     * @return ClassFileTransformer object array
     */
    public static Object[] getTransformers()
    {
    // transformers is not intended to be changed frequently,
    // so it is okay to not put synchronized block here
    // to speed up performance.
    //
    return transformers;
    }


    /**
     * Transform a byte array from one to the other.
     *
     * @param b Byte array
     * @param off Offset
     * @param len Length of byte array
     * @return Transformed byte array
     */
    public abstract byte[] transform(byte[] b, int off, int len) 
               throws ClassFormatError;
}
			
			

Browsed Source: [clear]