From 65d792471d800f65dda7455dbe8e595d8643c5b2 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Thu, 31 Jul 2008 14:56:36 +0000 Subject: [PATCH] Fixed: incorrect type for certain collection items Fixed: use XMLIntf.IXMLDocument in case of a conflicting 'Document' element (Google KML) --- Units/DelphiXMLDataBindingGenerator.pas | 72 +++++++++++++------------ Units/DelphiXMLDataBindingResources.pas | 61 ++++++++++----------- Units/XMLDataBindingGenerator.pas | 53 ++++++++++-------- X2XMLDataBinding.cfg | 15 ++++-- 4 files changed, 109 insertions(+), 92 deletions(-) diff --git a/Units/DelphiXMLDataBindingGenerator.pas b/Units/DelphiXMLDataBindingGenerator.pas index cdda3ba..3d5a0b2 100644 --- a/Units/DelphiXMLDataBindingGenerator.pas +++ b/Units/DelphiXMLDataBindingGenerator.pas @@ -780,50 +780,52 @@ begin hasPrototype := False; - + for propertyIndex := 0 to Pred(AItem.PropertyCount) do 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(''%:s'', %:s);', - ['ItemSourceName', propertyItem.Name, - 'ItemClass', PrefixClass + propertyItem.TranslatedName]); - - AStream.WriteLnNamedFmt(' %:s := CreateCollection(%:s, %:s, ''%:s'') as %: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; - - dxsImplementation: - begin + WritePrototype; + + { Inline collection } + if ASection = dxsImplementation then + begin + AStream.WriteLnNamedFmt(' RegisterChildNode(''%:s'', %:s);', + ['ItemSourceName', propertyItem.Name, + 'ItemClass', PrefixClass + itemProperty.Item.TranslatedName]); + + AStream.WriteLnNamedFmt(' %:s := CreateCollection(%:s, %:s, ''%:s'') as %: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(''%:s'', TXML%:s);', - ['SourceName', propertyItem.Name, - 'Name', itemProperty.Item.TranslatedName]); - end; + + dxsImplementation: + begin + WritePrototype; + AStream.WriteLnNamedFmt(' RegisterChildNode(''%:s'', TXML%:s);', + ['SourceName', propertyItem.Name, + 'Name', itemProperty.Item.TranslatedName]); + end; + end; end; end; end; diff --git a/Units/DelphiXMLDataBindingResources.pas b/Units/DelphiXMLDataBindingResources.pas index 259af5d..449ba86 100644 --- a/Units/DelphiXMLDataBindingResources.pas +++ b/Units/DelphiXMLDataBindingResources.pas @@ -38,36 +38,36 @@ const DocumentBinding = 'GetDocBinding(''%:s'', TXML%:s, TargetNamespace) as IXML%:s'; - DocumentFunctionsInterface = ' function Get%:s(ADocument: IXMLDocument): IXML%:s;' + CrLf + - ' function Load%:s(const AFileName: String): IXML%:s;' + CrLf + - ' function Load%:sFromStream(AStream: TStream): IXML%:s;' + CrLf + - ' function New%:s: IXML%:s;' + CrLf; + DocumentFunctionsInterface = ' function Get%:s(ADocument: XMLIntf.IXMLDocument): IXML%:s;' + CrLf + + ' function Load%:s(const AFileName: String): IXML%:s;' + CrLf + + ' function Load%:sFromStream(AStream: TStream): IXML%:s;' + CrLf + + ' function New%:s: IXML%:s;' + CrLf; - DocumentFunctionsImplementation = 'function Get%:s(ADocument: IXMLDocument): IXML%:s;' + CrLf + - 'begin' + CrLf + - ' Result := ADocument.' + DocumentBinding + CrLf + - 'end;' + CrLf + - '' + CrLf + - 'function Load%:s(const AFileName: String): IXML%:s;' + CrLf + - 'begin' + CrLf + - ' Result := LoadXMLDocument(AFileName).' + DocumentBinding + CrLf + - 'end;' + CrLf + - '' + CrLf + - 'function Load%:sFromStream(AStream: TStream): IXML%:s;' + CrLf + - 'var' + CrLf + - ' doc: IXMLDocument;' + CrLf + - '' + CrLf + - 'begin' + CrLf + - ' doc := NewXMLDocument;' + CrLf + - ' doc.LoadFromStream(AStream);' + CrLf + - ' Result := Get%:s(doc);' + CrLf + - 'end;' + CrLf + - '' + CrLf + - 'function New%:s: IXML%:s;' + CrLf + - 'begin' + CrLf + - ' Result := NewXMLDocument.' + DocumentBinding + CrLf + - 'end;' + CrLf + - '' + CrLf; + DocumentFunctionsImplementation = 'function Get%:s(ADocument: XMLIntf.IXMLDocument): IXML%:s;' + CrLf + + 'begin' + CrLf + + ' Result := ADocument.' + DocumentBinding + CrLf + + 'end;' + CrLf + + '' + CrLf + + 'function Load%:s(const AFileName: String): IXML%:s;' + CrLf + + 'begin' + CrLf + + ' Result := LoadXMLDocument(AFileName).' + DocumentBinding + CrLf + + 'end;' + CrLf + + '' + CrLf + + 'function Load%:sFromStream(AStream: TStream): IXML%:s;' + CrLf + + 'var' + CrLf + + ' doc: XMLIntf.IXMLDocument;' + CrLf + + '' + CrLf + + 'begin' + CrLf + + ' doc := NewXMLDocument;' + CrLf + + ' doc.LoadFromStream(AStream);' + CrLf + + ' Result := Get%:s(doc);' + CrLf + + 'end;' + CrLf + + '' + CrLf + + 'function New%:s: IXML%:s;' + CrLf + + 'begin' + CrLf + + ' Result := NewXMLDocument.' + DocumentBinding + CrLf + + 'end;' + CrLf + + '' + CrLf; PropertyIntfMethodGetOptional = ' function GetHas%: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) ); diff --git a/Units/XMLDataBindingGenerator.pas b/Units/XMLDataBindingGenerator.pas index e4a16ad..afb6bf3 100644 --- a/Units/XMLDataBindingGenerator.pas +++ b/Units/XMLDataBindingGenerator.pas @@ -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; diff --git a/X2XMLDataBinding.cfg b/X2XMLDataBinding.cfg index 2125801..fe87b98 100644 --- a/X2XMLDataBinding.cfg +++ b/X2XMLDataBinding.cfg @@ -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