Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Next, you import these projects into your favorite workspace of Eclipse.

Develop the interface

Two interesting projects exist today to simplify the life of a Java Developer or an architect when they would like to develop a bundle :

  • iPOJO (Apache Felix)
  • Spring Dynamic Modules (Spring)
    The goals of these frameworks are to :
  • Design the business logic as POJO,
  • Inject dependency(ies) though IoC,
  • Handle lifecycle of the bundle and its relation with BundleContext
    With such frameworks, The developer focus its development time on the business logic and not on How to call the OSGI server ? How Can I have access to the bundle context ? How can I register my bundle in the Osgi Bundle Registry registry ?

Create the class implementing the interface

In this first part, we will not re-invent the wheel but instead we will use the MyTransform class of the Camel osgi example. So, copy the following code from Camel SVN project and create a class inside the folder src/java/main/demo named MyTransform.java.

Code Block
java
java

package demo;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MyTransform  {
    private static final transient Log LOG = LogFactory.getLog(MyTransform.class);
    private boolean verbose = true;
    private String prefix = "MyTransform";

    public Object transform(Object body) {
        String answer = prefix + " set body:  " + new Date();
        if (verbose) {
            System.out.println(">>>> " + answer);
        }
        LOG.info(">>>> " + answer);
        return answer;
    }

    public boolean isVerbose() {
        return verbose;
    }

    public void setVerbose(boolean verbose) {
        this.verbose = verbose;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }
}

Remark : the package name of the camel example must be renamed to 'demo'

#Resources

  • Attachments
    patterns.*part-one.zip