From: <fab...@us...> - 2008-09-18 13:29:53
|
Revision: 3765 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3765&view=rev Author: fabiomaulo Date: 2008-09-18 20:29:55 +0000 (Thu, 18 Sep 2008) Log Message: ----------- - Refactoring - One more step to support entity-name - previous ignored test passed Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/MappingRootBinder.cs trunk/nhibernate/src/NHibernate.Test/Extendshbm/ExtendsFixture.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs 2008-09-18 18:44:37 UTC (rev 3764) +++ trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs 2008-09-18 20:29:55 UTC (rev 3765) @@ -173,20 +173,11 @@ propertyReferences.Add(upr); } - /// <summary> - /// - /// </summary> - /// <param name="type"></param> - /// <returns></returns> - public PersistentClass GetClass(System.Type type) - { - // TODO NH: Remove this method - return GetClass(type.FullName); - } - public PersistentClass GetClass(string className) { - return classes[className]; + PersistentClass result; + classes.TryGetValue(className, out result); + return result; } /// <summary> @@ -215,11 +206,6 @@ set { defaultAssembly = value; } } - /// <summary> - /// - /// </summary> - /// <param name="role"></param> - /// <returns></returns> public Mapping.Collection GetCollection(string role) { return collections[role]; Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2008-09-18 18:44:37 UTC (rev 3764) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2008-09-18 20:29:55 UTC (rev 3765) @@ -37,7 +37,7 @@ /// <param name="className"></param> /// <param name="mappings"></param> /// <returns></returns> - protected static string FullClassName(string className, Mappings mappings) + protected static string FullQualifiedClassName(string className, Mappings mappings) { if (className == null) return null; @@ -47,6 +47,23 @@ } /// <summary> + /// Converts a partial class name into a fully one + /// </summary> + /// <param name="className"></param> + /// <param name="mappings"></param> + /// <returns>The class FullName (without the assembly)</returns> + /// <remarks> + /// The FullName is equivalent to the default entity-name + /// </remarks> + protected static string FullClassName(string className, Mappings mappings) + { + if (className == null) + return null; + + return TypeNameParser.Parse(className, mappings.DefaultNamespace, mappings.DefaultAssembly).Type; + } + + /// <summary> /// Attempts to find a type by its full name. Throws a <see cref="MappingException" /> /// using the provided <paramref name="errorMessage" /> in case of failure. /// </summary> @@ -72,7 +89,7 @@ /// <summary> /// Similar to <see cref="ClassForFullNameChecked" />, but handles short class names - /// by calling <see cref="FullClassName" />. + /// by calling <see cref="FullQualifiedClassName" />. /// </summary> /// <param name="name"></param> /// <param name="mappings"></param> @@ -80,7 +97,7 @@ /// <returns></returns> protected static System.Type ClassForNameChecked(string name, Mappings mappings, string errorMessage) { - return ClassForFullNameChecked(FullClassName(name, mappings), errorMessage); + return ClassForFullNameChecked(FullQualifiedClassName(name, mappings), errorMessage); } protected static string GetClassName(string unqualifiedName, Mappings mappings) Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2008-09-18 18:44:37 UTC (rev 3764) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2008-09-18 20:29:55 UTC (rev 3765) @@ -235,7 +235,7 @@ XmlNode tuplizer = LocateTuplizerDefinition(node, EntityMode.Map); if (tuplizer != null) { - string tupClassName = FullClassName(tuplizer.Attributes["class"].Value, mappings); + string tupClassName = FullQualifiedClassName(tuplizer.Attributes["class"].Value, mappings); entity.AddTuplizer(EntityMode.Map, tupClassName); } } @@ -253,7 +253,7 @@ XmlNode tuplizer = LocateTuplizerDefinition(node, EntityMode.Xml); if (tuplizer != null) { - string tupClassName = FullClassName(tuplizer.Attributes["class"].Value, mappings); + string tupClassName = FullQualifiedClassName(tuplizer.Attributes["class"].Value, mappings); entity.AddTuplizer(EntityMode.Xml, tupClassName); } } @@ -279,7 +279,7 @@ XmlNode tuplizer = LocateTuplizerDefinition(node, EntityMode.Poco); if (tuplizer != null) { - string tupClassName = FullClassName(tuplizer.Attributes["class"].Value, mappings); + string tupClassName = FullQualifiedClassName(tuplizer.Attributes["class"].Value, mappings); entity.AddTuplizer(EntityMode.Poco, tupClassName); } } @@ -460,14 +460,20 @@ { XmlAttribute extendsAttr = subnode.Attributes["extends"]; if (extendsAttr == null) + { throw new MappingException("'extends' attribute is not found."); - String extendsValue = FullClassName(extendsAttr.Value, mappings); - System.Type superclass = ClassForFullNameChecked(extendsValue, - "extended class not found: {0}"); - PersistentClass superModel = mappings.GetClass(superclass); - + } + string extendsName = extendsAttr.Value; + PersistentClass superModel = mappings.GetClass(extendsName); + if(superModel == null) + { + string qualifiedExtendsName = FullClassName(extendsName, mappings); + superModel = mappings.GetClass(qualifiedExtendsName); + } if (superModel == null) - throw new MappingException("Cannot extend unmapped class: " + extendsValue); + { + throw new MappingException("Cannot extend unmapped class: " + extendsName); + } return superModel; } @@ -541,7 +547,7 @@ model.ComponentClass = ClassForNameChecked( classNode.Value, mappings, "component class not found: {0}"); - model.ComponentClassName = FullClassName(classNode.Value, mappings); + model.ComponentClassName = FullQualifiedClassName(classNode.Value, mappings); model.IsEmbedded = false; } else if (reflectedClass != null) @@ -767,7 +773,7 @@ { originalTypeName = typeChild.Attributes["name"].Value; // NH: allow className completing it with assembly+namespace of the mapping doc. - typeName = FullClassName(originalTypeName, mappings); + typeName = FullQualifiedClassName(originalTypeName, mappings); foreach (XmlNode childNode in typeChild.ChildNodes) parameters.Add(childNode.Attributes["name"].Value, childNode.InnerText.Trim()); } @@ -780,7 +786,7 @@ TypeDef typeDef = originalTypeName == null ? mappings.GetTypeDef(typeName) : mappings.GetTypeDef(originalTypeName); if (typeDef != null) { - typeName = FullClassName(typeDef.TypeClass, mappings); + typeName = FullQualifiedClassName(typeDef.TypeClass, mappings); // parameters on the property mapping should // override parameters in the typedef Dictionary<string, string> allParameters = new Dictionary<string, string>(typeDef.Parameters); @@ -1207,7 +1213,7 @@ string entityName = XmlHelper.GetAttributeValue(elem, "entity-name"); string className = XmlHelper.GetAttributeValue(elem, "class"); entityName = entityName - ?? (className == null ? null : StringHelper.GetFullClassname(FullClassName(className, model))); + ?? (className == null ? null : StringHelper.GetFullClassname(FullQualifiedClassName(className, model))); return entityName; } Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2008-09-18 18:44:37 UTC (rev 3764) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs 2008-09-18 20:29:55 UTC (rev 3765) @@ -152,7 +152,7 @@ } else { - model.TypeName = FullClassName(typeName, mappings); + model.TypeName = FullQualifiedClassName(typeName, mappings); } } @@ -211,7 +211,7 @@ model.IsSorted = true; if (!sortedAtt.Value.Equals("natural")) { - string comparatorClassName = FullClassName(sortedAtt.Value, mappings); + string comparatorClassName = FullQualifiedClassName(sortedAtt.Value, mappings); try { model.Comparer = Activator.CreateInstance(ReflectHelper.ClassForName(comparatorClassName)); Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/MappingRootBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/MappingRootBinder.cs 2008-09-18 18:44:37 UTC (rev 3764) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/MappingRootBinder.cs 2008-09-18 20:29:55 UTC (rev 3765) @@ -123,7 +123,7 @@ { foreach (HbmImport importSchema in mappingSchema.import ?? new HbmImport[0]) { - string fullClassName = FullClassName(importSchema.@class, mappings); + string fullClassName = FullQualifiedClassName(importSchema.@class, mappings); string rename = importSchema.rename ?? StringHelper.GetClassname(fullClassName); log.DebugFormat("Import: {0} -> {1}", rename, fullClassName); @@ -135,7 +135,7 @@ { foreach (HbmTypedef typedef in mappingSchema.typedef ?? new HbmTypedef[0]) { - string typeClass = FullClassName(typedef.@class, mappings); + string typeClass = FullQualifiedClassName(typedef.@class, mappings); string typeName = typedef.name; IEnumerable<HbmParam> paramIter = typedef.param ?? new HbmParam[0]; Dictionary<string, string> parameters = new Dictionary<string, string>(5); Modified: trunk/nhibernate/src/NHibernate.Test/Extendshbm/ExtendsFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Extendshbm/ExtendsFixture.cs 2008-09-18 18:44:37 UTC (rev 3764) +++ trunk/nhibernate/src/NHibernate.Test/Extendshbm/ExtendsFixture.cs 2008-09-18 20:29:55 UTC (rev 3765) @@ -92,7 +92,7 @@ Assert.That(cfg.GetClassMapping(typeof (Employee).FullName), Is.Not.Null); } - [Test, Ignore("Not supported yet!")] + [Test] public void JoinedSubclassAndEntityNamesOnly() { Configuration cfg = new Configuration(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |