2008-02-20 06:52:00 +00:00
|
|
|
unit DelphiXMLDataBindingGenerator;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Classes,
|
|
|
|
XMLSchema,
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
X2UtHashes,
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
XMLDataBindingGenerator,
|
|
|
|
XMLDataBindingHelpers;
|
|
|
|
|
|
|
|
type
|
|
|
|
TGetFileNameEvent = procedure(Sender: TObject; const SchemaName: String; var Result: String) of object;
|
|
|
|
|
2008-02-26 21:53:11 +00:00
|
|
|
TDelphiXMLSection = (dxsForward, dxsInterface, dxsClass, dxsImplementation);
|
|
|
|
TDelphiXMLMember = (dxmPropertyGet, dxmPropertySet, dxmPropertyDeclaration);
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
TDelphiXMLDataBindingGenerator = class(TXMLDataBindingGenerator)
|
|
|
|
private
|
|
|
|
FOnGetFileName: TGetFileNameEvent;
|
2008-03-09 20:36:27 +00:00
|
|
|
FProcessedItems: TX2OIHash;
|
2008-02-20 06:52:00 +00:00
|
|
|
protected
|
|
|
|
procedure GenerateDataBinding(); override;
|
|
|
|
procedure GenerateSingleDataBinding();
|
|
|
|
procedure GenerateMultipleDataBinding();
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
function DelphiSafeName(const AName: String): String;
|
|
|
|
function TranslateItemName(AItem: TXMLDataBindingItem): String; override;
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
function DoGetFileName(const ASchemaName: String): String;
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-02-26 21:53:11 +00:00
|
|
|
function TranslateDataType(ADataType: IXMLTypeDef): String;
|
|
|
|
function CreateNewGUID(): String;
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
procedure WriteUnitHeader(AStream: TStreamHelper; const AFileName: String);
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure WriteInterface(AStream: TStreamHelper);
|
2008-02-20 06:52:00 +00:00
|
|
|
procedure WriteImplementation(AStream: TStreamHelper);
|
|
|
|
procedure WriteUnitFooter(AStream: TStreamHelper);
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure WriteSection(AStream: TStreamHelper; ASection: TDelphiXMLSection);
|
|
|
|
procedure WriteDocumentFunctions(AStream: TStreamHelper; ASection: TDelphiXMLSection);
|
|
|
|
procedure WriteEnumerationConstants(AStream: TStreamHelper);
|
|
|
|
procedure WriteDocumentation(AStream: TStreamHelper; AItem: TXMLDataBindingItem);
|
|
|
|
|
|
|
|
procedure WriteSchemaItem(AStream: TStreamHelper; AItem: TXMLDataBindingItem; ASection: TDelphiXMLSection);
|
|
|
|
procedure WriteSchemaInterface(AStream: TStreamHelper; AItem: TXMLDataBindingInterface; ASection: TDelphiXMLSection);
|
|
|
|
procedure WriteSchemaInterfaceProperties(AStream: TStreamHelper; AItem: TXMLDataBindingInterface; ASection: TDelphiXMLSection);
|
|
|
|
procedure WriteSchemaCollection(AStream: TStreamHelper; AItem: TXMLDataBindingCollection; ASection: TDelphiXMLSection);
|
|
|
|
procedure WriteSchemaCollectionProperties(AStream: TStreamHelper; AItem: TXMLDataBindingCollection; ASection: TDelphiXMLSection);
|
|
|
|
procedure WriteSchemaEnumeration(AStream: TStreamHelper; AItem: TXMLDataBindingEnumeration; ASection: TDelphiXMLSection);
|
|
|
|
procedure WriteSchemaEnumerationArray(AStream: TStreamHelper; AItem: TXMLDataBindingEnumeration);
|
|
|
|
|
|
|
|
property ProcessedItems: TX2OIHash read FProcessedItems;
|
2008-02-20 06:52:00 +00:00
|
|
|
public
|
|
|
|
property OnGetFileName: TGetFileNameEvent read FOnGetFileName write FOnGetFileName;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
2008-03-17 06:08:49 +00:00
|
|
|
SysUtils,
|
|
|
|
|
|
|
|
X2UtNamedFormat;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
|
2008-02-26 21:53:11 +00:00
|
|
|
const
|
|
|
|
SectionComments: array[TDelphiXMLSection] of String =
|
|
|
|
(
|
2008-03-17 16:02:57 +00:00
|
|
|
' { Forward declarations for %<SchemaName>:s }',
|
|
|
|
' { Interfaces for %<SchemaName>:s }',
|
|
|
|
' { Classes for %<SchemaName>:s }',
|
|
|
|
'{ Implementation for %<SchemaName>:s }'
|
2008-02-26 21:53:11 +00:00
|
|
|
);
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
PrefixInterface = 'IXML';
|
|
|
|
PrefixClass = 'TXML';
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
InterfaceItemForward = ' IXML%<Name>:s = interface;';
|
|
|
|
InterfaceItemInterface = ' IXML%<Name>:s = interface(%<ParentName>:s)';
|
|
|
|
InterfaceItemClass = ' TXML%<Name>:s = class(%<ParentName>:s, IXML%<Name>:s)';
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
CollectionInterface = 'IXMLNodeCollection';
|
|
|
|
CollectionClass = 'TXMLNodeCollection';
|
|
|
|
|
|
|
|
ItemInterface = 'IXMLNode';
|
|
|
|
ItemClass = 'TXMLNode';
|
|
|
|
|
|
|
|
|
2008-02-26 21:53:11 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
// #ToDo1 (MvR) 9-3-2008: document / node / etc
|
|
|
|
// #ToDo1 (MvR) 9-3-2008: WideString etc ?
|
2008-02-26 21:53:11 +00:00
|
|
|
ReservedWords: array[0..111] of String =
|
|
|
|
(
|
|
|
|
'absolute', 'abstract', 'and', 'array', 'as', 'asm',
|
|
|
|
'assembler', 'automated', 'begin', 'case', 'cdecl', 'class',
|
|
|
|
'const', 'constructor', 'contains', 'default', 'deprecated',
|
|
|
|
'destructor', 'dispid', 'dispinterface', 'div', 'do',
|
|
|
|
'downto', 'dynamic', 'else', 'end', 'except', 'export',
|
|
|
|
'exports', 'external', 'far', 'file', 'final', 'finalization',
|
|
|
|
'finally', 'for', 'forward', 'function', 'goto', 'if',
|
|
|
|
'implementation', 'implements', 'in', 'index', 'inherited',
|
|
|
|
'initialization', 'inline', 'interface', 'is', 'label',
|
|
|
|
'library', 'local', 'message', 'mod', 'name', 'near',
|
|
|
|
'nil', 'nodefault', 'not', 'object', 'of', 'or', 'out',
|
|
|
|
'overload', 'override', 'package', 'packed', 'pascal',
|
|
|
|
'platform', 'private', 'procedure', 'program', 'property',
|
|
|
|
'protected', 'public', 'published', 'raise', 'read',
|
|
|
|
'readonly', 'record', 'register', 'reintroduce', 'repeat',
|
|
|
|
'requires', 'resident', 'resourcestring', 'safecall',
|
|
|
|
'sealed', 'set', 'shl', 'shr', 'static', 'stdcall',
|
|
|
|
'stored', 'string', 'then', 'threadvar', 'to', 'try', 'type',
|
|
|
|
'unit', 'unsafe', 'until', 'uses', 'var', 'varargs',
|
|
|
|
'virtual', 'while', 'with', 'write', 'writeonly', 'xor'
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2008-03-10 16:04:46 +00:00
|
|
|
type
|
|
|
|
// #ToDo1 (MvR) 10-3-2008: check handling for floats and booleans maybe?
|
|
|
|
TTypeHandling = (thNone, thDateTime);
|
|
|
|
|
|
|
|
TTypeMapping = record
|
|
|
|
SchemaName: String;
|
|
|
|
DelphiName: String;
|
|
|
|
Handling: TTypeHandling;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
SimpleTypeMapping: array[0..9] of TTypeMapping =
|
2008-03-09 20:36:27 +00:00
|
|
|
(
|
2008-03-17 06:08:49 +00:00
|
|
|
(SchemaName: 'int'; DelphiName: 'Integer'; Handling: thNone),
|
|
|
|
(SchemaName: 'integer'; DelphiName: 'Integer'; Handling: thNone),
|
|
|
|
(SchemaName: 'short'; DelphiName: 'Smallint'; Handling: thNone),
|
|
|
|
(SchemaName: 'date'; DelphiName: 'TDateTime'; Handling: thDateTime),
|
|
|
|
(SchemaName: 'time'; DelphiName: 'TDateTime'; Handling: thDateTime),
|
|
|
|
(SchemaName: 'dateTime'; DelphiName: 'TDateTime'; Handling: thDateTime),
|
|
|
|
(SchemaName: 'float'; DelphiName: 'Double'; Handling: thNone),
|
|
|
|
(SchemaName: 'double'; DelphiName: 'Extended'; Handling: thNone),
|
|
|
|
(SchemaName: 'boolean'; DelphiName: 'Boolean'; Handling: thNone),
|
|
|
|
(SchemaName: 'string'; DelphiName: 'WideString'; Handling: thNone)
|
2008-03-09 20:36:27 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
{ TDelphiXMLDataBindingGenerator }
|
|
|
|
procedure TDelphiXMLDataBindingGenerator.GenerateDataBinding();
|
|
|
|
begin
|
|
|
|
case OutputType of
|
|
|
|
otSingle: GenerateSingleDataBinding();
|
|
|
|
otMultiple: GenerateMultipleDataBinding();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TDelphiXMLDataBindingGenerator.GenerateSingleDataBinding();
|
|
|
|
var
|
|
|
|
unitName: String;
|
|
|
|
unitStream: TStreamHelper;
|
|
|
|
|
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
unitName := DoGetFileName(Schemas[0].SchemaName);
|
2008-02-20 06:52:00 +00:00
|
|
|
unitStream := TStreamHelper.Create(TFileStream.Create(unitName, fmCreate), soOwned);
|
|
|
|
try
|
|
|
|
WriteUnitHeader(unitStream, unitName);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
WriteInterface(unitStream);
|
|
|
|
WriteSection(unitStream, dxsForward);
|
|
|
|
|
|
|
|
FProcessedItems := TX2OIHash.Create();
|
|
|
|
try
|
|
|
|
FProcessedItems.Clear();
|
|
|
|
WriteSection(unitStream, dxsInterface);
|
|
|
|
|
|
|
|
FProcessedItems.Clear();
|
|
|
|
WriteSection(unitStream, dxsClass);
|
|
|
|
finally
|
|
|
|
FreeAndNil(FProcessedItems);
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
WriteDocumentFunctions(unitStream, dxsInterface);
|
|
|
|
WriteEnumerationConstants(unitStream);
|
2008-02-26 21:53:11 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
WriteImplementation(unitStream);
|
|
|
|
WriteDocumentFunctions(unitStream, dxsImplementation);
|
|
|
|
WriteSection(unitStream, dxsImplementation);
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
WriteUnitFooter(unitStream);
|
|
|
|
finally
|
|
|
|
FreeAndNil(unitStream);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TDelphiXMLDataBindingGenerator.GenerateMultipleDataBinding();
|
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-02-26 21:53:11 +00:00
|
|
|
function TDelphiXMLDataBindingGenerator.TranslateDataType(ADataType: IXMLTypeDef): String;
|
2008-03-09 20:36:27 +00:00
|
|
|
var
|
|
|
|
mappingIndex: Integer;
|
|
|
|
dataTypeName: string;
|
|
|
|
|
2008-02-26 21:53:11 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
Assert(not ADataType.IsComplex, 'Complex DataTypes not supported');
|
|
|
|
Assert(ADataType.Enumerations.Count = 0, 'Enumerations not supported');
|
2008-02-26 21:53:11 +00:00
|
|
|
Result := 'Variant';
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
if (ADataType.NamespaceURI = SXMLSchemaURI_1999) or
|
|
|
|
(ADataType.NamespaceURI = SXMLSchemaURI_2000_10) or
|
|
|
|
(ADataType.NamespaceURI = SXMLSchemaURI_2001) then
|
2008-02-26 21:53:11 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
dataTypeName := ADataType.Name;
|
|
|
|
|
|
|
|
for mappingIndex := Low(SimpleTypeMapping) to High(SimpleTypeMapping) do
|
2008-03-10 16:04:46 +00:00
|
|
|
if SimpleTypeMapping[mappingIndex].SchemaName = dataTypeName then
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-03-10 16:04:46 +00:00
|
|
|
Result := SimpleTypeMapping[mappingIndex].DelphiName;
|
2008-03-09 20:36:27 +00:00
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
2008-03-10 16:04:46 +00:00
|
|
|
|
|
|
|
// if Result = 'Variant' then
|
|
|
|
// ShowMessage('Unknown type: ' + ADataType.Name);
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TDelphiXMLDataBindingGenerator.DelphiSafeName(const AName: String): String;
|
|
|
|
var
|
|
|
|
wordIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := AName;
|
|
|
|
|
|
|
|
for wordIndex := Low(ReservedWords) to High(ReservedWords) do
|
2008-02-26 21:53:11 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
if Result = ReservedWords[wordIndex] then
|
2008-02-26 21:53:11 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
Result := '_' + Result;
|
|
|
|
Break;
|
2008-02-26 21:53:11 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
function TDelphiXMLDataBindingGenerator.TranslateItemName(AItem: TXMLDataBindingItem): String;
|
|
|
|
begin
|
|
|
|
Result := DelphiSafeName(inherited TranslateItemName(AItem));
|
|
|
|
|
|
|
|
case AItem.ItemType of
|
|
|
|
itEnumerationMember:
|
|
|
|
Result := TXMLDataBindingEnumerationMember(AItem).Enumeration.TranslatedName + '_' + Result;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteUnitHeader(AStream: TStreamHelper; const AFileName: String);
|
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
// #ToDo3 (MvR) 14-4-2007: if outputtype = multiple, use include files
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
AStream.WriteLn('{');
|
|
|
|
AStream.WriteLn(' X2Software XML Data Binding Wizard');
|
|
|
|
AStream.WriteLn(' Generated from: ' + SourceFileName);
|
|
|
|
AStream.WriteLn('}');
|
|
|
|
AStream.WriteLn('unit ' + ChangeFileExt(ExtractFileName(AFileName), '') + ';');
|
|
|
|
AStream.WriteLn();
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteInterface(AStream: TStreamHelper);
|
|
|
|
begin
|
2008-02-20 06:52:00 +00:00
|
|
|
AStream.WriteLn('interface');
|
|
|
|
AStream.WriteLn('uses');
|
2008-03-09 20:36:27 +00:00
|
|
|
AStream.WriteLn(' Classes,');
|
2008-02-20 06:52:00 +00:00
|
|
|
AStream.WriteLn(' XMLDoc,');
|
2008-03-09 20:36:27 +00:00
|
|
|
AStream.WriteLn(' XMLIntf;');
|
2008-02-20 06:52:00 +00:00
|
|
|
AStream.WriteLn();
|
2008-03-09 20:36:27 +00:00
|
|
|
AStream.WriteLn('type');
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteImplementation(AStream: TStreamHelper);
|
|
|
|
begin
|
|
|
|
AStream.WriteLn('implementation');
|
|
|
|
AStream.WriteLn();
|
|
|
|
end;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteUnitFooter(AStream: TStreamHelper);
|
|
|
|
begin
|
|
|
|
AStream.WriteLn();
|
|
|
|
AStream.WriteLn('end.');
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteSection(AStream: TStreamHelper; ASection: TDelphiXMLSection);
|
|
|
|
var
|
|
|
|
schemaIndex: Integer;
|
|
|
|
schema: TXMLDataBindingSchema;
|
|
|
|
itemIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
for schemaIndex := 0 to Pred(SchemaCount) do
|
|
|
|
begin
|
|
|
|
schema := Schemas[schemaIndex];
|
2008-03-17 06:08:49 +00:00
|
|
|
AStream.WriteLnNamedFmt(SectionComments[ASection],
|
|
|
|
['SchemaName', schema.SchemaName]);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
for itemIndex := 0 to Pred(schema.ItemCount) do
|
|
|
|
WriteSchemaItem(AStream, schema.Items[itemIndex], ASection);
|
|
|
|
|
|
|
|
AStream.WriteLn;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteDocumentFunctions(AStream: TStreamHelper; ASection: TDelphiXMLSection);
|
|
|
|
var
|
|
|
|
schemaIndex: Integer;
|
|
|
|
schema: TXMLDataBindingSchema;
|
|
|
|
itemIndex: Integer;
|
|
|
|
item: TXMLDataBindingItem;
|
|
|
|
interfaceItem: TXMLDataBindingInterface;
|
|
|
|
hasItem: Boolean;
|
|
|
|
docBinding: String;
|
|
|
|
|
|
|
|
begin
|
|
|
|
hasItem := False;
|
|
|
|
|
|
|
|
for schemaIndex := 0 to Pred(SchemaCount) do
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
schema := Schemas[schemaIndex];
|
|
|
|
|
|
|
|
for itemIndex := 0 to Pred(schema.ItemCount) do
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
item := schema.Items[itemIndex];
|
2008-02-20 06:52:00 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
if item.ItemType = itInterface then
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
interfaceItem := TXMLDataBindingInterface(item);
|
|
|
|
|
|
|
|
if item.DocumentElement then
|
2008-02-26 21:53:11 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
if not hasItem then
|
|
|
|
begin
|
|
|
|
if ASection = dxsInterface then
|
|
|
|
AStream.Write(' ');
|
2008-03-17 12:17:55 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
AStream.WriteLn('{ Document functions }');
|
|
|
|
hasItem := True;
|
|
|
|
end;
|
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
docBinding := NamedFormat('GetDocBinding(''%<SourceName>:s'', TXML%<Name>:s, TargetNamespace) as IXML%<Name>:s',
|
2008-03-17 12:17:55 +00:00
|
|
|
['SourceName', interfaceItem.Name,
|
|
|
|
'Name', interfaceItem.TranslatedName]);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
with TNamedFormatStringList.Create() do
|
|
|
|
try
|
|
|
|
case ASection of
|
|
|
|
dxsInterface:
|
|
|
|
begin
|
2008-03-17 16:02:57 +00:00
|
|
|
Add(' function Get%<Name>:s(ADocument: IXMLDocument): IXML%<Name>:s;');
|
|
|
|
Add(' function Load%<Name>:s(const AFileName: String): IXML%<Name>:s;');
|
|
|
|
Add(' function Load%<Name>:sFromStream(AStream: TStream): IXML%<Name>:s;');
|
|
|
|
Add(' function New%<Name>:s: IXML%<Name>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
end;
|
|
|
|
dxsImplementation:
|
|
|
|
begin
|
2008-03-17 16:02:57 +00:00
|
|
|
Add('function Get%<Name>:s(ADocument: IXMLDocument): IXML%<Name>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
Add('begin');
|
|
|
|
Add(' Result := ADocument.' + docBinding);
|
|
|
|
Add('end;');
|
|
|
|
AddLn;
|
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
Add('function Load%<Name>:s(const AFileName: String): IXML%<Name>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
Add('begin');
|
|
|
|
Add(' Result := LoadXMLDocument(AFileName).' + docBinding);
|
|
|
|
Add('end;');
|
|
|
|
AddLn;
|
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
Add('function Load%<Name>:sFromStream(AStream: TStream): IXML%<Name>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
Add('var');
|
|
|
|
Add(' doc: IXMLDocument;');
|
|
|
|
AddLn;
|
|
|
|
Add('begin');
|
|
|
|
Add(' doc := NewXMLDocument;');
|
|
|
|
Add(' doc.LoadFromStream(AStream);');
|
2008-03-17 16:02:57 +00:00
|
|
|
Add(' Result := Get%<Name>:s(doc);');
|
2008-03-17 12:17:55 +00:00
|
|
|
Add('end;');
|
|
|
|
AddLn;
|
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
Add('function New%<Name>:s: IXML%<Name>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
Add('begin');
|
|
|
|
Add(' Result := NewXMLDocument.' + docBinding);
|
|
|
|
Add('end;');
|
|
|
|
AddLn;
|
|
|
|
end;
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
AStream.Write(Format(['Name', interfaceItem.TranslatedName]));
|
|
|
|
finally
|
|
|
|
Free();
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
AStream.WriteLn();
|
2008-02-26 21:53:11 +00:00
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
if hasItem and (ASection = dxsInterface) then
|
|
|
|
begin
|
|
|
|
// #ToDo3 (MvR) 9-3-2008: namespace support?
|
|
|
|
AStream.WriteLn('const');
|
|
|
|
AStream.WriteLn(' TargetNamespace = '''';');
|
|
|
|
AStream.WriteLn();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteEnumerationConstants(AStream: TStreamHelper);
|
2008-02-20 06:52:00 +00:00
|
|
|
var
|
2008-03-09 20:36:27 +00:00
|
|
|
item: TXMLDataBindingItem;
|
|
|
|
itemIndex: Integer;
|
|
|
|
schema: TXMLDataBindingSchema;
|
|
|
|
schemaIndex: Integer;
|
|
|
|
hasItem: Boolean;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
{ Write array constants for enumerations }
|
|
|
|
hasItem := False;
|
|
|
|
|
|
|
|
for schemaIndex := 0 to Pred(SchemaCount) do
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
schema := Schemas[schemaIndex];
|
2008-02-20 06:52:00 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
for itemIndex := 0 to Pred(schema.ItemCount) do
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
item := schema.Items[itemIndex];
|
|
|
|
|
|
|
|
if item.ItemType = itEnumeration then
|
2008-02-26 21:53:11 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
if not hasItem then
|
|
|
|
AStream.WriteLn('const');
|
|
|
|
|
|
|
|
WriteSchemaEnumerationArray(AStream, TXMLDataBindingEnumeration(item));
|
|
|
|
hasItem := True;
|
2008-02-26 21:53:11 +00:00
|
|
|
end;
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteDocumentation(AStream: TStreamHelper; AItem: TXMLDataBindingItem);
|
|
|
|
var
|
|
|
|
lines: TStringList;
|
|
|
|
lineIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
// #ToDo2 (MvR) 9-3-2008: check for Delphi comment-ending sequences
|
|
|
|
if not AItem.HasDocumentation then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
lines := TStringList.Create();
|
|
|
|
try
|
|
|
|
lines.Text := WrapText(AItem.Documentation, 76);
|
|
|
|
|
|
|
|
AStream.WriteLn(' {');
|
|
|
|
for lineIndex := 0 to Pred(lines.Count) do
|
|
|
|
AStream.WriteLn(' ' + lines[lineIndex]);
|
|
|
|
|
|
|
|
AStream.WriteLn(' }');
|
|
|
|
finally
|
|
|
|
FreeAndNil(lines);
|
|
|
|
end;
|
|
|
|
end;
|
2008-02-26 21:53:11 +00:00
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteSchemaItem(AStream: TStreamHelper; AItem: TXMLDataBindingItem; ASection: TDelphiXMLSection);
|
|
|
|
begin
|
|
|
|
case AItem.ItemType of
|
|
|
|
itInterface: WriteSchemaInterface(AStream, TXMLDataBindingInterface(AItem), ASection);
|
|
|
|
itCollection: WriteSchemaCollection(AStream, TXMLDataBindingCollection(AItem), ASection);
|
|
|
|
itEnumeration: WriteSchemaEnumeration(AStream, TXMLDataBindingEnumeration(AItem), ASection);
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteSchemaInterface(AStream: TStreamHelper; AItem: TXMLDataBindingInterface; ASection: TDelphiXMLSection);
|
|
|
|
var
|
|
|
|
parent: String;
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
if ASection in [dxsInterface, dxsClass] then
|
|
|
|
begin
|
|
|
|
{ Ensure the base item is completely defined first, Delphi doesn't allow
|
|
|
|
inheritance with just a forward declaration. }
|
|
|
|
if ProcessedItems.Exists(AItem) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
if Assigned(AItem.BaseItem) then
|
|
|
|
WriteSchemaInterface(AStream, AItem.BaseItem, ASection);
|
|
|
|
|
|
|
|
ProcessedItems[AItem] := 1;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-02-26 21:53:11 +00:00
|
|
|
case ASection of
|
|
|
|
dxsForward:
|
2008-03-17 06:08:49 +00:00
|
|
|
AStream.WriteLnNamedFmt(InterfaceItemForward,
|
|
|
|
['Name', AItem.TranslatedName]);
|
2008-02-26 21:53:11 +00:00
|
|
|
dxsInterface:
|
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
if Assigned(AItem.BaseItem) then
|
2008-03-17 12:17:55 +00:00
|
|
|
parent := PrefixInterface + AItem.BaseItem.TranslatedName
|
2008-03-09 20:36:27 +00:00
|
|
|
else
|
|
|
|
parent := ItemInterface;
|
|
|
|
|
|
|
|
WriteDocumentation(AStream, AItem);
|
2008-03-17 06:08:49 +00:00
|
|
|
AStream.WriteLnNamedFmt(InterfaceItemInterface,
|
|
|
|
['Name', AItem.TranslatedName,
|
|
|
|
'ParentName', parent]);
|
|
|
|
AStream.WriteLn(' ' + CreateNewGUID());
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
WriteSchemaInterfaceProperties(AStream, AItem, ASection);
|
|
|
|
|
2008-02-26 21:53:11 +00:00
|
|
|
AStream.WriteLn(' end;');
|
|
|
|
AStream.WriteLn();
|
|
|
|
end;
|
|
|
|
dxsClass:
|
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
if Assigned(AItem.BaseItem) then
|
2008-03-17 12:17:55 +00:00
|
|
|
parent := PrefixClass + AItem.BaseItem.TranslatedName
|
2008-03-09 20:36:27 +00:00
|
|
|
else
|
|
|
|
parent := ItemClass;
|
|
|
|
|
2008-03-17 06:08:49 +00:00
|
|
|
AStream.WriteLnNamedFmt(InterfaceItemClass,
|
|
|
|
['Name', AItem.TranslatedName,
|
|
|
|
'ParentName', parent]);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
WriteSchemaInterfaceProperties(AStream, AItem, ASection);
|
|
|
|
|
2008-02-26 21:53:11 +00:00
|
|
|
AStream.WriteLn(' end;');
|
|
|
|
AStream.WriteLn();
|
|
|
|
end;
|
|
|
|
dxsImplementation:
|
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
WriteSchemaInterfaceProperties(AStream, AItem, ASection);
|
2008-02-26 21:53:11 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteSchemaInterfaceProperties(AStream: TStreamHelper; AItem: TXMLDataBindingInterface; ASection: TDelphiXMLSection);
|
|
|
|
|
|
|
|
procedure WriteAfterConstruction;
|
|
|
|
var
|
|
|
|
propertyIndex: Integer;
|
|
|
|
propertyItem: TXMLDataBindingProperty;
|
|
|
|
itemProperty: TXMLDataBindingItemProperty;
|
|
|
|
hasInterface: Boolean;
|
|
|
|
|
|
|
|
begin
|
|
|
|
hasInterface := False;
|
|
|
|
|
|
|
|
for propertyIndex := 0 to Pred(AItem.PropertyCount) do
|
|
|
|
begin
|
|
|
|
propertyItem := AItem.Properties[propertyIndex];
|
|
|
|
|
|
|
|
if propertyItem.PropertyType = ptItem then
|
|
|
|
begin
|
|
|
|
itemProperty := TXMLDataBindingItemProperty(propertyItem);
|
|
|
|
|
|
|
|
if Assigned(itemProperty.Item) and
|
|
|
|
(itemProperty.Item.ItemType <> itEnumeration) then
|
|
|
|
begin
|
|
|
|
case ASection of
|
|
|
|
dxsClass:
|
|
|
|
begin
|
|
|
|
AStream.WriteLn(' public');
|
|
|
|
AStream.WriteLn(' procedure AfterConstruction; override;');
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
dxsImplementation:
|
|
|
|
begin
|
|
|
|
if not hasInterface then
|
|
|
|
begin
|
2008-03-17 06:08:49 +00:00
|
|
|
AStream.WriteLnFmt('procedure TXML%s.AfterConstruction;', [AItem.TranslatedName]);
|
2008-03-09 20:36:27 +00:00
|
|
|
AStream.WriteLn('begin');
|
|
|
|
hasInterface := True;
|
|
|
|
end;
|
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<SourceName>:s'', TXML%<Name>:s);',
|
2008-03-17 06:08:49 +00:00
|
|
|
['SourceName', itemProperty.Item.Name,
|
|
|
|
'Name', itemProperty.Item.TranslatedName]);
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if (ASection = dxsImplementation) and hasInterface then
|
|
|
|
begin
|
|
|
|
AStream.WriteLn('end;');
|
|
|
|
AStream.WriteLn();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-02-26 21:53:11 +00:00
|
|
|
var
|
2008-03-09 20:36:27 +00:00
|
|
|
propertyIndex: Integer;
|
|
|
|
itemProperty: TXMLDataBindingProperty;
|
|
|
|
propertyItem: TXMLDataBindingItem;
|
|
|
|
dataTypeName: String;
|
|
|
|
writeOptional: Boolean;
|
|
|
|
writeTextProp: Boolean;
|
|
|
|
hasMembers: Boolean;
|
|
|
|
localHasMembers: Boolean;
|
|
|
|
member: TDelphiXMLMember;
|
|
|
|
value: String;
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode: TNamedFormatStringList;
|
|
|
|
propertyItemName: String;
|
2008-02-26 21:53:11 +00:00
|
|
|
|
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
// #ToDo1 (MvR) 9-3-2008: refactor WriteSchemaInterfaceProperties
|
2008-03-17 12:17:55 +00:00
|
|
|
// #ToDo1 (MvR) 17-3-2008: support conversions!
|
2008-03-09 20:36:27 +00:00
|
|
|
if ASection = dxsForward then
|
|
|
|
Exit;
|
2008-02-26 21:53:11 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
if ASection = dxsImplementation then
|
|
|
|
WriteAfterConstruction();
|
2008-02-26 21:53:11 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
hasMembers := False;
|
|
|
|
|
|
|
|
for member := Low(TDelphiXMLMember) to High(TDelphiXMLMember) do
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
localHasMembers := False;
|
|
|
|
|
|
|
|
for propertyIndex := 0 to Pred(AItem.PropertyCount) do
|
|
|
|
begin
|
|
|
|
itemProperty := AItem.Properties[propertyIndex];
|
2008-03-17 12:17:55 +00:00
|
|
|
propertyItem := nil;
|
2008-03-09 20:36:27 +00:00
|
|
|
dataTypeName := '';
|
|
|
|
writeTextProp := False;
|
2008-03-12 06:31:09 +00:00
|
|
|
writeOptional := True;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
{ Get data type }
|
|
|
|
case itemProperty.PropertyType of
|
|
|
|
ptSimple:
|
|
|
|
dataTypeName := TranslateDataType(TXMLDataBindingSimpleProperty(itemProperty).DataType);
|
|
|
|
ptItem:
|
|
|
|
begin
|
|
|
|
propertyItem := TXMLDataBindingItemProperty(itemProperty).Item;
|
|
|
|
if Assigned(propertyItem) then
|
|
|
|
begin
|
|
|
|
if propertyItem.ItemType = itEnumeration then
|
|
|
|
begin
|
2008-03-17 12:17:55 +00:00
|
|
|
dataTypeName := PrefixClass;
|
2008-03-09 20:36:27 +00:00
|
|
|
writeTextProp := True;
|
|
|
|
end else
|
2008-03-17 12:17:55 +00:00
|
|
|
dataTypeName := PrefixInterface;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-12 06:31:09 +00:00
|
|
|
{ Collections have a Count property, no need to write a
|
2008-03-17 12:17:55 +00:00
|
|
|
HasX property as well. }
|
2008-03-12 06:31:09 +00:00
|
|
|
writeOptional := (propertyItem.ItemType <> itCollection);
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
dataTypeName := dataTypeName + propertyItem.TranslatedName;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
if Length(dataTypeName) > 0 then
|
|
|
|
begin
|
2008-03-17 12:17:55 +00:00
|
|
|
writeOptional := writeOptional and
|
|
|
|
itemProperty.IsOptional and
|
|
|
|
(member in [dxmPropertyGet, dxmPropertyDeclaration]);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode := TNamedFormatStringList.Create();
|
|
|
|
try
|
|
|
|
case ASection of
|
|
|
|
dxsInterface,
|
|
|
|
dxsClass:
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-03-17 12:17:55 +00:00
|
|
|
{ Interface declaration }
|
2008-03-09 20:36:27 +00:00
|
|
|
if not hasMembers then
|
|
|
|
begin
|
|
|
|
if ASection = dxsClass then
|
|
|
|
AStream.WriteLn(' protected');
|
|
|
|
end else if not localHasMembers then
|
|
|
|
AStream.WriteLn();
|
2008-03-17 12:17:55 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
case member of
|
|
|
|
dxmPropertyGet:
|
|
|
|
begin
|
|
|
|
if writeOptional then
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' function GetHas%<PropertyName>:s: Boolean;');
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
if writeTextProp then
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' function Get%<PropertyName>:sText: WideString;');
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' function Get%<PropertyName>:s: %<DataType>:s;');
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
dxmPropertySet:
|
|
|
|
if not itemProperty.IsReadOnly then
|
|
|
|
begin
|
|
|
|
if writeTextProp then
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' procedure Set%<PropertyName>:sText(const Value: WideString);');
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' procedure Set%<PropertyName>:s(const Value: %<DataType>:s);');
|
2008-03-17 12:17:55 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
dxmPropertyDeclaration:
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-03-17 12:17:55 +00:00
|
|
|
if writeOptional then
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' property Has%<PropertyName>:s: Boolean read GetHas%<PropertyName>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
|
|
|
|
if writeTextProp then
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' property %<PropertyName>:sText: WideString read Get%<PropertyName>:sText;');
|
2008-03-17 12:17:55 +00:00
|
|
|
|
|
|
|
if itemProperty.IsReadOnly then
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' property %<PropertyName>:s: %<DataType>:s read Get%<PropertyName>:s;')
|
2008-03-17 12:17:55 +00:00
|
|
|
else
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' property %<PropertyName>:s: %<DataType>:s read Get%<PropertyName>:s write Set%<PropertyName>:s;');
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
2008-03-17 12:17:55 +00:00
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
hasMembers := True;
|
|
|
|
localHasMembers := True;
|
|
|
|
end;
|
|
|
|
dxsImplementation:
|
|
|
|
begin
|
|
|
|
{ Implementation }
|
|
|
|
case member of
|
|
|
|
dxmPropertyGet:
|
|
|
|
begin
|
|
|
|
if writeOptional then
|
|
|
|
begin
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add('function TXML%<Name>:s.GetHas%<PropertyName>:s: Boolean;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('begin');
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' Result := Assigned(ChildNodes.FindNode(''%<PropertySourceName>:s''));');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('end;');
|
|
|
|
sourceCode.AddLn;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
if writeTextProp then
|
|
|
|
begin
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add('function TXML%<Name>:s.Get%<PropertyName>:sText: WideString;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('begin');
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' Result := ChildNodes[''%<PropertySourceName>:s''].NodeValue;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('end;');
|
|
|
|
sourceCode.AddLn;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add('function TXML%<Name>:s.Get%<PropertyName>:s: %<DataType>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
|
|
|
|
case itemProperty.PropertyType of
|
|
|
|
ptSimple:
|
|
|
|
begin
|
|
|
|
sourceCode.Add('begin');
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' Result := ChildNodes[''%<PropertySourceName>:s''].NodeValue;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('end;');
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
ptItem:
|
|
|
|
begin
|
|
|
|
if Assigned(propertyItem) then
|
|
|
|
begin
|
|
|
|
case propertyItem.ItemType of
|
|
|
|
itInterface,
|
|
|
|
itCollection:
|
|
|
|
begin
|
|
|
|
sourceCode.Add('begin');
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' Result := (ChildNodes[''%<Name>:s''] as IXML%<PropertyItemName>:s);');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('end;');
|
|
|
|
end;
|
|
|
|
|
|
|
|
itEnumeration:
|
|
|
|
begin
|
|
|
|
sourceCode.Add('var');
|
|
|
|
sourceCode.Add(' nodeValue: WideString;');
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' enumValue: %<DataType>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.AddLn;
|
|
|
|
sourceCode.Add('begin');
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' Result := %<DataType>:s(-1);');
|
|
|
|
sourceCode.Add(' nodeValue := Get%<PropertyName>:sText;');
|
|
|
|
sourceCode.Add(' for enumValue := Low(%<DataType>:s) to High(%<DataType>:s) do');
|
|
|
|
sourceCode.Add(' if %<PropertyName>:sValues[enumValue] = nodeValue then');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add(' begin');
|
|
|
|
sourceCode.Add(' Result := enumValue;');
|
|
|
|
sourceCode.Add(' break;');
|
|
|
|
sourceCode.Add(' end;');
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
2008-03-17 12:17:55 +00:00
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
2008-03-17 12:17:55 +00:00
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.AddLn;
|
|
|
|
end;
|
|
|
|
dxmPropertySet:
|
|
|
|
if not itemProperty.IsReadOnly then
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-03-17 12:17:55 +00:00
|
|
|
if writeTextProp then
|
|
|
|
begin
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add('procedure TXML%<Name>:s.Set%<PropertyName>:sText(const Value: WideString);');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('begin');
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' ChildNodes[''%<PropertySourceName>:s''].NodeValue := Value;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('end;');
|
|
|
|
sourceCode.AddLn;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Assigned(propertyItem) and (propertyItem.ItemType = itEnumeration) then
|
2008-03-17 16:02:57 +00:00
|
|
|
value := '%<PropertyItemName>:sValues[Value]'
|
2008-03-17 12:17:55 +00:00
|
|
|
else
|
|
|
|
value := 'Value';
|
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add('procedure TXML%<Name>:s.Set%<PropertyName>:s(const Value: %<DataType>:s);');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('begin');
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' ChildNodes[''%<PropertySourceName>:s''].NodeValue := ' + value + ';');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('end;');
|
|
|
|
sourceCode.AddLn;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
2008-03-17 12:17:55 +00:00
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
end;
|
2008-03-17 12:17:55 +00:00
|
|
|
|
|
|
|
propertyItemName := '';
|
|
|
|
if Assigned(propertyItem) then
|
|
|
|
propertyItemName := propertyItem.TranslatedName;
|
|
|
|
|
|
|
|
AStream.Write(sourceCode.Format(['Name', AItem.TranslatedName,
|
|
|
|
'PropertySourceName', itemProperty.Name,
|
|
|
|
'PropertyName', itemProperty.TranslatedName,
|
|
|
|
'PropertyItemName', propertyItemName,
|
|
|
|
'DataType', dataTypeName]));
|
|
|
|
finally
|
|
|
|
FreeAndNil(sourceCode);
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if ASection = dxsClass then
|
|
|
|
WriteAfterConstruction();
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteSchemaCollection(AStream: TStreamHelper; AItem: TXMLDataBindingCollection; ASection: TDelphiXMLSection);
|
|
|
|
begin
|
2008-03-17 12:17:55 +00:00
|
|
|
if not Assigned(AItem.CollectionItem) then
|
|
|
|
Exit;
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
case ASection of
|
|
|
|
dxsForward:
|
2008-03-17 12:17:55 +00:00
|
|
|
AStream.WriteLnNamedFmt(InterfaceItemForward,
|
|
|
|
['Name',
|
|
|
|
AItem.TranslatedName]);
|
2008-03-09 20:36:27 +00:00
|
|
|
dxsInterface:
|
|
|
|
begin
|
2008-03-17 12:17:55 +00:00
|
|
|
AStream.WriteLnNamedFmt(InterfaceItemInterface,
|
|
|
|
['Name', AItem.TranslatedName,
|
|
|
|
'ParentName', CollectionInterface]);
|
|
|
|
AStream.WriteLn(' ' + CreateNewGUID());
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
WriteSchemaCollectionProperties(AStream, AItem, ASection);
|
|
|
|
|
|
|
|
AStream.WriteLn(' end;');
|
|
|
|
AStream.WriteLn();
|
|
|
|
end;
|
|
|
|
dxsClass:
|
|
|
|
begin
|
2008-03-17 12:17:55 +00:00
|
|
|
AStream.WriteLnNamedFmt(InterfaceItemClass,
|
|
|
|
['Name', AItem.TranslatedName,
|
|
|
|
'ParentName', CollectionClass]);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
WriteSchemaCollectionProperties(AStream, AItem, ASection);
|
|
|
|
|
|
|
|
AStream.WriteLn(' end;');
|
|
|
|
AStream.WriteLn();
|
|
|
|
end;
|
|
|
|
dxsImplementation:
|
|
|
|
begin
|
|
|
|
WriteSchemaCollectionProperties(AStream, AItem, ASection);
|
|
|
|
end;
|
2008-02-26 21:53:11 +00:00
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
2008-02-26 21:53:11 +00:00
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteSchemaCollectionProperties(AStream: TStreamHelper; AItem: TXMLDataBindingCollection; ASection: TDelphiXMLSection);
|
2008-03-14 15:35:07 +00:00
|
|
|
var
|
2008-03-17 12:17:55 +00:00
|
|
|
dataIntfName: string;
|
2008-03-17 16:02:57 +00:00
|
|
|
dataTypeName: string;
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode: TNamedFormatStringList;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if ASection = dxsClass then
|
|
|
|
AStream.WriteLn(' protected');
|
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
// #ToDo1 (MvR) 17-3-2008: DataType for enumerations etc.
|
2008-03-17 16:02:57 +00:00
|
|
|
case AItem.CollectionItem.PropertyType of
|
|
|
|
ptSimple:
|
|
|
|
begin
|
|
|
|
dataTypeName := AItem.CollectionItem.TranslatedName;
|
|
|
|
dataIntfName := 'IXMLNode';
|
|
|
|
end;
|
|
|
|
ptItem:
|
|
|
|
begin
|
|
|
|
dataTypeName := PrefixInterface + AItem.CollectionItem.TranslatedName;
|
|
|
|
dataIntfName := dataTypeName;
|
|
|
|
end;
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode := TNamedFormatStringList.Create();
|
|
|
|
try
|
|
|
|
case ASection of
|
|
|
|
dxsInterface,
|
|
|
|
dxsClass:
|
|
|
|
begin
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' function Get_%<ItemName>:s(Index: Integer): %<DataType>:s;');
|
|
|
|
sourceCode.Add(' function Add: %<DataType>:s;');
|
|
|
|
sourceCode.Add(' function Insert(Index: Integer): %<DataType>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
end;
|
|
|
|
dxsImplementation:
|
|
|
|
begin
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add('procedure TXML%<Name>:s.AfterConstruction;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('begin');
|
|
|
|
|
|
|
|
// #ToDo1 (MvR) 17-3-2008: DataType class / interface!!
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' RegisterChildNode(''%<ItemSourceName>:s'', %<DataType>:s);');
|
2008-03-17 12:17:55 +00:00
|
|
|
|
|
|
|
sourceCode.AddLn;
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' ItemTag := ''%<ItemSourceName>:s'';');
|
|
|
|
sourceCode.Add(' ItemInterface := %<DataInterface>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.AddLn;
|
|
|
|
sourceCode.Add(' inherited;');
|
|
|
|
sourceCode.Add('end;');
|
|
|
|
sourceCode.AddLn;
|
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add('function TXML%<Name>:s.Get_%<ItemName>:s(Index: Integer): %<DataType>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('begin');
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' Result := (List[Index] as %<DataType>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('end;');
|
|
|
|
sourceCode.AddLn;
|
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add('function TXML%<Name>:s.Add(Index: Integer): %<DataType>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('begin');
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' Result := (AddItem(-1) as %<DataType>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('end;');
|
|
|
|
sourceCode.AddLn;
|
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add('function TXML%<Name>:s.Insert(Index: Integer): %<DataType>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('begin');
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' Result := (AddItem(Index) as %<DataType>:s;');
|
2008-03-17 12:17:55 +00:00
|
|
|
sourceCode.Add('end;');
|
|
|
|
sourceCode.AddLn;
|
|
|
|
end;
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
case ASection of
|
|
|
|
dxsInterface:
|
|
|
|
begin
|
|
|
|
sourceCode.AddLn;
|
2008-03-17 16:02:57 +00:00
|
|
|
sourceCode.Add(' property %<ItemName>:s[Index: Integer]: %<DataType>:s read Get_%<ItemName>:s; default;');
|
2008-03-17 12:17:55 +00:00
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
dxsClass:
|
|
|
|
begin
|
|
|
|
sourceCode.Add(' public');
|
|
|
|
sourceCode.Add(' procedure AfterConstruction; override;');
|
|
|
|
end;
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-17 12:17:55 +00:00
|
|
|
AStream.Write(sourceCode.Format(['Name', AItem.TranslatedName,
|
|
|
|
'ItemName', AItem.CollectionItem.TranslatedName,
|
|
|
|
'ItemSourceName', AItem.CollectionItem.Name,
|
|
|
|
'DataType', dataTypeName,
|
|
|
|
'DataInterface', dataIntfName]));
|
|
|
|
finally
|
|
|
|
FreeAndNil(sourceCode);
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
2008-02-26 21:53:11 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteSchemaEnumeration(AStream: TStreamHelper; AItem: TXMLDataBindingEnumeration; ASection: TDelphiXMLSection);
|
2008-02-26 21:53:11 +00:00
|
|
|
var
|
2008-03-09 20:36:27 +00:00
|
|
|
memberIndex: Integer;
|
2008-02-26 21:53:11 +00:00
|
|
|
enumStart: String;
|
|
|
|
lineIndent: String;
|
|
|
|
|
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
if (ASection <> dxsForward) or (AItem.MemberCount = 0) then
|
2008-02-26 21:53:11 +00:00
|
|
|
exit;
|
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
enumStart := NamedFormat(' TXML%<Name>:s = (',
|
2008-03-17 06:08:49 +00:00
|
|
|
['Name', AItem.TranslatedName]);
|
2008-02-26 21:53:11 +00:00
|
|
|
AStream.Write(enumStart);
|
|
|
|
lineIndent := StringOfChar(' ', Length(enumStart));
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
for memberIndex := 0 to Pred(AItem.MemberCount) do
|
2008-02-26 21:53:11 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
if memberIndex > 0 then
|
2008-02-26 21:53:11 +00:00
|
|
|
AStream.Write(lineIndent);
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
AStream.Write(AItem.Members[memberIndex].TranslatedName);
|
2008-02-26 21:53:11 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
if memberIndex < Pred(AItem.MemberCount) then
|
2008-02-26 21:53:11 +00:00
|
|
|
AStream.WriteLn(',')
|
|
|
|
else
|
|
|
|
AStream.WriteLn(');');
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TDelphiXMLDataBindingGenerator.WriteSchemaEnumerationArray(AStream: TStreamHelper; AItem: TXMLDataBindingEnumeration);
|
2008-02-26 21:53:11 +00:00
|
|
|
var
|
2008-03-09 20:36:27 +00:00
|
|
|
memberIndex: Integer;
|
|
|
|
enumStart: String;
|
|
|
|
lineIndent: String;
|
2008-02-26 21:53:11 +00:00
|
|
|
|
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
if (AItem.MemberCount = 0) then
|
|
|
|
exit;
|
2008-02-26 21:53:11 +00:00
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
enumStart := NamedFormat(' %<Name>:sValues: ', ['Name', AItem.TranslatedName]);
|
|
|
|
AStream.WriteLn(enumStart + NamedFormat('array[TXML%<Name>:s] of WideString =',
|
2008-03-17 06:08:49 +00:00
|
|
|
['Name', AItem.TranslatedName]));
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
lineIndent := StringOfChar(' ', Length(enumStart));
|
2008-02-26 21:53:11 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
AStream.WriteLn(lineIndent + '(');
|
2008-02-26 21:53:11 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
for memberIndex := 0 to Pred(AItem.MemberCount) do
|
2008-02-26 21:53:11 +00:00
|
|
|
begin
|
2008-03-17 16:02:57 +00:00
|
|
|
AStream.Write(NamedFormat('%<Indent>:s ''%<Name>:s''',
|
2008-03-17 06:08:49 +00:00
|
|
|
['Indent', lineIndent,
|
|
|
|
'Name', AItem.Members[memberIndex].Name]));
|
2008-02-26 21:53:11 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
if memberIndex < Pred(AItem.MemberCount) then
|
|
|
|
AStream.WriteLn(',')
|
|
|
|
else
|
2008-02-26 21:53:11 +00:00
|
|
|
AStream.WriteLn();
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
AStream.WriteLn(lineIndent + ');');
|
2008-02-20 06:52:00 +00:00
|
|
|
AStream.WriteLn();
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-02-26 21:53:11 +00:00
|
|
|
function TDelphiXMLDataBindingGenerator.CreateNewGUID(): String;
|
|
|
|
var
|
|
|
|
guid: TGUID;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := '{ GUID generation failed }';
|
|
|
|
if CreateGUID(guid) = S_OK then
|
|
|
|
Result := '[''' + GUIDToString(guid) + ''']';
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
function TDelphiXMLDataBindingGenerator.DoGetFileName(const ASchemaName: String): String;
|
|
|
|
begin
|
|
|
|
Result := OutputPath;
|
|
|
|
|
|
|
|
if OutputType = otMultiple then
|
|
|
|
begin
|
|
|
|
Result := IncludeTrailingPathDelimiter(Result) + ASchemaName + '.pas';
|
|
|
|
if Assigned(FOnGetFileName) then
|
|
|
|
FOnGetFileName(Self, ASchemaName, Result);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-03-17 16:02:57 +00:00
|
|
|
|