Type Hint handling record, alias, array ( WideString, AnsiString, UnicodeString handling ). Parsers and generators.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@772 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
inoussa
2009-04-07 16:28:22 +00:00
parent 8650ae4029
commit f267faed72
14 changed files with 330 additions and 85 deletions

View File

@ -3,7 +3,8 @@
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="library1"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wst="urn:wst_base"
targetNamespace="urn:wst-test">
<types>
@ -13,6 +14,7 @@
<xsd:element name="AliasString" type="xsd:string"/>
<xsd:element name="AliasInt" type="xsd:int"/>
<xsd:element name="AliasWideString" type="xsd:string" wst:TypeHint="WideString"/>
</xsd:schema>
</types>

View File

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:n="urn:wst-test"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wst="urn:wst_base"
targetNamespace="urn:wst-test">
<xsd:element name="AliasString" type="xsd:string"/>
<xsd:element name="AliasInt" type="xsd:int"/>
<xsd:element name="AliasWideString" type="xsd:string" wst:TypeHint="WideString"/>
</xsd:schema>

View File

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<schema xmlns:tns="urn:wst-test" xmlns:wst="urn:wst_base" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:wst-test">
<xsd:element name="AliasedType" type="xsd:string" wst:TypeHint="WideString"/>
</schema>

View File

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<schema xmlns:tns="urn:wst-test"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wst="urn:wst_base"
targetNamespace="urn:wst-test">
<xsd:complexType name="AliasedType">
<xsd:sequence>
<xsd:element name="item" type="xsd:string" wst:TypeHint="WideString" maxOccurs="unbounded" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="EmbeddedAliasedType">
<xsd:sequence>
<xsd:element name="item" type="xsd:string" wst:TypeHint="WideString" maxOccurs="unbounded" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</schema>

View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<schema xmlns:tns="type_hint_record_item"
xmlns:wst="urn:wst_base"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="type_hint_record_item">
<xsd:complexType name="TSampleRecord" wst:wst_record="true">
<xsd:sequence>
<xsd:element name="elementProp" type="xsd:string" wst:TypeHint="WideString"/>
</xsd:sequence>
<xsd:attribute name="elementAtt" type="xsd:string" wst:TypeHint="WideString"/>
</xsd:complexType>
</schema>

View File

