1
0
mirror of synced 2024-11-14 19:13:50 +00:00

Changed: collection behaviour (not yet finished - waiting for named Format implementation)

This commit is contained in:
Mark van Renswoude 2008-03-14 15:35:07 +00:00
parent 3df5f92709
commit 478551716c
10 changed files with 217 additions and 67 deletions

View File

@ -5,15 +5,15 @@
<Name>01. Basic simple and complex types</Name> <Name>01. Basic simple and complex types</Name>
<Items> <Items>
<Item> <Item>
<ItemType>Interface</ItemType>
<Name>TestElement</Name> <Name>TestElement</Name>
<ItemType>Interface</ItemType>
<Interface> <Interface>
<InterfaceType>Interface</InterfaceType> <InterfaceType>Interface</InterfaceType>
</Interface> </Interface>
</Item> </Item>
<Item> <Item>
<ItemType>Interface</ItemType>
<Name>TestComplexType</Name> <Name>TestComplexType</Name>
<ItemType>Interface</ItemType>
<Interface> <Interface>
<InterfaceType>ComplexType</InterfaceType> <InterfaceType>ComplexType</InterfaceType>
</Interface> </Interface>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="ComplexParts">
<xs:complexType>
<xs:sequence>
<xs:element name="ComplexPart" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="ComplexValue" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="SimpleParts">
<xs:complexType>
<xs:sequence>
<xs:element name="SimpleValue" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<DataBindingResult xsi:noNamespaceSchemaLocation="F:\Archive\2007\XMLDataBinding\Tests\XSD\DataBindingResult.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Schemas>
<Schema>
<Name>02. Collection</Name>
<Items>
<Item>
<Name>Root</Name>
<ItemType>Interface</ItemType>
<Interface>
<InterfaceType>Interface</InterfaceType>
</Interface>
</Item>
<!-- TODO: Parts moet worden gecollapsed naar een ItemType Collection -->
<Item>
<Name>ComplexParts</Name>
<ItemType>Interface</ItemType>
<Interface>
<InterfaceType>Interface</InterfaceType>
</Interface>
</Item>
<Item>
<ItemType>Collection</ItemType>
<Name>ComplexPartList</Name>
<Collection>
<ItemName>ComplexPart</ItemName>
</Collection>
</Item>
<Item>
<Name>ComplexPart</Name>
<ItemType>Interface</ItemType>
<Interface>
<InterfaceType>Interface</InterfaceType>
</Interface>
</Item>
<Item>
<Name>SimpleParts</Name>
<ItemType>Interface</ItemType>
<Interface>
<InterfaceType>Interface</InterfaceType>
</Interface>
</Item>
<Item>
<ItemType>Collection</ItemType>
<Name>SimpleValueList</Name>
<Collection>
<ItemName>SimpleValue</ItemName>
</Collection>
</Item>
</Items>
</Schema>
</Schemas>
</DataBindingResult>

View File

