I would suggest the proxy to implement the GoF state pattern (an idea I got from commons-collection FastArrayList):
You have two proxies where the outer one contains the inner one. The outerone just plainly gives further to a service field which is either the innter proxy or the actual loaded service. The inner proxy is like the current deferred proxy:
The code of a ready proxy would look like this: (This would of course have to be produced with JavaAssist):
public class OuterProxy implements ServiceInterface{
private ServiceExtenstionPointImpl _sep; private InnerProxy _inner = new InnerProxy(); private ServiceInterface _service = new InnerProxy();
//an example method of the ServiceInterface public Object exampleMethod(Object arg){ return _service.exampleMethod(arg); }
//the innerproxy public class InnerProxy implements ServiceInterface{ //method which loads the actual service private synchronized ServiceInterface getService(){ if(_service != this) return _service; _service = _sep.constructServiceImplementation(); return _service; }
//and the exampleMethod public Object exampleMethod(Object arg){ return this.getService().exampleMethod(arg); }
} }
This also prevents the - potential - method conflict that can happen when a ServiceInterface implements the SERVICE_ACCESSOR_METHOD_NAME (_service) method.
By the way I saw this when I was looking for a way to implement basic livecycle management. Have you thought of a destroy method. I think it is realy needed before Database, DAO, Pool, Cache, etc Services can be implemented.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]