SCA intent

Implementing new SCA intent for FraSCAti can be easily done by following these steps:

SCA definition

SCA intents for OW2 FraSCAti are implemented as SCA composites. Assuming that you want to create an intent named foo, you have first to write a foo.composite file, that promotes the intent service of the primitive SCA component inside.

<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" name="foo">
  
  <service name="intent" promote="primitiveIntentHandler/fooIntentService"/>
  
  <component name="primitiveIntentHandler">
     <service name="fooIntentService">
       <interface.java interface="org.ow2.frascati.tinfi.control.intent.IntentHandler"/>
     </service>
    <implementation.java class="org.ow2.frascati.tutorial.FooIntentHandlerImpl"/>
  </component>
  
</composite>

The name of the service this composite must be intent and its Java interface must implement the IntentHandler Tinfi interface. Then, the Java implementation class of the primitive intent handler will implement this interface, as shown in next section.

This is the minimum to do for creating an intent, but an intent composite can be much more complex (with several SCA components, other services and references to external services, etc.)

Intent implementation

The Java implementation of the handler must be a class that implement the IntentHandler Tinfi interface. Intent handlers are implemented in an AOP way, with the invoke/proceed pattern. Then, implementing the intent handler means to add some non-functionnal code before and after the execution of the business code.

package org.ow2.frascati.tutorial;

import org.osoa.sca.annotations.Scope;

@Scope("COMPOSITE")
public class FooIntentHandler
  implements IntentHandler {

  // --------------------------------------------------------------------------
  // Implementation of the IntentHandler interface
  // --------------------------------------------------------------------------

  /**
   * @see org.ow2.frascati.tinfi.control.intent.IntentHandler#invoke(IntentJoinPoint)
   */
  public Object invoke(IntentJoinPoint ijp) throws Throwable {
    Object ret;
    //
    // PUT HERE CODE TO RUN BEFORE THE JOINPOINT PROCESSING
    //
    ret = ijp.proceed();
    //
    // PUT HERE CODE TO RUN AFTER THE JOINPOINT PROCESSING
    //
    return ret;
  }
}

Use your SCA intent

When your intent is implemented, the only thing you have to do for using it is to set its name as a requires on any component, service or reference of an SCA definition. With the foo.composite intent previously described, a usage can be:

<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" >
  
  <component name="myComponent" requires="foo">
    ...
  </component>

</composite>

In this case, the foo intent is applied on all services and interfaces of the component myComponent.

You can also define an intent on one or several service(s)/reference(s) as following:

<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" >
  
  <component name="myComponent">
    <service name="s1" requires="foo">
      ...
    </service>
    <service name="s2">
      ...
    </service>
    <reference name="r1" requires="foo">
      ...
    </reference>
    ...
  </component>

</composite>

Here, the foo intent wil only be applied on the s1 service and r1 reference.

Last, you can define several intents on the same component/service/reference as following (space-separated):

<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" >
  
  <component name="myComponent" requires="foo bar">
    ...
  </component>

</composite>