// Copyright 2003-2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Apache.Avalon.Container.Lookup
{
using System;
using System.Collections;
using Apache.Avalon.Framework;
using Apache.Avalon.Container.Services;
///
/// Summary description for InternalLookupManager.
///
internal class InternalLookupManager : ILookupManager
{
private Hashtable m_instances;
public InternalLookupManager()
{
m_instances = new Hashtable();
}
///
/// Adds component instances to this BlindLookupManager.
/// This should be called by the Container Framework in order to
/// expose dependencies instances to the component.
///
/// Role name (Could be anything)
/// Component instance
public void Add(String role, object instance )
{
if ( role == null || role.Length == 0 )
{
throw new ArgumentNullException( "role" );
}
if ( instance == null )
{
throw new ArgumentNullException( "instance" );
}
m_instances.Add( role, instance );
}
#region ILookupManager Members
///
/// Returns the component associated with the given role.
///
/// The component instance.
/// If the role argument is null.
/// If the role could not be resolved.
public object this[string role]
{
get
{
if ( role == null || role.Length == 0 )
{
throw new ArgumentNullException("role", "You can't look up using an empty role.");
}
object instance = m_instances[ role ];
if ( instance == null )
{
throw new LookupException( role, "Unknown component." );
}
return instance;
}
}
///
/// Releases the component associated with the given role.
///
///
/// A InternalLookupManager should not release anything as its not
/// have ownership of any component.
///
/// If the role argument is null.
public void Release(object resource)
{
}
///
/// Checks to see if a component exists for a role.
///
/// A String identifying the lookup name to check.
/// True if the resource exists; otherwise, false.
/// If the role argument is null.
public bool Contains(string role)
{
return m_instances.Contains( role );
}
#endregion
}
}