|
|||||
|
|||||
User DocumentationOne minute descriptionTwo minute tutorial Five minute introduction Advanced Topics FAQ Container Components Terminology Mock Objects Inversion of Control Types PatternsInversion of ControlDependency Injection Constructor Injection Setter Injection Interface Implementation Separation Lifecycle Antipatterns Developer DocumentationHow To Contribute Relative Volunteering Release Process Project InformationSloganMailing lists Source Repositories Open Issues Blog entries Statistics Team Sister Projects TShirts MiscellaneousDifferentiatorsNirvana Full SitemapFeeds
|
Authors: Paul Hammant OverviewApache'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 componentExample 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(); } } |
||||
|