You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/06/13 23:49:33 UTC
cvs commit: jakarta-avalon/src/proposal/avalon5/org/apache/framework/component/impl DefaultComponentLocator.java DefaultComponentManager.java
bloritsch 2002/06/13 14:49:33
Modified: src/proposal/avalon5/org/apache/framework/component
ComponentException.java Composable.java
Added: src/proposal/avalon5/org/apache/framework/component
ComponentLocator.java
src/proposal/avalon5/org/apache/framework/component/impl
DefaultComponentLocator.java
Removed: src/proposal/avalon5/org/apache/framework/component
ComponentManager.java
src/proposal/avalon5/org/apache/framework/component/impl
DefaultComponentManager.java
Log:
change proposal name for ComponentManager to ComponentLocator
Revision Changes Path
1.2 +2 -2 jakarta-avalon/src/proposal/avalon5/org/apache/framework/component/ComponentException.java
Index: ComponentException.java
===================================================================
RCS file: /home/cvs/jakarta-avalon/src/proposal/avalon5/org/apache/framework/component/ComponentException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ComponentException.java 7 Jun 2002 20:04:11 -0000 1.1
+++ ComponentException.java 13 Jun 2002 21:49:33 -0000 1.2
@@ -9,7 +9,7 @@
/**
* The exception thrown to indicate a problem with service.
- * It is usually thrown by ComponentManager or ServiceSelector.
+ * It is usually thrown by ComponentLocator or ServiceSelector.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
@@ -18,7 +18,7 @@
* @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
*/
public class ComponentException
- extends RuntimeException
+ extends Exception
{
/**
* The Throwable that caused this exception to be thrown.
1.2 +6 -6 jakarta-avalon/src/proposal/avalon5/org/apache/framework/component/Composable.java
Index: Composable.java
===================================================================
RCS file: /home/cvs/jakarta-avalon/src/proposal/avalon5/org/apache/framework/component/Composable.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Composable.java 7 Jun 2002 20:04:11 -0000 1.1
+++ Composable.java 13 Jun 2002 21:49:33 -0000 1.2
@@ -15,7 +15,7 @@
*
* The contract surrounding a <code>Composable</code> is that it is a user.
* The <code>Composable</code> is able to use <code>Object</code>s managed
- * by the <code>ComponentManager</code> it was initialized with. As part
+ * by the <code>ComponentLocator</code> it was initialized with. As part
* of the contract with the system, the instantiating entity must call
* the <code>compose</code> method before the <code>Composable</code>
* can be considered valid.
@@ -26,21 +26,21 @@
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
* @version 1.0
- * @see org.apache.framework.component.ComponentManager
+ * @see org.apache.framework.component.ComponentLocator
*
*/
public interface Composable
{
/**
- * Pass the <code>ComponentManager</code> to the <code>Composable</code>.
+ * Pass the <code>ComponentLocator</code> to the <code>Composable</code>.
* The <code>Composable</code> implementation should use the specified
- * <code>ComponentManager</code> to acquire the components it needs for
+ * <code>ComponentLocator</code> to acquire the components it needs for
* execution.
*
- * @param manager The <code>ComponentManager</code> which this
+ * @param manager The <code>ComponentLocator</code> which this
* <code>Composable</code> uses.
* @exception ComponentException if an error occurs
*/
- void compose( ComponentManager manager )
+ void compose( ComponentLocator manager )
throws ComponentException;
}
1.1 jakarta-avalon/src/proposal/avalon5/org/apache/framework/component/ComponentLocator.java
Index: ComponentLocator.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.framework.component;
/**
* A <code>ComponentLocator</code> selects <code>Object</code>s based on a
* role. The contract is that all the <code>Object</code>s implement the
* differing roles and there is one <code>Object</code> per role. If you
* need to select on of many <code>Object</code>s that implement the same
* role, then you need to use a <code>ServiceSelector</code>. Roles are
* usually the full interface name.
*
* A role is better understood by the analogy of a play. There are many
* different roles in a script. Any actor or actress can play any given part
* and you get the same results (phrases said, movements made, etc.). The exact
* nuances of the performance is different.
*
* Below is a list of things that might be considered the different roles:
*
* <ul>
* <li> InputAdaptor and OutputAdaptor</li>
* <li> Store and Spool</li>
* </ul>
*
* The <code>ComponentLocator</code> does not specify the methodology of
* getting the <code>Object</code>, merely the interface used to get it.
* Therefore the <code>ComponentLocator</code> can be implemented with a
* factory pattern, an object pool, or a simple Hashtable.
*
* @author <a href="mailto:scoobie@betaversion.org">Federico Barbieri</a>
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
* @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
* @version 1.0
* @see org.apache.framework.component.Composable
*/
public interface ComponentLocator
{
/**
* Get the <code>Object</code> associated with the given role. For
* instance, If the <code>ComponentLocator</code> had a
* <code>LoggerComponent</code> stored and referenced by role, I would use
* the following call:
* <pre>
* try
* {
* MyComponent log;
* myComponent = (MyComponent) manager.lookup(MyComponent.ROLE);
* }
* catch (...)
* {
* ...
* }
* </pre>
*
* @param role The role name of the <code>Object</code> to retrieve.
* @return an <code>Object</code> value
* @throws ComponentException if the component is not available
*/
Object lookup( String role ) throws ComponentException;
/**
* Get the <code>Object</code> associated with the given role. For
* instance, If the <code>ComponentLocator</code> had a
* <code>LoggerComponent</code> stored and referenced by role, I would use
* the following call:
* <pre>
* try
* {
* MyComponent log;
* myComponent = (MyComponent) manager.lookup(MyComponent.ROLE,
* "myhint");
* }
* catch (...)
* {
* ...
* }
* </pre>
*
* @param role The role name of the <code>Object</code> to retrieve.
* @return an <code>Object</code> value
* @throws ComponentException if the component is not available
*/
Object lookup( String role, Object hint ) throws ComponentException;
/**
* Check to see if a <code>Object</code> exists for a role.
*
* @param role a string identifying the role to check.
* @return True if the object exists, False if it does not.
*/
boolean exists( String role );
}
1.1 jakarta-avalon/src/proposal/avalon5/org/apache/framework/component/impl/DefaultComponentLocator.java
Index: DefaultComponentLocator.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.framework.component.impl;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.framework.component.ComponentLocator;
import org.apache.framework.component.ComponentException;
/**
* This class is a static implementation of a ComponentLocator. Allow ineritance
* and extension so you can generate a tree of ComponentLocator each defining
* Object scope.
*
* @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
* @version 1.0
*/
public class DefaultComponentLocator
implements ComponentLocator
{
private final HashMap m_objects = new HashMap();
private final ComponentLocator m_parent;
private boolean m_readOnly;
/**
* Construct ComponentLocator with no parent.
*
*/
public DefaultComponentLocator()
{
this( null );
}
/**
* Construct ComponentLocator with specified parent.
*
* @param parent the ComponentLocator parent
*/
public DefaultComponentLocator( final ComponentLocator parent )
{
m_parent = parent;
}
/**
* Retrieve Object by role from ComponentLocator.
*
* @param role the role
* @return the Object
* @exception org.apache.framework.component.ComponentException if an error occurs
*/
public Object lookup( final String role )
throws ComponentException
{
return lookup( role, null );
}
/**
* Retrieve Object by role/hint from ComponentLocator.
*
* @param role the role
* @return the Object
* @exception org.apache.framework.component.ComponentException if an error occurs
*/
public Object lookup( final String role, Object hint )
throws ComponentException
{
// the default version of the method ignores the hint
final Object object = m_objects.get( role );
if( null != object )
{
return object;
}
else if( null != m_parent )
{
return m_parent.lookup( role );
}
else
{
throw new ComponentException( "Unable to provide implementation for " + role );
}
}
/**
* Check to see if a <code>Object</code> exists for a role.
*
* @param role a string identifying the role to check.
* @return True if the object exists, False if it does not.
*/
public boolean exists( final String role )
{
boolean objectExists = false;
try
{
this.lookup(role);
objectExists = true;
}
catch (Throwable t)
{
// Ignore all throwables--we want a yes or no answer.
}
return objectExists;
}
/**
* Place Object into ComponentLocator.
*
* @param role the components role
* @param object an <code>Object</code> value
*/
public void put( final String role, final Object object )
{
checkWriteable();
m_objects.put( role, object );
}
/**
* Build a human readable representation of the ComponentLocator.
*
* @return the description of the ComponentLocator
*/
public String toString()
{
final StringBuffer buffer = new StringBuffer();
final Iterator objects = m_objects.keySet().iterator();
buffer.append( "Services:" );
while( objects.hasNext() )
{
buffer.append( "[" );
buffer.append( objects.next() );
buffer.append( "]" );
}
return buffer.toString();
}
/**
* Helper method for subclasses to retrieve parent.
*
* @return the parent ComponentLocator
*/
protected final ComponentLocator getParent()
{
return m_parent;
}
/**
* Helper method for subclasses to retrieve object map.
*
* @return the object map
*/
protected final Map getObjectMap()
{
return m_objects;
}
/**
* Makes this service manager read-only.
*
*/
public void makeReadOnly()
{
m_readOnly = true;
}
/**
* Checks if this service manager is writeable.
*
* @exception java.lang.IllegalStateException if this service manager is read-only
*/
protected final void checkWriteable()
throws IllegalStateException
{
if( m_readOnly )
{
throw new IllegalStateException
( "ComponentLocator is read only and can not be modified" );
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>