Fixed: support for global elements of a complex type
This commit is contained in:
parent
107589b839
commit
dba905ace4
@ -783,8 +783,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
ptItem:
|
ptItem:
|
||||||
begin
|
begin
|
||||||
dataTypeName := PrefixInterface + AItem.CollectionItem.TranslatedName;
|
dataTypeName := PrefixInterface + AItem.CollectionItemTranslatedName;
|
||||||
dataClassName := PrefixClass + AItem.CollectionItem.TranslatedName;
|
dataClassName := PrefixClass + AItem.CollectionItemTranslatedName;
|
||||||
dataIntfName := dataTypeName;
|
dataIntfName := dataTypeName;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -886,7 +886,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
AStream.Write(sourceCode.Format(['Name', AItem.TranslatedName,
|
AStream.Write(sourceCode.Format(['Name', AItem.TranslatedName,
|
||||||
'ItemName', AItem.CollectionItem.TranslatedName,
|
'ItemName', AItem.CollectionItemTranslatedName,
|
||||||
'ItemSourceName', AItem.CollectionItem.Name,
|
'ItemSourceName', AItem.CollectionItem.Name,
|
||||||
'DataType', dataTypeName,
|
'DataType', dataTypeName,
|
||||||
'DataClass', dataClassName,
|
'DataClass', dataClassName,
|
||||||
|
@ -21,7 +21,8 @@ type
|
|||||||
|
|
||||||
TXMLDataBindingOutputType = (otSingle, otMultiple);
|
TXMLDataBindingOutputType = (otSingle, otMultiple);
|
||||||
TXMLDataBindingItemType = (itInterface, itCollection, itEnumeration,
|
TXMLDataBindingItemType = (itInterface, itCollection, itEnumeration,
|
||||||
itEnumerationMember, itProperty, itForward);
|
itEnumerationMember, itProperty, itForward,
|
||||||
|
itComplexTypeElement);
|
||||||
TXMLDataBindingInterfaceType = (ifElement, ifComplexType);
|
TXMLDataBindingInterfaceType = (ifElement, ifComplexType);
|
||||||
TXMLDataBindingPropertyType = (ptSimple, ptItem);
|
TXMLDataBindingPropertyType = (ptSimple, ptItem);
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ type
|
|||||||
FSourceFileName: String;
|
FSourceFileName: String;
|
||||||
|
|
||||||
FSchemas: TObjectList;
|
FSchemas: TObjectList;
|
||||||
|
FMustResolve: Boolean;
|
||||||
|
|
||||||
function GetSchemaCount(): Integer;
|
function GetSchemaCount(): Integer;
|
||||||
function GetSchemas(Index: Integer): TXMLDataBindingSchema;
|
function GetSchemas(Index: Integer): TXMLDataBindingSchema;
|
||||||
@ -179,11 +181,16 @@ type
|
|||||||
private
|
private
|
||||||
FCollectionItem: TXMLDataBindingProperty;
|
FCollectionItem: TXMLDataBindingProperty;
|
||||||
|
|
||||||
|
function GetActualCollectionItem(): TXMLDataBindingItem;
|
||||||
|
function GetCollectionItemName(): String;
|
||||||
|
function GetCollectionItemTranslatedName(): String;
|
||||||
procedure SetCollectionItem(const Value: TXMLDataBindingProperty);
|
procedure SetCollectionItem(const Value: TXMLDataBindingProperty);
|
||||||
protected
|
protected
|
||||||
function GetItemType(): TXMLDataBindingItemType; override;
|
function GetItemType(): TXMLDataBindingItemType; override;
|
||||||
public
|
public
|
||||||
property CollectionItem: TXMLDataBindingProperty read FCollectionItem;
|
property CollectionItem: TXMLDataBindingProperty read FCollectionItem;
|
||||||
|
property CollectionItemName: String read GetCollectionItemName;
|
||||||
|
property CollectionItemTranslatedName: String read GetCollectionItemTranslatedName;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -275,12 +282,23 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
TXMLDataBindingComplexTypeElementItem = class(TXMLDataBindingItem)
|
||||||
|
private
|
||||||
|
FItem: TXMLDataBindingItem;
|
||||||
|
protected
|
||||||
|
function GetItemType(): TXMLDataBindingItemType; override;
|
||||||
|
public
|
||||||
|
property Item: TXMLDataBindingItem read FItem write FItem;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
uses
|
uses
|
||||||
SysUtils,
|
SysUtils,
|
||||||
Windows,
|
Windows,
|
||||||
XMLDoc,
|
XMLDoc,
|
||||||
XMLIntf,
|
XMLIntf,
|
||||||
|
XMLSchemaTags,
|
||||||
|
|
||||||
X2UtHashes;
|
X2UtHashes;
|
||||||
|
|
||||||
@ -300,6 +318,25 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function GetActualItem(AItem: TXMLDataBindingItem): TXMLDataBindingItem;
|
||||||
|
begin
|
||||||
|
Result := AItem;
|
||||||
|
|
||||||
|
while Assigned(Result) do
|
||||||
|
begin
|
||||||
|
case Result.ItemType of
|
||||||
|
itForward:
|
||||||
|
Result := TXMLDataBindingForwardItem(Result).Item;
|
||||||
|
|
||||||
|
itComplexTypeElement:
|
||||||
|
Result := TXMLDataBindingComplexTypeElementItem(Result).Item;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TXMLDataBindingGenerator }
|
{ TXMLDataBindingGenerator }
|
||||||
constructor TXMLDataBindingGenerator.Create();
|
constructor TXMLDataBindingGenerator.Create();
|
||||||
begin
|
begin
|
||||||
@ -340,7 +377,12 @@ begin
|
|||||||
GenerateSchemaObjects(Schemas[schemaIndex], (schemaIndex = 0));
|
GenerateSchemaObjects(Schemas[schemaIndex], (schemaIndex = 0));
|
||||||
|
|
||||||
|
|
||||||
{ Process unresolved references }
|
{ Process unresolved references
|
||||||
|
- some references can't be resolved the first time (especially
|
||||||
|
ComplexTypeElement references). Fix this workaround some time. }
|
||||||
|
for schemaIndex := 0 to Pred(SchemaCount) do
|
||||||
|
ResolveSchema(Schemas[schemaIndex]);
|
||||||
|
|
||||||
for schemaIndex := 0 to Pred(SchemaCount) do
|
for schemaIndex := 0 to Pred(SchemaCount) do
|
||||||
ResolveSchema(Schemas[schemaIndex]);
|
ResolveSchema(Schemas[schemaIndex]);
|
||||||
|
|
||||||
@ -551,6 +593,7 @@ var
|
|||||||
elementIndex: Integer;
|
elementIndex: Integer;
|
||||||
enumerationObject: TXMLDataBindingEnumeration;
|
enumerationObject: TXMLDataBindingEnumeration;
|
||||||
interfaceObject: TXMLDataBindingInterface;
|
interfaceObject: TXMLDataBindingInterface;
|
||||||
|
complexTypeElement: TXMLDataBindingComplexTypeElementItem;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result := nil;
|
Result := nil;
|
||||||
@ -569,7 +612,7 @@ begin
|
|||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
if (not AElement.DataType.IsAnonymous) and
|
if (not AElement.DataType.IsAnonymous) and
|
||||||
(AElement.DataType.IsComplex) then
|
AElement.DataType.IsComplex then
|
||||||
begin
|
begin
|
||||||
{ Find data type. If not found, mark as "resolve later". }
|
{ Find data type. If not found, mark as "resolve later". }
|
||||||
Result := FindInterface(ASchema, AElement.DataTypeName, ifComplexType);
|
Result := FindInterface(ASchema, AElement.DataTypeName, ifComplexType);
|
||||||
@ -579,6 +622,15 @@ begin
|
|||||||
Result := TXMLDataBindingForwardItem.Create(AElement, AElement.DataTypeName, ifComplexType);
|
Result := TXMLDataBindingForwardItem.Create(AElement, AElement.DataTypeName, ifComplexType);
|
||||||
ASchema.AddItem(Result);
|
ASchema.AddItem(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if AElement.IsGlobal then
|
||||||
|
begin
|
||||||
|
{ The element is global, but only references a complex type. Keep track
|
||||||
|
to properly resolve references to the element. }
|
||||||
|
complexTypeElement := TXMLDataBindingComplexTypeElementItem.Create(AElement, AElement.Name);
|
||||||
|
complexTypeElement.Item := Result;
|
||||||
|
ASchema.AddItem(complexTypeElement);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if not Assigned(Result) then
|
if not Assigned(Result) then
|
||||||
@ -643,7 +695,7 @@ begin
|
|||||||
{ Create intermediate object for collections }
|
{ Create intermediate object for collections }
|
||||||
if Assigned(propertyType) then
|
if Assigned(propertyType) then
|
||||||
propertyItem := TXMLDataBindingItemProperty.Create(AElement,
|
propertyItem := TXMLDataBindingItemProperty.Create(AElement,
|
||||||
AElement.Name,
|
propertyType.Name,
|
||||||
propertyType)
|
propertyType)
|
||||||
else
|
else
|
||||||
propertyItem := TXMLDataBindingSimpleProperty.Create(AElement,
|
propertyItem := TXMLDataBindingSimpleProperty.Create(AElement,
|
||||||
@ -722,10 +774,20 @@ var
|
|||||||
findInfo: PFindInterfaceInfo;
|
findInfo: PFindInterfaceInfo;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
AAbort := False;
|
||||||
findInfo := PFindInterfaceInfo(AData);
|
findInfo := PFindInterfaceInfo(AData);
|
||||||
AAbort := (AItem.ItemType = itInterface) and
|
|
||||||
(TXMLDataBindingInterface(AItem).InterfaceType = findInfo^.InterfaceType) and
|
|
||||||
(AItem.Name = findInfo^.Name);
|
if AItem.Name = findInfo^.Name then
|
||||||
|
begin
|
||||||
|
case AItem.ItemType of
|
||||||
|
itInterface:
|
||||||
|
AAbort := (TXMLDataBindingInterface(AItem).InterfaceType = findInfo^.InterfaceType);
|
||||||
|
|
||||||
|
itComplexTypeElement:
|
||||||
|
AAbort := (findInfo^.InterfaceType = ifElement);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -736,7 +798,7 @@ var
|
|||||||
begin
|
begin
|
||||||
findInfo.InterfaceType := AType;
|
findInfo.InterfaceType := AType;
|
||||||
findInfo.Name := AName;
|
findInfo.Name := AName;
|
||||||
Result := TXMLDataBindingInterface(IterateSchemaItems(ASchema, FindInterfaceProc, @findInfo));
|
Result := TXMLDataBindingInterface(GetActualItem(IterateSchemaItems(ASchema, FindInterfaceProc, @findInfo)));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -791,7 +853,8 @@ begin
|
|||||||
{ Resolve base interface }
|
{ Resolve base interface }
|
||||||
interfaceItem := TXMLDataBindingInterface(item);
|
interfaceItem := TXMLDataBindingInterface(item);
|
||||||
|
|
||||||
if Length(interfaceItem.BaseName) > 0 then
|
if (not Assigned(interfaceItem.BaseItem)) and
|
||||||
|
(Length(interfaceItem.BaseName) > 0) then
|
||||||
interfaceItem.BaseItem := FindInterface(ASchema, interfaceItem.BaseName, ifComplexType);
|
interfaceItem.BaseItem := FindInterface(ASchema, interfaceItem.BaseName, ifComplexType);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -813,6 +876,8 @@ begin
|
|||||||
|
|
||||||
{ Resolve forwarded item }
|
{ Resolve forwarded item }
|
||||||
forwardItem := TXMLDataBindingForwardItem(AItem);
|
forwardItem := TXMLDataBindingForwardItem(AItem);
|
||||||
|
if not Assigned(forwardItem.Item) then
|
||||||
|
begin
|
||||||
referenceItem := FindInterface(ASchema, AItem.Name, forwardItem.InterfaceType);
|
referenceItem := FindInterface(ASchema, AItem.Name, forwardItem.InterfaceType);
|
||||||
|
|
||||||
if (not Assigned(referenceItem)) and
|
if (not Assigned(referenceItem)) and
|
||||||
@ -822,6 +887,7 @@ begin
|
|||||||
if Assigned(referenceItem) then
|
if Assigned(referenceItem) then
|
||||||
forwardItem.Item := referenceItem;
|
forwardItem.Item := referenceItem;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TXMLDataBindingGenerator.ResolveNameConflicts();
|
procedure TXMLDataBindingGenerator.ResolveNameConflicts();
|
||||||
@ -1164,6 +1230,43 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TXMLDataBindingCollection.GetActualCollectionItem(): TXMLDataBindingItem;
|
||||||
|
begin
|
||||||
|
Result := nil;
|
||||||
|
|
||||||
|
if Assigned(CollectionItem) then
|
||||||
|
begin
|
||||||
|
case CollectionItem.PropertyType of
|
||||||
|
ptSimple: Result := CollectionItem;
|
||||||
|
ptItem: Result := TXMLDataBindingItemProperty(CollectionItem).Item;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TXMLDataBindingCollection.GetCollectionItemName(): String;
|
||||||
|
var
|
||||||
|
item: TXMLDataBindingItem;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Result := '';
|
||||||
|
item := GetActualCollectionItem();
|
||||||
|
if Assigned(item) then
|
||||||
|
Result := item.Name;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TXMLDataBindingCollection.GetCollectionItemTranslatedName(): String;
|
||||||
|
var
|
||||||
|
item: TXMLDataBindingItem;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Result := '';
|
||||||
|
item := GetActualCollectionItem();
|
||||||
|
if Assigned(item) then
|
||||||
|
Result := item.Name;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TXMLDataBindingCollection.SetCollectionItem(const Value: TXMLDataBindingProperty);
|
procedure TXMLDataBindingCollection.SetCollectionItem(const Value: TXMLDataBindingProperty);
|
||||||
begin
|
begin
|
||||||
FCollectionItem := Value;
|
FCollectionItem := Value;
|
||||||
@ -1278,10 +1381,7 @@ end;
|
|||||||
|
|
||||||
function TXMLDataBindingItemProperty.GetItem(): TXMLDataBindingItem;
|
function TXMLDataBindingItemProperty.GetItem(): TXMLDataBindingItem;
|
||||||
begin
|
begin
|
||||||
Result := FItem;
|
Result := GetActualItem(FItem);
|
||||||
|
|
||||||
while Assigned(Result) and (Result.ItemType = itForward) do
|
|
||||||
Result := TXMLDataBindingForwardItem(Result).Item;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1299,6 +1399,13 @@ begin
|
|||||||
Result := itForward;
|
Result := itForward;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TXMLDataBindingComplexTypeElementItem }
|
||||||
|
function TXMLDataBindingComplexTypeElementItem.GetItemType(): TXMLDataBindingItemType;
|
||||||
|
begin
|
||||||
|
Result := itComplexTypeElement;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@
|
|||||||
<Directories Name="UsePackages">False</Directories>
|
<Directories Name="UsePackages">False</Directories>
|
||||||
</Directories>
|
</Directories>
|
||||||
<Parameters>
|
<Parameters>
|
||||||
<Parameters Name="RunParams">"F:\XTxXSD\Offerte.xsd" "F:\XTxXSD\Output\xml_Offerte.pas"</Parameters>
|
<Parameters Name="RunParams">"F:\XTxXSD\Ombouw.xsd" "F:\XTxXSD\Output\xml_Offerte.pas"</Parameters>
|
||||||
<Parameters Name="HostApplication"></Parameters>
|
<Parameters Name="HostApplication"></Parameters>
|
||||||
<Parameters Name="Launcher"></Parameters>
|
<Parameters Name="Launcher"></Parameters>
|
||||||
<Parameters Name="UseLauncher">False</Parameters>
|
<Parameters Name="UseLauncher">False</Parameters>
|
||||||
|
@ -32,9 +32,9 @@
|
|||||||
-M
|
-M
|
||||||
-$M16384,1048576
|
-$M16384,1048576
|
||||||
-K$00400000
|
-K$00400000
|
||||||
-N"Lib"
|
-N0"Lib"
|
||||||
-LE"c:\program files\borland\delphi7\Projects\Bpl"
|
-LE"C:\Documents and Settings\PsychoMark\My Documents\Borland Studio Projects\Bpl"
|
||||||
-LN"c:\program files\borland\delphi7\Projects\Bpl"
|
-LN"C:\Documents and Settings\PsychoMark\My Documents\Borland Studio Projects\Bpl"
|
||||||
-w-UNSAFE_TYPE
|
-w-UNSAFE_TYPE
|
||||||
-w-UNSAFE_CODE
|
-w-UNSAFE_CODE
|
||||||
-w-UNSAFE_CAST
|
-w-UNSAFE_CAST
|
||||||
|
Loading…
Reference in New Issue
Block a user