Sunday, June 21, 2015

Re: Can an interface serve as proxy for more than one class in RequestFactory?

HI,

I know this is an old thread, but I'm having a similar problem.

I have a class A that is an entity on my server side and a class B that extends A (with PrimaryKeyJoinColumn). So, in other words I have:

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class A {
...
}

@Entity
@PrimaryKeyJoinColumn(name="a_id", referencedColumnName="id")
public class B extends A {
...
}

I already have A extending EntityProxy:

@ProxyFor(A.class)
public interface AProxy extends EntityProxy {
...
}

And now I need to map B as an Entity Proxy as well, but I'm getting an exception. What I did is:

@ProxyFor(B.class)
public interface BProxy extends AProxy, EntityProxy {
...
}

but I get the following exception:
BProxy is not an EntityProxy type
    at com.google.web.bindery.requestfactory.shared.impl.IdFactory.asEntityProxy(IdFactory.java:66)


Is it possible to do what I'm trying here? If so, how?

Thanks,
Aldo


On Mon, Jun 27, 2011 at 12:48 PM, Ryan McFall <mcfall.ryan@gmail.com> wrote:
Thanks for the reply.  I think you're right that there's no great
solution to my problem.

I've got it solved at the moment by creating a client side interface,
and wrapper classes for the two proxies that both implement that
client-side interface (basically mimicking the functionality of the
common server interface).  I don't like it, but it seems to be
working.

Ryan

On Jun 27, 10:00 am, Thomas Broyer <t.bro...@gmail.com> wrote:
> On Monday, June 27, 2011 12:40:05 PM UTC+2, Ryan McFall wrote:
>
> > I have two domain objects that implement the same interface on the
> > server, and a third class that contains a (heterogeneous) List of
> > those objects.  I need to be able to expose this list on the client
> > side.  The domain objects do not share a common super-class (they
> > instead delegate the common functionality to another object).
>
> > Given that all proxy interfaces are required to extend BaseProxy, I
> > cannot figure out how to write multiple proxies that will have a
> > parent interface in common.  I tried making a base interface that both
> > proxies extend, but that base interface must extend EntityProxy, and
> > the GWT compiler complains if you have an interface that extends
> > EntityProxy but does not have a ProxyFor annotation.
>
> The interface need not extend EntityProxy, you can have:
> interface BaseInterface { ... }
> interface FooProxy extends BaseInterface, EntityProxy { }
> interface BarProxy extends BaseInterface, EntityProxy { }
>
> ...but then you obviously cannot have a proxy declare a list that contain
> both FooProxy and BarProxy, as a Collection<BaseInterface> would be rejected
> because BaseInterface doesn't extend EntityProxy or ValueProxy.
>
> BUT!
>
>    - The hierarchy of proxy interfaces need not mimic the one of domain
>    objects on the server-side. You could have "interface BarProxy extends
>    FooProxy" for example.
>    - or, because you can have more than one proxy interface for the same
>    domain object, you could annotate the base interface with a @ProxyFor for
>    one of the domain class.
>
> I am wondering (although I suspect the answer is no) whether I can
>
> > have a single interface declare that it is a proxy for multiple
> > entities.  If not, other ideas for making this work are welcome.
>
> You're right: an interface can only map to a single domain class. Moreover,
> you cannot use an interface in a @ProxyFor, as the
> RequestFactoryInterfaceValidator used by the RequestFactoryServlet will
> ultimately flag it as an error (so you unfortunately cannot use the
> interface implemented by both your domain objects).
>
> RequestFactory does not (yet<http://code.google.com/p/google-web-toolkit/issues/detail?id=5367>)
> support polymorphism, so your collection can only ever contain a single
> "interface".
>
> Not sure there's a solution to your problem besides refactoring your domain
> classes (but maybe if you share a bit more information, maybe there's a
> solution)

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


--
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/d/optout.

No comments:

Post a Comment