|
From: <fab...@us...> - 2009-12-01 21:03:51
|
Revision: 4885
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4885&view=rev
Author: fabiomaulo
Date: 2009-12-01 21:03:41 +0000 (Tue, 01 Dec 2009)
Log Message:
-----------
binders refactoring
- TypeBinder partially on the road
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate/Util/ArrayHelper.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/TypeBinder.cs
Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs 2009-12-01 16:47:38 UTC (rev 4884)
+++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs 2009-12-01 21:03:41 UTC (rev 4885)
@@ -197,7 +197,7 @@
string propertyName = versionSchema.name;
var simpleValue = new SimpleValue(table);
- BindVersionType(versionSchema.type, simpleValue);
+ new TypeBinder(simpleValue, Mappings).Bind(versionSchema.type);
new ColumnsBinder(simpleValue, Mappings).Bind(versionSchema.Columns, false,
() =>
new HbmColumn
@@ -221,13 +221,6 @@
rootClass.AddProperty(property);
}
- private void BindVersionType(string versionTypeName, SimpleValue simpleValue)
- {
- if (versionTypeName == null)
- return;
- BindTypeDef(versionTypeName, versionTypeName, new Dictionary<string, string>(), simpleValue);
- }
-
private void BindProperty(HbmVersion versionSchema, Property property, IDictionary<string, MetaAttribute> inheritedMetas)
{
property.Name = versionSchema.name;
Added: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/TypeBinder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/TypeBinder.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/TypeBinder.cs 2009-12-01 21:03:41 UTC (rev 4885)
@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using NHibernate.Cfg.MappingSchema;
+using NHibernate.Mapping;
+using NHibernate.Util;
+
+namespace NHibernate.Cfg.XmlHbmBinding
+{
+ public class TypeBinder: Binder
+ {
+ private readonly SimpleValue value;
+
+ public TypeBinder(SimpleValue value, Mappings mappings)
+ : base(mappings)
+ {
+ if (value == null)
+ {
+ throw new ArgumentNullException("value");
+ }
+ this.value = value;
+ }
+
+ public void Bind(string typeName)
+ {
+ if(string.IsNullOrEmpty(typeName))
+ {
+ return;
+ }
+ Bind(new HbmType { name= typeName });
+ }
+
+ private void Bind(HbmType typeMapping)
+ {
+ if (typeMapping == null)
+ {
+ throw new ArgumentNullException("typeMapping");
+ }
+ string originalTypeName = typeMapping.name;
+ if(originalTypeName == null)
+ {
+ return;
+ }
+ var parameters = new Dictionary<string, string>();
+ if(typeMapping.param != null)
+ {
+ System.Array.ForEach(typeMapping.param, p => parameters[p.name] = p.Text.LinesToString());
+ }
+
+ BindThroughTypeDefOrType(originalTypeName, parameters);
+ }
+
+ private void BindThroughTypeDefOrType(string originalTypeName, IDictionary<string, string> parameters)
+ {
+ string typeName = null;
+ TypeDef typeDef = Mappings.GetTypeDef(originalTypeName);
+ if (typeDef != null)
+ {
+ typeName = FullQualifiedClassName(typeDef.TypeClass, Mappings);
+ // parameters on the property mapping should
+ // override parameters in the typedef
+ parameters = new Dictionary<string, string>(typeDef.Parameters).AddOrOverride(parameters);
+ }
+ else if (NeedQualifiedClassName(originalTypeName)
+ && (typeDef = Mappings.GetTypeDef(FullQualifiedClassName(originalTypeName, Mappings))) != null)
+ {
+ // NH: allow className completing it with assembly+namespace of the mapping doc.
+ typeName = typeDef.TypeClass;
+ // parameters on the property mapping should
+ // override parameters in the typedef
+ parameters = new Dictionary<string, string>(typeDef.Parameters).AddOrOverride(parameters);
+ }
+
+ if (parameters.Count != 0)
+ {
+ value.TypeParameters = parameters;
+ }
+ var typeToMap = typeName ?? originalTypeName;
+ if (NeedQualifiedClassName(typeToMap))
+ {
+ typeToMap = FullQualifiedClassName(typeToMap, Mappings);
+ }
+ value.TypeName = typeToMap;
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-12-01 16:47:38 UTC (rev 4884)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-12-01 21:03:41 UTC (rev 4885)
@@ -551,6 +551,7 @@
<Compile Include="Cfg\XmlHbmBinding\PropertiesBinder.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Cfg\XmlHbmBinding\TypeBinder.cs" />
<Compile Include="Context\WcfOperationSessionContext.cs" />
<Compile Include="Criterion\GroupedProjection.cs" />
<Compile Include="Criterion\IPropertyProjection.cs" />
Modified: trunk/nhibernate/src/NHibernate/Util/ArrayHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Util/ArrayHelper.cs 2009-12-01 16:47:38 UTC (rev 4884)
+++ trunk/nhibernate/src/NHibernate/Util/ArrayHelper.cs 2009-12-01 21:03:41 UTC (rev 4885)
@@ -12,7 +12,7 @@
/// Helper class that contains common array functions and
/// data structures used through out NHibernate.
/// </summary>
- public sealed class ArrayHelper
+ public static class ArrayHelper
{
public static readonly object[] EmptyObjectArray = new object[0];
public static readonly IType[] EmptyTypeArray = new IType[0];
@@ -22,10 +22,6 @@
public static readonly bool[] True = new bool[] { true };
public static readonly bool[] False = new bool[] { false };
- private ArrayHelper()
- {
- }
-
public static bool IsAllNegative(int[] array)
{
for (int i = 0; i < array.Length; i++)
@@ -226,6 +222,16 @@
}
}
+ public static IDictionary<TKey, TValue> AddOrOverride<TKey, TValue>(this IDictionary<TKey, TValue> destination, IDictionary<TKey, TValue> sourceOverride)
+ {
+ foreach (KeyValuePair<TKey, TValue> de in sourceOverride)
+ {
+ // we want to override the values from to if they exists
+ destination[de.Key] = de.Value;
+ }
+ return destination;
+ }
+
public static int[] GetBatchSizes(int maxBatchSize)
{
int batchSize = maxBatchSize;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|