Re: Enum method overrides and WO bindings

2013-06-07 Thread Kieran Kelleher
Declare the enum as its own java class file and see if that works:

MyClass.java
public class MyClass {
   
   }

Status.java
   public enum Status {
   one{ @Override public String description() { return "eins"; } },
   two{ @Override public String description() { return "zwei"; } };
   public abstract String description();
   }
  

Regards, Kieran.
(Sent from my iPhone)


On Jun 7, 2013, at 3:58 AM, 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  (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/kelleherk%40gmail.com
> 
> This email sent to kelleh...@gmail.com

 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Enum method overrides and WO bindings

2013-06-07 Thread Musall Maik
Hi Kieran,

makes no difference.

java.lang.IllegalAccessException: Class 
com.webobjects.foundation.NSKeyValueCoding$ValueAccessor$1 can not
access com.foo.bar.Status$1!

Maik


Am 07.06.2013 um 11:40 schrieb Kieran Kelleher :

> Declare the enum as its own java class file and see if that works:
> 
> MyClass.java
> public class MyClass {
> 
>   }
> 
> Status.java
>   public enum Status {
>   one{ @Override public String description() { return "eins"; } },
>   two{ @Override public String description() { return "zwei"; } };
>   public abstract String description();
>   }
> 
> 
> Regards, Kieran.
> (Sent from my iPhone)
> 
> 
> On Jun 7, 2013, at 3:58 AM, 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  (Webobjects-dev@lists.apple.com)
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/webobjects-dev/kelleherk%40gmail.com
>> 
>> This email sent to kelleh...@gmail.com


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Enum method overrides and WO bindings

2013-06-07 Thread D Tim Cummings
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  (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/tim%40triptera.com.au
> 
> This email sent to t...@triptera.com.au

 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Enum method overrides and WO bindings

2013-06-07 Thread Musall Maik

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 :

> 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  (Webobjects-dev@lists.apple.com)
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/webobjects-dev/tim%40triptera.com.au
>> 
>> This email sent to t...@triptera.com.au
> 

 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Enum method overrides and WO bindings

2013-06-07 Thread D Tim Cummings
public enum Status {
  one (1),
  two (2);
  private final int days;
  Status(int days) {
this.days = days;
  }
  public DateTime computeValue() {
return new DateTime().plusDays(days);
  }
}

On 07/06/2013, at 8:34 PM, 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 :
> 
>> 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  (Webobjects-dev@lists.apple.com)
>>> Help/Unsubscribe/Update your Subscription:
>>> https://lists.apple.com/mailman/options/webobjects-dev/tim%40triptera.com.au
>>> 
>>> This email sent to t...@triptera.com.au
>> 
> 

 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Enum method overrides and WO bindings

2013-06-07 Thread Bogdan Zlatanov
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 :
> 
>> 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  (Webobjects-dev@lists.apple.com)
>>> Help/Unsubscribe/Update your Subscription:
>>> https://lists.apple.com/mailman/options/webobjects-dev/tim%40triptera.com.au
>>> 
>>> This email sent to t...@triptera.com.au
>> 
> 
> ___
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/bogdan.zlatanov%40gmail.com
> 
> This email sent to bogdan.zlata...@gmail.com

 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Enum method overrides and WO bindings

2013-06-07 Thread Musall Maik

Uh, I should have made the implementation more different in the two. In 
general, the enums I have are more lengthy, and they do all sorts of different 
stuff to compute something in their methods. They can't share a common 
implementation, or at least there could be a common one, but the point would be 
that a few enum instances would need to override the implementation, not just 
differ in fixed values.


Am 07.06.2013 um 12:45 schrieb D Tim Cummings :

> public enum Status {
>   one (1),
>   two (2);
>   private final int days;
>   Status(int days) {
> this.days = days;
>   }
>   public DateTime computeValue() {
> return new DateTime().plusDays(days);
>   }
> }
> 
> On 07/06/2013, at 8:34 PM, 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 :
>> 
>>> 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  (Webobjects-dev@lists.apple.com)
 Help/Unsubscribe/Update your Subscription:
 https://lists.apple.com/mailman/options/webobjects-dev/tim%40triptera.com.au
 
 This email sent to t...@triptera.com.au
>>> 
>> 
> 
> ___
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/maik%40selbstdenker.ag
> 
> This email sent to m...@selbstdenker.ag

 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Enum method overrides and WO bindings

2013-06-07 Thread Musall Maik
Good one!

Although this isn't exactly reducing boilerplate, it shows up a completely 
different way that actually works. I didn't really think of implementing 
NSKeyValueCoding in an enum class. I think this is worthwhile at least for long 
complicated enums where two more methods are ok. Thanks!

Anyone else? :)

Maik


Am 07.06.2013 um 13:16 schrieb Bogdan Zlatanov :

> And this is a more general way, but you probably guessed that already :)
> 
> public enum Status implements NSKeyValueCoding {
>   one { 
>   @Override public String description() { return "one"; }
>   @Override public Integer code() { return 1; }
>   },
>   two { 
>   @Override public String description() { return "two"; }
>   @Override public Integer code() { return 2; }
>   };
>   
>   public abstract String description();
>   public abstract Integer code();
> 
>   @Override
>   public Object valueForKey(String s) {
>   System.out.println("Status.valueForKey(): " + s);
>   try {
>   return this.getClass().getMethod(s, (Class[]) 
> null).invoke(this, (Object[]) null);
>   } catch (Exception e) {
>   e.printStackTrace();
>   throw new RuntimeException(e);
>   }
>   }
> 
>   @Override
>   public void takeValueForKey(Object obj, String s) {
>   // TODO Auto-generated method stub
>   System.out.println("Status.takeValueForKey()");
>   }
> }
> 
> On 7 Jun 2013, at 13:07, Bogdan Zlatanov wrote:
> 
>> 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 :
>>> 
 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(); }
