001: /*
002: * @(#)MemberFilter.java 1.6 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027: package sun.misc;
028:
029: /*
030: * @(#)MemberFilter.java 1.1 03/06/24
031: *
032: * A MemberFilter is used in conjunction with a restrictive class loader,
033: * such as the MidletClassLoader. It keeps a list of classes and a subset of
034: * their fields. Once a class's constant pool is set up,
035: * checkMemberAccessValidity will look at it. It will report on any
036: * field, method, or interfacemethod references which are
037: * (a) to classes named in the restrictions but
038: * (b) not on the allowed list.
039: * The implementation is very specific to CVM.
040: */
041:
042: // probably want this package-visible only once debugged
043: public class MemberFilter {
044: private int partialData;
045: private int fullData;
046: private String badClass;
047: private String badMember;
048: private String badSig;
049:
050: private native void finalize0();
051:
052: protected void finalize() {
053: finalize0();
054: partialData = 0;
055: fullData = 0;
056: }
057:
058: public MemberFilter() {
059: }
060:
061: /*
062: * Find ROMized filter data. If exists, set 'fullData' field
063: * and return true. Otherwise, return false.
064: */
065: public native boolean findROMFilterData();
066:
067: /*
068: * the name of a class and arrays of all the fields and methods
069: * -- including type signatures -- which are allowed.
070: * Separate names from signatures using a colon :
071: * classname uses / separators!
072: * an element of the methods array could look something like this:
073: * "toString():Ljava/lang/String;"
074: */
075: public native void addRestrictions(String classname,
076: String fields[], String methods[]);
077:
078: /*
079: * Once addRestrictions has been called a number of times,
080: * a call to doneAddingRestrictions() will allow us to form a
081: * more compact and easily searched form of the data structure.
082: */
083: public native void doneAddingRestrictions();
084:
085: private native boolean checkMemberAccessValidity0(Class newclass);
086:
087: public synchronized void /* synchronized IS DEBUG: REMOVE IT */
088: checkMemberAccessValidity(Class newclass) throws Error {
089: if (!checkMemberAccessValidity0(newclass)) {
090: /* DEBUG */
091: /* the native code will set the badClass, badMember and badSig
092: * fields. But unless you decide that this method should be
093: * synchronized, there is no reason to believe that they won't
094: * get clobbered in another thread!
095: */
096: /* Don't throw an exception here. Let constantpool resolution
097: * throw the exception on first use of this illegal member
098: * instead. */
099: // throw new Error("Class "+(newclass.getName())+" makes illegal member references to "+badClass+"."+badMember+":"+badSig);
100: /* END DEBUG */
101: // throw new Error("Class "+(newclass.getName())+" makes illegal member references");
102: }
103: }
104: }
|