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/09/24 16:32:33 UTC
cvs commit: jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util StaticAssemblyMap.java
bloritsch 2002/09/24 07:32:33
Added: fortress/src/java/org/apache/excalibur/fortress/util
StaticAssemblyMap.java
Log:
add acratchings for StaticAssemblyMap--it is not functional, but it compiles at least
Revision Changes Path
1.1 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/StaticAssemblyMap.java
Index: StaticAssemblyMap.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ 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", "Avalon", "Excalibur" 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 <http://www.apache.org/>.
*/
package org.apache.excalibur.fortress.util;
import org.apache.excalibur.meta.info.*;
import org.apache.avalon.framework.context.*;
import org.apache.avalon.framework.configuration.*;
import org.apache.avalon.framework.logger.*;
import org.apache.avalon.framework.Version;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* The AssemblyMap takes care of the mapping logic for the assembly files. The
* assembly file format is the same for all AssemblyMaps to allow for a system
* to upgrade from static mapping (where all mappings *must* be provided) to
* dynmic mapping (where a mapping will be generated if it does not exist).
*/
public class StaticAssemblyMap
extends AbstractLogEnabled
implements AssemblyMap, Configurable, Contextualizable
{
private Map m_types;
private Map m_services;
private final Map m_serviceMap;
private final Map m_typeMap;
private final Map m_nameMap;
private final List m_requiredServices;
public StaticAssemblyMap()
{
m_serviceMap = new HashMap();
m_typeMap = new HashMap();
m_nameMap = new HashMap();
m_requiredServices = new ArrayList();
}
public void contextualize( Context context )
throws ContextException
{
m_services = (Map) context.get("available-services");
m_types = (Map) context.get("available-types");
Iterator it = m_services.values().iterator();
while ( it.hasNext() )
{
m_serviceMap.put( it.next(), new ArrayList() );
}
it = m_types.values().iterator();
while ( it.hasNext() )
{
Type type = (Type) it.next();
ServiceDescriptor[] serviceDescriptors = type.getServices();
for (int i = 0; i < serviceDescriptors.length; i++ )
{
List typeList = (List) m_serviceMap.get( serviceDescriptors[i].getReference() );
// DEBUG
System.out.println( typeList );
typeList.add( type );
}
}
}
public void configure( Configuration config )
throws ConfigurationException
{
Configuration[] components = config.getChildren( "component" );
Configuration[] requiredServices = config.getChildren( "required-service" );
for (int i = 0; i < components.length; i++ )
{
String name = components[i].getAttribute( "name" );
String klass = components[i].getAttribute( "class" );
m_nameMap.put( name, klass );
m_nameMap.put( klass, name );
Type type = (Type) m_types.get( klass ); // I need to make it a Class
Configuration[] supplied = components[i].getChildren( "supply" );
List typeList = new ArrayList( supplied.length );
m_typeMap.put( type, typeList );
for (int s = 0; s < supplied.length; s++)
{
typeList.add( supplied[s].getAttribute( "name" ) );
}
}
for (int i = 0; i < requiredServices.length; i++ )
{
Configuration serviceConfig = requiredServices[i].getChild( "service" );
String className = serviceConfig.getAttribute( "name" );
Version version = Version
.getVersion( serviceConfig.getAttribute( "version" ) );
Properties attributes = new Properties();
Configuration[] attrs = requiredServices[i].getChild( "attributes" )
.getChildren( "attribute" );
for ( int at = 0; at < attrs.length; at++ )
{
attributes.setProperty( attrs[at].getAttribute( "name" ),
attrs[at].getAttribute( "value" )
);
}
ReferenceDescriptor service = new ReferenceDescriptor( className, version );
String role = service.getClassname();
DependencyDescriptor descriptor = new DependencyDescriptor(
role, service, false, attributes
);
m_requiredServices.add( descriptor );
}
}
/**
* Get the name that this particular Type is bound to for a configuration
* file. It assists in "self-healing" configuration files.
*/
public String getNameForType( Type component )
{
return (String) m_nameMap.get( component.getInfo().getImplementationKey() );
}
/**
* Get the Type boud to a particular name for a configuration file. It
* assists in "self-healing" configuration files.
*/
public Type getTypeForName( String name )
{
throw new UnsupportedOperationException();
}
/**
* Get the Type that is mapped to a particular DependencyDescriptor for a
* particular Type. It helps the AssemblyMap return the proper Type
* reference for the dependency since different components may have different
* mappings.
*/
public Type getMappedType( DependencyDescriptor dependency, Type forType )
{
throw new UnsupportedOperationException();
}
/**
* Get the Type that is mapped to a particular DependencyDescriptor.
*/
public Type getMappedType( DependencyDescriptor dependency )
{
throw new UnsupportedOperationException();
}
/**
* Get the array of DependencyDescriptors that are required to make a system
* work. They are made to evaluate the system once the components are loaded.
* If any of the required services are not loaded, we can use the
* DependencyDescriptor to find the best solution.
*/
public DependencyDescriptor[] getRequiredServices()
{
throw new UnsupportedOperationException();
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>