>}
>}

Re: Enum method overrides and WO bindings

2013-06-07 Thread D Tim Cummings
Fair enough.  Looks like your original workaround is the way to go.  I haven't 
come across a situation where I needed to override methods in enums.

Tim


On 07/06/2013, at 9:22 PM, Musall Maik wrote:

> 
> Uh, I should have made the implementation more different in the two. In 
> general, the enums I have are more lengthy, and they do all sorts of 
> different stuff to compute something in their methods. They can't share a 
> common implementation, or at least there could be a common one, but the point 
> would be that a few enum instances would need to override the implementation, 
> not just differ in fixed values.
> 
> 
> Am 07.06.2013 um 12:45 schrieb D Tim Cummings :
> 
>> public enum Status {
>>   one (1),
>>   two (2);
>>   private final int days;
>>   Status(int days) {
>> this.days = days;
>>   }
>>   public DateTime computeValue() {
>> return new DateTime().plusDays(days);
>>   }
>> }
>> 
>> On 07/06/2013, at 8:34 PM, 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 :
>>> 
 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  (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/tim%40triptera.com.au
> 
> This email sent to t...@triptera.com.au
 
>>> 
>> 
>> ___
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/webobjects-dev/maik%40selbstdenker.ag
>> 
>> This email sent to m...@selbstdenker.ag
> 

 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Enum method overrides and WO bindings

2013-06-07 Thread Chuck Hill
This would be my suggestion of how to make this work.

Chuck

On 2013-06-07, at 4:34 AM, Musall Maik wrote:

> Good one!
> 
> Although this isn't exactly reducing boilerplate, it shows up a completely 
> different way that actually works. I didn't really think of implementing 
> NSKeyValueCoding in an enum class. I think this is worthwhile at least for 
> long complicated enums where two more methods are ok. Thanks!
> 
> Anyone else? :)
> 
> Maik
> 
> 
> Am 07.06.2013 um 13:16 schrieb Bogdan Zlatanov :
> 
>> And this is a more general way, but you probably guessed that already :)
>> 
>> public enum Status implements NSKeyValueCoding {
>>  one { 
>>  @Override public String description() { return "one"; }
>>  @Override public Integer code() { return 1; }
>>  },
>>  two { 
>>  @Override public String description() { return "two"; }
>>  @Override public Integer code() { return 2; }
>>  };
>>  
>>  public abstract String description();
>>  public abstract Integer code();
>> 
>>  @Override
>>  public Object valueForKey(String s) {
>>  System.out.println("Status.valueForKey(): " + s);
>>  try {
>>  return this.getClass().getMethod(s, (Class[]) 
>> null).invoke(this, (Object[]) null);
>>  } catch (Exception e) {
>>  e.printStackTrace();
>>  throw new RuntimeException(e);
>>  }
>>  }
>> 
>>  @Override
>>  public void takeValueForKey(Object obj, String s) {
>>  // TODO Auto-generated method stub
>>  System.out.println("Status.takeValueForKey()");
>>  }
>> }
>> 
>> On 7 Jun 2013, at 13:07, Bogdan Zlatanov wrote:
>> 
>>> 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 :
 
> 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"; 
>> } },
>> 

Re: Enum method overrides and WO bindings

2013-06-07 Thread Bogdan Zlatanov

If you plan to keep all your enums in one package your only alternative I see 
is to:

1. Create your own NSKeyValueCoding.ValueAccessor and place it in the 
same package as your enums.

2. Register your newly created NSKeyValueCoding.ValueAccessor by 
something like this

NSKeyValueCoding.ValueAccessor.setProtectedAccessorForPackageNamed(new 
MyValueAccessor(), MyEnum.class.getPackage().getName());

in your Application() constructor or if you use Wonder in either 
finishInitialization() or didFinishLaunching().

If your enums will be just a few and/or placed in different packages, then this 
will cause even bigger hassle.


Cheers,
Bogdan


On 7 Jun 2013, at 13:34, Musall Maik wrote:

> Good one!
> 
> Although this isn't exactly reducing boilerplate, it shows up a completely 
> different way that actually works. I didn't really think of implementing 
> NSKeyValueCoding in an enum class. I think this is worthwhile at least for 
> long complicated enums where two more methods are ok. Thanks!
> 
> Anyone else? :)
> 
> Maik
> 
> 
> Am 07.06.2013 um 13:16 schrieb Bogdan Zlatanov :
> 
>> And this is a more general way, but you probably guessed that already :)
>> 
>> public enum Status implements NSKeyValueCoding {
>>  one { 
>>  @Override public String description() { return "one"; }
>>  @Override public Integer code() { return 1; }
>>  },
>>  two { 
>>  @Override public String description() { return "two"; }
>>  @Override public Integer code() { return 2; }
>>  };
>>  
>>  public abstract String description();
>>  public abstract Integer code();
>> 
>>  @Override
>>  public Object valueForKey(String s) {
>>  System.out.println("Status.valueForKey(): " + s);
>>  try {
>>  return this.getClass().getMethod(s, (Class[]) 
>> null).invoke(this, (Object[]) null);
>>  } catch (Exception e) {
>>  e.printStackTrace();
>>  throw new RuntimeException(e);
>>  }
>>  }
>> 
>>  @Override
>>  public void takeValueForKey(Object obj, String s) {
>>  // TODO Auto-generated method stub
>>  System.out.println("Status.takeValueForKey()");
>>  }
>> }
>> 
>> On 7 Jun 2013, at 13:07, Bogdan Zlatanov wrote:
>> 
>>> 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 :
 
> 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.webobje