Welcome to Chaplin ACT Open Source Project

Chaplin ACT is a Java class transformer which modifies classes in such a way that their instances can form composites at runtime. With the help of this dynamic composition several modern language concepts can be introduced to Java. Among them for example traits (mixins), duck-typing, runtime type conversion, AOP-like features etc. A class written with the help of Chaplin ACT can be absolutely decoupled from other classes. Interactions between objects are mediated by the composite's context by means of an internal messaging. As a consequence we get a code which is well testable because no mocks are necessary. Furthermore, the components inside the composite can arbitrarily be added, removed or replaced. It faciliates, for instance, developing application which are able to be modified without restarts.

See the list of features.

Note:
Chaplin ACT does not extends the Java syntax. All features enhancing Java(TM) are implemented only by transforming application's compiled code.

The Greeting Service Example

The following simple example illustrates how the dynamic composition works. The GreetingService class offers two greeting methods. Both methods delegate the call to the printMessage method:

  public abstract class GreetingService {

    public void sayHello() {
        printMessage("Hello!");
    }

    public void sayGoodBye() {
        printMessage("Good Bye!");
    }

    @FromContext
    abstract void printMessage(String message);

  }

The @FromContext annotation causes that by invoking the printMessage abstract method a message is emitted to the composites's context. It can be intercepted by any component that has a method with the same signature as the emitting one. The MessagePriter class has such a method so it can serve as a receiver of the printMessage message. This method is annotated by annotation ToContext which indicates that the method can be shared via the composite context. However, as the method is public this annotation in not necessary here.

  public class MessagePrinter {

    @ToContext
    public void printMessage(String message) {
        System.out.println(message);
    }

  }

The composite of both object can be created as follows:

 public static void main(String[] args) {
    // The $ operator is a statically imported method
    // which fuses GreetingService and MessagePrinter objects
    // into a composite.
    GreetingService greetServ = $(new MessagePrinter());
    greetServ.sayHello();
    greetServ.sayGoodBye();
 }

The program must be run with the following JVM command line arguments:

   -javaagent:chaplin.jar=examples.chaplin

which installs the Chaplin ACT JVM plugin into the JVM. This plugin will transform all classes belonging to examples.chaplin package or to its subpackages.

More Examples

For more examples go to the Introduction To Chaplin ACT on the project's wiki.

Loading

free counters
© 2009 iquality.org