I've found that a useful trick is to create your classloader, and then use
classloader).
I.e. do
And then do a newInstance() and call eval() by reflection.
-----Original Message-----
Behalf Of Tomasz Kowaltowski
Sent: Friday, October 03, 2003 10:20 AM
Subject: Re: [Beanshell-users] Controlling class loading
Post by Shankar UnniI'm afraid you'll have to be a lot more precise about the
requirement
than
Post by Shankar Unnithat.
[...]
If you want more fine-grained access (i.e. you'd like your program
itself to
Post by Shankar Unnibe able to access java.awt.Frame, but not your scripts),
then you'll
have to
Post by Shankar Unnicreate a custom ProtectionDomain (and certainly load
BeanShell using a > separate class loader), and at this
point I'm stepping into deep
waters and
Post by Shankar Unnineed help myself :-/..
--
Shankar.
What I am trying to do is to prevent any script interpreted by the
BeanShell interpreter from loading any existing precompiled
classes of
my system, i.e, "*.class" files. Loading source "*.java"
files is OK. I
read the documentation and looked at the BeanShell source files and
tried the following solution (all source files are at the end of this
(1) declared my own class loader which (for testing purposes)
blocks any
loading;
(2) in my main program I set this class loader into the
interpreter, and
then tried the execution of a very simple example of a (pure Java)
script SimpleClass.
(3) I tested my program with and without SimpleClass.class
file present.
Without, the source version was loaded, with the interpreter
printing,
as expected: "Loading class from source file: /SimpleClass.java".
With the SimpleClass.class present (with or without
SimpleClass.java),
it was also loaded but without this message. It seems that the loader
ignored my "setClassLoader(new ClassLoaderNone());" statement :-(.
Any hints will be appreciated.
-- Tomasz
------------------------------------------------------
import bsh.*;
public class Test {
public static void main(String[] args) throws Exception {
Interpreter bi = new bsh.Interpreter();
bi.setClassLoader(new ClassLoaderNone());
SimpleInterface sc =
(SimpleInterface)(bi.eval("new SimpleClass()"));
System.out.println(sc.countParams(new String[]{}));
System.out.println(sc.countParams(new
String[]{"abc","123","def"}));
}
}
------------------------------------------
public class ClassLoaderNone extends ClassLoader {
public Class loadClass(String name) throws
ClassNotFoundException {
return this.loadClass(name,false);
}
public Class loadClass(String name, boolean resolve) throws
ClassNotFoundException {
throw new ClassNotFoundException();
}
}
------------------------------------------
public interface SimpleInterface {
public int countParams(String[] params);
}
-------------------------------------------
public class SimpleClass implements SimpleInterface {
public int countParams(String[] params) {
return params.length;
}
}
---------------------------------------------
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
https://lists.sourceforge.net/lists/listinfo/beanshell-users