01: /*
02: * @(#)ClassFileTransformer.java 1.6 06/10/10
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26: package sun.misc;
27:
28: import java.util.ArrayList;
29:
30: /**
31: * This is an abstract base class which is called by java.lang.ClassLoader
32: * when ClassFormatError is thrown inside defineClass().
33: *
34: * The purpose of this class is to allow applications (e.g. Java Plug-in)
35: * to have a chance to transform the byte code from one form to another
36: * if necessary.
37: *
38: * One application of this class is used by Java Plug-in to transform
39: * malformed JDK 1.1 class file into a well-formed Java 2 class file
40: * on-the-fly, so JDK 1.1 applets with malformed class file in the
41: * Internet may run in Java 2 after transformation.
42: *
43: * @author Stanley Man-Kit Ho
44: */
45:
46: public abstract class ClassFileTransformer {
47: // Singleton of ClassFileTransformer
48: //
49: private static ArrayList transformerList = new ArrayList();
50: private static Object[] transformers = new Object[0];
51:
52: /**
53: * Add the class file transformer object.
54: *
55: * @param t Class file transformer instance
56: */
57: public static void add(ClassFileTransformer t) {
58: synchronized (transformerList) {
59: transformerList.add(t);
60: transformers = transformerList.toArray();
61: }
62: }
63:
64: /**
65: * Get the array of ClassFileTransformer object.
66: *
67: * @return ClassFileTransformer object array
68: */
69: public static Object[] getTransformers() {
70: // transformers is not intended to be changed frequently,
71: // so it is okay to not put synchronized block here
72: // to speed up performance.
73: //
74: return transformers;
75: }
76:
77: /**
78: * Transform a byte array from one to the other.
79: *
80: * @param b Byte array
81: * @param off Offset
82: * @param len Length of byte array
83: * @return Transformed byte array
84: */
85: public abstract byte[] transform(byte[] b, int off, int len)
86: throws ClassFormatError;
87: }
|