@ -23,6 +23,7 @@ type
procedure CompareSchemas(ATestResult: TTestResult; AGenerator: TTestXMLDataBindingGenerator; AResult: IXMLDataBindingResult); procedure CompareSchemas(ATestResult: TTestResult; AGenerator: TTestXMLDataBindingGenerator; AResult: IXMLDataBindingResult);
procedure CompareItems(ATestResult: TTestResult; AGeneratorSchema: TXMLDataBindingSchema; AResultSchema: IXMLSchema); procedure CompareItems(ATestResult: TTestResult; AGeneratorSchema: TXMLDataBindingSchema; AResultSchema: IXMLSchema);
procedure CompareCollection(ATestResult: TTestResult; AGeneratorSchema: TXMLDataBindingSchema; AGeneratorItem: TXMLDataBindingCollection; AResultItem: IXMLItem);
property FileName: String read FFileName; property FileName: String read FFileName;
public public
@ -134,21 +135,33 @@ end;
procedure TObjectMappingTests.CompareItems(ATestResult: TTestResult; AGeneratorSchema: TXMLDataBindingSchema; AResultSchema: IXMLSchema); procedure TObjectMappingTests.CompareItems(ATestResult: TTestResult; AGeneratorSchema: TXMLDataBindingSchema; AResultSchema: IXMLSchema);
function FindItem(const AName: String): TXMLDataBindingItem; function FindItem(const AResultItem: IXMLItem): TXMLDataBindingItem;
var var
itemType: TXMLDataBindingItemType;
itemIndex: Integer; itemIndex: Integer;
item: TXMLDataBindingItem;
begin begin
Result := nil; Result := nil;
itemType := itInterface;
if AResultItem.ItemType = 'Collection' then
itemType := itCollection
else if AResultItem.ItemType = 'Enumeration' then
itemType := itEnumeration;
for itemIndex := 0 to Pred(AGeneratorSchema.ItemCount) do for itemIndex := 0 to Pred(AGeneratorSchema.ItemCount) do
if (AGeneratorSchema.Items[itemIndex].Name = AName) and
(AGeneratorSchema.Items[itemIndex].ItemType <> itForward) then
begin begin
Result := AGeneratorSchema.Items[itemIndex]; item := AGeneratorSchema.Items[itemIndex];
if (item.ItemType = itemType) and
(item.Name = AResultItem.Name) then
begin
Result := item;
break; break;
end; end;
end; end;
end;
var var
@ -160,22 +173,26 @@ var
begin begin
handled := TObjectList.Create(False); handled := TObjectList.Create(False);
try try
{ Iterate expected schemas } { Iterate expected items }
for itemIndex := 0 to Pred(AResultSchema.Items.Count) do for itemIndex := 0 to Pred(AResultSchema.Items.Count) do
begin begin
resultItem := AResultSchema.Items[itemIndex]; resultItem := AResultSchema.Items[itemIndex];
bindingItem := FindItem(resultItem.Name); bindingItem := FindItem(resultItem);
if Assigned(bindingItem) then if Assigned(bindingItem) then
begin begin
handled.Add(bindingItem); handled.Add(bindingItem);
// CompareItems(ATestResult, bindingSchema, resultSchema);
case bindingItem.ItemType of
// itInterface: CompareProperties;
itCollection: CompareCollection(ATestResult, AGeneratorSchema, TXMLDataBindingCollection(bindingItem), resultItem);
end;
end else end else
ATestResult.AddFailure(Self, nil, Format('Schema "%s": item "%s" expected', ATestResult.AddFailure(Self, nil, Format('Item "%s.%s" expected',
[AGeneratorSchema.SchemaName, resultItem.Name])); [AGeneratorSchema.SchemaName, resultItem.Name]));
end; end;
{ Find unexpected schemas } { Find unexpected items }
for itemIndex := 0 to Pred(AGeneratorSchema.ItemCount) do for itemIndex := 0 to Pred(AGeneratorSchema.ItemCount) do
begin begin
bindingItem := AGeneratorSchema.Items[itemIndex]; bindingItem := AGeneratorSchema.Items[itemIndex];
@ -184,7 +201,7 @@ begin
begin begin
if handled.IndexOf(bindingItem) = -1 then if handled.IndexOf(bindingItem) = -1 then
begin begin
ATestResult.AddFailure(Self, nil, Format('Schema "%s": item "%s" not expected', ATestResult.AddFailure(Self, nil, Format('Item "%s.%s" not expected',
[AGeneratorSchema.SchemaName, [AGeneratorSchema.SchemaName,
AGeneratorSchema.Items[itemIndex].Name])); AGeneratorSchema.Items[itemIndex].Name]));
end; end;
@ -196,6 +213,23 @@ begin
end; end;
procedure TObjectMappingTests.CompareCollection(ATestResult: TTestResult; AGeneratorSchema: TXMLDataBindingSchema; AGeneratorItem: TXMLDataBindingCollection; AResultItem: IXMLItem);
begin
if Assigned(AGeneratorItem.CollectionItem) then
begin
if AGeneratorItem.CollectionItem.Name <> AResultItem.Collection.ItemName then
ATestResult.AddFailure(Self, nil, Format('Item "%s.%s": collection item "%s" expected but "%s" found',
[AGeneratorSchema.SchemaName,
AGeneratorItem.Name,
AResultItem.Collection.ItemName,
AGeneratorItem.CollectionItem.Name]));
end else
ATestResult.AddFailure(Self, nil, Format('Item "%s.%s": collection item not Assigned',
[AGeneratorSchema.SchemaName,
AGeneratorItem.Name]));
end;
{ TTestXMLDataBindingGenerator } { TTestXMLDataBindingGenerator }
procedure TTestXMLDataBindingGenerator.GenerateDataBinding(); procedure TTestXMLDataBindingGenerator.GenerateDataBinding();
begin begin

View File

