Commit c70db4ed authored by Nicolas Dolet's avatar Nicolas Dolet

Update SCA Java Annotation section

parent 3de50036
......@@ -397,7 +397,7 @@ public class Client implements Runnable {
}</programlisting>
</section>
<section>
<section id="hw-pojo-composite">
<title>Hello World SCA composite</title>
<para>An SCA composite assembles SCA components to form SCA
......@@ -555,7 +555,7 @@ public class Client implements Runnable {
<para>The following command shows you how to start your application by
calling the method <code>run</code> of the <code>r</code> service on
the <code>helloworld</code>-pojo composite.</para>
the <code>helloworld-pojo</code> composite.</para>
<para>
<programlisting language="">$ frascati run helloworld-pojo -libpath examples/helloworld-pojo/target/helloworld-pojo.jar --service-name r --method-name run</programlisting>
......@@ -580,41 +580,107 @@ public class Client implements Runnable {
<section>
<title>SCA Java annotations</title>
<para>Since Java 5.0, java source code supports annotations. The SCA
specifications defines a set of SCA Java annotations to make easier the
implementation of an SCA Java-based application (more information <ulink
<para>The SCA specification defines a set of SCA Java annotations that
enable service components and service clients to be built in the Java
programming language.(more information <ulink
url="http://osoa.org/display/Main/Java+Common+Annotations+and+APIs">here</ulink>).</para>
<para>Here is an example of an SCA composite containing a runner
component that delegates business code processing to a processer and
logs the call using a logger component.</para>
<section>
<title>Annotating the Helloworld POJO example</title>
<para>This section describes how to use the SCA Java annotations on
the previous helloworld POJO example.</para>
<screenshot>
<mediaobject>
<imageobject>
<imagedata fileref="images/loggable-runner-composite.png" />
</imageobject>
</mediaobject>
</screenshot>
<para>First, the PrintService Java interface implemented by the server
is described with the <code>&lt;service/&gt;</code> tag from lines 22 to
24 of the <code>helloworld-pojo.composite</code> file, in
<xref linkend="hw-pojo-composite" />. These lines can be omitted when
using the <code>@Service</code> annotation on the <code>PrintService</code>
Java interface:</para>
<para>First, <xref linkend="runner-component" /> describes the runner
component, using the <code>@Service</code>, <code>@Reference</code> and
<code>@Scope</code> annotations and
<xref linkend="logger-component" /> uses also the <code>@Service</code>
annotation and illustrates the <code>@Property</code> usage and another
usage for <code>@Scope</code>.</para>
<programlisting linenumbering="unnumbered">package org.ow2.frascati.examples.helloworld.pojo;
<section id="runner-component">
<title>The runner component</title>
/** A basic service used to print messages. */
<emphasis role="bold">@Service</emphasis>
public interface PrintService {
void print(String msg);
}
</programlisting>
<para>The runner component offers a runnable service and has a
reference to a processer and a logger. The scope of this component is
defined as <code>COMPOSITE</code>, this means that the same instance of
this component will be used for any call on this component.</para>
<para>Concerning the server component, its Java implementation can also
be annotated for the description of its property (header), described
line 26 in the SCA composite of <xref linkend="hw-pojo-composite" />.
This annotation exempts also the developper to write getters and
setters for SCA properties defined with this annotation. Thus, the
<code>Server</code> Java class now looks like:</para>
<para>The annoted Java code for this component will look like:</para>
<programlisting linenumbering="unnumbered">package org.ow2.frascati.examples.helloworld.pojo;
/** The print service implementation. */
public class Server implements PrintService {
<emphasis role="bold">@Property</emphasis>
protected String header = "-&gt;";
private int count = 1;
/** Default constructor. */
public Server() {
System.out.println("SERVER created.");
}
/** PrintService implementation. */
public void print(final String msg) {
System.out.println("SERVER: begin printing...");
for (int i = 0; i &lt; count; ++i) {
System.out.println(header + msg);
}
System.out.println("SERVER: print done.");
}
}
</programlisting>
<programlisting><emphasis role="bold">import org.osoa.sca.annotations.Reference;
<note>
<para>The Java modifier of an SCA annotated property can't be
<code>private</code>: it must be <code>protected</code> at least.</para>
</note>
<para></para>
</section>
<section>
<title>Other example</title>
<para>Here is another example of an SCA composite that contains a
runner component which delegates business code processing to a
processer and logs the call using a logger component.</para>
<screenshot>
<mediaobject>
<imageobject>
<imagedata fileref="images/loggable-runner-composite.png" />
</imageobject>
</mediaobject>
</screenshot>
<para>First, <xref linkend="runner-component" /> describes the runner
component, using the <code>@Service</code>, <code>@Reference</code>
and <code>@Scope</code> annotations and <xref
linkend="logger-component" /> uses also the <code>@Service</code>
annotation and illustrates the <code>@Property</code> usage and
another usage for <code>@Scope</code>.</para>
<section id="runner-component">
<title>The runner component</title>
<para>The runner component offers a runnable service and has a
reference to a processer and a logger. The scope of this component
is defined as <code>COMPOSITE</code>, this means that the same
instance of this component will be used for any call on this
component.</para>
<para>The annoted Java code for this component will look
like:</para>
<programlisting><emphasis role="bold">import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
@Scope("COMPOSITE")</emphasis>
public class Runner
......@@ -639,20 +705,23 @@ public class Runner
processer.process();
}
}</programlisting>
</section>
</section>
<section id="logger-component">
<title>The logger component</title>
<section id="logger-component">
<title>The logger component</title>
<para>The logger component offers a log service and its scope is
<code>STATELESS</code>. It's means that a different instance of this
component may be used when invoking a service of this
component.</para>
<para>The logger component offers a log service and its scope is
<code>STATELESS</code>. It's means that a different instance of this
component may be used when invoking a service of this component.</para>
<para>This component has a configurable property (the logging
header) that can be defined with the <code>@Property</code>
annotation.</para>
<para>This component has a configurable property (the logging header)
that can be defined with the <code>@Property</code> annotation.</para>
<para>The Java code of this component will look like:</para>
<para>The Java code of this component will look like:</para>
<programlisting><emphasis role="bold">import org.osoa.sca.annotations.Property;
<programlisting><emphasis role="bold">import org.osoa.sca.annotations.Property;
@Scope("STATELESS")</emphasis>
public class LoggerImpl
......@@ -672,12 +741,14 @@ public class LoggerImpl
// Logging code
}
}</programlisting>
<note>
<para>For the logger component, the provided SCA service can be
defined with the <code>@Service</code> annotation on the
<code>Logger</code> Java interface implemented by this
<code>LoggerImpl</code> class.</para>
</note>
<note>
<para>For the logger component, the provided SCA service can be
defined with the <code>@Service</code> annotation on the
<code>Logger</code> Java interface implemented by this
<code>LoggerImpl</code> class.</para>
</note>
</section>
</section>
</section>
</chapter>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment