From 587964d20efab5079a4ba1dedb02eedf0575befa Mon Sep 17 00:00:00 2001
From: eeichinger
Date: Tue, 3 Mar 2009 02:48:35 +0000
Subject: [PATCH] further refactoring towards Spring/J 2.5 codebase to better
support new extension projects (SPRNET-929)
---
.../Factory/Config/IObjectDefinition.cs | 10 +
.../Support/AbstractObjectDefinition.cs | 41 +-
.../Factory/Support/AbstractObjectFactory.cs | 53 +-
.../Factory/Support/ChildObjectDefinition.cs | 7 +-
.../Support/GenericObjectDefinition.cs | 110 +++
.../Support/ObjectDefinitionBuilder.cs | 33 +
.../Factory/Support/RootObjectDefinition.cs | 25 +-
.../Xml/AbstractObjectDefinitionParser.cs | 4 +-
.../AbstractSingleObjectDefinitionParser.cs | 41 +-
.../Factory/Xml/NamespaceParserRegistry.cs | 650 ++++++++++--------
.../Factory/Xml/ObjectsNamespaceParser.cs | 2 +-
.../Spring.Core/Spring.Core.2008.csproj | 3 +-
.../Config/ValidationNamespaceParser.cs | 23 +-
.../Data/Config/DatabaseNamespaceParser.cs | 182 ++---
.../Support/ChildWebObjectDefinition.cs | 28 +-
.../Support/RootWebObjectDefinition.cs | 18 +-
.../Factory/AbstractObjectFactoryTests.cs | 12 +-
...supportedObjectDefinitionImplementation.cs | 12 +
.../Factory/Support/WebObjectFactoryTests.cs | 6 +-
19 files changed, 815 insertions(+), 445 deletions(-)
create mode 100644 src/Spring/Spring.Core/Objects/Factory/Support/GenericObjectDefinition.cs
diff --git a/src/Spring/Spring.Core/Objects/Factory/Config/IObjectDefinition.cs b/src/Spring/Spring.Core/Objects/Factory/Config/IObjectDefinition.cs
index a190de8a..5e629e95 100644
--- a/src/Spring/Spring.Core/Objects/Factory/Config/IObjectDefinition.cs
+++ b/src/Spring/Spring.Core/Objects/Factory/Config/IObjectDefinition.cs
@@ -110,6 +110,16 @@ namespace Spring.Objects.Factory.Config
///
bool IsLazyInit { get; }
+ ///
+ /// The name of the parent definition of this object definition, if any.
+ ///
+ string ParentName { get; set; }
+
+ ///
+ /// The target scope for this object.
+ ///
+ string Scope { get; set; }
+
///
/// Returns the of the object definition (if any).
///
diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/AbstractObjectDefinition.cs b/src/Spring/Spring.Core/Objects/Factory/Support/AbstractObjectDefinition.cs
index 45413425..8cad90e7 100644
--- a/src/Spring/Spring.Core/Objects/Factory/Support/AbstractObjectDefinition.cs
+++ b/src/Spring/Spring.Core/Objects/Factory/Support/AbstractObjectDefinition.cs
@@ -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
///
@@ -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
+ ///
+ /// The name of the parent definition of this object definition, if any.
+ ///
+ public abstract string ParentName { get; set; }
+
///
/// 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; }
}
+ ///
+ /// The name of the target scope for the object.
+ /// Defaults to "singleton", ootb alternative is "prototype". Extended object factories
+ /// might support further scopes.
+ ///
+ 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);
+ }
+ }
+
///
/// Is this definition a singleton, 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); }
}
+
///
/// 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
///
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;
diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/AbstractObjectFactory.cs b/src/Spring/Spring.Core/Objects/Factory/Support/AbstractObjectFactory.cs
index 1adbf103..021afdaa 100644
--- a/src/Spring/Spring.Core/Objects/Factory/Support/AbstractObjectFactory.cs
+++ b/src/Spring/Spring.Core/Objects/Factory/Support/AbstractObjectFactory.cs
@@ -526,53 +526,54 @@ namespace Spring.Objects.Factory.Support
/// A merged
/// with overridden properties.
///
- 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
+
///
/// Is this object a singleton?
///
@@ -1987,6 +1990,8 @@ namespace Spring.Objects.Factory.Support
#endregion
+ #endregion
+
///
/// Destroy all cached singletons in this factory.
///
diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/ChildObjectDefinition.cs b/src/Spring/Spring.Core/Objects/Factory/Support/ChildObjectDefinition.cs
index 91b72bf0..d257a871 100644
--- a/src/Spring/Spring.Core/Objects/Factory/Support/ChildObjectDefinition.cs
+++ b/src/Spring/Spring.Core/Objects/Factory/Support/ChildObjectDefinition.cs
@@ -186,16 +186,15 @@ namespace Spring.Objects.Factory.Support
/// The name of the parent object definition.
///
///
- ///
/// This value is required.
- ///
///
///
/// The name of the parent object definition.
///
- public string ParentName
+ public override string ParentName
{
- get { return parentName; }
+ get { return parentName; }
+ set { parentName = value; }
}
#endregion
diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/GenericObjectDefinition.cs b/src/Spring/Spring.Core/Objects/Factory/Support/GenericObjectDefinition.cs
new file mode 100644
index 00000000..2d8aaae4
--- /dev/null
+++ b/src/Spring/Spring.Core/Objects/Factory/Support/GenericObjectDefinition.cs
@@ -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
+{
+ ///
+ /// 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 "parentName" property.
+ ///
+ /// In general, use this class for the purpose of
+ /// registering user-visible object definitions (which a post-processor might operate on,
+ /// potentially even reconfiguring the parent name).
+ /// Use /
+ /// where parent/child relationships happen to be pre-determined.
+ ///
+ ///
+ ///
+ /// Juergen Hoeller
+ /// Erich Eichinger
+ [Serializable]
+ public class GenericObjectDefinition : AbstractObjectDefinition
+ {
+ private string parentName;
+
+ ///
+ /// The name of the parent object definition.
+ ///
+ ///
+ /// This value is required.
+ ///
+ ///
+ /// The name of the parent object definition.
+ ///
+ public override string ParentName
+ {
+ get { return parentName; }
+ set { parentName = value; }
+ }
+
+ ///
+ /// Creates a new to be configured through its
+ /// object properties and configuration methods.
+ ///
+ public GenericObjectDefinition()
+ { }
+
+ ///
+ /// Creates a new as deep copy of the given
+ /// object definition.
+ ///
+ /// the original object definition to copy from
+ 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 */
+// ///
+// /// Checks, if equals this object definition.
+// ///
+// ///
+// ///
+// public override bool Equals(object other)
+// {
+// return object.ReferenceEquals(this, other)
+// || (other is GenericObjectDefinition && base.Equals(obj));
+// }
+//
+// public override int GetHashCode()
+// {
+// return base.GetHashCode();
+// }
+
+ ///
+ /// Returns a representation of this
+ /// for debugging purposes.
+ ///
+ public override string ToString()
+ {
+ return "Generic Object:" + base.ToString();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/ObjectDefinitionBuilder.cs b/src/Spring/Spring.Core/Objects/Factory/Support/ObjectDefinitionBuilder.cs
index 260eed0b..fb811ffc 100644
--- a/src/Spring/Spring.Core/Objects/Factory/Support/ObjectDefinitionBuilder.cs
+++ b/src/Spring/Spring.Core/Objects/Factory/Support/ObjectDefinitionBuilder.cs
@@ -61,6 +61,39 @@ namespace Spring.Objects.Factory.Support
#region Factory Methods
+ ///
+ /// Creates a new used to construct a .
+ ///
+ public static ObjectDefinitionBuilder GenericObjectDefinition()
+ {
+ ObjectDefinitionBuilder builder = new ObjectDefinitionBuilder();
+ builder.objectDefinition = new GenericObjectDefinition();
+ return builder;
+ }
+
+ ///
+ /// Creates a new used to construct a .
+ ///
+ /// the of the object that the definition is being created for
+ public static ObjectDefinitionBuilder GenericObjectDefinition(Type objectType)
+ {
+ ObjectDefinitionBuilder builder = new ObjectDefinitionBuilder();
+ builder.objectDefinition = new GenericObjectDefinition();
+ builder.objectDefinition.ObjectType = objectType;
+ return builder;
+ }
+
+ ///
+ /// Creates a new used to construct a .
+ ///
+ /// the name of the of the object that the definition is being created for
+ public static ObjectDefinitionBuilder GenericObjectDefinition(string objectTypeName)
+ {
+ ObjectDefinitionBuilder builder = new ObjectDefinitionBuilder();
+ builder.objectDefinition = new GenericObjectDefinition();
+ builder.objectDefinition.ObjectTypeName = objectTypeName;
+ return builder;
+ }
///
/// Create a new ObjectDefinitionBuilder used to construct a root object definition.
diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/RootObjectDefinition.cs b/src/Spring/Spring.Core/Objects/Factory/Support/RootObjectDefinition.cs
index 481e3a7f..9263da79 100644
--- a/src/Spring/Spring.Core/Objects/Factory/Support/RootObjectDefinition.cs
+++ b/src/Spring/Spring.Core/Objects/Factory/Support/RootObjectDefinition.cs
@@ -253,7 +253,30 @@ namespace Spring.Objects.Factory.Support
public RootObjectDefinition(IObjectDefinition other) : base(other)
{}
- #endregion
+ #endregion
+
+ ///
+ /// Is always null for a .
+ ///
+ ///
+ /// It is safe to request this property's value. Setting any other value than null will
+ /// raise an .
+ ///
+ /// Raised on any attempt to set a non-null value on this property.
+ 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");
+ }
+ }
+ }
///
/// Validate this object definition.
diff --git a/src/Spring/Spring.Core/Objects/Factory/Xml/AbstractObjectDefinitionParser.cs b/src/Spring/Spring.Core/Objects/Factory/Xml/AbstractObjectDefinitionParser.cs
index 09cfd758..dfb8e516 100644
--- a/src/Spring/Spring.Core/Objects/Factory/Xml/AbstractObjectDefinitionParser.cs
+++ b/src/Spring/Spring.Core/Objects/Factory/Xml/AbstractObjectDefinitionParser.cs
@@ -18,7 +18,9 @@
#endregion
-#region Imports
+#region Imports
+
+using System;
using System.Xml;
using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Support;
diff --git a/src/Spring/Spring.Core/Objects/Factory/Xml/AbstractSingleObjectDefinitionParser.cs b/src/Spring/Spring.Core/Objects/Factory/Xml/AbstractSingleObjectDefinitionParser.cs
index c690bbd7..050d726d 100644
--- a/src/Spring/Spring.Core/Objects/Factory/Xml/AbstractSingleObjectDefinitionParser.cs
+++ b/src/Spring/Spring.Core/Objects/Factory/Xml/AbstractSingleObjectDefinitionParser.cs
@@ -57,18 +57,30 @@ namespace Spring.Objects.Factory.Xml
///
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
}
+ ///
+ /// 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 null
+ /// indicating a root object definition.
+ ///
+ ///
+ /// the name of the parent object for the currently parsed object.
+ protected virtual string GetParentName(XmlElement element)
+ {
+ return null;
+ }
+
///
/// Gets the type of the object corresponding to the supplied XmlElement.
///
diff --git a/src/Spring/Spring.Core/Objects/Factory/Xml/NamespaceParserRegistry.cs b/src/Spring/Spring.Core/Objects/Factory/Xml/NamespaceParserRegistry.cs
index 38a203f9..bc928554 100644
--- a/src/Spring/Spring.Core/Objects/Factory/Xml/NamespaceParserRegistry.cs
+++ b/src/Spring/Spring.Core/Objects/Factory/Xml/NamespaceParserRegistry.cs
@@ -1,5 +1,5 @@
-#region License
-
+#region License
+
/*
* Copyright © 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
-{
- ///
- /// Provides a resolution mechanism for configuration parsers.
- ///
- ///
- ///
- /// The uses this registry
- /// class to find the parser handling a specific namespace.
- ///
- ///
- /// Aleksandar Seovic
- 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
+{
+ ///
+ /// Provides a resolution mechanism for configuration parsers.
+ ///
+ ///
+ ///
+ /// The uses this registry
+ /// class to find the parser handling a specific namespace.
+ ///
+ ///
+ /// Aleksandar Seovic
+ public class NamespaceParserRegistry
+ {
///
/// Resolves xml entities by using the infrastructure.
- ///
+ ///
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);
}
}
- ///
- /// Name of the .Net config section that contains definitions
- /// for custom config parsers.
- ///
- private const string ConfigParsersSectionName = "spring/parsers";
-
- #region Fields
-
- private readonly static IDictionary parsers;
- private readonly static IDictionary wellknownNamespaceParserTypeNames;
-
+ ///
+ /// Name of the .Net config section that contains definitions
+ /// for custom config parsers.
+ ///
+ 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
-
- ///
- /// Creates a new instance of the NamespaceParserRegistry class.
- ///
- static NamespaceParserRegistry()
- {
- parsers = new HybridDictionary();
+#else
+ private readonly static XmlSchemaSet schemas;
+#endif
+
+ #endregion
+
+ ///
+ /// Creates a new instance of the NamespaceParserRegistry class.
+ ///
+ 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();
}
///
@@ -117,9 +118,9 @@ namespace Spring.Objects.Factory.Xml
/// use for unit tests only
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.
///
- 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;
- }
-
- ///
- /// Returns a parser for the given namespace.
- ///
- ///
- /// The namespace for which to lookup the parser implementation.
- ///
- ///
- /// A parser for a given , or
- /// if no parser was found.
- ///
- 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;
+ }
+
+ ///
+ /// Returns a parser for the given namespace.
+ ///
+ ///
+ /// The namespace for which to lookup the parser implementation.
+ ///
+ ///
+ /// A parser for a given , or
+ /// if no parser was found.
+ ///
+ 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;
- }
-
- ///
- /// Returns a schema collection containing validation schemas for all registered parsers.
- ///
- ///
- /// A schema collection containing validation schemas for all registered parsers.
- ///
+ }
+ return parser;
+ }
+
+ ///
+ /// Returns a schema collection containing validation schemas for all registered parsers.
+ ///
+ ///
+ /// A schema collection containing validation schemas for all registered parsers.
+ ///
#if !NET_2_0
public static XmlSchemaCollection GetSchemas()
-#else
- public static XmlSchemaSet GetSchemas()
-#endif
- {
- return schemas;
- }
-
- ///
- /// Pegisters parser, using default namespace and schema location
- /// as defined by the .
- ///
- ///
- /// The of the parser that will be activated
- /// when an element in its default namespace is encountered.
- ///
- ///
- /// If is .
- ///
- public static void RegisterParser(Type parserType)
- {
- RegisterParser(parserType, null, null);
- }
-
- ///
- /// Associates a parser with a namespace.
- ///
- ///
- ///
- /// Parsers registered with the same as that
- /// of a parser that has previously been registered will overwrite the existing
- /// parser.
- ///
- ///
- ///
- /// The of the parser that will be activated
- /// when the attendant is
- /// encountered.
- ///
- ///
- /// The namespace with which to associate instance of the parser.
- ///
- ///
- /// 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).
- ///
- ///
- /// If the is not a
- /// that implements the
- /// interface.
- ///
- ///
- /// If is .
- ///
- 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);
- }
-
- ///
- /// Pegisters parser, using default namespace and schema location
- /// as defined by the .
- ///
- ///
- /// The parser instance.
- ///
- ///
- /// If is .
- ///
- public static void RegisterParser(INamespaceParser parser)
- {
- RegisterParser(parser, null, null);
- }
-
- ///
- /// Associates a parser with a namespace.
- ///
- ///
- ///
- /// Parsers registered with the same as that
- /// of a parser that has previously been registered will overwrite the existing
- /// parser.
- ///
- ///
- ///
- /// The namespace with which to associate instance of the parser.
- ///
- ///
- /// The parser instance.
- ///
- ///
- /// 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).
- ///
- ///
- /// If is , or if
- /// is not specified and parser class
- /// does not have default value defined using .
- ///
- 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;
+ }
+
+ ///
+ /// Pegisters parser, using default namespace and schema location
+ /// as defined by the .
+ ///
+ ///
+ /// The of the parser that will be activated
+ /// when an element in its default namespace is encountered.
+ ///
+ ///
+ /// If is .
+ ///
+ public static void RegisterParser(Type parserType)
+ {
+ RegisterParser(parserType, null, null);
+ }
+
+ ///
+ /// Associates a parser with a namespace.
+ ///
+ ///
+ ///
+ /// Parsers registered with the same as that
+ /// of a parser that has previously been registered will overwrite the existing
+ /// parser.
+ ///
+ ///
+ ///
+ /// The of the parser that will be activated
+ /// when the attendant is
+ /// encountered.
+ ///
+ ///
+ /// The namespace with which to associate instance of the parser.
+ ///
+ ///
+ /// 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).
+ ///
+ ///
+ /// If the is not a
+ /// that implements the
+ /// interface.
+ ///
+ ///
+ /// If is .
+ ///
+ 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);
+ }
+
+ ///
+ /// Pegisters parser, using default namespace and schema location
+ /// as defined by the .
+ ///
+ ///
+ /// The parser instance.
+ ///
+ ///
+ /// If is .
+ ///
+ public static void RegisterParser(INamespaceParser parser)
+ {
+ RegisterParser(parser, null, null);
+ }
+
+ ///
+ /// Associates a parser with a namespace.
+ ///
+ ///
+ ///
+ /// Parsers registered with the same as that
+ /// of a parser that has previously been registered will overwrite the existing
+ /// parser.
+ ///
+ ///
+ ///
+ /// The namespace with which to associate instance of the parser.
+ ///
+ ///
+ /// The parser instance.
+ ///
+ ///
+ /// 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).
+ ///
+ ///
+ /// If is , or if
+ /// is not specified and parser class
+ /// does not have default value defined using .
+ ///
+ 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);
+ }
+ }
}
///
@@ -350,46 +387,79 @@ namespace Spring.Objects.Factory.Xml
///
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);
}
- }
-
- ///
- /// Returns default values for the parser namespace and schema location as
- /// defined by the .
- ///
- ///
- /// A parser instance.
- ///
- ///
- /// A instance containing
- /// default values for the parser namsepace and schema location
- ///
- private static NamespaceParserAttribute GetDefaults(INamespaceParser parser)
- {
- object[] attrs = parser.GetType().GetCustomAttributes(typeof(NamespaceParserAttribute), true);
- if (attrs.Length > 0)
- {
- return (NamespaceParserAttribute)attrs[0];
- }
- return null;
- }
- }
+ }
+
+ ///
+ /// Returns default values for the parser namespace and schema location as
+ /// defined by the .
+ ///
+ ///
+ /// A type of the parser.
+ ///
+ ///
+ /// A instance containing
+ /// default values for the parser namsepace and schema location
+ ///
+ 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
+
+ ///
+ /// Adapts the interface to .
+ /// Only for smooth transition between 1.x and 2.0 style namespace handling, will be dropped for 2.0
+ ///
+ 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
+ }
}
\ No newline at end of file
diff --git a/src/Spring/Spring.Core/Objects/Factory/Xml/ObjectsNamespaceParser.cs b/src/Spring/Spring.Core/Objects/Factory/Xml/ObjectsNamespaceParser.cs
index 3759d2ee..a7838852 100644
--- a/src/Spring/Spring.Core/Objects/Factory/Xml/ObjectsNamespaceParser.cs
+++ b/src/Spring/Spring.Core/Objects/Factory/Xml/ObjectsNamespaceParser.cs
@@ -108,7 +108,7 @@ namespace Spring.Objects.Factory.Xml
/// and was called to process the root node.
///
///
- [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
diff --git a/src/Spring/Spring.Core/Spring.Core.2008.csproj b/src/Spring/Spring.Core/Spring.Core.2008.csproj
index bc147690..3dc89ca4 100644
--- a/src/Spring/Spring.Core/Spring.Core.2008.csproj
+++ b/src/Spring/Spring.Core/Spring.Core.2008.csproj
@@ -1,7 +1,7 @@

Local
- 9.0.21022
+ 9.0.30729
2.0
{710961A3-0DF4-49E4-A26E-F5B9C044AC84}
Debug
@@ -588,6 +588,7 @@
+
diff --git a/src/Spring/Spring.Core/Validation/Config/ValidationNamespaceParser.cs b/src/Spring/Spring.Core/Validation/Config/ValidationNamespaceParser.cs
index b818b38a..ddd56ae5 100644
--- a/src/Spring/Spring.Core/Validation/Config/ValidationNamespaceParser.cs
+++ b/src/Spring/Spring.Core/Validation/Config/ValidationNamespaceParser.cs
@@ -45,7 +45,7 @@ namespace Spring.Validation.Config
/// Aleksandar Seovic
[
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.
///
///
- [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
diff --git a/src/Spring/Spring.Data/Data/Config/DatabaseNamespaceParser.cs b/src/Spring/Spring.Data/Data/Config/DatabaseNamespaceParser.cs
index 37bf29a6..cf1a2088 100644
--- a/src/Spring/Spring.Data/Data/Config/DatabaseNamespaceParser.cs
+++ b/src/Spring/Spring.Data/Data/Config/DatabaseNamespaceParser.cs
@@ -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
{
}
-
-
-
- ///
- /// Parse the specified element and register any resulting
- /// IObjectDefinitions with the IObjectDefinitionRegistry that is
- /// embedded in the supplied ParserContext.
- ///
- /// The element to be parsed into one or more IObjectDefinitions
- /// The object encapsulating the current state of the parsing
- /// process.
- ///
- /// The primary IObjectDefinition (can be null as explained above)
- ///
- ///
- /// Implementations should return the primary IObjectDefinition
- /// that results from the parse phase if they wish to used nested
- /// inside (for example) a <property> tag.
- /// Implementations may return null if they will not
- /// be used in a nested scenario.
- ///
- ///
- public override IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext)
+// ///
+// /// Parse the specified element and register any resulting
+// /// IObjectDefinitions with the IObjectDefinitionRegistry that is
+// /// embedded in the supplied ParserContext.
+// ///
+// /// The element to be parsed into one or more IObjectDefinitions
+// /// The object encapsulating the current state of the parsing
+// /// process.
+// ///
+// /// The primary IObjectDefinition (can be null as explained above)
+// ///
+// ///
+// /// Implementations should return the primary IObjectDefinition
+// /// that results from the parse phase if they wish to used nested
+// /// inside (for example) a <property> tag.
+// /// Implementations may return null if they will not
+// /// be used in a nested scenario.
+// ///
+// ///
+// [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;
- }
-
- ///
- /// Gets the name of the object type for the specified element. This has already been aliased
- /// in the static constructor.
- ///
- /// The element.
- /// The name of the object type.
- 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;
}
+// ///
+// /// Gets the name of the object type for the specified element. This has already been aliased
+// /// in the static constructor.
+// ///
+// /// The element.
+// /// The name of the object type.
+// 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";
diff --git a/src/Spring/Spring.Web/Objects/Factory/Support/ChildWebObjectDefinition.cs b/src/Spring/Spring.Web/Objects/Factory/Support/ChildWebObjectDefinition.cs
index 9b690868..0579a2bf 100644
--- a/src/Spring/Spring.Web/Objects/Factory/Support/ChildWebObjectDefinition.cs
+++ b/src/Spring/Spring.Web/Objects/Factory/Support/ChildWebObjectDefinition.cs
@@ -38,7 +38,7 @@ namespace Spring.Objects.Factory.Support
/// Aleksandar Seovic
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
///
/// Object scope.
///
- 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(); }
}
///
@@ -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; }
}
+ ///
+ /// Overrides this object's values using values from other argument.
+ ///
+ /// The object to copy values from.
+ public override void OverrideFrom(IObjectDefinition other)
+ {
+ base.OverrideFrom(other);
+ if (other is IWebObjectDefinition)
+ {
+ // this._scope = ((IWebObjectDefinition) other).Scope;
+ this._pageName = ((IWebObjectDefinition)other).PageName;
+ }
+ }
+
///
/// A that represents the current
/// .
diff --git a/src/Spring/Spring.Web/Objects/Factory/Support/RootWebObjectDefinition.cs b/src/Spring/Spring.Web/Objects/Factory/Support/RootWebObjectDefinition.cs
index 36226a50..46b328b3 100644
--- a/src/Spring/Spring.Web/Objects/Factory/Support/RootWebObjectDefinition.cs
+++ b/src/Spring/Spring.Web/Objects/Factory/Support/RootWebObjectDefinition.cs
@@ -42,7 +42,7 @@ namespace Spring.Objects.Factory.Support
/// Aleksandar Seovic
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
///
/// Object scope.
///
- 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(); }
}
///
@@ -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;
}
}
diff --git a/test/Spring/Spring.Core.Tests/Objects/Factory/AbstractObjectFactoryTests.cs b/test/Spring/Spring.Core.Tests/Objects/Factory/AbstractObjectFactoryTests.cs
index 15759f7d..9f6b1649 100644
--- a/test/Spring/Spring.Core.Tests/Objects/Factory/AbstractObjectFactoryTests.cs
+++ b/test/Spring/Spring.Core.Tests/Objects/Factory/AbstractObjectFactoryTests.cs
@@ -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
}
diff --git a/test/Spring/Spring.Core.Tests/Objects/Factory/UnsupportedObjectDefinitionImplementation.cs b/test/Spring/Spring.Core.Tests/Objects/Factory/UnsupportedObjectDefinitionImplementation.cs
index 5ab9f6b8..e3b8c2f7 100644
--- a/test/Spring/Spring.Core.Tests/Objects/Factory/UnsupportedObjectDefinitionImplementation.cs
+++ b/test/Spring/Spring.Core.Tests/Objects/Factory/UnsupportedObjectDefinitionImplementation.cs
@@ -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(); }
diff --git a/test/Spring/Spring.Web.Tests/Objects/Factory/Support/WebObjectFactoryTests.cs b/test/Spring/Spring.Web.Tests/Objects/Factory/Support/WebObjectFactoryTests.cs
index 0d742a5b..dcd22910 100644
--- a/test/Spring/Spring.Web.Tests/Objects/Factory/Support/WebObjectFactoryTests.cs
+++ b/test/Spring/Spring.Web.Tests/Objects/Factory/Support/WebObjectFactoryTests.cs
@@ -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;