Skip to content

Commit ada7377

Browse files
committed
NH-3807 - Guard on XmlSchemas and Xml ValidationEventHandler
1 parent 564018e commit ada7377

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/NHibernate/Cfg/Configuration.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,8 +1242,10 @@ public ISessionFactory BuildSessionFactory()
12421242
Environment.VerifyProperties(properties);
12431243
Settings settings = BuildSettings();
12441244

1245+
#if FEATURE_XML_SCHEMAS
12451246
// Ok, don't need schemas anymore, so free them
12461247
Schemas = null;
1248+
#endif
12471249

12481250
return new SessionFactoryImpl(this, mapping, settings, GetInitializedEventListeners());
12491251
}
@@ -1769,8 +1771,16 @@ public void AddSqlFunction(string functionName, ISQLFunction sqlFunction)
17691771
/// <returns>NamedXmlDocument containing the validated XmlDocument built from the XmlReader.</returns>
17701772
public NamedXmlDocument LoadMappingDocument(XmlReader hbmReader, string name)
17711773
{
1772-
XmlReaderSettings settings = Schemas.CreateMappingReaderSettings();
1774+
XmlReaderSettings settings =
1775+
#if FEATURE_XML_SCHEMAS
1776+
Schemas.CreateMappingReaderSettings();
1777+
#else
1778+
new XmlReaderSettings();
1779+
#endif
1780+
1781+
#if FEATURE_XML_VALIDATIONEVENTHANDLER
17731782
settings.ValidationEventHandler += ValidationHandler;
1783+
#endif
17741784

17751785
using (XmlReader reader = XmlReader.Create(hbmReader, settings))
17761786
{
@@ -1841,12 +1851,14 @@ private void ProcessMappingsQueue()
18411851
}
18421852
}
18431853

1854+
#if FEATURE_XML_VALIDATIONEVENTHANDLER
18441855
private void ValidationHandler(object o, ValidationEventArgs args)
18451856
{
18461857
string message = string.Format("{0}({1},{2}): XML validation error: {3}", currentDocumentName,
18471858
args.Exception.LineNumber, args.Exception.LinePosition, args.Exception.Message);
18481859
LogAndThrow(new MappingException(message, args.Exception));
18491860
}
1861+
#endif
18501862

18511863
protected virtual string GetDefaultConfigurationFilePath()
18521864
{
@@ -1862,13 +1874,15 @@ protected virtual string GetDefaultConfigurationFilePath()
18621874

18631875
#endregion
18641876

1877+
#if FEATURE_XML_SCHEMAS
18651878
private XmlSchemas schemas;
18661879

18671880
private XmlSchemas Schemas
18681881
{
18691882
get { return schemas = schemas ?? new XmlSchemas(); }
18701883
set { schemas = value; }
18711884
}
1885+
#endif
18721886

18731887
/// <summary>
18741888
/// Set or clear listener for a given <see cref="ListenerType"/>.

src/NHibernate/Cfg/ConfigurationSchema/HibernateConfiguration.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ internal static HibernateConfiguration FromAppConfig(XmlNode node)
6969

7070
private XmlReaderSettings GetSettings()
7171
{
72-
XmlReaderSettings xmlrs = (new XmlSchemas()).CreateConfigReaderSettings();
72+
XmlReaderSettings xmlrs =
73+
#if FEATURE_XML_SCHEMAS
74+
(new XmlSchemas()).CreateConfigReaderSettings();
75+
#else
76+
new XmlReaderSettings();
77+
#endif
7378
return xmlrs;
7479
}
7580

src/NHibernate/Cfg/XmlSchemas.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#if FEATURE_XML_SCHEMAS
2+
13
using System.IO;
24
using System.Reflection;
35
using System.Xml;
@@ -16,7 +18,9 @@ internal class XmlSchemas
1618
public XmlReaderSettings CreateConfigReaderSettings()
1719
{
1820
XmlReaderSettings result = CreateXmlReaderSettings(ConfigSchemaSet);
21+
#if FEATURE_XML_VALIDATIONEVENTHANDLER
1922
result.ValidationEventHandler += ConfigSettingsValidationEventHandler;
23+
#endif
2024
result.IgnoreComments = true;
2125
return result;
2226
}
@@ -45,9 +49,13 @@ private static XmlReaderSettings CreateXmlReaderSettings(XmlSchemaSet xmlSchemaS
4549
return new XmlReaderSettings {ValidationType = ValidationType.Schema, Schemas = xmlSchemaSet};
4650
}
4751

52+
#if FEATURE_XML_VALIDATIONEVENTHANDLER
4853
private static void ConfigSettingsValidationEventHandler(object sender, ValidationEventArgs e)
4954
{
5055
throw new HibernateConfigException("An exception occurred parsing configuration :" + e.Message, e.Exception);
5156
}
57+
#endif
5258
}
53-
}
59+
}
60+
61+
#endif

0 commit comments

Comments
 (0)