Runtime WSDL generation : object collection handling and test case.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@864 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
inoussa
2009-06-26 12:36:05 +00:00
parent 28da302bc6
commit 2ac2f77e12
4 changed files with 102 additions and 17 deletions

View File

@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<definitions name="runtime_generator"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="urn:sample-namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
targetNamespace="urn:sample-namespace">
<types>
<xsd:schema
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:wst="urn:wst_base"
targetNamespace="urn:sample-namespace">
<xsd:complexType name="TClass_A">
<xsd:sequence>
<xsd:element name="A_StringProp" type="xsd:string" maxOccurs="1" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TClass_A_Collection">
<xsd:sequence>
<xsd:element name="item" type="tns:TClass_A" maxOccurs="unbounded" minOccurs="0" wst:wst_collection="true"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</types>
</definitions>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<definitions name="runtime_generator" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:sample-namespace" xmlns:wst="urn:wst_base" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="urn:sample-namespace">
<definitions name="runtime_generator" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:sample-namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="urn:sample-namespace">
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:sample-namespace">
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:wst="urn:wst_base" targetNamespace="urn:sample-namespace">
<xsd:complexType name="TTestSmallRecord" wst:wst_record="true">
<xsd:sequence>
<xsd:element name="fieldSmallint" type="xsd:short" maxOccurs="1" minOccurs="0"/>

View File

@@ -80,6 +80,16 @@ type
property Password : string read FPassword write FPassword;
end;
TClass_A_Collection = class(TObjectCollectionRemotable)
private
function GetItem(AIndex: Integer): TClass_A;
public
class function GetItemClass():TBaseRemotableClass;override;
function Add(): TClass_A; {$IFDEF USE_INLINE}inline;{$ENDIF}
function AddAt(const APosition : Integer) : TClass_A; {$IFDEF USE_INLINE}inline;{$ENDIF}
property Item[AIndex:Integer] : TClass_A Read GetItem;Default;
end;
{ TTestWSDLGenerator }
TTestWSDLGenerator= class(TTestCase)
@@ -89,6 +99,7 @@ type
procedure generate_complex_type_derivation();
procedure generate_enum();
procedure generate_array();
procedure generate_collection();
procedure generate_record();
procedure generate_soap_headerblock();
end;
@@ -113,6 +124,28 @@ begin
end;
{$ENDIF WST_RECORD_RTTI}
{ TClass_A_Collection }
function TClass_A_Collection.GetItem(AIndex: Integer): TClass_A;
begin
Result := TClass_A(Inherited GetItem(AIndex));
end;
class function TClass_A_Collection.GetItemClass(): TBaseRemotableClass;
begin
Result:= TClass_A;
end;
function TClass_A_Collection.Add() : TClass_A;
begin
Result := TClass_A(inherited Add());
end;
function TClass_A_Collection.AddAt(const APosition : Integer) : TClass_A;
begin
Result := TClass_A(inherited AddAt(APosition));
end;
{ TTestWSDLGenerator }
function TTestWSDLGenerator.CreateRepository() : PServiceRepository;
@@ -228,6 +261,37 @@ begin
end;
end;
procedure TTestWSDLGenerator.generate_collection();
var
locRep : PServiceRepository;
locDoc, locExistDoc : TXMLDocument;
typeReg : TTypeRegistry;
handlerReg : IWsdlTypeHandlerRegistry;
begin
locExistDoc := nil;
typeReg := nil;
locDoc := nil;
locRep := CreateRepository();
try
typeReg := TTypeRegistry.Create();
RegisterStdTypes(typeReg);
typeReg.Register(sNAMESPACE_SAMPLE,TypeInfo(TClass_A));
typeReg.Register(sNAMESPACE_SAMPLE,TypeInfo(TClass_A_Collection));
handlerReg := CreateWsdlTypeHandlerRegistry(typeReg);
RegisterFondamentalTypesHandler(handlerReg);
locDoc := CreateDoc();
GenerateWSDL(locRep,locDoc,typeReg,handlerReg);
//WriteXML(locDoc,wstExpandLocalFileName('wsdl_gen_generate_collection.wsdl'));
ReadXMLFile(locExistDoc,wstExpandLocalFileName(TestFilesPath + 'wsdl_gen_generate_collection.wsdl'));
Check(CompareNodes(locExistDoc.DocumentElement,locDoc.DocumentElement),'generated document differs from the existent one.');
finally
typeReg.Free();
ReleaseDomNode(locExistDoc);
ReleaseDomNode(locDoc);
Dispose(locRep);
end;
end;
procedure TTestWSDLGenerator.generate_record();
var
locRep : PServiceRepository;