You can develop an Service Component Architecture (SCA) service implementation when starting with an existing Java application.
The bottom-up development approach provides a simplified way to begin developing SCA services for the Java developer that does not desire to work with WSDL or XML schema (XSD) authoring or when building new SCA services that expose existing legacy implementations with Java interfaces.
The top-down development approach takes advantage of the interoperable XML-based WSDL, and XSD interface and data definitions.
This task describes the steps when using the bottom-up development approach to develop an SCA service implementation when starting with Java.
When using the bottom-up development methodology, begin by writing a Java interface and implementation that describes the desired business logic. This implementation is then packaged into an application archive file such as a web application archive (WAR) file or a Java archive (JAR) file that is subsequently is used by an SCA component that is configured with deployment information containing the bindings when the SCA application is deployed.
You have developed an SCA service using the bottom-up methodology by starting with an existing Java interface or implementation.
//NameGetter.java
package myintf;
import mypkg.Person;
public interface NameGetter {
public String getName(Person p);
}
//Person.java
package mypkg;
public class Person {
protected String firstName;
protected String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String value) {
this.firstName = value;
}
public String getLastName() {
return lastName;
}
public void setLastName(String value) {
this.lastName = value;
}
}
In this example, the mypkg.Person class is well-suited for use over a remotable interface, because it follows the JavaBeans pattern and contains a public getter and setter pair for its important data fields. The XML wire format used by the runtime environment will serialize and deserialize this class. However, other existing Java types that do not adhere to the JavaBeans pattern can cause problems as they dol not serialize correctly and data loss occurs. For this reason, it is a best practice to use a top-down development approach, starting from schema definitions and generating JAXB classes for use in the application programming model. See the developing SCA services from existing WSDL files to learn more about the top-down development approach.
//NameGetter.java
package myintf;
import mypkg.Person;
import org.osoa.sca.annotations.Remotable;
@Remotable
public interface NameGetter {
public String getName(Person p);
}
package myintf;
import mypkg.Person;
public class NameGetterImpl implements NameGetter {
public String getName(Person p) {
// Example "business logic"
return p.getFirstName() + " " + p.getLastName();
}
}
package myintf;
import mypkg.Person;
import org.osoa.sca.annotations.Service;
@Service(NameGetter.class)
public class NameGetterImpl implements NameGetter {
public String getName(Person p) {
// Example "business logic"
return p.getFirstName() + " " + p.getLastName();
}
}
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
targetNamespace="http://org.services.naming"
name="NameServices">
<component name="NamingServicesComponent">
<implementation.java class="myintf.NameGetterImpl"/>
<service name="NameGetter">
<!-- The interface.java is not required because the run time can introspect it. -->
<interface.java interface=myintf.NameGetter/>
<!-- The choice of bindings is not important for the example. Here, both the
SCA default and web services bindings are configured. -->
<binding.ws/>
<binding.sca/>
</service>
</component>
</composite>