SPRNET-1124

-added direct support for specifying a collection of IResource instances to configure the container
-introduced various ApplicationContextArgs classes to encapsulate ever-expanding constructor params for ApplicationContexts
-revise constructors chaining to fall over to ApplicationContextArgs-based constructors.
-move codifation of differnt ApplicationContext 'defaults' (caseSensitive, Refresh, etc.) from ApplicationContext constructors into ApplicationContextArgs classes
This commit is contained in:
sbohlen
2010-07-28 15:02:31 +00:00
parent ce275c9a25
commit 617adb53d6
15 changed files with 558 additions and 261 deletions

View File

@@ -29,6 +29,7 @@ using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Support;
using Spring.Objects.Factory.Xml;
using Spring.Util;
using Spring.Core.IO;
#endregion
@@ -99,6 +100,24 @@ namespace Spring.Context.Support
/// </returns>
protected abstract string[] ConfigurationLocations { get; }
/// <summary>
/// An array of resources that this context is to be built with.
/// </summary>
/// <remarks>
/// <p>
/// Examples of the format of the various strings that would be
/// returned by accessing this property can be found in the overview
/// documentation of with the <see cref="XmlApplicationContext"/>
/// class.
/// </p>
/// </remarks>
/// <returns>
/// An array of <see cref="Spring.Core.IO.IResource"/>s, or <see langword="null"/> if none.
/// </returns>
protected abstract IResource[] ConfigurationResources { get; }
/// <summary>
/// Instantiates and populates the underlying
/// <see cref="Spring.Objects.Factory.IObjectFactory"/> with the object
@@ -200,16 +219,23 @@ namespace Spring.Context.Support
/// </exception>
/// <exception cref="Spring.Objects.ObjectsException">
/// In the case of errors encountered reading any of the resources
/// yielded by the <see cref="ConfigurationLocations"/> method.
/// yielded by either the <see cref="ConfigurationLocations"/> or
/// the <see cref="ConfigurationResources"/> methods.
/// </exception>
protected virtual void LoadObjectDefinitions(
XmlObjectDefinitionReader objectDefinitionReader)
protected virtual void LoadObjectDefinitions(XmlObjectDefinitionReader objectDefinitionReader)
{
string[] locations = ConfigurationLocations;
if (locations != null)
{
objectDefinitionReader.LoadObjectDefinitions(ConfigurationLocations);
objectDefinitionReader.LoadObjectDefinitions(locations);
}
IResource[] resources = ConfigurationResources;
if (resources != null)
{
objectDefinitionReader.LoadObjectDefinitions(resources);
}
}

View File

