1
0
mirror of synced 2024-11-21 21:43:49 +00:00

Fixed: incorrect type for certain collection items

Fixed: use XMLIntf.IXMLDocument in case of a conflicting 'Document' element (Google KML)
This commit is contained in:
Mark van Renswoude 2008-07-31 14:56:36 +00:00
parent 7ed849490c
commit 65d792471d
4 changed files with 109 additions and 92 deletions

View File

@ -785,45 +785,47 @@ begin
begin
propertyItem := AItem.Properties[propertyIndex];
if (not AItem.IsCollection) and Assigned(propertyItem.Collection) then
if propertyItem.PropertyType = ptItem then
begin
WritePrototype;
{ Inline collection }
if ASection = dxsImplementation then
begin
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<ItemSourceName>:s'', %<ItemClass>:s);',
['ItemSourceName', propertyItem.Name,
'ItemClass', PrefixClass + propertyItem.TranslatedName]);
AStream.WriteLnNamedFmt(' %<FieldName>:s := CreateCollection(%<CollectionClass>:s, %<ItemInterface>:s, ''%<ItemSourceName>:s'') as %<CollectionInterface>:s;',
['FieldName', PrefixField + propertyItem.TranslatedName,
'CollectionClass', PrefixClass + propertyItem.Collection.TranslatedName,
'CollectionInterface', PrefixInterface + propertyItem.Collection.TranslatedName,
'ItemInterface', PrefixInterface + propertyItem.TranslatedName,
'ItemSourceName', propertyItem.Name]);
end;
end else if (propertyItem.PropertyType = ptItem) and
((not AItem.IsCollection) or
(propertyItem <> AItem.CollectionItem)) then
begin
{ Item property }
itemProperty := TXMLDataBindingItemProperty(propertyItem);
if Assigned(itemProperty.Item) and
(itemProperty.Item.ItemType = itInterface) then
if (not AItem.IsCollection) and Assigned(propertyItem.Collection) then
begin
case ASection of
dxsClass:
WritePrototype;
WritePrototype;
dxsImplementation:
begin
{ Inline collection }
if ASection = dxsImplementation then
begin
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<ItemSourceName>:s'', %<ItemClass>:s);',
['ItemSourceName', propertyItem.Name,
'ItemClass', PrefixClass + itemProperty.Item.TranslatedName]);
AStream.WriteLnNamedFmt(' %<FieldName>:s := CreateCollection(%<CollectionClass>:s, %<ItemInterface>:s, ''%<ItemSourceName>:s'') as %<CollectionInterface>:s;',
['FieldName', PrefixField + propertyItem.TranslatedName,
'CollectionClass', PrefixClass + propertyItem.Collection.TranslatedName,
'CollectionInterface', PrefixInterface + propertyItem.Collection.TranslatedName,
'ItemInterface', PrefixInterface + itemProperty.Item.TranslatedName,
'ItemSourceName', propertyItem.Name]);
end;
end else if ((not AItem.IsCollection) or
(propertyItem <> AItem.CollectionItem)) then
begin
{ Item property }
if Assigned(itemProperty.Item) and
(itemProperty.Item.ItemType = itInterface) then
begin
case ASection of
dxsClass:
WritePrototype;
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<SourceName>:s'', TXML%<Name>:s);',
['SourceName', propertyItem.Name,
'Name', itemProperty.Item.TranslatedName]);
end;
dxsImplementation:
begin
WritePrototype;
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<SourceName>:s'', TXML%<Name>:s);',
['SourceName', propertyItem.Name,
'Name', itemProperty.Item.TranslatedName]);
end;
end;
end;
end;
end;

View File

