|
From: <fab...@us...> - 2010-01-06 05:08:29
|
Revision: 4904
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4904&view=rev
Author: fabiomaulo
Date: 2010-01-06 05:08:17 +0000 (Wed, 06 Jan 2010)
Log Message:
-----------
- Refactoring
- removed unused code
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/ClassExtractor.cs
trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
trunk/nhibernate/src/NHibernate/Cfg/NamedXmlDocument.cs
trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
Removed Paths:
-------------
trunk/nhibernate/src/NHibernate/Util/XmlHelper.cs
Modified: trunk/nhibernate/src/NHibernate/Cfg/ClassExtractor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/ClassExtractor.cs 2010-01-06 04:00:10 UTC (rev 4903)
+++ trunk/nhibernate/src/NHibernate/Cfg/ClassExtractor.cs 2010-01-06 05:08:17 UTC (rev 4904)
@@ -1,8 +1,8 @@
using System.Xml;
-using NHibernate.Cfg.XmlHbmBinding;
+using System.Linq;
using NHibernate.Util;
using System.Collections.Generic;
-using Iesi.Collections.Generic;
+using NHibernate.Cfg.MappingSchema;
namespace NHibernate.Cfg
{
@@ -59,8 +59,7 @@
public override bool Equals(object obj)
{
- ClassEntry that = obj as ClassEntry;
- return Equals(that);
+ return Equals(obj as ClassEntry);
}
public bool Equals(ClassEntry obj)
@@ -88,40 +87,19 @@
/// </summary>
/// <param name="document">A validated <see cref="XmlDocument"/> representing
/// a mapping file.</param>
- public static ICollection<ClassEntry> GetClassEntries(XmlDocument document)
+ public static ICollection<ClassEntry> GetClassEntries(HbmMapping document)
{
- // TODO this should be extracted into a utility method since there's similar
- // code in Configuration
- XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable);
- nsmgr.AddNamespace(HbmConstants.nsPrefix, Binder.MappingSchemaXMLNS);
-
// Since the document is validated, no error checking is done in this method.
- HashedSet<ClassEntry> classEntries = new HashedSet<ClassEntry>();
+ var classEntries = new HashSet<ClassEntry>();
- XmlNode root = document.DocumentElement;
+ string assembly = document.assembly;
+ string @namespace = document.@namespace;
- string assembly = XmlHelper.GetAttributeValue(root, "assembly");
- string @namespace = XmlHelper.GetAttributeValue(root, "namespace");
+ classEntries.UnionWith(document.RootClasses.Select(c=> new ClassEntry(null, c.Name, c.EntityName, assembly, @namespace)));
+ classEntries.UnionWith(document.SubClasses.Select(c => new ClassEntry(c.extends, c.Name, c.EntityName, assembly, @namespace)));
+ classEntries.UnionWith(document.JoinedSubclasses.Select(c => new ClassEntry(c.extends, c.Name, c.EntityName, assembly, @namespace)));
+ classEntries.UnionWith(document.UnionSubclasses.Select(c => new ClassEntry(c.extends, c.Name, c.EntityName, assembly, @namespace)));
- XmlNodeList classNodes = document.SelectNodes(
- "//" + HbmConstants.nsClass +
- "|//" + HbmConstants.nsSubclass +
- "|//" + HbmConstants.nsJoinedSubclass +
- "|//" + HbmConstants.nsUnionSubclass,
- nsmgr
- );
-
- if (classNodes != null)
- {
- foreach (XmlNode classNode in classNodes)
- {
- string name = XmlHelper.GetAttributeValue(classNode, "name");
- string extends = XmlHelper.GetAttributeValue(classNode, "extends");
- string entityName = XmlHelper.GetAttributeValue(classNode, "entity-name");
- classEntries.Add(new ClassEntry(extends, name, entityName, assembly, @namespace));
- }
- }
-
return classEntries;
}
}
Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2010-01-06 04:00:10 UTC (rev 4903)
+++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2010-01-06 05:08:17 UTC (rev 4904)
@@ -8,7 +8,6 @@
using System.Text;
using System.Xml;
using System.Xml.Schema;
-using System.Xml.Serialization;
using Iesi.Collections;
using Iesi.Collections.Generic;
using log4net;
@@ -494,22 +493,7 @@
/// <param name="doc">The NamedXmlDocument that contains the <b>validated</b> mapping XML file.</param>
private void AddValidatedDocument(NamedXmlDocument doc)
{
- HbmMapping mappingMeta = null;
- try
- {
- // TODO : The mappingMeta should be the property of NamedXmlDocument
- // A validated document IS a deserialized doc and we don't need to deserialize it more than one time.
- using (var reader = new StringReader(doc.Document.DocumentElement.OuterXml))
- {
- mappingMeta = (HbmMapping) new XmlSerializer(typeof (HbmMapping)).Deserialize(reader);
- }
- }
- catch (Exception e)
- {
- string nameFormatted = doc.Name ?? "(unknown)";
- LogAndThrow(new MappingException("Could not compile the mapping document: " + nameFormatted, e));
- }
- AddDeserializedMapping(mappingMeta, doc.Name);
+ AddDeserializedMapping(doc.Document, doc.Name);
}
/// <summary>
@@ -1762,11 +1746,21 @@
hbmDocument.Load(reader);
return new NamedXmlDocument(name, hbmDocument);
}
+ catch(MappingException)
+ {
+ throw;
+ }
+ catch (Exception e)
+ {
+ string nameFormatted = name ?? "(unknown)";
+ LogAndThrow(new MappingException("Could not compile the mapping document: " + nameFormatted, e));
+ }
finally
{
currentDocumentName = null;
}
}
+ return null;
}
/// <summary>
Modified: trunk/nhibernate/src/NHibernate/Cfg/NamedXmlDocument.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/NamedXmlDocument.cs 2010-01-06 04:00:10 UTC (rev 4903)
+++ trunk/nhibernate/src/NHibernate/Cfg/NamedXmlDocument.cs 2010-01-06 05:08:17 UTC (rev 4904)
@@ -1,16 +1,31 @@
+using System;
+using System.IO;
using System.Xml;
+using System.Xml.Serialization;
+using NHibernate.Cfg.MappingSchema;
namespace NHibernate.Cfg
{
public class NamedXmlDocument
{
private readonly string name;
- private readonly XmlDocument document;
+ private readonly HbmMapping document;
public NamedXmlDocument(string name, XmlDocument document)
{
+ if (document == null)
+ {
+ throw new ArgumentNullException("document");
+ }
this.name = name;
- this.document = document;
+ if (document.DocumentElement == null)
+ {
+ throw new MappingException("Empty XML document:" + name);
+ }
+ using (var reader = new StringReader(document.DocumentElement.OuterXml))
+ {
+ this.document = (HbmMapping)new XmlSerializer(typeof(HbmMapping)).Deserialize(reader);
+ }
}
public string Name
@@ -18,7 +33,7 @@
get { return name; }
}
- public XmlDocument Document
+ public HbmMapping Document
{
get { return document; }
}
Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2010-01-06 04:00:10 UTC (rev 4903)
+++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/Binder.cs 2010-01-06 05:08:17 UTC (rev 4904)
@@ -10,9 +10,6 @@
{
public abstract class Binder
{
- /// <summary>The XML Namespace for the nhibernate-mapping</summary>
- public const string MappingSchemaXMLNS = "urn:nhibernate-mapping-2.2";
-
protected static readonly ILog log = LogManager.GetLogger(typeof (Binder));
protected static readonly IDictionary<string, MetaAttribute> EmptyMeta =
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-01-06 04:00:10 UTC (rev 4903)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-01-06 05:08:17 UTC (rev 4904)
@@ -1487,7 +1487,6 @@
<Compile Include="Util\WeakHashtable.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="Util\XmlHelper.cs" />
<Compile Include="Properties\XmlAccessor.cs" />
<EmbeddedResource Include="nhibernate-configuration.xsd">
<SubType>
Deleted: trunk/nhibernate/src/NHibernate/Util/XmlHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Util/XmlHelper.cs 2010-01-06 04:00:10 UTC (rev 4903)
+++ trunk/nhibernate/src/NHibernate/Util/XmlHelper.cs 2010-01-06 05:08:17 UTC (rev 4904)
@@ -1,29 +0,0 @@
-using System;
-using System.Xml;
-
-namespace NHibernate.Util
-{
- public class XmlHelper
- {
- public static string GetAttributeValue(XmlNode node, string attributeName)
- {
- XmlAttribute attribute = node.Attributes[attributeName];
- if (attribute == null)
- {
- return null;
- }
- return attribute.Value;
- }
-
- public static string ElementTextTrim(XmlNode node, string elementName, XmlNamespaceManager nsmgr)
- {
- XmlNode subNode = node.SelectSingleNode(elementName, nsmgr);
- if (subNode == null)
- {
- return null;
- }
-
- return subNode.InnerText.Trim();
- }
- }
-}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|