There's almost never a reason to use a static variable in your Application
class, because Application is singleton. But beside that, both valueForKey and
the crazy reflection stuff are totally unnecessary in this case. For a static,
you don't need an "instance", so just refer to your.app.Application.appPilot.
For the valueForKey case, I would never use valueForKey, because you're just
giving up compiler checking for not much ... Do
((your.app.Application)WOApplication.application()).whateverKey() instead and
let the compiler watch your back.
ms
On Oct 21, 2011, at 6:10 AM, Jürgen Tabert wrote:
> I think the problem is that the "variable" is static. (the developer told me
> to use static)
>
> from Application.java
>
> public class Application extends ERXApplication {
>
> public static Pilot appPilot = null;
>
> ...
>
> @Override
> public void finishInitialization() {
> ...
> // init Library
> appPilot = new Pilot();
> try {
> ...
> appPilot.init(lKey, lKey, libPath, languageId);
> } catch (PilotException e) {
> ...
> }
>
>
> inside a class in the framework some ugly code
>
> ...
> try {
> ...
> // works
> ERXApplication app = ERXApplication.erxApplication();
> Class<? extends ERXApplication> appClass = app.getClass();
> Field appField = appClass.getField("appPilot");
> Pilot appPilot = (Pilot) appField.get(app);
> ...
>
> something like app.valueForKey("appPilot") works only if the variable is not
> static
>
>
> On 21.10.2011, at 04:02, Andrew Lindesay wrote:
>
>> Hello Jürgen;
>>
>> It depends on the situation.
>>
>> Can you elaborate what you mean by "variables".
>>
>> At the very least, you could use KVC;
>>
>> WOApplication.application().valueForKey(<key>)
>>
>> cheers.
>>
>> On 21/10/11 1:13 PM, Jürgen Tabert wrote:
>>> Hi all,
>>>
>>> I am looking for the easiest (best?) way to access a WOApplication
>>> variables from inside a framework.
>>>
>>> Thanks for any help,
>>> Jürgen
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Webobjects-dev mailing list ([email protected])
>>> Help/Unsubscribe/Update your Subscription:
>>> http://lists.apple.com/mailman/options/webobjects-dev/apl%40lindesay.co.nz
>>>
>>> This email sent to [email protected]
>>>
>>
>>
>> --
>> Andrew Lindesay
>> www.silvereye.co.nz
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list ([email protected])
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/webobjects-dev/jtabert%40htgreenline.de
>>
>> This email sent to [email protected]
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list ([email protected])
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com
>
> This email sent to [email protected]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]