Return-Path: Delivered-To: apmail-jakarta-avalon-cvs-archive@apache.org Received: (qmail 57183 invoked from network); 27 Dec 2002 16:11:47 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 27 Dec 2002 16:11:47 -0000 Received: (qmail 13091 invoked by uid 97); 27 Dec 2002 16:13:03 -0000 Delivered-To: qmlist-jakarta-archive-avalon-cvs@jakarta.apache.org Received: (qmail 13044 invoked by uid 97); 27 Dec 2002 16:13:02 -0000 Mailing-List: contact avalon-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list avalon-cvs@jakarta.apache.org Received: (qmail 13032 invoked by uid 98); 27 Dec 2002 16:13:01 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Date: 27 Dec 2002 16:11:42 -0000 Message-ID: <20021227161142.79823.qmail@icarus.apache.org> From: mcconnell@apache.org To: avalon-sandbox-cvs@apache.org Subject: cvs commit: avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/service ServiceRepository.java ServiceManager.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N mcconnell 2002/12/27 08:11:42 Added: assembly/src/java/org/apache/avalon/assembly/engine/service ServiceRepository.java Removed: assembly/src/java/org/apache/avalon/assembly/engine/service ServiceManager.java Log: Renamed ServiceManager to ServiceRepository to eliminate naming conflict with framework ServiceManager. Revision Changes Path 1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/service/ServiceRepository.java Index: ServiceRepository.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see . */ package org.apache.avalon.assembly.engine.service; import java.util.List; import java.util.ArrayList; import java.util.Iterator; import org.apache.avalon.framework.Version; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.meta.info.Service; import org.apache.avalon.meta.info.builder.ServiceBuilder; import org.apache.avalon.meta.info.ReferenceDescriptor; /** * A service repository provides support for the storage and retrival * of service defintions. * * @author Avalon Development Team * @version $Revision: 1.1 $ $Date: 2002/12/27 16:11:42 $ */ public class ServiceRepository extends AbstractLogEnabled { //============================================================== // state //============================================================== /** * The classloader supplied to the manager. */ private ClassLoader m_classloader; /** * The parent service manager (may be null) */ private ServiceRepository m_parent; /** * The service builder. */ private static final ServiceBuilder DEFAULT_BUILDER = new ServiceBuilder(); /** * List of service entries. */ private List m_services = new ArrayList(); //============================================================== // constructor //============================================================== /** * Creation of a new root service manager. * @param classloader the classloder to use * @exception NullPointerException if the classloader is null */ public ServiceRepository( ClassLoader classloader ) throws NullPointerException { this( classloader, null ); } /** * Creation of a new service manager. * @param classloader the classloder to use * @param parent the parent type manager * @exception NullPointerException if the classloader is null */ public ServiceRepository( ClassLoader classloader, ServiceRepository parent ) throws NullPointerException { if( classloader == null ) { throw new NullPointerException("classloader"); } m_classloader = classloader; m_parent = parent; } //============================================================== // implemetation //============================================================== /** * Create a services associated from a supplied path. * * @param clazz the service class * @return the service defintions * @exception ServiceException if an error occurs during service creation */ public Service createService( Class clazz ) throws ServiceException { if( clazz == null ) { throw new NullPointerException("clazz"); } try { return DEFAULT_BUILDER.build( clazz.getName(), clazz.getClassLoader() ); } catch( Throwable e ) { final String error = "Could not create a service relative to the path: " + clazz.getName() + " due to a service build error."; throw new ServiceException( error, e ); } } /** * Create a service instance based on a supplied classname. * * @param classname the component implementation classname * @return the service defintion * @exception ServiceException if an error occurs during service creation */ public Service createService( String classname ) throws ServiceException { if( classname == null ) { throw new NullPointerException("classname"); } try { Class clazz = m_classloader.loadClass( classname ); return createService( clazz ); } catch( Throwable e ) { final String error = "Unexpected error while attempting to build a service from the classname: " + classname; throw new ServiceException( error, e ); } } /** * Locate a {@link Service} instances associated with the * supplied classname and version. If a service defintion is not * found locally, the implementation redirects the request to * the parent service manager. * * @param classname the service class name * @param version the service version * @return the service matching the supplied classname and version. * @exception UnknownServiceException if a matching service cannot be found */ public Service getService( String classname, Version version ) throws UnknownServiceException { return getService( new ReferenceDescriptor( classname, version ) ); } /** * Locate a {@link Service} instances associated with the * supplied referecne descriptor. If a service defintion is not * found locally, the implementation redirects the request to * the parent service manager. * * @param classname the service class name * @param reference the reference descriptor * @return the service matching the supplied descriptor. * @exception UnknownServiceException if a matching service cannot be found */ public Service getService( ReferenceDescriptor reference ) throws UnknownServiceException { Service service = getLocalService( reference ); if( service == null ) { if( m_parent != null ) { return m_parent.getService( reference ); } else { final String error = "Unknown service defintion: " + reference; throw new UnknownServiceException( error ); } } return service; } private Service getLocalService( ReferenceDescriptor reference ) { Iterator iterator = m_services.iterator(); while( iterator.hasNext() ) { Service service = (Service) iterator.next(); if( service.equals( reference ) ) { return service; } } return null; } /** * Add a service to the manager. * * @param service the service defintion * @exception DuplicateServiceException if the service already exists * @exception ServiceException if the service definition is invalid */ public void addService( Service service ) throws DuplicateServiceException, ServiceException { if( getLogger() == null ) { throw new IllegalStateException("logging"); } // // make sure that there is not already a local defintion for // this service // try { getService( service.getReference() ); throw new DuplicateServiceException( service.toString() ); } catch( UnknownServiceException use ) { // continue } // // make sure we are dealing with a service that is verified // verifyService( service ); // // make sure that there is not already a local defintion for // this service // m_services.add( service ); if( getLogger().isDebugEnabled() ) { StringBuffer buffer = new StringBuffer(); buffer.append( "add: " + service.getClassname() ); buffer.append( ":" + service.getVersion() ); String[] names = service.getAttributeNames(); buffer.append( ", entries: " + service.getEntries().length ); buffer.append( ", attributes: " + service.getAttributeNames().length ); getLogger().debug( buffer.toString() ); } } /** * Verify that a class exists within the classloader representing the * service type. * @param service the service to verify * @exception ServiceException if a verification error occurs */ private void verifyService( Service service ) throws ServiceException { Class clazz; try { clazz = m_classloader.loadClass( service.getClassname() ); } catch( Throwable e ) { final String error = "Unresolvable service class."; throw new ServiceException( error, e ); } } } -- To unsubscribe, e-mail: For additional commands, e-mail: