Hi Rony,
On 1/7/06, Rony G. Flatscher <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> while finalizing a little project in which BSF is used to allow ooRexx
> to be used as a scripting language for OpenOffice.org (will announce it,
> once it is out of beta), I wanted to use BSF as an optional Java
> extension. This way installation gets eased and it becomes an
> infrastructure any program on a system can use.
>
> In order to do so, it was necessary to change Class.forName(...) to
> Thread.currentThread().getContextClassLoader().loadClass(...).
>
> The attached diff will show you the differences which I would like to
> commit in two weeks, such that everyone has enough feedback time. This
> patch would also contain the renaming to "public static double
> byteArrayToDouble(byte value[])" (util/event/generator/ByteUtility.java).
+1 for the suggested changes
Sanka
>
> Regards,
>
> ---rony
> P.S.: Please express your thoughts about the suggest time-frames for
> getting BSF Golden and about the persons who could/should tackle
> different parts of it.
>
>
>
>
>
>
> Index: BSFManager.java
> ===================================================================
> --- BSFManager.java (Revision 344174)
> +++ BSFManager.java (Arbeitskopie)
> @@ -68,16 +68,16 @@
>
> /**
> * This class is the entry point to the bean scripting framework. An
> - * application wishing to integrate scripting to a Java app would
> + * application wishing to integrate scripting to a Java app would
> * place an instance of a BSFManager in their code and use its services
> * to register the beans they want to make available for scripting,
> - * load scripting engines, and run scripts.
> + * load scripting engines, and run scripts.
> * <p>
> * BSFManager serves as the registry of available scripting engines
> * as well. Loading and unloading of scripting engines is
> * supported as well. Each BSFManager loads one engine per language.
> * Several BSFManagers can be created per JVM.
> - *
> + *
> * @author Sanjiva Weerawarana
> * @author Matthew J. Duftler
> * @author Sam Ruby
> @@ -91,7 +91,7 @@
> // mapping of file extensions to languages
> protected static Hashtable extn2Lang = new Hashtable();
>
> - // table of scripting engine instances created by this manager.
> + // table of scripting engine instances created by this manager.
> // only one instance of a given language engine is created by a single
> // manager instance.
> protected Hashtable loadedEngines = new Hashtable();
> @@ -105,10 +105,11 @@
>
> // the class loader to use if a class loader is needed. Default is
> // he who loaded me (which may be null in which case its Class.forName).
> - protected ClassLoader classLoader = getClass().getClassLoader();
> + // protected ClassLoader classLoader = getClass().getClassLoader();
> + protected ClassLoader classLoader =
> Thread.currentThread().getContextClassLoader(); // rgf, 2006-01-05
>
> // temporary directory to use to dump temporary files into. Note that
> - // if class files are dropped here then unless this dir is in the
> + // if class files are dropped here then unless this dir is in the
> // classpath or unless the classloader knows to look here, the classes
> // will not be found.
> protected String tempDir = ".";
> @@ -116,7 +117,7 @@
> // classpath used by those that need a classpath
> protected String classPath;
>
> - // stores BSFDeclaredBeans representing objects
> + // stores BSFDeclaredBeans representing objects
> // introduced by a client of BSFManager
> protected Vector declaredBeans = new Vector();
>
> @@ -140,10 +141,10 @@
> while (keys.hasMoreElements()) {
> String key = (String) keys.nextElement();
> String value = p.getProperty(key);
> -
> +
> StringTokenizer tokens = new StringTokenizer(value, ",");
> String className = (String) tokens.nextToken();
> -
> +
> // get the extensions for this language
> String exts = (String) tokens.nextToken();
> StringTokenizer st = new StringTokenizer(exts, "|");
> @@ -159,11 +160,11 @@
> catch (IOException ex) {
> ex.printStackTrace();
> System.err.println("Error reading Languages file " + ex);
> - }
> + }
> catch (NoSuchElementException nsee) {
> nsee.printStackTrace();
> System.err.println("Syntax error in Languages resource bundle");
> - }
> + }
> catch (MissingResourceException mre) {
> mre.printStackTrace();
> System.err.println("Initialization error: " + mre.toString());
> @@ -206,10 +207,10 @@
> Object result = null;
>
> try {
> - final Object resultf =
> + final Object resultf =
> AccessController.doPrivileged(new
> PrivilegedExceptionAction() {
> public Object run() throws Exception {
> - return e.apply(sourcef, lineNof, columnNof,
> + return e.apply(sourcef, lineNof, columnNof,
> funcBodyf, paramNamesf,
> argumentsf);
> }
> });
> @@ -254,12 +255,12 @@
> final Vector paramNamesf = paramNames;
> final Vector argumentsf = arguments;
> final CodeBuffer cbf = cb;
> -
> +
> try {
> AccessController.doPrivileged(new PrivilegedExceptionAction() {
> public Object run() throws Exception {
> - e.compileApply(sourcef, lineNof, columnNof,
> - funcBodyf, paramNamesf,
> + e.compileApply(sourcef, lineNof, columnNof,
> + funcBodyf, paramNamesf,
> argumentsf, cbf);
> return null;
> }
> @@ -271,7 +272,7 @@
> }
>
> /**
> - * Compile the given expression of the given language into the given
> + * Compile the given expression of the given language into the given
> * <tt>CodeBuffer</tt>.
> *
> * @param lang language identifier
> @@ -311,7 +312,7 @@
> }
>
> /**
> - * Compile the given script of the given language into the given
> + * Compile the given script of the given language into the given
> * <tt>CodeBuffer</tt>.
> *
> * @param lang language identifier
> @@ -340,7 +341,7 @@
> try {
> AccessController.doPrivileged(new PrivilegedExceptionAction() {
> public Object run() throws Exception {
> - e.compileScript(sourcef, lineNof, columnNof,
> + e.compileScript(sourcef, lineNof, columnNof,
> scriptf, cbf);
> return null;
> }
> @@ -352,7 +353,7 @@
> }
>
> /**
> - * Declare a bean. The difference between declaring and registering
> + * Declare a bean. The difference between declaring and registering
> * is that engines are spsed to make declared beans "pre-available"
> * in the scripts as far as possible. That is, if a script author
> * needs a registered bean, he needs to look it up in some way. However
> @@ -366,7 +367,7 @@
> * says they don't like this (by throwing an exception) then this
> * method will simply quit with that exception. That is, any engines
> * that come after than in the engine enumeration will not even be
> - * told about this new bean.
> + * told about this new bean.
> * <p>
> * So, in general its best to declare beans before the manager has
> * been asked to load any engines because then the user can be informed
> @@ -420,7 +421,7 @@
> final int lineNof = lineNo, columnNof = columnNo;
> final Object exprf = expr;
> Object result = null;
> -
> +
> try {
> final Object resultf =
> AccessController.doPrivileged(new
> PrivilegedExceptionAction() {
> @@ -485,7 +486,7 @@
> * emulate an interactive session w/ the language.
> *
> * @param lang language identifier
> - * @param source (context info) the source of this expression
> + * @param source (context info) the source of this expression
> * (e.g., filename)
> * @param lineNo (context info) the line number in source for expr
> * @param columnNo (context info) the column number in source for expr
> @@ -531,7 +532,7 @@
> if (classPath == null) {
> try {
> classPath = System.getProperty("java.class.path");
> - }
> + }
> catch (Throwable t) {
> // prolly a security exception .. so no can do
> }
> @@ -541,17 +542,17 @@
>
> /**
> * Determine the language of a script file by looking at the file
> - * extension.
> + * extension.
> *
> * @param fileName the name of the file
> *
> * @return the scripting language the file is in if the file extension
> - * is known to me (must have been registered via
> + * is known to me (must have been registered via
> * registerScriptingEngine).
> *
> * @exception BSFException if file's extension is unknown.
> */
> - public static String getLangFromFilename(String fileName)
> + public static String getLangFromFilename(String fileName)
> throws BSFException {
> int dotIndex = fileName.lastIndexOf(".");
>
> @@ -571,7 +572,7 @@
>
> // Test to see if in classpath
> try {
> - String engineName =
> + String engineName =
> (String) registeredEngines.get(lang);
> Class.forName(engineName);
> }
> @@ -586,7 +587,7 @@
> }
> if (loops == 0) lang = langval;
> }
> -
> +
> if (lang != null && lang != "") {
> return lang;
> }
> @@ -636,7 +637,7 @@
> *
> * @param lang string identifying language
> * @exception BSFException if the language is unknown (i.e., if it
> - * has not been registered) with a reason of
> + * has not been registered) with a reason of
> * REASON_UNKNOWN_LANGUAGE. If the language is known but
> * if the interface can't be created for some reason, then
> * the reason is set to REASON_OTHER_ERROR and the actual
> @@ -677,7 +678,7 @@
> loadedEngines.put(lang, eng);
> pcs.addPropertyChangeListener(eng);
> return eng;
> - }
> + }
> catch (PrivilegedActionException prive) {
> throw (BSFException) prive.getException();
> }
> @@ -690,7 +691,7 @@
>
> /**
> * return a handle to a bean registered in the bean registry by the
> - * application or a scripting engine. Returns null if bean is not found.
> + * application or a scripting engine. Returns null if bean is not found.
> *
> * @param beanName name of bean to look up
> *
> @@ -699,14 +700,14 @@
> public Object lookupBean(String beanName) {
> try {
> return ((BSFDeclaredBean)objectRegistry.lookup(beanName)).bean;
> - }
> + }
> catch (IllegalArgumentException e) {
> return null;
> }
> }
>
> - /**
> - * Registering a bean allows a scripting engine or the application to
> + /**
> + * Registering a bean allows a scripting engine or the application to
> * access that bean by name and to manipulate it.
> *
> * @param beanName name to register under
> @@ -725,7 +726,7 @@
> }
>
> /**
> - * Register a scripting engine in the static registry of the
> + * Register a scripting engine in the static registry of the
> * BSFManager.
> *
> * @param lang string identifying language
> @@ -771,7 +772,7 @@
>
> /**
> * Set the object registry used by this manager. By default a new
> - * one is created when the manager is new'ed and this overwrites
> + * one is created when the manager is new'ed and this overwrites
> * that one.
> *
> * @param objectRegistry the registry to use
> @@ -782,13 +783,13 @@
>
> /**
> * Temporary directory to put stuff into (for those who need to). Note
> - * that unless this directory is in the classpath or unless the
> - * classloader knows to look in here, any classes here will not
> - * be found! BSFManager provides a service method to load a class
> - * which uses either the classLoader provided by the class loader
> - * property or, if that fails, a class loader which knows to load from
> - * the tempdir to try to load the class. Default value of tempDir
> - * is "." (current working dir).
> + * that unless this directory is in the classpath or unless the
> + * classloader knows to look in here, any classes here will not
> + * be found! BSFManager provides a service method to load a class
> + * which uses either the classLoader provided by the class loader
> + * property or, if that fails, a class loader which knows to load from
> + * the tempdir to try to load the class. Default value of tempDir
> + * is "." (current working dir).
> *
> * @param tempDir the temporary directory
> */
> @@ -848,7 +849,7 @@
> }
> }
>
> - /**
> + /**
> * Unregister a previously registered bean. Silent if name is not found.
> *
> * @param beanName name of bean to unregister
> Index: util/event/generator/ByteUtility.java
> ===================================================================
> --- util/event/generator/ByteUtility.java (Revision 344174)
> +++ util/event/generator/ByteUtility.java (Arbeitskopie)
> @@ -190,7 +190,7 @@
> temp += (((long)low[3]) & 0xFF);
> return temp;
> }
> - public static double byteArrayToDounle(byte value[])
> + public static double byteArrayToDouble(byte value[])
> {
> byte high[] = new byte[4];
> byte low[] = new byte[4];
> Index: util/event/generator/EventAdapterGenerator.java
> ===================================================================
> --- util/event/generator/EventAdapterGenerator.java (Revision 344174)
> +++ util/event/generator/EventAdapterGenerator.java (Arbeitskopie)
> @@ -105,11 +105,12 @@
> { WRITEDIRECTORY = WRITEDIRECTORY+"/"; }
> }
> try
> - { EVENTLISTENER = Class.forName("java.util.EventListener"); }
> + // { EVENTLISTENER = Class.forName("java.util.EventListener"); }
> + { EVENTLISTENER =
> Thread.currentThread().getContextClassLoader().loadClass
> ("java.util.EventListener"); } // rgf, 2006-01-05
> catch(ClassNotFoundException ex)
> - {
> + {
> System.err.println(ex.getMessage());
> - ex.printStackTrace();
> + ex.printStackTrace();
> }
>
> // start of the Java Class File
> @@ -243,7 +244,7 @@
> return cached;
> }
> catch(VerifyError ex)
> - {
> + {
> System.err.println(ex.getMessage());
> ex.printStackTrace();
> return cached;
> @@ -559,9 +560,9 @@
> fos.close();
> }
> catch(IOException ex)
> - {
> + {
> System.err.println(ex.getMessage());
> - ex.printStackTrace();
> + ex.printStackTrace();
> }
>
> try
> @@ -573,9 +574,9 @@
> return ret;
> }
> catch (ClassNotFoundException ex)
> - {
> - System.err.println(ex.getMessage());
> - ex.printStackTrace();
> + {
> + System.err.println(ex.getMessage());
> + ex.printStackTrace();
> }
> }
>
> @@ -589,9 +590,9 @@
> return ret;
> }
> catch(Exception ex)
> - {
> - System.err.println(ex.getMessage());
> - ex.printStackTrace();
> + {
> + System.err.println(ex.getMessage());
> + ex.printStackTrace();
> }
> }
> else
> Index: util/event/EventAdapterRegistry.java
> ===================================================================
> --- util/event/EventAdapterRegistry.java (Revision 344174)
> +++ util/event/EventAdapterRegistry.java (Arbeitskopie)
> @@ -68,13 +68,13 @@
> * and if it doesn't find one looks for a standard implementation of
> * that adapter in the org.apache.bsf.util.event.adapters package with a
> * standard naming convention. The naming convention it assumes is the
> - * following: for event listener type <tt>a.b.c.FooListener</tt>,
> - * it loads an adapter of type
> + * following: for event listener type <tt>a.b.c.FooListener</tt>,
> + * it loads an adapter of type
> * <tt>org.apache.bsf.util.event.adapters.a_b_c_FooAdapter</tt>.
> * If both the loading and the dynamic generation fail, then a
> * <code>null</code> is returned.
> * <p>
> - *
> + *
> * @author Sanjiva Weerawarana
> * @author Matthew J. Duftler
> * @see EventAdapter
> @@ -89,14 +89,17 @@
> public static Class lookup (Class listenerType) {
> String key = listenerType.getName().replace ('.', '_');
> Class adapterClass = (Class) reg.get (key);
> -
> +
> if (adapterClass == null) {
> String en = key.substring (0, key.lastIndexOf ("Listener"));
> String cn = adapterPackage + "." + en + adapterSuffix;
>
> try {
> // Try to resolve one.
> - adapterClass = (cl != null) ? cl.loadClass (cn) :
> Class.forName (cn);
> + // adapterClass = (cl != null) ? cl.loadClass (cn) :
> Class.forName (cn);
> + adapterClass = (cl != null) ? cl.loadClass (cn)
> + :
> Thread.currentThread().getContextClassLoader().loadClass (cn); // rgf,
> 2006-01-05
> +
> } catch (ClassNotFoundException e) {
> if (dynamic) {
> // Unable to resolve one, try to generate one.
> @@ -129,7 +132,7 @@
> * If the <code>dynamic</code> property is set to true, and the
> * <code>ClassLoader</code> is unable to resolve an adapter, one will be
> * dynamically generated.
> - *
> + *
> * @param dynamic whether or not to dynamically generate adapters.
> */
> public static void setDynamic (boolean dynamic) {
> Index: util/ReflectionUtils.java
> ===================================================================
> --- util/ReflectionUtils.java (Revision 344174)
> +++ util/ReflectionUtils.java (Arbeitskopie)
> @@ -67,7 +67,7 @@
> * This file is a collection of reflection utilities. There are utilities
> * for creating beans, getting bean infos, setting/getting properties,
> * and binding events.
> - *
> + *
> * @author Sanjiva Weerawarana
> * @author Joseph Kesselman
> */
> @@ -76,19 +76,19 @@
> //////////////////////////////////////////////////////////////////////////
>
> /**
> - * Add an event processor as a listener to some event coming out of an
> + * Add an event processor as a listener to some event coming out of an
> * object.
> - *
> + *
> * @param source event source
> * @param eventSetName name of event set from event src to bind to
> * @param processor event processor the event should be delegated to
> * when it occurs; either via processEvent or
> - * processExceptionableEvent.
> + * processExceptionableEvent.
> *
> * @exception IntrospectionException if unable to introspect
> * @exception IllegalArgumentException if event set is unknown
> - * @exception IllegalAccessException if the event adapter class or
> - * initializer is not accessible.
> + * @exception IllegalAccessException if the event adapter class or
> + * initializer is not accessible.
> * @exception InstantiationException if event adapter instantiation fails
> * @exception InvocationTargetException if something goes wrong while
> * running add event listener method
> @@ -103,7 +103,7 @@
> EventSetDescriptor esd = (EventSetDescriptor)
> findFeatureByName ("event", eventSetName, bi.getEventSetDescriptors
> ());
> if (esd == null) {
> - throw new IllegalArgumentException ("event set '" + eventSetName +
> + throw new IllegalArgumentException ("event set '" + eventSetName +
>
> "' unknown for source type '" +
>
> source.getClass () + "'");
> }
> @@ -128,10 +128,10 @@
> Object[] args;
> if (eventSetName.equals ("propertyChange") ||
> eventSetName.equals ("vetoableChange")) {
> - // In Java 1.2, beans may have direct listener adding methods
> + // In Java 1.2, beans may have direct listener adding methods
> // for property and vetoable change events which take the
> // property name as a filter to be applied at the event source.
> - // The filter property of the event processor should be used
> + // The filter property of the event processor should be used
> // in this case to support the source-side filtering.
> //
> // ** TBD **: the following two lines need to change appropriately
> @@ -164,16 +164,18 @@
> * @exception InvocationTargetException if constructor excepted
> * @exception IOException if I/O error in beans.instantiate
> */
> - public static Bean createBean (ClassLoader cld, String className,
> - Class[]
> argTypes, Object[] args)
> + public static Bean createBean (ClassLoader cld, String className,
> + Class[]
> argTypes, Object[] args)
> throws ClassNotFoundException, NoSuchMethodException,
> - InstantiationException, IllegalAccessException,
> + InstantiationException, IllegalAccessException,
> IllegalArgumentException, InvocationTargetException,
> IOException {
> if (argTypes != null) {
> // find the right constructor and use that to create bean
> Class cl = (cld != null) ? cld.loadClass (className)
> - : Class.forName
> (className);
> + :
> Thread.currentThread().getContextClassLoader().loadClass (className); // rgf,
> 2006-01-05
> + // : Class.forName (className);
> +
> Constructor c = MethodUtils.getConstructor (cl, argTypes);
> return new Bean (cl, c.newInstance (args));
> } else {
> @@ -203,10 +205,10 @@
> * @exception InvocationTargetException if constructor excepted
> * @exception IOException if I/O error in beans.instantiate
> */
> - public static Bean createBean (ClassLoader cld, String className,
> - Object[]
> args)
> + public static Bean createBean (ClassLoader cld, String className,
> + Object[]
> args)
> throws ClassNotFoundException, NoSuchMethodException,
> - InstantiationException, IllegalAccessException,
> + InstantiationException, IllegalAccessException,
> IllegalArgumentException, InvocationTargetException,
> IOException {
> Class[] argTypes = null;
> @@ -221,10 +223,10 @@
> //////////////////////////////////////////////////////////////////////////
>
> /**
> - * locate the item in the fds array whose name is as given. returns
> + * locate the item in the fds array whose name is as given. returns
> * null if not found.
> */
> - private static
> + private static
> FeatureDescriptor findFeatureByName (String featureType, String name,
>
> FeatureDescriptor[] fds) {
> for (int i = 0; i < fds.length; i++) {
> @@ -244,7 +246,7 @@
> try {
> Field f = targetClass.getField (fieldName);
> Class fieldType = f.getType ();
> -
> +
> // Get the value and return it.
> Object value = f.get (target);
> return new Bean (fieldType, value);
> @@ -276,7 +278,7 @@
> IllegalAccessException, InvocationTargetException {
> // find the property descriptor
> BeanInfo bi = Introspector.getBeanInfo (target.getClass ());
> - PropertyDescriptor pd = (PropertyDescriptor)
> + PropertyDescriptor pd = (PropertyDescriptor)
> findFeatureByName ("property", propName, bi.getPropertyDescriptors
> ());
> if (pd == null) {
> throw new IllegalArgumentException ("property '" + propName + "' is
> " +
> @@ -290,7 +292,7 @@
> // if index != null, then property is indexed - pd better be so too
> if (!(pd instanceof IndexedPropertyDescriptor)) {
> throw new IllegalArgumentException ("attempt to get
> non-indexed " +
> -
> "property '" + propName +
> +
> "property '" + propName +
>
> "' as being indexed");
> }
> IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
> @@ -302,7 +304,7 @@
> }
>
> if (rm == null) {
> - throw new IllegalArgumentException ("property '" + propName +
> + throw new IllegalArgumentException ("property '" + propName +
>
> "' is not readable");
> }
>
> @@ -377,12 +379,12 @@
> */
> public static void setProperty (Object target, String propName,
> Integer
> index, Object value,
> - Class
> valueType, TypeConvertorRegistry tcr)
> + Class
> valueType, TypeConvertorRegistry tcr)
> throws IntrospectionException, IllegalArgumentException,
> IllegalAccessException, InvocationTargetException {
> // find the property descriptor
> BeanInfo bi = Introspector.getBeanInfo (target.getClass ());
> - PropertyDescriptor pd = (PropertyDescriptor)
> + PropertyDescriptor pd = (PropertyDescriptor)
> findFeatureByName ("property", propName, bi.getPropertyDescriptors
> ());
> if (pd == null) {
> throw new IllegalArgumentException ("property '" + propName + "' is
> " +
> @@ -397,7 +399,7 @@
> // if index != null, then property is indexed - pd better be so too
> if (!(pd instanceof IndexedPropertyDescriptor)) {
> throw new IllegalArgumentException ("attempt to set
> non-indexed " +
> -
> "property '" + propName +
> +
> "property '" + propName +
>
> "' as being indexed");
> }
> IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
> @@ -409,7 +411,7 @@
> }
>
> if (wm == null) {
> - throw new IllegalArgumentException ("property '" + propName +
> + throw new IllegalArgumentException ("property '" + propName +
>
> "' is not writeable");
> }
>
> Index: util/EngineUtils.java
> ===================================================================
> --- util/EngineUtils.java (Revision 344174)
> +++ util/EngineUtils.java (Arbeitskopie)
> @@ -339,7 +339,9 @@
> ClassLoader classLoader = mgr.getClassLoader ();
>
> try {
> - return (classLoader == null) ? Class.forName (name)
> + return (classLoader == null) ?
> + // Class.forName (name)
> +
> Thread.currentThread().getContextClassLoader().loadClass (name)
> : classLoader.loadClass (name);
> } catch (ClassNotFoundException e) {
> // try to load it from the temp dir using my own class loader
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]