ixcclassloader.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,155 行 · 第 1/4 页
JAVA
1,155 行
/* * @(#)IxcClassLoader.java 1.29 06/10/10 * * Copyright 1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.xlet.ixc;import java.rmi.Remote;import java.rmi.RemoteException;import javax.microedition.xlet.XletContext;import javax.microedition.xlet.ixc.StubException;import java.net.URL;import java.lang.reflect.Method;import java.lang.reflect.Array;import java.util.Enumeration;import java.util.Hashtable;import java.util.HashSet;import java.util.Iterator;import java.io.ByteArrayOutputStream;import java.io.DataOutputStream;import java.io.IOException;import java.security.AccessController;import java.security.PrivilegedAction;/** * Class loader for Xlets. This is needed to automatically generate stub * classes for IXC. * <p> * Suppose, for example, that a user class implemens a remote interface UserIF, * and that interface contains two methods, void frob(Something), and * int glorp(float). This classloader will automatically generate * a remote stub. The stub will be equivalent to the following class: * <pre> * * package com.sun.xlet; * * import java.lang.reflect.Method; * * public final class StubClass$$42 extends com.sun.xlet.WrappedRemote * implements UserIF { * * private static Method com_sun_xlet_method0; * private static Method com_sun_xlet_method1; * * * public static void com_sun_xlet_init(Method findMethodMethod) * throws Exception { * // findMethodMethod is Utils.findMethod for the ClassLoader * // where the *target* Remote object lives. * * if (com_sun_xlet_method0 != null) { * return; * } * com_sun_xlet_method0 = (Method) findMethodMethod.invoke(null, * new Object[] { "UserIF", "frob", new Object[] { "Something" }}); * com_sun_xlet_method1 = (Method) findMethodMethod.invoke(null, * new Object[] { "UserIF", "glorp", * new Object[] { java.lang.Float.TYPE }}); * } * * public static void com_sun_xlet_destroy() { * com_sun_xlet_method0 = null; * com_sun_xlet_method1 = null; * } * * public StubClass$$42(Remote target, ImportRegistryImpl registry, * RegistryKey key) { * super(target, registry, key); * } * * public void frob(Something arg1) throws org.dvb.ixc.RemoteException { * com_sun_xlet_execute(com_sun_xlet_method0, * new Object[] { arg1 }); * } * * public int glorp(float arg1) throws org.dvb.ixc.RemoteException { * Object r = com_sun_xlet_execute(com_sun_xlet_method1, * new Object[] { new Float(arg1) }); * return ((Integer) r).intValue(); * } * } * * </pre> * <p> * @@ Add the synthetic attribute * @@ Do this with a security manager installed * @@ Make exception handling consistent with 1.2 behavior. Specifically, * RemoteExceptions should be cloned and wrapped, RuntimeExceptions * should be cloned and re-thrown, checked exception that appear in the * interface method's signature should be cloned and re-thrown (probably * with our deprecated friend, Thread.stop(Throwable)), and unexpected * checked exceptions should be cloned and wrapped (there's some exception * under java.rmi specifically for this). *//* * This classloader is deligated from an Xlet's class loader and generates * a stub class to be used for inter-xlet communication */class IxcClassLoader extends ClassLoader { private static Class theRemoteIF = Remote.class; private Hashtable generated = new Hashtable(11); // Key is remote class, value is stub we generate. private static // for debugging int nextStubNumber = 1; // ImportRegistryImpl.copyObject needs to // deserialize objects in the context of this classloader. To do this, // it defines a class called com.sun.xlet.DeserializeUtility, with // a single static method, deserialize(byte[]). The source for this // class, and a little utility for converting the .class to a // byte[], can be found in ~/misc/com/sun/xlet. private Method deserializeMethod = null; private Method findMethodMethod = null; private Class utilsClass = null; private static byte[] utilsClassBody = { // The .class file (byte) 0xca, (byte) 0xfe, (byte) 0xba, (byte) 0xbe, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2e, (byte) 0x00, (byte) 0x3d, (byte) 0x0a, (byte) 0x00, (byte) 0x11, (byte) 0x00, (byte) 0x1f, (byte) 0x07, (byte) 0x00, (byte) 0x20, (byte) 0x07, (byte) 0x00, (byte) 0x21, (byte) 0x0a, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x22, (byte) 0x0a, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x23, (byte) 0x0a, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x24, (byte) 0x07, (byte) 0x00, (byte) 0x25, (byte) 0x07, (byte) 0x00, (byte) 0x26, (byte) 0x07, (byte) 0x00, (byte) 0x27, (byte) 0x0a, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x28, (byte) 0x0a, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x29, (byte) 0x07, (byte) 0x00, (byte) 0x2a, (byte) 0x07, (byte) 0x00, (byte) 0x2b, (byte) 0x0a, (byte) 0x00, (byte) 0x0c, (byte) 0x00, (byte) 0x2c, (byte) 0x0a, (byte) 0x00, (byte) 0x0d, (byte) 0x00, (byte) 0x2d, (byte) 0x07, (byte) 0x00, (byte) 0x2e, (byte) 0x07, (byte) 0x00, (byte) 0x2f, (byte) 0x01, (byte) 0x00, (byte) 0x06, (byte) 0x3c, (byte) 0x69, (byte) 0x6e, (byte) 0x69, (byte) 0x74, (byte) 0x3e, (byte) 0x01, (byte) 0x00, (byte) 0x03, (byte) 0x28, (byte) 0x29, (byte) 0x56, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x43, (byte) 0x6f, (byte) 0x64, (byte) 0x65, (byte) 0x01, (byte) 0x00, (byte) 0x0f, (byte) 0x4c, (byte) 0x69, (byte) 0x6e, (byte) 0x65, (byte) 0x4e, (byte) 0x75, (byte) 0x6d, (byte) 0x62, (byte) 0x65, (byte) 0x72, (byte) 0x54, (byte) 0x61, (byte) 0x62, (byte) 0x6c, (byte) 0x65, (byte) 0x01, (byte) 0x00, (byte) 0x0b, (byte) 0x64, (byte) 0x65, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x69, (byte) 0x61, (byte) 0x6c, (byte) 0x69, (byte) 0x7a, (byte) 0x65, (byte) 0x01, (byte) 0x00, (byte) 0x1a, (byte) 0x28, (byte) 0x5b, (byte) 0x42, (byte) 0x29, (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x69, (byte) 0x6f, (byte) 0x2f, (byte) 0x53, (byte) 0x65, (byte) 0x72, (byte) 0x69, (byte) 0x61, (byte) 0x6c, (byte) 0x69, (byte) 0x7a, (byte) 0x61, (byte) 0x62, (byte) 0x6c, (byte) 0x65, (byte) 0x3b, (byte) 0x01, (byte) 0x00, (byte) 0x0a, (byte) 0x45, (byte) 0x78, (byte) 0x63, (byte) 0x65, (byte) 0x70, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x73, (byte) 0x07, (byte) 0x00, (byte) 0x30, (byte) 0x07, (byte) 0x00, (byte) 0x31, (byte) 0x01, (byte) 0x00, (byte) 0x0a, (byte) 0x66, (byte) 0x69, (byte) 0x6e, (byte) 0x64, (byte) 0x4d, (byte) 0x65, (byte) 0x74, (byte) 0x68, (byte) 0x6f, (byte) 0x64, (byte) 0x01, (byte) 0x00, (byte) 0x4b, (byte) 0x28, (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x3b, (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x3b, (byte) 0x5b, (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x4f, (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0x3b, (byte) 0x29, (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x4f, (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0x3b, (byte) 0x01, (byte) 0x00, (byte) 0x0a, (byte) 0x53, (byte) 0x6f, (byte) 0x75, (byte) 0x72, (byte) 0x63, (byte) 0x65, (byte) 0x46, (byte) 0x69, (byte) 0x6c, (byte) 0x65, (byte) 0x01, (byte) 0x00, (byte) 0x0a, (byte) 0x55, (byte) 0x74, (byte) 0x69, (byte) 0x6c, (byte) 0x73, (byte) 0x2e, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x0c, (byte) 0x00, (byte) 0x12, (byte) 0x00, (byte) 0x13, (byte) 0x01, (byte) 0x00, (byte) 0x19, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x69, (byte) 0x6f, (byte) 0x2f, (byte) 0x4f, (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0x49, (byte) 0x6e, (byte) 0x70, (byte) 0x75, (byte) 0x74, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x65, (byte) 0x61, (byte) 0x6d, (byte) 0x01, (byte) 0x00, (byte) 0x1c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x69, (byte) 0x6f, (byte) 0x2f, (byte) 0x42, (byte) 0x79, (byte) 0x74, (byte) 0x65, (byte) 0x41, (byte) 0x72, (byte) 0x72, (byte) 0x61, (byte) 0x79, (byte) 0x49, (byte) 0x6e, (byte) 0x70, (byte) 0x75, (byte) 0x74, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x65, (byte) 0x61, (byte) 0x6d, (byte) 0x0c, (byte) 0x00, (byte) 0x12, (byte) 0x00, (byte) 0x32, (byte) 0x0c, (byte) 0x00, (byte) 0x12, (byte) 0x00, (byte) 0x33, (byte) 0x0c, (byte) 0x00, (byte) 0x34, (byte) 0x00, (byte) 0x35, (byte) 0x01, (byte) 0x00, (byte) 0x14, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x69, (byte) 0x6f, (byte) 0x2f, (byte) 0x53, (byte) 0x65, (byte) 0x72, (byte) 0x69, (byte) 0x61, (byte) 0x6c, (byte) 0x69, (byte) 0x7a, (byte) 0x61, (byte) 0x62, (byte) 0x6c, (byte) 0x65, (byte) 0x01, (byte) 0x00, (byte) 0x0f, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x43, (byte) 0x6c, (byte) 0x61, (byte) 0x73, (byte) 0x73, (byte) 0x01, (byte) 0x00, (byte) 0x10, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x0c, (byte) 0x00, (byte) 0x36, (byte) 0x00, (byte) 0x37, (byte) 0x0c, (byte) 0x00, (byte) 0x38, (byte) 0x00, (byte) 0x39, (byte) 0x01, (byte) 0x00, (byte) 0x13, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x45, (byte) 0x78, (byte) 0x63, (byte) 0x65, (byte) 0x70, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x01, (byte) 0x00, (byte) 0x1a, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x52, (byte) 0x75, (byte) 0x6e, (byte) 0x74, (byte) 0x69, (byte) 0x6d, (byte) 0x65, (byte) 0x45, (byte) 0x78, (byte) 0x63, (byte) 0x65, (byte) 0x70, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x0c, (byte) 0x00, (byte) 0x3a, (byte) 0x00, (byte) 0x3b, (byte) 0x0c, (byte) 0x00, (byte) 0x12, (byte) 0x00, (byte) 0x3c, (byte) 0x01, (byte) 0x00, (byte) 0x12, (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x2f, (byte) 0x73, (byte) 0x75, (byte) 0x6e, (byte) 0x2f, (byte) 0x78, (byte) 0x6c, (byte) 0x65, (byte) 0x74, (byte) 0x2f, (byte) 0x55, (byte) 0x74, (byte) 0x69, (byte) 0x6c, (byte) 0x73, (byte) 0x01, (byte) 0x00, (byte) 0x10, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x4f, (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0x01, (byte) 0x00, (byte) 0x13, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x69, (byte) 0x6f, (byte) 0x2f, (byte) 0x49, (byte) 0x4f, (byte) 0x45, (byte) 0x78, (byte) 0x63, (byte) 0x65, (byte) 0x70, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x01, (byte) 0x00, (byte) 0x20, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x43, (byte) 0x6c, (byte) 0x61, (byte) 0x73, (byte) 0x73, (byte) 0x4e, (byte) 0x6f, (byte) 0x74, (byte) 0x46, (byte) 0x6f, (byte) 0x75, (byte) 0x6e, (byte) 0x64, (byte) 0x45, (byte) 0x78, (byte) 0x63, (byte) 0x65, (byte) 0x70, (byte) 0x74,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?