further refactoring towards Spring/J 2.5 codebase to better support new extension projects (SPRNET-929)

This commit is contained in:
eeichinger
2009-03-03 02:48:35 +00:00
parent bd2b4bda11
commit 587964d20e
19 changed files with 815 additions and 445 deletions

View File

@@ -110,6 +110,16 @@ namespace Spring.Objects.Factory.Config
/// </remarks>
bool IsLazyInit { get; }
/// <summary>
/// The name of the parent definition of this object definition, if any.
/// </summary>
string ParentName { get; set; }
/// <summary>
/// The target scope for this object.
/// </summary>
string Scope { get; set; }
/// <summary>
/// Returns the <see cref="System.Type"/> of the object definition (if any).
/// </summary>

View File

@@ -46,6 +46,10 @@ namespace Spring.Objects.Factory.Support
[Serializable]
public abstract class AbstractObjectDefinition : IConfigurableObjectDefinition
{
private static readonly string SCOPE_SINGLETON = "singleton";
private static readonly string SCOPE_PROTOTYPE = "prototype";
#region Constructor (s) / Destructor
/// <summary>
@@ -118,8 +122,10 @@ namespace Spring.Objects.Factory.Support
MethodOverrides = new MethodOverrides(aod.MethodOverrides);
DependencyCheck = aod.DependencyCheck;
}
ParentName = other.ParentName;
IsAbstract = other.IsAbstract;
IsSingleton = other.IsSingleton;
// IsSingleton = other.IsSingleton;
Scope = other.Scope;
IsLazyInit = other.IsLazyInit;
ConstructorArgumentValues
= new ConstructorArgumentValues(other.ConstructorArgumentValues);
@@ -141,6 +147,11 @@ namespace Spring.Objects.Factory.Support
#region Properties
/// <summary>
/// The name of the parent definition of this object definition, if any.
/// </summary>
public abstract string ParentName { get; set; }
/// <summary>
/// The property values that are to be applied to the object
/// upon creation.
@@ -243,6 +254,23 @@ namespace Spring.Objects.Factory.Support
set { methodOverrides = value == null ? new MethodOverrides() : value; }
}
/// <summary>
/// The name of the target scope for the object.
/// Defaults to "singleton", ootb alternative is "prototype". Extended object factories
/// might support further scopes.
/// </summary>
public virtual string Scope
{
get { return scope; }
set
{
AssertUtils.ArgumentNotNull(value, "Scope");
this.scope = value;
this.isSingleton = 0==string.Compare(SCOPE_SINGLETON, value, true);
this.isPrototype = 0==string.Compare(SCOPE_PROTOTYPE, value, true);
}
}
/// <summary>
/// Is this definition a <b>singleton</b>, with
/// a single, shared instance returned on all calls to an enclosing
@@ -265,6 +293,7 @@ namespace Spring.Objects.Factory.Support
get { return isSingleton; }
set
{
scope = (value ? SCOPE_SINGLETON : SCOPE_PROTOTYPE);
isSingleton = value;
isPrototype = !value;
}
@@ -387,6 +416,7 @@ namespace Spring.Objects.Factory.Support
set { objectType = StringUtils.GetTextOrNull(value); }
}
/// <summary>
/// A description of the resource that this object definition
/// came from (for the purpose of showing context in case of errors).
@@ -674,7 +704,7 @@ namespace Spring.Objects.Factory.Support
AssertUtils.ArgumentNotNull(other, "other");
IsAbstract = other.IsAbstract;
IsSingleton = other.IsSingleton;
Scope = other.Scope;
IsLazyInit = other.IsLazyInit;
ConstructorArgumentValues.AddAll(other.ConstructorArgumentValues);
PropertyValues.AddAll(other.PropertyValues.PropertyValues);
@@ -734,8 +764,10 @@ namespace Spring.Objects.Factory.Support
/// </returns>
public override string ToString()
{
StringBuilder buffer = new StringBuilder();
buffer.Append("Abstract = ").Append(IsAbstract);
StringBuilder buffer = new StringBuilder(string.Format("Class [{0}]", ObjectTypeName));
buffer.Append("; Abstract = ").Append(IsAbstract);
buffer.Append("; Parent = ").Append(ParentName);
buffer.Append("; Scope = ").Append(Scope);
buffer.Append("; Singleton = ").Append(IsSingleton);
buffer.Append("; LazyInit = ").Append(IsLazyInit);
buffer.Append("; Autowire = ").Append(AutowireMode);
@@ -764,6 +796,7 @@ namespace Spring.Objects.Factory.Support
private bool isPrototype = false;
private bool isLazyInit = false;
private bool isAbstract = false;
private string scope = SCOPE_SINGLETON;
private object objectType;
private AutoWiringMode autowireMode = AutoWiringMode.No;
private DependencyCheckingMode dependencyCheck = DependencyCheckingMode.None;

View File

@@ -526,53 +526,54 @@ namespace Spring.Objects.Factory.Support
/// A merged <see cref="Spring.Objects.Factory.Support.RootObjectDefinition"/>
/// with overridden properties.
/// </returns>
protected internal virtual RootObjectDefinition GetMergedObjectDefinition( string name, IObjectDefinition definition )
protected internal virtual RootObjectDefinition GetMergedObjectDefinition( string name, IObjectDefinition od )
{
if (definition == null)
if (od == null)
{
return null;
}
else if (definition is RootObjectDefinition)
RootObjectDefinition mod;
if (od.ParentName == null)
{
return (RootObjectDefinition)definition;
mod = CreateRootObjectDefinition(od);
}
else if (definition is ChildObjectDefinition)
else
{
ChildObjectDefinition childDefinition = (ChildObjectDefinition)definition;
RootObjectDefinition parentDefinition = null;
if (!name.Equals( childDefinition.ParentName ))
// IObjectDefinition childDefinition = definition;
IObjectDefinition pod = null;
if (!name.Equals( od.ParentName ))
{
parentDefinition =
GetMergedObjectDefinition( TransformedObjectName( childDefinition.ParentName ), true );
pod = GetMergedObjectDefinition( TransformedObjectName( od.ParentName ), true );
}
else
{
if (ParentObjectFactory is AbstractObjectFactory)
{
parentDefinition =
((AbstractObjectFactory)ParentObjectFactory).GetMergedObjectDefinition(
childDefinition.ParentName, true );
pod = ((AbstractObjectFactory)ParentObjectFactory).GetMergedObjectDefinition( od.ParentName, true );
}
}
if (parentDefinition == null)
if (pod == null)
{
throw new NoSuchObjectDefinitionException( childDefinition.ParentName,
throw new NoSuchObjectDefinitionException( od.ParentName,
string.Format(
"Parent name '{0}' is equal to object name '{1}' - "
+
"cannot be resolved without an AbstractObjectFactory parent.",
childDefinition.ParentName, name ) );
od.ParentName, name ) );
}
RootObjectDefinition rootDefinition = CreateRootObjectDefinition( parentDefinition );
rootDefinition.OverrideFrom( childDefinition );
return rootDefinition;
}
else
{
throw new ObjectDefinitionStoreException( definition.ResourceDescription, name,
"Definition is neither a RootObjectDefinition nor a ChildObjectDefinition." );
mod = CreateRootObjectDefinition( pod );
mod.OverrideFrom( od );
}
// else
// {
// throw new ObjectDefinitionStoreException( definition.ResourceDescription, name,
// "Definition is neither a RootObjectDefinition nor a ChildObjectDefinition." );
// }
return mod;
}
/*
@@ -1485,6 +1486,8 @@ namespace Spring.Objects.Factory.Support
#region IObjectFactory Members
#region New region
/// <summary>
/// Is this object a singleton?
/// </summary>
@@ -1987,6 +1990,8 @@ namespace Spring.Objects.Factory.Support
#endregion
#endregion
/// <summary>
/// Destroy all cached singletons in this factory.
/// </summary>

View File

@@ -186,16 +186,15 @@ namespace Spring.Objects.Factory.Support
/// The name of the parent object definition.
/// </summary>
/// <remarks>
/// <p>
/// This value is <b>required</b>.
/// </p>
/// </remarks>
/// <value>
/// The name of the parent object definition.
/// </value>
public string ParentName
public override string ParentName
{
get { return parentName; }
get { return parentName; }
set { parentName = value; }
}
#endregion

View File

@@ -0,0 +1,110 @@
#region License
/*
* Copyright 2002-2009 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 Spring.Objects.Factory.Config;
namespace Spring.Objects.Factory.Support
{
/// <summary>
/// GenericObjectDefinition is a one-stop shop for standard object definition purposes.
/// Like any object definition, it allows for specifying a class plus optionally
/// constructor argument values and property values. Additionally, deriving from a
/// parent bean definition can be flexibly configured through the &quot;parentName&quot; property.
/// </summary>
/// <remarks>In general, use this <see cref="GenericObjectDefinition"/> class for the purpose of
/// registering user-visible object definitions (which a post-processor might operate on,
/// potentially even reconfiguring the parent name).
/// Use <see cref="RootObjectDefinition"/>/<see cref="ChildObjectDefinition"/>
/// where parent/child relationships happen to be pre-determined.
/// </remarks>
/// <seealso cref="RootObjectDefinition"/>
/// <seealso cref="ChildObjectDefinition"/>
/// <author>Juergen Hoeller</author>
/// <author>Erich Eichinger</author>
[Serializable]
public class GenericObjectDefinition : AbstractObjectDefinition
{
private string parentName;
/// <summary>
/// The name of the parent object definition.
/// </summary>
/// <remarks>
/// This value is <b>required</b>.
/// </remarks>
/// <value>
/// The name of the parent object definition.
/// </value>
public override string ParentName
{
get { return parentName; }
set { parentName = value; }
}
/// <summary>
/// Creates a new <see cref="GenericObjectDefinition"/> to be configured through its
/// object properties and configuration methods.
/// </summary>
public GenericObjectDefinition()
{ }
/// <summary>
/// Creates a new <see cref="GenericObjectDefinition"/> as deep copy of the given
/// object definition.
/// </summary>
/// <param name="original">the original object definition to copy from</param>
public GenericObjectDefinition(IObjectDefinition original)
: base(original)
{
GenericObjectDefinition god = original as GenericObjectDefinition;
if (god != null)
{
this.parentName = god.parentName;
}
}
/* TODO (EE): this is not supported atm, need to implement AbstractObjectDefinition.Equals() first */
// /// <summary>
// /// Checks, if <paramref name="other"/> equals this object definition.
// /// </summary>
// /// <param name="other"></param>
// /// <returns></returns>
// public override bool Equals(object other)
// {
// return object.ReferenceEquals(this, other)
// || (other is GenericObjectDefinition && base.Equals(obj));
// }
//
// public override int GetHashCode()
// {
// return base.GetHashCode();
// }
/// <summary>
/// Returns a <see cref="System.String"/> representation of this
/// <see cref="GenericObjectDefinition"/> for debugging purposes.
/// </summary>
public override string ToString()
{
return "Generic Object:" + base.ToString();
}
}
}

