Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

another Permissions question

Status
Not open for further replies.

carpeliam

Programmer
Mar 17, 2000
990
US
I'm getting closer and closer...<br><br>It won't find my methods when they're private, but <FONT FACE=monospace>getDeclaredMethod()</font> is supposed to do that... anybody have any clues as to where I can go from here?<br><FONT FACE=monospace><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SecurityManager sm = new SecurityManager();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sm.checkPermission(new ReflectPermission(&quot;suppressAccessChecks&quot;));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sm.checkPermission(new RuntimePermission(&quot;accessDeclaredMembers&quot;));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.setSecurityManager(sm);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// grant access to get/set methods<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Class c = o.getClass().getMethod(&quot;get&quot;+key, null).getReturnType();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Class[] parameterFiller={c};<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Method mSet = propMethod(o.getClass(), key, parameterFiller);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mSet.setAccessible(true);</font><br><br>=======================================================================<FONT FACE=monospace><br><br>&nbsp;&nbsp;&nbsp;&nbsp;private static Method propMethod (Class c, String key, Class[] parameterFiller) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return c.getDeclaredMethod(&quot;set&quot;+key, parameterFiller);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} catch (NoSuchMethodException e) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return propMethod (c.getSuperclass(), key, parameterFiller);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font><br><br><br>=======================================================================<br><br>if anybody can help me go from here... propMethod will never find the right method, even though I know it exists. If there's any code here you don't understand, just let me know, I'll explain... I'm in a rush at the moment, sorry.<br><br>Thanks all...<br> <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence."
 
Nevermind, my problem was that a particular class's &quot;setSerialNumber()&quot; method forgot to include the parameter... so when it said &quot;this.serialNumber = serialNumber&quot;, it wasn't setting with a new serial #, it was just copying the same old value to the new one.<br><br>So... I now know how to get and set private variables using the Java 1.2 Reflect API. woohoo! That was only a few weeks of searching. I'm rather happy at the moment. And if anybody wants me to write a FAQ with my findings (if you think that kind of thing would be useful to you in your own coding), I could do that. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top