You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Mark-Anthony Hutton <mh...@Navsys.com> on 2010/10/12 00:03:48 UTC

Component Wrapping Problem

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?

Thank you,

Mark-Anthony Hutton


RE: Component Wrapping Problem

Posted by Joel Schuster <jo...@Navsys.com>.
Mark-Anthony,

I believe what you are looking for is not getServiceReference as you already have the reference. I'm sure that what you need is getService() with passing in the reference.

- Joel



-----Original Message-----
From: Mark-Anthony Hutton [mailto:mhutton@Navsys.com] 
Sent: Monday, October 11, 2010 4:04 PM
To: users@felix.apache.org
Subject: Component Wrapping Problem

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?

Thank you,

Mark-Anthony Hutton


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


RE: Component Wrapping Problem

Posted by Mark-Anthony Hutton <mh...@Navsys.com>.
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:clement.escoffier@gmail.com] 
Sent: Monday, October 11, 2010 11:28 PM
To: users@felix.apache.org
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: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Component Wrapping Problem

Posted by Clement Escoffier <cl...@gmail.com>.
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: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org