i have got the same problem to solve and inspired by John's solution, i have done something like this on top of code provided above and it seem to solve the problem atleast for a sample that i tried. would be great if John or Thomas or anyone could review it and point me if anything is wrong. Also John, would be great if you could share your complete code.
This comes in the custom Service Locator that i hooked in via custom Request Factory Servlet class: Also see it formatted here: http://pastie.org/1685351 private final static Map<Class<?>, Class<? extends BaseProxy>> s_proxyTypeCache = new HashMap<Class<?>, Class<? extends BaseProxy>>(); @SuppressWarnings("unchecked") @Override public <T> Class<? extends T> resolveClientType(Class<?> domainClass, Class<T> clientType, boolean required) { /*- * Inspired by * http://groups.google.com/group/google-web-toolkit/browse_thread/thread/dddd36d0ed4f87be/45af985914ac1780?lnk=gst&q=maitland * as we mostly use interface type of domain in ProxyFor annotation. * Assumption: * Type <T> should be one that is/extends BaseProxy */ Class<? extends T> c = null; ProxyFor p = clientType.getAnnotation(ProxyFor.class); if (p != null && p.value().isAssignableFrom(domainClass)) { // job made simple as clientType passed was the real client proxy // that we defined c = super.resolveClientType(p.value(), clientType, required); } else { // ProxyFor won't be present obviously if clientType param was // BaseProxy itself c = super.resolveClientType(domainClass, clientType, required); if (c != null) { // we might need/use it later s_proxyTypeCache.put(domainClass, (Class<? extends BaseProxy>) c); } else { // client type couldn't be retrieved if we had given interface // type of domain obj in ProxyFor anno and if Locator had // resolved it to the actual impl type of domain obj and passed // it as domainClass; See if we already had gotten and stored // the client type for the same domain's corresponding interface // type Set<Class<?>> domainTypes = s_proxyTypeCache.keySet(); for (Iterator<Class<?>> iterator = domainTypes.iterator(); iterator .hasNext();) { Class<?> domType = iterator.next(); if (domType.isAssignableFrom(domainClass)) { // good, we have an entry for domain obj's // interface/class type c = (Class<? extends T>) s_proxyTypeCache.get(domType); break; } } } } if (null == c) { throw new YourApplicationRuntimeException( "Unable to resolve the client side custom defined proxy class given the i/p {domain class : " + domainClass + ", " + "client type : " + clientType + "}"); } return c; } On Jan 15, 6:28 pm, John Maitland <[email protected]> wrote: > Thanks for the advise. After using getTop().resolveClientType this > open up further compilications, not least a circular dependency in the > layers. However, the next problem was intergrating this with a custom > Locator, which resolves the domain class with the BaseProxy and not > the actual proxy for the domain class (therefore above code doesnt > work with BaseProxy). Therefore I put in a further cache map the > ProxyFor class to the client class. > > Problem solved! On Jan 15, 6:28 pm, John Maitland <[email protected]> wrote: > Thanks for the advise. After using getTop().resolveClientType this > open up further compilications, not least a circular dependency in the > layers. However, the next problem was intergrating this with a custom > Locator, which resolves the domain class with the BaseProxy and not > the actual proxy for the domain class (therefore above code doesnt > work with BaseProxy). Therefore I put in a further cache map the > ProxyFor class to the client class. > > Problem solved! -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