@ -38,36 +38,36 @@ const
DocumentBinding = 'GetDocBinding(''%<SourceName>:s'', TXML%<Name>:s, TargetNamespace) as IXML%<Name>:s';
DocumentFunctionsInterface = ' function Get%<Name>:s(ADocument: IXMLDocument): IXML%<Name>:s;' + CrLf +
' function Load%<Name>:s(const AFileName: String): IXML%<Name>:s;' + CrLf +
' function Load%<Name>:sFromStream(AStream: TStream): IXML%<Name>:s;' + CrLf +
' function New%<Name>:s: IXML%<Name>:s;' + CrLf;
DocumentFunctionsInterface = ' function Get%<Name>:s(ADocument: XMLIntf.IXMLDocument): IXML%<Name>:s;' + CrLf +
' function Load%<Name>:s(const AFileName: String): IXML%<Name>:s;' + CrLf +
' function Load%<Name>:sFromStream(AStream: TStream): IXML%<Name>:s;' + CrLf +
' function New%<Name>:s: IXML%<Name>:s;' + CrLf;
DocumentFunctionsImplementation = 'function Get%<Name>:s(ADocument: IXMLDocument): IXML%<Name>:s;' + CrLf +
'begin' + CrLf +
' Result := ADocument.' + DocumentBinding + CrLf +
'end;' + CrLf +
'' + CrLf +
'function Load%<Name>:s(const AFileName: String): IXML%<Name>:s;' + CrLf +
'begin' + CrLf +
' Result := LoadXMLDocument(AFileName).' + DocumentBinding + CrLf +
'end;' + CrLf +
'' + CrLf +
'function Load%<Name>:sFromStream(AStream: TStream): IXML%<Name>:s;' + CrLf +
'var' + CrLf +
' doc: IXMLDocument;' + CrLf +
'' + CrLf +
'begin' + CrLf +
' doc := NewXMLDocument;' + CrLf +
' doc.LoadFromStream(AStream);' + CrLf +
' Result := Get%<Name>:s(doc);' + CrLf +
'end;' + CrLf +
'' + CrLf +
'function New%<Name>:s: IXML%<Name>:s;' + CrLf +
'begin' + CrLf +
' Result := NewXMLDocument.' + DocumentBinding + CrLf +
'end;' + CrLf +
'' + CrLf;
DocumentFunctionsImplementation = 'function Get%<Name>:s(ADocument: XMLIntf.IXMLDocument): IXML%<Name>:s;' + CrLf +
'begin' + CrLf +
' Result := ADocument.' + DocumentBinding + CrLf +
'end;' + CrLf +
'' + CrLf +
'function Load%<Name>:s(const AFileName: String): IXML%<Name>:s;' + CrLf +
'begin' + CrLf +
' Result := LoadXMLDocument(AFileName).' + DocumentBinding + CrLf +
'end;' + CrLf +
'' + CrLf +
'function Load%<Name>:sFromStream(AStream: TStream): IXML%<Name>:s;' + CrLf +
'var' + CrLf +
' doc: XMLIntf.IXMLDocument;' + CrLf +
'' + CrLf +
'begin' + CrLf +
' doc := NewXMLDocument;' + CrLf +
' doc.LoadFromStream(AStream);' + CrLf +
' Result := Get%<Name>:s(doc);' + CrLf +
'end;' + CrLf +
'' + CrLf +
'function New%<Name>:s: IXML%<Name>:s;' + CrLf +
'begin' + CrLf +
' Result := NewXMLDocument.' + DocumentBinding + CrLf +
'end;' + CrLf +
'' + CrLf;
PropertyIntfMethodGetOptional = ' function GetHas%<PropertyName>:s: Boolean;';
@ -194,7 +194,7 @@ type
const
SimpleTypeMapping: array[0..10] of TTypeMapping =
SimpleTypeMapping: array[0..11] of TTypeMapping =
(
(SchemaName: 'int'; DelphiName: 'Integer'; Conversion: tcNone),
(SchemaName: 'integer'; DelphiName: 'Integer'; Conversion: tcNone),
@ -206,6 +206,7 @@ const
(SchemaName: 'double'; DelphiName: 'Double'; Conversion: tcFloat),
(SchemaName: 'boolean'; DelphiName: 'Boolean'; Conversion: tcBoolean),
(SchemaName: 'string'; DelphiName: 'WideString'; Conversion: tcString),
(SchemaName: 'anyURI'; DelphiName: 'WideString'; Conversion: tcString),
(SchemaName: 'base64Binary'; DelphiName: 'WideString'; Conversion: tcBase64)
);

View File

