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.SnapshotReader-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.SnapshotReader > 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]

