Merge pull request #42 from thomast74/SPRNET-1543
SPRNET-1543 Reviewed GetObjectDefinionNames inconsistencies
This commit is contained in:
@@ -182,8 +182,7 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
string name = objectDefinitionNames[i];
|
||||
if (IsObjectNameMatch(name))
|
||||
{
|
||||
IConfigurableObjectDefinition definition =
|
||||
factory.GetObjectDefinition(name) as IConfigurableObjectDefinition;
|
||||
var definition = factory.GetObjectDefinition(name) as IConfigurableObjectDefinition;
|
||||
|
||||
if (definition == null || IsInfrastructureType(definition.ObjectType, name))
|
||||
{
|
||||
|
||||
@@ -1338,7 +1338,21 @@ namespace Spring.Context.Support
|
||||
/// <seealso cref="Spring.Objects.Factory.IListableObjectFactory.GetObjectDefinitionNames()"/>
|
||||
public IList<string> GetObjectDefinitionNames()
|
||||
{
|
||||
return ObjectFactory.GetObjectDefinitionNames();
|
||||
return GetObjectDefinitionNames(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the names of all objects defined in this factory, if <code>includeAncestors</code>is <code>true</code>
|
||||
/// includes all parent factories.
|
||||
/// </summary>
|
||||
/// <param name="includeAncestors">to include parent factories into result</param>
|
||||
/// <returns>
|
||||
/// The names of all objects defined in this factory, if <code>includeAncestors</code> is <code>true</code> includes all
|
||||
/// objects defined in parent factories, or an empty array if none are defined.
|
||||
/// </returns>
|
||||
public IList<string> GetObjectDefinitionNames(bool includeAncestors)
|
||||
{
|
||||
return ObjectFactory.GetObjectDefinitionNames(includeAncestors);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Spring.Objects.Factory.Support;
|
||||
|
||||
namespace Spring.Objects.Factory.Config
|
||||
{
|
||||
/// <summary>
|
||||
@@ -138,8 +140,8 @@ namespace Spring.Objects.Factory.Config
|
||||
/// </remarks>
|
||||
/// <value>The list of names as String array (never <code>null</code>).</value>
|
||||
/// <see cref="RegisterSingleton"/>
|
||||
/// <see cref="Spring.Objects.Factory.Support.IObjectDefinitionRegistry.GetObjectDefinitionNames"/>
|
||||
/// <see cref="Spring.Objects.Factory.IListableObjectFactory.GetObjectDefinitionNames"/>
|
||||
/// <see cref="IObjectDefinitionRegistry.GetObjectDefinitionNames()"/>
|
||||
/// <see cref="IListableObjectFactory.GetObjectDefinitionNames()"/>
|
||||
IList<string> SingletonNames
|
||||
{
|
||||
get;
|
||||
|
||||
@@ -161,6 +161,7 @@ namespace Spring.Objects.Factory.Config
|
||||
private string placeholderPrefix = DefaultPlaceholderPrefix;
|
||||
private string placeholderSuffix = DefaultPlaceholderSuffix;
|
||||
private EnvironmentVariableMode environmentVariableMode = EnvironmentVariableMode.Fallback;
|
||||
private bool includeAncestors;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the new instance
|
||||
@@ -171,6 +172,7 @@ namespace Spring.Objects.Factory.Config
|
||||
}
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// The placeholder prefix (the default is <c>${</c>).
|
||||
/// </summary>
|
||||
@@ -214,45 +216,58 @@ namespace Spring.Objects.Factory.Config
|
||||
set { environmentVariableMode = value; }
|
||||
}
|
||||
|
||||
public bool IncludeAncestors
|
||||
{
|
||||
set { includeAncestors = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Apply the given properties to the supplied
|
||||
/// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>.
|
||||
/// </summary>
|
||||
/// <param name="factory">
|
||||
/// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>
|
||||
/// used by the application context.
|
||||
/// </param>
|
||||
/// <param name="props">The properties to apply.</param>
|
||||
/// <exception cref="Spring.Objects.ObjectsException">
|
||||
/// If an error occured.
|
||||
/// </exception>
|
||||
protected override void ProcessProperties(IConfigurableListableObjectFactory factory, NameValueCollection props)
|
||||
{
|
||||
PlaceholderResolveHandlerAdapter resolveAdapter = new PlaceholderResolveHandlerAdapter(this, props);
|
||||
ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(resolveAdapter.ParseAndResolveVariables);
|
||||
/// <summary>
|
||||
/// Apply the given properties to the supplied
|
||||
/// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>.
|
||||
/// </summary>
|
||||
/// <param name="factory">
|
||||
/// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>
|
||||
/// used by the application context.
|
||||
/// </param>
|
||||
/// <param name="props">The properties to apply.</param>
|
||||
/// <exception cref="Spring.Objects.ObjectsException">
|
||||
/// If an error occured.
|
||||
/// </exception>
|
||||
protected override void ProcessProperties(IConfigurableListableObjectFactory factory, NameValueCollection props)
|
||||
{
|
||||
PlaceholderResolveHandlerAdapter resolveAdapter = new PlaceholderResolveHandlerAdapter(this, props);
|
||||
ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(resolveAdapter.ParseAndResolveVariables);
|
||||
|
||||
IList<string> objectDefinitionNames = factory.GetObjectDefinitionNames();
|
||||
for (int i = 0; i < objectDefinitionNames.Count; ++i)
|
||||
{
|
||||
string name = objectDefinitionNames[i];
|
||||
IObjectDefinition definition = factory.GetObjectDefinition(name);
|
||||
try
|
||||
{
|
||||
visitor.VisitObjectDefinition(definition);
|
||||
}
|
||||
catch (ObjectDefinitionStoreException ex)
|
||||
{
|
||||
throw new ObjectDefinitionStoreException(
|
||||
definition.ResourceDescription, name, ex.Message);
|
||||
}
|
||||
}
|
||||
IList<string> objectDefinitionNames = factory.GetObjectDefinitionNames(includeAncestors);
|
||||
for (int i = 0; i < objectDefinitionNames.Count; ++i)
|
||||
{
|
||||
string name = objectDefinitionNames[i];
|
||||
IObjectDefinition definition = factory.GetObjectDefinition(name, includeAncestors);
|
||||
|
||||
factory.AddEmbeddedValueResolver(resolveAdapter);
|
||||
}
|
||||
if (definition == null)
|
||||
{
|
||||
logger.ErrorFormat("'{0}' can't be found in factorys' '{1}' object definition (includeAncestor {2})",
|
||||
name, factory, includeAncestors);
|
||||
continue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
try
|
||||
{
|
||||
visitor.VisitObjectDefinition(definition);
|
||||
}
|
||||
catch (ObjectDefinitionStoreException ex)
|
||||
{
|
||||
throw new ObjectDefinitionStoreException(
|
||||
definition.ResourceDescription, name, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
factory.AddEmbeddedValueResolver(resolveAdapter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse values recursively to be able to resolve cross-references between
|
||||
/// placeholder values.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
/*
|
||||
* Copyright 2002-2010 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
|
||||
@@ -79,6 +79,7 @@ namespace Spring.Objects.Factory.Config
|
||||
|
||||
private int order = Int32.MaxValue; // default: same as non-Ordered
|
||||
|
||||
private bool includeAncestors;
|
||||
private bool ignoreUnresolvablePlaceholders;
|
||||
private string placeholderPrefix = DefaultPlaceholderPrefix;
|
||||
private string placeholderSuffix = DefaultPlaceholderSuffix;
|
||||
@@ -160,6 +161,11 @@ namespace Spring.Objects.Factory.Config
|
||||
set { ignoreUnresolvablePlaceholders = value; }
|
||||
}
|
||||
|
||||
public bool IncludeAncestors
|
||||
{
|
||||
set { includeAncestors = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IObjectFactoryPostProcessor Members
|
||||
@@ -246,11 +252,15 @@ namespace Spring.Objects.Factory.Config
|
||||
TextProcessor tp = new TextProcessor(this, compositeVariableSource);
|
||||
ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(tp.ParseAndResolveVariables));
|
||||
|
||||
IList<string> objectDefinitionNames = factory.GetObjectDefinitionNames();
|
||||
IList<string> objectDefinitionNames = factory.GetObjectDefinitionNames(includeAncestors);
|
||||
for (int i = 0; i < objectDefinitionNames.Count; ++i)
|
||||
{
|
||||
string name = objectDefinitionNames[i];
|
||||
IObjectDefinition definition = factory.GetObjectDefinition( name );
|
||||
IObjectDefinition definition = factory.GetObjectDefinition( name, includeAncestors );
|
||||
|
||||
if (definition == null)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
visitor.VisitObjectDefinition( definition );
|
||||
|
||||
@@ -96,6 +96,17 @@ namespace Spring.Objects.Factory
|
||||
/// </returns>
|
||||
IList<string> GetObjectDefinitionNames();
|
||||
|
||||
/// <summary>
|
||||
/// Return the names of all objects defined in this factory, if <code>includeAncestors</code> is <code>true</code>
|
||||
/// includes all parent factories.
|
||||
/// </summary>
|
||||
/// <param name="includeAncestors">to include parent factories in result</param>
|
||||
/// <returns>
|
||||
/// The names of all objects defined in this factory, if <code>includeAncestors</code> is <code>true</code> includes all
|
||||
/// objects defined in parent factories, or an empty array if none are defined.
|
||||
/// </returns>
|
||||
IList<string> GetObjectDefinitionNames(bool includeAncestors);
|
||||
|
||||
/// <summary>
|
||||
/// Return the names of objects matching the given <see cref="System.Type"/>
|
||||
/// (including subclasses), judging from the object definitions.
|
||||
@@ -121,7 +132,6 @@ namespace Spring.Objects.Factory
|
||||
/// </returns>
|
||||
IList<string> GetObjectNamesForType(Type type);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Return the names of objects matching the given <see cref="System.Type"/>
|
||||
/// (including subclasses), judging from the object definitions.
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace Spring.Objects.Factory
|
||||
/// If this isn't also an
|
||||
/// <see cref="Spring.Objects.Factory.IHierarchicalObjectFactory"/>,
|
||||
/// this method will return the same as it's own
|
||||
/// <see cref="Spring.Objects.Factory.IListableObjectFactory.GetObjectDefinitionNames"/>
|
||||
/// <see cref="IListableObjectFactory.GetObjectDefinitionNames()"/>
|
||||
/// method.
|
||||
/// </param>
|
||||
/// <param name="type">
|
||||
@@ -197,11 +197,8 @@ namespace Spring.Objects.Factory
|
||||
/// </p>
|
||||
/// </remarks>
|
||||
/// <param name="factory">
|
||||
/// If this isn't also an
|
||||
/// <see cref="Spring.Objects.Factory.IHierarchicalObjectFactory"/>,
|
||||
/// this method will return the same as it's own
|
||||
/// <see cref="Spring.Objects.Factory.IListableObjectFactory.GetObjectDefinitionNames"/>
|
||||
/// method.
|
||||
/// If this isn't also an <see cref="Spring.Objects.Factory.IHierarchicalObjectFactory"/>,
|
||||
/// this method will return the same as it's own <see cref="IListableObjectFactory.GetObjectDefinitionNames()"/> method.
|
||||
/// </param>
|
||||
/// <param name="type">
|
||||
/// The <see cref="System.Type"/> that objects must match.
|
||||
@@ -209,8 +206,7 @@ namespace Spring.Objects.Factory
|
||||
/// <returns>
|
||||
/// The array of object names, or an empty array if none.
|
||||
/// </returns>
|
||||
public static IList<string> ObjectNamesForTypeIncludingAncestors(
|
||||
IListableObjectFactory factory, Type type)
|
||||
public static IList<string> ObjectNamesForTypeIncludingAncestors(IListableObjectFactory factory, Type type)
|
||||
{
|
||||
return factory.GetObjectNamesForType(type);
|
||||
}
|
||||
|
||||
@@ -2739,8 +2739,8 @@ namespace Spring.Objects.Factory.Support
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <see cref="RegisterSingleton"/>
|
||||
/// <see cref="Spring.Objects.Factory.Support.IObjectDefinitionRegistry.GetObjectDefinitionNames"/>
|
||||
/// <see cref="Spring.Objects.Factory.IListableObjectFactory.GetObjectDefinitionNames"/>
|
||||
/// <see cref="IObjectDefinitionRegistry.GetObjectDefinitionNames()"/>
|
||||
/// <see cref="IListableObjectFactory.GetObjectDefinitionNames()"/>
|
||||
public IList<string> SingletonNames
|
||||
{
|
||||
get
|
||||
|
||||
@@ -239,9 +239,9 @@ namespace Spring.Objects.Factory.Support
|
||||
if (log.IsDebugEnabled)
|
||||
{
|
||||
log.Debug(string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"Found depending object '{0}' for object '{1}'.",
|
||||
name, objectName));
|
||||
CultureInfo.InvariantCulture,
|
||||
"Found depending object '{0}' for object '{1}'.",
|
||||
name, objectName));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -276,30 +276,20 @@ namespace Spring.Objects.Factory.Support
|
||||
}
|
||||
|
||||
private bool IsObjectDefinitionTypeMatch(string name, Type checkedType)
|
||||
{
|
||||
return IsObjectDefinitionTypeMatch(name, checkedType, false);
|
||||
}
|
||||
|
||||
private bool IsObjectDefinitionTypeMatch(string name, Type checkedType, bool includeAncestor)
|
||||
{
|
||||
if (checkedType == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
RootObjectDefinition rod = GetMergedObjectDefinition(name, false);
|
||||
RootObjectDefinition rod = GetMergedObjectDefinition(name, includeAncestor);
|
||||
return (rod.HasObjectType && checkedType.IsAssignableFrom(rod.ObjectType));
|
||||
}
|
||||
/*
|
||||
/// <summary>
|
||||
/// Merges the object definitions.
|
||||
/// </summary>
|
||||
/// <param name="name">Object definition name.</param>
|
||||
/// <param name="parentDefinition">The parent definition.</param>
|
||||
/// <param name="childDefinition">The child definition.</param>
|
||||
/// <returns>Merged object definition.</returns>
|
||||
protected override RootObjectDefinition MergeObjectDefinitions(string name, IObjectDefinition parentDefinition,
|
||||
IObjectDefinition childDefinition)
|
||||
{
|
||||
RootObjectDefinition rootDefinition = base.MergeObjectDefinitions(name, parentDefinition, childDefinition);
|
||||
RegisterObjectDefinition(name, rootDefinition);
|
||||
return rootDefinition;
|
||||
}
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
@@ -598,6 +588,7 @@ namespace Spring.Objects.Factory.Support
|
||||
|
||||
#region IListableObjectFactory Members
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Return the names of all objects defined in this factory.
|
||||
/// </summary>
|
||||
@@ -607,14 +598,28 @@ namespace Spring.Objects.Factory.Support
|
||||
/// </returns>
|
||||
/// <seealso cref="Spring.Objects.Factory.IListableObjectFactory.GetObjectDefinitionNames()"/>
|
||||
public IList<string> GetObjectDefinitionNames()
|
||||
{
|
||||
return GetObjectDefinitionNames(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the names of all objects defined in this factory, if <code>includeAncestors</code> is <code>true</code>
|
||||
/// includes all parent factories.
|
||||
/// </summary>
|
||||
/// <param name="includeAncestors">to include parent factories in result</param>
|
||||
/// <returns>
|
||||
/// The names of all objects defined in this factory, if <code>includeAncestors</code> is <code>true</code> includes all
|
||||
/// objects defined in parent factories, or an empty array if none are defined.
|
||||
/// </returns>
|
||||
public IList<string> GetObjectDefinitionNames(bool includeAncestors)
|
||||
{
|
||||
IList<string> results = new List<string>(objectDefinitionNames);
|
||||
|
||||
var listableObjectFactory = ParentObjectFactory as IListableObjectFactory;
|
||||
|
||||
if (listableObjectFactory != null)
|
||||
if (includeAncestors && listableObjectFactory != null)
|
||||
{
|
||||
foreach (var name in listableObjectFactory.GetObjectDefinitionNames())
|
||||
foreach (var name in listableObjectFactory.GetObjectDefinitionNames(includeAncestors))
|
||||
{
|
||||
if (!results.Contains(name))
|
||||
{
|
||||
@@ -640,16 +645,21 @@ namespace Spring.Objects.Factory.Support
|
||||
/// </returns>
|
||||
/// <seealso cref="Spring.Objects.Factory.IListableObjectFactory.GetObjectDefinitionNames()"/>
|
||||
public IList<string> GetObjectDefinitionNames(Type type)
|
||||
{
|
||||
return GetObjectDefinitionNames(type, false);
|
||||
}
|
||||
|
||||
public IList<string> GetObjectDefinitionNames(Type type, bool includeAncestor)
|
||||
{
|
||||
List<string> matches = new List<string>();
|
||||
foreach (string name in objectDefinitionNames)
|
||||
foreach (string name in GetObjectDefinitionNames(includeAncestor))
|
||||
{
|
||||
if (IsObjectDefinitionTypeMatch(name, type))
|
||||
if (IsObjectDefinitionTypeMatch(name, type, includeAncestor))
|
||||
{
|
||||
matches.Add(name);
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
return matches;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1013,7 +1023,7 @@ namespace Spring.Objects.Factory.Support
|
||||
protected List<string> DoGetObjectNamesForType(Type type, bool includeNonSingletons, bool allowEagerInit)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
IList<string> objectNames = GetObjectDefinitionNames();
|
||||
IList<string> objectNames = GetObjectDefinitionNames(true);
|
||||
foreach (string s in objectNames)
|
||||
{
|
||||
string objectName = s;
|
||||
|
||||
@@ -71,8 +71,20 @@ namespace Spring.Objects.Factory.Support
|
||||
/// The names of all objects defined in this registry, or an empty array
|
||||
/// if none defined
|
||||
/// </returns>
|
||||
IList<string> GetObjectDefinitionNames ();
|
||||
|
||||
IList<string> GetObjectDefinitionNames();
|
||||
|
||||
/// <summary>
|
||||
/// Return the names of all objects defined in this registry.
|
||||
/// If <code>includeAncestors</code> is <code>true</code> it includes all objects in the defined parent factories.
|
||||
/// </summary>
|
||||
/// <param name="includeAncestors">to include parent factories in result</param>
|
||||
/// <returns>
|
||||
/// The names of all objects defined in this registry, if <code>includeAncestors</code> is <code>true</code> it includes
|
||||
/// all objects in the defined parent factories, or an empty array if none defined
|
||||
/// </returns>
|
||||
IList<string> GetObjectDefinitionNames(bool includeAncestors);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Check if this registry contains a object definition with the given name.
|
||||
/// </summary>
|
||||
|
||||
@@ -557,6 +557,20 @@ namespace Spring.Objects.Factory.Support
|
||||
return names;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the names of all objects defined in this factory, if <code>includeAncestors</code> is <code>true</code>
|
||||
/// includes all parent factories.
|
||||
/// </summary>
|
||||
/// <param name="includeAncestors">to include parent factories in result</param>
|
||||
/// <returns>
|
||||
/// The names of all objects defined in this factory, if <code>includeAncestors</code> is <code>true</code> includes all
|
||||
/// objects defined in parent factories, or an empty array if none are defined.
|
||||
/// </returns>
|
||||
public IList<string> GetObjectDefinitionNames(bool includeAncestors)
|
||||
{
|
||||
throw new NotSupportedException("StaticListableObjectFactory does not contain object definitions.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the names of objects matching the given <see cref="System.Type"/>
|
||||
/// (including subclasses), judging from the object definitions.
|
||||
|
||||
Reference in New Issue
Block a user