@ -717,6 +717,7 @@ var
complexAliasItem: TXMLDataBindingComplexTypeAliasItem;
simpleAliasItem: TXMLDataBindingSimpleTypeAliasItem;
elementIndex: Integer;
simpleTypeDef: IXMLSimpleTypeDef;
begin
Result := nil;
@ -755,24 +756,27 @@ begin
complexAliasItem.Item := Result;
ASchema.AddItem(complexAliasItem);
end;
end else if AElement.DataType.Enumerations.Count > 0 then
end else if Supports(AElement.DataType, IXMLSimpleTypeDef, simpleTypeDef) then
begin
{ References enumeration. }
Result := FindEnumeration(ASchema, AElement.DataTypeName);
if not Assigned(Result) then
if simpleTypeDef.Enumerations.Count > 0 then
begin
Result := TXMLDataBindingUnresolvedItem.Create(Self, AElement, AElement.DataTypeName, ifEnumeration);
ASchema.AddItem(Result);
end;
end else if AElement.IsGlobal then
begin
{ The element is global, but only references a simple type. }
simpleAliasItem := TXMLDataBindingSimpleTypeAliasItem.Create(Self, AElement, AElement.Name);
simpleAliasItem.DataType := AElement.DataType;
ASchema.AddItem(simpleAliasItem);
{ References enumeration. }
Result := FindEnumeration(ASchema, AElement.DataTypeName);
Result := simpleAliasItem;
if not Assigned(Result) then
begin
Result := TXMLDataBindingUnresolvedItem.Create(Self, AElement, AElement.DataTypeName, ifEnumeration);
ASchema.AddItem(Result);
end;
end else if simpleTypeDef.IsBuiltInType and AElement.IsGlobal then
begin
{ The element is global, but only references a simple type. }
simpleAliasItem := TXMLDataBindingSimpleTypeAliasItem.Create(Self, AElement, AElement.Name);
simpleAliasItem.DataType := AElement.DataType;
ASchema.AddItem(simpleAliasItem);
Result := simpleAliasItem;
end;
end;
end;
@ -1239,16 +1243,21 @@ begin
// #ToDo1 (MvR) 7-4-2008: check if an item with the "List" postfix
// exists in the schema, as it could cause
// conflicts.
// #ToDo1 (MvR) 30-7-2008: temporary implementation; have to check
// for proper functioning later.
collectionItem := FindInterface(ASchema, propertyItem.TranslatedName + CollectionPostfix, ifElement);
if not Assigned(collectionItem) then
begin
case propertyItem.PropertyType of
ptSimple: collectionName := propertyItem.TranslatedName + CollectionPostfix;
ptItem: collectionName := propertyItem.TranslatedName + CollectionPostfix;
end;
case propertyItem.PropertyType of
ptSimple: collectionName := propertyItem.TranslatedName + CollectionPostfix;
ptItem: collectionName := propertyItem.TranslatedName + CollectionPostfix;
collectionItem := TXMLDataBindingInterface.Create(Self, propertyItem.SchemaItem, collectionName);
collectionItem.CollectionItem := propertyItem;
ASchema.InsertItem(collectionItem, interfaceItem);
end;
collectionItem := TXMLDataBindingInterface.Create(Self, propertyItem.SchemaItem, collectionName);
collectionItem.CollectionItem := propertyItem;
ASchema.InsertItem(collectionItem, interfaceItem);
propertyItem.Collection := collectionItem;
end;
end;

View File

@ -1,6 +1,6 @@
-$A8
-$B-
-$C+
-$C-
-$D+
-$E-
-$F-
@ -12,7 +12,7 @@
-$L+
-$M-
-$N+
-$O+
-$O-
-$P+
-$Q-
-$R-
@ -22,7 +22,7 @@
-$V+
-$W-
-$X+
-$YD
-$Y+
-$Z1
-GD
-cg
@ -32,8 +32,13 @@
-M
-$M16384,1048576
-K$00400000
-LE"C:\Documents and Settings\PsychoMark\My Documents\Borland Studio Projects\Bpl"
-LN"C:\Documents and Settings\PsychoMark\My Documents\Borland Studio Projects\Bpl"
-N"lib"
-LE"c:\program files\borland\delphi7\Projects\Bpl"
-LN"c:\program files\borland\delphi7\Projects\Bpl"
-U"c:\program files\borland\delphi7\Lib\Debug"
-O"c:\program files\borland\delphi7\Lib\Debug"
-I"c:\program files\borland\delphi7\Lib\Debug"
-R"c:\program files\borland\delphi7\Lib\Debug"
-w-UNSAFE_TYPE
-w-UNSAFE_CODE
-w-UNSAFE_CAST