@@ -0,0 +1,53 @@
#region License
/*
* Copyright © 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using Spring.Core.IO;
namespace Spring.Context.Support
{
public abstract class AbstractXmlApplicationContextArgs
{
public virtual bool CaseSensitive { get; set; }
public virtual string[] ConfigurationLocations { get; set; }
public virtual IResource[] ConfigurationResources { get; set; }
public virtual string Name { get; set; }
public virtual IApplicationContext ParentContext { get; set; }
public virtual bool Refresh { get; set; }
/// <summary>
/// Initializes a new instance of the AbstractXmlApplicationContextArgs class.
/// </summary>
public AbstractXmlApplicationContextArgs()
{
ConfigurationLocations = new string[0];
ConfigurationResources = new IResource[0];
}
}
}

View File

@@ -1,237 +1,286 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
using Spring.Util;
#region License
namespace Spring.Context.Support
{
/// <summary>
/// An <see cref="Spring.Context.IApplicationContext"/> implementation that
/// reads context definitions from XML based resources.
/// </summary>
/// <remarks>
/// <p>
/// Currently, the resources that are supported are the <c>file</c>,
/// <c>http</c>, <c>ftp</c>, <c>config</c> and <c>assembly</c> resource
/// types.
/// </p>
/// <p>
/// You can provide custom implementations of the
/// <see cref="Spring.Core.IO.IResource"/> interface and and register them
/// with any <see cref="Spring.Context.IApplicationContext"/> that inherits
/// from the
/// <see cref="Spring.Context.Support.AbstractApplicationContext"/>
/// interface.
/// </p>
/// <note>
/// In case of multiple config locations, later object definitions will
/// override ones defined in previously loaded resources. This can be
/// leveraged to deliberately override certain object definitions via an
/// extra XML file.
/// </note>
/// </remarks>
/// <example>
/// <p>
/// Find below some examples of instantiating an
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> using a
/// variety of different XML resources.
/// </p>
/// <code language="C#">
/// // an XmlApplicationContext that reads its object definitions from an
/// // XML file that has been embedded in an assembly...
/// IApplicationContext context = new XmlApplicationContext
/// (
/// "assembly://AssemblyName/NameSpace/ResourceName"
/// );
///
/// // an XmlApplicationContext that reads its object definitions from a
/// // number of disparate XML resources...
/// IApplicationContext context = new XmlApplicationContext
/// (
/// // from an XML file that has been embedded in an assembly...
/// "assembly://AssemblyName/NameSpace/ResourceName",
/// // and from a (relative) filesystem-based resource...
/// "file://Objects/services.xml",
/// // and from an App.config / Web.config resource...
/// "config://spring/objects"
/// );
/// </code>
/// </example>
/// <author>Rod Johnson</author>
/// <author>Juergen Hoeller</author>
/// <author>Griffin Caprio (.NET)</author>
/// <seealso cref="Spring.Core.IO.IResource"/>
/// <seealso cref="Spring.Core.IO.IResourceLoader"/>
/// <seealso cref="Spring.Core.IO.ConfigurableResourceLoader"/>
public class XmlApplicationContext : AbstractXmlApplicationContext
{
private readonly string[] _configurationLocations;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations.
/// </summary>
/// <remarks>The created context will be case sensitive.</remarks>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(params string[] configurationLocations)
: this(true, null, true, null, configurationLocations)
{ }
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations.
/// </summary>
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(bool caseSensitive,
params string[] configurationLocations)
: this(true, null, caseSensitive, null, configurationLocations)
{ }
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations.
/// </summary>
/// <param name="name">The application context name.</param>
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(string name, bool caseSensitive,
params string[] configurationLocations)
: this(true, name, caseSensitive, null, configurationLocations)
{ }
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations,
/// with the given <paramref name="parentContext"/>.
/// </summary>
/// <param name="parentContext">
/// The parent context (may be <see langword="null"/>).
/// </param>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(
IApplicationContext parentContext,
params string[] configurationLocations)
: this(true, null, true, parentContext, configurationLocations)
{ }
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations,
/// with the given <paramref name="parentContext"/>.
/// </summary>
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="parentContext">
/// The parent context (may be <see langword="null"/>).
/// </param>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(
bool caseSensitive,
IApplicationContext parentContext,
params string[] configurationLocations)
: this(true, null, caseSensitive, parentContext, configurationLocations)
{ }
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations,
/// with the given <paramref name="parentContext"/>.
/// </summary>
/// <param name="name">The application context name.</param>
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="parentContext">
/// The parent context (may be <see langword="null"/>).
/// </param>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(
string name,
bool caseSensitive,
IApplicationContext parentContext,
params string[] configurationLocations)
: this(true, name, caseSensitive, parentContext, configurationLocations)
{}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations,
/// with the given <paramref name="parentContext"/>.
/// </summary>
/// <remarks>
/// This constructor is meant to be used by derived classes. By passing <paramref name="refresh"/>=false, it is
/// the responsibility of the deriving class to call <see cref="AbstractApplicationContext.Refresh()"/> to initialize the context instance.
/// </remarks>
/// <param name="refresh">if true, <see cref="AbstractApplicationContext.Refresh()"/> is called automatically.</param>
/// <param name="name">The application context name.</param>
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="parentContext">
/// The parent context (may be <see langword="null"/>).
/// </param>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(
bool refresh,
string name,
bool caseSensitive,
IApplicationContext parentContext,
params string[] configurationLocations)
: base(name, caseSensitive, parentContext )
{
_configurationLocations = configurationLocations;
if (refresh)
{
AssertUtils.ArgumentHasElements(configurationLocations, "configurationLocations");
Refresh();
}
}
/// <summary>
/// An array of resource locations, referring to the XML object
/// definition files that this context is to be built with.
/// </summary>
/// <returns>
/// An array of resource locations, or <see langword="null"/> if none.
/// </returns>
/// <seealso cref="Spring.Context.Support.AbstractXmlApplicationContext.ConfigurationLocations"/>
protected override string[] ConfigurationLocations
{
get { return _configurationLocations; }
}
}
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
using Spring.Util;
using Spring.Core.IO;
using System;
namespace Spring.Context.Support
{
/// <summary>
/// An <see cref="Spring.Context.IApplicationContext"/> implementation that
/// reads context definitions from XML based resources.
/// </summary>
/// <remarks>
/// <p>
/// Currently, the resources that are supported are the <c>file</c>,
/// <c>http</c>, <c>ftp</c>, <c>config</c> and <c>assembly</c> resource
/// types.
/// </p>
/// <p>
/// You can provide custom implementations of the
/// <see cref="Spring.Core.IO.IResource"/> interface and and register them
/// with any <see cref="Spring.Context.IApplicationContext"/> that inherits
/// from the
/// <see cref="Spring.Context.Support.AbstractApplicationContext"/>
/// interface.
/// </p>
/// <note>
/// In case of multiple config locations, later object definitions will
/// override ones defined in previously loaded resources. This can be
/// leveraged to deliberately override certain object definitions via an
/// extra XML file.
/// </note>
/// </remarks>
/// <example>
/// <p>
/// Find below some examples of instantiating an
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> using a
/// variety of different XML resources.
/// </p>
/// <code language="C#">
/// // an XmlApplicationContext that reads its object definitions from an
/// // XML file that has been embedded in an assembly...
/// IApplicationContext context = new XmlApplicationContext
/// (
/// "assembly://AssemblyName/NameSpace/ResourceName"
/// );
///
/// // an XmlApplicationContext that reads its object definitions from a
/// // number of disparate XML resources...
/// IApplicationContext context = new XmlApplicationContext
/// (
/// // from an XML file that has been embedded in an assembly...
/// "assembly://AssemblyName/NameSpace/ResourceName",
/// // and from a (relative) filesystem-based resource...
/// "file://Objects/services.xml",
/// // and from an App.config / Web.config resource...
/// "config://spring/objects"
/// );
/// </code>
/// </example>
/// <author>Rod Johnson</author>
/// <author>Juergen Hoeller</author>
/// <author>Griffin Caprio (.NET)</author>
/// <seealso cref="Spring.Core.IO.IResource"/>
/// <seealso cref="Spring.Core.IO.IResourceLoader"/>
/// <seealso cref="Spring.Core.IO.ConfigurableResourceLoader"/>
public class XmlApplicationContext : AbstractXmlApplicationContext
{
private readonly string[] _configurationLocations;
private readonly IResource[] _configurationResources;
/// <summary>
/// Initializes a new instance of the XmlApplicationContext class.
/// </summary>
public XmlApplicationContext(XmlApplicationContextArgs args)
: base(args.Name, args.CaseSensitive, args.ParentContext)
{
_configurationLocations = args.ConfigurationLocations;
_configurationResources = args.ConfigurationResources;
if (args.Refresh)
{
bool hasLocations = args.ConfigurationLocations.Length > 0;
bool hasResources = args.ConfigurationResources.Length > 0;
if (!hasLocations && !hasResources)
throw new ArgumentException("You must provide either or both Configuration Locations and/or Configuration Resources!");
if (hasLocations || hasResources)
{
Refresh();
}
}
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations.
/// </summary>
/// <remarks>The created context will be case sensitive.</remarks>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(params string[] configurationLocations)
: this(new XmlApplicationContextArgs() { ConfigurationLocations = configurationLocations })
{ }
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations.
/// </summary>
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(bool caseSensitive,
params string[] configurationLocations)
: this(new XmlApplicationContextArgs() { CaseSensitive = caseSensitive, ConfigurationLocations = configurationLocations })
{ }
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations.
/// </summary>
/// <param name="name">The application context name.</param>
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(string name, bool caseSensitive,
params string[] configurationLocations)
: this(new XmlApplicationContextArgs() { Name = name, CaseSensitive = caseSensitive, ConfigurationLocations = configurationLocations })
{ }
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations,
/// with the given <paramref name="parentContext"/>.
/// </summary>
/// <param name="parentContext">
/// The parent context (may be <see langword="null"/>).
/// </param>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(
IApplicationContext parentContext,
params string[] configurationLocations)
: this(new XmlApplicationContextArgs() { ParentContext = parentContext, ConfigurationLocations = configurationLocations })
{ }
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations,
/// with the given <paramref name="parentContext"/>.
/// </summary>
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="parentContext">
/// The parent context (may be <see langword="null"/>).
/// </param>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(
bool caseSensitive,
IApplicationContext parentContext,
params string[] configurationLocations)
: this(new XmlApplicationContextArgs() { CaseSensitive = caseSensitive, ParentContext = parentContext, ConfigurationLocations = configurationLocations })
{ }
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations,
/// with the given <paramref name="parentContext"/>.
/// </summary>
/// <param name="name">The application context name.</param>
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="parentContext">
/// The parent context (may be <see langword="null"/>).
/// </param>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(
string name,
bool caseSensitive,
IApplicationContext parentContext,
params string[] configurationLocations)
: this(new XmlApplicationContextArgs() { Name = name, CaseSensitive = caseSensitive, ParentContext = parentContext, ConfigurationLocations = configurationLocations })
{ }
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Context.Support.XmlApplicationContext"/> class,
/// loading the definitions from the supplied XML resource locations,
/// with the given <paramref name="parentContext"/>.
/// </summary>
/// <remarks>
/// This constructor is meant to be used by derived classes. By passing <paramref name="refresh"/>=false, it is
/// the responsibility of the deriving class to call <see cref="AbstractApplicationContext.Refresh()"/> to initialize the context instance.
/// </remarks>
/// <param name="refresh">if true, <see cref="AbstractApplicationContext.Refresh()"/> is called automatically.</param>
/// <param name="name">The application context name.</param>
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="parentContext">
/// The parent context (may be <see langword="null"/>).
/// </param>
/// <param name="configurationLocations">
/// Any number of XML based object definition resource locations.
/// </param>
public XmlApplicationContext(
bool refresh,
string name,
bool caseSensitive,
IApplicationContext parentContext,
params string[] configurationLocations)
: this(new XmlApplicationContextArgs() { Refresh = refresh, Name = name, CaseSensitive = caseSensitive, ParentContext = parentContext, ConfigurationLocations = configurationLocations })
{ }
public XmlApplicationContext(
bool refresh,
string name,
bool caseSensitive,
IApplicationContext parentContext,
string[] configurationLocations,
IResource[] configurationResources)
: this(new XmlApplicationContextArgs() { Refresh = refresh, Name = name, CaseSensitive = caseSensitive, ParentContext = parentContext, ConfigurationLocations = configurationLocations, ConfigurationResources = configurationResources })
{ }
/// <summary>
/// An array of resource locations, referring to the XML object
/// definition files with which this context is to be built.
/// </summary>
/// <returns>
/// An array of resource locations, or <see langword="null"/> if none.
/// </returns>
/// <seealso cref="Spring.Context.Support.AbstractXmlApplicationContext.ConfigurationLocations"/>
protected override string[] ConfigurationLocations
{
get { return _configurationLocations; }
}
/// <summary>
/// An array of resources instances with which this context is to be built.
/// </summary>
/// <returns>
/// An array of <see cref="Spring.Core.IO.IResource"/>s, or <see langword="null"/> if none.
/// </returns>
/// <seealso cref="Spring.Context.Support.AbstractXmlApplicationContext.ConfigurationLocations"/>
protected override IResource[] ConfigurationResources
{
get { return _configurationResources; }
}
}
}

View File

@@ -0,0 +1,39 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using Spring.Core.IO;
namespace Spring.Context.Support
{
public class XmlApplicationContextArgs : AbstractXmlApplicationContextArgs
{
/// <summary>
/// Initializes a new instance of the XmlApplicationContextArgs class.
/// </summary>
public XmlApplicationContextArgs()
{
CaseSensitive = true;
Refresh = true;
}
}
}

View File

@@ -1324,11 +1324,11 @@ namespace Spring.Objects.Factory.Support
}
else
{
// No singleton instance found -> check bean definition.
// No singleton instance found -> check object definition.
IObjectFactory parentFactory = ParentObjectFactory;
if (parentFactory != null && !ContainsObjectDefinition(objectName))
{
// No bean definition found in this factory -> delegate to parent.
// No object definition found in this factory -> delegate to parent.
return parentFactory.GetType(this.OriginalObjectName(name));
}
@@ -1339,7 +1339,7 @@ namespace Spring.Objects.Factory.Support
{
if (!IsFactoryDereference(name))
{
// If it's a FactoryBean, we want to look at what it creates, not the factory class.
// If it's a FactoryObject, we want to look at what it creates, not the factory class.
return GetTypeForFactoryObject(objectName, mod);
}
else

View File

@@ -214,6 +214,7 @@
<Compile Include="Context\Support\AbstractXmlApplicationContext.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Context\Support\AbstractXmlApplicationContextArgs.cs" />
<Compile Include="Context\Support\ApplicationContextAwareProcessor.cs">
<SubType>Code</SubType>
</Compile>
@@ -265,6 +266,7 @@
<Compile Include="Context\Support\XmlApplicationContext.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Context\Support\XmlApplicationContextArgs.cs" />
<Compile Include="Core\CannotLoadObjectTypeException.cs" />
<Compile Include="Core\ComposedCriteria.cs" />
<Compile Include="Core\ControlFlowFactory.cs">

View File

@@ -36,6 +36,7 @@ using Spring.Objects.Factory.Xml;
using Spring.Objects.Support;
using Spring.Reflection.Dynamic;
using Spring.Util;
using Spring.Core.IO;
namespace Spring.Context.Support
{
@@ -59,6 +60,7 @@ namespace Spring.Context.Support
private string _constructionUrl;
private readonly string[] _configurationLocations;
private readonly IResource[] _configurationResources;
/// <summary>
/// Create a new WebApplicationContext, loading the definitions
@@ -66,7 +68,7 @@ namespace Spring.Context.Support
/// </summary>
/// <param name="configurationLocations">Names of configuration resources.</param>
public WebApplicationContext(params string[] configurationLocations)
: this(null, false, null, configurationLocations)
: this(new WebApplicationContextArgs() { ConfigurationLocations = configurationLocations })
{
}
@@ -78,7 +80,20 @@ namespace Spring.Context.Support
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="configurationLocations">Names of configuration resources.</param>
public WebApplicationContext(string name, bool caseSensitive, params string[] configurationLocations)
: this(name, caseSensitive, null, configurationLocations)
: this(new WebApplicationContextArgs() { Name = name, CaseSensitive = caseSensitive, ConfigurationLocations = configurationLocations })
{
}
/// <summary>
/// Create a new WebApplicationContext, loading the definitions
/// from the given XML resource.
/// </summary>
/// <param name="name">The application context name.</param>
/// <param name="caseSensitive">Flag specifying whether to make this context case sensitive or not.</param>
/// <param name="configurationLocations">Names of configuration resources.</param>
/// <param name="configurationResources">Configuration resources.</param>
public WebApplicationContext(string name, bool caseSensitive, string[] configurationLocations, IResource[] configurationResources)
: this(new WebApplicationContextArgs() { Name = name, CaseSensitive = caseSensitive, ConfigurationLocations = configurationLocations, ConfigurationResources=configurationResources })
{
}
@@ -91,9 +106,15 @@ namespace Spring.Context.Support
/// <param name="parentContext">The parent context.</param>
/// <param name="configurationLocations">Names of configuration resources.</param>
public WebApplicationContext(string name, bool caseSensitive, IApplicationContext parentContext,
params string[] configurationLocations) : base(name, caseSensitive, parentContext)
params string[] configurationLocations)
: this(new WebApplicationContextArgs() { Name = name, CaseSensitive = caseSensitive, ParentContext = parentContext, ConfigurationLocations = configurationLocations })
{ }
public WebApplicationContext(WebApplicationContextArgs args)
: base(args.Name, args.CaseSensitive, args.ParentContext)
{
_configurationLocations = configurationLocations;
_configurationLocations = args.ConfigurationLocations;
DefaultResourceProtocol = WebUtils.DEFAULT_RESOURCE_PROTOCOL;
Refresh();
@@ -106,6 +127,7 @@ namespace Spring.Context.Support
}
}
/// <summary>
/// returns detailed instance information for debugging
/// </summary>
@@ -154,11 +176,11 @@ namespace Spring.Context.Support
{
string firstRequestPath = HttpRuntime.AppDomainAppVirtualPath.TrimEnd('/') + "/dummy.context";
s_weblog.Info("Forcing first request " + firstRequestPath);
SafeMethod fnProcessRequestNow = new SafeMethod(typeof(HttpRuntime).GetMethod("ProcessRequestNow", BindingFlags.Static|BindingFlags.NonPublic));
SafeMethod fnProcessRequestNow = new SafeMethod(typeof(HttpRuntime).GetMethod("ProcessRequestNow", BindingFlags.Static | BindingFlags.NonPublic));
SimpleWorkerRequest wr = new SimpleWorkerRequest(firstRequestPath, string.Empty, new StringWriter());
fnProcessRequestNow.Invoke(null, new object[] { wr });
// HttpRuntime.ProcessRequest(
// wr);
// HttpRuntime.ProcessRequest(
// wr);
s_weblog.Info("Successfully processed first request!");
}
catch (Exception ex)
@@ -192,7 +214,7 @@ namespace Spring.Context.Support
/// </summary>
public static IApplicationContext GetRootContext()
{
return GetContextInternal( ("" + HttpRuntime.AppDomainAppVirtualPath).TrimEnd('/') + "/dummy.context");
return GetContextInternal(("" + HttpRuntime.AppDomainAppVirtualPath).TrimEnd('/') + "/dummy.context");
}
/// <summary>
@@ -219,7 +241,7 @@ namespace Spring.Context.Support
{
string virtualDirectory = WebUtils.GetVirtualDirectory(virtualPath);
string contextName = virtualDirectory;
if ( 0 == string.Compare( contextName , ("" + HttpRuntime.AppDomainAppVirtualPath).TrimEnd('/') + "/", true) )
if (0 == string.Compare(contextName, ("" + HttpRuntime.AppDomainAppVirtualPath).TrimEnd('/') + "/", true))
{
contextName = DefaultRootContextName;
}
@@ -234,7 +256,7 @@ namespace Spring.Context.Support
s_weblog.Debug(string.Format("looking up web context '{0}' in WebContextCache", contextName));
}
// first lookup in our own cache
IApplicationContext context = (IApplicationContext) s_webContextCache[contextName];
IApplicationContext context = (IApplicationContext)s_webContextCache[contextName];
if (context != null)
{
// found - nothing to do anymore
@@ -347,19 +369,34 @@ namespace Spring.Context.Support
/// <param name="objectDefinitionReader">Reader to initialize.</param>
protected override void InitObjectDefinitionReader(XmlObjectDefinitionReader objectDefinitionReader)
{
// NamespaceParserRegistry.RegisterParser(typeof(WebObjectsNamespaceParser));
// NamespaceParserRegistry.RegisterParser(typeof(WebObjectsNamespaceParser));
}
/// <summary>
/// Return an array of resource locations, referring to the XML object
/// definition files that this context should be built with.
/// An array of resource locations, referring to the XML object
/// definition files with which this context is to be built.
/// </summary>
/// <returns>an array of resource locations, or null if none</returns>
/// <returns>
/// An array of resource locations, or <see langword="null"/> if none.
/// </returns>
/// <seealso cref="Spring.Context.Support.AbstractXmlApplicationContext.ConfigurationLocations"/>
protected override string[] ConfigurationLocations
{
get { return _configurationLocations; }
}
/// <summary>
/// An array of resources instances with which this context is to be built.
/// </summary>
/// <returns>
/// An array of <see cref="Spring.Core.IO.IResource"/>s, or <see langword="null"/> if none.
/// </returns>
/// <seealso cref="Spring.Context.Support.AbstractXmlApplicationContext.ConfigurationLocations"/>
protected override IResource[] ConfigurationResources
{
get { return _configurationResources; }
}
/// <summary>
/// Creates web object factory for this context using parent context's factory as a parent.
/// </summary>

View File

@@ -0,0 +1,40 @@
#region License
/*
* Copyright © 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace Spring.Context.Support
{
public class WebApplicationContextArgs : AbstractXmlApplicationContextArgs
{
/// <summary>
/// Initializes a new instance of the WebApplicationContextArgs class.
/// </summary>
public WebApplicationContextArgs()
{
CaseSensitive = false;
}
}
}

View File

@@ -110,6 +110,7 @@
<Compile Include="Context\Support\WebApplicationContext.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Context\Support\WebApplicationContextArgs.cs" />
<Compile Include="Context\Support\WebContextHandler.cs" />
<Compile Include="Context\Support\WebSupportModule.cs" />
<Compile Include="Core\IO\WebResource.cs" />

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
namespace Spring.Context.Support
{
[TestFixture]
public class XmlApplicationContentArgsTests
{
[Test]
public void Default_CaseSensitivity_isTrue()
{
XmlApplicationContextArgs args = new XmlApplicationContextArgs();
Assert.True(args.CaseSensitive);
}
[Test]
public void Default_AutoRefresh_isTrue()
{
XmlApplicationContextArgs args = new XmlApplicationContextArgs();
Assert.True(args.Refresh);
}
}
}

View File

@@ -74,15 +74,15 @@ namespace Spring.Core.IO
[Test]
public void ThrowsIoExceptionIfConfigSectionDoesNotExist()
{
IResource res = new ConfigSectionResource("DOES NOT EXIST");
IResource res = new ConfigSectionResource(Guid.NewGuid().ToString());
try
{
Stream istm = res.InputStream;
Assert.Fail();
Assert.Fail("Did not receive expected IOException!");
}
catch(IOException ioex)
{
Console.WriteLine(ioex);
catch(IOException)
{
}
}
}

View File

@@ -217,6 +217,7 @@
<Compile Include="Context\Support\TypeAliasesSectionHandlerTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Context\Support\XmlApplicationContentArgsTests.cs" />
<Compile Include="Context\Support\XmlApplicationContextTests.cs">
<SubType>Code</SubType>
</Compile>

View File

@@ -61,6 +61,11 @@ namespace Spring.Transaction.Config
{
get { return null; }
}
protected override IResource[] ConfigurationResources
{
get { return null; }
}
}
private const string APPCTXCFG_PROLOG = @"<?xml version='1.0' encoding='utf-8' ?>";

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
namespace Spring.Context.Support
{
[TestFixture]
public class WebApplicationContextArgsTests
{
[Test]
public void Default_CaseSensitivity_isFalse()
{
WebApplicationContextArgs args = new WebApplicationContextArgs();
Assert.False(args.CaseSensitive);
}
}
}

View File

@@ -91,6 +91,7 @@
</Compile>
<Compile Include="Caching\AspNetCacheTests.cs" />
<Compile Include="Context\Support\HttpApplicationConfigurerTests.cs" />
<Compile Include="Context\Support\WebApplicationContextArgsTests.cs" />
<Compile Include="Context\Support\WebApplicationContextTests.cs" />
<Compile Include="Core\IO\WebResourceTests.cs" />
<Compile Include="Data\Spring\Objects\Factory\Support\TestForm.aspx.cs">