hammett 2003/11/23 05:00:56
Modified: avalon-net/cscontainer/AvalonContainer DefaultContainer.cs
LifestyleManager.cs
avalon-net/cscontainer/AvalonContainer/Handler
InternalComponentHandler.cs
avalon-net/cscontainer/Samples/bin/Samples
Samples.Components.dll
avalon-net/cscontainer/bin Apache.Avalon.Container.dll
Apache.Avalon.Framework.dll
avalon-net/csframework AvalonFramework.build
avalon-net/csframework/AvalonFramework ContainerUtil.cs
Added: avalon-net/csframework/AvalonFramework ContextException.cs
IContext.cs IContextualizable.cs IResolvable.cs
avalon-net/cscontainer/AvalonContainerTest/Context
ContextTestCase.cs
avalon-net/cscontainer/AvalonContainer/Context
DefaultContext.cs
Removed: avalon-net/cscontainer/bin Apache.Avalon.Container.Test.dll
Apache.Avalon.Framework.Test.dll
avalon-net/csframework/bin Apache.Avalon.Framework.Test.dll
Apache.Avalon.Framework.dll
Log:
Applying patch from [EMAIL PROTECTED]
Revision Changes Path
1.6 +32 -9
avalon-sandbox/avalon-net/cscontainer/AvalonContainer/DefaultContainer.cs
Index: DefaultContainer.cs
===================================================================
RCS file:
/home/cvs/avalon-sandbox/avalon-net/cscontainer/AvalonContainer/DefaultContainer.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultContainer.cs 1 Nov 2003 23:47:26 -0000 1.5
+++ DefaultContainer.cs 23 Nov 2003 13:00:55 -0000 1.6
@@ -55,6 +55,7 @@
using Apache.Avalon.Framework;
using Apache.Avalon.Container.Configuration;
+ using Apache.Avalon.Container.Context;
using Apache.Avalon.Container.Lookup;
using Apache.Avalon.Container.Services;
using Apache.Avalon.Container.Handler;
@@ -119,6 +120,7 @@
private ComponentCollection m_components;
private IComponentFactoryManager m_factoryManager;
private ILookupManager m_lookupManager;
+ private IContext m_context;
private ILogger m_baseLogger;
#endregion
@@ -133,12 +135,8 @@
/// is not found, an exception is throwed.
/// </remarks>
/// <exception cref="ContainerException">If the configuration file is
not found.</exception>
- public DefaultContainer()
+ public DefaultContainer() : this( GetDefaultConfiguration() )
{
- ContainerConfiguration config = (ContainerConfiguration)
-
ConfigurationSettings.GetConfig(ContainerConfigurationSectionHandler.Section);
-
- Setup(config);
}
/// <summary>
@@ -150,13 +148,38 @@
/// <seealso
cref="Apache.Avalon.Container.Configuration.ContainerConfiguration"/>
/// </remarks>
/// <param name="config"></param>
- public DefaultContainer(ContainerConfiguration config)
+ public DefaultContainer(ContainerConfiguration config) : this( config,
null )
+ {
+ }
+
+ /// <summary>
+ /// Constructs a <b>DefaultContainer</b>.
+ /// </summary>
+ /// <param name="context"></param>
+ public DefaultContainer(IContext context) : this( null, context )
+ {
+ }
+
+ /// <summary>
+ /// Constructs a <b>DefaultContainer</b>.
+ /// </summary>
+ /// <param name="config"></param>
+ /// <param name="context"></param>
+ public DefaultContainer(ContainerConfiguration config, IContext
context)
{
+ this.m_context = ( context == null ) ? new DefaultContext() :
context;
Setup(config);
}
#endregion
#region Methods
+ private static ContainerConfiguration GetDefaultConfiguration()
+ {
+ ContainerConfiguration config = (ContainerConfiguration)
+
ConfigurationSettings.GetConfig(ContainerConfigurationSectionHandler.Section);
+ return config;
+ }
+
private void Setup(ContainerConfiguration config)
{
if (config == null)
@@ -248,7 +271,7 @@
}
IComponentHandler handler =
- new InternalComponentHandler( m_baseLogger,
loggerConfiguration, loggerType );
+ new InternalComponentHandler( m_baseLogger, m_context,
loggerConfiguration, loggerType );
m_loggerManager = (ILoggerManager) handler.GetInstance();
}
@@ -263,7 +286,7 @@
Type factoryManagerType = typeof( ComponentFactoryManager );
InternalComponentHandler handler =
- new InternalComponentHandler( logger,
extensionsConfiguration, factoryManagerType );
+ new InternalComponentHandler( logger, m_context,
extensionsConfiguration, factoryManagerType );
m_factoryManager = (IComponentFactoryManager)
handler.GetInstance();
}
@@ -281,7 +304,7 @@
Type lifestyleManager = typeof( LifecycleManager );
InternalComponentHandler handler =
- new InternalComponentHandler( logger,
extensionsConfiguration, lifestyleManager );
+ new InternalComponentHandler( logger, m_context,
extensionsConfiguration, lifestyleManager );
InternalLookupManager lookUpManager = new
InternalLookupManager();
lookUpManager.Add( typeof(IComponentFactoryManager).FullName,
m_factoryManager );
1.5 +16 -1
avalon-sandbox/avalon-net/cscontainer/AvalonContainer/LifestyleManager.cs
Index: LifestyleManager.cs
===================================================================
RCS file:
/home/cvs/avalon-sandbox/avalon-net/cscontainer/AvalonContainer/LifestyleManager.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LifestyleManager.cs 14 Oct 2003 02:06:14 -0000 1.4
+++ LifestyleManager.cs 23 Nov 2003 13:00:55 -0000 1.5
@@ -70,7 +70,7 @@
/// Summary description for LifecycleManager.
/// </summary>
public sealed class LifecycleManager :
- ILogEnabled, IInitializable, IDisposable, IConfigurable, ILookupEnabled
+ ILogEnabled, IInitializable, IDisposable, IConfigurable,
ILookupEnabled, IContextualizable
{
private static readonly object BeforeCreationEvent = new object();
private static readonly object AfterCreationEvent = new object();
@@ -82,6 +82,7 @@
private IComponentFactoryManager m_factoryManager;
private DefaultContainer m_container;
private ILogger m_logger;
+ private IContext m_context;
private ILoggerManager m_loggerManager;
private ArrayList m_loadedModules;
private WeakMap m_knowReferences;
@@ -137,6 +138,11 @@
ContainerUtil.EnableLogging(instance,
m_loggerManager[entry.LoggerName]);
}
+ if (instance is IContextualizable)
+ {
+ ContainerUtil.Contextualize(instance,
m_context);
+ }
+
BlindLookupManager lookupManager = new
BlindLookupManager(m_container);
if (entry.Dependencies.Length != 0)
@@ -415,6 +421,15 @@
m_loggerManager = (ILoggerManager)
manager[ typeof(ILoggerManager).FullName ];
+ }
+
+ #endregion
+
+ #region IContextualizable Members
+
+ public void Contextualize(IContext context)
+ {
+ this.m_context = context;
}
#endregion
1.2 +4 -1
avalon-sandbox/avalon-net/cscontainer/AvalonContainer/Handler/InternalComponentHandler.cs
Index: InternalComponentHandler.cs
===================================================================
RCS file:
/home/cvs/avalon-sandbox/avalon-net/cscontainer/AvalonContainer/Handler/InternalComponentHandler.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InternalComponentHandler.cs 22 Sep 2003 23:49:24 -0000 1.1
+++ InternalComponentHandler.cs 23 Nov 2003 13:00:55 -0000 1.2
@@ -64,11 +64,13 @@
private ILogger m_logger;
private IConfiguration m_configuration;
private ILookupManager m_lookupManager;
+ private IContext m_context;
private Type m_componentType;
- public InternalComponentHandler(ILogger logger, IConfiguration
configuration, Type componentType)
+ public InternalComponentHandler(ILogger logger, IContext context,
IConfiguration configuration, Type componentType)
{
m_logger = logger;
+ m_context = context;
m_configuration = configuration;
m_componentType = componentType;
}
@@ -92,6 +94,7 @@
object instance = Activator.CreateInstance(m_componentType);
ContainerUtil.EnableLogging(instance, m_logger);
+ ContainerUtil.Contextualize(instance, m_context);
ContainerUtil.Configure(instance, m_configuration);
if (LookupManager != null)
1.6 +18 -17
avalon-sandbox/avalon-net/cscontainer/Samples/bin/Samples/Samples.Components.dll
<<Binary file>>
1.7 +636 -652
avalon-sandbox/avalon-net/cscontainer/bin/Apache.Avalon.Container.dll
<<Binary file>>
1.6 +141 -127
avalon-sandbox/avalon-net/cscontainer/bin/Apache.Avalon.Framework.dll
<<Binary file>>
1.3 +16 -5 avalon-sandbox/avalon-net/csframework/AvalonFramework.build
Index: AvalonFramework.build
===================================================================
RCS file: /home/cvs/avalon-sandbox/avalon-net/csframework/AvalonFramework.build,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AvalonFramework.build 25 Sep 2003 01:42:34 -0000 1.2
+++ AvalonFramework.build 23 Nov 2003 13:00:56 -0000 1.3
@@ -1,4 +1,5 @@
-<project name="Avalon Framework - C#" default="test">
+<project name="Avalon Framework - C#" default="test">
+
<property name="name" value="Apache.Avalon.Framework"/>
<property name="version" value="1.0"/>
<property name="library.name" value="${name}"/>
@@ -9,7 +10,7 @@
<property name="output.test.file" value="${bin.dir}\${library.name}.Test.dll"/>
<property name="source.dir" value="AvalonFramework"/>
<property name="source.test.dir" value="AvalonFrameworkTest"/>
-
<target name="build" depends="clean" description="Build the AvalonFramework dll">
+ <target name="build" depends="clean" description="Build the AvalonFramework dll">
<csc target="library" output="${output.file}" debug="${build.debug}"
doc="${output.doc.file}">
<references basedir="${bin.dir}">
<includes name="*.dll"/>
@@ -27,15 +28,25 @@
<sources basedir="${source.test.dir}">
<includes name="**.cs"/>
</sources>
- </csc>
</target>
+ </csc>
+ </target>
+
<target name="test" depends="build-test" description="Run the NUnit tests">
<exec program="nunit-console.exe" commandline="/assembly:${output.test.file}"/>
</target>
- <target name="ndoc" depends="build" description="Build the API documentation">
<ndoc>
<assemblies>
<includes name="${output.file}"/>
</assemblies>
<summaries>
<includes name="${source.dir}/NamespaceSummary.xml"/>
</summaries>
<documenters>
<documenter name="MSDN">
<property name="OutputDirectory" value="doc\MSDN" />
<property name="HtmlHelpName" value="${library.name}" />
<property name="HtmlHelpCompilerFilename" value="hhc.exe" />
<property name="IncludeFavorites" value="False" />
<property name="Title" value="The Avalon Framework API Docs" />
<property name="SplitTOCs" value="False" />
<property name="DefaulTOC" value="" />
<property name="ShowMissingSummaries" value="True" />
<property name="ShowMissingRemarks" value="False" />
<property name="ShowMissingParams" value="False" />
<property name="ShowMissingReturns" value="False" />
<property name="ShowMissingValues" value="False" />
<property name="DocumentInternals" value="False" />
<property name="DocumentProtected" value="True" />
<property name="DocumentPrivates" value="False" />
<property name="DocumentEmptyNamespaces" value="False" />
<property name="IncludeAssemblyVersion" value="False" />
<property name="CopyrightText" value="Copyright 2003 (c) The Apache Software
Foundation. All rights reserved." />
<property name="CopyrightHref" value="http://avalon.apache.org/" />
</documenter>
</documenters>
</ndoc>
</target>
<target name="clean" description="Clean up after ourselves">
+
+ <target name="ndoc" depends="build" description="Build the API documentation">
+ <ndoc>
+ <assemblies>
+ <includes name="${output.file}"/>
+ </assemblies>
+ <summaries>
+ <includes name="${source.dir}/NamespaceSummary.xml"/>
</summaries>
<documenters>
<documenter name="MSDN">
<property name="OutputDirectory" value="doc\MSDN" />
<property name="HtmlHelpName" value="${library.name}" />
<property name="HtmlHelpCompilerFilename" value="hhc.exe" />
<property name="IncludeFavorites" value="False" />
<property name="Title" value="The Avalon Framework API Docs" />
<property name="SplitTOCs" value="False" />
<property name="DefaulTOC" value="" />
<property name="ShowMissingSummaries" value="True" />
<property name="ShowMissingRemarks" value="False" />
<property name="ShowMissingParams" value="False" />
<property name="ShowMissingReturns" value="False" />
<property name="ShowMissingValues" value="False" />
<property name="DocumentInternals" value="False" />
<property name="DocumentProtected" value="True" />
<property name="DocumentPrivates" value="False" />
<property name="DocumentEmptyNamespaces" value="False" />
<property name="IncludeAssemblyVersion" value="False" />
<property name="CopyrightText" value="Copyright 2003 (c) The Apache Software
Foundation. All rights reserved." />
<property name="CopyrightHref" value="http://avalon.apache.org/" />
</documenter>
</documenters>
</ndoc>
</target>
<target name="clean" description="Clean up after ourselves">
<delete>
<fileset>
<includes name="${output.file}"/>
<includes name="${output.test.file}"/>
</fileset>
</delete>
- </target>
</project>
+ </target>
+</project>
1.4 +25 -1
avalon-sandbox/avalon-net/csframework/AvalonFramework/ContainerUtil.cs
Index: ContainerUtil.cs
===================================================================
RCS file:
/home/cvs/avalon-sandbox/avalon-net/csframework/AvalonFramework/ContainerUtil.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ContainerUtil.cs 14 Oct 2003 02:06:14 -0000 1.3
+++ ContainerUtil.cs 23 Nov 2003 13:00:56 -0000 1.4
@@ -45,7 +45,6 @@
// Apache Software Foundation, please see <http://www.apache.org/>.
// ============================================================================
-
using System;
namespace Apache.Avalon.Framework
@@ -91,6 +90,31 @@
}
((ILogEnabled) component).EnableLogging(logger);
+ }
+ }
+
+ /// <summary>
+ /// Supplies specified object with Context if it implements the
+ /// <see cref="IContextualizable"/> interface.
+ /// </summary>
+ /// <param name="component">The component instance</param>
+ /// <param name="context">The context.</param>
+ /// <exception cref="ArgumentException">
+ /// If the component is <see cref="IContextualizable"/> but <see
cref="IContext"/> is null.
+ /// </exception>
+ /// <remarks>
+ ///
+ /// </remarks>
+ public static void Contextualize(object component, IContext context)
+ {
+ if (component is IContextualizable)
+ {
+ if (context == null)
+ {
+ throw new ArgumentNullException("context");
+ }
+
+ ((IContextualizable) component).Contextualize(context);
}
}
1.1
avalon-sandbox/avalon-net/csframework/AvalonFramework/ContextException.cs
Index: ContextException.cs
===================================================================
// ============================================================================
// The Apache Software License, Version 1.1
// ============================================================================
//
// Copyright (C) 2002-2003 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
// [EMAIL PROTECTED]
//
// 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/>.
// ============================================================================
namespace Apache.Avalon.Framework
{
using System;
using System.Runtime.Serialization;
/// <summary>
/// Exception signalling a badly formed Context.
///
/// This can be thrown by Context object when a entry is not
/// found. It can also be thrown manually in Contextualize()
/// when Component detects a malformed context value.
/// </summary>
[Serializable]
public class ContextException : Exception
{
/// <summary>
/// Constructs a new <see cref="ContextException"/> instance.
/// </summary>
public ContextException(): this( null )
{
}
/// <summary>
/// Constructs a new <see cref="ContextException"/> instance.
/// </summary>
/// <param name="message">The Detail message of the exception.</param>
public ContextException(string message): this( message, null )
{
}
/// <summary>
/// Constructs a new <see cref="ContextException"/> instance.
/// </summary>
/// <param name="message">The Detail message of the exception.</param>
/// <param name="inner">The Root cause of the exception.</param>
public ContextException(string message, Exception inner): base(
message, inner )
{
}
/// <summary>
/// Constructs a new <see cref="ContextException"/> instance.
/// </summary>
public ContextException(SerializationInfo info, StreamingContext
context): base( info, context )
{
}
}
}
1.1
avalon-sandbox/avalon-net/csframework/AvalonFramework/IContext.cs
Index: IContext.cs
===================================================================
// ============================================================================
// The Apache Software License, Version 1.1
// ============================================================================
//
// Copyright (C) 2002-2003 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
// [EMAIL PROTECTED]
//
// 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/>.
// ============================================================================
namespace Apache.Avalon.Framework
{
using System;
/// <summary>
/// The context is the interface through which the component and its
/// container communicate.
/// </summary>
public interface IContext
{
/// <summary>
/// Retrieve an object from Context.
/// </summary>
/// <param name="key">the key into context</param>
/// <returns>the object</returns>
/// <exception cref="ContextException">if object not found. Note that
this
/// means that either Component is asking for invalid entry
/// or the Container is not living up to contract.</exception>
object this[ object key ]
{
get;
}
}
}
1.1
avalon-sandbox/avalon-net/csframework/AvalonFramework/IContextualizable.cs
Index: IContextualizable.cs
===================================================================
// ============================================================================
// The Apache Software License, Version 1.1
// ============================================================================
//
// Copyright (C) 2002-2003 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
// [EMAIL PROTECTED]
//
// 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/>.
// ============================================================================
namespace Apache.Avalon.Framework
{
using System;
/// <summary>
/// This inteface should be implemented by components that need
/// a Context to work. Context contains runtime generated object
/// provided by the Container to this Component.
/// </summary>
public interface IContextualizable
{
/// <summary>
/// Pass the Context to the component.
/// This method is called after the ILogEnabled.EnableLogging() (if
present)
/// method and before any other method.
/// </summary>
/// <param name="context">the context. Must not be
<code>null</code>.</param>
/// <exception cref="ContextException">if context is
invalid</exception>
void Contextualize( IContext context );
}
}
1.1
avalon-sandbox/avalon-net/csframework/AvalonFramework/IResolvable.cs
Index: IResolvable.cs
===================================================================
// ============================================================================
// The Apache Software License, Version 1.1
// ============================================================================
//
// Copyright (C) 2002-2003 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
// [EMAIL PROTECTED]
//
// 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/>.
// ============================================================================
namespace Apache.Avalon.Framework
{
using System;
/// <summary>
/// This interface is used to indicate objects that need to be
/// resolved in some particular context.
/// </summary>
public interface IResolvable
{
/// <summary>
/// Resolve a object to a value.
/// </summary>
/// <param name="context">the contextwith respect which to
resolve</param>
/// <returns>the resolved object</returns>
/// <exception cref="ContextException">if an error occurs</exception>
object Resolve( IContext context );
}
}
1.1
avalon-sandbox/avalon-net/cscontainer/AvalonContainerTest/Context/ContextTestCase.cs
Index: ContextTestCase.cs
===================================================================
// ============================================================================
// The Apache Software License, Version 1.1
// ============================================================================
//
// Copyright (C) 2002-2003 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
// [EMAIL PROTECTED]
//
// 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/>.
// ============================================================================
namespace Apache.Avalon.Container.Test.Context
{
using System;
using System.Text;
using NUnit.Framework;
using Apache.Avalon.Framework;
using Apache.Avalon.Container.Context;
/// <summary>
/// Summary description for ContextTestCase.
/// </summary>
[TestFixture]
public class ContextTestCase
{
private class ResolvableString : IResolvable
{
private string m_content;
public ResolvableString( string content )
{
this.m_content = content;
}
public ResolvableString() : this( "This is a ${test}." )
{
}
#region IResolvable Members
public object Resolve(IContext context)
{
int index = this.m_content.IndexOf( "${" );
if ( index < 0 )
{
return this.m_content;
}
StringBuilder buf = new StringBuilder(
this.m_content.Substring( 0, index ) );
while ( index >= 0 && index <= this.m_content.Length )
{
index += 2;
int end = this.m_content.IndexOf( "}", index);
if ( end < 0 )
{
end = this.m_content.Length;
}
buf.Append( context[ this.m_content.Substring(
index, end - index ) ] );
end++;
index = this.m_content.IndexOf( "${", end ) +
2;
if ( index < 2 )
{
index = -1;
buf.Append( this.m_content.Substring(
end, this.m_content.Length - end ) );
}
if ( index >=0 && index <=
this.m_content.Length )
{
buf.Append( this.m_content.Substring(
end, index - end ) );
}
}
return buf.ToString();
}
#endregion
}
[Test]
public void AddContext()
{
DefaultContext context = new DefaultContext();
context.Put( "key1", "value1" );
Assertion.Assert( "value1".Equals( context["key1"] ) );
context.Put( "key1", String.Empty );
Assertion.Assert( String.Empty.Equals( context["key1"] ) );
context.Put( "key1", "value1" );
context.MakeReadOnly();
try
{
context.Put( "key1", String.Empty );
Assertion.Fail( "You are not allowed to change a value
after it has been made read only" );
}
catch ( ContextException )
{
Assertion.Assert( "Value is null", "value1".Equals(
context["key1"] ) );
}
}
[Test]
public void ResolveableObject()
{
DefaultContext context = new DefaultContext();
context.Put( "key1", new ResolvableString() );
context.Put( "test", "Cool Test" );
context.MakeReadOnly();
IContext newContext = (IContext) context;
Assertion.Assert( "Cool Test".Equals( newContext["test"] ) );
Assertion.Assert( ! "This is a ${test}.".Equals(
newContext["key1"] ) );
Assertion.Assert( "This is a Cool Test.".Equals(
newContext["key1"] ) );
}
[Test]
public void CascadingContext()
{
DefaultContext parent = new DefaultContext();
parent.Put( "test", "ok test" );
parent.MakeReadOnly();
DefaultContext child = new DefaultContext( parent );
child.Put( "check", new ResolvableString("This is an
${test}.") );
child.MakeReadOnly();
IContext context = (IContext) child;
Assertion.Assert ( "ok test".Equals( context["test"] ) );
Assertion.Assert ( ! "This is an ${test}.".Equals(
context["check"] ) );
Assertion.Assert ( "This is an ok test.".Equals(
context["check"] ) );
}
[Test]
public void HiddenItems()
{
DefaultContext parent = new DefaultContext();
parent.Put( "test", "test" );
parent.MakeReadOnly();
DefaultContext child = new DefaultContext( parent );
child.Put( "check", "check" );
IContext context = (IContext) child;
Assertion.Assert ( "check".Equals( context["check"] ) );
Assertion.Assert ( "test".Equals( context["test"] ) );
child.Hide( "test" );
try
{
object o = context["test"];
Assertion.Fail( "The item \"test\" was hidden in the
child context, but could still be retrieved via Get()." );
}
catch (ContextException)
{
// Supposed to be thrown.
}
child.MakeReadOnly();
try
{
child.Hide( "test" );
Assertion.Fail( "Hide() did not throw an exception,
even though the context is supposed to be read-only." );
}
catch (ContextException)
{
// Supposed to be thrown.
}
}
}
}
1.1
avalon-sandbox/avalon-net/cscontainer/AvalonContainer/Context/DefaultContext.cs
Index: DefaultContext.cs
===================================================================
// ============================================================================
// The Apache Software License, Version 1.1
// ============================================================================
//
// Copyright (C) 2002-2003 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
// [EMAIL PROTECTED]
//
// 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/>.
// ============================================================================
namespace Apache.Avalon.Container.Context
{
using System;
using System.Collections;
using System.Runtime.Serialization;
using Apache.Avalon.Framework;
/// <summary>
/// Default implementation of IContext.
/// </summary>
public class DefaultContext : IContext
{
[Serializable]
private sealed class Hidden
{
}
private static Hidden HIDDEN_MAKER = new Hidden();
private IDictionary m_contextData;
private IContext m_parent;
private bool m_readOnly;
/// <summary>
/// Create a Context with specified data and parent.
/// </summary>
/// <param name="contextData">the context data</param>
/// <param name="parent">the parent Context (may be null)</param>
public DefaultContext( IDictionary contextData, IContext parent )
{
m_parent = parent;
m_contextData = contextData;
}
/// <summary>
/// Create a Context with specified data.
/// </summary>
/// <param name="contextData">the context data</param>
public DefaultContext( IDictionary contextData ) : this( contextData,
null )
{
}
/// <summary>
/// Create a Context with specified parent.
/// </summary>
/// <param name="parent">the parent Context (may be null)</param>
public DefaultContext( IContext parent )
: this( Hashtable.Synchronized( new Hashtable() ), parent )
{
}
/// <summary>
/// Create a Context with no parent.
/// </summary>
public DefaultContext() : this( (IContext)null )
{
}
#region IContext Members
/// <summary>
/// Retrieve an item from the Context.
/// </summary>
/// <param name="key">the key of item</param>
/// <returns>the item stored in context</returns>
/// <exception cref="ContextException">if item not present</exception>
public object this[ object key ]
{
get
{
object data = m_contextData[key];
if( null != data )
{
if( data is Hidden )
{
// Always fail.
string message = "Unable to locate " +
key;
throw new ContextException( message );
}
if( data is IResolvable )
{
return ( (IResolvable)data ).Resolve(
this );
}
return data;
}
// If data was null, check the parent
if( null == m_parent )
{
// There was no parent, and no data
string message = "Unable to resolve context
key: " + key;
throw new ContextException( message );
}
return m_parent[ key ];
}
}
#endregion
/// <summary>
/// Helper method fo adding items to Context.
/// </summary>
/// <param name="key">the items key</param>
/// <param name="value">the item</param>
/// <exception cref="ContextException">if context is read
only</exception>
public void Put( object key, object value )
{
checkWriteable();
if( null == value )
{
m_contextData.Remove( key );
}
else
{
m_contextData[ key ] = value;
}
}
/// <summary>
/// Hides the item in the context.
/// After Hide(key) has been called, a Get(key)
/// will always fail, even if the parent context
/// has such a mapping.
/// </summary>
/// <param name="key">the items key</param>
/// <exception cref="ContextException">if context is read
only</exception>
public void Hide( object key )
{
checkWriteable();
m_contextData[ key ] = HIDDEN_MAKER;
}
/// <summary>
/// Utility method to retrieve context data.
/// </summary>
/// <returns>the context data</returns>
protected IDictionary GetContextData()
{
return m_contextData;
}
/// <summary>
/// Get parent context if any.
/// </summary>
/// <returns>the parent Context (may be null)</returns>
protected IContext GetParent()
{
return m_parent;
}
/// <summary>
/// Make the context read-only.
/// Any attempt to write to the context via Add()
/// will result in an IllegalStateException.
/// </summary>
public void MakeReadOnly()
{
m_readOnly = true;
}
/// <summary>
/// Utility method to check if context is writeable and if not throw
exception.
/// </summary>
/// <exception cref="ContextException">if context is read
only</exception>
protected void checkWriteable()
{
if( m_readOnly )
{
string message = "Context is read only and can not be
modified";
throw new ContextException( message );
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]