01: /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
02: *
03: * ***** BEGIN LICENSE BLOCK *****
04: * Version: MPL 1.1/GPL 2.0
05: *
06: * The contents of this file are subject to the Mozilla Public License Version
07: * 1.1 (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: * http://www.mozilla.org/MPL/
10: *
11: * Software distributed under the License is distributed on an "AS IS" basis,
12: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13: * for the specific language governing rights and limitations under the
14: * License.
15: *
16: * The Original Code is Rhino code, released
17: * May 6, 1999.
18: *
19: * The Initial Developer of the Original Code is
20: * Netscape Communications Corporation.
21: * Portions created by the Initial Developer are Copyright (C) 1997-1999
22: * the Initial Developer. All Rights Reserved.
23: *
24: * Contributor(s):
25: * Norris Boyd
26: * Igor Bukanov
27: *
28: * Alternatively, the contents of this file may be used under the terms of
29: * the GNU General Public License Version 2 or later (the "GPL"), in which
30: * case the provisions of the GPL are applicable instead of those above. If
31: * you wish to allow use of your version of this file only under the terms of
32: * the GPL and not to allow others to use your version of this file under the
33: * MPL, indicate your decision by deleting the provisions above and replacing
34: * them with the notice and other provisions required by the GPL. If you do
35: * not delete the provisions above, a recipient may use your version of this
36: * file under either the MPL or the GPL.
37: *
38: * ***** END LICENSE BLOCK ***** */
39:
40: // API class
41: package org.mozilla.javascript;
42:
43: /**
44: Embeddings that wish to filter Java classes that are visible to scripts
45: through the LiveConnect, should implement this interface.
46:
47: @see Context#setClassShutter(ClassShutter)
48: @since 1.5 Release 4
49: @author Norris Boyd
50: */
51:
52: public interface ClassShutter {
53:
54: /**
55: * Return true iff the Java class with the given name should be exposed
56: * to scripts.
57: * <p>
58: * An embedding may filter which Java classes are exposed through
59: * LiveConnect to JavaScript scripts.
60: * <p>
61: * Due to the fact that there is no package reflection in Java,
62: * this method will also be called with package names. There
63: * is no way for Rhino to tell if "Packages.a.b" is a package name
64: * or a class that doesn't exist. What Rhino does is attempt
65: * to load each segment of "Packages.a.b.c": It first attempts to
66: * load class "a", then attempts to load class "a.b", then
67: * finally attempts to load class "a.b.c". On a Rhino installation
68: * without any ClassShutter set, and without any of the
69: * above classes, the expression "Packages.a.b.c" will result in
70: * a [JavaPackage a.b.c] and not an error.
71: * <p>
72: * With ClassShutter supplied, Rhino will first call
73: * visibleToScripts before attempting to look up the class name. If
74: * visibleToScripts returns false, the class name lookup is not
75: * performed and subsequent Rhino execution assumes the class is
76: * not present. So for "java.lang.System.out.println" the lookup
77: * of "java.lang.System" is skipped and thus Rhino assumes that
78: * "java.lang.System" doesn't exist. So then for "java.lang.System.out",
79: * Rhino attempts to load the class "java.lang.System.out" because
80: * it assumes that "java.lang.System" is a package name.
81: * <p>
82: * @param fullClassName the full name of the class (including the package
83: * name, with '.' as a delimiter). For example the
84: * standard string class is "java.lang.String"
85: * @return whether or not to reveal this class to scripts
86: */
87: public boolean visibleToScripts(String fullClassName);
88: }
|