From 5e75e3435fe77c759539061a841f1adf0de8ca55 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Tue, 29 Sep 2009 15:12:47 +0000 Subject: [PATCH] Support for renaming properties using the Hints file Fixed support for simple type collections --- Forms/MainFrm.dfm | 8 ++ Forms/MainFrm.pas | 59 ++++++++-- Units/DataBindingHintsXML.pas | 137 +++++++++++++++++++---- Units/DelphiXMLDataBindingGenerator.pas | 5 +- X2XMLDataBinding.dof | 138 ++++++++++++++++++++++++ X2XMLDataBinding.dproj | 81 ++++++++++++++ XSD/DataBindingHints.xsd | 17 ++- 7 files changed, 414 insertions(+), 31 deletions(-) create mode 100644 X2XMLDataBinding.dof create mode 100644 X2XMLDataBinding.dproj diff --git a/Forms/MainFrm.dfm b/Forms/MainFrm.dfm index d5e4a09..e4b1f54 100644 --- a/Forms/MainFrm.dfm +++ b/Forms/MainFrm.dfm @@ -82,6 +82,10 @@ object MainForm: TMainForm TabOrder = 2 object spFile: TTabSheet TabVisible = False + ExplicitLeft = 0 + ExplicitTop = 0 + ExplicitWidth = 0 + ExplicitHeight = 0 object lblFile: TLabel Left = 8 Top = 7 @@ -103,6 +107,10 @@ object MainForm: TMainForm end object spFolder: TTabSheet TabVisible = False + ExplicitLeft = 0 + ExplicitTop = 0 + ExplicitWidth = 0 + ExplicitHeight = 0 DesignSize = ( 408 85) diff --git a/Forms/MainFrm.pas b/Forms/MainFrm.pas index 2edf967..39611ad 100644 --- a/Forms/MainFrm.pas +++ b/Forms/MainFrm.pas @@ -89,7 +89,8 @@ uses type - TProtectedXMLDataBindingItem = class(TXMLDataBindingItem); + TProtectedXMLDataBindingItem = class(TXMLDataBindingItem); + TProtectedXMLDataBindingProperty = class(TXMLDataBindingProperty); THintsDelphiXMLDataBindingGenerator = class(TDelphiXMLDataBindingGenerator) private @@ -102,6 +103,7 @@ type procedure ProcessEnumerations; procedure ProcessDocumentElements; procedure ProcessInterfaces; + procedure ProcessProperties; function FindSchema(const ASchemaName: String; out ASchema: TXMLDataBindingSchema): Boolean; function FindNode(const ASchemaName, AXPath: String; out AItem: TXMLDataBindingItem): Boolean; @@ -391,6 +393,9 @@ begin if Hints.HasInterfaces then ProcessInterfaces; + + if Hints.HasProperties then + ProcessProperties; end; @@ -482,6 +487,26 @@ begin end; +procedure THintsDelphiXMLDataBindingGenerator.ProcessProperties; +var + itemIndex: Integer; + propertyName: IXMLPropertyName; + schemaItem: TXMLDataBindingItem; + +begin + for itemIndex := 0 to Pred(Hints.Properties.Count) do + begin + propertyName := Hints.Properties[itemIndex]; + + if FindNode(propertyName.Schema, propertyName.XPath, schemaItem) then + begin + if schemaItem.ItemType = itProperty then + schemaItem.TranslatedName := propertyName.Text; + end; + end; +end; + + function THintsDelphiXMLDataBindingGenerator.FindSchema(const ASchemaName: String; out ASchema: TXMLDataBindingSchema): Boolean; var schemaIndex: Integer; @@ -557,11 +582,14 @@ function THintsDelphiXMLDataBindingGenerator.FindNode(const ASchemaName, AXPath: var - schema: TXMLDataBindingSchema; - schemaItem: IDOMNode; - item: TProtectedXMLDataBindingItem; - itemIndex: Integer; - domDocument: IXMLDOMDocument2; + schema: TXMLDataBindingSchema; + schemaItem: IDOMNode; + item: TProtectedXMLDataBindingItem; + itemIndex: Integer; + domDocument: IXMLDOMDocument2; + interfaceItem: TXMLDataBindingInterface; + propertyIndex: Integer; + propertyItem: TProtectedXMLDataBindingProperty; begin Result := False; @@ -584,8 +612,25 @@ begin begin AItem := schema.Items[itemIndex]; Result := True; - Break; + end else if item.ItemType = itInterface then + begin + interfaceItem := TXMLDataBindingInterface(item); + + for propertyIndex := 0 to Pred(interfaceItem.PropertyCount) do + begin + propertyItem := TProtectedXMLDataBindingProperty(interfaceItem.Properties[propertyIndex]); + + if Assigned(propertyItem.SchemaItem) and SameNode(propertyItem.SchemaItem.DOMNode, schemaItem) then + begin + AItem := propertyItem; + Result := True; + Break; + end; + end; end; + + if Result then + Break; end; end; end; diff --git a/Units/DataBindingHintsXML.pas b/Units/DataBindingHintsXML.pas index 629a468..e40cff4 100644 --- a/Units/DataBindingHintsXML.pas +++ b/Units/DataBindingHintsXML.pas @@ -1,7 +1,7 @@ { X2Software XML Data Binding - Generated on: 14-5-2008 11:21:00 + Generated on: 29-9-2009 14:31:13 Generated from: P:\test\XMLDataBinding\XSD\DataBindingHints.xsd } unit DataBindingHintsXML; @@ -22,19 +22,23 @@ type IXMLDocumentElement = interface; IXMLInterfaces = interface; IXMLInterfaceName = interface; + IXMLProperties = interface; + IXMLPropertyName = interface; { Interfaces for DataBindingHints } { Contains hints and mappings for the data binding output } IXMLDataBindingHints = interface(IXMLNode) - ['{D2B7C152-7F8F-4B0F-9270-7330351B8D4E}'] + ['{434CBC09-8E33-4970-9C4A-535B4C898185}'] function GetHasEnumerations: Boolean; function GetEnumerations: IXMLEnumerations; function GetHasDocumentElements: Boolean; function GetDocumentElements: IXMLDocumentElements; function GetHasInterfaces: Boolean; function GetInterfaces: IXMLInterfaces; + function GetHasProperties: Boolean; + function GetProperties: IXMLProperties; property HasEnumerations: Boolean read GetHasEnumerations; property Enumerations: IXMLEnumerations read GetEnumerations; @@ -42,10 +46,12 @@ type property DocumentElements: IXMLDocumentElements read GetDocumentElements; property HasInterfaces: Boolean read GetHasInterfaces; property Interfaces: IXMLInterfaces read GetInterfaces; + property HasProperties: Boolean read GetHasProperties; + property Properties: IXMLProperties read GetProperties; end; IXMLEnumerations = interface(IXMLNodeCollection) - ['{1D5E90E0-06DD-4476-BA73-0753D35B6193}'] + ['{115ECCB0-407B-476E-AA99-63F584F883F7}'] function Get_Enumeration(Index: Integer): IXMLEnumeration; function Add: IXMLEnumeration; function Insert(Index: Integer): IXMLEnumeration; @@ -54,7 +60,7 @@ type end; IXMLEnumeration = interface(IXMLNodeCollection) - ['{07097378-D346-4809-B0A2-86C4BA09C124}'] + ['{4B776A26-325C-4589-8F5B-88E2EE86DEC6}'] function Get_Member(Index: Integer): IXMLMember; function Add: IXMLMember; function Insert(Index: Integer): IXMLMember; @@ -72,7 +78,7 @@ type end; IXMLMember = interface(IXMLNode) - ['{A5C711D5-FEC5-4490-A36B-A2687AB39748}'] + ['{2575F0F6-EDCA-4CC6-B532-94833BCFAB64}'] function GetName: WideString; procedure SetName(const Value: WideString); @@ -85,7 +91,7 @@ type a Document Element. } IXMLDocumentElements = interface(IXMLNodeCollection) - ['{E6C9CBB2-7457-4597-939D-AAE9B1C5F42B}'] + ['{8D3A5543-68FF-4101-9874-639A39E33950}'] function Get_DocumentElement(Index: Integer): IXMLDocumentElement; function Add: IXMLDocumentElement; function Insert(Index: Integer): IXMLDocumentElement; @@ -94,7 +100,7 @@ type end; IXMLDocumentElement = interface(IXMLNode) - ['{93F6182F-4E03-420A-8E84-49F33DC29FA3}'] + ['{3DFD0655-26DA-4237-ACEC-BB7CB3354DD2}'] function GetSchema: WideString; function GetXPath: WideString; @@ -106,7 +112,7 @@ type end; IXMLInterfaces = interface(IXMLNodeCollection) - ['{A18D3AFF-24FC-45FD-9583-15D9292249D2}'] + ['{E70E67E3-C108-4015-B996-962D800BE555}'] function Get_InterfaceName(Index: Integer): IXMLInterfaceName; function Add: IXMLInterfaceName; function Insert(Index: Integer): IXMLInterfaceName; @@ -115,15 +121,34 @@ type end; IXMLInterfaceName = interface(IXMLNode) - ['{EB24ED8F-0D81-48D5-A420-438CAE003A23}'] - function GetHasSchema: Boolean; + ['{2B8126E7-2F89-4E5D-89E3-4F5F7AEE35E9}'] + function GetSchema: WideString; + function GetXPath: WideString; + + procedure SetSchema(const Value: WideString); + procedure SetXPath(const Value: WideString); + + property Schema: WideString read GetSchema write SetSchema; + property XPath: WideString read GetXPath write SetXPath; + end; + + IXMLProperties = interface(IXMLNodeCollection) + ['{88260AE1-1C40-4F0F-AA44-C61EDAA53B38}'] + function Get_PropertyName(Index: Integer): IXMLPropertyName; + function Add: IXMLPropertyName; + function Insert(Index: Integer): IXMLPropertyName; + + property PropertyName[Index: Integer]: IXMLPropertyName read Get_PropertyName; default; + end; + + IXMLPropertyName = interface(IXMLNode) + ['{DB714E5D-E62B-44C4-B7D4-0623887BCDF6}'] function GetSchema: WideString; function GetXPath: WideString; procedure SetSchema(const Value: WideString); procedure SetXPath(const Value: WideString); - property HasSchema: Boolean read GetHasSchema; property Schema: WideString read GetSchema write SetSchema; property XPath: WideString read GetXPath write SetXPath; end; @@ -140,6 +165,8 @@ type function GetDocumentElements: IXMLDocumentElements; function GetHasInterfaces: Boolean; function GetInterfaces: IXMLInterfaces; + function GetHasProperties: Boolean; + function GetProperties: IXMLProperties; end; TXMLEnumerations = class(TXMLNodeCollection, IXMLEnumerations) @@ -202,7 +229,24 @@ type TXMLInterfaceName = class(TXMLNode, IXMLInterfaceName) protected - function GetHasSchema: Boolean; + function GetSchema: WideString; + function GetXPath: WideString; + + procedure SetSchema(const Value: WideString); + procedure SetXPath(const Value: WideString); + end; + + TXMLProperties = class(TXMLNodeCollection, IXMLProperties) + public + procedure AfterConstruction; override; + protected + function Get_PropertyName(Index: Integer): IXMLPropertyName; + function Add: IXMLPropertyName; + function Insert(Index: Integer): IXMLPropertyName; + end; + + TXMLPropertyName = class(TXMLNode, IXMLPropertyName) + protected function GetSchema: WideString; function GetXPath: WideString; @@ -212,7 +256,7 @@ type { Document functions } - function GetDataBindingHints(ADocument: IXMLDocument): IXMLDataBindingHints; + function GetDataBindingHints(ADocument: XMLIntf.IXMLDocument): IXMLDataBindingHints; function LoadDataBindingHints(const AFileName: String): IXMLDataBindingHints; function LoadDataBindingHintsFromStream(AStream: TStream): IXMLDataBindingHints; function NewDataBindingHints: IXMLDataBindingHints; @@ -227,7 +271,7 @@ uses SysUtils; { Document functions } -function GetDataBindingHints(ADocument: IXMLDocument): IXMLDataBindingHints; +function GetDataBindingHints(ADocument: XMLIntf.IXMLDocument): IXMLDataBindingHints; begin Result := ADocument.GetDocBinding('DataBindingHints', TXMLDataBindingHints, TargetNamespace) as IXMLDataBindingHints end; @@ -239,7 +283,7 @@ end; function LoadDataBindingHintsFromStream(AStream: TStream): IXMLDataBindingHints; var - doc: IXMLDocument; + doc: XMLIntf.IXMLDocument; begin doc := NewXMLDocument; @@ -260,6 +304,7 @@ begin RegisterChildNode('Enumerations', TXMLEnumerations); RegisterChildNode('DocumentElements', TXMLDocumentElements); RegisterChildNode('Interfaces', TXMLInterfaces); + RegisterChildNode('Properties', TXMLProperties); inherited; end; @@ -296,6 +341,17 @@ begin Result := (ChildNodes['Interfaces'] as IXMLInterfaces); end; +function TXMLDataBindingHints.GetHasProperties: Boolean; +begin + Result := Assigned(ChildNodes.FindNode('Properties')); +end; + + +function TXMLDataBindingHints.GetProperties: IXMLProperties; +begin + Result := (ChildNodes['Properties'] as IXMLProperties); +end; + procedure TXMLEnumerations.AfterConstruction; begin RegisterChildNode('Enumeration', TXMLEnumeration); @@ -446,12 +502,6 @@ begin Result := (AddItem(Index) as IXMLInterfaceName); end; -function TXMLInterfaceName.GetHasSchema: Boolean; -begin - Result := Assigned(ChildNodes.FindNode('Schema')); -end; - - function TXMLInterfaceName.GetSchema: WideString; begin Result := AttributeNodes['Schema'].Text; @@ -472,6 +522,51 @@ begin SetAttribute('XPath', Value); end; +procedure TXMLProperties.AfterConstruction; +begin + RegisterChildNode('PropertyName', TXMLPropertyName); + + ItemTag := 'PropertyName'; + ItemInterface := IXMLPropertyName; + + inherited; +end; + +function TXMLProperties.Get_PropertyName(Index: Integer): IXMLPropertyName; +begin + Result := (List[Index] as IXMLPropertyName); +end; + +function TXMLProperties.Add: IXMLPropertyName; +begin + Result := (AddItem(-1) as IXMLPropertyName); +end; + +function TXMLProperties.Insert(Index: Integer): IXMLPropertyName; +begin + Result := (AddItem(Index) as IXMLPropertyName); +end; + +function TXMLPropertyName.GetSchema: WideString; +begin + Result := AttributeNodes['Schema'].Text; +end; + +function TXMLPropertyName.GetXPath: WideString; +begin + Result := AttributeNodes['XPath'].Text; +end; + +procedure TXMLPropertyName.SetSchema(const Value: WideString); +begin + SetAttribute('Schema', Value); +end; + +procedure TXMLPropertyName.SetXPath(const Value: WideString); +begin + SetAttribute('XPath', Value); +end; + end. diff --git a/Units/DelphiXMLDataBindingGenerator.pas b/Units/DelphiXMLDataBindingGenerator.pas index 723d0b3..07799f3 100644 --- a/Units/DelphiXMLDataBindingGenerator.pas +++ b/Units/DelphiXMLDataBindingGenerator.pas @@ -289,7 +289,7 @@ var begin case AProperty.PropertyType of ptSimple: - if Assigned(AProperty.Collection) then + if AProperty.IsRepeating then begin if AInterfaceName then Result := ItemInterface @@ -675,6 +675,9 @@ var parent: String; begin + if AItem.Name = 'KeyStrokesType' then + asm int 3 end; + if ASection in [dxsInterface, dxsClass] then begin { Ensure the base item is completely defined first, Delphi doesn't allow diff --git a/X2XMLDataBinding.dof b/X2XMLDataBinding.dof new file mode 100644 index 0000000..920fea1 --- /dev/null +++ b/X2XMLDataBinding.dof @@ -0,0 +1,138 @@ +[FileVersion] +Version=7.0 +[Compiler] +A=8 +B=0 +C=0 +D=1 +E=0 +F=0 +G=1 +H=1 +I=1 +J=0 +K=0 +L=1 +M=0 +N=1 +O=0 +P=1 +Q=0 +R=0 +S=0 +T=0 +U=0 +V=1 +W=0 +X=1 +Y=2 +Z=1 +ShowHints=1 +ShowWarnings=1 +UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; +NamespacePrefix= +SymbolDeprecated=1 +SymbolLibrary=1 +SymbolPlatform=1 +UnitLibrary=1 +UnitPlatform=1 +UnitDeprecated=1 +HResultCompat=1 +HidingMember=1 +HiddenVirtual=1 +Garbage=1 +BoundsError=1 +ZeroNilCompat=1 +StringConstTruncated=1 +ForLoopVarVarPar=1 +TypedConstVarPar=1 +AsgToTypedConst=1 +CaseLabelRange=1 +ForVariable=1 +ConstructingAbstract=1 +ComparisonFalse=1 +ComparisonTrue=1 +ComparingSignedUnsigned=1 +CombiningSignedUnsigned=1 +UnsupportedConstruct=1 +FileOpen=1 +FileOpenUnitSrc=1 +BadGlobalSymbol=1 +DuplicateConstructorDestructor=1 +InvalidDirective=1 +PackageNoLink=1 +PackageThreadVar=1 +ImplicitImport=1 +HPPEMITIgnored=1 +NoRetVal=1 +UseBeforeDef=1 +ForLoopVarUndef=1 +UnitNameMismatch=1 +NoCFGFileFound=1 +MessageDirective=1 +ImplicitVariants=1 +UnicodeToLocale=1 +LocaleToUnicode=1 +ImagebaseMultiple=1 +SuspiciousTypecast=1 +PrivatePropAccessor=1 +UnsafeType=0 +UnsafeCode=0 +UnsafeCast=0 +[Linker] +MapFile=3 +OutputObjs=0 +ConsoleApp=1 +DebugInfo=0 +RemoteSymbols=0 +MinStackSize=16384 +MaxStackSize=1048576 +ImageBase=4194304 +ExeDescription= +[Directories] +OutputDir= +UnitOutputDir=lib +PackageDLLOutputDir= +PackageDCPOutputDir= +SearchPath= +Packages=vcl;rtl;vclx;inet;xmlrtl;vclie;inetdbbde;inetdbxpress;dbrtl;dsnap;vcldb;dsnapcon;soaprtl;VclSmp;dbexpress;dbxcds;inetdb;bdertl;vcldbx;webdsnap;websnap;adortl;CLXIB;ibxpress;VCLIB;teeui;teedb;tee;dss;vclactnband;vclshlctrls;dclOfficeXP;Indy70;cxLibraryVCLD7;dxBarD7;dxComnD7;dxBarDBNavD7;dxBarExtDBItemsD7;dxBarExtItemsD7;dxDockingD7;dxsbD7;cxEditorsVCLD7;dxThemeD7;cxDataD7;cxExtEditorsVCLD7;cxPageControlVCLD7;cxGridVCLD7;cxSchedulerVCLD7;cxTreeListVCLD7;cxVerticalGridVCLD7;cxSpreadSheetVCLD7;dxNavBarD7;cxWebD7;cxWebPascalScriptD7;cxWebSnapD7;cxWebTeeChartD7;dxMasterViewD7;dxmdsD7;dxdbtrD7;dxtrmdD7;dxorgcD7;dxdborD7;dxFlowChartD7;dxLayoutControlD7;dxLayoutControlcxEditAdaptersD7;dxPSCoreD7;dxPSTeeChartD7;dxPsPrVwAdvD7;dxPSLnksD7;dxPSdxOCLnkD7;dxPSdxMVLnkD7;dxPSdxLCLnkD7;dxPSdxFCLnkD7;dxPSdxDBTVLnkD7;dxPSdxDBOCLnkD7;dxPSDBTeeChartD7;dxPScxCommonD7;dxPScxTLLnkD7;dxPScxSSLnkD7;dxPScxPCProdD7;dxPScxGridLnkD7;dxPScxExtCommonD7;dxPScxVGridLnkD7;fo_d7;xtx_d7;Rave50CLX;Rave50VCL;pngimaged7;dxGDIPlusD7;UnRegDxPNG +Conditionals= +DebugSourceDirs= +UsePackages=0 +[Parameters] +RunParams=P:\test\DealerMap\xsd\kml21-simplified.xsd +HostApplication= +Launcher= +UseLauncher=0 +DebugCWD= +[Language] +ActiveLang= +ProjectLang= +RootDir=C:\Program Files\Borland\Delphi7\Bin\ +[Version Info] +IncludeVerInfo=0 +AutoIncBuild=0 +MajorVer=0 +MinorVer=0 +Release=0 +Build=0 +Debug=0 +PreRelease=0 +Special=0 +Private=0 +DLL=0 +Locale=1043 +CodePage=1252 +[Version Info Keys] +CompanyName= +FileDescription= +FileVersion=0.0.0.0 +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +Comments= +[Excluded Packages] +C:\Program Files\Borland\Indy\D7\dclIndy70.bpl=Internet Direct (Indy) for D7 Property and Component Editors diff --git a/X2XMLDataBinding.dproj b/X2XMLDataBinding.dproj new file mode 100644 index 0000000..99a9084 --- /dev/null +++ b/X2XMLDataBinding.dproj @@ -0,0 +1,81 @@ + + + {983dfcaf-23ca-48a0-a147-d96769428a71} + X2XMLDataBinding.dpr + Debug + AnyCPU + DCC32 + X2XMLDataBinding.exe + + + 7.0 + False + False + 0 + 3 + RELEASE + + + 7.0 + 3 + DEBUG + + + Delphi.Personality + + + + + False + True + False + + + False + False + 1 + 0 + 0 + 0 + False + False + False + False + False + 1043 + 1252 + + + + + 1.0.0.0 + + + + + + 1.0.0.0 + + + + X2XMLDataBinding.dpr + + + + + + + MainSource + + +
MainForm
+
+ + + + + + + +
+
\ No newline at end of file diff --git a/XSD/DataBindingHints.xsd b/XSD/DataBindingHints.xsd index c10aff9..997687c 100644 --- a/XSD/DataBindingHints.xsd +++ b/XSD/DataBindingHints.xsd @@ -1,5 +1,6 @@ - + + Contains hints and mappings for the data binding output @@ -51,7 +52,7 @@ - + @@ -60,6 +61,18 @@ + + + + + + + + + + + +