@ -49,6 +49,10 @@ type
procedure class_sequence_open_type_any();
procedure class_sequence_open_type_any_attribute();
procedure class_sequence_open_type_any_any_attribute();
procedure type_alias_widestring();
procedure type_hint_array_item();
procedure type_hint_record_item();
end;
TTest_XsdGenerator = class(TTest_CustomXsdGenerator)
@ -853,6 +857,136 @@ begin
end;
end;
procedure TTest_CustomXsdGenerator.type_alias_widestring();
var
tr : TwstPasTreeContainer;
mdl : TPasModule;
aliasType : TPasAliasType;
g : IGenerator;
locDoc, locExistDoc : TXMLDocument;
arrayTyp : TPasArrayType;
begin
locDoc := nil;
locExistDoc := nil;
tr := TwstPasTreeContainer.Create();
try
CreateWstInterfaceSymbolTable(tr);
mdl := TPasModule(tr.CreateElement(TPasModule,'type_alias_widestring',tr.Package,visDefault,'',0));
tr.RegisterExternalAlias(mdl,'urn:wst-test');
tr.Package.Modules.Add(mdl);
mdl.InterfaceSection := TPasSection(tr.CreateElement(TPasSection,'',mdl,visDefault,'',0));
aliasType := TPasAliasType(tr.CreateElement(TPasAliasType,'AliasedType',mdl.InterfaceSection,visDefault,'',0));
aliasType.DestType := tr.FindElementNS('WideString',s_xs) as TPasType;
aliasType.DestType.AddRef();
mdl.InterfaceSection.Declarations.Add(aliasType);
mdl.InterfaceSection.Types.Add(aliasType);
locDoc := CreateDoc();
g := CreateGenerator(locDoc);
g.Execute(tr,mdl.Name);
//WriteXMLFile(locDoc,wstExpandLocalFileName('type_alias_widestring.xsd'));
locExistDoc := LoadXmlFromFilesList('type_alias_widestring.xsd');
Check(CompareNodes(locExistDoc.DocumentElement,locDoc.DocumentElement),'generated document differs from the existent one.');
finally
ReleaseDomNode(locExistDoc);
ReleaseDomNode(locDoc);
FreeAndNil(tr);
end;
end;
procedure TTest_CustomXsdGenerator.type_hint_array_item();
var
tr : TwstPasTreeContainer;
mdl : TPasModule;
aliasType : TPasArrayType;
g : IGenerator;
locDoc, locExistDoc : TXMLDocument;
arrayTyp : TPasArrayType;
begin
locDoc := nil;
locExistDoc := nil;
tr := TwstPasTreeContainer.Create();
try
CreateWstInterfaceSymbolTable(tr);
mdl := TPasModule(tr.CreateElement(TPasModule,'type_hint_array_item',tr.Package,visDefault,'',0));
tr.RegisterExternalAlias(mdl,'urn:wst-test');
tr.Package.Modules.Add(mdl);
mdl.InterfaceSection := TPasSection(tr.CreateElement(TPasSection,'',mdl,visDefault,'',0));
aliasType := tr.CreateArray('AliasedType',tr.FindElementNS('WideString',s_xs) as TPasType,'Item','Item',asScoped);
mdl.InterfaceSection.Declarations.Add(aliasType);
mdl.InterfaceSection.Types.Add(aliasType);
aliasType := tr.CreateArray('EmbeddedAliasedType',tr.FindElementNS('WideString',s_xs) as TPasType,'EmbeddedItem','EmbeddedItem',asScoped);
mdl.InterfaceSection.Declarations.Add(aliasType);
mdl.InterfaceSection.Types.Add(aliasType);
locDoc := CreateDoc();
g := CreateGenerator(locDoc);
g.Execute(tr,mdl.Name);
//WriteXMLFile(locDoc,wstExpandLocalFileName('type_hint_array_item.xsd'));
locExistDoc := LoadXmlFromFilesList('type_hint_array_item.xsd');
Check(CompareNodes(locExistDoc.DocumentElement,locDoc.DocumentElement),'generated document differs from the existent one.');
finally
ReleaseDomNode(locExistDoc);
ReleaseDomNode(locDoc);
FreeAndNil(tr);
end;
end;
procedure TTest_CustomXsdGenerator.type_hint_record_item();
var
tr : TwstPasTreeContainer;
mdl : TPasModule;
cltyp : TPasRecordType;
procedure AddProperty(
const AName,
ATypeName : string;
const AKind : TPropertyType
);
var
p : TPasVariable;
begin
p := TPasVariable(tr.CreateElement(TPasVariable,AName,cltyp,visDefault,'',0));
cltyp.Members.Add(p);
p.Name := AName;
p.VarType := tr.FindElement(ATypeName) as TPasType;
Check( (p.VarType <> nil), Format('Type not found : "%s".',[ATypeName]));
p.VarType.AddRef();
if ( AKind = ptAttribute ) then
tr.SetPropertyAsAttribute(p,True);
end;
var
g : IGenerator;
locDoc, locExistDoc : TXMLDocument;
begin
locDoc := nil;
locExistDoc := nil;
tr := TwstPasTreeContainer.Create();
try
CreateWstInterfaceSymbolTable(tr);
mdl := TPasModule(tr.CreateElement(TPasModule,'type_hint_record_item',tr.Package,visDefault,'',0));
tr.Package.Modules.Add(mdl);
mdl.InterfaceSection := TPasSection(tr.CreateElement(TPasSection,'',mdl,visDefault,'',0));
cltyp := TPasRecordType(tr.CreateElement(TPasRecordType,'TSampleRecord',mdl.InterfaceSection,visDefault,'',0));
mdl.InterfaceSection.Declarations.Add(cltyp);
mdl.InterfaceSection.Types.Add(cltyp);
AddProperty('elementProp','WideString',ptField);
AddProperty('elementAtt','WideString',ptAttribute);
locDoc := CreateDoc();
g := CreateGenerator(locDoc);
g.Execute(tr,mdl.Name);
WriteXMLFile(locDoc,wstExpandLocalFileName('type_hint_record_item.xsd'));
locExistDoc := LoadXmlFromFilesList('type_hint_record_item.xsd');
Check(CompareNodes(locExistDoc.DocumentElement,locDoc.DocumentElement),'generated document differs from the existent one.');
finally
ReleaseDomNode(locExistDoc);
ReleaseDomNode(locDoc);
FreeAndNil(tr);
end;
end;
function TTest_CustomXsdGenerator.LoadXmlFromFilesList(const AFileName: string): TXMLDocument;
begin
ReadXMLFile(Result,wstExpandLocalFileName(TestFilesPath + AFileName));

