midpconfig.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 479 行 · 第 1/2 页
JAVA
479 行
/* * * 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. *//* * @(#)MIDPConfig.java 1.11 06/10/30 * This class contains all the information necessary * to configure a MemberFilter appropriate for MIDP2.0 * as well as some tables we need to configure the * MIDPImplementationClassLoader */package sun.misc;import java.net.URL;import java.security.PermissionCollection;import java.security.Permissions;import java.io.IOException;import java.io.File;import java.io.FileReader;import java.io.InputStream;import java.io.InputStreamReader;import java.io.BufferedReader;import java.io.IOException;import java.util.jar.JarFile;import java.util.zip.ZipEntry;import java.util.Vector;import java.net.MalformedURLException;import java.util.HashSet;public finalclass MIDPConfig{ /* The MIDP library classloader */ private static MIDPImplementationClassLoader midpImplCL; /* The midlet classloader */ /*private static MIDletClassLoader midletCL;*/ /* The MemberFilter */ private static MemberFilter memberFilter; /* The classes allowed for Midlet */ private static HashSet allowedClasses; public static String MIDPVersion = "2.0"; public static String CLDCVersion = "1.1"; /* * The following data structures are for * managing name visibility. */ static String systemPackages[] = { "java.", "javax.microedition." }; static { // Create the member filter. memberFilter = newMemberFilter(); // Get the permitted class list. getPermittedClasses(); } private static File[] getDefaultPath() throws IOException { String libdir = System.getProperty("java.home") + File.separator + "lib" + File.separator; String jars[] = split(System.getProperty( "com.sun.midp.implementation"), ' '); int num = jars.length; File files[] = new File[num]; for (int i = 0; i<num; i++) { String jar = libdir + jars[i]; File f = new File(jar); if (!f.exists()) { throw new IOException("Can't find " + jar); } files[i] = f; } return files; } /* * Set up a MemberFilter using the classes and members * given in the permittedMembers structures above. * All MIDletClassLoaders will share the same MemberFilter * since using it does not change its state. */ public static MemberFilter newMemberFilter(){ try{ String filename = System.getProperty("java.home") + File.separator + "lib" + File.separator + "MIDPFilterConfig.txt"; MemberFilterConfig mfc = new MemberFilterConfig(filename); MemberFilter mf; // DEBUG System.out.println( // "Starting MemberFilter file parsing"); // DEBUG mfc.setVerbose(true); mf = mfc.parseFile(); // DEBUG System.out.println("Done MemberFilter file parsing"); return mf; }catch(java.io.IOException e){ e.printStackTrace(); return null; } } private static void readPermittedClassFile(BufferedReader infile) { try{ while(true){ String inline = infile.readLine(); if (inline == null) break; // eof if (inline.length() == 0) continue; // blank line if (inline.charAt(0) == '#') continue; // comment allowedClasses.add(inline.intern()); } }catch(java.io.IOException e){ } } /* Read the permitted class list. */ private static void getPermittedClasses() { BufferedReader infile; if (allowedClasses != null){ return; } allowedClasses = new HashSet(); /* First, read the default lib/MIDPPermittedClasses.txt */ try { String filename = System.getProperty("java.home") + File.separator + "lib" + File.separator + "MIDPPermittedClasses.txt"; infile = new BufferedReader(new FileReader(filename)); readPermittedClassFile(infile); infile.close(); } catch (IOException ie) { throw new InternalError( "Failed to read lib/MIDPPermittedClasses.txt"); } /* Then, search the jar files in the bootclasspath to see if * there are additional class lists. */ String jarfiles[] = split( System.getProperty("sun.boot.class.path"), File.pathSeparatorChar); int num = jarfiles.length; for (int i = 0; i < num; i++) { try { JarFile jarfile = new JarFile(jarfiles[i]); ZipEntry entry = jarfile.getEntry("MIDPPermittedClasses.txt"); if (entry != null) { InputStream jis = jarfile.getInputStream(entry); infile = new BufferedReader(new InputStreamReader(jis)); readPermittedClassFile(infile); infile.close(); } } catch (IOException ioe) { throw new InternalError( "Failed to read " + jarfiles[i] + "MIDPPermittedClasses.txt"); } } } public static MIDPImplementationClassLoader getMIDPImplementationClassLoader() { return midpImplCL; } public static MIDPImplementationClassLoader newMIDPImplementationClassLoader(File files[]){ /* The MIDPImplementationClassLoader already exist. Throw an * exception. */ if (midpImplCL != null) { throw new InternalError( "The MIDPImplementationClassLoader is already created"); } PermissionCollection perms = new Permissions(); if (files == null || files.length == 0) { try { files = getDefaultPath(); } catch (IOException e) { System.err.println(e.getMessage()); e.printStackTrace(); return null; } } URL urls[] = new URL[files.length]; for (int i = 0; i < files.length; i++) { try { urls[i] = files[i].toURL(); } catch (MalformedURLException e) { e.printStackTrace(); urls = null; break; } } perms.add(new java.security.AllPermission()); //DEBUG System.out.println( // "Constructing MIDPImplementationClassLoader with permissions " // +perms); midpImplCL = new MIDPImplementationClassLoader( urls, perms, null); return midpImplCL;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?