Skip to content

Commit c47095c

Browse files
committed
Bring XmlParsing in line with hapi
* Port hapi version of XMLParser and DefaultXMLParser - nHapi versions of these were years behind hapi. * Keep old implementations as LegacyXMLParser and LegacyDefaultXMLParser for people or depend on old imperfect behaviour * Add Unit tests for changes * Fix some code styling warnings * Improve XML Documentation * Update some Nuget packages * Unblocks #308 * Closes some Dependabot pull requests
1 parent f437a4d commit c47095c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3432
-676
lines changed

src/NHapi.Base/Model/AbstractGroup.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,11 @@ namespace NHapi.Base.Model
4242
/// </author>
4343
public abstract class AbstractGroup : IGroup
4444
{
45-
private static readonly IHapiLog Log;
45+
private static readonly IHapiLog Log = HapiLogFactory.GetHapiLog(typeof(AbstractGroup));
4646

4747
private readonly IModelClassFactory myFactory;
4848
private List<AbstractGroupItem> items;
4949

50-
static AbstractGroup()
51-
{
52-
Log = HapiLogFactory.GetHapiLog(typeof(AbstractGroup));
53-
}
54-
5550
/// <summary> This constructor should be used by implementing classes that do not
5651
/// also implement Message.
5752
///
@@ -527,7 +522,7 @@ private IStructure TryToInstantiateStructure(Type c, string name)
527522
var argClasses = new[] { typeof(IGroup), typeof(IModelClassFactory) };
528523
var argObjects = new object[] { this, myFactory };
529524
var con = c.GetConstructor(argClasses);
530-
o = con.Invoke(argObjects);
525+
o = con?.Invoke(argObjects);
531526
}
532527
catch (MethodAccessException)
533528
{

src/NHapi.Base/Model/AbstractPrimitive.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public AbstractPrimitive(IMessage message, string description)
5656
{
5757
}
5858

59-
/// <summary> Sets the value of this Primitive, first performing validation as specified
60-
/// by. <code>getMessage().getValidationContext()</code>. No validation is performed
61-
/// if getMessage() returns null.
62-
///
59+
/// <summary>
60+
/// Sets the value of this Primitive, first performing validation as specified
61+
/// by. <see cref="AbstractMessage.ValidationContext">Message.ValidationContext</see>
62+
/// No validation is performed if <see cref="AbstractType.Message"/> returns null.
6363
/// </summary>
6464
public virtual string Value
6565
{

src/NHapi.Base/Model/GenericComposite.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace NHapi.Base.Model
22
{
33
using System.Collections;
4+
using System.Collections.Generic;
45

56
/// <summary>
67
/// An unspecified Composite datatype that has an undefined number of components, each
@@ -11,7 +12,7 @@ namespace NHapi.Base.Model
1112
/// <author>Bryan Tripp.</author>
1213
public class GenericComposite : AbstractType, IComposite
1314
{
14-
private readonly ArrayList components;
15+
private readonly List<IType> components;
1516

1617
/// <summary>
1718
/// Creates a new instance of GenericComposite.
@@ -30,25 +31,13 @@ public GenericComposite(IMessage theMessage)
3031
public GenericComposite(IMessage theMessage, string description)
3132
: base(theMessage, description)
3233
{
33-
components = new ArrayList(20);
34+
components = new List<IType>(20);
3435
}
3536

3637
/// <summary>
3738
/// Returns an array containing the components of this field.
3839
/// </summary>
39-
public virtual IType[] Components
40-
{
41-
get
42-
{
43-
var ret = new IType[components.Count];
44-
for (var i = 0; i < ret.Length; i++)
45-
{
46-
ret[i] = (IType)components[i];
47-
}
48-
49-
return ret;
50-
}
51-
}
40+
public virtual IType[] Components => components.ToArray();
5241

5342
/// <summary>
5443
/// Returns the name of the type (used in XML encoding and profile checking).
@@ -68,7 +57,7 @@ public virtual IType this[int index]
6857
components.Add(new Varies(Message));
6958
}
7059

71-
return (IType)components[index];
60+
return components[index];
7261
}
7362
}
7463
}

