You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by ah...@remainsoftware.com on 2009/07/20 15:26:51 UTC
[DOSGi] Downcasting from Proxies
Hi
Given an interface, sub-interfaces and multiple implementations, how to
enable the consumer to downcast to a specific implementation or interface.
For instance:
//given some interfaces
interface IPersistable{...}
interface ILocation extends IPersistable{...}
interface IComponent extends IPersistable{...}
...
//some implementations
public class Component implements IComponent {...}
public class Location implements ILocation{..}
...
//and some osgi service
public class RequestService implements IRequestService{
...
public IPersistable syncRequest(IRequest){
//in this arbitrary case return an IComponent object
IComponent c = .......
return c;
}
...
}
//and some remote consumer
How to avoid:
>> java.lang.ClassCastException: $Proxy39 cannot be cast to ...
when the consumer tries doing something like:
class SomeConsumer{
...
IRequestService requestService=...;
IComponent c = (IComponent) requestService.syncRequest(request);
....
}
Many thanks