Request Factory polymorphic with locator

72 views
Skip to first unread message

bond

unread,
Aug 22, 2012, 12:06:25 PM8/22/12
to google-we...@googlegroups.com
Hi,
I'd like to use polymorphic type mapping with use of Locator.

I'm in this situation:

@Entity class MyBase {...}
@Entity class MyChild1 extends MyBase {...}
@Entity class MyChild2 extends MyBase {...}
...
@ProxyFor(MyBase.class) class MyBaseProxy extends EntityProxy {...}
@ProxyFor(MyChild1.class) class MyChild1Proxy extends MyBaseProxy {...}
@ProxyFor(MyChild2.class) class MyChild2Proxy extends MyBaseProxy {...}
...

@Service(value =
MyBaseRequestDao.class, locator = DaoLocator.class)
@ExtraTypes({
MyChild1.class, MyChild2.class })
public interface MyBaseRequest extends RequestContext {
   
Request<MyBaseProxy> getStuff(); // MyChild1 here
}
...
Request<MyBaseProxy> getStuffRequest = request.getStuff();
getStuffRequest
.fire(new Receiver<MyBaseProxy>() {
   
@Override
   
public void onSuccess(MyBaseProxy proxy) {
if(proxy instanceof
MyChild1Proxy)         button.setText(((MyChild1Proxy)proxy).getQwerty()); // HERE!
   
}
});

I'm using Hibernate on the server and in the server (on my
MyBaseRequestDao) I can see the correct type of objects. On the client instead the polymorphic mapping seems don't work.

Maybe the problem is the use of locator?

Thanks very much

bond

unread,
Aug 24, 2012, 3:30:20 AM8/24/12
to google-we...@googlegroups.com
Hi,
anyone has some ideas about this problem?

Thanks!!

Thomas Broyer

unread,
Aug 24, 2012, 4:31:46 AM8/24/12
to google-we...@googlegroups.com
All I can say is that it's nothing to do with the use of a ServiceLocator, and that it works for me.
Can you look at the DeobfuscatorBuilder generated by ValidationTool? (if you configured annotation processing in Eclipse, look at the .apt_generated folder, otherwise use the "apt" tool from the JDK (or javac) with the "-s" argument to write the generated source to disk) Does it look OK wrt client/server-classes mappings?
Alternately, could you set a breakpoint in com.google.web.bindery.server.ResolverServiceLayer#resolveClientType and try to understand why it chooses MyBaseProxy for a MyChild1 object instead of MyChild1Proxy?

bond

unread,
Aug 24, 2012, 4:59:26 AM8/24/12
to google-we...@googlegroups.com
Hi Thomas,
I watched the DeobfuscatorBuilder and it seems ok. After some tests the example that I wrote works but this one no:

@Entity class Document {...}

@Entity class CustomerDocument extends
Document{...}
@Entity class CustomerInvoice extends CustomerDocument{...}
@Entity class CustomerCreditNote extends CustomerDocument{...}

@Entity class SupplierDocument extends Document{...}
@Entity class SupplierInvoice extends SupplierDocument {...}
@Entity class SupplierCreditNote extends SupplierDocument {...}
...
@ProxyFor(
Document .class) class DocumentProxy extends EntityProxy {...}
@ProxyFor(
CustomerDocument.class) class CustomerDocumentProxy extends DocumentProxy {...}
@ProxyFor(
CustomerInvoice.class) class CustomerInvoiceProxy extends CustomerDocumentProxy {...}
...

@Service(value =
CustomerDocumentDao.class, locator = DaoLocator.class)
@ExtraTypes({
CustomerInvoice.class, CustomerCreditNote.class })
public interface
CustomerDocumentRequest extends RequestContext {
   
Request<
CustomerDocumentProxy> getStuff(); //
}
...
Request<CustomerDocumentProxy> getStuffRequest = request.getStuff();
getStuffRequest
.fire(new Receiver<
CustomerDocumentProxy>() {
   
@Override
   
public void onSuccess(
CustomerDocumentProxy proxy) {
if(proxy instanceof
CustomerInvoiceProxy){ //HERE IS THE PROBLEM!!
}else if(proxy instanceof CustomerInvoiceProxy){}
     }
});

In this case, I want get the customer's documents on the client. On the server, with Hibernate, I get the list without problem with the correct type of every document.
On the client RF tell me that all entries are of type CustomerDocument insted of concrete class that should be CustomerInvoice or CustomerCreditNote.

I hope that my example is
enough clear.

Thanks
Reply all
Reply to author
Forward
0 new messages