Re: Custom attribute class conversion in entity modeler
Re: Custom attribute class conversion in entity modeler
- Subject: Re: Custom attribute class conversion in entity modeler
- From: Anjo Krank <email@hidden>
- Date: Sun, 8 Feb 2009 13:44:37 +0100
Inner classes end up with a '$' instead of a '.' as the class name:
com.tuorlo.hdm.eo.Client$Status
Cheers, Anjo
Am 08.02.2009 um 12:50 schrieb Riccardo De Menna:
BTW... I'm having a lot of issues with the custom classes setup.
Now for instance I'm trying to use a static inner class and it fails
at runtime.
Immagine the following:
public static class Status {
public final static Status ACTIVE = new Status(0);
public final static Status DISABLED = new Status(1);
public final static Status TRIAL = new Status(2);
public final static Status DELETED = new Status(3);
public static Status forID(int id) { return new Status(id); }
private final int _id;
private Status(int id) { _id = id; }
public int id() { return _id; }
public boolean equals(Status s) { return _id == s.id(); }
}
or even the more fancy
public static enum Status {
ACTIVE(0),
DISABLED(1),
TRIAL(2),
DELETED(-2);
private static final Map<Integer,Status> lookup = new
HashMap<Integer,Status>();
public static Status forID(int id) { return lookup.get(id); }
private final int _id;
private Status(int id) { _id = id; }
public int id() { return _id; }
static {
for( Status s : EnumSet.allOf(Status.class) )
lookup.put(s.id(), s);
}
}
I'd like to have these factored/converted directly from the db (with
the forID/id methods) but since they are strongly related to the
specific entity class their perfect setup for me is to have them as
static inner classes of the entity itself (or even better as java
enums).
The static inner setup fails at runtime with:
java.lang.IllegalStateException: adaptorValueType: unable to load
class named 'com.tuorlo.hdm.eo.Client.Status' for attribute status
on entity Client
Is there a workaround?
rdm
On 06/feb/09, at 20:21, Mike Schrag wrote:
someone else had an issue with a static initializer previously,
which is why i was considering this change ...
On Feb 6, 2009, at 11:50 AM, Riccardo De Menna wrote:
Nevermind,
The issue was not caused by the Entity Modeler setting but rather
from a static piece of code in the Entity class. The static code
is being executed by entity modeler as soon as the class
initializes I guess.
This is the static code:
static {
TEvent.define(1,"SOMETHING NASTY HAS HAPPEND");
TEvent.define(2,"SOMETHING FUNNY HAS HAPPEND", TEvent.forID(1) );
}
If I remove the second TEvent.define it works. It's the nested
TEvent causing the problem. As if entity modeler can't find the
class for the nested one but it can for the non nested.
In this case it's just a matter of slightly changing the
TEvent.define parameters so that it takes an int instead of
itself. Simple workaround... it works now but I guess there could
be more complicate cases where this might not be possible.
No idea what it could be. Just wrote this reply to clear what was
going on and thank mike for his usual kindness.
rdm
On 06/feb/09, at 16:04, Mike Schrag wrote:
And my com.tuorlo.user.TEvent class has these two methods:
Does this class actually exist in your project? And is it in the
classpath? Entity Modeler constructs its classpath based on you
project's classpath definition.
ms
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden