1
0
mirror of synced 2024-11-23 06:03:50 +00:00

Merged last changes into trunk

This commit is contained in:
Mark van Renswoude 2008-04-18 14:36:17 +00:00
parent e402505cbb
commit 0c38a497f9
5 changed files with 143 additions and 59 deletions

View File

@ -318,17 +318,36 @@ end;
function TDelphiXMLDataBindingGenerator.DelphiSafeName(const AName: String): String; function TDelphiXMLDataBindingGenerator.DelphiSafeName(const AName: String): String;
var var
charIndex: Integer;
wordIndex: Integer; wordIndex: Integer;
begin begin
Result := AName; Result := AName;
for wordIndex := Low(ReservedWords) to High(ReservedWords) do
{ Remove unsafe characters }
for charIndex := Length(Result) downto 1 do
begin begin
if Result = ReservedWords[wordIndex] then if not (Result[charIndex] in SafeChars) then
begin Delete(Result, charIndex, 1);
end;
if Length(Result) > 0 then
begin
{ Number as the first character is not allowed }
if Result[1] in ['0'..'9'] then
Result := '_' + Result; Result := '_' + Result;
Break;
{ Check for reserved words }
for wordIndex := Low(ReservedWords) to High(ReservedWords) do
begin
if Result = ReservedWords[wordIndex] then
begin
Result := '_' + Result;
Break;
end;
end; end;
end; end;
end; end;

View File

@ -158,6 +158,8 @@ const
'virtual', 'while', 'with', 'write', 'writeonly', 'xor' 'virtual', 'while', 'with', 'write', 'writeonly', 'xor'
); );
SafeChars = ['A'..'Z', 'a'..'z', '0'..'9', '_', '-'];
type type
TTypeConversion = (tcNone, tcBoolean, tcFloat, tcDateTime); TTypeConversion = (tcNone, tcBoolean, tcFloat, tcDateTime);

View File

