You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2002/11/19 04:14:09 UTC
cvs commit: jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/service DefaultServiceManager.java ServiceException.java ServiceManager.java ServiceRuntimeException.java UnknownServiceException.java package.html
mcconnell 2002/11/18 19:14:09
Added: assembly/src/java/org/apache/excalibur/assembly/service
DefaultServiceManager.java ServiceException.java
ServiceManager.java ServiceRuntimeException.java
UnknownServiceException.java package.html
Log:
Addition of a servivce manager as a seperated facilitity. This is part of the
overall type/service/profile/applicance refactoring.
Revision Changes Path
1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/service/DefaultServiceManager.java
Index: DefaultServiceManager.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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", "Avalon", 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 (INCLUDING, 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
* <http://www.apache.org/>.
*/
package org.apache.excalibur.assembly.service;
import java.util.Map;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.ArrayList;
import org.apache.avalon.framework.Version;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.excalibur.meta.info.Service;
import org.apache.excalibur.meta.info.builder.ServiceBuilder;
import org.apache.excalibur.meta.info.builder.ServiceCreator;
import org.apache.excalibur.meta.info.ReferenceDescriptor;
import org.apache.excalibur.meta.info.DependencyDescriptor;
import org.apache.excalibur.meta.info.ServiceDescriptor;
import org.apache.excalibur.meta.info.StageDescriptor;
import org.apache.excalibur.meta.verifier.ComponentVerifier;
/**
* A service manager implemetation provides support for the creation,
* storage and retrival of service defintions.
*
* @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2002/11/19 03:14:09 $
*/
public class DefaultServiceManager extends AbstractLogEnabled implements ServiceManager
{
//==============================================================
// state
//==============================================================
/**
* The classloader supplied to the manager.
*/
private final ClassLoader m_classloader;
/**
* The parent service manager (may be null)
*/
private final ServiceManager m_parent;
/**
* The service builder.
*/
private final ServiceBuilder m_builder = new ServiceBuilder();
/**
* Table of component types keyed by implementation classname.
*/
private Hashtable m_services = new Hashtable();
//==============================================================
// constructor
//==============================================================
/**
* Creation of a new {@link ServiceManager} based on a supplied parent
* and classloader.
* @param parent the parent service manager (may be null)
* @param classloader the classloader
*/
public DefaultServiceManager( ServiceManager parent, ClassLoader classloader )
{
if( classloader == null )
{
throw new NullPointerException("classloader");
}
m_parent = parent;
m_classloader = classloader;
}
//==============================================================
// LogEnabled
//==============================================================
/**
* Setup logging for all subcomponents
* @param logger the logging channel
*/
public void enableLogging( final Logger logger )
{
super.enableLogging( logger );
m_builder.enableLogging( logger.getChildLogger( "builder" ) );
}
//==============================================================
// ServiceManager
//==============================================================
/**
* Locate a {@link Service} instances associated with the
* supplied classname and version. If a formal service defintion is
* unknown the method returns a default service defintion based on
* the supplied classname and version.
*
* @return the service matching the supplied implementation classname.
* @exception UnknownServiceException if a matching service cannot be found
*/
public Service getService( String classname, Version version ) throws UnknownServiceException
{
Map map = getServiceMap( classname, false );
if( map != null )
{
Service service = (Service) map.get( version );
if( service != null )
{
return service;
}
}
//
// check the parent first
//
if( m_parent != null )
{
return m_parent.getService( classname, version );
}
else
{
final String error = "Unknown service defintion: " + classname + "/" + version;
throw new UnknownServiceException( error );
}
}
//==============================================================
// implemetation
//==============================================================
/**
* Add a service to the manager.
*
* @param path the service class name
* @return the set of service defintions
*/
public void addService( Service service ) throws ServiceException
{
//
// 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
//
String classname = service.getClassname();
Version version = service.getVersion();
Map map = getServiceMap( classname, false );
if( map != null )
{
if( map.get( version ) != null )
{
final String error =
"Duplicate service defintion: " + service;
throw new ServiceException( error );
}
}
else
{
map = getServiceMap( classname, true );
}
map.put( version, service );
}
/**
* Install the set of services associated with the supplied path.
*
* @param path the service class name
* @return the set of service defintions
*/
public Service installService( String path ) throws ServiceException
{
final String classname = path.replace( '/', '.' );
Service service;
try
{
service = m_builder.build( classname, m_classloader );
}
catch( Throwable e )
{
final String error =
"Could not register a service relative to the path: "
+ path + " due to a service build error.";
throw new ServiceException( error, e );
}
addService( service );
return service;
}
/**
* Internal utility that returns a map of services keyed by version. The
* map is resolved from the m_services list based on the classname key.
* @param classname the classname key
* @param create if TRUE create a new map if no map found
* @return the service map for the class
*/
private Map getServiceMap( String classname, boolean create )
{
Map map = (Map) m_services.get( classname );
if(( map == null ) && create )
{
map = new Hashtable();
m_services.put( classname, map );
}
return map;
}
/**
* 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 );
}
}
}
1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/service/ServiceException.java
Index: ServiceException.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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", "Avalon", 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 (INCLUDING, 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
* <http://www.apache.org/>.
*/
package org.apache.excalibur.assembly.service;
import org.apache.avalon.framework.CascadingException;
/**
* Exception to indicate that there was a service related error.
*
* @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2002/11/19 03:14:09 $
*/
public class ServiceException
extends CascadingException
{
/**
* Construct a new <code>ServiceException</code> instance.
*
* @param message The detail message for this exception.
*/
public ServiceException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>ServiceException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public ServiceException( final String message, final Throwable throwable )
{
super( message, throwable );
}
}
1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/service/ServiceManager.java
Index: ServiceManager.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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", "Avalon", 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 (INCLUDING, 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
* <http://www.apache.org/>.
*/
package org.apache.excalibur.assembly.service;
import org.apache.avalon.framework.Version;
import org.apache.excalibur.meta.info.Service;
/**
* A type manager implemetation provides support for the creation,
* storage and retrival of service defintions.
*
* @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2002/11/19 03:14:09 $
*/
public interface ServiceManager
{
/**
* Locate a {@link Service} instances associated with the
* supplied classname and 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;
}
1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/service/ServiceRuntimeException.java
Index: ServiceRuntimeException.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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", "Avalon", 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 (INCLUDING, 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
* <http://www.apache.org/>.
*/
package org.apache.excalibur.assembly.service;
import org.apache.avalon.framework.CascadingRuntimeException;
/**
* Exception to indicate that there was a seervice related runtime error.
*
* @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2002/11/19 03:14:09 $
*/
public final class ServiceRuntimeException
extends CascadingRuntimeException
{
/**
* Construct a new <code>ServiceRuntimeException</code> instance.
*
* @param message The detail message for this exception.
*/
public ServiceRuntimeException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>ServiceRuntimeException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public ServiceRuntimeException( final String message, final Throwable throwable )
{
super( message, throwable );
}
}
1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/service/UnknownServiceException.java
Index: UnknownServiceException.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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", "Avalon", 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 (INCLUDING, 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
* <http://www.apache.org/>.
*/
package org.apache.excalibur.assembly.service;
/**
* Exception to indicate that a service defintioon is unknown within
* the scope of a service manager.
*
* @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2002/11/19 03:14:09 $
*/
public final class UnknownServiceException
extends ServiceException
{
/**
* Construct a new <code>UnknownServiceException</code> instance.
*
* @param message The detail message for this exception.
*/
public UnknownServiceException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>UnknownServiceException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public UnknownServiceException( final String message, final Throwable throwable )
{
super( message, throwable );
}
}
1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/service/package.html
Index: package.html
===================================================================
<body>
<p>
The <code>type</code> package contains classes and interfaces for the {@link org.apache.excalibur.assembly.type.TypeManager} and related default implementations supporting the management of a repository of component types.
</p>
</body>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>