Enumerator support for node collections
This commit is contained in:
parent
cc62e18e4e
commit
1e12269490
@ -46,6 +46,21 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
TXMLNodeCollectionEnumerator = class(TInterfacedObject)
|
||||||
|
private
|
||||||
|
FNodeCollection: IXMLNodeCollection;
|
||||||
|
FIndex: Integer;
|
||||||
|
public
|
||||||
|
constructor Create(ANodeCollection: IXMLNodeCollection);
|
||||||
|
|
||||||
|
function GetCurrent: IXMLNode;
|
||||||
|
function MoveNext: Boolean; virtual;
|
||||||
|
|
||||||
|
property Current: IXMLNode read GetCurrent;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const
|
const
|
||||||
AllTimeFragments = [Low(TXMLTimeFragment)..High(TXMLTimeFragment)];
|
AllTimeFragments = [Low(TXMLTimeFragment)..High(TXMLTimeFragment)];
|
||||||
|
|
||||||
@ -160,6 +175,33 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{ TXMLNodeCollectionEnumerator }
|
||||||
|
constructor TXMLNodeCollectionEnumerator.Create(ANodeCollection: IXMLNodeCollection);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
|
||||||
|
FNodeCollection := ANodeCollection;
|
||||||
|
FIndex := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TXMLNodeCollectionEnumerator.GetCurrent: IXMLNode;
|
||||||
|
begin
|
||||||
|
if (FIndex >= 0) and (FIndex < FNodeCollection.Count) then
|
||||||
|
Result := FNodeCollection.Nodes[FIndex]
|
||||||
|
else
|
||||||
|
Result := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TXMLNodeCollectionEnumerator.MoveNext: Boolean;
|
||||||
|
begin
|
||||||
|
Inc(FIndex);
|
||||||
|
Result := (FIndex < FNodeCollection.Count);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function DateTimeToXML(ADate: TDateTime; AFormat: TXMLDateTimeFormat; ATimeFragments: TXMLTimeFragments): string;
|
function DateTimeToXML(ADate: TDateTime; AFormat: TXMLDateTimeFormat; ATimeFragments: TXMLTimeFragments): string;
|
||||||
var
|
var
|
||||||
formatSettings: TFormatSettings;
|
formatSettings: TFormatSettings;
|
||||||
|
@ -69,6 +69,8 @@ type
|
|||||||
procedure WriteSchemaEnumerationArray(AStream: TStreamHelper; AItem: TXMLDataBindingEnumeration);
|
procedure WriteSchemaEnumerationArray(AStream: TStreamHelper; AItem: TXMLDataBindingEnumeration);
|
||||||
|
|
||||||
procedure WriteValidate(AStream: TStreamHelper; AItem: TXMLDataBindingInterface; ASection: TDelphiXMLSection);
|
procedure WriteValidate(AStream: TStreamHelper; AItem: TXMLDataBindingInterface; ASection: TDelphiXMLSection);
|
||||||
|
procedure WriteEnumeratorMethod(AStream: TStreamHelper; AItem: TXMLDataBindingInterface; ASection: TDelphiXMLSection);
|
||||||
|
procedure WriteEnumerator(AStream: TStreamHelper; AItem: TXMLDataBindingInterface; ASection: TDelphiXMLSection);
|
||||||
|
|
||||||
function GetDelphiNodeType(AProperty: TXMLDataBindingProperty): TDelphiNodeType;
|
function GetDelphiNodeType(AProperty: TXMLDataBindingProperty): TDelphiNodeType;
|
||||||
function GetDelphiElementType(AProperty: TXMLDataBindingProperty): TDelphiElementType;
|
function GetDelphiElementType(AProperty: TXMLDataBindingProperty): TDelphiElementType;
|
||||||
@ -695,8 +697,10 @@ begin
|
|||||||
if Assigned(AItem.BaseItem) then
|
if Assigned(AItem.BaseItem) then
|
||||||
parent := PrefixInterface + AItem.BaseItem.TranslatedName
|
parent := PrefixInterface + AItem.BaseItem.TranslatedName
|
||||||
else if AItem.IsCollection then
|
else if AItem.IsCollection then
|
||||||
parent := CollectionInterface
|
begin
|
||||||
else
|
parent := CollectionInterface;
|
||||||
|
WriteEnumerator(AStream, AItem, ASection);
|
||||||
|
end else
|
||||||
parent := ItemInterface;
|
parent := ItemInterface;
|
||||||
|
|
||||||
|
|
||||||
@ -717,8 +721,10 @@ begin
|
|||||||
if Assigned(AItem.BaseItem) then
|
if Assigned(AItem.BaseItem) then
|
||||||
parent := PrefixClass + AItem.BaseItem.TranslatedName
|
parent := PrefixClass + AItem.BaseItem.TranslatedName
|
||||||
else if AItem.IsCollection then
|
else if AItem.IsCollection then
|
||||||
parent := CollectionClass
|
begin
|
||||||
else
|
parent := CollectionClass;
|
||||||
|
WriteEnumerator(AStream, AItem, ASection);
|
||||||
|
end else
|
||||||
parent := ItemClass;
|
parent := ItemClass;
|
||||||
|
|
||||||
|
|
||||||
@ -738,6 +744,7 @@ begin
|
|||||||
|
|
||||||
dxsImplementation:
|
dxsImplementation:
|
||||||
begin
|
begin
|
||||||
|
WriteEnumerator(AStream, AItem, ASection);
|
||||||
WriteSchemaInterfaceProperties(AStream, AItem, ASection);
|
WriteSchemaInterfaceProperties(AStream, AItem, ASection);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -937,6 +944,7 @@ begin
|
|||||||
AStream.WriteLn(' protected');
|
AStream.WriteLn(' protected');
|
||||||
|
|
||||||
WriteValidate(AStream, AItem, ASection);
|
WriteValidate(AStream, AItem, ASection);
|
||||||
|
WriteEnumeratorMethod(AStream, AItem, ASection);
|
||||||
hasMembers := WriteSchemaInterfaceCollectionProperties(AStream, AItem, ASection);
|
hasMembers := WriteSchemaInterfaceCollectionProperties(AStream, AItem, ASection);
|
||||||
|
|
||||||
for member := Low(TDelphiXMLMember) to High(TDelphiXMLMember) do
|
for member := Low(TDelphiXMLMember) to High(TDelphiXMLMember) do
|
||||||
@ -1594,6 +1602,63 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TDelphiXMLDataBindingGenerator.WriteEnumeratorMethod(AStream: TStreamHelper; AItem: TXMLDataBindingInterface; ASection: TDelphiXMLSection);
|
||||||
|
begin
|
||||||
|
if not AItem.IsCollection then
|
||||||
|
Exit;
|
||||||
|
|
||||||
|
case ASection of
|
||||||
|
dxsInterface,
|
||||||
|
dxsClass:
|
||||||
|
begin
|
||||||
|
AStream.WriteLnNamedFmt(EnumeratorMethodInterface,
|
||||||
|
['Name', AItem.TranslatedName]);
|
||||||
|
AStream.WriteLn('');
|
||||||
|
end;
|
||||||
|
|
||||||
|
dxsImplementation:
|
||||||
|
begin
|
||||||
|
AStream.WriteLnNamedFmt(EnumeratorMethodImplementation,
|
||||||
|
['Name', AItem.TranslatedName]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
procedure TDelphiXMLDataBindingGenerator.WriteEnumerator(AStream: TStreamHelper; AItem: TXMLDataBindingInterface; ASection: TDelphiXMLSection);
|
||||||
|
begin
|
||||||
|
if not AItem.IsCollection then
|
||||||
|
Exit;
|
||||||
|
|
||||||
|
case ASection of
|
||||||
|
dxsInterface:
|
||||||
|
begin
|
||||||
|
AStream.WriteLnNamedFmt(EnumeratorInterface,
|
||||||
|
['Name', AItem.TranslatedName,
|
||||||
|
'ItemName', AItem.CollectionItem.TranslatedName,
|
||||||
|
'GUID', CreateNewGUID]);
|
||||||
|
AStream.WriteLn('');
|
||||||
|
end;
|
||||||
|
|
||||||
|
dxsClass:
|
||||||
|
begin
|
||||||
|
AStream.WriteLnNamedFmt(EnumeratorClass,
|
||||||
|
['Name', AItem.TranslatedName,
|
||||||
|
'ItemName', AItem.CollectionItem.TranslatedName]);
|
||||||
|
AStream.WriteLn('');
|
||||||
|
end;
|
||||||
|
|
||||||
|
dxsImplementation:
|
||||||
|
begin
|
||||||
|
AStream.WriteLnNamedFmt(EnumeratorImplementation,
|
||||||
|
['Name', AItem.TranslatedName,
|
||||||
|
'ItemName', AItem.CollectionItem.TranslatedName]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TDelphiXMLDataBindingGenerator.GetDelphiNodeType(AProperty: TXMLDataBindingProperty): TDelphiNodeType;
|
function TDelphiXMLDataBindingGenerator.GetDelphiNodeType(AProperty: TXMLDataBindingProperty): TDelphiNodeType;
|
||||||
begin
|
begin
|
||||||
if AProperty.IsAttribute then
|
if AProperty.IsAttribute then
|
||||||
|
@ -98,6 +98,31 @@ const
|
|||||||
XSDValidateMethodImplementationEnd = 'end;' + CrLf;
|
XSDValidateMethodImplementationEnd = 'end;' + CrLf;
|
||||||
|
|
||||||
|
|
||||||
|
EnumeratorMethodInterface = ' function GetEnumerator: IXML%<Name>:sEnumerator;';
|
||||||
|
EnumeratorMethodImplementation = 'function TXML%<Name>:s.GetEnumerator: IXML%<Name>:sEnumerator;' + CrLf +
|
||||||
|
'begin' + CrLf +
|
||||||
|
' Result := TXML%<Name>:sEnumerator.Create(Self);' + CrLf +
|
||||||
|
'end;' + CrLf;
|
||||||
|
|
||||||
|
|
||||||
|
EnumeratorInterface = ' IXML%<Name>:sEnumerator = interface' + CrLf +
|
||||||
|
' %<GUID>:s' + CrLf +
|
||||||
|
' function GetCurrent: IXML%<ItemName>:s;' + CrLf +
|
||||||
|
' function MoveNext: Boolean;' + CrLf +
|
||||||
|
' property Current: IXML%<ItemName>:s read GetCurrent;' + CrLf +
|
||||||
|
' end;' + CrLf;
|
||||||
|
|
||||||
|
|
||||||
|
EnumeratorClass = ' TXML%<Name>:sEnumerator = class(TXMLNodeCollectionEnumerator, IXML%<Name>:sEnumerator)' + CrLf +
|
||||||
|
' protected' + CrLf +
|
||||||
|
' function GetCurrent: IXML%<ItemName>:s;' + CrLf +
|
||||||
|
' end;' + CrLf;
|
||||||
|
|
||||||
|
EnumeratorImplementation = 'function TXML%<Name>:sEnumerator.GetCurrent: IXML%<ItemName>:s;' + CrLf +
|
||||||
|
'begin' + CrLf +
|
||||||
|
' Result := (inherited GetCurrent as IXML%<ItemName>:s);' + CrLf +
|
||||||
|
'end;' + CrLf;
|
||||||
|
|
||||||
PropertyIntfMethodGetOptional = ' function GetHas%<PropertyName>:s: Boolean;';
|
PropertyIntfMethodGetOptional = ' function GetHas%<PropertyName>:s: Boolean;';
|
||||||
PropertyIntfMethodGetNil = ' function Get%<PropertyName>:sIsNil: Boolean;';
|
PropertyIntfMethodGetNil = ' function Get%<PropertyName>:sIsNil: Boolean;';
|
||||||
PropertyIntfMethodGetText = ' function Get%<PropertyName>:sText: WideString;';
|
PropertyIntfMethodGetText = ' function Get%<PropertyName>:sText: WideString;';
|
||||||
|
Loading…
Reference in New Issue
Block a user