@ -19,7 +19,8 @@ type
TXMLDataBindingOutputType = (otSingle, otMultiple); TXMLDataBindingOutputType = (otSingle, otMultiple);
TXMLDataBindingItemType = (itInterface, itEnumeration, itEnumerationMember, TXMLDataBindingItemType = (itInterface, itEnumeration, itEnumerationMember,
itProperty, itUnresolved, itAlias); itProperty, itUnresolved,
itComplexTypeAlias, itSimpleTypeAlias);
TXMLDataBindingInterfaceType = (ifElement, ifComplexType); TXMLDataBindingInterfaceType = (ifElement, ifComplexType);
TXMLDataBindingPropertyType = (ptSimple, ptItem); TXMLDataBindingPropertyType = (ptSimple, ptItem);
TXMLDataBindingOccurance = (boMinOccurs, boMaxOccurs); TXMLDataBindingOccurance = (boMinOccurs, boMaxOccurs);
@ -300,7 +301,7 @@ type
end; end;
TXMLDataBindingAliasItem = class(TXMLDataBindingItem) TXMLDataBindingComplexTypeAliasItem = class(TXMLDataBindingItem)
private private
FItem: TXMLDataBindingItem; FItem: TXMLDataBindingItem;
protected protected
@ -312,6 +313,16 @@ type
end; end;
TXMLDataBindingSimpleTypeAliasItem = class(TXMLDataBindingItem)
private
FDataType: IXMLTypeDef;
protected
function GetItemType(): TXMLDataBindingItemType; override;
public
property DataType: IXMLTypeDef read FDataType write FDataType;
end;
implementation implementation
uses uses
SysUtils, SysUtils,
@ -587,7 +598,12 @@ begin
for complexTypeIndex := 0 to Pred(schemaDef.ComplexTypes.Count) do for complexTypeIndex := 0 to Pred(schemaDef.ComplexTypes.Count) do
begin begin
complexType := schemaDef.ComplexTypes[complexTypeIndex]; complexType := schemaDef.ComplexTypes[complexTypeIndex];
interfaceItem := TXMLDataBindingInterface.Create(Self, complexType, complexType.Name); interfaceItem := TXMLDataBindingInterface.Create(Self, complexType, complexType.Name);
if complexType.DerivationMethod <> dmNone then
interfaceItem.BaseName := complexType.BaseTypeName;
ASchema.AddItem(interfaceItem); ASchema.AddItem(interfaceItem);
for elementIndex := 0 to Pred(complexType.ElementDefs.Count) do for elementIndex := 0 to Pred(complexType.ElementDefs.Count) do
@ -664,7 +680,8 @@ var
attributeIndex: Integer; attributeIndex: Integer;
enumerationObject: TXMLDataBindingEnumeration; enumerationObject: TXMLDataBindingEnumeration;
interfaceObject: TXMLDataBindingInterface; interfaceObject: TXMLDataBindingInterface;
aliasItem: TXMLDataBindingAliasItem; complexAliasItem: TXMLDataBindingComplexTypeAliasItem;
simpleAliasItem: TXMLDataBindingSimpleTypeAliasItem;
begin begin
Result := nil; Result := nil;
@ -682,25 +699,35 @@ begin
end; end;
end else end else
begin begin
if (not AElement.DataType.IsAnonymous) and if not AElement.DataType.IsAnonymous then
AElement.DataType.IsComplex then
begin begin
{ Find data type. If not found, mark as "resolve later". } if AElement.DataType.IsComplex then
Result := FindInterface(ASchema, AElement.DataTypeName, ifComplexType);
if not Assigned(Result) then
begin begin
Result := TXMLDataBindingUnresolvedItem.Create(Self, AElement, AElement.DataTypeName, ifComplexType); { Find data type. If not found, mark as "resolve later". }
ASchema.AddItem(Result); Result := FindInterface(ASchema, AElement.DataTypeName, ifComplexType);
end;
if AElement.IsGlobal then if not Assigned(Result) then
begin
Result := TXMLDataBindingUnresolvedItem.Create(Self, AElement, AElement.DataTypeName, ifComplexType);
ASchema.AddItem(Result);
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. }
complexAliasItem := TXMLDataBindingComplexTypeAliasItem.Create(Self, AElement, AElement.Name);
complexAliasItem.Item := Result;
ASchema.AddItem(complexAliasItem);
end;
end else if AElement.IsGlobal then
begin begin
{ The element is global, but only references a complex type. Keep track { The element is global, but only references a simple type. }
to properly resolve references to the element. } simpleAliasItem := TXMLDataBindingSimpleTypeAliasItem.Create(Self, AElement, AElement.Name);
aliasItem := TXMLDataBindingAliasItem.Create(Self, AElement, AElement.Name); simpleAliasItem.DataType := AElement.DataType;
aliasItem.Item := Result; ASchema.AddItem(simpleAliasItem);
ASchema.AddItem(aliasItem);
Result := simpleAliasItem;
end; end;
end; end;
@ -840,7 +867,8 @@ begin
itInterface: itInterface:
AAbort := (TXMLDataBindingInterface(AItem).InterfaceType = findInfo^.InterfaceType); AAbort := (TXMLDataBindingInterface(AItem).InterfaceType = findInfo^.InterfaceType);
itAlias: itComplexTypeAlias,
itSimpleTypeAlias:
AAbort := (findInfo^.InterfaceType = ifElement); AAbort := (findInfo^.InterfaceType = ifElement);
end; end;
end; end;
@ -912,20 +940,36 @@ end;
procedure TXMLDataBindingGenerator.ResolveAlias(ASchema: TXMLDataBindingSchema); procedure TXMLDataBindingGenerator.ResolveAlias(ASchema: TXMLDataBindingSchema);
var var
itemIndex: Integer; itemIndex: Integer;
item: TXMLDataBindingItem; item: TXMLDataBindingItem;
aliasItem: TXMLDataBindingAliasItem; complexAliasItem: TXMLDataBindingComplexTypeAliasItem;
simpleAliasItem: TXMLDataBindingSimpleTypeAliasItem;
begin begin
for itemIndex := Pred(ASchema.ItemCount) downto 0 do for itemIndex := Pred(ASchema.ItemCount) downto 0 do
begin begin
item := ASchema.Items[itemIndex]; item := ASchema.Items[itemIndex];
if item.ItemType = itAlias then case item.ItemType of
begin itComplexTypeAlias:
aliasItem := TXMLDataBindingAliasItem(item); begin
if Assigned(aliasItem.Item) then { Replace alias element with the actual complex type }
ReplaceItem(aliasItem, aliasItem.Item); complexAliasItem := TXMLDataBindingComplexTypeAliasItem(item);
if Assigned(complexAliasItem.Item) then
begin
ReplaceItem(complexAliasItem, complexAliasItem.Item);
FreeAndNil(complexAliasItem);
end;
end;
itSimpleTypeAlias:
begin
{ Remove the alias element - TXMLDataBindingInterfaceItem.ReplaceItem
will take care of fixing it's properties. }
simpleAliasItem := TXMLDataBindingSimpleTypeAliasItem(item);
ReplaceItem(simpleAliasItem, nil);
FreeAndNil(simpleAliasItem);
end;
end; end;
end; end;
end; end;
@ -1371,13 +1415,43 @@ end;
procedure TXMLDataBindingInterface.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem); procedure TXMLDataBindingInterface.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem);
var var
propertyIndex: Integer; propertyIndex: Integer;
propertyItem: TXMLDataBindingProperty;
itemProperty: TXMLDataBindingItemProperty;
simpleProperty: TXMLDataBindingSimpleProperty;
begin begin
inherited; inherited;
for propertyIndex := Pred(PropertyCount) downto 0 do for propertyIndex := Pred(PropertyCount) downto 0 do
Properties[propertyIndex].ReplaceItem(AOldItem, ANewItem); begin
propertyItem := Properties[propertyIndex];
if propertyItem = AOldItem then
FProperties.Extract(AOldItem)
else
begin
if (AOldItem.ItemType = itSimpleTypeAlias) and
(propertyItem.PropertyType = ptItem) then
begin
itemProperty := TXMLDataBindingItemProperty(propertyItem);
if itemProperty.Item = AOldItem then
begin
{ Replace item property with simple property }
simpleProperty := TXMLDataBindingSimpleProperty.Create(Owner,
itemProperty.SchemaItem,
itemProperty.Name,
TXMLDataBindingSimpleTypeAliasItem(AOldItem).DataType);
{ FProperties owns itemProperty and will free it }
FProperties[propertyIndex] := simpleProperty;
end else
Properties[propertyIndex].ReplaceItem(AOldItem, ANewItem);
end else
Properties[propertyIndex].ReplaceItem(AOldItem, ANewItem);
end;
end;
end; end;
@ -1535,8 +1609,8 @@ begin
end; end;
{ TXMLDataBindingAliasItem } { TXMLDataBindingComplexTypeAliasItem }
procedure TXMLDataBindingAliasItem.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem); procedure TXMLDataBindingComplexTypeAliasItem.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem);
begin begin
inherited; inherited;
@ -1545,9 +1619,16 @@ begin
end; end;
function TXMLDataBindingAliasItem.GetItemType(): TXMLDataBindingItemType; function TXMLDataBindingComplexTypeAliasItem.GetItemType(): TXMLDataBindingItemType;
begin begin
Result := itAlias; Result := itComplexTypeAlias;
end;
{ TXMLDataBindingSimpleTypeAliasItem }
function TXMLDataBindingSimpleTypeAliasItem.GetItemType: TXMLDataBindingItemType;
begin
Result := itSimpleTypeAlias;
end; end;
end. end.

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\" RunParams="Z:\SAM\Mitsubishi\Copernica\Koppelingbeschijving.xsd" "C:\Temp\Koppelingbeschrijving.pas"
HostApplication= HostApplication=
Launcher= Launcher=
UseLauncher=0 UseLauncher=0
@ -139,21 +139,6 @@ C:\Program Files\Borland\Indy\D7\dclIndy70.bpl=Internet Direct (Indy) for D7 Pro
[HistoryLists\hlUnitAliases] [HistoryLists\hlUnitAliases]
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\hlSearchPath]
Count=3
Item0=P:\xtx\xtx\xsd
Item1=..\..
Item2=F:\Development\VDarts\Packages
[HistoryLists\hlUnitOutputDirectory] [HistoryLists\hlUnitOutputDirectory]
Count=6 Count=1
Item0=Lib Item0=Lib
Item1=P:\Algemeen\lib
Item2=..\..\Lib\D7
Item3=..\..\Dcu
Item4=..\..\..\Dcu
Item5=Dcu
[HistoryLists\hlBPLOutput]
Count=3
Item0=..\..\Lib\D7
Item1=Lib\D7
Item2=..\Lib\D7

View File

@ -6,10 +6,7 @@ uses
DelphiXMLDataBindingGenerator in 'Units\DelphiXMLDataBindingGenerator.pas', DelphiXMLDataBindingGenerator in 'Units\DelphiXMLDataBindingGenerator.pas',
XMLDataBindingGenerator in 'Units\XMLDataBindingGenerator.pas', XMLDataBindingGenerator in 'Units\XMLDataBindingGenerator.pas',
XMLDataBindingHelpers in 'Units\XMLDataBindingHelpers.pas', XMLDataBindingHelpers in 'Units\XMLDataBindingHelpers.pas',
DelphiXMLDataBindingResources in 'Units\DelphiXMLDataBindingResources.pas', DelphiXMLDataBindingResources in 'Units\DelphiXMLDataBindingResources.pas';
xml_ExternalLeadFeed in '..\xml_ExternalLeadFeed.pas',
xml_Offerte in '..\..\xtx\xtx\xsd\xml_Offerte.pas';
begin begin
CoInitialize(nil); CoInitialize(nil);