User Documentation

One minute description
Two minute tutorial
Five minute introduction
Advanced Topics
FAQ
Container
Components
Terminology
Mock Objects
Inversion of Control Types

Patterns

Inversion of Control 
Dependency Injection 
Constructor Injection 
Setter Injection 
Interface Implementation Separation 
Lifecycle 
Antipatterns

Developer Documentation

 Current build status
How To Contribute
Relative Volunteering
Release Process

Project Information

Slogan
Mailing lists
Source Repositories
Open Issues
Blog entries 
Statistics
Team
Sister Projects
TShirts

Miscellaneous

Differentiators
Nirvana

Full Sitemap

Feeds


Site
News
Avalon Framework

Authors: Paul Hammant

Overview

Apache's Avalon's component specification is enshrined in a number of interfaces. What this means is that the component writer has to implement them to designate their class as an Avalon component. PicoComponents require adaptation to fit the Avalon-Framework (contextualized depenedency lookup) design.

This document details how to do this manually.

A simple example component

Example component APIs

public interface Engine {
  void runEngine();
}
public interface Persistor {
  void persist(String key, Object data);
}

A simple Pico implementation of the hypothetical engine.

public class EngineImpl implements Engine {
  Persistor persistor;
  String persistenceKey;
  Object persistable;
  public void EngineImpl(Persistor persistor, String persistenceKey) {
    this.persistor = persistor;
    this.persistorKey = persistorKey;
    persistable = new Object(); // not very 'heavy' we appreciate.
  }
  public void runEngine() {
  {
    persistor.persist(persistorKey, persistable);
  }
}

The same component natively written for Apache Avalon

public class AvalonEngine implements Engine, Servicable, Configurable, Initializable {
  Persistor persistor;
  String persistenceKey;
  Object persistable;
  public void service (ServiceManager sm) throws ServiceException {
    this.persistor = (Persistor) sm.lookup("Persistor");
  }
  public void configure(Configuration conf) {
    this.persistorKey = conf.getAttribute("persistorKey");
  }
  public void initialize() {
    persistable = new Object(); // not very 'heavy' we appreciate.
  }
  public void runEngine() {
  {
    persistor.persist(persistorKey, persistable);
  }
}

An alternate wrapping strategy for Apache Avalon compatability.

public class AvalonEngine implements Engine, Servicable, Configurable, Initializable {
  private Engine engine;
  // temporary
  private Persistor persistor;
  private String persistenceKey;
  public void service (ServiceManager sm) throws ServiceException {
    this.persistor = (Persistor) sm.lookup("Persistor");
  }
  public void configure(Configuration conf) {
    this.persistorKey = conf.getAttribute("persistorKey");
  }
  public void initialize() {
    engine = new EngineImpl(persistor persistenceKey);
  }
  public void runEngine() {
  {
    engine.runEngine();
  }
}