2008-02-20 06:52:00 +00:00
|
|
|
unit XMLDataBindingGenerator;
|
|
|
|
|
2008-04-25 10:34:16 +00:00
|
|
|
// #ToDo2 (MvR) 25-4-2008: typed wrapper for NodeValue if needed (eg. element with attributes and a value)
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
interface
|
|
|
|
uses
|
2014-10-28 14:22:41 +00:00
|
|
|
System.Classes,
|
|
|
|
System.Generics.Collections,
|
2014-11-15 11:29:35 +00:00
|
|
|
System.SysUtils,
|
2014-10-28 14:22:41 +00:00
|
|
|
Xml.XMLSchema;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
type
|
2014-11-15 11:29:35 +00:00
|
|
|
EXMLDataBindingError = class(Exception);
|
|
|
|
EXMLDataBindingUnresolvedItem = class(EXMLDataBindingError);
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
TXMLDataBindingSchema = class;
|
2008-04-14 19:28:57 +00:00
|
|
|
TXMLDataBindingGeneratorItem = class;
|
2008-03-09 20:36:27 +00:00
|
|
|
TXMLDataBindingItem = class;
|
|
|
|
TXMLDataBindingInterface = class;
|
|
|
|
TXMLDataBindingEnumerationMember = class;
|
|
|
|
TXMLDataBindingEnumeration = class;
|
|
|
|
TXMLDataBindingProperty = class;
|
2008-04-21 15:24:33 +00:00
|
|
|
TXMLDataBindingItemProperty = class;
|
2008-04-14 19:28:57 +00:00
|
|
|
TXMLDataBindingUnresolvedItem = class;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
TXMLDataBindingOutputType = (otSingle, otMultiple);
|
2008-04-14 19:28:57 +00:00
|
|
|
TXMLDataBindingItemType = (itInterface, itEnumeration, itEnumerationMember,
|
2008-04-18 14:36:17 +00:00
|
|
|
itProperty, itUnresolved,
|
|
|
|
itComplexTypeAlias, itSimpleTypeAlias);
|
2014-11-15 11:29:35 +00:00
|
|
|
TXMLDataBindingInterfaceType = (ifElement, ifComplexType, ifEnumeration, ifAttribute);
|
2008-03-09 20:36:27 +00:00
|
|
|
TXMLDataBindingPropertyType = (ptSimple, ptItem);
|
2008-04-14 19:28:57 +00:00
|
|
|
TXMLDataBindingOccurance = (boMinOccurs, boMaxOccurs);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
|
2014-11-15 11:29:35 +00:00
|
|
|
TXMLDataBindingIterateItemsProc = reference to procedure(AItem: TXMLDataBindingItem; var AAbort: Boolean);
|
2008-04-22 13:36:55 +00:00
|
|
|
TXMLDataBindingPostProcessItemEvent = procedure(Sender: TObject; Item: TXMLDataBindingItem) of object;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
TXMLDataBindingGenerator = class(TObject)
|
|
|
|
private
|
|
|
|
FIncludePaths: TStrings;
|
2008-03-09 20:36:27 +00:00
|
|
|
FOutputPath: String;
|
2008-02-20 06:52:00 +00:00
|
|
|
FOutputType: TXMLDataBindingOutputType;
|
|
|
|
FSourceFileName: String;
|
|
|
|
|
2014-10-28 14:22:41 +00:00
|
|
|
FSchemas: TObjectList<TXMLDataBindingSchema>;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
2008-04-22 13:36:55 +00:00
|
|
|
FOnPostProcessItem: TXMLDataBindingPostProcessItemEvent;
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetSchemaCount: Integer;
|
2008-03-09 20:36:27 +00:00
|
|
|
function GetSchemas(Index: Integer): TXMLDataBindingSchema;
|
2008-02-20 06:52:00 +00:00
|
|
|
protected
|
2017-02-17 14:27:30 +00:00
|
|
|
function LoadSchema(const AStream: TStream; const ASchemaName, ASourceFileName: String): TXMLDataBindingSchema;
|
2008-04-14 19:28:57 +00:00
|
|
|
function GetSchemaData(const ALocation: String; out ASourceFileName: String): TStream;
|
2008-03-09 20:36:27 +00:00
|
|
|
function FindSchema(const ALocation: String): TXMLDataBindingSchema;
|
2008-03-14 15:35:07 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure GenerateSchemaObjects(ASchema: TXMLDataBindingSchema; ARootDocument: Boolean);
|
|
|
|
procedure GenerateElementObjects(ASchema: TXMLDataBindingSchema; ARootDocument: Boolean);
|
|
|
|
procedure GenerateComplexTypeObjects(ASchema: TXMLDataBindingSchema);
|
2008-05-14 13:30:54 +00:00
|
|
|
procedure GenerateSimpleTypeObjects(ASchema: TXMLDataBindingSchema);
|
2014-11-15 11:29:35 +00:00
|
|
|
procedure GenerateAttributeObjects(ASchema: TXMLDataBindingSchema);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
function CheckElementOccurance(AElement: IXMLElementDef; AOccurance: TXMLDataBindingOccurance): Boolean;
|
|
|
|
function IsElementOptional(AElement: IXMLElementDef): Boolean;
|
|
|
|
function IsElementRepeating(AElement: IXMLElementDef): Boolean;
|
|
|
|
function IsChoice(AElement: IXMLElementDef): Boolean;
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function ProcessElement(ASchema: TXMLDataBindingSchema; AElement: IXMLElementDef): TXMLDataBindingItem; overload;
|
|
|
|
function ProcessElement(ASchema: TXMLDataBindingSchema; AAttribute: IXMLAttributeDef): TXMLDataBindingItem; overload;
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure ProcessChildElement(ASchema: TXMLDataBindingSchema; AElement: IXMLElementDef; AInterface: TXMLDataBindingInterface);
|
2008-04-14 19:28:57 +00:00
|
|
|
procedure ProcessAttribute(ASchema: TXMLDataBindingSchema; AAttribute: IXMLAttributeDef; AInterface: TXMLDataBindingInterface);
|
2012-05-22 13:16:16 +00:00
|
|
|
function ProcessSimpleTypeReference(ASchema: TXMLDataBindingSchema; AItem: IXMLSchemaItem; ADataType: IXMLTypeDef): TXMLDataBindingItem;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2014-11-15 11:29:35 +00:00
|
|
|
function IterateSchemaItems(ASchema: TXMLDataBindingSchema; AIterateProc: TXMLDataBindingIterateItemsProc): TXMLDataBindingItem;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
function FindInterface(ASchema: TXMLDataBindingSchema; const AName: String; AType: TXMLDataBindingInterfaceType): TXMLDataBindingInterface;
|
2014-11-15 11:29:35 +00:00
|
|
|
function FindEnumeration(ASchema: TXMLDataBindingSchema; const AName: String): TXMLDataBindingEnumeration;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
|
2008-04-14 19:28:57 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure ResolveSchema(ASchema: TXMLDataBindingSchema);
|
2008-04-14 19:28:57 +00:00
|
|
|
procedure ResolveAlias(ASchema: TXMLDataBindingSchema);
|
|
|
|
procedure ResolveItem(ASchema: TXMLDataBindingSchema; AItem: TXMLDataBindingUnresolvedItem);
|
2012-05-22 13:16:16 +00:00
|
|
|
procedure ResolveNameConflicts; virtual;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2010-07-15 10:57:03 +00:00
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
procedure PostProcessSchema(ASchema: TXMLDataBindingSchema);
|
2012-05-22 13:16:16 +00:00
|
|
|
procedure PostProcessItem(ASchema: TXMLDataBindingSchema; AItem: TXMLDataBindingItem); virtual;
|
2008-03-09 20:36:27 +00:00
|
|
|
function TranslateItemName(AItem: TXMLDataBindingItem): String; virtual;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
procedure GenerateDataBinding; virtual; abstract;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
property SourceFileName: String read FSourceFileName write FSourceFileName;
|
|
|
|
property SchemaCount: Integer read GetSchemaCount;
|
|
|
|
property Schemas[Index: Integer]: TXMLDataBindingSchema read GetSchemas;
|
2008-02-20 06:52:00 +00:00
|
|
|
public
|
2010-06-22 08:27:28 +00:00
|
|
|
constructor Create;
|
|
|
|
destructor Destroy; override;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
procedure Execute(const AStream: TStream; const ASchemaName: String); overload;
|
|
|
|
procedure Execute(const AFileName: String); overload;
|
|
|
|
|
|
|
|
property IncludePaths: TStrings read FIncludePaths;
|
|
|
|
property OutputType: TXMLDataBindingOutputType read FOutputType write FOutputType;
|
2008-03-09 20:36:27 +00:00
|
|
|
property OutputPath: String read FOutputPath write FOutputPath;
|
2008-04-22 13:36:55 +00:00
|
|
|
|
|
|
|
property OnPostProcessItem: TXMLDataBindingPostProcessItemEvent read FOnPostProcessItem write FOnPostProcessItem;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
TXMLDataBindingGeneratorItem = class(TObject)
|
|
|
|
private
|
|
|
|
FOwner: TXMLDataBindingGenerator;
|
|
|
|
protected
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean); virtual;
|
2008-04-14 19:28:57 +00:00
|
|
|
|
|
|
|
property Owner: TXMLDataBindingGenerator read FOwner;
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TXMLDataBindingGenerator);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TXMLDataBindingSchema = class(TXMLDataBindingGeneratorItem)
|
2008-03-09 20:36:27 +00:00
|
|
|
private
|
2014-10-28 14:22:41 +00:00
|
|
|
FIncludes: TObjectList<TXMLDataBindingSchema>;
|
|
|
|
FItems: TObjectList<TXMLDataBindingItem>;
|
2008-03-09 20:36:27 +00:00
|
|
|
FItemsGenerated: Boolean;
|
|
|
|
FSchemaDef: IXMLSchemaDef;
|
|
|
|
FSchemaName: String;
|
2008-04-14 19:28:57 +00:00
|
|
|
FSourceFileName: String;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetItemCount: Integer;
|
2008-03-09 20:36:27 +00:00
|
|
|
function GetItems(Index: Integer): TXMLDataBindingItem;
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetIncludeCount: Integer;
|
2008-03-09 20:36:27 +00:00
|
|
|
function GetIncludes(Index: Integer): TXMLDataBindingSchema;
|
2008-04-24 14:37:05 +00:00
|
|
|
function GetTargetNamespace: String;
|
2008-03-09 20:36:27 +00:00
|
|
|
protected
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean); override;
|
2008-04-14 19:28:57 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure AddInclude(ASchema: TXMLDataBindingSchema);
|
2008-04-14 19:28:57 +00:00
|
|
|
procedure InsertItem(AItem, AAfter: TXMLDataBindingItem);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
property ItemsGenerated: Boolean read FItemsGenerated write FItemsGenerated;
|
|
|
|
public
|
2008-04-14 19:28:57 +00:00
|
|
|
constructor Create(AOwner: TXMLDataBindingGenerator);
|
2010-06-22 08:27:28 +00:00
|
|
|
destructor Destroy; override;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2020-04-22 10:34:21 +00:00
|
|
|
procedure AddItem(AItem: TXMLDataBindingItem);
|
|
|
|
|
2008-04-24 14:37:05 +00:00
|
|
|
property TargetNamespace: String read GetTargetNamespace;
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
property IncludeCount: Integer read GetIncludeCount;
|
|
|
|
property Includes[Index: Integer]: TXMLDataBindingSchema read GetIncludes;
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
property SchemaDef: IXMLSchemaDef read FSchemaDef write FSchemaDef;
|
|
|
|
property SchemaName: String read FSchemaName write FSchemaName;
|
|
|
|
property SourceFileName: String read FSourceFileName write FSourceFileName;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
property ItemCount: Integer read GetItemCount;
|
|
|
|
property Items[Index: Integer]: TXMLDataBindingItem read GetItems;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
TXMLDataBindingItem = class(TXMLDataBindingGeneratorItem)
|
2008-03-09 20:36:27 +00:00
|
|
|
private
|
2008-04-14 19:28:57 +00:00
|
|
|
FCollectionItem: TXMLDataBindingProperty;
|
2008-03-09 20:36:27 +00:00
|
|
|
FDocumentElement: Boolean;
|
|
|
|
FName: String;
|
2008-04-14 19:28:57 +00:00
|
|
|
FSchema: TXMLDataBindingSchema;
|
2008-03-09 20:36:27 +00:00
|
|
|
FSchemaItem: IXMLSchemaItem;
|
|
|
|
FTranslatedName: String;
|
2012-04-17 07:36:23 +00:00
|
|
|
FTargetNamespace: String;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetDocumentation: String;
|
|
|
|
function GetHasDocumentation: Boolean;
|
2008-04-14 19:28:57 +00:00
|
|
|
function GetIsCollection: Boolean;
|
2008-03-09 20:36:27 +00:00
|
|
|
protected
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetItemType: TXMLDataBindingItemType; virtual; abstract;
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure SetName(const Value: String);
|
|
|
|
public
|
2008-04-14 19:28:57 +00:00
|
|
|
constructor Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; const AName: String);
|
|
|
|
|
|
|
|
property Schema: TXMLDataBindingSchema read FSchema write FSchema;
|
2020-04-22 10:26:47 +00:00
|
|
|
property SchemaItem: IXMLSchemaItem read FSchemaItem;
|
2012-04-17 07:36:23 +00:00
|
|
|
property TargetNamespace: String read FTargetNamespace write FTargetNamespace;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
property DocumentElement: Boolean read FDocumentElement write FDocumentElement;
|
|
|
|
property Documentation: String read GetDocumentation;
|
|
|
|
property HasDocumentation: Boolean read GetHasDocumentation;
|
|
|
|
property ItemType: TXMLDataBindingItemType read GetItemType;
|
|
|
|
property Name: String read FName;
|
2008-04-22 13:36:55 +00:00
|
|
|
property TranslatedName: String read FTranslatedName write FTranslatedName;
|
2008-04-14 19:28:57 +00:00
|
|
|
|
|
|
|
property CollectionItem: TXMLDataBindingProperty read FCollectionItem write FCollectionItem;
|
|
|
|
property IsCollection: Boolean read GetIsCollection;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TXMLDataBindingInterface = class(TXMLDataBindingItem)
|
|
|
|
private
|
|
|
|
FInterfaceType: TXMLDataBindingInterfaceType;
|
2010-07-15 10:57:03 +00:00
|
|
|
FIsSequence: Boolean;
|
2014-10-28 14:22:41 +00:00
|
|
|
FProperties: TObjectList<TXMLDataBindingProperty>;
|
2008-03-09 20:36:27 +00:00
|
|
|
FBaseName: String;
|
|
|
|
FBaseItem: TXMLDataBindingInterface;
|
|
|
|
|
|
|
|
function GetProperties(Index: Integer): TXMLDataBindingProperty;
|
|
|
|
function GetPropertyCount: Integer;
|
2010-07-15 10:57:03 +00:00
|
|
|
function GetCanValidate: Boolean;
|
2008-03-09 20:36:27 +00:00
|
|
|
protected
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetItemType: TXMLDataBindingItemType; override;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure ReplaceItem(const AOldItem: TXMLDataBindingItem; const ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean); override;
|
2008-04-14 19:28:57 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure AddProperty(AProperty: TXMLDataBindingProperty);
|
|
|
|
public
|
2008-04-14 19:28:57 +00:00
|
|
|
constructor Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; const AName: String);
|
2008-03-09 20:36:27 +00:00
|
|
|
destructor Destroy; override;
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
property BaseName: String read FBaseName write FBaseName;
|
|
|
|
property BaseItem: TXMLDataBindingInterface read FBaseItem write FBaseItem;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2010-07-15 10:57:03 +00:00
|
|
|
property CanValidate: Boolean read GetCanValidate;
|
2008-03-09 20:36:27 +00:00
|
|
|
property InterfaceType: TXMLDataBindingInterfaceType read FInterfaceType;
|
2010-07-15 10:57:03 +00:00
|
|
|
property IsSequence: Boolean read FIsSequence;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
property PropertyCount: Integer read GetPropertyCount;
|
|
|
|
property Properties[Index: Integer]: TXMLDataBindingProperty read GetProperties;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TXMLDataBindingEnumerationMember = class(TXMLDataBindingItem)
|
|
|
|
private
|
|
|
|
FEnumeration: TXMLDataBindingEnumeration;
|
|
|
|
protected
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetItemType: TXMLDataBindingItemType; override;
|
2008-03-09 20:36:27 +00:00
|
|
|
public
|
2008-04-14 19:28:57 +00:00
|
|
|
constructor Create(AOwner: TXMLDataBindingGenerator; AEnumeration: TXMLDataBindingEnumeration; const AName: String);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
property Enumeration: TXMLDataBindingEnumeration read FEnumeration;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TXMLDataBindingEnumeration = class(TXMLDataBindingItem)
|
|
|
|
private
|
2014-10-28 14:22:41 +00:00
|
|
|
FMembers: TObjectList<TXMLDataBindingEnumerationMember>;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetMemberCount: Integer;
|
2008-03-09 20:36:27 +00:00
|
|
|
function GetMembers(Index: Integer): TXMLDataBindingEnumerationMember;
|
|
|
|
protected
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetItemType: TXMLDataBindingItemType; override;
|
2008-03-09 20:36:27 +00:00
|
|
|
public
|
2020-04-22 10:26:47 +00:00
|
|
|
constructor Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; AEnumerations: IXMLEnumerationCollection; const AName: String); overload;
|
2010-06-22 08:27:28 +00:00
|
|
|
destructor Destroy; override;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure ReplaceMembers(AMembers: TEnumerable<TXMLDataBindingEnumerationMember>);
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
property MemberCount: Integer read GetMemberCount;
|
|
|
|
property Members[Index: Integer]: TXMLDataBindingEnumerationMember read GetMembers;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TXMLDataBindingProperty = class(TXMLDataBindingItem)
|
|
|
|
private
|
2012-04-10 08:47:48 +00:00
|
|
|
FIsAttribute: Boolean;
|
|
|
|
FIsOptional: Boolean;
|
|
|
|
FIsNillable: Boolean;
|
|
|
|
FIsRepeating: Boolean;
|
|
|
|
FIsNodeValue: Boolean;
|
|
|
|
FCollection: TXMLDataBindingInterface;
|
|
|
|
function GetHasTargetNamespace: Boolean;
|
2008-03-09 20:36:27 +00:00
|
|
|
protected
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetIsReadOnly: Boolean; virtual; abstract;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetItemType: TXMLDataBindingItemType; override;
|
|
|
|
function GetPropertyType: TXMLDataBindingPropertyType; virtual; abstract;
|
2008-03-09 20:36:27 +00:00
|
|
|
public
|
2012-04-10 08:47:48 +00:00
|
|
|
property IsAttribute: Boolean read FIsAttribute write FIsAttribute;
|
|
|
|
property IsOptional: Boolean read FIsOptional write FIsOptional;
|
|
|
|
property IsNillable: Boolean read FIsNillable write FIsNillable;
|
|
|
|
property IsReadOnly: Boolean read GetIsReadOnly;
|
|
|
|
property IsRepeating: Boolean read FIsRepeating write FIsRepeating;
|
|
|
|
property IsNodeValue: Boolean read FIsNodeValue write FIsNodeValue;
|
|
|
|
property PropertyType: TXMLDataBindingPropertyType read GetPropertyType;
|
|
|
|
|
|
|
|
property Collection: TXMLDataBindingInterface read FCollection write FCollection;
|
|
|
|
|
|
|
|
property HasTargetNamespace: Boolean read GetHasTargetNamespace;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TXMLDataBindingSimpleProperty = class(TXMLDataBindingProperty)
|
|
|
|
private
|
|
|
|
FDataType: IXMLTypeDef;
|
|
|
|
protected
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetIsReadOnly: Boolean; override;
|
|
|
|
function GetPropertyType: TXMLDataBindingPropertyType; override;
|
2008-03-09 20:36:27 +00:00
|
|
|
public
|
2008-04-14 19:28:57 +00:00
|
|
|
constructor Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; const AName: String; ADataType: IXMLTypeDef);
|
2008-04-21 15:24:33 +00:00
|
|
|
constructor CreateFromAlias(AOwner: TXMLDataBindingGenerator; AProperty: TXMLDataBindingItemProperty; ADataType: IXMLTypeDef);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
property DataType: IXMLTypeDef read FDataType;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TXMLDataBindingItemProperty = class(TXMLDataBindingProperty)
|
|
|
|
private
|
|
|
|
FItem: TXMLDataBindingItem;
|
|
|
|
protected
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetIsReadOnly: Boolean; override;
|
|
|
|
function GetPropertyType: TXMLDataBindingPropertyType; override;
|
2008-04-14 19:28:57 +00:00
|
|
|
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean); override;
|
2008-03-09 20:36:27 +00:00
|
|
|
public
|
2008-04-14 19:28:57 +00:00
|
|
|
constructor Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; const AName: String; AItem: TXMLDataBindingItem);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
property Item: TXMLDataBindingItem read FItem;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
TXMLDataBindingUnresolvedItem = class(TXMLDataBindingItem)
|
2008-03-09 20:36:27 +00:00
|
|
|
private
|
|
|
|
FInterfaceType: TXMLDataBindingInterfaceType;
|
|
|
|
protected
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetItemType: TXMLDataBindingItemType; override;
|
2008-03-09 20:36:27 +00:00
|
|
|
public
|
2010-07-15 10:57:03 +00:00
|
|
|
constructor Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; const AName: String; AInterfaceType: TXMLDataBindingInterfaceType; AIsAttribute: Boolean);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
property InterfaceType: TXMLDataBindingInterfaceType read FInterfaceType;
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-18 14:36:17 +00:00
|
|
|
TXMLDataBindingComplexTypeAliasItem = class(TXMLDataBindingItem)
|
2008-03-31 21:15:13 +00:00
|
|
|
private
|
|
|
|
FItem: TXMLDataBindingItem;
|
|
|
|
protected
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetItemType: TXMLDataBindingItemType; override;
|
2008-04-14 19:28:57 +00:00
|
|
|
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean); override;
|
2008-03-31 21:15:13 +00:00
|
|
|
public
|
|
|
|
property Item: TXMLDataBindingItem read FItem write FItem;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-18 14:36:17 +00:00
|
|
|
TXMLDataBindingSimpleTypeAliasItem = class(TXMLDataBindingItem)
|
|
|
|
private
|
|
|
|
FDataType: IXMLTypeDef;
|
|
|
|
protected
|
2010-06-22 08:27:28 +00:00
|
|
|
function GetItemType: TXMLDataBindingItemType; override;
|
2008-04-18 14:36:17 +00:00
|
|
|
public
|
|
|
|
property DataType: IXMLTypeDef read FDataType write FDataType;
|
|
|
|
end;
|
2014-11-15 11:29:35 +00:00
|
|
|
|
2008-04-18 14:36:17 +00:00
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
implementation
|
|
|
|
uses
|
2014-11-15 11:29:35 +00:00
|
|
|
System.TypInfo,
|
2014-10-28 14:22:41 +00:00
|
|
|
System.Variants,
|
|
|
|
Winapi.Windows,
|
|
|
|
Xml.XMLDoc,
|
|
|
|
Xml.XMLIntf,
|
|
|
|
Xml.XMLSchemaTags;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
MaxOccursUnbounded = 'unbounded';
|
2010-07-15 13:53:52 +00:00
|
|
|
UseRequired = 'required';
|
2008-03-14 15:35:07 +00:00
|
|
|
CollectionPostfix = 'List';
|
2008-04-21 15:24:33 +00:00
|
|
|
AttributeNillable = 'nillable';
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
function GetInterfaceType(ASchemaItem: IXMLSchemaItem): TXMLDataBindingInterfaceType;
|
|
|
|
begin
|
|
|
|
if Supports(ASchemaItem, IXMLComplexTypeDef) then
|
|
|
|
Result := ifComplexType
|
|
|
|
else
|
|
|
|
Result := ifElement;
|
|
|
|
end;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
|
2008-03-31 21:15:13 +00:00
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
{ TXMLDataBindingGenerator }
|
2010-06-22 08:27:28 +00:00
|
|
|
constructor TXMLDataBindingGenerator.Create;
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
2010-06-22 08:27:28 +00:00
|
|
|
inherited Create;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
FIncludePaths := TStringList.Create;
|
2014-10-28 14:22:41 +00:00
|
|
|
FSchemas := TObjectList<TXMLDataBindingSchema>.Create(True);
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
with TStringList(FIncludePaths) do
|
|
|
|
begin
|
|
|
|
CaseSensitive := False;
|
|
|
|
Duplicates := dupIgnore;
|
|
|
|
end;
|
2010-09-10 10:38:31 +00:00
|
|
|
|
|
|
|
IncludePaths.Add('');
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
destructor TXMLDataBindingGenerator.Destroy;
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FSchemas);
|
|
|
|
FreeAndNil(FIncludePaths);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TXMLDataBindingGenerator.Execute(const AStream: TStream; const ASchemaName: String);
|
2008-03-09 20:36:27 +00:00
|
|
|
var
|
2017-02-17 14:27:30 +00:00
|
|
|
schemaIndex: Integer;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
2010-06-22 08:27:28 +00:00
|
|
|
FSchemas.Clear;
|
2017-02-17 14:27:30 +00:00
|
|
|
LoadSchema(AStream, ASchemaName, SourceFileName);
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
if SchemaCount > 0 then
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
{ Map schema elements to objects }
|
|
|
|
for schemaIndex := 0 to Pred(SchemaCount) do
|
|
|
|
GenerateSchemaObjects(Schemas[schemaIndex], (schemaIndex = 0));
|
|
|
|
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
{ Process unresolved references }
|
|
|
|
for schemaIndex := Pred(SchemaCount) downto 0 do
|
2008-03-09 20:36:27 +00:00
|
|
|
ResolveSchema(Schemas[schemaIndex]);
|
|
|
|
|
2008-03-21 15:23:14 +00:00
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
{ After all lookups have been done, unwrap alias items }
|
|
|
|
for schemaIndex := Pred(SchemaCount) downto 0 do
|
|
|
|
ResolveAlias(Schemas[schemaIndex]);
|
2008-03-21 15:23:14 +00:00
|
|
|
|
2008-04-22 13:36:55 +00:00
|
|
|
|
2008-03-21 15:23:14 +00:00
|
|
|
{ Resolve naming conflicts }
|
2010-06-22 08:27:28 +00:00
|
|
|
ResolveNameConflicts;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
{ Perform final post-processing (translating names, generating collections) }
|
2008-03-09 20:36:27 +00:00
|
|
|
for schemaIndex := 0 to Pred(SchemaCount) do
|
2008-04-14 19:28:57 +00:00
|
|
|
PostProcessSchema(Schemas[schemaIndex]);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
{ Output }
|
2010-06-22 08:27:28 +00:00
|
|
|
GenerateDataBinding;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TXMLDataBindingGenerator.Execute(const AFileName: String);
|
|
|
|
var
|
|
|
|
currentDir: String;
|
|
|
|
fileStream: TFileStream;
|
|
|
|
|
|
|
|
begin
|
2010-06-22 08:27:28 +00:00
|
|
|
currentDir := GetCurrentDir;
|
2008-02-20 06:52:00 +00:00
|
|
|
try
|
|
|
|
ChDir(ExtractFilePath(AFileName));
|
|
|
|
|
|
|
|
fileStream := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyNone);
|
|
|
|
try
|
|
|
|
FSourceFileName := AFileName;
|
|
|
|
IncludePaths.Add(ExtractFilePath(AFileName));
|
|
|
|
|
|
|
|
Execute(fileStream, ChangeFileExt(ExtractFileName(AFileName), ''));
|
|
|
|
finally
|
|
|
|
FreeAndNil(fileStream);
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
ChDir(currentDir);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-17 14:27:30 +00:00
|
|
|
function TXMLDataBindingGenerator.LoadSchema(const AStream: TStream; const ASchemaName, ASourceFileName: String): TXMLDataBindingSchema;
|
2008-02-26 21:53:11 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure HandleDocRefs(const ADocRefs: IXMLSchemaDocRefs; ASchema: TXMLDataBindingSchema);
|
2008-02-26 21:53:11 +00:00
|
|
|
var
|
|
|
|
location: String;
|
2008-03-09 20:36:27 +00:00
|
|
|
schemaName: String;
|
|
|
|
refSchema: TXMLDataBindingSchema;
|
2008-02-26 21:53:11 +00:00
|
|
|
refIndex: Integer;
|
|
|
|
refStream: TStream;
|
2008-04-14 19:28:57 +00:00
|
|
|
sourceFileName: String;
|
2008-02-26 21:53:11 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
for refIndex := 0 to Pred(ADocRefs.Count) do
|
|
|
|
begin
|
2017-02-17 14:27:30 +00:00
|
|
|
location := ADocRefs[refIndex].SchemaLocation;
|
|
|
|
schemaName := ChangeFileExt(ExtractFileName(location), '');
|
2021-03-19 17:16:49 +00:00
|
|
|
schemaName := schemaName.Replace('./', ''); // fix explizit current dir
|
2017-02-17 14:27:30 +00:00
|
|
|
refSchema := FindSchema(schemaName);
|
2008-02-26 21:53:11 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
if not Assigned(refSchema) then
|
2008-02-26 21:53:11 +00:00
|
|
|
begin
|
2017-02-17 14:27:30 +00:00
|
|
|
refStream := GetSchemaData(location, sourceFileName);
|
2008-02-26 21:53:11 +00:00
|
|
|
|
|
|
|
if Assigned(refStream) then
|
|
|
|
try
|
2017-02-17 14:27:30 +00:00
|
|
|
refSchema := LoadSchema(refStream, schemaName, sourceFileName);
|
2008-02-26 21:53:11 +00:00
|
|
|
finally
|
|
|
|
FreeAndNil(refStream);
|
|
|
|
end;
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
if Assigned(refSchema) then
|
2017-02-17 14:27:30 +00:00
|
|
|
begin
|
|
|
|
// Update the schema location to an absolute path,
|
|
|
|
// the Delphi XMLSchema unit has trouble resolving relative references
|
|
|
|
// in a relatively referenced file.
|
|
|
|
ADocRefs[refIndex].SchemaLocation := refSchema.SourceFileName;
|
2008-03-09 20:36:27 +00:00
|
|
|
ASchema.AddInclude(refSchema);
|
2017-02-17 14:27:30 +00:00
|
|
|
end;
|
2008-02-26 21:53:11 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
var
|
2017-02-17 14:27:30 +00:00
|
|
|
currentDir: string;
|
|
|
|
schemaDoc: IXMLSchemaDoc;
|
|
|
|
schemaDef: IXMLSchemaDef;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
schemaDoc := TXMLSchemaDoc.Create(nil);
|
|
|
|
schemaDoc.LoadFromStream(AStream);
|
2008-03-09 20:36:27 +00:00
|
|
|
schemaDef := schemaDoc.SchemaDef;
|
2008-02-20 06:52:00 +00:00
|
|
|
|
2017-02-17 14:27:30 +00:00
|
|
|
Result := TXMLDataBindingSchema.Create(Self);
|
|
|
|
Result.SchemaDef := schemaDef;
|
2008-03-09 20:36:27 +00:00
|
|
|
Result.SchemaName := ASchemaName;
|
2017-02-17 14:27:30 +00:00
|
|
|
Result.SourceFileName := ExpandFileName(ASourceFileName);
|
2008-03-09 20:36:27 +00:00
|
|
|
FSchemas.Add(Result);
|
2008-02-20 06:52:00 +00:00
|
|
|
|
2017-02-17 14:27:30 +00:00
|
|
|
currentDir := GetCurrentDir;
|
|
|
|
SetCurrentDir(ExtractFilePath(Result.SourceFileName));
|
|
|
|
try
|
|
|
|
{ Handle imports / includes }
|
|
|
|
HandleDocRefs(schemaDef.SchemaImports, Result);
|
|
|
|
HandleDocRefs(schemaDef.SchemaIncludes, Result);
|
|
|
|
finally
|
|
|
|
SetCurrentDir(currentDir);
|
|
|
|
end;
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
function TXMLDataBindingGenerator.GetSchemaData(const ALocation: String; out ASourceFileName: String): TStream;
|
2008-02-20 06:52:00 +00:00
|
|
|
var
|
|
|
|
includeIndex: Integer;
|
|
|
|
includePath: String;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
for includeIndex := 0 to Pred(IncludePaths.Count) do
|
|
|
|
begin
|
2010-09-10 10:38:31 +00:00
|
|
|
includePath := IncludePaths[includeIndex];
|
|
|
|
if Length(includePath) > 0 then
|
|
|
|
includePath := IncludeTrailingPathDelimiter(includePath);
|
2008-02-20 06:52:00 +00:00
|
|
|
|
|
|
|
if FileExists(includePath + ALocation) then
|
|
|
|
begin
|
2017-02-17 14:27:30 +00:00
|
|
|
ASourceFileName := ExpandFileName(includePath + ALocation);
|
2008-04-14 19:28:57 +00:00
|
|
|
Result := TFileStream.Create(ASourceFileName, fmOpenRead or fmShareDenyNone);
|
2008-02-20 06:52:00 +00:00
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
function TXMLDataBindingGenerator.FindSchema(const ALocation: String): TXMLDataBindingSchema;
|
2008-02-26 21:53:11 +00:00
|
|
|
var
|
|
|
|
schemaIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
Result := nil;
|
|
|
|
|
2008-02-26 21:53:11 +00:00
|
|
|
for schemaIndex := 0 to Pred(SchemaCount) do
|
2008-03-09 20:36:27 +00:00
|
|
|
if Schemas[schemaIndex].SchemaName = ALocation then
|
2008-02-26 21:53:11 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
Result := Schemas[schemaIndex];
|
2008-02-26 21:53:11 +00:00
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TXMLDataBindingGenerator.GenerateSchemaObjects(ASchema: TXMLDataBindingSchema; ARootDocument: Boolean);
|
|
|
|
var
|
|
|
|
includeIndex: Integer;
|
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
if ASchema.ItemsGenerated then
|
|
|
|
exit;
|
|
|
|
|
2017-02-17 14:27:30 +00:00
|
|
|
OutputDebugString(PChar('> ' + ASchema.SchemaName));
|
2008-03-09 20:36:27 +00:00
|
|
|
ASchema.ItemsGenerated := True;
|
|
|
|
|
2017-02-17 14:27:30 +00:00
|
|
|
OutputDebugString('Includes...');
|
2008-03-09 20:36:27 +00:00
|
|
|
{ First generate the objects for all includes and imports, so we can get
|
|
|
|
proper references. }
|
|
|
|
for includeIndex := 0 to Pred(ASchema.IncludeCount) do
|
|
|
|
GenerateSchemaObjects(ASchema.Includes[includeIndex], False);
|
|
|
|
|
2017-02-17 14:27:30 +00:00
|
|
|
OutputDebugString(PChar(ASchema.SchemaName + ': Generate objects'));
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
GenerateElementObjects(ASchema, ARootDocument);
|
|
|
|
GenerateComplexTypeObjects(ASchema);
|
2008-05-14 13:30:54 +00:00
|
|
|
GenerateSimpleTypeObjects(ASchema);
|
2014-11-15 11:29:35 +00:00
|
|
|
GenerateAttributeObjects(ASchema);
|
2017-02-17 14:27:30 +00:00
|
|
|
|
|
|
|
OutputDebugString(PChar('< ' + ASchema.SchemaName));
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TXMLDataBindingGenerator.GenerateElementObjects(ASchema: TXMLDataBindingSchema; ARootDocument: Boolean);
|
|
|
|
var
|
2010-07-15 10:57:03 +00:00
|
|
|
schemaDef: IXMLSchemaDef;
|
|
|
|
elementIndex: Integer;
|
|
|
|
item: TXMLDataBindingItem;
|
|
|
|
attributeIndex: Integer;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-02-20 06:52:00 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
schemaDef := ASchema.SchemaDef;
|
|
|
|
|
|
|
|
for elementIndex := 0 to Pred(schemaDef.ElementDefs.Count) do
|
|
|
|
begin
|
|
|
|
item := ProcessElement(ASchema, schemaDef.ElementDefs[elementIndex]);
|
|
|
|
|
|
|
|
if Assigned(item) and ARootDocument then
|
|
|
|
item.DocumentElement := True;
|
|
|
|
end;
|
2010-07-15 10:57:03 +00:00
|
|
|
|
|
|
|
for attributeIndex := 0 to Pred(schemaDef.AttributeDefs.Count) do
|
|
|
|
ProcessElement(ASchema, schemaDef.AttributeDefs[attributeIndex]);
|
2008-02-20 06:52:00 +00:00
|
|
|
end;
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
procedure TXMLDataBindingGenerator.GenerateComplexTypeObjects(ASchema: TXMLDataBindingSchema);
|
|
|
|
var
|
|
|
|
schemaDef: IXMLSchemaDef;
|
|
|
|
complexTypeIndex: Integer;
|
|
|
|
complexType: IXMLComplexTypeDef;
|
|
|
|
interfaceItem: TXMLDataBindingInterface;
|
|
|
|
elementIndex: Integer;
|
2009-04-14 13:20:41 +00:00
|
|
|
attributeIndex: Integer;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
schemaDef := ASchema.SchemaDef;
|
|
|
|
|
|
|
|
for complexTypeIndex := 0 to Pred(schemaDef.ComplexTypes.Count) do
|
|
|
|
begin
|
|
|
|
complexType := schemaDef.ComplexTypes[complexTypeIndex];
|
2008-04-18 14:36:17 +00:00
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
interfaceItem := TXMLDataBindingInterface.Create(Self, complexType, complexType.Name);
|
2008-04-18 14:36:17 +00:00
|
|
|
|
|
|
|
if complexType.DerivationMethod <> dmNone then
|
|
|
|
interfaceItem.BaseName := complexType.BaseTypeName;
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
ASchema.AddItem(interfaceItem);
|
|
|
|
|
2008-04-22 13:36:55 +00:00
|
|
|
for elementIndex := 0 to Pred(complexType.ElementDefList.Count) do
|
|
|
|
ProcessChildElement(ASchema, complexType.ElementDefList[elementIndex], interfaceItem);
|
2009-04-14 13:20:41 +00:00
|
|
|
|
|
|
|
for attributeIndex := 0 to Pred(complexType.AttributeDefs.Count) do
|
|
|
|
ProcessAttribute(ASchema, complexType.AttributeDefs[attributeIndex], interfaceItem);
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-05-14 13:30:54 +00:00
|
|
|
procedure TXMLDataBindingGenerator.GenerateSimpleTypeObjects(ASchema: TXMLDataBindingSchema);
|
|
|
|
var
|
|
|
|
schemaDef: IXMLSchemaDef;
|
|
|
|
simpleTypeIndex: Integer;
|
|
|
|
simpleType: IXMLSimpleTypeDef;
|
2012-04-13 13:33:23 +00:00
|
|
|
enumerationObject: TXMLDataBindingEnumeration;
|
|
|
|
baseType: IXMLTypeDef;
|
2012-04-17 07:36:23 +00:00
|
|
|
namespace: String;
|
|
|
|
simpleTypeAlias: TXMLDataBindingSimpleTypeAliasItem;
|
2008-05-14 13:30:54 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
schemaDef := ASchema.SchemaDef;
|
|
|
|
|
|
|
|
for simpleTypeIndex := 0 to Pred(schemaDef.SimpleTypes.Count) do
|
|
|
|
begin
|
|
|
|
simpleType := schemaDef.SimpleTypes[simpleTypeIndex];
|
|
|
|
|
2014-11-15 11:29:35 +00:00
|
|
|
if simpleType.DerivationMethod <> sdmList then
|
2012-04-13 13:33:23 +00:00
|
|
|
begin
|
2014-11-15 11:29:35 +00:00
|
|
|
if simpleType.Enumerations.Count > 0 then
|
|
|
|
begin
|
|
|
|
enumerationObject := TXMLDataBindingEnumeration.Create(Self, simpleType, simpleType.Enumerations, simpleType.Name);
|
|
|
|
ASchema.AddItem(enumerationObject);
|
|
|
|
end else if simpleType.DerivationMethod = sdmRestriction then
|
|
|
|
begin
|
|
|
|
baseType := simpleType.BaseType;
|
2017-02-17 14:27:30 +00:00
|
|
|
if Assigned(baseType) then
|
2012-05-22 13:16:16 +00:00
|
|
|
begin
|
2017-02-17 14:27:30 +00:00
|
|
|
while Assigned(baseType.BaseType) do
|
|
|
|
baseType := baseType.BaseType;
|
|
|
|
|
|
|
|
if not baseType.IsComplex then
|
2014-11-15 11:29:35 +00:00
|
|
|
begin
|
2017-02-17 14:27:30 +00:00
|
|
|
if not VarIsNull(simpleType.SchemaDef.TargetNamespace) then
|
|
|
|
begin
|
|
|
|
namespace := simpleType.SchemaDef.TargetNamespace;
|
|
|
|
if namespace = Schemas[0].TargetNamespace then
|
|
|
|
namespace := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
simpleTypeAlias := TXMLDataBindingSimpleTypeAliasItem.Create(Self, baseType, simpleType.Name);
|
|
|
|
simpleTypeAlias.TargetNamespace := namespace;
|
|
|
|
ASchema.AddItem(simpleTypeAlias);
|
2014-11-15 11:29:35 +00:00
|
|
|
end;
|
2017-02-17 14:27:30 +00:00
|
|
|
end else
|
|
|
|
begin
|
|
|
|
// ...I literally can't even.
|
2014-11-15 11:29:35 +00:00
|
|
|
end;
|
2012-04-17 07:36:23 +00:00
|
|
|
end;
|
2008-05-14 13:30:54 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-11-15 11:29:35 +00:00
|
|
|
procedure TXMLDataBindingGenerator.GenerateAttributeObjects(ASchema: TXMLDataBindingSchema);
|
|
|
|
var
|
|
|
|
schemaDef: IXMLSchemaDef;
|
|
|
|
attributeIndex: Integer;
|
|
|
|
attribute: IXMLAttributeDef;
|
|
|
|
|
|
|
|
begin
|
|
|
|
schemaDef := ASchema.SchemaDef;
|
|
|
|
|
|
|
|
for attributeIndex := 0 to Pred(schemaDef.AttributeDefs.Count) do
|
|
|
|
begin
|
|
|
|
attribute := schemaDef.AttributeDefs[attributeIndex];
|
|
|
|
ProcessElement(ASchema, attribute);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
function TXMLDataBindingGenerator.CheckElementOccurance(AElement: IXMLElementDef; AOccurance: TXMLDataBindingOccurance): Boolean;
|
|
|
|
|
|
|
|
function CheckParent(const ANode: IXMLNode): Boolean;
|
|
|
|
var
|
|
|
|
compositor: IXMLElementCompositor;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
if Supports(ANode, IXMLElementCompositor, compositor) then
|
|
|
|
begin
|
|
|
|
case AOccurance of
|
2008-04-21 15:24:33 +00:00
|
|
|
boMinOccurs: Result := (compositor.MinOccurs = 0);
|
2008-04-14 19:28:57 +00:00
|
|
|
boMaxOccurs: Result := (compositor.MaxOccurs = MaxOccursUnbounded) or
|
|
|
|
(compositor.MaxOccurs > 1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if not Result then
|
|
|
|
Result := CheckParent(compositor.ParentNode);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
case AOccurance of
|
|
|
|
boMinOccurs: Result := (AElement.MinOccurs = 0);
|
|
|
|
boMaxOccurs: Result := (AElement.MaxOccurs = MaxOccursUnbounded) or
|
|
|
|
(AElement.MaxOccurs > 1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if not Result then
|
|
|
|
Result := CheckParent(AElement.ParentNode);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLDataBindingGenerator.IsElementOptional(AElement: IXMLElementDef): Boolean;
|
|
|
|
begin
|
|
|
|
Result := CheckElementOccurance(AElement, boMinOccurs);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLDataBindingGenerator.IsElementRepeating(AElement: IXMLElementDef): Boolean;
|
|
|
|
begin
|
|
|
|
Result := CheckElementOccurance(AElement, boMaxOccurs);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLDataBindingGenerator.IsChoice(AElement: IXMLElementDef): Boolean;
|
|
|
|
var
|
|
|
|
compositor: IXMLElementCompositor;
|
2022-06-10 13:20:22 +00:00
|
|
|
parent: IXMLNode;
|
2008-04-14 19:28:57 +00:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
2022-06-10 13:20:22 +00:00
|
|
|
parent := AElement.ParentNode;
|
|
|
|
while Supports(parent, IXMLElementCompositor, compositor) do
|
|
|
|
begin
|
|
|
|
if compositor.CompositorType = ctSequence then
|
|
|
|
begin
|
|
|
|
parent := compositor.ParentNode;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
Result := (compositor.CompositorType = ctChoice) and
|
|
|
|
(compositor.ElementDefs.Count + compositor.Compositors.Count > 1);
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
end;
|
2008-04-14 19:28:57 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
function TXMLDataBindingGenerator.ProcessElement(ASchema: TXMLDataBindingSchema; AElement: IXMLElementDef): TXMLDataBindingItem;
|
|
|
|
var
|
2008-04-14 19:28:57 +00:00
|
|
|
attributeIndex: Integer;
|
2008-03-09 20:36:27 +00:00
|
|
|
enumerationObject: TXMLDataBindingEnumeration;
|
|
|
|
interfaceObject: TXMLDataBindingInterface;
|
2008-04-18 14:36:17 +00:00
|
|
|
complexAliasItem: TXMLDataBindingComplexTypeAliasItem;
|
|
|
|
simpleAliasItem: TXMLDataBindingSimpleTypeAliasItem;
|
2008-04-22 13:36:55 +00:00
|
|
|
elementIndex: Integer;
|
2008-07-31 14:56:36 +00:00
|
|
|
simpleTypeDef: IXMLSimpleTypeDef;
|
2014-11-15 11:29:35 +00:00
|
|
|
dataTypeName: string;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
interfaceObject := nil;
|
|
|
|
|
|
|
|
if Assigned(AElement.Ref) then
|
|
|
|
begin
|
|
|
|
{ Find reference. If not found, mark as "resolve later". }
|
|
|
|
Result := FindInterface(ASchema, AElement.Ref.Name, ifElement);
|
|
|
|
|
|
|
|
if not Assigned(Result) then
|
|
|
|
begin
|
2010-07-15 10:57:03 +00:00
|
|
|
Result := TXMLDataBindingUnresolvedItem.Create(Self, AElement, AElement.Ref.Name, ifElement, False);
|
2008-03-09 20:36:27 +00:00
|
|
|
ASchema.AddItem(Result);
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
begin
|
2008-04-18 14:36:17 +00:00
|
|
|
if not AElement.DataType.IsAnonymous then
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-04-18 14:36:17 +00:00
|
|
|
if AElement.DataType.IsComplex then
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-04-18 14:36:17 +00:00
|
|
|
{ Find data type. If not found, mark as "resolve later". }
|
2008-05-14 13:30:54 +00:00
|
|
|
Result := FindInterface(ASchema, AElement.DataTypeName, ifComplexType);
|
2008-04-18 14:36:17 +00:00
|
|
|
|
|
|
|
if not Assigned(Result) then
|
|
|
|
begin
|
2014-11-15 11:29:35 +00:00
|
|
|
Result := TXMLDataBindingUnresolvedItem.Create(Self, AElement, AElement.DataTypeName, ifComplexType, False);
|
2008-04-18 14:36:17 +00:00
|
|
|
ASchema.AddItem(Result);
|
|
|
|
end;
|
2008-03-31 21:15:13 +00:00
|
|
|
|
2008-04-18 14:36:17 +00:00
|
|
|
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;
|
2008-07-31 14:56:36 +00:00
|
|
|
end else if Supports(AElement.DataType, IXMLSimpleTypeDef, simpleTypeDef) then
|
2008-05-14 13:30:54 +00:00
|
|
|
begin
|
2014-11-15 11:29:35 +00:00
|
|
|
if (simpleTypeDef.DerivationMethod = sdmList) or (simpleTypeDef.Enumerations.Count > 0) then
|
2008-07-31 14:56:36 +00:00
|
|
|
begin
|
2014-11-15 11:29:35 +00:00
|
|
|
if simpleTypeDef.DerivationMethod = sdmList then
|
|
|
|
dataTypeName := (simpleTypeDef.ContentNode as IXMLSimpleTypeList).ItemType
|
|
|
|
else
|
|
|
|
dataTypeName := AElement.DataTypeName;
|
|
|
|
|
2008-07-31 14:56:36 +00:00
|
|
|
{ References enumeration. }
|
2014-11-15 11:29:35 +00:00
|
|
|
Result := FindEnumeration(ASchema, dataTypeName);
|
2008-05-14 13:30:54 +00:00
|
|
|
|
2008-07-31 14:56:36 +00:00
|
|
|
if not Assigned(Result) then
|
|
|
|
begin
|
2014-11-15 11:29:35 +00:00
|
|
|
Result := TXMLDataBindingUnresolvedItem.Create(Self, AElement, dataTypeName, ifEnumeration, False);
|
2008-07-31 14:56:36 +00:00
|
|
|
ASchema.AddItem(Result);
|
|
|
|
end;
|
|
|
|
end else if simpleTypeDef.IsBuiltInType and AElement.IsGlobal then
|
2008-05-14 13:30:54 +00:00
|
|
|
begin
|
2008-07-31 14:56:36 +00:00
|
|
|
{ The element is global, but only references a simple type. }
|
|
|
|
simpleAliasItem := TXMLDataBindingSimpleTypeAliasItem.Create(Self, AElement, AElement.Name);
|
2012-04-17 07:36:23 +00:00
|
|
|
// #ToDo1 -oMvR: 17-4-2012: TargetNamespace!
|
2008-07-31 14:56:36 +00:00
|
|
|
simpleAliasItem.DataType := AElement.DataType;
|
|
|
|
ASchema.AddItem(simpleAliasItem);
|
2008-04-18 14:36:17 +00:00
|
|
|
|
2008-07-31 14:56:36 +00:00
|
|
|
Result := simpleAliasItem;
|
|
|
|
end;
|
2008-03-31 21:15:13 +00:00
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
if not Assigned(Result) then
|
|
|
|
begin
|
|
|
|
if AElement.DataType.Enumerations.Count > 0 then
|
|
|
|
begin
|
|
|
|
{ Enumeration }
|
2014-11-15 11:29:35 +00:00
|
|
|
enumerationObject := TXMLDataBindingEnumeration.Create(Self, AElement, AElement.DataType.Enumerations, AElement.Name);
|
2008-03-09 20:36:27 +00:00
|
|
|
ASchema.AddItem(enumerationObject);
|
|
|
|
Result := enumerationObject;
|
2011-10-12 10:47:37 +00:00
|
|
|
end else
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2011-10-12 10:47:37 +00:00
|
|
|
if AElement.DataType.IsComplex then
|
|
|
|
begin
|
|
|
|
{ Interface }
|
|
|
|
interfaceObject := TXMLDataBindingInterface.Create(Self, AElement, AElement.Name);
|
|
|
|
if Assigned(AElement.DataType.BaseType) then
|
|
|
|
interfaceObject.BaseName := AElement.DataType.BaseTypeName;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2011-10-12 10:47:37 +00:00
|
|
|
ASchema.AddItem(interfaceObject);
|
|
|
|
Result := interfaceObject;
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2011-10-12 10:47:37 +00:00
|
|
|
if Assigned(interfaceObject) then
|
|
|
|
begin
|
|
|
|
for elementIndex := 0 to Pred(AElement.ChildElements.Count) do
|
|
|
|
ProcessChildElement(ASchema, AElement.ChildElements[elementIndex], interfaceObject);
|
2008-04-14 19:28:57 +00:00
|
|
|
|
2011-10-12 10:47:37 +00:00
|
|
|
for attributeIndex := 0 to Pred(AElement.AttributeDefs.Count) do
|
|
|
|
ProcessAttribute(ASchema, AElement.AttributeDefs[attributeIndex], interfaceObject);
|
2012-05-22 13:16:16 +00:00
|
|
|
end else //if AElement.IsGlobal then
|
2011-10-12 10:47:37 +00:00
|
|
|
begin
|
|
|
|
{ Non-anonymous non-complex type. Assume somewhere in there is a
|
2012-05-22 13:16:16 +00:00
|
|
|
built-in type. }
|
|
|
|
Result := ProcessSimpleTypeReference(ASchema, AElement, AElement.DataType);
|
2010-07-15 10:57:03 +00:00
|
|
|
end;
|
2008-04-14 19:28:57 +00:00
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingGenerator.ProcessElement(ASchema: TXMLDataBindingSchema; AAttribute: IXMLAttributeDef): TXMLDataBindingItem;
|
|
|
|
var
|
2012-05-22 13:16:16 +00:00
|
|
|
enumerationObject: TXMLDataBindingEnumeration;
|
|
|
|
interfaceObject: TXMLDataBindingInterface;
|
|
|
|
complexAliasItem: TXMLDataBindingComplexTypeAliasItem;
|
|
|
|
simpleAliasItem: TXMLDataBindingSimpleTypeAliasItem;
|
|
|
|
simpleTypeDef: IXMLSimpleTypeDef;
|
2014-11-15 11:29:35 +00:00
|
|
|
dataTypeName: string;
|
2010-06-22 08:27:28 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
if Assigned(AAttribute.Ref) then
|
|
|
|
begin
|
|
|
|
{ Find reference. If not found, mark as "resolve later". }
|
2014-11-15 11:29:35 +00:00
|
|
|
Result := FindInterface(ASchema, AAttribute.Ref.Name, ifAttribute);
|
2010-06-22 08:27:28 +00:00
|
|
|
|
|
|
|
if not Assigned(Result) then
|
|
|
|
begin
|
2014-11-15 11:29:35 +00:00
|
|
|
Result := TXMLDataBindingUnresolvedItem.Create(Self, AAttribute, AAttribute.Ref.Name, ifAttribute, True);
|
2010-06-22 08:27:28 +00:00
|
|
|
ASchema.AddItem(Result);
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
if not AAttribute.DataType.IsAnonymous then
|
|
|
|
begin
|
|
|
|
if AAttribute.DataType.IsComplex then
|
|
|
|
begin
|
|
|
|
{ Find data type. If not found, mark as "resolve later". }
|
|
|
|
Result := FindInterface(ASchema, AAttribute.DataTypeName, ifComplexType);
|
|
|
|
|
|
|
|
if not Assigned(Result) then
|
|
|
|
begin
|
2010-07-15 10:57:03 +00:00
|
|
|
Result := TXMLDataBindingUnresolvedItem.Create(Self, AAttribute, AAttribute.DataTypeName, ifComplexType, True);
|
2010-06-22 08:27:28 +00:00
|
|
|
ASchema.AddItem(Result);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if AAttribute.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, AAttribute, AAttribute.Name);
|
|
|
|
complexAliasItem.Item := Result;
|
|
|
|
ASchema.AddItem(complexAliasItem);
|
|
|
|
end;
|
2014-11-15 11:29:35 +00:00
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
end else if Supports(AAttribute.DataType, IXMLSimpleTypeDef, simpleTypeDef) then
|
|
|
|
begin
|
2014-11-15 11:29:35 +00:00
|
|
|
if (simpleTypeDef.DerivationMethod = sdmList) or (simpleTypeDef.Enumerations.Count > 0) then
|
2010-06-22 08:27:28 +00:00
|
|
|
begin
|
2014-11-15 11:29:35 +00:00
|
|
|
if simpleTypeDef.DerivationMethod = sdmList then
|
|
|
|
dataTypeName := (simpleTypeDef.ContentNode as IXMLSimpleTypeList).ItemType
|
|
|
|
else
|
|
|
|
dataTypeName := AAttribute.DataTypeName;
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
{ References enumeration. }
|
2014-11-15 11:29:35 +00:00
|
|
|
Result := FindEnumeration(ASchema, dataTypeName);
|
2010-06-22 08:27:28 +00:00
|
|
|
|
|
|
|
if not Assigned(Result) then
|
|
|
|
begin
|
2014-11-15 11:29:35 +00:00
|
|
|
Result := TXMLDataBindingUnresolvedItem.Create(Self, AAttribute, dataTypeName, ifEnumeration, True);
|
2010-06-22 08:27:28 +00:00
|
|
|
ASchema.AddItem(Result);
|
|
|
|
end;
|
|
|
|
end else if simpleTypeDef.IsBuiltInType and AAttribute.IsGlobal then
|
|
|
|
begin
|
|
|
|
{ The element is global, but only references a simple type. }
|
|
|
|
simpleAliasItem := TXMLDataBindingSimpleTypeAliasItem.Create(Self, AAttribute, AAttribute.Name);
|
2012-04-17 07:36:23 +00:00
|
|
|
// #ToDo1 -oMvR: 17-4-2012: TargetNamespace!
|
2010-06-22 08:27:28 +00:00
|
|
|
simpleAliasItem.DataType := AAttribute.DataType;
|
|
|
|
ASchema.AddItem(simpleAliasItem);
|
|
|
|
|
|
|
|
Result := simpleAliasItem;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if not Assigned(Result) then
|
|
|
|
begin
|
|
|
|
if AAttribute.DataType.Enumerations.Count > 0 then
|
|
|
|
begin
|
|
|
|
{ Enumeration }
|
2014-11-15 11:29:35 +00:00
|
|
|
enumerationObject := TXMLDataBindingEnumeration.Create(Self, AAttribute, AAttribute.DataType.Enumerations, AAttribute.Name);
|
2010-06-22 08:27:28 +00:00
|
|
|
ASchema.AddItem(enumerationObject);
|
|
|
|
Result := enumerationObject;
|
|
|
|
end else if AAttribute.DataType.IsComplex then
|
|
|
|
begin
|
|
|
|
{ Interface }
|
|
|
|
interfaceObject := TXMLDataBindingInterface.Create(Self, AAttribute, AAttribute.Name);
|
|
|
|
if Assigned(AAttribute.DataType.BaseType) then
|
|
|
|
interfaceObject.BaseName := AAttribute.DataType.BaseTypeName;
|
|
|
|
|
|
|
|
ASchema.AddItem(interfaceObject);
|
|
|
|
Result := interfaceObject;
|
2012-05-22 13:16:16 +00:00
|
|
|
end else //if AAttribute.IsGlobal then
|
2010-07-15 10:57:03 +00:00
|
|
|
begin
|
|
|
|
{ Non-anonymous non-complex type. Assume somewhere in there is a
|
2012-05-22 13:16:16 +00:00
|
|
|
built-in type. }
|
|
|
|
Result := ProcessSimpleTypeReference(ASchema, AAttribute, AAttribute.DataType);
|
2010-06-22 08:27:28 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TXMLDataBindingGenerator.ProcessChildElement(ASchema: TXMLDataBindingSchema; AElement: IXMLElementDef; AInterface: TXMLDataBindingInterface);
|
|
|
|
var
|
2008-04-21 15:24:33 +00:00
|
|
|
actualElement: IXMLElementDef;
|
2008-03-09 20:36:27 +00:00
|
|
|
propertyType: TXMLDataBindingItem;
|
|
|
|
propertyItem: TXMLDataBindingProperty;
|
2012-04-10 08:47:48 +00:00
|
|
|
namespace: string;
|
2013-06-21 10:25:49 +00:00
|
|
|
schemaDef: IXMLSchemaDef;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
propertyType := ProcessElement(ASchema, AElement);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
if Assigned(AInterface) then
|
|
|
|
begin
|
2008-03-14 15:35:07 +00:00
|
|
|
if Assigned(propertyType) then
|
2008-04-14 19:28:57 +00:00
|
|
|
propertyItem := TXMLDataBindingItemProperty.Create(Self, AElement,
|
|
|
|
AElement.Name,
|
2008-03-14 15:35:07 +00:00
|
|
|
propertyType)
|
|
|
|
else
|
2008-04-14 19:28:57 +00:00
|
|
|
propertyItem := TXMLDataBindingSimpleProperty.Create(Self, AElement,
|
2008-03-14 15:35:07 +00:00
|
|
|
AElement.Name,
|
|
|
|
AElement.DataType);
|
|
|
|
|
2013-06-21 10:25:49 +00:00
|
|
|
if Assigned(AElement.Ref) then
|
|
|
|
schemaDef := AElement.Ref.SchemaDef
|
|
|
|
else
|
|
|
|
schemaDef := AElement.SchemaDef;
|
|
|
|
|
|
|
|
if Assigned(schemaDef) and (not VarIsNull(schemaDef.TargetNamespace)) then
|
2012-05-22 13:16:16 +00:00
|
|
|
begin
|
2013-06-21 10:25:49 +00:00
|
|
|
namespace := schemaDef.TargetNamespace;
|
2012-05-22 13:16:16 +00:00
|
|
|
if namespace <> Schemas[0].TargetNamespace then
|
|
|
|
propertyItem.TargetNamespace := namespace;
|
|
|
|
end;
|
2012-04-10 08:47:48 +00:00
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
propertyItem.IsOptional := IsElementOptional(AElement) or
|
|
|
|
IsChoice(AElement);
|
|
|
|
propertyItem.IsRepeating := IsElementRepeating(AElement);
|
2008-03-14 15:35:07 +00:00
|
|
|
|
2008-04-21 15:24:33 +00:00
|
|
|
|
|
|
|
actualElement := AElement;
|
|
|
|
while Assigned(actualElement) and Assigned(actualElement.Ref) do
|
|
|
|
actualElement := actualElement.Ref;
|
|
|
|
|
|
|
|
if AElement.HasAttribute(AttributeNillable) then
|
|
|
|
propertyItem.IsNillable := StrToBoolDef(AElement.Attributes[AttributeNillable], False)
|
|
|
|
else if actualElement.HasAttribute(AttributeNillable) then
|
|
|
|
propertyItem.IsNillable := StrToBoolDef(actualElement.Attributes[AttributeNillable], False);
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
AInterface.AddProperty(propertyItem);
|
2008-03-14 15:35:07 +00:00
|
|
|
end;
|
2008-04-14 19:28:57 +00:00
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
procedure TXMLDataBindingGenerator.ProcessAttribute(ASchema: TXMLDataBindingSchema; AAttribute: IXMLAttributeDef; AInterface: TXMLDataBindingInterface);
|
|
|
|
var
|
|
|
|
propertyItem: TXMLDataBindingProperty;
|
2010-06-22 08:27:28 +00:00
|
|
|
propertyType: TXMLDataBindingItem;
|
2012-04-10 08:47:48 +00:00
|
|
|
namespace: string;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
begin
|
2010-06-22 08:27:28 +00:00
|
|
|
propertyType := ProcessElement(ASchema, AAttribute);
|
|
|
|
|
|
|
|
if Assigned(propertyType) then
|
|
|
|
propertyItem := TXMLDataBindingItemProperty.Create(Self, AAttribute,
|
2008-04-14 19:28:57 +00:00
|
|
|
AAttribute.Name,
|
2010-06-22 08:27:28 +00:00
|
|
|
propertyType)
|
|
|
|
else
|
|
|
|
propertyItem := TXMLDataBindingSimpleProperty.Create(Self, AAttribute,
|
|
|
|
AAttribute.Name,
|
|
|
|
AAttribute.DataType);
|
2008-04-14 19:28:57 +00:00
|
|
|
|
2012-05-22 13:16:16 +00:00
|
|
|
if not VarIsNull(AAttribute.SchemaDef.TargetNamespace) then
|
|
|
|
begin
|
|
|
|
namespace := AAttribute.SchemaDef.TargetNamespace;
|
|
|
|
if namespace <> ASchema.TargetNamespace then
|
|
|
|
propertyItem.TargetNamespace := namespace;
|
|
|
|
end;
|
2012-04-10 08:47:48 +00:00
|
|
|
|
2010-07-15 13:53:52 +00:00
|
|
|
propertyItem.IsOptional := (AAttribute.Use <> UseRequired);
|
2008-04-14 19:28:57 +00:00
|
|
|
propertyItem.IsAttribute := True;
|
|
|
|
|
|
|
|
AInterface.AddProperty(propertyItem);
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2012-05-22 13:16:16 +00:00
|
|
|
function TXMLDataBindingGenerator.ProcessSimpleTypeReference(ASchema: TXMLDataBindingSchema; AItem: IXMLSchemaItem; ADataType: IXMLTypeDef): TXMLDataBindingItem;
|
|
|
|
var
|
|
|
|
typeDef: IXMLTypeDef;
|
|
|
|
simpleTypeDef: IXMLSimpleTypeDef;
|
|
|
|
simpleAliasItem: TXMLDataBindingSimpleTypeAliasItem;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
{ This code is a fine bit of trial-and-error. It works for the files
|
|
|
|
I've seen so far, but has been modified enough times to say for sure
|
|
|
|
there'll be another unsupported way of referencing simple types. }
|
|
|
|
typeDef := ADataType;
|
|
|
|
|
|
|
|
while Assigned(typeDef) do
|
|
|
|
begin
|
|
|
|
if Supports(typeDef, IXMLSimpleTypeDef, simpleTypeDef) then
|
|
|
|
begin
|
|
|
|
if simpleTypeDef.IsBuiltInType then
|
|
|
|
begin
|
|
|
|
{ The element is global, but only references a simple type. }
|
|
|
|
simpleAliasItem := TXMLDataBindingSimpleTypeAliasItem.Create(Self, AItem, AItem.Name);
|
|
|
|
simpleAliasItem.DataType := typeDef;
|
|
|
|
ASchema.AddItem(simpleAliasItem);
|
|
|
|
|
|
|
|
Result := simpleAliasItem;
|
|
|
|
Break;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
case simpleTypeDef.DerivationMethod of
|
|
|
|
sdmRestriction:
|
|
|
|
typeDef := typeDef.BaseType;
|
|
|
|
|
|
|
|
sdmUnion:
|
|
|
|
begin
|
|
|
|
simpleAliasItem := TXMLDataBindingSimpleTypeAliasItem.Create(Self, AItem, AItem.Name);
|
|
|
|
simpleAliasItem.DataType := typeDef;
|
|
|
|
|
|
|
|
// #ToDo1 -oMvR: set type "union"
|
|
|
|
|
|
|
|
ASchema.AddItem(simpleAliasItem);
|
2017-02-17 14:27:30 +00:00
|
|
|
break;
|
2012-05-22 13:16:16 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
typeDef := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// if not VarIsNull(typeDef.SchemaDef.TargetNamespace) then
|
|
|
|
// begin
|
|
|
|
// namespace := typeDef.SchemaDef.TargetNamespace;
|
|
|
|
// if namespace <> ASchema.TargetNamespace then
|
|
|
|
// propertyItem.TargetNamespace := namespace;
|
|
|
|
// end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-11-15 11:29:35 +00:00
|
|
|
function TXMLDataBindingGenerator.IterateSchemaItems(ASchema: TXMLDataBindingSchema; AIterateProc: TXMLDataBindingIterateItemsProc): TXMLDataBindingItem;
|
2008-03-09 20:36:27 +00:00
|
|
|
var
|
|
|
|
abort: Boolean;
|
|
|
|
itemIndex: Integer;
|
|
|
|
schemaItem: TXMLDataBindingItem;
|
|
|
|
includeIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
abort := False;
|
|
|
|
|
|
|
|
for itemIndex := 0 to Pred(ASchema.ItemCount) do
|
|
|
|
begin
|
|
|
|
schemaItem := ASchema.Items[itemIndex];
|
|
|
|
|
2014-11-15 11:29:35 +00:00
|
|
|
AIterateProc(schemaItem, abort);
|
2008-03-09 20:36:27 +00:00
|
|
|
if abort then
|
|
|
|
begin
|
|
|
|
Result := schemaItem;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if not Assigned(Result) then
|
|
|
|
begin
|
|
|
|
for includeIndex := 0 to Pred(ASchema.IncludeCount) do
|
|
|
|
begin
|
2014-11-15 11:29:35 +00:00
|
|
|
Result := IterateSchemaItems(ASchema.Includes[includeIndex], AIterateProc);
|
2008-03-09 20:36:27 +00:00
|
|
|
if Assigned(Result) then
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLDataBindingGenerator.FindInterface(ASchema: TXMLDataBindingSchema; const AName: String; AType: TXMLDataBindingInterfaceType): TXMLDataBindingInterface;
|
|
|
|
begin
|
2014-11-15 11:29:35 +00:00
|
|
|
Result := TXMLDataBindingInterface(IterateSchemaItems(ASchema,
|
|
|
|
procedure(AItem: TXMLDataBindingItem; var AAbort: Boolean)
|
|
|
|
begin
|
|
|
|
AAbort := False;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2014-11-15 11:29:35 +00:00
|
|
|
if AItem.Name = AName then
|
|
|
|
begin
|
|
|
|
case AItem.ItemType of
|
|
|
|
itInterface:
|
|
|
|
AAbort := (TXMLDataBindingInterface(AItem).InterfaceType = AType);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2014-11-15 11:29:35 +00:00
|
|
|
itComplexTypeAlias,
|
|
|
|
itSimpleTypeAlias:
|
|
|
|
AAbort := (AType = ifElement);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end));
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-11-15 11:29:35 +00:00
|
|
|
function TXMLDataBindingGenerator.FindEnumeration(ASchema: TXMLDataBindingSchema; const AName: String): TXMLDataBindingEnumeration;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2014-11-15 11:29:35 +00:00
|
|
|
Result := TXMLDataBindingEnumeration(IterateSchemaItems(ASchema,
|
|
|
|
procedure(AItem: TXMLDataBindingItem; var AAbort: Boolean)
|
|
|
|
begin
|
|
|
|
AAbort := (AItem.ItemType = itEnumeration) and
|
|
|
|
(AItem.Name = AName);
|
|
|
|
end));
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure TXMLDataBindingGenerator.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
|
2008-03-14 15:35:07 +00:00
|
|
|
var
|
2008-04-14 19:28:57 +00:00
|
|
|
schemaIndex: Integer;
|
2008-03-14 15:35:07 +00:00
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
for schemaIndex := Pred(SchemaCount) downto 0 do
|
2020-04-22 10:26:47 +00:00
|
|
|
Schemas[schemaIndex].ReplaceItem(AOldItem, ANewItem, ARemoveOnly);
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TXMLDataBindingGenerator.ResolveSchema(ASchema: TXMLDataBindingSchema);
|
|
|
|
var
|
|
|
|
itemIndex: Integer;
|
|
|
|
item: TXMLDataBindingItem;
|
|
|
|
interfaceItem: TXMLDataBindingInterface;
|
|
|
|
|
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
for itemIndex := Pred(ASchema.ItemCount) downto 0 do
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
item := ASchema.Items[itemIndex];
|
|
|
|
|
|
|
|
case item.ItemType of
|
|
|
|
itInterface:
|
|
|
|
begin
|
|
|
|
{ Resolve base interface }
|
|
|
|
interfaceItem := TXMLDataBindingInterface(item);
|
|
|
|
|
2008-03-31 21:15:13 +00:00
|
|
|
if (not Assigned(interfaceItem.BaseItem)) and
|
|
|
|
(Length(interfaceItem.BaseName) > 0) then
|
2008-03-09 20:36:27 +00:00
|
|
|
interfaceItem.BaseItem := FindInterface(ASchema, interfaceItem.BaseName, ifComplexType);
|
|
|
|
end;
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
itUnresolved:
|
2011-10-12 10:47:37 +00:00
|
|
|
begin
|
|
|
|
ResolveItem(ASchema, TXMLDataBindingUnresolvedItem(item));
|
|
|
|
FreeAndNil(item);
|
|
|
|
end;
|
2008-04-14 19:28:57 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TXMLDataBindingGenerator.ResolveAlias(ASchema: TXMLDataBindingSchema);
|
|
|
|
var
|
2008-04-18 14:36:17 +00:00
|
|
|
itemIndex: Integer;
|
|
|
|
item: TXMLDataBindingItem;
|
|
|
|
complexAliasItem: TXMLDataBindingComplexTypeAliasItem;
|
|
|
|
simpleAliasItem: TXMLDataBindingSimpleTypeAliasItem;
|
2008-08-27 10:10:04 +00:00
|
|
|
interfaceItem: TXMLDataBindingInterface;
|
2008-04-18 14:36:17 +00:00
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
begin
|
|
|
|
for itemIndex := Pred(ASchema.ItemCount) downto 0 do
|
|
|
|
begin
|
|
|
|
item := ASchema.Items[itemIndex];
|
|
|
|
|
2008-04-18 14:36:17 +00:00
|
|
|
case item.ItemType of
|
|
|
|
itComplexTypeAlias:
|
|
|
|
begin
|
|
|
|
{ Replace alias element with the actual complex type }
|
|
|
|
complexAliasItem := TXMLDataBindingComplexTypeAliasItem(item);
|
|
|
|
if Assigned(complexAliasItem.Item) then
|
|
|
|
begin
|
2008-08-27 10:10:04 +00:00
|
|
|
// (MvR) 27-8-2008: instead, we allow the generation of an alias in
|
|
|
|
// code, so it can be used as a document element
|
|
|
|
// ReplaceItem(complexAliasItem, complexAliasItem.Item);
|
|
|
|
|
|
|
|
interfaceItem := TXMLDataBindingInterface.Create(Self, complexAliasItem.SchemaItem, complexAliasItem.Name);
|
|
|
|
interfaceItem.BaseItem := (complexAliasItem.Item as TXMLDataBindingInterface);
|
|
|
|
interfaceItem.BaseName := complexAliasItem.Item.Name;
|
|
|
|
ASchema.AddItem(interfaceItem);
|
|
|
|
|
2020-04-22 10:26:47 +00:00
|
|
|
ReplaceItem(complexAliasItem, interfaceItem, True);
|
2008-04-18 14:36:17 +00:00
|
|
|
FreeAndNil(complexAliasItem);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
itSimpleTypeAlias:
|
|
|
|
begin
|
|
|
|
{ Remove the alias element - TXMLDataBindingInterfaceItem.ReplaceItem
|
|
|
|
will take care of fixing it's properties. }
|
|
|
|
simpleAliasItem := TXMLDataBindingSimpleTypeAliasItem(item);
|
2020-04-22 10:26:47 +00:00
|
|
|
ReplaceItem(simpleAliasItem, nil, True);
|
2008-04-18 14:36:17 +00:00
|
|
|
FreeAndNil(simpleAliasItem);
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
procedure TXMLDataBindingGenerator.ResolveItem(ASchema: TXMLDataBindingSchema; AItem: TXMLDataBindingUnresolvedItem);
|
2008-03-14 15:35:07 +00:00
|
|
|
var
|
|
|
|
referenceItem: TXMLDataBindingItem;
|
|
|
|
|
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
if not Assigned(AItem) then
|
2008-03-14 15:35:07 +00:00
|
|
|
Exit;
|
|
|
|
|
2014-11-15 11:29:35 +00:00
|
|
|
case AItem.InterfaceType of
|
|
|
|
ifEnumeration:
|
|
|
|
referenceItem := FindEnumeration(ASchema, AItem.Name);
|
|
|
|
|
|
|
|
ifAttribute:
|
|
|
|
begin
|
|
|
|
referenceItem := FindInterface(ASchema, AItem.Name, ifAttribute);
|
|
|
|
|
|
|
|
if not Assigned(referenceItem) then
|
|
|
|
referenceItem := FindEnumeration(ASchema, AItem.Name);
|
|
|
|
|
|
|
|
if not Assigned(referenceItem) then
|
|
|
|
referenceItem := FindInterface(ASchema, AItem.Name, ifElement);
|
|
|
|
end;
|
2008-05-14 13:30:54 +00:00
|
|
|
else
|
|
|
|
referenceItem := FindInterface(ASchema, AItem.Name, AItem.InterfaceType);
|
2008-03-14 15:35:07 +00:00
|
|
|
|
2008-05-14 13:30:54 +00:00
|
|
|
if (not Assigned(referenceItem)) and
|
|
|
|
(AItem.InterfaceType = ifElement) then
|
2014-11-15 11:29:35 +00:00
|
|
|
referenceItem := FindEnumeration(ASchema, AItem.Name);
|
2008-05-14 13:30:54 +00:00
|
|
|
end;
|
2008-03-14 15:35:07 +00:00
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
if Assigned(referenceItem) then
|
2020-04-22 10:26:47 +00:00
|
|
|
ReplaceItem(AItem, referenceItem, True)
|
2014-11-15 11:29:35 +00:00
|
|
|
else
|
|
|
|
raise EXMLDataBindingUnresolvedItem.CreateFmt('Unresolved %s: %s',
|
|
|
|
[GetEnumName(TypeInfo(TXMLDataBindingInterfaceType), Ord(AItem.InterfaceType)),
|
|
|
|
AItem.Name]);
|
2008-03-14 15:35:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
procedure TXMLDataBindingGenerator.ResolveNameConflicts;
|
2014-10-28 14:22:41 +00:00
|
|
|
type
|
|
|
|
TItemNamesDictionary = TObjectDictionary<String, TObjectList<TXMLDataBindingItem>>;
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
var
|
2014-10-28 14:22:41 +00:00
|
|
|
itemNames: TItemNamesDictionary;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
procedure AddItem(AItem: TXMLDataBindingItem);
|
|
|
|
var
|
|
|
|
hashName: String;
|
2014-10-28 14:22:41 +00:00
|
|
|
items: TObjectList<TXMLDataBindingItem>;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
begin
|
2012-05-22 13:16:16 +00:00
|
|
|
{ LowerCase because XML is case-sensitive, but Delphi isn't. }
|
|
|
|
hashName := LowerCase(AItem.Name);
|
2008-04-14 19:28:57 +00:00
|
|
|
|
2014-10-28 14:22:41 +00:00
|
|
|
if not itemNames.ContainsKey(hashName) then
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2014-10-28 14:22:41 +00:00
|
|
|
items := TObjectList<TXMLDataBindingItem>.Create(False);
|
|
|
|
itemNames.Add(hashName, items);
|
2008-03-09 20:36:27 +00:00
|
|
|
end else
|
2014-10-28 14:22:41 +00:00
|
|
|
items := itemNames[hashName];
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
items.Add(AItem);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function ResolveItemNameConflict(AItem: TXMLDataBindingItem; ADepth: Integer; out ANewName: String): Boolean;
|
|
|
|
var
|
|
|
|
currentDepth: Integer;
|
|
|
|
parentNode: IXMLNode;
|
|
|
|
schemaItem: IXMLSchemaItem;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
currentDepth := 0;
|
|
|
|
parentNode := AItem.SchemaItem;
|
|
|
|
ANewName := AItem.Name;
|
|
|
|
|
|
|
|
while Assigned(parentNode) do
|
|
|
|
begin
|
|
|
|
parentNode := parentNode.ParentNode;
|
|
|
|
|
|
|
|
if Assigned(parentNode) and
|
|
|
|
Supports(parentNode, IXMLSchemaItem, schemaItem) and
|
|
|
|
(Length(schemaItem.Name) > 0) then
|
|
|
|
begin
|
|
|
|
ANewName := schemaItem.Name + ANewName;
|
|
|
|
|
|
|
|
Inc(currentDepth);
|
|
|
|
if currentDepth = ADepth then
|
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
schemaIndex: Integer;
|
|
|
|
schema: TXMLDataBindingSchema;
|
|
|
|
itemIndex: Integer;
|
2014-10-28 14:22:41 +00:00
|
|
|
items: TObjectList<TXMLDataBindingItem>;
|
2008-03-09 20:36:27 +00:00
|
|
|
item: TXMLDataBindingItem;
|
|
|
|
depth: Integer;
|
|
|
|
newName: String;
|
|
|
|
resolved: Boolean;
|
|
|
|
|
|
|
|
begin
|
2014-10-28 14:22:41 +00:00
|
|
|
itemNames := TItemNamesDictionary.Create([doOwnsValues]);
|
2008-03-09 20:36:27 +00:00
|
|
|
try
|
|
|
|
{ Gather names }
|
|
|
|
for schemaIndex := 0 to Pred(SchemaCount) do
|
|
|
|
begin
|
|
|
|
schema := Schemas[schemaIndex];
|
|
|
|
|
|
|
|
for itemIndex := 0 to Pred(schema.ItemCount) do
|
|
|
|
begin
|
2014-10-28 14:22:41 +00:00
|
|
|
item := schema.Items[itemIndex];
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
if item.ItemType in [itInterface, itEnumeration] then
|
2008-03-09 20:36:27 +00:00
|
|
|
AddItem(item);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ Find conflicts }
|
2014-10-28 14:22:41 +00:00
|
|
|
for items in itemNames.Values do
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
if items.Count > 1 then
|
|
|
|
begin
|
|
|
|
{ Attempt to rename items }
|
|
|
|
for itemIndex := Pred(items.Count) downto 0 do
|
|
|
|
begin
|
2014-10-28 14:22:41 +00:00
|
|
|
item := items[itemIndex];
|
2008-03-09 20:36:27 +00:00
|
|
|
newName := item.Name;
|
|
|
|
resolved := False;
|
|
|
|
depth := 1;
|
|
|
|
|
|
|
|
while ResolveItemNameConflict(item, depth, newName) do
|
|
|
|
begin
|
2014-11-15 11:29:35 +00:00
|
|
|
if not itemNames.ContainsKey(LowerCase(newName)) then
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
resolved := True;
|
|
|
|
break;
|
|
|
|
end else
|
|
|
|
Inc(depth);
|
|
|
|
end;
|
|
|
|
|
2010-07-15 10:57:03 +00:00
|
|
|
{ test }
|
|
|
|
if not resolved then
|
|
|
|
begin
|
|
|
|
newName := newName + IntToStr(Succ(itemIndex));
|
|
|
|
resolved := True;
|
|
|
|
end;
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
if resolved then
|
|
|
|
begin
|
|
|
|
items.Delete(itemIndex);
|
|
|
|
|
|
|
|
item.SetName(newName);
|
|
|
|
AddItem(item);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FreeAndNil(itemNames);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
procedure TXMLDataBindingGenerator.PostProcessSchema(ASchema: TXMLDataBindingSchema);
|
2008-03-09 20:36:27 +00:00
|
|
|
var
|
|
|
|
itemIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
for itemIndex := Pred(ASchema.ItemCount) downto 0 do
|
|
|
|
PostProcessItem(ASchema, ASchema.Items[itemIndex]);
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
procedure TXMLDataBindingGenerator.PostProcessItem(ASchema: TXMLDataBindingSchema; AItem: TXMLDataBindingItem);
|
2008-03-09 20:36:27 +00:00
|
|
|
var
|
2008-04-14 19:28:57 +00:00
|
|
|
collectionItem: TXMLDataBindingInterface;
|
|
|
|
collectionName: string;
|
|
|
|
enumerationItem: TXMLDataBindingEnumeration;
|
|
|
|
interfaceItem: TXMLDataBindingInterface;
|
|
|
|
memberIndex: Integer;
|
|
|
|
propertyIndex: Integer;
|
|
|
|
propertyItem: TXMLDataBindingProperty;
|
2014-10-28 14:22:41 +00:00
|
|
|
repeatingItems: TObjectList<TXMLDataBindingProperty>;
|
2010-06-22 08:27:28 +00:00
|
|
|
typedSchemaItem: IXMLTypedSchemaItem;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
{ Translate name }
|
2010-07-15 10:57:03 +00:00
|
|
|
AItem.TranslatedName := TranslateItemName(AItem);
|
|
|
|
|
|
|
|
{ Process members }
|
|
|
|
case AItem.ItemType of
|
|
|
|
itInterface:
|
|
|
|
begin
|
|
|
|
interfaceItem := TXMLDataBindingInterface(AItem);
|
|
|
|
|
|
|
|
if (not Assigned(interfaceItem.BaseItem)) and
|
|
|
|
(Length(interfaceItem.BaseName) > 0) then
|
|
|
|
begin
|
|
|
|
{ Assume this is a reference to a simple type }
|
|
|
|
if Supports(interfaceItem.SchemaItem, IXMLTypedSchemaItem, typedSchemaItem) then
|
|
|
|
begin
|
|
|
|
propertyItem := TXMLDataBindingSimpleProperty.Create(Self, interfaceItem.SchemaItem, 'Value',
|
|
|
|
typedSchemaItem.DataType.BaseType);
|
|
|
|
propertyItem.IsNodeValue := True;
|
|
|
|
|
|
|
|
interfaceItem.AddProperty(propertyItem);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
for propertyIndex := 0 to Pred(interfaceItem.PropertyCount) do
|
|
|
|
PostProcessItem(ASchema, interfaceItem.Properties[propertyIndex]);
|
|
|
|
end;
|
|
|
|
itEnumeration:
|
|
|
|
begin
|
|
|
|
enumerationItem := TXMLDataBindingEnumeration(AItem);
|
|
|
|
|
|
|
|
for memberIndex := 0 to Pred(enumerationItem.MemberCount) do
|
|
|
|
PostProcessItem(ASchema, enumerationItem.Members[memberIndex]);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
|
|
|
|
{ Extract collections }
|
|
|
|
if AItem.ItemType = itInterface then
|
|
|
|
begin
|
|
|
|
interfaceItem := TXMLDataBindingInterface(AItem);
|
|
|
|
interfaceItem.CollectionItem := nil;
|
|
|
|
|
2014-10-28 14:22:41 +00:00
|
|
|
repeatingItems := TObjectList<TXMLDataBindingProperty>.Create(False);
|
2008-04-14 19:28:57 +00:00
|
|
|
try
|
|
|
|
for propertyIndex := 0 to Pred(interfaceItem.PropertyCount) do
|
|
|
|
if interfaceItem.Properties[propertyIndex].IsRepeating then
|
|
|
|
repeatingItems.Add(interfaceItem.Properties[propertyIndex]);
|
|
|
|
|
|
|
|
if repeatingItems.Count > 0 then
|
|
|
|
begin
|
2008-04-25 10:34:16 +00:00
|
|
|
if (repeatingItems.Count = 1) and
|
|
|
|
(not Assigned(interfaceItem.BaseItem)) then
|
2008-04-14 19:28:57 +00:00
|
|
|
begin
|
|
|
|
{ Single repeating child, the item itself is a collection parent }
|
2014-10-28 14:22:41 +00:00
|
|
|
interfaceItem.CollectionItem := repeatingItems[0];
|
2008-04-14 19:28:57 +00:00
|
|
|
end else
|
|
|
|
begin
|
2008-04-25 10:34:16 +00:00
|
|
|
{ Multiple repeating children or this interface is a descendant,
|
|
|
|
create intermediate collections for each }
|
2008-04-14 19:28:57 +00:00
|
|
|
for propertyIndex := 0 to Pred(repeatingItems.Count) do
|
|
|
|
begin
|
|
|
|
propertyItem := TXMLDataBindingProperty(repeatingItems[propertyIndex]);
|
|
|
|
|
|
|
|
// #ToDo1 (MvR) 7-4-2008: check if an item with the "List" postfix
|
|
|
|
// exists in the schema, as it could cause
|
|
|
|
// conflicts.
|
2008-07-31 14:56:36 +00:00
|
|
|
// #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;
|
|
|
|
|
|
|
|
collectionItem := TXMLDataBindingInterface.Create(Self, propertyItem.SchemaItem, collectionName);
|
|
|
|
collectionItem.CollectionItem := propertyItem;
|
|
|
|
ASchema.InsertItem(collectionItem, interfaceItem);
|
2008-04-14 19:28:57 +00:00
|
|
|
end;
|
|
|
|
|
2009-09-18 07:49:04 +00:00
|
|
|
propertyItem.Collection := collectionItem;
|
2008-04-14 19:28:57 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FreeAndNil(repeatingItems);
|
|
|
|
end;
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLDataBindingGenerator.TranslateItemName(AItem: TXMLDataBindingItem): String;
|
|
|
|
begin
|
|
|
|
Result := AItem.Name;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingGenerator.GetSchemaCount: Integer;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := FSchemas.Count;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLDataBindingGenerator.GetSchemas(Index: Integer): TXMLDataBindingSchema;
|
|
|
|
begin
|
2014-10-28 14:22:41 +00:00
|
|
|
Result := FSchemas[Index];
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
{ TXMLDataBindingGeneratorItem }
|
|
|
|
constructor TXMLDataBindingGeneratorItem.Create(AOwner: TXMLDataBindingGenerator);
|
|
|
|
begin
|
2010-06-22 08:27:28 +00:00
|
|
|
inherited Create;
|
2008-04-14 19:28:57 +00:00
|
|
|
|
|
|
|
FOwner := AOwner;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure TXMLDataBindingGeneratorItem.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
|
2008-04-14 19:28:57 +00:00
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
{ TXMLDataBindingSchema }
|
2008-04-14 19:28:57 +00:00
|
|
|
constructor TXMLDataBindingSchema.Create(AOwner: TXMLDataBindingGenerator);
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
inherited Create(AOwner);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2014-10-28 14:22:41 +00:00
|
|
|
FIncludes := TObjectList<TXMLDataBindingSchema>.Create(False);
|
|
|
|
FItems := TObjectList<TXMLDataBindingItem>.Create(True);
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
destructor TXMLDataBindingSchema.Destroy;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FItems);
|
|
|
|
FreeAndNil(FIncludes);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure TXMLDataBindingSchema.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
|
2008-04-14 19:28:57 +00:00
|
|
|
var
|
|
|
|
itemIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
for itemIndex := Pred(ItemCount) downto 0 do
|
|
|
|
if Items[itemIndex] = AOldItem then
|
2020-04-22 10:26:47 +00:00
|
|
|
begin
|
|
|
|
if ARemoveOnly then
|
|
|
|
FItems.Extract(AOldItem)
|
|
|
|
else
|
|
|
|
FItems[itemIndex] := ANewItem;
|
|
|
|
end else
|
|
|
|
Items[itemIndex].ReplaceItem(AOldItem, ANewItem, ARemoveOnly);
|
2008-04-14 19:28:57 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TXMLDataBindingSchema.AddInclude(ASchema: TXMLDataBindingSchema);
|
|
|
|
begin
|
|
|
|
if FIncludes.IndexOf(ASchema) = -1 then
|
|
|
|
FIncludes.Add(ASchema);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TXMLDataBindingSchema.AddItem(AItem: TXMLDataBindingItem);
|
|
|
|
begin
|
|
|
|
if FItems.IndexOf(AItem) = -1 then
|
2008-04-14 19:28:57 +00:00
|
|
|
begin
|
2008-03-09 20:36:27 +00:00
|
|
|
FItems.Add(AItem);
|
2008-04-14 19:28:57 +00:00
|
|
|
AItem.Schema := Self;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TXMLDataBindingSchema.InsertItem(AItem, AAfter: TXMLDataBindingItem);
|
|
|
|
var
|
|
|
|
itemIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if FItems.IndexOf(AItem) = -1 then
|
|
|
|
begin
|
|
|
|
itemIndex := FItems.IndexOf(AAfter);
|
|
|
|
if itemIndex > -1 then
|
|
|
|
FItems.Insert(Succ(itemIndex), AItem)
|
|
|
|
else
|
|
|
|
FItems.Add(AItem);
|
|
|
|
|
|
|
|
AItem.Schema := Self;
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingSchema.GetIncludeCount: Integer;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := FIncludes.Count;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLDataBindingSchema.GetIncludes(Index: Integer): TXMLDataBindingSchema;
|
|
|
|
begin
|
2014-10-28 14:22:41 +00:00
|
|
|
Result := FIncludes[Index];
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingSchema.GetItemCount: Integer;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := FItems.Count;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLDataBindingSchema.GetItems(Index: Integer): TXMLDataBindingItem;
|
|
|
|
begin
|
2014-10-28 14:22:41 +00:00
|
|
|
Result := FItems[Index];
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingSchema.GetTargetNamespace: String;
|
2008-04-24 14:37:05 +00:00
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
if Assigned(FSchemaDef) and (not VarIsNull(FSchemaDef.TargetNamespace)) then
|
|
|
|
Result := FSchemaDef.TargetNamespace;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
{ TXMLDataBindingItem }
|
2008-04-14 19:28:57 +00:00
|
|
|
constructor TXMLDataBindingItem.Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; const AName: String);
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
inherited Create(AOwner);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
FName := AName;
|
|
|
|
FSchemaItem := ASchemaItem;
|
|
|
|
FTranslatedName := AName;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingItem.GetDocumentation: String;
|
2008-03-09 20:36:27 +00:00
|
|
|
var
|
|
|
|
documentationIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
if HasDocumentation then
|
|
|
|
begin
|
|
|
|
for documentationIndex := 0 to Pred(SchemaItem.Documentation.Count) do
|
|
|
|
Result := Result + SchemaItem.Documentation[documentationIndex].Text + #13#10;
|
|
|
|
|
|
|
|
Result := Trim(Result);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingItem.GetHasDocumentation: Boolean;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := Assigned(SchemaItem) and
|
|
|
|
(SchemaItem.Documentation.Count > 0);
|
|
|
|
end;
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingItem.GetIsCollection: Boolean;
|
2008-04-14 19:28:57 +00:00
|
|
|
begin
|
|
|
|
Result := Assigned(FCollectionItem);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TXMLDataBindingItem.SetName(const Value: String);
|
|
|
|
begin
|
|
|
|
FName := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TXMLDataBindingInterface }
|
2008-04-14 19:28:57 +00:00
|
|
|
constructor TXMLDataBindingInterface.Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; const AName: String);
|
2010-07-15 10:57:03 +00:00
|
|
|
var
|
|
|
|
elementDef: IXMLElementDef;
|
|
|
|
compositor: IXMLElementCompositor;
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
inherited Create(AOwner, ASchemaItem, AName);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2014-10-28 14:22:41 +00:00
|
|
|
FProperties := TObjectList<TXMLDataBindingProperty>.Create(True);
|
2008-03-09 20:36:27 +00:00
|
|
|
FInterfaceType := GetInterfaceType(SchemaItem);
|
2010-07-15 10:57:03 +00:00
|
|
|
FIsSequence := False;
|
|
|
|
|
|
|
|
if Supports(ASchemaItem, IXMLElementDef, elementDef) then
|
|
|
|
begin
|
|
|
|
{ To access the compositor, we need to go through a ChildElement's ParentNode.
|
|
|
|
|
|
|
|
Tried but did not work:
|
|
|
|
ASchemaItem as IXMLElementCompositor
|
|
|
|
ASchemaItem.ChildNodes[0] as IXMLElementCompositor
|
|
|
|
}
|
|
|
|
if elementDef.ChildElements.Count > 0 then
|
|
|
|
begin
|
|
|
|
if Supports(elementDef.ChildElements[0].ParentNode, IXMLElementCompositor, compositor) then
|
|
|
|
FIsSequence := (compositor.CompositorType = ctSequence);
|
|
|
|
end;
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
destructor TXMLDataBindingInterface.Destroy;
|
|
|
|
begin
|
|
|
|
FreeAndNil(FProperties);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure TXMLDataBindingInterface.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
|
2008-04-14 19:28:57 +00:00
|
|
|
var
|
2008-04-18 14:36:17 +00:00
|
|
|
propertyIndex: Integer;
|
|
|
|
propertyItem: TXMLDataBindingProperty;
|
|
|
|
itemProperty: TXMLDataBindingItemProperty;
|
|
|
|
simpleProperty: TXMLDataBindingSimpleProperty;
|
2008-04-14 19:28:57 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2012-05-22 13:16:16 +00:00
|
|
|
// #ToDo1 -oMvR: replacing a simpletypealias with nil doesn't quite work. not sure yet why.
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
for propertyIndex := Pred(PropertyCount) downto 0 do
|
2008-04-18 14:36:17 +00:00
|
|
|
begin
|
|
|
|
propertyItem := Properties[propertyIndex];
|
|
|
|
|
|
|
|
if propertyItem = AOldItem then
|
2020-04-22 10:26:47 +00:00
|
|
|
begin
|
|
|
|
if ARemoveOnly then
|
|
|
|
FProperties.Extract(propertyItem)
|
|
|
|
else
|
|
|
|
FProperties[propertyIndex] := ANewItem as TXMLDataBindingProperty;
|
|
|
|
end else
|
2008-04-18 14:36:17 +00:00
|
|
|
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 }
|
2008-04-21 15:24:33 +00:00
|
|
|
simpleProperty := TXMLDataBindingSimpleProperty.CreateFromAlias(Owner, itemProperty, TXMLDataBindingSimpleTypeAliasItem(AOldItem).DataType);
|
2008-04-18 14:36:17 +00:00
|
|
|
|
|
|
|
{ FProperties owns itemProperty and will free it }
|
|
|
|
FProperties[propertyIndex] := simpleProperty;
|
|
|
|
end else
|
2020-04-22 10:26:47 +00:00
|
|
|
Properties[propertyIndex].ReplaceItem(AOldItem, ANewItem, ARemoveOnly);
|
2008-04-18 14:36:17 +00:00
|
|
|
end else
|
2020-04-22 10:26:47 +00:00
|
|
|
Properties[propertyIndex].ReplaceItem(AOldItem, ANewItem, ARemoveOnly);
|
2008-04-18 14:36:17 +00:00
|
|
|
end;
|
|
|
|
end;
|
2008-04-14 19:28:57 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
procedure TXMLDataBindingInterface.AddProperty(AProperty: TXMLDataBindingProperty);
|
|
|
|
begin
|
|
|
|
FProperties.Add(AProperty);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-07-15 10:57:03 +00:00
|
|
|
function TXMLDataBindingInterface.GetCanValidate: Boolean;
|
|
|
|
var
|
|
|
|
propertyIndex: Integer;
|
|
|
|
elementCount: Integer;
|
|
|
|
requiredCount: Integer;
|
|
|
|
propertyItem: TXMLDataBindingProperty;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
elementCount := 0;
|
|
|
|
requiredCount := 0;
|
|
|
|
|
|
|
|
for propertyIndex := 0 to Pred(PropertyCount) do
|
|
|
|
begin
|
|
|
|
propertyItem := Properties[propertyIndex];
|
|
|
|
|
|
|
|
if propertyItem.IsAttribute then
|
|
|
|
begin
|
|
|
|
if not propertyItem.IsOptional then
|
|
|
|
Inc(requiredCount);
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
Inc(elementCount);
|
|
|
|
if not propertyItem.IsOptional then
|
|
|
|
Inc(requiredCount);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ If there's a required element or attribute,
|
|
|
|
we can validate their presence. }
|
|
|
|
if requiredCount > 0 then
|
|
|
|
Result := True
|
|
|
|
|
|
|
|
{ If our children are a sequence and there's at least two elements,
|
|
|
|
we can validate their order. }
|
|
|
|
else if IsSequence and (elementCount > 1) then
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingInterface.GetItemType: TXMLDataBindingItemType;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := itInterface;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingInterface.GetPropertyCount: Integer;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := FProperties.Count;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLDataBindingInterface.GetProperties(Index: Integer): TXMLDataBindingProperty;
|
|
|
|
begin
|
2014-10-28 14:22:41 +00:00
|
|
|
Result := FProperties[Index];
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TXMLDataBindingEnumerationMember }
|
2008-04-14 19:28:57 +00:00
|
|
|
constructor TXMLDataBindingEnumerationMember.Create(AOwner: TXMLDataBindingGenerator; AEnumeration: TXMLDataBindingEnumeration; const AName: String);
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
inherited Create(AOwner, nil, AName);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
FEnumeration := AEnumeration;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingEnumerationMember.GetItemType: TXMLDataBindingItemType;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := itEnumerationMember;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TXMLDataBindingEnumeration }
|
2014-11-15 11:29:35 +00:00
|
|
|
constructor TXMLDataBindingEnumeration.Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; AEnumerations: IXMLEnumerationCollection; const AName: String);
|
2008-03-09 20:36:27 +00:00
|
|
|
var
|
|
|
|
memberIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
inherited Create(AOwner, ASchemaItem, AName);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2014-10-28 14:22:41 +00:00
|
|
|
FMembers := TObjectList<TXMLDataBindingEnumerationMember>.Create;
|
2008-03-09 20:36:27 +00:00
|
|
|
|
2020-04-22 10:26:47 +00:00
|
|
|
if Assigned(AEnumerations) then
|
|
|
|
begin
|
|
|
|
for memberIndex := 0 to Pred(AEnumerations.Count) do
|
|
|
|
FMembers.Add(TXMLDataBindingEnumerationMember.Create(Owner, Self, AEnumerations.Items[memberIndex].Value));
|
|
|
|
end;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
destructor TXMLDataBindingEnumeration.Destroy;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FMembers);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure TXMLDataBindingEnumeration.ReplaceMembers(AMembers: TEnumerable<TXMLDataBindingEnumerationMember>);
|
|
|
|
var
|
|
|
|
member: TXMLDataBindingEnumerationMember;
|
|
|
|
|
|
|
|
begin
|
|
|
|
FMembers.Clear;
|
|
|
|
|
|
|
|
for member in AMembers do
|
|
|
|
FMembers.Add(member);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingEnumeration.GetItemType: TXMLDataBindingItemType;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := itEnumeration;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingEnumeration.GetMemberCount: Integer;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := FMembers.Count;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TXMLDataBindingEnumeration.GetMembers(Index: Integer): TXMLDataBindingEnumerationMember;
|
|
|
|
begin
|
2014-10-28 14:22:41 +00:00
|
|
|
Result := FMembers[Index];
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TXMLDataBindingProperty }
|
2012-04-10 08:47:48 +00:00
|
|
|
function TXMLDataBindingProperty.GetHasTargetNamespace: Boolean;
|
|
|
|
begin
|
|
|
|
Result := (Length(TargetNamespace) > 0);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingProperty.GetItemType: TXMLDataBindingItemType;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := itProperty;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TXMLDataBindingSimpleProperty }
|
2008-04-14 19:28:57 +00:00
|
|
|
constructor TXMLDataBindingSimpleProperty.Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; const AName: String; ADataType: IXMLTypeDef);
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
inherited Create(AOwner, ASchemaItem, AName);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
FDataType := ADataType;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-21 15:24:33 +00:00
|
|
|
constructor TXMLDataBindingSimpleProperty.CreateFromAlias(AOwner: TXMLDataBindingGenerator; AProperty: TXMLDataBindingItemProperty; ADataType: IXMLTypeDef);
|
|
|
|
begin
|
|
|
|
Create(AOwner, AProperty.SchemaItem, AProperty.Name, ADataType);
|
|
|
|
|
2012-04-17 07:36:23 +00:00
|
|
|
TargetNamespace := AProperty.TargetNamespace;
|
|
|
|
|
2008-04-21 15:24:33 +00:00
|
|
|
IsAttribute := AProperty.IsAttribute;
|
|
|
|
IsOptional := AProperty.IsOptional;
|
|
|
|
IsNillable := AProperty.IsNillable;
|
|
|
|
IsRepeating := AProperty.IsRepeating;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingSimpleProperty.GetIsReadOnly: Boolean;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingSimpleProperty.GetPropertyType: TXMLDataBindingPropertyType;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := ptSimple;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TXMLDataBindingItemProperty }
|
2008-04-14 19:28:57 +00:00
|
|
|
constructor TXMLDataBindingItemProperty.Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; const AName: String; AItem: TXMLDataBindingItem);
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
inherited Create(AOwner, ASchemaItem, AName);
|
2008-03-09 20:36:27 +00:00
|
|
|
|
|
|
|
FItem := AItem;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure TXMLDataBindingItemProperty.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
|
2008-04-14 19:28:57 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
if FItem = AOldItem then
|
|
|
|
FItem := ANewItem;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingItemProperty.GetIsReadOnly: Boolean;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := Assigned(Item) and (Item.ItemType <> itEnumeration);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingItemProperty.GetPropertyType: TXMLDataBindingPropertyType;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
|
|
|
Result := ptItem;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-14 19:28:57 +00:00
|
|
|
{ TXMLDataBindingUnresolvedItem }
|
2010-07-15 10:57:03 +00:00
|
|
|
constructor TXMLDataBindingUnresolvedItem.Create(AOwner: TXMLDataBindingGenerator; ASchemaItem: IXMLSchemaItem; const AName: String; AInterfaceType: TXMLDataBindingInterfaceType; AIsAttribute: Boolean);
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
inherited Create(AOwner, ASchemaItem, AName);
|
|
|
|
|
2010-07-15 10:57:03 +00:00
|
|
|
FInterfaceType := AInterfaceType;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingUnresolvedItem.GetItemType: TXMLDataBindingItemType;
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
Result := itUnresolved;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-04-18 14:36:17 +00:00
|
|
|
{ TXMLDataBindingComplexTypeAliasItem }
|
2020-04-22 10:26:47 +00:00
|
|
|
procedure TXMLDataBindingComplexTypeAliasItem.ReplaceItem(const AOldItem, ANewItem: TXMLDataBindingItem; ARemoveOnly: Boolean);
|
2008-03-09 20:36:27 +00:00
|
|
|
begin
|
2008-04-14 19:28:57 +00:00
|
|
|
inherited;
|
|
|
|
|
|
|
|
if FItem = AOldItem then
|
|
|
|
FItem := ANewItem;
|
2008-03-09 20:36:27 +00:00
|
|
|
end;
|
|
|
|
|
2008-03-31 21:15:13 +00:00
|
|
|
|
2010-06-22 08:27:28 +00:00
|
|
|
function TXMLDataBindingComplexTypeAliasItem.GetItemType: TXMLDataBindingItemType;
|
2008-04-18 14:36:17 +00:00
|
|
|
begin
|
|
|
|
Result := itComplexTypeAlias;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TXMLDataBindingSimpleTypeAliasItem }
|
|
|
|
function TXMLDataBindingSimpleTypeAliasItem.GetItemType: TXMLDataBindingItemType;
|
2008-03-31 21:15:13 +00:00
|
|
|
begin
|
2008-04-18 14:36:17 +00:00
|
|
|
Result := itSimpleTypeAlias;
|
2008-03-31 21:15:13 +00:00
|
|
|
end;
|
|
|
|
|
2008-03-09 20:36:27 +00:00
|
|
|
end.
|
|
|
|
|
|
|
|
|
|
|
|
|