You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by fahim salim <sa...@gmail.com> on 2008/10/06 17:04:32 UTC
some questions concerning "Java component Implementation specification"
Hi
I have some points concerning SCA Java Component Implementation
Specification that I'd like to clarify.
1/ use of @Service annotation (p. 2)
In this document, it is said that a service offered by a component can be
defined in two ways :
a/ by an interface
Diapositive 4 @Service (HelloService.class)
Public class HelloServiceImpl implements HelloService {
public String hello(String message) {
�
}
HelloService.java (interface) defines the method implemented by the
component in HelloServiceImpl.java
b/ by a class
Diapositive 6 @Service (HelloServiceImpl.class)
Public class HelloServiceImpl implements AnotherInterface {
public String hello(String message) {
�
}
In this case the java class itself defines the service offered by the
component
*my question : Why to have such a choice ? Is an interface not enough to
define service offered by a component ?*
2/ use of @Reference annotation(p.4)
we can use @Reference in one of the following ways :
a/ with setter method
public class MyClientImpl implements MyClient{
private MyService myService;
@Reference
public void setMyService(MyService myService) {
this.myService = myService;
}
b/ with field injection
public class MyClientImpl implements MyClient{
@Reference (name="myService")
protected MyService myService;
...
}
Diapositive 11where myService is the reference to a service used by MyClient
component
*my question : Why and when to prefer setter method than field injection ?*
3/ References (p.4)
Do we have two distinct manners of obtaining references? One through
injection and one through ComponentContextAPI ?
Thanks
Fahim
Re: some questions concerning "Java component Implementation specification"
Posted by fahim salim <sa...@gmail.com>.
Hello Luciano
Thanks for your explanations.
I will test such a use case by offering a service with a jar file.
Regards
Fahim
2008/10/11 Luciano Resende <lu...@gmail.com>
> Interesting questions Fahim, let me try to answer them, or at least
> give my understanding os possible use cases for these features in
> question:
>
> 2008/10/6 fahim salim <sa...@gmail.com>:
> > Hi
> >
> > I have some points concerning SCA Java Component Implementation
> > Specification that I'd like to clarify.
> >
> > 1/ use of @Service annotation (p. 2)
> > In this document, it is said that a service offered by a component can be
> > defined in two ways :
> >
> > a/ by an interface
> >
> > @Service (HelloService.class)
> > Public class HelloServiceImpl implements HelloService {
> > public String hello(String message) {
> > …
> > }
> > HelloService.java (interface) defines the method implemented by the
> > component in HelloServiceImpl.java
> >
> > b/ by a class
> >
> > @Service (HelloServiceImpl.class)
> > Public class HelloServiceImpl implements AnotherInterface {
> > public String hello(String message) {
> > …
> > }
> > In this case the java class itself defines the service offered by the
> > component
> >
> >
> > my question : Why to have such a choice ? Is an interface not enough to
> > define service offered by a component ?
> >
>
> I can imagine that the option to introspect the service contract from
> the implementation class would be usefull when you are exposing a
> service from a jar that you don't have access to the source code, and
> it was implemented as a pojo. I think there are also talks to make
> interfaces optional in EJB 3.1, this might be another use case for
> this feature.
>
> >
> > 2/ use of @Reference annotation(p.4)
> >
> > we can use @Reference in one of the following ways :
> >
> > a/ with setter method
> >
> > public class MyClientImpl implements MyClient{
> >
> > private MyService myService;
> >
> > @Reference
> > public void setMyService(MyService myService) {
> > this.myService = myService;
> > }
> >
> > b/ with field injection
> >
> > public class MyClientImpl implements MyClient{
> > @Reference (name="myService")
> > protected MyService myService;
> > ...
> > }
> >
> > where myService is the reference to a service used by MyClient component
> >
> > my question : Why and when to prefer setter method than field injection ?
>
> While using fields, they would be injected with the reference and
> that's it. If you use setters, you can get injected and perform
> further operations/configurations as needed in the set method.
>
> >
> > 3/ References (p.4)
> >
> > Do we have two distinct manners of obtaining references? One through
> > injection and one through ComponentContextAPI ?
> >
> > Thanks
> > Fahim
> >
> >
> >
> >
>
>
>
> --
> Luciano Resende
> Apache Tuscany, Apache PhotArk
> http://people.apache.org/~lresende <http://people.apache.org/%7Elresende>
> http://lresende.blogspot.com/
>
Re: some questions concerning "Java component Implementation specification"
Posted by Luciano Resende <lu...@gmail.com>.
Interesting questions Fahim, let me try to answer them, or at least
give my understanding os possible use cases for these features in
question:
2008/10/6 fahim salim <sa...@gmail.com>:
> Hi
>
> I have some points concerning SCA Java Component Implementation
> Specification that I'd like to clarify.
>
> 1/ use of @Service annotation (p. 2)
> In this document, it is said that a service offered by a component can be
> defined in two ways :
>
> a/ by an interface
>
> @Service (HelloService.class)
> Public class HelloServiceImpl implements HelloService {
> public String hello(String message) {
> …
> }
> HelloService.java (interface) defines the method implemented by the
> component in HelloServiceImpl.java
>
> b/ by a class
>
> @Service (HelloServiceImpl.class)
> Public class HelloServiceImpl implements AnotherInterface {
> public String hello(String message) {
> …
> }
> In this case the java class itself defines the service offered by the
> component
>
>
> my question : Why to have such a choice ? Is an interface not enough to
> define service offered by a component ?
>
I can imagine that the option to introspect the service contract from
the implementation class would be usefull when you are exposing a
service from a jar that you don't have access to the source code, and
it was implemented as a pojo. I think there are also talks to make
interfaces optional in EJB 3.1, this might be another use case for
this feature.
>
> 2/ use of @Reference annotation(p.4)
>
> we can use @Reference in one of the following ways :
>
> a/ with setter method
>
> public class MyClientImpl implements MyClient{
>
> private MyService myService;
>
> @Reference
> public void setMyService(MyService myService) {
> this.myService = myService;
> }
>
> b/ with field injection
>
> public class MyClientImpl implements MyClient{
> @Reference (name="myService")
> protected MyService myService;
> ...
> }
>
> where myService is the reference to a service used by MyClient component
>
> my question : Why and when to prefer setter method than field injection ?
While using fields, they would be injected with the reference and
that's it. If you use setters, you can get injected and perform
further operations/configurations as needed in the set method.
>
> 3/ References (p.4)
>
> Do we have two distinct manners of obtaining references? One through
> injection and one through ComponentContextAPI ?
>
> Thanks
> Fahim
>
>
>
>
--
Luciano Resende
Apache Tuscany, Apache PhotArk
http://people.apache.org/~lresende
http://lresende.blogspot.com/