On 30/07/2011 20:02, Eranda Sooriyabandara wrote:
Hi Raymond,
Can you model them as SCA properties? We support constructor based
injection.
Is there a example code which explain how to use it? Or can you explain a bit
how can to do it.
thanks
Eranda
Eranda,
The OASIS SCA Java CAA spec has an explanation of the lifecycle of a Java component implementation
in Section 4:
http://docs.oasis-open.org/opencsa/sca-j/sca-javacaa-1.1-spec.pdf
Figure 4.1 is useful in understanding the sequence in which the implementation
is created:
Constructing -> Injecting -> Initializing -> Running
Note that a method annotated with @Init is called during the Initializing phase - and that this
occurs AFTER construction and injection are complete. What this means is that all Properties and
all References will be present at the point the @Init method is called.
Properties and References can be injected either via the constructor or via separate Setter methods
or public fields, appropriately annotated.
If you want Constructor injection, then create a constructor with one or more parameters and
annotate each parameter with either @Reference or @Property, as appropriate. something like this:
@Service(Service1.class)
public class service1ConstrImpl implements Service1 {
@Constructor
public service1ConstrImpl(@Property(name="serviceName",required=true)
String s) {
serviceName = s;
}
private String serviceName = "service1";
...
} // end class
This example has a constructor - annotated with @Constructor - and a single parameter which is a
String and which is annotated as a property (@Property) with the name "serviceName".
A complex but comprehensive example of the use of all aspects of the lifecycle of a Java
implementation is contained in the OASIS test suite for the Java CAA test suite here:
http://tools.oasis-open.org/version-control/browse/wsvn/sca-j/TestCases/JCA_General_POJO/src/main/java/org/oasisopen/sca/test/service1LifecycleExceptionsImpl.java
(WARNING! long & complex piece of code)
So, if you do model all your dependencies as either References or as Properties, the @Init method
will have access to them all, ready to use.
Yours, Mike.