View File

@ -207,7 +207,7 @@ begin
RegisterFondamentalTypesHandler(handlerReg);
locDoc := CreateDoc();
GenerateWSDL(locRep,locDoc,typeReg,handlerReg);
WriteXML(locDoc,wstExpandLocalFileName('wsdl_gen_generate_array.wsdl'));
//WriteXML(locDoc,wstExpandLocalFileName('wsdl_gen_generate_array.wsdl'));
ReadXMLFile(locExistDoc,wstExpandLocalFileName(TestFilesPath + 'wsdl_gen_generate_array.wsdl'));
Check(CompareNodes(locExistDoc.DocumentElement,locDoc.DocumentElement),'generated document differs from the existent one.');
finally

View File

@ -220,6 +220,7 @@ const
x_enumSampleLIST : array[0..( x_enumSampleLIST_COUNT - 1 )] of string = ( 'esOne', 'esTwo', 'esThree', 'begin', 'finally', 'True', 'False' );
x_simpleTypeAliasString = 'AliasString';
x_simpleTypeAliasInt = 'AliasInt';
x_simpleTypeAliasWideString = 'AliasWideString';
x_simpleType = 'simpletype';
x_simpleTypeEmbedded = 'simpletype_embedded';
x_simpletypeNativeAlias = 'simpletypeNativeAlias';
@ -362,7 +363,7 @@ begin
CheckEquals(x_simpletypeNativeAlias,mdl.Name);
CheckEquals(x_targetNamespace,tr.GetExternalName(mdl));
ls := mdl.InterfaceSection.Declarations;
CheckEquals(2,ls.Count);
CheckEquals(3,ls.Count);
elt := tr.FindElement(x_simpleTypeAliasString);
CheckNotNull(elt,x_simpleTypeAliasString);
CheckEquals(x_simpleTypeAliasString,elt.Name);
@ -380,6 +381,16 @@ begin
aliasType := elt as TPasAliasType;
CheckNotNull(aliasType.DestType);
Check(tr.SameName(aliasType.DestType,'int'));
elt := tr.FindElement(x_simpleTypeAliasWideString);
CheckNotNull(elt,x_simpleTypeAliasWideString);
CheckEquals(x_simpleTypeAliasWideString,elt.Name);
CheckEquals(x_simpleTypeAliasWideString,tr.GetExternalName(elt));
CheckIs(elt,TPasAliasType);
aliasType := elt as TPasAliasType;
CheckNotNull(aliasType.DestType);
CheckIs(aliasType.DestType,TPasNativeSimpleType);
CheckEquals('WideString',aliasType.DestType.Name);
end;
type

View File

@ -714,7 +714,7 @@ begin
locStream := TMemoryStream.Create();
try
ser.SaveToStream(locStream);
locStream.SaveToFile(wstExpandLocalFileName('write_header_proxy_header_block.xml'));
//locStream.SaveToFile(wstExpandLocalFileName('write_header_proxy_header_block.xml'));
locStream.Position := 0;
ReadXMLFile(locDoc,locStream);
ReadXMLFile(locExistDoc,wstExpandLocalFileName(TestFilesPath + 'write_header_proxy_header_block.xml'));
@ -747,7 +747,7 @@ begin
locStream := TMemoryStream.Create();
try
ser.SaveToStream(locStream);
locStream.SaveToFile(wstExpandLocalFileName('write_header_proxy_header_block_name.xml'));
//locStream.SaveToFile(wstExpandLocalFileName('write_header_proxy_header_block_name.xml'));
locStream.Position := 0;
ReadXMLFile(locDoc,locStream);
ReadXMLFile(locExistDoc,wstExpandLocalFileName(TestFilesPath + 'write_header_proxy_header_block_name.xml'));