I'm trying to work up an example of request factory using a service locator. The discussions/tutorials all say that ServiceLocator is useful when there's a generic DAO with static methods for instance operations. I'm taking that to mean that my entity classes don't have their own methods to get a specific instance.
The javadocs for ServiceLocator say "A ServiceLocator provides instances of a type specified by a
My entities are all instances of DataStoreItem. One specific subclass is Flick.
I can write a service that uses a locator with static methods including public static DataStoreItem find(Class<? extends DataStoreItem> clazz, Long id).
My request context class is public interface FlickRequest extends RequestContext.
And, unlike so many of the examples I've seen, I actually see benefit to having the context definition include a method to retrieve a single instance (otherwise, how do I actually request one?):
public Request<FlickProxy> get(long id);
But, as I said before, my Flick class doesn't include a static get method. The locator analog to that method takes a class object in addition to the id (to be honest, I haven't tried passing it my proxy class object, but I doubt that would work, since on the server side it would have to receive the actual bean class, not the proxy class). And, it looks like the ServiceLocator will only work for the methods that ought to operate on instances, not methods that would always be static.
I tried this as my service locator:
public class FlickServiceLocator implements ServiceLocator {
@Override
public Object getInstance(Class<?> clazz) {
return new ItemDAOWrapper<Flick>(Flick.class);
}
}
Where the ItemDAOWrapper holds the class object and delegates find(id) to find(clazz, id), but am still seeing errors on my request context that my domain class doesn't have a find method.
So, how do I write a method to get an instance by id, when the entity class doesn't do that, and my generic DAO class can only do that when given an class to work on (short of writing an explicit wrapper class for each domain type that can add those methods)?
-- The javadocs for ServiceLocator say "A ServiceLocator provides instances of a type specified by a
Service when Request methods declared in a RequestContext are mapped onto instance (non-static) methods." I think that's actually backwards -- it looks like the ServiceLocator supplies an instance when what would normally be instance methods (like persist) are actually static and passed an instance. My guess is that the framework generates glue code to invoke the methods on the instance but also pass them the instance.My entities are all instances of DataStoreItem. One specific subclass is Flick.
I can write a service that uses a locator with static methods including public static DataStoreItem find(Class<? extends DataStoreItem> clazz, Long id).
My request context class is public interface FlickRequest extends RequestContext.
And, unlike so many of the examples I've seen, I actually see benefit to having the context definition include a method to retrieve a single instance (otherwise, how do I actually request one?):
public Request<FlickProxy> get(long id);
But, as I said before, my Flick class doesn't include a static get method. The locator analog to that method takes a class object in addition to the id (to be honest, I haven't tried passing it my proxy class object, but I doubt that would work, since on the server side it would have to receive the actual bean class, not the proxy class). And, it looks like the ServiceLocator will only work for the methods that ought to operate on instances, not methods that would always be static.
I tried this as my service locator:
public class FlickServiceLocator implements ServiceLocator {
@Override
public Object getInstance(Class<?> clazz) {
return new ItemDAOWrapper<Flick>(Flick.class);
}
}
Where the ItemDAOWrapper holds the class object and delegates find(id) to find(clazz, id), but am still seeing errors on my request context that my domain class doesn't have a find method.
So, how do I write a method to get an instance by id, when the entity class doesn't do that, and my generic DAO class can only do that when given an class to work on (short of writing an explicit wrapper class for each domain type that can add those methods)?
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment