Added: support for multiple namespaces in the generated binding
This commit is contained in:
parent
23d6e7e18e
commit
8a5fa4af6d
@ -70,9 +70,10 @@ type
|
|||||||
procedure WriteValidate(AStream: TStreamHelper; AItem: TXMLDataBindingInterface; ASection: TDelphiXMLSection);
|
procedure WriteValidate(AStream: TStreamHelper; AItem: TXMLDataBindingInterface; ASection: TDelphiXMLSection);
|
||||||
|
|
||||||
function GetDelphiNodeType(AProperty: TXMLDataBindingProperty): TDelphiNodeType;
|
function GetDelphiNodeType(AProperty: TXMLDataBindingProperty): TDelphiNodeType;
|
||||||
function DataTypeConversion(const ADestination, ASource: String; ADataType: IXMLTypeDef; AAccessor: TDelphiAccessor; ANodeType: TDelphiNodeType; const ALinesBefore: String = ''): String;
|
function GetDelphiElementType(AProperty: TXMLDataBindingProperty): TDelphiElementType;
|
||||||
function XMLToNativeDataType(const ADestination, ASource: String; ADataType: IXMLTypeDef; ANodeType: TDelphiNodeType; const ALinesBefore: String = ''): String;
|
function DataTypeConversion(const ADestination, ASource: String; ADataType: IXMLTypeDef; AAccessor: TDelphiAccessor; ANodeType: TDelphiNodeType; const ATargetNamespace: string; const ALinesBefore: String = ''): String;
|
||||||
function NativeDataTypeToXML(const ADestination, ASource: String; ADataType: IXMLTypeDef; ANodeType: TDelphiNodeType; const ALinesBefore: String = ''): String;
|
function XMLToNativeDataType(const ADestination, ASource: String; ADataType: IXMLTypeDef; ANodeType: TDelphiNodeType; const ATargetNamespace: string; const ALinesBefore: String = ''): String;
|
||||||
|
function NativeDataTypeToXML(const ADestination, ASource: String; ADataType: IXMLTypeDef; ANodeType: TDelphiNodeType; const ATargetNamespace: string; const ALinesBefore: String = ''): String;
|
||||||
|
|
||||||
property ProcessedItems: TX2OIHash read FProcessedItems;
|
property ProcessedItems: TX2OIHash read FProcessedItems;
|
||||||
property UnitNames: TX2OSHash read FUnitNames;
|
property UnitNames: TX2OSHash read FUnitNames;
|
||||||
@ -417,6 +418,7 @@ begin
|
|||||||
hasItem := False;
|
hasItem := False;
|
||||||
nameSpace := '';
|
nameSpace := '';
|
||||||
|
|
||||||
|
// #ToDo1 -oMvR: 6-4-2012: bij de Hyundai XSD's wordt hiermee TargetNamespace incorrect de laatste schema namespace
|
||||||
for schemaIndex := 0 to Pred(ASchemaList.Count) do
|
for schemaIndex := 0 to Pred(ASchemaList.Count) do
|
||||||
begin
|
begin
|
||||||
schema := ASchemaList[schemaIndex];
|
schema := ASchemaList[schemaIndex];
|
||||||
@ -751,9 +753,17 @@ begin
|
|||||||
if ASection = dxsImplementation then
|
if ASection = dxsImplementation then
|
||||||
begin
|
begin
|
||||||
if propertyItem.PropertyType = ptItem then
|
if propertyItem.PropertyType = ptItem then
|
||||||
|
begin
|
||||||
|
if propertyItem.HasTargetNamespace then
|
||||||
|
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<ItemSourceName>:s'', %<ItemClass>:s, ''%<Namespace>:s'');',
|
||||||
|
['ItemSourceName', propertyItem.Name,
|
||||||
|
'ItemClass', GetDataTypeName(propertyItem, False),
|
||||||
|
'Namespace', propertyItem.TargetNamespace])
|
||||||
|
else
|
||||||
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<ItemSourceName>:s'', %<ItemClass>:s);',
|
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<ItemSourceName>:s'', %<ItemClass>:s);',
|
||||||
['ItemSourceName', propertyItem.Name,
|
['ItemSourceName', propertyItem.Name,
|
||||||
'ItemClass', GetDataTypeName(propertyItem, False)]);
|
'ItemClass', GetDataTypeName(propertyItem, False)]);
|
||||||
|
end;
|
||||||
|
|
||||||
AStream.WriteLnNamedFmt(' %<FieldName>:s := CreateCollection(%<CollectionClass>:s, %<ItemInterface>:s, ''%<ItemSourceName>:s'') as %<CollectionInterface>:s;',
|
AStream.WriteLnNamedFmt(' %<FieldName>:s := CreateCollection(%<CollectionClass>:s, %<ItemInterface>:s, ''%<ItemSourceName>:s'') as %<CollectionInterface>:s;',
|
||||||
['FieldName', PrefixField + propertyItem.TranslatedName,
|
['FieldName', PrefixField + propertyItem.TranslatedName,
|
||||||
@ -782,6 +792,13 @@ begin
|
|||||||
dxsImplementation:
|
dxsImplementation:
|
||||||
begin
|
begin
|
||||||
WritePrototype;
|
WritePrototype;
|
||||||
|
|
||||||
|
if propertyItem.HasTargetNamespace then
|
||||||
|
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<SourceName>:s'', TXML%<Name>:s, ''%<Namespace>:s'');',
|
||||||
|
['SourceName', propertyItem.Name,
|
||||||
|
'Name', itemProperty.Item.TranslatedName,
|
||||||
|
'Namespace', propertyItem.TargetNamespace])
|
||||||
|
else
|
||||||
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<SourceName>:s'', TXML%<Name>:s);',
|
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<SourceName>:s'', TXML%<Name>:s);',
|
||||||
['SourceName', propertyItem.Name,
|
['SourceName', propertyItem.Name,
|
||||||
'Name', itemProperty.Item.TranslatedName]);
|
'Name', itemProperty.Item.TranslatedName]);
|
||||||
@ -799,9 +816,16 @@ begin
|
|||||||
if ASection = dxsImplementation then
|
if ASection = dxsImplementation then
|
||||||
begin
|
begin
|
||||||
WritePrototype;
|
WritePrototype;
|
||||||
|
if AItem.CollectionItem.HasTargetNamespace then
|
||||||
|
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<SourceName>:s'', %<DataClass>:s, ''%<Namespace>:s'');',
|
||||||
|
['SourceName', AItem.CollectionItem.Name,
|
||||||
|
'DataClass', GetDataTypeName(AItem.CollectionItem, False),
|
||||||
|
'Namespace', AItem.CollectionItem.TargetNamespace])
|
||||||
|
else
|
||||||
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<SourceName>:s'', %<DataClass>:s);',
|
AStream.WriteLnNamedFmt(' RegisterChildNode(''%<SourceName>:s'', %<DataClass>:s);',
|
||||||
['SourceName', AItem.CollectionItem.Name,
|
['SourceName', AItem.CollectionItem.Name,
|
||||||
'DataClass', GetDataTypeName(AItem.CollectionItem, False)]);
|
'DataClass', GetDataTypeName(AItem.CollectionItem, False)]);
|
||||||
|
|
||||||
AStream.WriteLn;
|
AStream.WriteLn;
|
||||||
AStream.WriteLnFmt(' ItemTag := ''%s'';', [AItem.CollectionItem.Name]);
|
AStream.WriteLnFmt(' ItemTag := ''%s'';', [AItem.CollectionItem.Name]);
|
||||||
AStream.WriteLnFmt(' ItemInterface := %s;', [GetDataTypeName(AItem.CollectionItem, True)]);
|
AStream.WriteLnFmt(' ItemInterface := %s;', [GetDataTypeName(AItem.CollectionItem, True)]);
|
||||||
@ -962,9 +986,9 @@ begin
|
|||||||
sourceCode.Add('function TXML%<Name>:s.Get_%<ItemName>:s(Index: Integer): %<DataType>:s;');
|
sourceCode.Add('function TXML%<Name>:s.Get_%<ItemName>:s(Index: Integer): %<DataType>:s;');
|
||||||
|
|
||||||
if GetDataTypeMapping(typeDef, typeMapping) and (typeMapping.Conversion = tcString) then
|
if GetDataTypeMapping(typeDef, typeMapping) and (typeMapping.Conversion = tcString) then
|
||||||
sourceCode.Add(XMLToNativeDataType('Result', 'List[Index].Text', typeDef, dntCustom))
|
sourceCode.Add(XMLToNativeDataType('Result', 'List[Index].Text', typeDef, dntCustom, AItem.CollectionItem.TargetNamespace))
|
||||||
else
|
else
|
||||||
sourceCode.Add(XMLToNativeDataType('Result', 'List[Index].NodeValue', typeDef, dntCustom));
|
sourceCode.Add(XMLToNativeDataType('Result', 'List[Index].NodeValue', typeDef, dntCustom, AItem.CollectionItem.TargetNamespace));
|
||||||
|
|
||||||
sourceCode.AddLn;
|
sourceCode.AddLn;
|
||||||
|
|
||||||
@ -1181,16 +1205,16 @@ begin
|
|||||||
if AProperty.IsAttribute then
|
if AProperty.IsAttribute then
|
||||||
sourceCode.Add(PropertyImplMethodGetOptionalAttr)
|
sourceCode.Add(PropertyImplMethodGetOptionalAttr)
|
||||||
else
|
else
|
||||||
sourceCode.Add(PropertyImplMethodGetOptional);
|
sourceCode.Add(PropertyImplMethodGetOptional[GetDelphiElementType(AProperty)]);
|
||||||
|
|
||||||
if writeNil then
|
if writeNil then
|
||||||
sourceCode.Add(PropertyImplMethodGetNil);
|
sourceCode.Add(PropertyImplMethodGetNil[GetDelphiElementType(AProperty)]);
|
||||||
|
|
||||||
if writeTextProp then
|
if writeTextProp then
|
||||||
if AProperty.IsAttribute then
|
if AProperty.IsAttribute then
|
||||||
sourceCode.Add(PropertyImplMethodGetTextAttr)
|
sourceCode.Add(PropertyImplMethodGetTextAttr)
|
||||||
else
|
else
|
||||||
sourceCode.Add(PropertyImplMethodGetText);
|
sourceCode.Add(PropertyImplMethodGetText[GetDelphiElementType(AProperty)]);
|
||||||
|
|
||||||
sourceCode.Add('function TXML%<Name>:s.Get%<PropertyName>:s: %<DataType>:s;');
|
sourceCode.Add('function TXML%<Name>:s.Get%<PropertyName>:s: %<DataType>:s;');
|
||||||
|
|
||||||
@ -1205,7 +1229,8 @@ begin
|
|||||||
sourceCode.Add(XMLToNativeDataType('Result',
|
sourceCode.Add(XMLToNativeDataType('Result',
|
||||||
'%<PropertySourceName>:s',
|
'%<PropertySourceName>:s',
|
||||||
TXMLDataBindingSimpleProperty(AProperty).DataType,
|
TXMLDataBindingSimpleProperty(AProperty).DataType,
|
||||||
GetDelphiNodeType(AProperty)));
|
GetDelphiNodeType(AProperty),
|
||||||
|
AProperty.TargetNamespace));
|
||||||
|
|
||||||
ptItem:
|
ptItem:
|
||||||
begin
|
begin
|
||||||
@ -1222,7 +1247,12 @@ begin
|
|||||||
itInterface:
|
itInterface:
|
||||||
begin
|
begin
|
||||||
sourceCode.Add('begin');
|
sourceCode.Add('begin');
|
||||||
|
|
||||||
|
if AProperty.HasTargetNamespace then
|
||||||
|
sourceCode.Add(' Result := (ChildNodes.FindNode(''%<PropertySourceName>:s'', ''%<Namespace>:s'') as IXML%<PropertyItemName>:s);')
|
||||||
|
else
|
||||||
sourceCode.Add(' Result := (ChildNodes[''%<PropertySourceName>:s''] as IXML%<PropertyItemName>:s);');
|
sourceCode.Add(' Result := (ChildNodes[''%<PropertySourceName>:s''] as IXML%<PropertyItemName>:s);');
|
||||||
|
|
||||||
sourceCode.Add('end;');
|
sourceCode.Add('end;');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1246,13 +1276,13 @@ begin
|
|||||||
WriteNewLine;
|
WriteNewLine;
|
||||||
|
|
||||||
if writeNil then
|
if writeNil then
|
||||||
sourceCode.Add(PropertyImplMethodSetNil);
|
sourceCode.Add(PropertyImplMethodSetNil[GetDelphiElementType(AProperty)]);
|
||||||
|
|
||||||
if writeTextProp then
|
if writeTextProp then
|
||||||
if AProperty.IsAttribute then
|
if AProperty.IsAttribute then
|
||||||
sourceCode.Add(PropertyImplMethodSetTextAttr)
|
sourceCode.Add(PropertyImplMethodSetTextAttr)
|
||||||
else
|
else
|
||||||
sourceCode.Add(PropertyImplMethodSetText);
|
sourceCode.Add(PropertyImplMethodSetText[GetDelphiElementType(AProperty)]);
|
||||||
|
|
||||||
sourceCode.Add('procedure TXML%<Name>:s.Set%<PropertyName>:s(const Value: %<DataType>:s);');
|
sourceCode.Add('procedure TXML%<Name>:s.Set%<PropertyName>:s(const Value: %<DataType>:s);');
|
||||||
value := '%<PropertySourceName>:s';
|
value := '%<PropertySourceName>:s';
|
||||||
@ -1260,7 +1290,8 @@ begin
|
|||||||
if Assigned(propertyItem) and (propertyItem.ItemType = itEnumeration) then
|
if Assigned(propertyItem) and (propertyItem.ItemType = itEnumeration) then
|
||||||
begin
|
begin
|
||||||
sourceCode.Add(NativeDataTypeToXML(value, '%<PropertyItemName>:sValues[Value]', nil,
|
sourceCode.Add(NativeDataTypeToXML(value, '%<PropertyItemName>:sValues[Value]', nil,
|
||||||
GetDelphiNodeType(AProperty)));
|
GetDelphiNodeType(AProperty),
|
||||||
|
AProperty.TargetNamespace));
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
if AProperty.PropertyType <> ptSimple then
|
if AProperty.PropertyType <> ptSimple then
|
||||||
@ -1268,7 +1299,8 @@ begin
|
|||||||
|
|
||||||
sourceCode.Add(NativeDataTypeToXML(value, 'Value',
|
sourceCode.Add(NativeDataTypeToXML(value, 'Value',
|
||||||
TXMLDataBindingSimpleProperty(AProperty).DataType,
|
TXMLDataBindingSimpleProperty(AProperty).DataType,
|
||||||
GetDelphiNodeType(AProperty)));
|
GetDelphiNodeType(AProperty),
|
||||||
|
AProperty.TargetNamespace));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
sourceCode.AddLn;
|
sourceCode.AddLn;
|
||||||
@ -1288,7 +1320,8 @@ begin
|
|||||||
'PropertyName', AProperty.TranslatedName,
|
'PropertyName', AProperty.TranslatedName,
|
||||||
'PropertyItemName', propertyItemName,
|
'PropertyItemName', propertyItemName,
|
||||||
'DataType', dataTypeName,
|
'DataType', dataTypeName,
|
||||||
'FieldName', fieldName]));
|
'FieldName', fieldName,
|
||||||
|
'Namespace', AProperty.TargetNamespace]));
|
||||||
finally
|
finally
|
||||||
FreeAndNil(sourceCode);
|
FreeAndNil(sourceCode);
|
||||||
end;
|
end;
|
||||||
@ -1482,12 +1515,24 @@ begin
|
|||||||
Result := dntAttribute
|
Result := dntAttribute
|
||||||
else if AProperty.IsNodeValue then
|
else if AProperty.IsNodeValue then
|
||||||
Result := dntNodeValue
|
Result := dntNodeValue
|
||||||
|
else if AProperty.HasTargetNamespace then
|
||||||
|
Result := dntElementNS
|
||||||
else
|
else
|
||||||
Result := dntElement;
|
Result := dntElement;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TDelphiXMLDataBindingGenerator.DataTypeConversion(const ADestination, ASource: String; ADataType: IXMLTypeDef; AAccessor: TDelphiAccessor; ANodeType: TDelphiNodeType; const ALinesBefore: String = ''): String;
|
function TDelphiXMLDataBindingGenerator.GetDelphiElementType(AProperty: TXMLDataBindingProperty): TDelphiElementType;
|
||||||
|
begin
|
||||||
|
Result := GetDelphiNodeType(AProperty);
|
||||||
|
if Result <> dntElementNS then
|
||||||
|
Result := dntElement;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TDelphiXMLDataBindingGenerator.DataTypeConversion(const ADestination, ASource: String; ADataType: IXMLTypeDef;
|
||||||
|
AAccessor: TDelphiAccessor; ANodeType: TDelphiNodeType;
|
||||||
|
const ATargetNamespace: string; const ALinesBefore: String = ''): String;
|
||||||
var
|
var
|
||||||
typeMapping: TTypeMapping;
|
typeMapping: TTypeMapping;
|
||||||
conversion: String;
|
conversion: String;
|
||||||
@ -1513,23 +1558,29 @@ begin
|
|||||||
Add(conversion);
|
Add(conversion);
|
||||||
Add('end;');
|
Add('end;');
|
||||||
|
|
||||||
|
// #ToDo1 -oMvR: 6-4-2012: Namespace
|
||||||
Result := Trim(Format(['Destination', ADestination,
|
Result := Trim(Format(['Destination', ADestination,
|
||||||
'Source', ASource]));
|
'Source', ASource,
|
||||||
|
'Namespace', ATargetNamespace]));
|
||||||
finally
|
finally
|
||||||
Free;
|
Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TDelphiXMLDataBindingGenerator.XMLToNativeDataType(const ADestination, ASource: String; ADataType: IXMLTypeDef; ANodeType: TDelphiNodeType; const ALinesBefore: String): String;
|
function TDelphiXMLDataBindingGenerator.XMLToNativeDataType(const ADestination, ASource: String; ADataType: IXMLTypeDef;
|
||||||
|
ANodeType: TDelphiNodeType; const ATargetNamespace: string;
|
||||||
|
const ALinesBefore: String): String;
|
||||||
begin
|
begin
|
||||||
Result := DataTypeConversion(ADestination, ASource, ADataType, daGet, ANodeType, ALinesBefore);
|
Result := DataTypeConversion(ADestination, ASource, ADataType, daGet, ANodeType, ATargetNamespace, ALinesBefore);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TDelphiXMLDataBindingGenerator.NativeDataTypeToXML(const ADestination, ASource: String; ADataType: IXMLTypeDef; ANodeType: TDelphiNodeType; const ALinesBefore: String): String;
|
function TDelphiXMLDataBindingGenerator.NativeDataTypeToXML(const ADestination, ASource: String; ADataType: IXMLTypeDef;
|
||||||
|
ANodeType: TDelphiNodeType; const ATargetNamespace: string;
|
||||||
|
const ALinesBefore: String): String;
|
||||||
begin
|
begin
|
||||||
Result := DataTypeConversion(ADestination, ASource, ADataType, daSet, ANodeType, ALinesBefore);
|
Result := DataTypeConversion(ADestination, ASource, ADataType, daSet, ANodeType, ATargetNamespace, ALinesBefore);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
unit DelphiXMLDataBindingResources;
|
unit DelphiXMLDataBindingResources;
|
||||||
|
|
||||||
|
// #ToDo1 -oMvR: 6-4-2012: namespace support voor attributes
|
||||||
|
|
||||||
interface
|
interface
|
||||||
type
|
type
|
||||||
TDelphiXMLSection = (dxsForward, dxsInterface, dxsClass, dxsImplementation);
|
TDelphiXMLSection = (dxsForward, dxsInterface, dxsClass, dxsImplementation);
|
||||||
TDelphiXMLMember = (dxmPropertyGet, dxmPropertySet, dxmPropertyDeclaration);
|
TDelphiXMLMember = (dxmPropertyGet, dxmPropertySet, dxmPropertyDeclaration);
|
||||||
TDelphiAccessor = (daGet, daSet);
|
TDelphiAccessor = (daGet, daSet);
|
||||||
TDelphiNodeType = (dntElement, dntAttribute, dntNodeValue, dntCustom);
|
TDelphiNodeType = (dntElement, dntElementNS, dntAttribute, dntNodeValue, dntCustom);
|
||||||
|
TDelphiElementType = dntElement..dntElementNS;
|
||||||
|
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -111,11 +114,22 @@ const
|
|||||||
PropertyInterfaceText = ' property %<PropertyName>:sText: WideString read Get%<PropertyName>:sText write Set%<PropertyName>:sText;';
|
PropertyInterfaceText = ' property %<PropertyName>:sText: WideString read Get%<PropertyName>:sText write Set%<PropertyName>:sText;';
|
||||||
PropertyInterface = ' property %<PropertyName>:s: %<DataType>:s read Get%<PropertyName>:s write Set%<PropertyName>:s;';
|
PropertyInterface = ' property %<PropertyName>:s: %<DataType>:s read Get%<PropertyName>:s write Set%<PropertyName>:s;';
|
||||||
|
|
||||||
PropertyImplMethodGetOptional = 'function TXML%<Name>:s.GetHas%<PropertyName>:s: Boolean;' + CrLf +
|
PropertyImplMethodGetOptional: array[TDelphiElementType] of string =
|
||||||
|
(
|
||||||
|
{ dntElement }
|
||||||
|
'function TXML%<Name>:s.GetHas%<PropertyName>:s: Boolean;' + CrLf +
|
||||||
'begin' + CrLf +
|
'begin' + CrLf +
|
||||||
' Result := Assigned(ChildNodes.FindNode(''%<PropertySourceName>:s''));' + CrLf +
|
' Result := Assigned(ChildNodes.FindNode(''%<PropertySourceName>:s''));' + CrLf +
|
||||||
'end;' + CrLf +
|
'end;' + CrLf +
|
||||||
'' + CrLf;
|
'' + CrLf,
|
||||||
|
|
||||||
|
{ dntElementNS }
|
||||||
|
'function TXML%<Name>:s.GetHas%<PropertyName>:s: Boolean;' + CrLf +
|
||||||
|
'begin' + CrLf +
|
||||||
|
' Result := Assigned(ChildNodes.FindNode(''%<PropertySourceName>:s'', ''%<Namespace>:s''));' + CrLf +
|
||||||
|
'end;' + CrLf +
|
||||||
|
'' + CrLf
|
||||||
|
);
|
||||||
|
|
||||||
PropertyImplMethodGetOptionalAttr = 'function TXML%<Name>:s.GetHas%<PropertyName>:s: Boolean;' + CrLf +
|
PropertyImplMethodGetOptionalAttr = 'function TXML%<Name>:s.GetHas%<PropertyName>:s: Boolean;' + CrLf +
|
||||||
'begin' + CrLf +
|
'begin' + CrLf +
|
||||||
@ -123,23 +137,56 @@ const
|
|||||||
'end;' + CrLf +
|
'end;' + CrLf +
|
||||||
'' + CrLf;
|
'' + CrLf;
|
||||||
|
|
||||||
PropertyImplMethodGetNil = 'function TXML%<Name>:s.Get%<PropertyName>:sIsNil: Boolean;' + CrLf +
|
PropertyImplMethodGetNil: array[TDelphiElementType] of string =
|
||||||
|
(
|
||||||
|
{ dntElement }
|
||||||
|
'function TXML%<Name>:s.Get%<PropertyName>:sIsNil: Boolean;' + CrLf +
|
||||||
'begin' + CrLf +
|
'begin' + CrLf +
|
||||||
' Result := GetNodeIsNil(ChildNodes[''%<PropertySourceName>:s'']);' + CrLf +
|
' Result := GetNodeIsNil(ChildNodes[''%<PropertySourceName>:s'']);' + CrLf +
|
||||||
'end;' + CrLf +
|
'end;' + CrLf +
|
||||||
'' + CrLf;
|
'' + CrLf,
|
||||||
|
|
||||||
PropertyImplMethodSetNil = 'procedure TXML%<Name>:s.Set%<PropertyName>:sIsNil(const Value: Boolean);' + CrLf +
|
{ dntElementNS }
|
||||||
|
'function TXML%<Name>:s.Get%<PropertyName>:sIsNil: Boolean;' + CrLf +
|
||||||
|
'begin' + CrLf +
|
||||||
|
' Result := GetNodeIsNil(ChildNodes.FindNode(''%<PropertySourceName>:s'', ''%<Namespace>:s''));' + CrLf +
|
||||||
|
'end;' + CrLf +
|
||||||
|
'' + CrLf
|
||||||
|
);
|
||||||
|
|
||||||
|
PropertyImplMethodSetNil: array[TDelphiElementType] of string =
|
||||||
|
(
|
||||||
|
{ dntElement }
|
||||||
|
'procedure TXML%<Name>:s.Set%<PropertyName>:sIsNil(const Value: Boolean);' + CrLf +
|
||||||
'begin' + CrLf +
|
'begin' + CrLf +
|
||||||
' SetNodeIsNil(ChildNodes[''%<PropertySourceName>:s''], Value);' + CrLf +
|
' SetNodeIsNil(ChildNodes[''%<PropertySourceName>:s''], Value);' + CrLf +
|
||||||
'end;' + CrLf +
|
'end;' + CrLf +
|
||||||
'' + CrLf;
|
'' + CrLf,
|
||||||
|
|
||||||
PropertyImplMethodGetText = 'function TXML%<Name>:s.Get%<PropertyName>:sText: WideString;' + CrLf +
|
{ dntElementNS }
|
||||||
|
'procedure TXML%<Name>:s.Set%<PropertyName>:sIsNil(const Value: Boolean);' + CrLf +
|
||||||
|
'begin' + CrLf +
|
||||||
|
' SetNodeIsNil(ChildNodes.FindNode(''%<PropertySourceName>:s'', ''%<Namespace>:s''), Value);' + CrLf +
|
||||||
|
'end;' + CrLf +
|
||||||
|
'' + CrLf
|
||||||
|
);
|
||||||
|
|
||||||
|
PropertyImplMethodGetText: array[TDelphiElementType] of string =
|
||||||
|
(
|
||||||
|
{ dntElement }
|
||||||
|
'function TXML%<Name>:s.Get%<PropertyName>:sText: WideString;' + CrLf +
|
||||||
'begin' + CrLf +
|
'begin' + CrLf +
|
||||||
' Result := ChildNodes[''%<PropertySourceName>:s''].Text;' + CrLf +
|
' Result := ChildNodes[''%<PropertySourceName>:s''].Text;' + CrLf +
|
||||||
'end;' + CrLf +
|
'end;' + CrLf +
|
||||||
'' + CrLf;
|
'' + CrLf,
|
||||||
|
|
||||||
|
{ dntElement }
|
||||||
|
'function TXML%<Name>:s.Get%<PropertyName>:sText: WideString;' + CrLf +
|
||||||
|
'begin' + CrLf +
|
||||||
|
' Result := ChildNodes.FindNode(''%<PropertySourceName>:s'', ''%<Namespace>:s'').Text;' + CrLf +
|
||||||
|
'end;' + CrLf +
|
||||||
|
'' + CrLf
|
||||||
|
);
|
||||||
|
|
||||||
PropertyImplMethodGetTextAttr = 'function TXML%<Name>:s.Get%<PropertyName>:sText: WideString;' + CrLf +
|
PropertyImplMethodGetTextAttr = 'function TXML%<Name>:s.Get%<PropertyName>:sText: WideString;' + CrLf +
|
||||||
'begin' + CrLf +
|
'begin' + CrLf +
|
||||||
@ -147,11 +194,22 @@ const
|
|||||||
'end;' + CrLf +
|
'end;' + CrLf +
|
||||||
'' + CrLf;
|
'' + CrLf;
|
||||||
|
|
||||||
PropertyImplMethodSetText = 'procedure TXML%<Name>:s.Set%<PropertyName>:sText(const Value: WideString);' + CrLf +
|
PropertyImplMethodSetText: array[TDelphiElementType] of string =
|
||||||
|
(
|
||||||
|
{ dntElement }
|
||||||
|
'procedure TXML%<Name>:s.Set%<PropertyName>:sText(const Value: WideString);' + CrLf +
|
||||||
'begin' + CrLf +
|
'begin' + CrLf +
|
||||||
' ChildNodes[''%<PropertySourceName>:s''].NodeValue := Value;' + CrLf +
|
' ChildNodes[''%<PropertySourceName>:s''].NodeValue := Value;' + CrLf +
|
||||||
'end;' + CrLf +
|
'end;' + CrLf +
|
||||||
'' + CrLf;
|
'' + CrLf,
|
||||||
|
|
||||||
|
{ dntElementNS }
|
||||||
|
'procedure TXML%<Name>:s.Set%<PropertyName>:sText(const Value: WideString);' + CrLf +
|
||||||
|
'begin' + CrLf +
|
||||||
|
' ChildNodes.FindNode(''%<PropertySourceName>:s'', ''%<Namespace>:s'').NodeValue := Value;' + CrLf +
|
||||||
|
'end;' + CrLf +
|
||||||
|
'' + CrLf
|
||||||
|
);
|
||||||
|
|
||||||
PropertyImplMethodSetTextAttr = 'procedure TXML%<Name>:s.Set%<PropertyName>:sText(const Value: WideString);' + CrLf +
|
PropertyImplMethodSetTextAttr = 'procedure TXML%<Name>:s.Set%<PropertyName>:sText(const Value: WideString);' + CrLf +
|
||||||
'begin' + CrLf +
|
'begin' + CrLf +
|
||||||
@ -272,6 +330,7 @@ const
|
|||||||
{ daGet }
|
{ daGet }
|
||||||
(
|
(
|
||||||
{ dntElement } ' %<Destination>:s := ChildNodes[''%<Source>:s''].NodeValue;',
|
{ dntElement } ' %<Destination>:s := ChildNodes[''%<Source>:s''].NodeValue;',
|
||||||
|
{ dntElementNS } ' %<Destination>:s := ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').NodeValue;',
|
||||||
{ dntAttribute } ' %<Destination>:s := AttributeNodes[''%<Source>:s''].NodeValue;',
|
{ dntAttribute } ' %<Destination>:s := AttributeNodes[''%<Source>:s''].NodeValue;',
|
||||||
{ dntNodeValue } ' %<Destination>:s := GetNodeValue;',
|
{ dntNodeValue } ' %<Destination>:s := GetNodeValue;',
|
||||||
{ dntCustom } ' %<Destination>:s := %<Source>:s;'
|
{ dntCustom } ' %<Destination>:s := %<Source>:s;'
|
||||||
@ -279,6 +338,7 @@ const
|
|||||||
{ daSet }
|
{ daSet }
|
||||||
(
|
(
|
||||||
{ dntElement } ' ChildNodes[''%<Destination>:s''].NodeValue := %<Source>:s;',
|
{ dntElement } ' ChildNodes[''%<Destination>:s''].NodeValue := %<Source>:s;',
|
||||||
|
{ dntElementNS } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := %<Source>:s;',
|
||||||
{ dntAttribute } ' SetAttribute(''%<Destination>:s'', %<Source>:s);',
|
{ dntAttribute } ' SetAttribute(''%<Destination>:s'', %<Source>:s);',
|
||||||
{ dntNodeValue } ' SetNodeValue(%<Source>:s);',
|
{ dntNodeValue } ' SetNodeValue(%<Source>:s);',
|
||||||
{ dntCustom } ' %<Destination>:s := %<Source>:s;'
|
{ dntCustom } ' %<Destination>:s := %<Source>:s;'
|
||||||
@ -301,6 +361,17 @@ const
|
|||||||
{ tcString } ' %<Destination>:s := ChildNodes[''%<Source>:s''].Text;',
|
{ tcString } ' %<Destination>:s := ChildNodes[''%<Source>:s''].Text;',
|
||||||
{ tcBas64 } ' %<Destination>:s := Base64Decode(Trim(ChildNodes[''%<Source>:s''].Text));'
|
{ tcBas64 } ' %<Destination>:s := Base64Decode(Trim(ChildNodes[''%<Source>:s''].Text));'
|
||||||
),
|
),
|
||||||
|
{ dntElementNS }
|
||||||
|
(
|
||||||
|
{ tcNone } '',
|
||||||
|
{ tcBoolean } '',
|
||||||
|
{ tcFloat } ' %<Destination>:s := XMLToFloat(ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').NodeValue);',
|
||||||
|
{ tcDateTime } ' %<Destination>:s := XMLToDateTime(ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').NodeValue, xdtDateTime);',
|
||||||
|
{ tcDate } ' %<Destination>:s := XMLToDateTime(ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').NodeValue, xdtDate);',
|
||||||
|
{ tcTime } ' %<Destination>:s := XMLToDateTime(ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').NodeValue, xdtTime);',
|
||||||
|
{ tcString } ' %<Destination>:s := ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').Text;',
|
||||||
|
{ tcBas64 } ' %<Destination>:s := Base64Decode(Trim(ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').Text));'
|
||||||
|
),
|
||||||
{ dntAttribute }
|
{ dntAttribute }
|
||||||
(
|
(
|
||||||
{ tcNone } '',
|
{ tcNone } '',
|
||||||
@ -348,6 +419,17 @@ const
|
|||||||
{ tcString } '',
|
{ tcString } '',
|
||||||
{ tcBase64 } ' ChildNodes[''%<Destination>:s''].NodeValue := Base64Encode(%<Source>:s);'
|
{ tcBase64 } ' ChildNodes[''%<Destination>:s''].NodeValue := Base64Encode(%<Source>:s);'
|
||||||
),
|
),
|
||||||
|
{ dntElementNS }
|
||||||
|
(
|
||||||
|
{ tcNone } '',
|
||||||
|
{ tcBoolean } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := BoolToXML(%<Source>:s);',
|
||||||
|
{ tcFloat } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := FloatToXML(%<Source>:s);',
|
||||||
|
{ tcDateTime } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := DateTimeToXML(%<Source>:s, xdtDateTime);',
|
||||||
|
{ tcDate } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := DateTimeToXML(%<Source>:s, xdtDate);',
|
||||||
|
{ tcTime } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := DateTimeToXML(%<Source>:s, xdtTime);',
|
||||||
|
{ tcString } '',
|
||||||
|
{ tcBase64 } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := Base64Encode(%<Source>:s);'
|
||||||
|
),
|
||||||
{ dntAttribute }
|
{ dntAttribute }
|
||||||
(
|
(
|
||||||
{ tcNone } '',
|
{ tcNone } '',
|
||||||
|
@ -258,18 +258,21 @@ type
|
|||||||
|
|
||||||
TXMLDataBindingProperty = class(TXMLDataBindingItem)
|
TXMLDataBindingProperty = class(TXMLDataBindingItem)
|
||||||
private
|
private
|
||||||
|
FTargetNamespace: string;
|
||||||
FIsAttribute: Boolean;
|
FIsAttribute: Boolean;
|
||||||
FIsOptional: Boolean;
|
FIsOptional: Boolean;
|
||||||
FIsNillable: Boolean;
|
FIsNillable: Boolean;
|
||||||
FIsRepeating: Boolean;
|
FIsRepeating: Boolean;
|
||||||
FIsNodeValue: Boolean;
|
FIsNodeValue: Boolean;
|
||||||
FCollection: TXMLDataBindingInterface;
|
FCollection: TXMLDataBindingInterface;
|
||||||
|
function GetHasTargetNamespace: Boolean;
|
||||||
protected
|
protected
|
||||||
function GetIsReadOnly: Boolean; virtual; abstract;
|
function GetIsReadOnly: Boolean; virtual; abstract;
|
||||||
|
|
||||||
function GetItemType: TXMLDataBindingItemType; override;
|
function GetItemType: TXMLDataBindingItemType; override;
|
||||||
function GetPropertyType: TXMLDataBindingPropertyType; virtual; abstract;
|
function GetPropertyType: TXMLDataBindingPropertyType; virtual; abstract;
|
||||||
public
|
public
|
||||||
|
property TargetNamespace: string read FTargetNamespace write FTargetNamespace;
|
||||||
property IsAttribute: Boolean read FIsAttribute write FIsAttribute;
|
property IsAttribute: Boolean read FIsAttribute write FIsAttribute;
|
||||||
property IsOptional: Boolean read FIsOptional write FIsOptional;
|
property IsOptional: Boolean read FIsOptional write FIsOptional;
|
||||||
property IsNillable: Boolean read FIsNillable write FIsNillable;
|
property IsNillable: Boolean read FIsNillable write FIsNillable;
|
||||||
@ -279,6 +282,8 @@ type
|
|||||||
property PropertyType: TXMLDataBindingPropertyType read GetPropertyType;
|
property PropertyType: TXMLDataBindingPropertyType read GetPropertyType;
|
||||||
|
|
||||||
property Collection: TXMLDataBindingInterface read FCollection write FCollection;
|
property Collection: TXMLDataBindingInterface read FCollection write FCollection;
|
||||||
|
|
||||||
|
property HasTargetNamespace: Boolean read GetHasTargetNamespace;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -982,6 +987,7 @@ var
|
|||||||
actualElement: IXMLElementDef;
|
actualElement: IXMLElementDef;
|
||||||
propertyType: TXMLDataBindingItem;
|
propertyType: TXMLDataBindingItem;
|
||||||
propertyItem: TXMLDataBindingProperty;
|
propertyItem: TXMLDataBindingProperty;
|
||||||
|
namespace: string;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
propertyType := ProcessElement(ASchema, AElement);
|
propertyType := ProcessElement(ASchema, AElement);
|
||||||
@ -997,6 +1003,10 @@ begin
|
|||||||
AElement.Name,
|
AElement.Name,
|
||||||
AElement.DataType);
|
AElement.DataType);
|
||||||
|
|
||||||
|
namespace := AElement.SchemaDef.TargetNamespace;
|
||||||
|
if namespace <> Schemas[0].TargetNamespace then
|
||||||
|
propertyItem.TargetNamespace := namespace;
|
||||||
|
|
||||||
propertyItem.IsOptional := IsElementOptional(AElement) or
|
propertyItem.IsOptional := IsElementOptional(AElement) or
|
||||||
IsChoice(AElement);
|
IsChoice(AElement);
|
||||||
propertyItem.IsRepeating := IsElementRepeating(AElement);
|
propertyItem.IsRepeating := IsElementRepeating(AElement);
|
||||||
@ -1020,6 +1030,7 @@ procedure TXMLDataBindingGenerator.ProcessAttribute(ASchema: TXMLDataBindingSche
|
|||||||
var
|
var
|
||||||
propertyItem: TXMLDataBindingProperty;
|
propertyItem: TXMLDataBindingProperty;
|
||||||
propertyType: TXMLDataBindingItem;
|
propertyType: TXMLDataBindingItem;
|
||||||
|
namespace: string;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
propertyType := ProcessElement(ASchema, AAttribute);
|
propertyType := ProcessElement(ASchema, AAttribute);
|
||||||
@ -1033,6 +1044,10 @@ begin
|
|||||||
AAttribute.Name,
|
AAttribute.Name,
|
||||||
AAttribute.DataType);
|
AAttribute.DataType);
|
||||||
|
|
||||||
|
namespace := AAttribute.SchemaDef.TargetNamespace;
|
||||||
|
if namespace <> ASchema.TargetNamespace then
|
||||||
|
propertyItem.TargetNamespace := namespace;
|
||||||
|
|
||||||
propertyItem.IsOptional := (AAttribute.Use <> UseRequired);
|
propertyItem.IsOptional := (AAttribute.Use <> UseRequired);
|
||||||
propertyItem.IsAttribute := True;
|
propertyItem.IsAttribute := True;
|
||||||
|
|
||||||
@ -1891,6 +1906,12 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
{ TXMLDataBindingProperty }
|
{ TXMLDataBindingProperty }
|
||||||
|
function TXMLDataBindingProperty.GetHasTargetNamespace: Boolean;
|
||||||
|
begin
|
||||||
|
Result := (Length(TargetNamespace) > 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TXMLDataBindingProperty.GetItemType: TXMLDataBindingItemType;
|
function TXMLDataBindingProperty.GetItemType: TXMLDataBindingItemType;
|
||||||
begin
|
begin
|
||||||
Result := itProperty;
|
Result := itProperty;
|
||||||
@ -1910,6 +1931,7 @@ constructor TXMLDataBindingSimpleProperty.CreateFromAlias(AOwner: TXMLDataBindin
|
|||||||
begin
|
begin
|
||||||
Create(AOwner, AProperty.SchemaItem, AProperty.Name, ADataType);
|
Create(AOwner, AProperty.SchemaItem, AProperty.Name, ADataType);
|
||||||
|
|
||||||
|
// #ToDo1 -oMvR: 6-4-2012: iets met TargetNamespace??
|
||||||
IsAttribute := AProperty.IsAttribute;
|
IsAttribute := AProperty.IsAttribute;
|
||||||
IsOptional := AProperty.IsOptional;
|
IsOptional := AProperty.IsOptional;
|
||||||
IsNillable := AProperty.IsNillable;
|
IsNillable := AProperty.IsNillable;
|
||||||
|
Loading…
Reference in New Issue
Block a user