View File

@@ -61,6 +61,39 @@ namespace Spring.Objects.Factory.Support
#region Factory Methods
/// <summary>
/// Creates a new <see cref="ObjectDefinitionBuilder"/> used to construct a <see cref="Spring.Objects.Factory.Support.GenericObjectDefinition"/>.
/// </summary>
public static ObjectDefinitionBuilder GenericObjectDefinition()
{
ObjectDefinitionBuilder builder = new ObjectDefinitionBuilder();
builder.objectDefinition = new GenericObjectDefinition();
return builder;
}
/// <summary>
/// Creates a new <see cref="ObjectDefinitionBuilder"/> used to construct a <see cref="Spring.Objects.Factory.Support.GenericObjectDefinition"/>.
/// </summary>
/// <param name="objectType">the <see cref="Type"/> of the object that the definition is being created for</param>
public static ObjectDefinitionBuilder GenericObjectDefinition(Type objectType)
{
ObjectDefinitionBuilder builder = new ObjectDefinitionBuilder();
builder.objectDefinition = new GenericObjectDefinition();
builder.objectDefinition.ObjectType = objectType;
return builder;
}
/// <summary>
/// Creates a new <see cref="ObjectDefinitionBuilder"/> used to construct a <see cref="Spring.Objects.Factory.Support.GenericObjectDefinition"/>.
/// </summary>
/// <param name="objectTypeName">the name of the <see cref="Type"/> of the object that the definition is being created for</param>
public static ObjectDefinitionBuilder GenericObjectDefinition(string objectTypeName)
{
ObjectDefinitionBuilder builder = new ObjectDefinitionBuilder();
builder.objectDefinition = new GenericObjectDefinition();
builder.objectDefinition.ObjectTypeName = objectTypeName;
return builder;
}
/// <summary>
/// Create a new <code>ObjectDefinitionBuilder</code> used to construct a root object definition.

View File

@@ -253,7 +253,30 @@ namespace Spring.Objects.Factory.Support
public RootObjectDefinition(IObjectDefinition other) : base(other)
{}
#endregion
#endregion
/// <summary>
/// Is always <c>null</c> for a <see cref="RootObjectDefinition"/>.
/// </summary>
/// <remarks>
/// It is safe to request this property's value. Setting any other value than <c>null</c> will
/// raise an <see cref="ArgumentException"/>.
/// </remarks>
/// <exception cref="ArgumentException">Raised on any attempt to set a non-null value on this property.</exception>
public override string ParentName
{
get
{
return null;
}
set
{
if (value != null)
{
throw new ArgumentException("Root Object cannot be changed into a child oject with parent reference");
}
}
}
/// <summary>
/// Validate this object definition.

View File

@@ -18,7 +18,9 @@
#endregion
#region Imports
#region Imports
using System;
using System.Xml;
using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Support;

View File

