org.apache.avalon.fortress.impl.role
Class ServiceMetaManager

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.avalon.fortress.impl.role.AbstractMetaInfoManager
          extended by org.apache.avalon.fortress.impl.role.ServiceMetaManager
All Implemented Interfaces:
org.apache.avalon.fortress.MetaInfoManager, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.logger.LogEnabled

public final class ServiceMetaManager
extends AbstractMetaInfoManager
implements org.apache.avalon.framework.activity.Initializable

ServiceMetaManager follows some simple rules to dynamically gather all services and the meta-information into one role manager. This really gets rid of the need of multiple role managers. It uses a set of entries in your JARs to do its magic.

/services.list

This lists all the services that are defined in this jar.

/META-INF/services/my.class.Name

One entry for each service where there are implementations for a role. This follows the JAR services mechanism.

/my/class/Implementation.meta

There is one entry sitting right beside every implementation class. This holds all the meta information for the associated class. It is a simple properties file.

ANT Tasks available

We have a couple of ANT tasks to make this really easy. If you add this to your ANT build script (customizing it to make it work in your environment), it will make your life alot easier:

   <taskdef name="collect-metainfo" classname="org.apache.avalon.fortress.tools.ComponentMetaAntTask">
     <classpath>
       <path refid="project.class.path"/>
       <pathelement path="${tools.dir}/guiapp-tools.jar"/>
     </classpath>
   </taskdef>

   <collect-metainfo destdir="${build.classes}">
      <fileset dir="${src.dir}"/>
   </collect-metainfo>
 

Version:
CVS $Revision: 1.12 $
Author:
Avalon Development Team

Field Summary
 
Fields inherited from interface org.apache.avalon.fortress.MetaInfoManager
ROLE
 
Constructor Summary
ServiceMetaManager()
          Create a ServiceMetaManager.
ServiceMetaManager(org.apache.avalon.fortress.MetaInfoManager parent)
          Create a ServiceMetaManager with a parent RoleManager.
ServiceMetaManager(org.apache.avalon.fortress.MetaInfoManager parent, java.lang.ClassLoader loader)
          Create a ServiceMetaManager with the supplied classloader and parent RoleManager.
ServiceMetaManager(org.apache.avalon.fortress.RoleManager parent)
          Create a ServiceMetaManager with a parent RoleManager.
 
Method Summary
private  java.lang.String getDepFile(java.lang.String implementation)
          Translate a class name into the meta file name.
private  java.lang.String getMetaFile(java.lang.String implementation)
          Translate a class name into the meta file name.
 void initialize()
          Initialize the ServiceMetaManager by looking at all the services and classes available in the system.
private  void readEntries(java.util.Set entries, java.net.URL url)
          Read entries in a list file and add them all to the provided Set.
private  void readMeta(java.lang.String role, java.lang.String implementation)
          Read the meta information in and actually add the role.
private  void setupImplementations(java.lang.String role)
          Get all the implementations of a service and set up their meta information.
 
Methods inherited from class org.apache.avalon.fortress.impl.role.AbstractMetaInfoManager
addComponent, getLoader, getMetaInfoForClassname, getMetaInfoForShortName, isAlreadyAdded
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceMetaManager

public ServiceMetaManager()
Create a ServiceMetaManager.


ServiceMetaManager

public ServiceMetaManager(org.apache.avalon.fortress.RoleManager parent)
Create a ServiceMetaManager with a parent RoleManager.

Parameters:
parent -

ServiceMetaManager

public ServiceMetaManager(org.apache.avalon.fortress.MetaInfoManager parent)
Create a ServiceMetaManager with a parent RoleManager.

Parameters:
parent -

ServiceMetaManager

public ServiceMetaManager(org.apache.avalon.fortress.MetaInfoManager parent,
                          java.lang.ClassLoader loader)
Create a ServiceMetaManager with the supplied classloader and parent RoleManager.

Parameters:
parent -
loader -
Method Detail

initialize

public void initialize()
                throws java.lang.Exception
Initialize the ServiceMetaManager by looking at all the services and classes available in the system.

Specified by:
initialize in interface org.apache.avalon.framework.activity.Initializable
Throws:
java.lang.Exception - if there is a problem

setupImplementations

private void setupImplementations(java.lang.String role)
                           throws java.lang.ClassNotFoundException
Get all the implementations of a service and set up their meta information.

Parameters:
role - The role name we are reading implementations for.
Throws:
java.lang.ClassNotFoundException - if the role or component cannot be found

readMeta

private void readMeta(java.lang.String role,
                      java.lang.String implementation)
Read the meta information in and actually add the role.

Parameters:
role -
implementation -

getMetaFile

private java.lang.String getMetaFile(java.lang.String implementation)
Translate a class name into the meta file name.

Parameters:
implementation -
Returns:
String

getDepFile

private java.lang.String getDepFile(java.lang.String implementation)
Translate a class name into the meta file name.

Parameters:
implementation -
Returns:
String

readEntries

private void readEntries(java.util.Set entries,
                         java.net.URL url)
                  throws java.io.IOException
Read entries in a list file and add them all to the provided Set.

Parameters:
entries -
url -
Throws:
java.io.IOException - if we cannot read the entries