-
Notifications
You must be signed in to change notification settings - Fork 934
/
Copy pathMappingsQueueEntry.cs
139 lines (120 loc) · 3.36 KB
/
MappingsQueueEntry.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System.Collections.Generic;
namespace NHibernate.Cfg
{
/// <summary>
/// Holds information about mapped classes found in an embedded resource
/// </summary>
public class MappingsQueueEntry
{
private readonly HashSet<string> containedClassNames;
private readonly NamedXmlDocument document;
private readonly HashSet<RequiredEntityName> requiredClassNames;
public MappingsQueueEntry(NamedXmlDocument document, IEnumerable<ClassExtractor.ClassEntry> classEntries)
{
this.document = document;
containedClassNames = GetClassNames(classEntries);
requiredClassNames = GetRequiredClassNames(classEntries, containedClassNames);
}
public NamedXmlDocument Document
{
get { return document; }
}
/// <summary>
/// Gets the names of all entities outside this resource
/// needed by the classes in this resource.
/// </summary>
public ICollection<RequiredEntityName> RequiredClassNames
{
get { return requiredClassNames; }
}
/// <summary>
/// Gets the names of all entities in this resource
/// </summary>
public ICollection<string> ContainedClassNames
{
get { return containedClassNames; }
}
private static HashSet<string> GetClassNames(IEnumerable<ClassExtractor.ClassEntry> classEntries)
{
var result = new HashSet<string>();
foreach (var ce in classEntries)
{
if (ce.EntityName != null)
{
result.Add(ce.EntityName);
}
else if (ce.FullClassName != null)
{
result.Add(ce.FullClassName.Type);
}
}
return result;
}
private static HashSet<RequiredEntityName> GetRequiredClassNames(IEnumerable<ClassExtractor.ClassEntry> classEntries,
ICollection<string> containedNames)
{
var result = new HashSet<RequiredEntityName>();
foreach (var ce in classEntries)
{
if (ce.ExtendsEntityName != null && !containedNames.Contains(ce.FullExtends.Type)
&& !containedNames.Contains(ce.ExtendsEntityName))
{
result.Add(new RequiredEntityName(ce.ExtendsEntityName, ce.FullExtends.Type));
}
}
return result;
}
public class RequiredEntityName
{
public RequiredEntityName(string entityName, string fullClassName)
{
EntityName = entityName;
FullClassName = fullClassName;
}
public string EntityName { get; private set; }
public string FullClassName { get; private set; }
public bool Equals(RequiredEntityName obj)
{
if (obj == null)
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return Equals(obj.EntityName, EntityName) && Equals(obj.FullClassName, FullClassName);
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
var thatSimple = obj as string;
if (thatSimple != null && (thatSimple.Equals(EntityName) || thatSimple.Equals(FullClassName)))
{
return true;
}
var that = obj as RequiredEntityName;
if (that != null)
{
return false;
}
return Equals(that);
}
public override int GetHashCode()
{
unchecked
{
return ((EntityName != null ? EntityName.GetHashCode() : 0) * 397)
^ (FullClassName != null ? FullClassName.GetHashCode() : 0);
}
}
public override string ToString()
{
return string.Format("FullName:{0} - Name:{1}", FullClassName ?? "<null>", EntityName ?? "<null>");
}
}
}
}