Factory for lifecycle listeners
-------------------------------
Key: CAY-949
URL: https://issues.apache.org/cayenne/browse/CAY-949
Project: Cayenne
Issue Type: New Feature
Components: Cayenne JPA
Affects Versions: 3.0
Reporter: Andrus Adamchik
Assignee: Andrus Adamchik
Fix For: 3.0
So far we've followed the JPA spec in Cayenne classic callbacks/listeners implementation. I am using listeners extensively and till now I used to install them in the code. Now that Modeler supports listeners, I discovered that the default mechanism of listener instantiation (Class.forName("listenerClass").newInstance()) is inadequate when a listener has dependencies on its environment. I guess in the J2EE world the dependencies are obtained via JNDI, but I wanted to use injection as a cleaner approach (and to avoid setting up JNDI).
So... I wrote an extension point that would allow users to register a factory object for creating the listeners:
public interface EntityListenerFactory {
<T> T createListener(Class<T> listenerClass, ObjEntity entity);
}
This would support dependency injection (or any other environment specific customization) of the listener objects, as well as using interfaces for the listeners - something JPA does not support. So the same listener configuration may be used with different implementations depending on some app logic.
-- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
This archive was generated by hypermail 2.0.0 : Fri Dec 28 2007 - 13:09:33 EST