Thanks Clement, I understand where you are coming from. After also talking to Joel Schuster, I know I will need to solve this using an interface extending the original interface with the functionality that I need and provide this new interface as a service.
Mark-Anthony Hutton -----Original Message----- From: Clement Escoffier [mailto:[email protected]] Sent: Monday, October 11, 2010 11:28 PM To: [email protected] Subject: Re: Component Wrapping Problem Hello, On 12.10.2010, at 00:03, Mark-Anthony Hutton wrote: > I appreciate any help I can get. > > I have an instantiation of a class called SnapshotReader using the > config file: > com.navsys.tidgetsaasm.gatewaymanager.localsnapshotmanager.SnapshotRea > der-LocalStore.cfg > > The class SnapshotReader @Provides the services TidgetSaasmDevice and Service. > > In my GUI Class I @Require(optional=false) a TidgetSaasmDevice that is > implemented by SnapshotReader. (I know this using the Felix WebConsole ). > > When I try to cast the TidgetSaasmDevice(implemented by a SnapshotReader) > into a SnapshotReader I get the exception(at Runtime): > Exception in thread "AWT-EventQueue-0" > java.lang.ClassCastException: > com.navsys.tidgetsaasm.gatewaymanager.tidgetdevice.TidgetSaasmDevice$$ > Proxy cannot be cast to > com.navsys.tidgetsaasm.gatewaymanager.localsnapshotmanager.SnapshotRea > der At the line: SnapshotReader templocalstoretidget = > (SnapshotReader) snapshotreadertidget; > > Another Felix develeoper recommended I used > bundleContext.getServiceReference(SnapshotReader.class.name()) to get the > instantiation instead, since the Proxy is not doing it for me. > It returns null, but > bundleContext.getServiceReference(TidgetSaasmDevice.class.getName()) works > just fine. > > I have confirmed for myself that a SnapshotReader instance does exist > using the Felix WebConsole > > Is there something I am missing or can do to get this instance as a > SnapshotReader? First, it's not recommended to cast a service interface into an implementation class (this break the substitutability of services). Anyway, it does not work in iPOJO because of the proxy injected by iPOJO. Indeed, the proxy implements the interface only not the implementtion class. So you have two way to deal with that: - disable the proxy injection for the dependency (@Requires(proxy=false)). - expose SnapshotReader as a service and depends on it. Regards, Clement > > Thank you, > > Mark-Anthony Hutton > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

