Files
lazarus-ccr/wst/trunk/server_binary_formatter.pas
inoussa 2090bf84b2 ws_helper parses ( and records in procedure Register_%service%_ServiceMetadata() )
- service/port for <soap:address>
  - binding/operation for "soapAction"
  
ws_helper : better parsing of "function" operations

ws_helper supports a new switch :
  -u MODE Generate the pascal translation of the WSDL input file
       MODE value may be U for used types or A for all types


Complexe types extending with simpleContent support in the runtime and ws_helper :
   sample WSDL type
  	<xs:complexType name="MeasureType">
  		<xs:simpleContent>
  			<xs:extension base="xs:decimal">
  				<xs:attribute name="UnitSystem" type="xs:token" use="optional">
  				</xs:attribute>
  				<xs:attribute name="ZeroPoint" type="string" use="optional">
  				</xs:attribute>
  			</xs:extension>
  		</xs:simpleContent>
  	</xs:complexType> 


embedded array support :
   sample WSDL type
      <xsd:complexType name="EmbeddeArraySample">
        <xsd:sequence>
          <xsd:element name="Name" type="xsd:string"/>
          <xsd:element name="Count" type="xsd:int"/>
          <xsd:element name="ArrayItem" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
      </xsd:complexType>

   sample instance of "EmbeddeArraySample"
      <example>
        <Name>WST NAME</Name>
        <Count>3</Count>
        <ArrayItem>Item 0</ArrayItem>
        <ArrayItem>Item 1</ArrayItem>
        <ArrayItem>Item 2</ArrayItem>
      </example>

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@139 8e941d3f-bd1b-0410-a28a-d453659cc2b4
2007-04-02 13:19:48 +00:00

138 lines
3.1 KiB
ObjectPascal

{
This file is part of the Web Service Toolkit
Copyright (c) 2006 by Inoussa OUEDRAOGO
This file is provide under modified LGPL licence
( the files COPYING.modifiedLGPL and COPYING.LGPL).
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
}
unit server_binary_formatter;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, TypInfo,
base_service_intf, server_service_intf,
base_binary_formatter;
const
sBINARY_CONTENT_TYPE = 'binary';
procedure Server_service_RegisterBinaryFormat();
implementation
Type
{ TBinaryFormatter }
TBinaryFormatter = class(TBaseBinaryFormatter,IFormatterBase,IFormatterResponse)
Private
FCallProcedureName : string;
FCallTarget : string;
Protected
procedure BeginCallResponse(Const AProcName,ATarget:string);
procedure EndCallResponse();
procedure BeginCallRead(ACallContext : ICallContext);
function GetCallProcedureName():String;
function GetCallTarget():String;
procedure BeginExceptionList(
const AErrorCode : string;
const AErrorMsg : string
);
procedure EndExceptionList();
End;
{ TBinaryFormatterFactory }
TBinaryFormatterFactory = class(TInterfacedObject,IItemFactory)
protected
function CreateInstance():IInterface;
End;
{ TBinaryFormatterFactory }
function TBinaryFormatterFactory.CreateInstance(): IInterface;
begin
Result := TBinaryFormatter.Create() as IFormatterResponse;
end;
{ TBinaryFormatter }
procedure TBinaryFormatter.BeginCallResponse(const AProcName, ATarget: string);
begin
BeginObject('Body',Nil);
BeginObject(ATarget,Nil);
BeginObject(AProcName + 'Response',Nil);
end;
procedure Print(const AMsg:string);
begin
WriteLn(AMsg);
End;
procedure TBinaryFormatter.EndCallResponse();
begin
EndScope();
EndScope();
EndScope();
//PrintObj(GetRootData(),0,@Print);
end;
procedure TBinaryFormatter.BeginCallRead(ACallContext : ICallContext);
Var
s : string;
begin
ClearStack();
PushStack(GetRootData(),stObject);
s := 'Body';
BeginObjectRead(s,nil);
FCallTarget := StackTop().GetByIndex(0)^.Name;
BeginObjectRead(FCallTarget,nil);
FCallProcedureName := StackTop().GetByIndex(0)^.Name;
BeginObjectRead(FCallProcedureName,nil);
end;
function TBinaryFormatter.GetCallProcedureName(): String;
begin
Result := FCallProcedureName;
end;
function TBinaryFormatter.GetCallTarget(): String;
begin
Result := FCallTarget;
end;
procedure TBinaryFormatter.BeginExceptionList(
const AErrorCode: string;
const AErrorMsg: string
);
begin
BeginObject('Body',Nil);
BeginObject('Fault',Nil);
Put('faultcode',TypeInfo(string),AErrorCode);
Put('faultstring',TypeInfo(string),AErrorMsg);
end;
procedure TBinaryFormatter.EndExceptionList();
begin
EndScope();
EndScope();
end;
procedure Server_service_RegisterBinaryFormat();
begin
GetFormatterRegistry().Register(sBINARY_CONTENT_TYPE,TBinaryFormatterFactory.Create() as IItemFactory);
end;
Initialization
end.