@ -33,9 +33,9 @@
-$M16384,1048576 -$M16384,1048576
-K$00400000 -K$00400000
-E"..\" -E"..\"
-N0"..\Lib" -N"..\Lib"
-LE"C:\Documents and Settings\PsychoMark\My Documents\Borland Studio Projects\Bpl" -LE"c:\program files\borland\delphi7\Projects\Bpl"
-LN"C:\Documents and Settings\PsychoMark\My Documents\Borland Studio Projects\Bpl" -LN"c:\program files\borland\delphi7\Projects\Bpl"
-w-UNSAFE_TYPE -w-UNSAFE_TYPE
-w-UNSAFE_CODE -w-UNSAFE_CODE
-w-UNSAFE_CAST -w-UNSAFE_CAST

View File

@ -140,9 +140,5 @@ C:\Program Files\Borland\Indy\D7\dclIndy70.bpl=Internet Direct (Indy) for D7 Pro
Count=1 Count=1
Item0=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; Item0=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
[HistoryLists\hlUnitOutputDirectory] [HistoryLists\hlUnitOutputDirectory]
Count=2
Item0=..\Lib
Item1=Lib
[HistoryLists\hlOutputDirectorry]
Count=1 Count=1
Item0=..\ Item0=Lib

View File

@ -31,8 +31,8 @@
</xs:complexType> </xs:complexType>
<xs:complexType name="Item"> <xs:complexType name="Item">
<xs:sequence> <xs:sequence>
<xs:element ref="ItemType"/>
<xs:element name="Name" type="xs:string"/> <xs:element name="Name" type="xs:string"/>
<xs:element ref="ItemType"/>
<xs:choice> <xs:choice>
<xs:element name="Interface"> <xs:element name="Interface">
<xs:complexType> <xs:complexType>

View File

@ -295,9 +295,6 @@ begin
Result := DelphiSafeName(inherited TranslateItemName(AItem)); Result := DelphiSafeName(inherited TranslateItemName(AItem));
case AItem.ItemType of case AItem.ItemType of
itCollection:
Result := Result + 'List';
itEnumerationMember: itEnumerationMember:
Result := TXMLDataBindingEnumerationMember(AItem).Enumeration.TranslatedName + '_' + Result; Result := TXMLDataBindingEnumerationMember(AItem).Enumeration.TranslatedName + '_' + Result;
end; end;
@ -945,11 +942,14 @@ end;
procedure TDelphiXMLDataBindingGenerator.WriteSchemaCollectionProperties(AStream: TStreamHelper; AItem: TXMLDataBindingCollection; ASection: TDelphiXMLSection); procedure TDelphiXMLDataBindingGenerator.WriteSchemaCollectionProperties(AStream: TStreamHelper; AItem: TXMLDataBindingCollection; ASection: TDelphiXMLSection);
var
dataTypeName: string;
procedure WriteMethodInterface(const AFunction: String); procedure WriteMethodInterface(const AFunction: String);
begin begin
AStream.WriteLnFmt(' function ' + AFunction + ': %1:s%0:s;', AStream.WriteLnFmt(' function ' + AFunction + ': %1:s%0:s;',
[AItem.CollectionItem.TranslatedName, [dataTypeName,
PrefixInterface]); PrefixInterface]);
end; end;
@ -958,13 +958,13 @@ procedure TDelphiXMLDataBindingGenerator.WriteSchemaCollectionProperties(AStream
begin begin
AStream.WriteLnFmt('function %3:s%0:s.' + AFunction + ': %2:s%1:s;', AStream.WriteLnFmt('function %3:s%0:s.' + AFunction + ': %2:s%1:s;',
[AItem.TranslatedName, [AItem.TranslatedName,
AItem.CollectionItem.TranslatedName, dataTypeName,
PrefixInterface, PrefixInterface,
PrefixClass]); PrefixClass]);
AStream.WriteLn('begin'); AStream.WriteLn('begin');
AStream.WriteLnFmt(AImplementation, AStream.WriteLnFmt(AImplementation,
[AItem.CollectionItem.TranslatedName, [dataTypeName,
PrefixInterface]); PrefixInterface]);
AStream.WriteLn('end;'); AStream.WriteLn('end;');
@ -994,7 +994,7 @@ begin
AStream.WriteLnFmt(' RegisterChildNode(''%0:s'', %2:s%1:s);', AStream.WriteLnFmt(' RegisterChildNode(''%0:s'', %2:s%1:s);',
[AItem.CollectionItem.Name, [AItem.CollectionItem.Name,
AItem.CollectionItem.TranslatedName, dataTypeName,
PrefixClass]); PrefixClass]);
AStream.WriteLn(); AStream.WriteLn();
@ -1002,7 +1002,7 @@ begin
[AItem.CollectionItem.Name]); [AItem.CollectionItem.Name]);
AStream.WriteLnFmt(' ItemInterface := %1:s%0:s;', AStream.WriteLnFmt(' ItemInterface := %1:s%0:s;',
[AItem.CollectionItem.TranslatedName, [dataTypeName,
PrefixInterface]); PrefixInterface]);
AStream.WriteLn(); AStream.WriteLn();
@ -1026,7 +1026,7 @@ begin
begin begin
AStream.WriteLn; AStream.WriteLn;
AStream.WriteLnFmt(' property %0:s[Index: Integer]: %1:s%0:s read Get_%0:s; default;', AStream.WriteLnFmt(' property %0:s[Index: Integer]: %1:s%0:s read Get_%0:s; default;',
[AItem.CollectionItem.TranslatedName, [dataTypeName,
PrefixInterface]); PrefixInterface]);
end; end;