@@ -57,18 +57,30 @@ namespace Spring.Objects.Factory.Xml
/// </returns>
protected override AbstractObjectDefinition ParseInternal(XmlElement element, ParserContext parserContext)
{
ObjectDefinitionBuilder builder;
ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.GenericObjectDefinition();
string parentName = GetParentName(element);
if (parentName != null)
{
builder.RawObjectDefinition.ParentName = parentName;
}
Type objectType = GetObjectType(element);
if (objectType != null)
{
builder =
ObjectDefinitionBuilder.RootObjectDefinition(parserContext.ReaderContext.ObjectDefinitionFactory,
objectType);
{
builder.RawObjectDefinition.ObjectType = objectType;
}
else
{
throw new NotSupportedException("Need to refactor IObjectDefinitionFactory to not resolve object type names");
}
{
string objectTypeName = GetObjectTypeName(element);
if (objectTypeName != null)
{
builder.RawObjectDefinition.ObjectTypeName = objectTypeName;
}
}
// TODO (EE)
// builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
if (parserContext.IsNested)
{
// Inner object definition must receive same singleton status as containing object.
@@ -84,6 +96,19 @@ namespace Spring.Objects.Factory.Xml
}
/// <summary>
/// Determine the name for the parent of the currently parsed object,
/// in case of the current object being defined as a child object.
/// The default implementation returns <c>null</c>
/// indicating a root object definition.
/// </summary>
/// <param name="element"></param>
/// <returns>the name of the parent object for the currently parsed object.</returns>
protected virtual string GetParentName(XmlElement element)
{
return null;
}
/// <summary>
/// Gets the type of the object corresponding to the supplied XmlElement.
/// </summary>

View File

@@ -1,5 +1,5 @@
#region License
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
@@ -14,47 +14,48 @@
* 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
#region Imports
using System;
using System.Collections;
using System.Collections.Specialized;
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.Xml;
using System.Xml.Schema;
using System.Xml;
using System.Xml.Schema;
using Spring.Collections;
using Spring.Core;
using Spring.Core.IO;
using Spring.Core.TypeResolution;
using Spring.Util;
using Spring.Validation;
#endregion
namespace Spring.Objects.Factory.Xml
{
/// <summary>
/// Provides a resolution mechanism for configuration parsers.
/// </summary>
/// <remarks>
/// <p>
/// The <see cref="DefaultObjectDefinitionDocumentReader"/> uses this registry
/// class to find the parser handling a specific namespace.
/// </p>
/// </remarks>
/// <author>Aleksandar Seovic</author>
public class NamespaceParserRegistry
{
using Spring.Core;
using Spring.Core.IO;
using Spring.Core.TypeResolution;
using Spring.Objects.Factory.Config;
using Spring.Util;
using Spring.Validation;
#endregion
namespace Spring.Objects.Factory.Xml
{
/// <summary>
/// Provides a resolution mechanism for configuration parsers.
/// </summary>
/// <remarks>
/// <p>
/// The <see cref="DefaultObjectDefinitionDocumentReader"/> uses this registry
/// class to find the parser handling a specific namespace.
/// </p>
/// </remarks>
/// <author>Aleksandar Seovic</author>
public class NamespaceParserRegistry
{
/// <summary>
/// Resolves xml entities by using the <see cref="IResourceLoader"/> infrastructure.
/// </summary>
/// </summary>
private class XmlResourceUrlResolver : XmlUrlResolver
{
public override object GetEntity( Uri absoluteUri, string role, Type ofObjectToReturn )
public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
{
IResourceLoader resourceLoader = new ConfigurableResourceLoader();
IResource resource = resourceLoader.GetResource(absoluteUri.AbsoluteUri);
@@ -62,53 +63,53 @@ namespace Spring.Objects.Factory.Xml
//return base.GetEntity( absoluteUri, role, ofObjectToReturn );
}
public override Uri ResolveUri( Uri baseUri, string relativeUri )
public override Uri ResolveUri(Uri baseUri, string relativeUri)
{
// TODO: resolve Uri using IResource instance
return base.ResolveUri( baseUri, relativeUri );
return base.ResolveUri(baseUri, relativeUri);
}
}
/// <summary>
/// Name of the .Net config section that contains definitions
/// for custom config parsers.
/// </summary>
private const string ConfigParsersSectionName = "spring/parsers";
#region Fields
private readonly static IDictionary parsers;
private readonly static IDictionary wellknownNamespaceParserTypeNames;
/// <summary>
/// Name of the .Net config section that contains definitions
/// for custom config parsers.
/// </summary>
private const string ConfigParsersSectionName = "spring/parsers";
#region Fields
private readonly static IDictionary parsers;
private readonly static IDictionary wellknownNamespaceParserTypeNames;
#if !NET_2_0
private readonly static XmlSchemaCollection schemas;
#else
private readonly static XmlSchemaSet schemas;
#endif
#endregion
/// <summary>
/// Creates a new instance of the NamespaceParserRegistry class.
/// </summary>
static NamespaceParserRegistry()
{
parsers = new HybridDictionary();
#else
private readonly static XmlSchemaSet schemas;
#endif
#endregion
/// <summary>
/// Creates a new instance of the NamespaceParserRegistry class.
/// </summary>
static NamespaceParserRegistry()
{
parsers = new HybridDictionary();
#if !NET_2_0
schemas = new XmlSchemaCollection();
#else
schemas = new XmlSchemaSet();
schemas.XmlResolver = new XmlResourceUrlResolver();
#endif
wellknownNamespaceParserTypeNames = new CaseInsensitiveHashtable();
wellknownNamespaceParserTypeNames["http://www.springframework.net/tx"] = "Spring.Transaction.Config.TxNamespaceParser, Spring.Data";
wellknownNamespaceParserTypeNames["http://www.springframework.net/aop"] = "Spring.Aop.Config.AopNamespaceParser, Spring.Aop";
wellknownNamespaceParserTypeNames["http://www.springframework.net/db"] = "Spring.Data.Config.DatabaseNamespaceParser, Spring.Data";
wellknownNamespaceParserTypeNames["http://www.springframework.net/remoting"] = "Spring.Remoting.Config.RemotingNamespaceParser, Spring.Services";
wellknownNamespaceParserTypeNames["http://www.springframework.net/nms"] = "Spring.Messaging.Nms.Config.NmsNamespaceParser, Spring.Messaging.Nms";
wellknownNamespaceParserTypeNames["http://www.springframework.net/validation"] = "Spring.Validation.Config.ValidationNamespaceParser, Spring.Core";
Reset();
#else
schemas = new XmlSchemaSet();
schemas.XmlResolver = new XmlResourceUrlResolver();
#endif
wellknownNamespaceParserTypeNames = new CaseInsensitiveHashtable();
wellknownNamespaceParserTypeNames["http://www.springframework.net/tx"] = "Spring.Transaction.Config.TxNamespaceParser, Spring.Data";
wellknownNamespaceParserTypeNames["http://www.springframework.net/aop"] = "Spring.Aop.Config.AopNamespaceParser, Spring.Aop";
wellknownNamespaceParserTypeNames["http://www.springframework.net/db"] = "Spring.Data.Config.DatabaseNamespaceParser, Spring.Data";
wellknownNamespaceParserTypeNames["http://www.springframework.net/remoting"] = "Spring.Remoting.Config.RemotingNamespaceParser, Spring.Services";
wellknownNamespaceParserTypeNames["http://www.springframework.net/nms"] = "Spring.Messaging.Nms.Config.NmsNamespaceParser, Spring.Messaging.Nms";
wellknownNamespaceParserTypeNames["http://www.springframework.net/validation"] = "Spring.Validation.Config.ValidationNamespaceParser, Spring.Core";
Reset();
}
/// <summary>
@@ -117,9 +118,9 @@ namespace Spring.Objects.Factory.Xml
/// <remarks>use for unit tests only</remarks>
public static void Reset()
{
//TODO - externalize default list of parsers.
RegisterParser(new ObjectsNamespaceParser());
// register custom config parsers
//TODO - externalize default list of parsers.
RegisterParser(new ObjectsNamespaceParser());
// register custom config parsers
ConfigurationUtils.GetSection(ConfigParsersSectionName);
}
@@ -133,7 +134,7 @@ namespace Spring.Objects.Factory.Xml
if (wellknownNamespaceParserTypeNames.Contains(namespaceUri))
{
string parserTypeName = (string) wellknownNamespaceParserTypeNames[namespaceUri];
string parserTypeName = (string)wellknownNamespaceParserTypeNames[namespaceUri];
// assume, that all Spring.XXX assemblies have same version + public key
// get the ", Version=x.x.x.x, Culture=neutral, PublicKeyToken=65e474d141e25e07" part of Spring.Core and append it
string name = typeof(NamespaceParserRegistry).Assembly.GetName().Name;
@@ -152,195 +153,231 @@ namespace Spring.Objects.Factory.Xml
/// Constructs a "assembly://..." qualified schemaLocation url using the given type
/// to obtain the assembly name.
/// </summary>
public static string GetAssemblySchemaLocation( Type schemaLocationAssemblyHint, string schemaLocation)
public static string GetAssemblySchemaLocation(Type schemaLocationAssemblyHint, string schemaLocation)
{
if (schemaLocationAssemblyHint != null)
{
return "assembly://" + schemaLocationAssemblyHint.Assembly.FullName + schemaLocation;
}
return schemaLocation;
}
/// <summary>
/// Returns a parser for the given namespace.
/// </summary>
/// <param name="namespaceURI">
/// The namespace for which to lookup the parser implementation.
/// </param>
/// <returns>
/// A parser for a given <paramref name="namespaceURI"/>, or
/// <see langword="null"/> if no parser was found.
/// </returns>
public static INamespaceParser GetParser(string namespaceURI)
{
INamespaceParser parser = (INamespaceParser) parsers[namespaceURI];
if (parser == null)
if (schemaLocationAssemblyHint != null)
{
return "assembly://" + schemaLocationAssemblyHint.Assembly.FullName + schemaLocation;
}
return schemaLocation;
}
/// <summary>
/// Returns a parser for the given namespace.
/// </summary>
/// <param name="namespaceURI">
/// The namespace for which to lookup the parser implementation.
/// </param>
/// <returns>
/// A parser for a given <paramref name="namespaceURI"/>, or
/// <see langword="null"/> if no parser was found.
/// </returns>
public static INamespaceParser GetParser(string namespaceURI)
{
INamespaceParser parser = (INamespaceParser)parsers[namespaceURI];
if (parser == null)
{
bool ok = RegisterWellknownNamespaceParserType(namespaceURI);
if (ok)
{
parser = (INamespaceParser) parsers[namespaceURI];
parser = (INamespaceParser)parsers[namespaceURI];
}
}
return parser;
}
/// <summary>
/// Returns a schema collection containing validation schemas for all registered parsers.
/// </summary>
/// <returns>
/// A schema collection containing validation schemas for all registered parsers.
/// </returns>
}
return parser;
}
/// <summary>
/// Returns a schema collection containing validation schemas for all registered parsers.
/// </summary>
/// <returns>
/// A schema collection containing validation schemas for all registered parsers.
/// </returns>
#if !NET_2_0
public static XmlSchemaCollection GetSchemas()
#else
public static XmlSchemaSet GetSchemas()
#endif
{
return schemas;
}
/// <summary>
/// Pegisters parser, using default namespace and schema location
/// as defined by the <see cref="NamespaceParserAttribute"/>.
/// </summary>
/// <param name="parserType">
/// The <see cref="System.Type"/> of the parser that will be activated
/// when an element in its default namespace is encountered.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If <paramref name="parserType"/> is <see langword="null"/>.
/// </exception>
public static void RegisterParser(Type parserType)
{
RegisterParser(parserType, null, null);
}
/// <summary>
/// Associates a parser with a namespace.
/// </summary>
/// <remarks>
/// <note>
/// Parsers registered with the same <paramref name="namespaceUri"/> as that
/// of a parser that has previously been registered will overwrite the existing
/// parser.
/// </note>
/// </remarks>
/// <param name="parserType">
/// The <see cref="System.Type"/> of the parser that will be activated
/// when the attendant <paramref name="namespaceUri"/> is
/// encountered.
/// </param>
/// <param name="namespaceUri">
/// The namespace with which to associate instance of the parser.
/// </param>
/// <param name="schemaLocation">
/// The location of the XML schema that should be used for validation
/// of the XML elements that belong to the specified namespace
/// (can be any valid Spring.NET resource URI).
/// </param>
/// <exception cref="System.ArgumentException">
/// If the <paramref name="parserType"/> is not a <see cref="System.Type"/>
/// that implements the <see cref="INamespaceParser"/>
/// interface.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// If <paramref name="parserType"/> is <see langword="null"/>.
/// </exception>
public static void RegisterParser(Type parserType, string namespaceUri, string schemaLocation)
{
AssertUtils.ArgumentNotNull(parserType, "parserType");
if (!(typeof(INamespaceParser)).IsAssignableFrom(parserType))
{
throw new ArgumentException(string.Format("The [{0}] Type must implement the IXmlObjectDefinitionParser interface.",
parserType.Name), "parserType");
}
RegisterParser((INamespaceParser) ObjectUtils.InstantiateType(parserType), namespaceUri, schemaLocation);
}
/// <summary>
/// Pegisters parser, using default namespace and schema location
/// as defined by the <see cref="NamespaceParserAttribute"/>.
/// </summary>
/// <param name="parser">
/// The parser instance.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If <paramref name="parser"/> is <see langword="null"/>.
/// </exception>
public static void RegisterParser(INamespaceParser parser)
{
RegisterParser(parser, null, null);
}
/// <summary>
/// Associates a parser with a namespace.
/// </summary>
/// <remarks>
/// <note>
/// Parsers registered with the same <paramref name="namespaceUri"/> as that
/// of a parser that has previously been registered will overwrite the existing
/// parser.
/// </note>
/// </remarks>
/// <param name="namespaceUri">
/// The namespace with which to associate instance of the parser.
/// </param>
/// <param name="parser">
/// The parser instance.
/// </param>
/// <param name="schemaLocation">
/// The location of the XML schema that should be used for validation
/// of the XML elements that belong to the specified namespace
/// (can be any valid Spring.NET resource URI).
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If <paramref name="parser"/> is <see langword="null"/>, or if
/// <paramref name="namespaceUri"/> is not specified and parser class
/// does not have default value defined using <see cref="NamespaceParserAttribute"/>.
/// </exception>
public static void RegisterParser(INamespaceParser parser, string namespaceUri, string schemaLocation)
{
AssertUtils.ArgumentNotNull(parser, "parser");
// determine and use defaults for the namespace and schema location, if necessary
if (StringUtils.IsNullOrEmpty(namespaceUri) || StringUtils.IsNullOrEmpty(schemaLocation))
{
NamespaceParserAttribute defaults = GetDefaults(parser);
if (defaults == null)
{
throw new ArgumentNullException(
"Either default or an explicit namespace value must be specified for a configuration parser.");
}
if (StringUtils.IsNullOrEmpty(namespaceUri))
{
namespaceUri = defaults.Namespace;
}
if (StringUtils.IsNullOrEmpty(schemaLocation))
{
schemaLocation = defaults.SchemaLocation;
if (defaults.SchemaLocationAssemblyHint != null)
#else
public static XmlSchemaSet GetSchemas()
#endif
{
return schemas;
}
/// <summary>
/// Pegisters parser, using default namespace and schema location
/// as defined by the <see cref="NamespaceParserAttribute"/>.
/// </summary>
/// <param name="parserType">
/// The <see cref="System.Type"/> of the parser that will be activated
/// when an element in its default namespace is encountered.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If <paramref name="parserType"/> is <see langword="null"/>.
/// </exception>
public static void RegisterParser(Type parserType)
{
RegisterParser(parserType, null, null);
}
/// <summary>
/// Associates a parser with a namespace.
/// </summary>
/// <remarks>
/// <note>
/// Parsers registered with the same <paramref name="namespaceUri"/> as that
/// of a parser that has previously been registered will overwrite the existing
/// parser.
/// </note>
/// </remarks>
/// <param name="parserType">
/// The <see cref="System.Type"/> of the parser that will be activated
/// when the attendant <paramref name="namespaceUri"/> is
/// encountered.
/// </param>
/// <param name="namespaceUri">
/// The namespace with which to associate instance of the parser.
/// </param>
/// <param name="schemaLocation">
/// The location of the XML schema that should be used for validation
/// of the XML elements that belong to the specified namespace
/// (can be any valid Spring.NET resource URI).
/// </param>
/// <exception cref="System.ArgumentException">
/// If the <paramref name="parserType"/> is not a <see cref="System.Type"/>
/// that implements the <see cref="INamespaceParser"/>
/// interface.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// If <paramref name="parserType"/> is <see langword="null"/>.
/// </exception>
public static void RegisterParser(Type parserType, string namespaceUri, string schemaLocation)
{
AssertUtils.ArgumentNotNull(parserType, "parserType");
INamespaceParser np = null;
if ((typeof(INamespaceParser)).IsAssignableFrom(parserType))
{
np = (INamespaceParser)ObjectUtils.InstantiateType(parserType);
}
// TODO (EE): workaround to enable smooth transition between 1.x and 2.0 style namespace handling
else if (typeof(IObjectDefinitionParser).IsAssignableFrom(parserType))
{
// determine and use defaults for the namespace and schema location, if necessary
if (StringUtils.IsNullOrEmpty(namespaceUri) || StringUtils.IsNullOrEmpty(schemaLocation))
{
NamespaceParserAttribute defaults = GetDefaults(parserType);
if (defaults == null)
{
throw new ArgumentNullException(
"Either default or an explicit namespace value must be specified for a configuration parser.");
}
if (StringUtils.IsNullOrEmpty(namespaceUri))
{
namespaceUri = defaults.Namespace;
}
if (StringUtils.IsNullOrEmpty(schemaLocation))
{
schemaLocation = defaults.SchemaLocation;
if (defaults.SchemaLocationAssemblyHint != null)
{
schemaLocation = GetAssemblySchemaLocation(defaults.SchemaLocationAssemblyHint, schemaLocation);
}
}
}
IObjectDefinitionParser odParser = (IObjectDefinitionParser)ObjectUtils.InstantiateType(parserType);
np = new ObjectDefinitionParserNamespaceParser(odParser);
}
else
{
throw new ArgumentException(
string.Format("The [{0}] Type must implement the INamespaceParser interface.", parserType.Name)
, "parserType");
}
RegisterParser(np, namespaceUri, schemaLocation);
}
/// <summary>
/// Pegisters parser, using default namespace and schema location
/// as defined by the <see cref="NamespaceParserAttribute"/>.
/// </summary>
/// <param name="parser">
/// The parser instance.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If <paramref name="parser"/> is <see langword="null"/>.
/// </exception>
public static void RegisterParser(INamespaceParser parser)
{
RegisterParser(parser, null, null);
}
/// <summary>
/// Associates a parser with a namespace.
/// </summary>
/// <remarks>
/// <note>
/// Parsers registered with the same <paramref name="namespaceUri"/> as that
/// of a parser that has previously been registered will overwrite the existing
/// parser.
/// </note>
/// </remarks>
/// <param name="namespaceUri">
/// The namespace with which to associate instance of the parser.
/// </param>
/// <param name="parser">
/// The parser instance.
/// </param>
/// <param name="schemaLocation">
/// The location of the XML schema that should be used for validation
/// of the XML elements that belong to the specified namespace
/// (can be any valid Spring.NET resource URI).
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If <paramref name="parser"/> is <see langword="null"/>, or if
/// <paramref name="namespaceUri"/> is not specified and parser class
/// does not have default value defined using <see cref="NamespaceParserAttribute"/>.
/// </exception>
public static void RegisterParser(INamespaceParser parser, string namespaceUri, string schemaLocation)
{
AssertUtils.ArgumentNotNull(parser, "parser");
// determine and use defaults for the namespace and schema location, if necessary
if (StringUtils.IsNullOrEmpty(namespaceUri) || StringUtils.IsNullOrEmpty(schemaLocation))
{
NamespaceParserAttribute defaults = GetDefaults(parser.GetType());
if (defaults == null)
{
throw new ArgumentNullException(
"Either default or an explicit namespace value must be specified for a configuration parser.");
}
if (StringUtils.IsNullOrEmpty(namespaceUri))
{
namespaceUri = defaults.Namespace;
}
if (StringUtils.IsNullOrEmpty(schemaLocation))
{
schemaLocation = defaults.SchemaLocation;
if (defaults.SchemaLocationAssemblyHint != null)
{
schemaLocation = GetAssemblySchemaLocation(defaults.SchemaLocationAssemblyHint, schemaLocation);
}
}
}
// initialize the parser
parser.Init();
// register parser
lock (parsers.SyncRoot)
lock (schemas)
{
parsers[namespaceUri] = parser;
if (StringUtils.HasText(schemaLocation) && !schemas.Contains(namespaceUri))
{
RegisterSchema(namespaceUri, schemaLocation);
}
}
}
}
}
// initialize the parser
parser.Init();
// register parser
lock (parsers.SyncRoot)
lock (schemas)
{
parsers[namespaceUri] = parser;
if (StringUtils.HasText(schemaLocation) && !schemas.Contains(namespaceUri))
{
RegisterSchema(namespaceUri, schemaLocation);
}
}
}
/// <summary>
@@ -350,46 +387,79 @@ namespace Spring.Objects.Factory.Xml
/// <param name="schemaLocation"></param>
private static void RegisterSchema(string namespaceUri, string schemaLocation)
{
IResourceLoader resourceLoader = new ConfigurableResourceLoader();
IResource schema = resourceLoader.GetResource(schemaLocation);
IResourceLoader resourceLoader = new ConfigurableResourceLoader();
IResource schema = resourceLoader.GetResource(schemaLocation);
try
{
{
#if NET_1_0
XmlTextReader schemaDocument = new XmlTextReader(schemaLocation, schema.InputStream);
schemas.Add(namespaceUri, schemaDocument);
#elif NET_1_1
XmlTextReader schemaDocument = new XmlTextReader(schemaLocation, schema.InputStream);
schemas.Add(namespaceUri, schemaDocument, new XmlResourceUrlResolver());
#else
#else
XmlTextReader schemaDocument = new XmlTextReader(schema.Uri.AbsoluteUri, schema.InputStream);
schemas.Add(namespaceUri, schemaDocument);
#endif
schemas.Add(namespaceUri, schemaDocument);
#endif
}
catch (Exception e)
{
throw new ArgumentException("Could not load schema from resource = " + schema, e);
catch (Exception e)
{
throw new ArgumentException("Could not load schema from resource = " + schema, e);
}
}
/// <summary>
/// Returns default values for the parser namespace and schema location as
/// defined by the <see cref="NamespaceParserAttribute"/>.
/// </summary>
/// <param name="parser">
/// A parser instance.
/// </param>
/// <returns>
/// A <see cref="NamespaceParserAttribute"/> instance containing
/// default values for the parser namsepace and schema location
/// </returns>
private static NamespaceParserAttribute GetDefaults(INamespaceParser parser)
{
object[] attrs = parser.GetType().GetCustomAttributes(typeof(NamespaceParserAttribute), true);
if (attrs.Length > 0)
{
return (NamespaceParserAttribute)attrs[0];
}
return null;
}
}
}
/// <summary>
/// Returns default values for the parser namespace and schema location as
/// defined by the <see cref="NamespaceParserAttribute"/>.
/// </summary>
/// <param name="parserType">
/// A type of the parser.
/// </param>
/// <returns>
/// A <see cref="NamespaceParserAttribute"/> instance containing
/// default values for the parser namsepace and schema location
/// </returns>
private static NamespaceParserAttribute GetDefaults(Type parserType)
{
object[] attrs = parserType.GetCustomAttributes(typeof(NamespaceParserAttribute), true);
if (attrs.Length > 0)
{
return (NamespaceParserAttribute)attrs[0];
}
return null;
}
#region ObjectDefinitionParserNamespaceParser Utility class
/// <summary>
/// Adapts the <see cref="IObjectDefinitionParser"/> interface to <see cref="INamespaceParser"/>.
/// Only for smooth transition between 1.x and 2.0 style namespace handling, will be dropped for 2.0
/// </summary>
private class ObjectDefinitionParserNamespaceParser : INamespaceParser
{
private readonly IObjectDefinitionParser odParser;
public ObjectDefinitionParserNamespaceParser(IObjectDefinitionParser odParser)
{
this.odParser = odParser;
}
public void Init()
{
// noop
}
public IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext)
{
return odParser.ParseElement(element, parserContext);
}
public ObjectDefinitionHolder Decorate(XmlNode node, ObjectDefinitionHolder definition, ParserContext parserContext)
{
return null;
}
}
#endregion
}
}

View File

@@ -108,7 +108,7 @@ namespace Spring.Objects.Factory.Xml
/// and was called to process the root node.
/// </p>
/// </remarks>
[Obsolete("not used anymore - ObjectsNamespaceParser will be dropped with 2.x, use ObjectDefinitionParserHelper instead", false)]
// [Obsolete("not used anymore - ObjectsNamespaceParser will be dropped with 2.x, use ObjectDefinitionParserHelper instead", false)]
public override IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext)
{
// TODO (EE): overridden just to stay binary compatible between 1.2.0 and 1.2.1

View File

@@ -1,7 +1,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{710961A3-0DF4-49E4-A26E-F5B9C044AC84}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -588,6 +588,7 @@
<Compile Include="Objects\Factory\Config\VariableAccessor.cs" />
<Compile Include="Objects\Factory\Config\VariablePlaceholderConfigurer.cs" />
<Compile Include="Objects\Factory\Parsing\ReaderContext.cs" />
<Compile Include="Objects\Factory\Support\GenericObjectDefinition.cs" />
<Compile Include="Objects\Factory\Support\IAutowireCandidateResolver.cs" />
<Compile Include="Objects\Factory\Support\ConstructorResolver.cs" />
<Compile Include="Objects\Factory\Support\DefaultObjectNameGenerator.cs" />

View File

@@ -45,7 +45,7 @@ namespace Spring.Validation.Config
/// <author>Aleksandar Seovic</author>
[
NamespaceParser(
Namespace = "http://www.springframework.net/validation",
Namespace = "http://www.springframework.net/validation",
SchemaLocationAssemblyHint = typeof(ValidationNamespaceParser),
SchemaLocation = "/Spring.Validation.Config/spring-validation-1.1.xsd")
]
@@ -55,15 +55,13 @@ namespace Spring.Validation.Config
[ThreadStatic]
private int definitionCount = 0;
static ValidationNamespaceParser()
{
TypeRegistry.RegisterType(ValidatorTypePrefix + "group", typeof(ValidatorGroup));
TypeRegistry.RegisterType(ValidatorTypePrefix + "any", typeof(AnyValidatorGroup));
TypeRegistry.RegisterType(ValidatorTypePrefix + "exclusive", typeof(ExclusiveValidatorGroup));
TypeRegistry.RegisterType(ValidatorTypePrefix + "collection", typeof(CollectionValidator));
TypeRegistry.RegisterType(ValidatorTypePrefix + "collection", typeof(CollectionValidator));
TypeRegistry.RegisterType(ValidatorTypePrefix + "required", typeof(RequiredValidator));
TypeRegistry.RegisterType(ValidatorTypePrefix + "condition", typeof(ConditionValidator));
TypeRegistry.RegisterType(ValidatorTypePrefix + "regex", typeof(RegularExpressionValidator));
@@ -98,7 +96,6 @@ namespace Spring.Validation.Config
/// be used in a nested scenario.
/// </para>
/// </remarks>
[Obsolete("not used anymore - ObjectsNamespaceParser will be dropped with 2.x, use ObjectDefinitionParserHelper instead", false)]
public override IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext)
{
if (!element.HasAttribute("id"))
@@ -129,7 +126,7 @@ namespace Spring.Validation.Config
string validateAll = GetAttributeValue(element, ValidatorDefinitionConstants.CollectionValidateAllAttribute);
string context = GetAttributeValue(element, ValidatorDefinitionConstants.CollectionContextAttribute);
string includeElementsErrors = GetAttributeValue(element, ValidatorDefinitionConstants.CollectionIncludeElementsErrors);
string name = "validator: " + (StringUtils.HasText(id) ? id : this.definitionCount.ToString());
MutablePropertyValues properties = new MutablePropertyValues();
if (StringUtils.HasText(test))
@@ -152,11 +149,11 @@ namespace Spring.Validation.Config
{
properties.Add("IncludeElementErrors", includeElementsErrors);
}
ManagedList nestedValidators = new ManagedList();
ManagedList actions = new ManagedList();
foreach (XmlNode node in element.ChildNodes)
foreach (XmlNode node in element.ChildNodes)
{
XmlElement child = node as XmlElement;
if (child != null)
@@ -272,7 +269,7 @@ namespace Spring.Validation.Config
{
properties.Add("Parameters", parameters.ToArray(typeof(IExpression)));
}
IConfigurableObjectDefinition action =
parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(typeName, null, parserContext.ReaderContext.Reader.Domain);
action.ConstructorArgumentValues = ctorArgs;
@@ -315,7 +312,7 @@ namespace Spring.Validation.Config
string typeName = "Spring.Validation.ValidatorReference, Spring.Core";
string name = GetAttributeValue(element, ValidatorDefinitionConstants.ReferenceNameAttribute);
string context = GetAttributeValue(element, ValidatorDefinitionConstants.ReferenceContextAttribute);
MutablePropertyValues properties = new MutablePropertyValues();
properties.Add("Name", name);
if (StringUtils.HasText(context))
@@ -328,7 +325,7 @@ namespace Spring.Validation.Config
reference.PropertyValues = properties;
return reference;
}
#region Element & Attribute Name Constants
private class ValidatorDefinitionConstants
@@ -350,7 +347,7 @@ namespace Spring.Validation.Config
public const string CollectionValidateAllAttribute = "validate-all";
public const string CollectionContextAttribute = "context";
public const string CollectionIncludeElementsErrors = "include-element-errors";
public const string CollectionIncludeElementsErrors = "include-element-errors";
}
private class MessageConstants

View File

@@ -20,6 +20,7 @@
#region Imports
using System;
using System.Globalization;
using System.Xml;
@@ -45,7 +46,7 @@ namespace Spring.Data.Config
SchemaLocationAssemblyHint = typeof(DatabaseNamespaceParser),
SchemaLocation = "/Spring.Data.Config/spring-database-1.1.xsd")
]
public class DatabaseNamespaceParser : ObjectsNamespaceParser
public class DatabaseNamespaceParser : AbstractSingleObjectDefinitionParser
{
private const string DatabaseTypePrefix = "database: ";
@@ -64,101 +65,124 @@ namespace Spring.Data.Config
{
}
/// <summary>
/// Parse the specified element and register any resulting
/// IObjectDefinitions with the IObjectDefinitionRegistry that is
/// embedded in the supplied ParserContext.
/// </summary>
/// <param name="element">The element to be parsed into one or more IObjectDefinitions</param>
/// <param name="parserContext">The object encapsulating the current state of the parsing
/// process.</param>
/// <returns>
/// The primary IObjectDefinition (can be null as explained above)
/// </returns>
/// <remarks>
/// Implementations should return the primary IObjectDefinition
/// that results from the parse phase if they wish to used nested
/// inside (for example) a <code>&lt;property&gt;</code> tag.
/// <para>Implementations may return null if they will not
/// be used in a nested scenario.
/// </para>
/// </remarks>
public override IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext)
// /// <summary>
// /// Parse the specified element and register any resulting
// /// IObjectDefinitions with the IObjectDefinitionRegistry that is
// /// embedded in the supplied ParserContext.
// /// </summary>
// /// <param name="element">The element to be parsed into one or more IObjectDefinitions</param>
// /// <param name="parserContext">The object encapsulating the current state of the parsing
// /// process.</param>
// /// <returns>
// /// The primary IObjectDefinition (can be null as explained above)
// /// </returns>
// /// <remarks>
// /// Implementations should return the primary IObjectDefinition
// /// that results from the parse phase if they wish to used nested
// /// inside (for example) a <code>&lt;property&gt;</code> tag.
// /// <para>Implementations may return null if they will not
// /// be used in a nested scenario.
// /// </para>
// /// </remarks>
// [Obsolete("not used anymore - ObjectsNamespaceParser will be dropped with 2.x, use ObjectDefinitionParserHelper instead", false)]
// public override IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext)
// {
// string id = GetAttributeValue(element, ObjectDefinitionConstants.IdAttribute);
// IConfigurableObjectDefinition databaseConfiguration = ParseDatabaseDefinition(element, id, parserContext);
// if (!StringUtils.HasText(id))
// {
// id = ObjectDefinitionReaderUtils.GenerateObjectName(databaseConfiguration, parserContext.Registry);
// }
// #region Instrumentation
//
// if (log.IsDebugEnabled)
// {
// log.Debug(
// string.Format(
// CultureInfo.InvariantCulture,
// "Registering object definition with id '{0}'.", id));
// }
//
// #endregion
// parserContext.Registry.RegisterObjectDefinition(id, databaseConfiguration);
//
// return null;
// }
protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
{
string id = GetAttributeValue(element, ObjectDefinitionConstants.IdAttribute);
IConfigurableObjectDefinition databaseConfiguration = ParseDatabaseDefinition(element, id, parserContext);
if (!StringUtils.HasText(id))
{
id = ObjectDefinitionReaderUtils.GenerateObjectName(databaseConfiguration, parserContext.Registry);
}
#region Instrumentation
if (log.IsDebugEnabled)
{
log.Debug(
string.Format(
CultureInfo.InvariantCulture,
"Registering object definition with id '{0}'.", id));
}
#endregion
parserContext.Registry.RegisterObjectDefinition(id, databaseConfiguration);
return null;
// base.DoParse(element, parserContext, builder);
switch (element.LocalName)
{
case DbProviderFactoryObjectConstants.DbProviderFactoryObjectElement:
{
ParseDatabaseConfigurer(element, parserContext, builder);
return;
}
}
}
private IConfigurableObjectDefinition ParseDatabaseDefinition(XmlElement element, string name, ParserContext parserContext)
{
switch (element.LocalName)
{
case DbProviderFactoryObjectConstants.DbProviderFactoryObjectElement:
return ParseDatabaseConfigurer(element, name, parserContext);
}
return null;
}
// private IConfigurableObjectDefinition ParseDatabaseDefinition(XmlElement element, string name, ParserContext parserContext)
// {
// switch (element.LocalName)
// {
// case DbProviderFactoryObjectConstants.DbProviderFactoryObjectElement:
// return ParseDatabaseConfigurer(element, name, parserContext);
// }
// return null;
// }
private IConfigurableObjectDefinition ParseDatabaseConfigurer(XmlElement element, string name, ParserContext parserContext)
private void ParseDatabaseConfigurer(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
{
string typeName = GetTypeName(element);
// string typeName = GetTypeName(element);
string providerNameAttribute = GetAttributeValue(element, DbProviderFactoryObjectConstants.ProviderNameAttribute);
string connectionString = GetAttributeValue(element, DbProviderFactoryObjectConstants.ConnectionStringAttribute);
MutablePropertyValues properties = new MutablePropertyValues();
// MutablePropertyValues properties = new MutablePropertyValues();
if (StringUtils.HasText(providerNameAttribute))
{
properties.Add("Provider", providerNameAttribute);
{
builder.AddPropertyValue("Provider", providerNameAttribute);
// properties.Add("Provider", providerNameAttribute);
}
if (StringUtils.HasText(connectionString))
{
properties.Add("ConnectionString", connectionString);
{
builder.AddPropertyValue("ConnectionString", connectionString);
// properties.Add("ConnectionString", connectionString);
}
IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(
typeName, null, parserContext.ReaderContext.Reader.Domain);
cod.PropertyValues = properties;
// IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(
// typeName, null, parserContext.ReaderContext.Reader.Domain);
// cod.PropertyValues = properties;
return cod;
}
/// <summary>
/// Gets the name of the object type for the specified element. This has already been aliased
/// in the static constructor.
/// </summary>
/// <param name="element">The element.</param>
/// <returns>The name of the object type.</returns>
private string GetTypeName(XmlElement element)
// return builder.ObjectDefinition;
}
protected override string GetObjectTypeName(XmlElement element)
{
string typeName = GetAttributeValue(element, ObjectDefinitionConstants.TypeAttribute);
if (StringUtils.IsNullOrEmpty(typeName))
{
return DatabaseTypePrefix + element.LocalName;
}
return typeName;
string typeName = GetAttributeValue(element, ObjectDefinitionConstants.TypeAttribute);
if (StringUtils.IsNullOrEmpty(typeName))
{
return DatabaseTypePrefix + element.LocalName;
}
return typeName;
}
// /// <summary>
// /// Gets the name of the object type for the specified element. This has already been aliased
// /// in the static constructor.
// /// </summary>
// /// <param name="element">The element.</param>
// /// <returns>The name of the object type.</returns>
// private string GetTypeName(XmlElement element)
// {
// string typeName = GetAttributeValue(element, ObjectDefinitionConstants.TypeAttribute);
// if (StringUtils.IsNullOrEmpty(typeName))
// {
// return DatabaseTypePrefix + element.LocalName;
// }
// return typeName;
// }
private class DbProviderFactoryObjectConstants
{
public const string DbProviderFactoryObjectElement = "provider";

View File

@@ -38,7 +38,7 @@ namespace Spring.Objects.Factory.Support
/// <author>Aleksandar Seovic</author>
public class ChildWebObjectDefinition : ChildObjectDefinition, IWebObjectDefinition
{
private ObjectScope _scope = ObjectScope.Default;
// private ObjectScope _scope = ObjectScope.Default;
private string _pageName;
#region Constructors
@@ -101,10 +101,10 @@ namespace Spring.Objects.Factory.Support
/// <summary>
/// Object scope.
/// </summary>
public ObjectScope Scope
ObjectScope IWebObjectDefinition.Scope
{
get { return _scope; }
set { _scope = value; }
get { return (ObjectScope)Enum.Parse(typeof(ObjectScope), this.Scope, true); }
set { this.Scope = value.ToString(); }
}
/// <summary>
@@ -134,6 +134,12 @@ namespace Spring.Objects.Factory.Support
{
return false;
}
else if (0 == string.Compare("application", this.Scope, true)
|| 0 == string.Compare("session", this.Scope, true)
|| 0 == string.Compare("request", this.Scope, true))
{
return true;
}
else
{
return base.IsSingleton;
@@ -142,6 +148,20 @@ namespace Spring.Objects.Factory.Support
set { base.IsSingleton = value; }
}
/// <summary>
/// Overrides this object's values using values from <c>other</c> argument.
/// </summary>
/// <param name="other">The object to copy values from.</param>
public override void OverrideFrom(IObjectDefinition other)
{
base.OverrideFrom(other);
if (other is IWebObjectDefinition)
{
// this._scope = ((IWebObjectDefinition) other).Scope;
this._pageName = ((IWebObjectDefinition)other).PageName;
}
}
/// <summary>
/// A <see cref="System.String"/> that represents the current
/// <see cref="System.Object"/>.

View File

@@ -42,7 +42,7 @@ namespace Spring.Objects.Factory.Support
/// <author>Aleksandar Seovic</author>
public class RootWebObjectDefinition : RootObjectDefinition, IWebObjectDefinition
{
private ObjectScope _scope = ObjectScope.Default;
// private ObjectScope _scope = ObjectScope.Default;
private string _pageName;
#region Constructors
@@ -135,7 +135,7 @@ namespace Spring.Objects.Factory.Support
{
if (other is IWebObjectDefinition)
{
this._scope = ((IWebObjectDefinition) other).Scope;
// this._scope = ((IWebObjectDefinition) other).Scope;
this._pageName = ((IWebObjectDefinition) other).PageName;
}
}
@@ -145,10 +145,10 @@ namespace Spring.Objects.Factory.Support
/// <summary>
/// Object scope.
/// </summary>
public ObjectScope Scope
ObjectScope IWebObjectDefinition.Scope
{
get { return _scope; }
set { _scope = value; }
get { return (ObjectScope) Enum.Parse(typeof(ObjectScope), base.Scope, true); }
set { base.Scope = value.ToString(); }
}
/// <summary>
@@ -178,6 +178,12 @@ namespace Spring.Objects.Factory.Support
{
return false;
}
else if (0 == string.Compare("application", this.Scope, true)
|| 0 == string.Compare("session", this.Scope, true)
|| 0 == string.Compare("request", this.Scope, true))
{
return true;
}
else
{
return base.IsSingleton;
@@ -195,7 +201,7 @@ namespace Spring.Objects.Factory.Support
base.OverrideFrom(other);
if (other is IWebObjectDefinition)
{
this._scope = ((IWebObjectDefinition) other).Scope;
// this._scope = ((IWebObjectDefinition) other).Scope;
this._pageName = ((IWebObjectDefinition) other).PageName;
}
}

View File

@@ -503,12 +503,12 @@ namespace Spring.Objects.Factory
((AbstractObjectFactory) ObjectFactory).RegisterAlias("rick", Environment.NewLine);
}
[Test]
[ExpectedException(typeof(ObjectDefinitionStoreException))]
public void ChokesIfNotGivenSupportedIObjectDefinitionImplementation()
{
ObjectFactory.GetObject("unsupportedDefinition");
}
// [Test]
// [ExpectedException(typeof(ObjectDefinitionStoreException))]
// public void ChokesIfNotGivenSupportedIObjectDefinitionImplementation()
// {
// ObjectFactory.GetObject("unsupportedDefinition");
// }
#endregion
}

View File

@@ -71,6 +71,18 @@ namespace Spring.Objects.Factory
get { throw new NotImplementedException(); }
}
public string ParentName
{
get { return null; }
set { throw new NotImplementedException(); }
}
public string Scope
{
get { throw new System.NotImplementedException(); }
set { throw new System.NotImplementedException(); }
}
public Type ObjectType
{
get { throw new NotImplementedException(); }

View File

@@ -50,15 +50,15 @@ namespace Spring.Objects.Factory.Support
}
rwod = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues());
rwod.Scope = ObjectScope.Application;
rwod.Scope = ObjectScope.Application.ToString();
wof.RegisterObjectDefinition("applicationScopedObject", rwod);
rwod = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues());
rwod.Scope = ObjectScope.Request;
rwod.Scope = ObjectScope.Request.ToString();
wof.RegisterObjectDefinition("requestScopedObject", rwod);
rwod = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues());
rwod.Scope = ObjectScope.Session;
rwod.Scope = ObjectScope.Session.ToString();
wof.RegisterObjectDefinition("sessionScopedObject", rwod);
object o;