Hi everyone,
I've been horribly busy, and still am, but I would like to have true
POJO support done before my presentation at Fosdem in three weeks.
As a recap, the plan is to allow people to re-use their existing models
without any changes. These can even be packaged in a bytecode jar
without any source code available. To allow them to add constraints,
validation and callbacks, they would create a sibling MetaData class
that extends for example CmfValidation and implements Callbacks.
For example:
public class Friend {
private String firstName;
private String lastName;
public void setFirstName(String name) { this.firstName = name; }
public String getFirstName() { return firstName; }
public void setLastName(String name) { this.lastName = name; }
public String getLastName() { return lastName; }
}
public class FriendMetaData extends CmfValidation implements
Callbacks<Friend> {
protected void activateValidation() {
addConstraint(...);
...
}
public void beforeInsert(Friend friend) {
...
}
...
}
Now the difficult part is how to bring these two together since RIFE
allows you to modify the meta data at runtime. This means that each POJO
instance has its own MetaData instance.
Initially I thought that I should maintain a WeakHashMap with all the
references and in the background look them up, etc etc. I worked out
some strategies to retrofit the existing approach and I don't feel
comfortable with it at all. It seems much too brittle and quite a lot of
overhead. I can also see memory problems arise since the HashMap needs
to be kept in sync with the sweeps of the garbage collector and the
instances that are collected.
I now am looking into a totally different approach. My reasoning is as
follows, what you want to do is implement all the meta data interfaces
(Constrained, Validated, Callbacks) and delegate to instances of the
concrete classes that you want to use. Typically you would to this with
a member variable and delegate all the methods of the interface classes
to the same methods on that variable. So, my plan now is to have the
custom classloader look for the MetaData sibling classes and if they're
found, instrument the bytecode of the models on-the-fly. They would then
automatically implement the interfaces that are implemented by the
MetaData class and a private member variable (for example:
rife$metadata$instance - this is a valid name in bytecode) would contain
an instance of the MetaData class. All the required methods would then
be added to the model class to perform the delegation. Of course, if
some already exist, they are not overridden.
What do you guys think, does this sound like a good way to implement it?
Best regards,
Geert
--
Geert Bevin Uwyn bvba
"Use what you need" Avenue de Scailmont 34
http://www.uwyn.com 7170 Manage, Belgium
gbevin[remove] at uwyn dot com Tel +32 64 84 80 03
PGP Fingerprint : 4E21 6399 CD9E A384 6619 719A C8F4 D40D 309F D6A9
Public PGP key : available at servers pgp.mit.edu, wwwkeys.pgp.net
_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users