Return-Path: Delivered-To: apmail-jakarta-bsf-dev-archive@www.apache.org Received: (qmail 54744 invoked from network); 25 Feb 2005 09:54:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 25 Feb 2005 09:54:46 -0000 Received: (qmail 23719 invoked by uid 500); 25 Feb 2005 09:54:46 -0000 Delivered-To: apmail-jakarta-bsf-dev-archive@jakarta.apache.org Received: (qmail 23689 invoked by uid 500); 25 Feb 2005 09:54:46 -0000 Mailing-List: contact bsf-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Bean Scripting Framework developers" Reply-To: "Bean Scripting Framework developers" Delivered-To: mailing list bsf-dev@jakarta.apache.org Received: (qmail 23671 invoked by uid 99); 25 Feb 2005 09:54:46 -0000 X-ASF-Spam-Status: No, hits=0.6 required=10.0 tests=HTML_30_40,HTML_FONT_BIG,HTML_MESSAGE,HTML_TAG_EXIST_TBODY,HTML_TITLE_EMPTY X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from falbala.wu-wien.ac.at (HELO falbala.wu-wien.ac.at) (137.208.7.75) by apache.org (qpsmtpd/0.28) with ESMTP; Fri, 25 Feb 2005 01:54:44 -0800 Received: from [137.208.224.172] (abt-wi-013.wu-wien.ac.at [137.208.224.172]) by falbala.wu-wien.ac.at (8.12.8/8.12.6) with ESMTP id j1P9sarq311500 for ; Fri, 25 Feb 2005 10:54:37 +0100 (envelope-from Rony.Flatscher@wu-wien.ac.at) Message-ID: <421EF5D8.80403@wu-wien.ac.at> Date: Fri, 25 Feb 2005 10:54:32 +0100 From: "Rony G. Flatscher" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: bsf-dev@jakarta.apache.org Subject: [PATCH] Not applied yet? [Fwd: [Bsf-discussion] Patch of "EngineUtils.java" to allow invoking public methods of inner classes] Content-Type: multipart/alternative; boundary="------------070001000301080609000103" X-WU-wumi-status: clean v4.4.00/v4433 hiphop wu 51a21dc481a2e27354bee70d0db5e9f6 X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N --------------070001000301080609000103 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Hi there, it seems that the enclosed message never made it to be recognized that it contained a patch which will allow the invocation of public methods of inner classes. Regards, ---rony -------- Original Message -------- Subject: [Bsf-discussion] Patch of "EngineUtils.java" to allow invoking public methods of inner classes Date: Fri, 14 Feb 2003 00:41:11 +0100 From: Rony G. Flatscher To: bsf-dev@jakarta.apache.org CC: bsf-discussion@www-124.southbury.usf.ibm.com Hi there, this is the "diff -uw" of the changes applied to com.ibm.bsf.util.EngineUtils.java (it depicts the already reported char-patch as well). This version uses reflection to find out whether setAccessible() is available (so it is not dependent on the official java version, thanks to Igor to point out that importance!). Regards, ---rony ----------------------------- cut here ------------------------ --- bkp\EngineUtils.java 2001-01-30 17:46:18.000000000 +0100 +++ EngineUtils.java 2003-02-13 22:31:28.000000000 +0100 @@ -20,6 +20,23 @@ // temp directory static BSFClassLoader bsfCL; + // ---rgf, 2003-02-13, determine whether changing accessibility of Methods is possible + static boolean bMethodHasSetAccessible=false; + + // ---rgf, 2003-02-13, determine whether changing accessibility of Methods is possible + static { + Class mc=Method.class; // get the "Method" class object + Class arg[]={boolean.class}; // define an array with the primitive "boolean" pseudo class object + try { + Object o=mc.getMethod("setAccessible", arg ); // is this method available? + bMethodHasSetAccessible=true; // no exception, hence method exists + } + catch (Exception e) + { + bMethodHasSetAccessible=false;// exception occurred, hence method does not exist + } + } + ////////////////////////////////////////////////////////////////////////// /** @@ -137,6 +154,8 @@ else if(args[i] instanceof Double ) argTypes[i]= double.class; } else if (args[i] instanceof Boolean) { argTypes[i] = boolean.class; + } else if (args[i] instanceof Character) { + argTypes[i] = char.class; } } m = MethodUtils.getMethod (beanClass, methodName, argTypes, @@ -147,6 +166,14 @@ } } + // in order to allow access to public methods of inner classes on Java 1.2, 1.3, 1.4 + // one needs to shut off the access-check; otherwise an "IllegalAccessException" is thrown + // ---rgf, 2003-02-13 (no general solution for Java 1.1) + if ( bMethodHasSetAccessible && Modifier.isPublic(m.getModifiers()) ) // available since Java 1.2 + { + m.setAccessible(true); // ---rgf, 2003-02-13, no access checks for this method! + } + // call it, and return the result return m.invoke (bean, args); } catch (Exception e) { ----------------------------- cut here ------------------------ With the above patch the following Object Rexx program now works flawlessly and dumps the System properties: ----------------------------- cut here ------------------------ /* Object Rexx (message operator is the tilde: ~) */ /* this version works on Java 1.2 and higher, *not* on 1.1 (see other variants which work on Java 1.1) */ system=.bsf.cls ~ Class.JC ~ forName("string", "java.lang.System") -- get the "System" class object properties=system~getProperties -- get the System properties enum=properties~propertyNames -- get an enumeration of the property names say copies("=", 70) do while enum~hasMoreElements -- loop over enumeration key=enum~nextElement -- get next element say "key:" left("["key"]", 30) "value: ["properties~getProperty("String", key)"]" end ::requires "BSF.cls" -- get the Object Rexx support for bsf4rexx ----------------------------- cut here ------------------------ If no more errors pop up with the Rexx and Object Rexx support until the end of February, I will adapt the Rexx engine to Apache BSF and apply the necessary licenses. _______________________________________________ Bsf-discussion mailing list Bsf-discussion@www-124.ibm.com http://www-124.ibm.com/developerworks/oss/mailman/listinfo/bsf-discussion --------------070001000301080609000103--