org.jdtaus.core.container
Interface Container


public interface Container

Implementation container.

The container is responsible for creating and maintaining instances of implementations of specifications. It is driven by a model defining the relationships between specifications and implementations. Its main use is to decouple compiletime classpaths from runtime classpaths. Implementations need not be visible during compiletime. Applications can be written against a stable API with no implementation dependent knowledge. The implementations building the runtime can then be exchanged independently during application assembly.

Example: Getting an instance of an implementation of a specification

 Specification spec = (Specification) ContainerFactory.getContainer().
     getImplementation(Specification.class, "jDTAUS Implementation");
 

Example: Getting an instance of an implementation of a dependency

 public class Implementation {

   private transient Specification _dependency0;

   private Specification getSpecification() {
       Specification ret = null;
       if(this._dependency0 != null) {
           ret = this._dependency0;
       } else {
           ret = (Specification) ContainerFactory.getContainer().
               getDependency(Implementation.class, "Specification");

           if(ModelFactory.getModel().getModules().
               getImplementation(Implementation.class.getName()).
               getDependencies().getDependency("Specification").isBound()) {

               this._dependency0 = ret;
           }
       }

       return ret;
   }

 }
 

Version:
$Id: Container.java 1914 2007-03-01 02:20:44Z schulte2005 $
Author:
Christian Schulte
See Also:
ContainerFactory

Method Summary
 Object getDependency(Class implementation, String dependencyName)
          Gets an instance of an implementation of some dependency.
 Object getImplementation(Class specification, String implementationName)
          Gets an instance of an implementation of some specification.
 

Method Detail

getDependency

public Object getDependency(Class implementation,
                            String dependencyName)
Gets an instance of an implementation of some dependency.

Parameters:
implementation - the class of the implementation to return an instance of a dependency for.
dependencyName - the logical name of the dependency to return.
Returns:
an instance of the implementation of the dependency named for .
Throws:
NullPointerException - if either or is .
InstantiationException - if creating an instance of the dependency fails.

getImplementation

public Object getImplementation(Class specification,
                                String implementationName)
Gets an instance of an implementation of some specification.

Parameters:
specification - the class of the specification to return an instance of an implementation for.
implementationName - the name of the implementation to return.
Returns:
an instance of the implementation named implementing .
Throws:
NullPointerException - if either or is .
InstantiationException - if creating an instance of the implementation fails.


Copyright © 2005-2007 jDTAUS. All Rights Reserved.