This should work, hopefully.
public enum Status implements NSKeyValueCoding {
one { @Override public String description() { return "one"; }},
two { @Override public String description() { return "two"; }};
public abstract String description();
@Override
public Object valueForKey(String s) {
System.out.println("Status.valueForKey(): " + s);
return description();
}
@Override
public void takeValueForKey(Object obj, String s) {
// TODO Auto-generated method stub
System.out.println("Status.takeValueForKey()");
}
}
On 7 Jun 2013, at 12:34, Musall Maik wrote:
>
> Got that already by private mail. All right, let's modify the example.
> Returning a fixed string was oversimplifying.
>
>
> public enum Status {
> one { @Override public DateTime computeValue() { new
> DateTime().plusDays( 1 ); },
> two { @Override public DateTime computeValue() { new
> DateTime().plusDays( 2 ); };
> public abstract DateTime computeValue();
> }
>
>
> Maik
>
>
> Am 07.06.2013 um 12:27 schrieb D Tim Cummings <[email protected]>:
>
>> Another workaround which is less ugly.
>>
>> public enum Status {
>> one ("eins"),
>> two ("zwei");
>> private final String description;
>> Status(String description) {
>> this.description = description;
>> }
>> public String description() {
>> return description;
>> }
>> }
>>
>> Tim
>>
>>
>> On 07/06/2013, at 5:58 PM, Musall Maik wrote:
>>
>>> Hi,
>>>
>>> some time ago, I discovered the following problem with Enums and WO
>>> bindings (broken down to a simple example):
>>>
>>> package com.foo.bar;
>>> public class MyClass {
>>> public static enum Status {
>>> one { @Override public String description() { return "eins";
>>> } },
>>> two { @Override public String description() { return "zwei";
>>> } };
>>> public abstract String description();
>>> }
>>> }
>>>
>>> While this works nicely in all Java code, WO bindings will not see the
>>> overridden description() implementations. At least not when using Java
>>> packages (it seems to work if everything is in the default package, but
>>> that doesn't help me). You get an error like:
>>>
>>> java.lang.IllegalAccessException: Class
>>> com.webobjects.foundation.NSKeyValueCoding$ValueAccessor$1 can not access
>>> a member of class com.foo.bar.MyClass$Status$1 with modifiers "public"
>>>
>>> or, if using JRebel, you get
>>>
>>> java.lang.IllegalAccessException: Class<?>
>>> com.webobjects.foundation.NSKeyValueCoding$ValueAccessor$1 can not access
>>> com.foo.bar.MyClass$Status$1!
>>>
>>> My current workaround:
>>>
>>> package com.foo.bar;
>>> public class MyClass {
>>> public static enum Status {
>>> one { @Override String descriptionImpl() { return "eins"; } },
>>> two { @Override String descriptionImpl() { return "zwei"; } };
>>> abstract String descriptionImpl();
>>> public String description() { return descriptionImpl(); }
>>> }
>>> }
>>>
>>> which works but is ugly. Now I'm about to implement another Enum with a lot
>>> of methods and it bothers me. Anyone an idea how to improve the situation?
>>>
>>> Thanks
>>> Maik
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Webobjects-dev mailing list ([email protected])
>>> Help/Unsubscribe/Update your Subscription:
>>> https://lists.apple.com/mailman/options/webobjects-dev/tim%40triptera.com.au
>>>
>>> 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:
> https://lists.apple.com/mailman/options/webobjects-dev/bogdan.zlatanov%40gmail.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:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]