src/NHapi.Base/Model/Primitive/CommonTM.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,11 @@ public virtual string Value
151151
{
152152
// check to see if any of the following characters exist: "." or "+/-"
153153
// this will help us determine the acceptable lengths
154-
var d = value.IndexOf(".");
155-
var sp = value.IndexOf("+");
156-
var sm = value.IndexOf("-");
154+
var d = value.IndexOf(".", StringComparison.Ordinal);
155+
var sp = value.IndexOf("+", StringComparison.Ordinal);
156+
var sm = value.IndexOf("-", StringComparison.Ordinal);
157157
var indexOfSign = -1;
158-
var offsetExists = false;
159-
if ((sp != -1) || (sm != -1))
160-
{
161-
offsetExists = true;
162-
}
158+
var offsetExists = (sp != -1) || (sm != -1);
163159

164160
if (sp != -1)
165161
{
@@ -189,7 +185,7 @@ public virtual string Value
189185
{
190186
// The length of the GMT offset must be 5 characters (including the sign)
191187
var msg = "The length of the TM datatype value does not conform to an allowable" +
192-
" format. Format should conform to HH[MM[SS[.S[S[S[S]]]]]][+/-ZZZZ]";
188+
" format. Format should conform to HH[MM[SS[.S[S[S[S]]]]]][+/-ZZZZ]";
193189
var e = new DataTypeException(msg);
194190
throw e;
195191
}
@@ -201,7 +197,7 @@ public virtual string Value
201197
if ((timeVal.Length < 8) || (timeVal.Length > 11))
202198
{
203199
var msg = "The length of the TM datatype value does not conform to an allowable" +
204-
" format. Format should conform to HH[MM[SS[.S[S[S[S]]]]]][+/-ZZZZ]";
200+
" format. Format should conform to HH[MM[SS[.S[S[S[S]]]]]][+/-ZZZZ]";
205201
var e = new DataTypeException(msg);
206202
throw e;
207203
}
@@ -214,7 +210,7 @@ public virtual string Value
214210
if ((timeVal.Length != 2) && (timeVal.Length != 4) && (timeVal.Length != 6))
215211
{
216212
var msg = "The length of the TM datatype value does not conform to an allowable" +
217-
" format. Format should conform to HH[MM[SS[.S[S[S[S]]]]]][+/-ZZZZ]";
213+
" format. Format should conform to HH[MM[SS[.S[S[S[S]]]]]][+/-ZZZZ]";
218214
var e = new DataTypeException(msg);
219215
throw e;
220216
}

src/NHapi.Base/Model/Primitive/CommonTS.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ public virtual string Value
206206
string dateVal = null;
207207
string timeVal = null;
208208
string timeValLessOffset = null;
209-
var sp = value.IndexOf("+");
210-
var sm = value.IndexOf("-");
209+
var sp = value.IndexOf("+", StringComparison.Ordinal);
210+
var sm = value.IndexOf("-", StringComparison.Ordinal);
211211
var indexOfSign = -1;
212212
var offsetExists = false;
213213
var timeValIsOffsetOnly = false;
@@ -310,7 +310,7 @@ public virtual string Value
310310
tm = new CommonTM();
311311

312312
// first extract the + sign from the offset value string if it exists
313-
if (timeVal.IndexOf("+") == 0)
313+
if (timeVal.IndexOf("+", StringComparison.Ordinal) == 0)
314314
{
315315
timeVal = timeVal.Substring(1);
316316
} // end if

src/NHapi.Base/NHapi.Base.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<ItemGroup>
1616
<InternalsVisibleTo Include="$(AssemblyName).NUnit" />
17+
<InternalsVisibleTo Include="NHapi.NUnit" />
1718
<InternalsVisibleTo Include="NHapi.SourceGeneration" />
1819
</ItemGroup>
1920

@@ -43,4 +44,4 @@
4344
</PackageReference>
4445
</ItemGroup>
4546

46-
</Project>
47+
</Project>

src/NHapi.Base/Parser/DefaultModelClassFactory.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@ namespace NHapi.Base.Parser
2222
public class DefaultModelClassFactory : IModelClassFactory
2323
{
2424
private static readonly object LockObject = new object();
25-
private static readonly IHapiLog Log;
25+
private static readonly IHapiLog Log = HapiLogFactory.GetHapiLog(typeof(DefaultModelClassFactory));
2626
private static Hashtable packages = null;
2727
private static bool isLoadingPackages = false;
2828

29-
static DefaultModelClassFactory()
30-
{
31-
Log = HapiLogFactory.GetHapiLog(typeof(DefaultModelClassFactory));
32-
}
33-
3429
/// <summary>
3530
/// <para>Lists all the packages (user-definable) where classes for standard and custom
3631
/// messages may be found. Each package has sub-packages called "message",

0 commit comments

Comments
 (0)