ymikulski 2002/08/13 06:02:33
Added: csframework/src/cs/Configuration ConfigurationCollection.cs
ConfigurationException.cs IConfigurable.cs
IConfiguration.cs IReconfigurable.cs
Log:
no message
Revision Changes Path
1.1
jakarta-avalon-excalibur/csframework/src/cs/Configuration/ConfigurationCollection.cs
Index: ConfigurationCollection.cs
===================================================================
///
/// 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.
///
using System;
using System.Collections;
namespace Apache.Avalon.Configuration
{
/// <summary>
/// A collection of <see cref="IConfiguration"/> objects.
/// </summary>
public class ConfigurationCollection: CollectionBase
{
private bool readOnly;
/// <summary>
/// Creates a new instance of <c>ConfigurationCollection</c>.
/// </summary>
public ConfigurationCollection()
{
}
/// <summary>
/// Creates a new instance of <c>ConfigurationCollection</c>.
/// </summary>
public ConfigurationCollection(ConfigurationCollection value)
{
this.AddRange(value);
}
/// <summary>
/// Creates a new instance of <c>ConfigurationCollection</c>.
/// </summary>
public ConfigurationCollection(IConfiguration[] value): this(new
ConfigurationCollection(value))
{
}
public bool IsReadOnly
{
get
{
return readOnly;
}
}
/// <summary>
/// Represents the entry at the specified index of the <see
cref="IConfiguration"/>.
/// </summary>
/// <param name="index">
/// The zero-based index of the entry to locate in the collection.
/// </param>
/// <value>
/// The entry at the specified index of the collection.
/// </value>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="index"/> is outside the valid range of indexes for
the collection.
/// </exception>
public IConfiguration this[int index]
{
get
{
IConfiguration configuration = (IConfiguration)
List[index];
if (IsReadOnly)
{
configuration.MakeReadOnly ();
}
return configuration;
}
set
{
CheckReadOnly();
List[index] = value;
}
}
/// <summary>
/// Adds an <see cref="IConfiguration"/>.
/// </summary>
/// <param name="value">The <see cref="IConfiguration"/> to
add.</param>
/// <returns>
/// The index at which the new element was inserted.
/// </returns>
public int Add(IConfiguration value)
{
CheckReadOnly();
return List.Add(value);
}
public void AddRange(IConfiguration[] value)
{
AddRange(new ConfigurationCollection(value));
}
public void AddRange(ConfigurationCollection value)
{
foreach(IConfiguration configuration in value)
{
this.Add(configuration);
}
}
public void CopyTo(IConfiguration[] array, int index)
{
List.CopyTo(array, index);
foreach (IConfiguration configuration in array)
{
if (IsReadOnly)
{
configuration.MakeReadOnly();
}
}
}
/// <summary>
/// Gets a value indicating whether the <see cref="IConfiguration"/>
contains
/// in the collection.
/// </summary>
/// <param name="value">The <see cref="IConfiguration"/> to
locate.</param>
/// <returns>
/// <see langword="true"/> if the <see cref="IConfiguration"/> is
contained in the collection;
/// otherwise, <see langword="false"/>.
/// </returns>
public bool Contains(IConfiguration value)
{
return List.Contains(value);
}
/// <summary>
/// Retuns the index of a <see cref="IConfiguration"/> in
/// the collection.
/// </summary>
/// <param name="value">The <see cref="IConfiguration"/> to
locate.</param>
/// <returns>
/// The index of the <see cref="IConfiguration"/> of <paramref
name="value"/> in the
/// collection, if found; otherwise, -1.
/// </returns>
public int IndexOf(IConfiguration value)
{
return List.IndexOf(value);
}
/// <summary>
/// Inserts a <see cref="IConfiguration"/> into the collection
/// at the specified index.
/// </summary>
/// <param name="index">The zero-based index where <paramref
name="value"/> should be inserted.</param>
/// <param name="value">The <see cref="IConfiguration"/> to
insert.</param>
public void Insert(int index, IConfiguration value)
{
CheckReadOnly();
List.Insert(index, value);
}
/// <summary>
/// Returns an enumerator that can iterate through the collection.
/// </summary>
public new ConfigurationEnumerator GetEnumerator()
{
return new ConfigurationEnumerator(this);
}
/// <summary>
/// Removes a specific <see cref="IConfiguration"/> from the
/// collection.
/// </summary>
/// <param name="value">The <see cref="IConfiguration"/> to remove
from the collection.</param>
/// <exception cref="System.ArgumentException">
/// <paramref name="value"/> is not found in the collection.
/// </exception>
public void Remove(IConfiguration value)
{
CheckReadOnly();
List.Remove(value);
}
public void MakeReadOnly()
{
readOnly = true;
}
protected void CheckReadOnly()
{
if( IsReadOnly )
{
throw new ConfigurationException( "Configuration is
read only and can not be modified." );
}
}
public class ConfigurationEnumerator : IEnumerator
{
private IEnumerator baseEnumerator;
private bool IsReadOnly;
public ConfigurationEnumerator(ConfigurationCollection
mappings)
{
this.baseEnumerator = mappings.GetEnumerator();
if (mappings.IsReadOnly)
this.IsReadOnly = true;
}
public IConfiguration Current
{
get
{
IConfiguration configuration =
(IConfiguration) baseEnumerator.Current;
if (IsReadOnly)
{
configuration.MakeReadOnly();
}
return configuration;
}
}
object IEnumerator.Current
{
get
{
return baseEnumerator.Current;
}
}
public bool MoveNext()
{
return baseEnumerator.MoveNext();
}
bool IEnumerator.MoveNext()
{
return baseEnumerator.MoveNext();
}
public void Reset()
{
baseEnumerator.Reset();
}
void IEnumerator.Reset()
{
baseEnumerator.Reset();
}
}
}
}
1.1
jakarta-avalon-excalibur/csframework/src/cs/Configuration/ConfigurationException.cs
Index: ConfigurationException.cs
===================================================================
///
/// 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.
///
using System;
namespace Apache.Avalon.Configuration
{
/// <summary>
/// Thrown when a <see cref="IConfigurable"/> component cannot be configured
/// properly.
/// </summary>
public class ConfigurationException: Exception
{
/// <summary>
/// Constructs a new <c>ConfigurationException</c> instance.
/// </summary>
public ConfigurationException(): this(null)
{
}
/// <summary>
/// Constructs a new <c>ConfigurationException</c> instance.
/// </summary>
/// <param name="message">The Detail message of the exception.</param>
public ConfigurationException(string message): this(message, null)
{
}
/// <summary>
/// Constructs a new <c>ConfigurationException</c> instance.
/// </summary>
/// <param name="message">The Detail message of the exception.</param>
/// <param name="inner">The Root cause of the exception.</param>
public ConfigurationException(string message, Exception inner):
base(message, inner)
{
}
}
}
1.1
jakarta-avalon-excalibur/csframework/src/cs/Configuration/IConfigurable.cs
Index: IConfigurable.cs
===================================================================
///
/// 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.
///
using System;
namespace Apache.Avalon.Configuration
{
/// <summary>
/// This interface should be implemented by classes that need to be
/// configured with custom parameters before initialization.
/// <para>
/// The contract surrounding a <c>IConfigurable</c> is that the
/// instantiating entity must call the <c>Configure</c>
/// method before it is valid. The <c>Configure</c> method
/// must be called after the constructor, and before any other method.
/// </para>
/// </summary>
/// <remarks>
/// Note that this interface is incompatible with <see
cref="Apache.Avalon.Parameters.IParameterizable"/>.
/// </remarks>
public interface IConfigurable
{
/// <summary>
///
/// Pass the <see cref="IConfiguration"/> to the <c>IConfigurable</c>
/// class. This method must always be called after the constructor
/// and before any other method.
/// </summary>
/// <param name="configuration">The Configuration</param>
void Configure( IConfiguration configuration );
}
}
1.1
jakarta-avalon-excalibur/csframework/src/cs/Configuration/IConfiguration.cs
Index: IConfiguration.cs
===================================================================
///
/// 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.
///
using System;
using System.Collections;
namespace Apache.Avalon.Configuration
{
/// <summary>
/// <c>IConfiguration</c> is a interface encapsulating a configuration node
/// used to retrieve configuration values.
/// </summary>
/// <remarks>
/// This is a "read only" interface preventing applications from modifying
their
/// own configurations. Once it is created, the information never changes.
/// </remarks>
public interface IConfiguration
{
/// <summary>
/// Gets the name of the node.
/// </summary>
/// <value>
/// The Name of the node.
/// </value>
string Name
{
get;
}
/// <summary>
/// Gets a string describing location of <c>IConfiguration</c>.
/// </summary>
/// <value>
/// A String describing location of <c>IConfiguration</c>.
/// </value>
string Location
{
get;
}
/// <summary>
/// Gets the value of the node.
/// </summary>
/// <value>
/// The Value of the node.
/// </value>
string Value
{
get;
}
/// <summary>
/// Gets a value indicating whether the <c>IConfiguration</c> is
read-only.
/// </summary>
/// <value>
/// True if the <c>IConfiguration</c> is read-only; otherwise, false.
/// </value>
bool IsReadOnly
{
get;
}
/// <summary>
/// Gets an <see cref="ConfigurationCollection"/> of
<c>IConfiguration</c>
/// elements containing all node children.
/// </summary>
/// <value>The Collection of child nodes.</value>
ConfigurationCollection Children
{
get;
}
/// <summary>
/// Gets an <see cref="IDictionary"/> of the configuration attributes.
/// </summary>
IDictionary Attributes
{
get;
}
/// <summary>
/// Gets a <c>IConfiguration</c> instance encapsulating the
specified
/// child node.
/// </summary>
/// <param name="child">The Name of the child node.</param>
/// <param name="createNew">
/// If <c>true</c>, a new <c>IConfiguration</c>
/// will be created and returned if the specified child does not exist.
/// If <c>false</c>, <c>null</c> will be returned when the specified
/// child doesn't exist.
/// </param>
/// <returns><c>IConfiguration</c></returns>
IConfiguration GetChild(string child, bool createNew);
/// <summary>
/// Return an <see cref="ConfigurationCollection"/> of
<c>IConfiguration</c>
/// elements containing all node children with the specified name.
/// </summary>
/// <param name="name">The Name of the children to get.</param>
/// <returns>
/// An <see cref="ConfigurationCollection"/> of
/// <c>IConfiguration</c> objects children of
/// this associated with the given name.
/// </returns>
ConfigurationCollection GetChildren(string name);
/// <summary>
/// Gets the Value of the node and converts it
/// into specified <see cref="System.Type"/>.
/// </summary>
/// <param name="type">The <see cref="System.Type"/></param>
/// <param name="defaultValue">
/// The defaultValue returned if the convertion fails.
/// </param>
/// <returns>The Value converted into the specified type.</returns>
object GetValue(Type type, object defaultValue);
/// <summary>
/// Gets the value of specified attribute and
/// converts it into specified <see cref="System.Type"/>.
/// </summary>
/// <param name="name">The Name of the attribute you ask the value
of.</param>
/// <param name="type">The <see cref="System.Type"/></param>
/// <param name="defaultValue">
/// The defaultValue returned if the convertion fails.
/// </param>
/// <returns>The Value of the attribute.</returns>
object GetAttribute(string name, Type type, object defaultValue);
/// <summary>
/// Make the configuration read only.
/// </summary>
void MakeReadOnly();
}
}
1.1
jakarta-avalon-excalibur/csframework/src/cs/Configuration/IReconfigurable.cs
Index: IReconfigurable.cs
===================================================================
///
/// 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.
///
using System;
namespace Apache.Avalon.Configuration
{
/// <summary>
/// Extends <see cref="IConfigurable"/> to allow reconfiguration at runtime.
/// </summary>
public interface IReconfigurable: IConfigurable
{
void Reconfigure( IConfiguration configuration );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>