1
0
mirror of synced 2024-11-14 02:59:16 +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;
var
charIndex: Integer;
wordIndex: Integer;
begin
Result := AName;
for wordIndex := Low(ReservedWords) to High(ReservedWords) do
{ Remove unsafe characters }
for charIndex := Length(Result) downto 1 do
begin
if Result = ReservedWords[wordIndex] then
begin
if not (Result[charIndex] in SafeChars) then
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;
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;

View File

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

View File

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

View File

@ -100,7 +100,7 @@ Conditionals=
DebugSourceDirs=
UsePackages=0
[Parameters]
RunParams="P:\xtx\xtx\xsd\Offerte.xsd" "P:\xtx\xtx\xsd\"
RunParams="Z:\SAM\Mitsubishi\Copernica\Koppelingbeschijving.xsd" "C:\Temp\Koppelingbeschrijving.pas"
HostApplication=
Launcher=
UseLauncher=0
@ -139,21 +139,6 @@ C:\Program Files\Borland\Indy\D7\dclIndy70.bpl=Internet Direct (Indy) for D7 Pro
[HistoryLists\hlUnitAliases]
Count=1
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]
Count=6
Count=1
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',
XMLDataBindingGenerator in 'Units\XMLDataBindingGenerator.pas',
XMLDataBindingHelpers in 'Units\XMLDataBindingHelpers.pas',
DelphiXMLDataBindingResources in 'Units\DelphiXMLDataBindingResources.pas',
xml_ExternalLeadFeed in '..\xml_ExternalLeadFeed.pas',
xml_Offerte in '..\..\xtx\xtx\xsd\xml_Offerte.pas';
DelphiXMLDataBindingResources in 'Units\DelphiXMLDataBindingResources.pas';
begin
CoInitialize(nil);