View File

@ -64,6 +64,7 @@ type
function FindEnumeration(ASchema: TXMLDataBindingSchema; const AName: String): TXMLDataBindingEnumeration; function FindEnumeration(ASchema: TXMLDataBindingSchema; const AName: String): TXMLDataBindingEnumeration;
procedure ResolveSchema(ASchema: TXMLDataBindingSchema); procedure ResolveSchema(ASchema: TXMLDataBindingSchema);
procedure ResolveItem(ASchema: TXMLDataBindingSchema; AItem: TXMLDataBindingItem);
procedure ResolveNameConflicts(); procedure ResolveNameConflicts();
procedure TranslateSchema(ASchema: TXMLDataBindingSchema); procedure TranslateSchema(ASchema: TXMLDataBindingSchema);
@ -176,13 +177,13 @@ type
TXMLDataBindingCollection = class(TXMLDataBindingItem) TXMLDataBindingCollection = class(TXMLDataBindingItem)
private private
FCollectionItem: TXMLDataBindingInterface; FCollectionItem: TXMLDataBindingProperty;
procedure SetCollectionItem(const Value: TXMLDataBindingProperty);
protected protected
function GetItemType(): TXMLDataBindingItemType; override; function GetItemType(): TXMLDataBindingItemType; override;
public public
constructor Create(ASchemaItem: IXMLSchemaItem; ACollectionItem: TXMLDataBindingInterface; const AName: String); property CollectionItem: TXMLDataBindingProperty read FCollectionItem;
property CollectionItem: TXMLDataBindingInterface read FCollectionItem;
end; end;
@ -286,6 +287,7 @@ uses
const const
MaxOccursUnbounded = 'unbounded'; MaxOccursUnbounded = 'unbounded';
CollectionPostfix = 'List';
@ -595,6 +597,7 @@ begin
end; end;
if Assigned(interfaceObject) then
for elementIndex := 0 to Pred(AElement.ChildElements.Count) do for elementIndex := 0 to Pred(AElement.ChildElements.Count) do
ProcessChildElement(ASchema, AElement.ChildElements[elementIndex], interfaceObject); ProcessChildElement(ASchema, AElement.ChildElements[elementIndex], interfaceObject);
end; end;
@ -622,7 +625,7 @@ begin
if not Assigned(collectionObject) then if not Assigned(collectionObject) then
begin begin
collectionObject := TXMLDataBindingCollection.Create(AELement, AInterface, AElement.Name); collectionObject := TXMLDataBindingCollection.Create(AElement, AElement.Name + CollectionPostfix);
ASchema.AddItem(collectionObject); ASchema.AddItem(collectionObject);
end; end;
end; end;
@ -630,8 +633,23 @@ begin
propertyType := ProcessElement(ASchema, AElement); propertyType := ProcessElement(ASchema, AElement);
if Assigned(collectionObject) then if Assigned(collectionObject) then
begin
{ Create intermediate object for collections }
if Assigned(propertyType) then
propertyItem := TXMLDataBindingItemProperty.Create(AElement,
AElement.Name,
propertyType)
else
propertyItem := TXMLDataBindingSimpleProperty.Create(AElement,
AElement.Name,
AElement.DataType);
collectionObject.SetCollectionItem(propertyItem);
propertyType := collectionObject; propertyType := collectionObject;
end;
if Assigned(AInterface) then if Assigned(AInterface) then
@ -732,9 +750,16 @@ end;
procedure TXMLDataBindingGenerator.FindCollectionProc(AItem: TXMLDataBindingItem; AData: Pointer; var AAbort: Boolean); procedure TXMLDataBindingGenerator.FindCollectionProc(AItem: TXMLDataBindingItem; AData: Pointer; var AAbort: Boolean);
var
collection: TXMLDataBindingCollection;
begin begin
AAbort := (AItem.ItemType = itCollection) and if AItem.ItemType = itCollection then
(AItem.Name = PChar(AData)); begin
collection := TXMLDataBindingCollection(AItem);
AAbort := Assigned(collection.CollectionItem) and
(collection.CollectionItem.Name = PChar(AData));
end;
end; end;
@ -749,8 +774,6 @@ procedure TXMLDataBindingGenerator.ResolveSchema(ASchema: TXMLDataBindingSchema)
var var
itemIndex: Integer; itemIndex: Integer;
item: TXMLDataBindingItem; item: TXMLDataBindingItem;
forwardItem: TXMLDataBindingForwardItem;
referenceItem: TXMLDataBindingItem;
interfaceItem: TXMLDataBindingInterface; interfaceItem: TXMLDataBindingInterface;
begin begin
@ -769,20 +792,31 @@ begin
end; end;
itForward: itForward:
ResolveItem(ASchema, item);
end;
end;
end;
procedure TXMLDataBindingGenerator.ResolveItem(ASchema: TXMLDataBindingSchema; AItem: TXMLDataBindingItem);
var
forwardItem: TXMLDataBindingForwardItem;
referenceItem: TXMLDataBindingItem;
begin begin
if (not Assigned(AItem)) or (AItem.ItemType <> itForward) then
Exit;
{ Resolve forwarded item } { Resolve forwarded item }
forwardItem := TXMLDataBindingForwardItem(item); forwardItem := TXMLDataBindingForwardItem(AItem);
referenceItem := FindInterface(ASchema, item.Name, forwardItem.InterfaceType); referenceItem := FindInterface(ASchema, AItem.Name, forwardItem.InterfaceType);
if (not Assigned(referenceItem)) and if (not Assigned(referenceItem)) and
(forwardItem.InterfaceType = ifElement) then (forwardItem.InterfaceType = ifElement) then
referenceItem := FindEnumeration(ASchema, item.Name); referenceItem := FindEnumeration(ASchema, AItem.Name);
if Assigned(referenceItem) then if Assigned(referenceItem) then
TXMLDataBindingForwardItem(item).Item := referenceItem; forwardItem.Item := referenceItem;
end;
end;
end;
end; end;
@ -1120,20 +1154,18 @@ end;
{ TXMLDataBindingCollection } { TXMLDataBindingCollection }
constructor TXMLDataBindingCollection.Create(ASchemaItem: IXMLSchemaItem; ACollectionItem: TXMLDataBindingInterface; const AName: String);
begin
inherited Create(ASchemaItem, AName);
FCollectionItem := ACollectionItem;
end;
function TXMLDataBindingCollection.GetItemType(): TXMLDataBindingItemType; function TXMLDataBindingCollection.GetItemType(): TXMLDataBindingItemType;
begin begin
Result := itCollection; Result := itCollection;
end; end;
procedure TXMLDataBindingCollection.SetCollectionItem(const Value: TXMLDataBindingProperty);
begin
FCollectionItem := Value;
end;
{ TXMLDataBindingEnumerationMember } { TXMLDataBindingEnumerationMember }
constructor TXMLDataBindingEnumerationMember.Create(AEnumeration: TXMLDataBindingEnumeration; const AName: String); constructor TXMLDataBindingEnumerationMember.Create(AEnumeration: TXMLDataBindingEnumeration; const AName: String);
begin begin

View File

@ -100,7 +100,7 @@ Conditionals=
DebugSourceDirs= DebugSourceDirs=
UsePackages=0 UsePackages=0
[Parameters] [Parameters]
RunParams="P:\xtx\xtx\xsd\Offerte.xsd" "P:\xtx\xtx\xsd\xml_Offerte.pas" RunParams="p:\test\XMLDataBinding\Tests\Data\02. Collection.xsd" "P:\xtx\xtx\xsd\xml_Offerte.pas"
HostApplication= HostApplication=
Launcher= Launcher=
UseLauncher=0 UseLauncher=0