Home > Articles > Programming

  • Print
  • + Share This
This chapter is from the book

Assembling the LoanApplication Composite

Listing 2.10 provides a complete version of the LoanApplication composite we first introduced in the last chapter. Let’s examine it in the context of the LoanComponent and CreditComponent implementations we have just discussed.

Listing 2.10. The LoanApplication Composite

<composite xmlns=http://www.osoa.org/xmlns/sca/1.0

      targetNamespace="
http://www.bigbank.com/xmlns/loanApplication/1.0"

      name="LoanApplication">

   <component name ="LoanComponent">
      <implementation.java class="com.acme.LoanComponent  "/>
      <property name="currency">USD</property>
      <reference name="creditService" target="CreditComponent "/>
   <component>

   <component name = "CreditComponent">
      <implementation.java class="com.acme.CreditComponent "/>
   <component>
</composite>

Composites include targetNamespace and name attributes, which together form their qualified name, or QName. The QName of the LoanApplication composite is http://www.bigbank.com/xmlns/loanApplication/1.0:LoanApplication. QNames are similar to the combination of package and class name in Java: They serve to uniquely identify an XML artifact—in this case, a composite. The targetNamespace portion of the QName can be used for versioning. In the example, the targetNamespace ends with 1.0, indicating the composite version. The version should be changed any time a non-backward-compatible change is made to the definition (and should not be changed otherwise).

Continuing with the composite listing in Listing 2.10, LoanComponent and CreditComponent are defined by the <component> element. Both component definitions contain an entry, <implementation.java>, which identifies the Java class for the respective component implementations. If the components were implemented in BPEL, the <implementation.bpel> element would have been used, as follows:

<implementation.bpel process="bb:LoanApplicationProcess">

The <reference> element in the LoanComponent definition configures the reference to CreditService, as follows:

<reference name="creditService" target="CreditService"/>

Recalling that the LoanComponent implementation declares a reference requiring a CreditService in its constructor, we get the following:

public LoanComponent  (@Reference (name="CreditService") CreditService creditService) {
// ...
}

The <reference> element configures the creditService reference by wiring it to the CreditService provided by CreditComponent. When an instance of LoanComponent is created by the SCA runtime, it will pass a proxy to CreditService as part of the constructor invocation.

Properties are configured in a composite file using the <property> element. In the LoanApplication composite, CreditComponent is configured with min and max values (see Listing 2.11).

Listing 2.11. Configuring Property Values

<component name="CreditComponent">
      <implementation.java class=".."/>
      <property name="min">300</property>
      <property name="max">850</property>
</component>

The property values will be injected into the component by the runtime when a component instance is created.

It is important to note the naming convention used for configuring references and properties defined on setter methods. In the absence of an explicit name attribute on @Reference or @Property annotation, the name of the reference is inferred from the method name according to JavaBean semantics. In other words, for method names of the form “setXXXX,” the set prefix is dropped and the initial letter of the remaining part is made lowercase. Otherwise, the value specified in the name attribute is used.

An interesting characteristic of reference and property configuration in a composite is that the format remains the same, regardless of the style of injection used in the implementation. For example, the following component entry

<component name="LoanComponent">
      <implementation.java class=".."/>
      <reference name="creditScoreService" target="CreditComponent "/>
</component>

configures a reference specified on a constructor parameter,

public LoanComponent  (@Reference(name="creditScoreService" CreditService CreditService) {
      // ...
}

or a setter method,

@Reference

public void setCreditScoreService(CreditService creditScoreService){

      //...
}

or a field:

@Reference

protected CreditService creditScoreService;
  • + Share This
  • 🔖 Save To Your Account