2006-08-26 00:35:42 +00:00
|
|
|
{
|
|
|
|
This unit is part of the Web Service Toolkit
|
|
|
|
Copyright (c) 2006 by Inoussa OUEDRAOGO
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
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. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
program ws_helper;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
uses
|
2006-11-12 13:31:22 +00:00
|
|
|
Classes, SysUtils, wst_resources_utils,
|
2006-08-26 00:35:42 +00:00
|
|
|
parserdefs, ws_parser, generator, parserutils, source_utils,
|
2007-03-23 23:22:35 +00:00
|
|
|
command_line_parser, metadata_generator, binary_streamer,
|
|
|
|
DOM, xmlread, wsdl2pas_imp;
|
2006-08-26 00:35:42 +00:00
|
|
|
|
|
|
|
resourcestring
|
2007-03-23 23:22:35 +00:00
|
|
|
sUSAGE = 'ws_helper [-u] [-p] [-b] [-i] [-oPATH] inputFilename' + sNEW_LINE +
|
|
|
|
' -u Generate the pascal translation of the WSDL input file ' + sNEW_LINE +
|
2006-08-26 00:35:42 +00:00
|
|
|
' -p Generate service proxy' + sNEW_LINE +
|
|
|
|
' -b Generate service binder' + sNEW_LINE +
|
|
|
|
' -i Generate service minimal implementation' + sNEW_LINE +
|
2007-03-23 23:22:35 +00:00
|
|
|
' -o PATH Relative output directory' + sNEW_LINE +
|
|
|
|
' -a PATH Absolute output directory' + sNEW_LINE;
|
2006-08-26 00:35:42 +00:00
|
|
|
sCOPYRIGHT = 'ws_helper, Web Service Toolkit 0.3 Copyright (c) 2006 by Inoussa OUEDRAOGO';
|
|
|
|
|
|
|
|
const
|
|
|
|
sWST_META = 'wst_meta';
|
|
|
|
|
2007-03-23 23:22:35 +00:00
|
|
|
type
|
|
|
|
TSourceFileType = ( sftPascal, sftWSDL );
|
|
|
|
|
2006-08-26 00:35:42 +00:00
|
|
|
Var
|
|
|
|
inFileName,outPath,errStr : string;
|
|
|
|
srcMngr : ISourceManager;
|
|
|
|
AppOptions : TComandLineOptions;
|
|
|
|
NextParam : Integer;
|
2007-03-23 23:22:35 +00:00
|
|
|
sourceType : TSourceFileType;
|
|
|
|
symtable : TSymbolTable;
|
2006-08-26 00:35:42 +00:00
|
|
|
|
|
|
|
function ProcessCmdLine():boolean;
|
|
|
|
begin
|
|
|
|
NextParam := ParseCmdLineOptions(AppOptions);
|
|
|
|
If ( NextParam <= Paramcount ) Then
|
|
|
|
inFileName := ParamStr(NextParam);
|
|
|
|
Result := FileExists(ExpandFileName(inFileName));
|
2007-03-23 23:22:35 +00:00
|
|
|
if AnsiSameText(ExtractFileExt(inFileName),'.PAS') or
|
|
|
|
AnsiSameText(ExtractFileExt(inFileName),'.PP')
|
|
|
|
then begin
|
|
|
|
sourceType := sftPascal;
|
|
|
|
end else if AnsiSameText(ExtractFileExt(inFileName),'.WSDL') then begin
|
|
|
|
sourceType := sftWSDL;
|
|
|
|
end;
|
2006-08-26 00:35:42 +00:00
|
|
|
If Result Then Begin
|
|
|
|
If ( AppOptions = [] ) Then
|
|
|
|
Include(AppOptions,cloProxy);
|
|
|
|
End Else
|
|
|
|
errStr := Format('File not Found : "%s"',[inFileName]);
|
2007-03-23 23:22:35 +00:00
|
|
|
if ( cloOutPutDirAbsolute in AppOptions ) then begin
|
|
|
|
outPath := Trim(GetOptionArg(cloOutPutDirAbsolute));
|
|
|
|
end else begin
|
|
|
|
outPath := ExtractFilePath(inFileName);
|
|
|
|
if ( cloOutPutDirRelative in AppOptions ) then begin
|
|
|
|
outPath := outPath + Trim(GetOptionArg(cloOutPutDirRelative));
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
outPath := IncludeTrailingPathDelimiter(outPath);
|
2006-08-26 00:35:42 +00:00
|
|
|
end;
|
|
|
|
|
2007-03-23 23:22:35 +00:00
|
|
|
function GenerateSymbolTable() : Boolean ;
|
|
|
|
|
|
|
|
procedure ParsePascalFile();
|
|
|
|
var
|
|
|
|
s : TFileStream;
|
|
|
|
p : TPascalParser;
|
|
|
|
begin
|
|
|
|
s := nil;
|
|
|
|
p := nil;
|
|
|
|
try
|
|
|
|
s := TFileStream.Create(inFileName,fmOpenRead);
|
|
|
|
p := TPascalParser.Create(s,symtable);
|
|
|
|
if not p.Parse() then
|
|
|
|
p.Error('"%s" at line %d',[p.ErrorMessage,p.SourceLine]);
|
|
|
|
finally
|
|
|
|
FreeAndNil(p);
|
|
|
|
FreeAndNil(s);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure ParseWsdlFile();
|
|
|
|
var
|
|
|
|
locDoc : TXMLDocument;
|
|
|
|
prsr : TWsdlParser;
|
|
|
|
begin
|
|
|
|
prsr := nil;
|
|
|
|
ReadXMLFile(locDoc,inFileName);
|
|
|
|
try
|
|
|
|
prsr := TWsdlParser.Create(locDoc,symtable);
|
|
|
|
prsr.Parse();
|
|
|
|
finally
|
|
|
|
FreeAndNil(prsr);
|
|
|
|
FreeAndNil(locDoc);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
WriteLn('Parsing the file : ', inFileName);
|
|
|
|
case sourceType of
|
|
|
|
sftPascal : ParsePascalFile();
|
|
|
|
sftWSDL : ParseWsdlFile();
|
|
|
|
end;
|
|
|
|
Result := True;
|
|
|
|
except
|
|
|
|
on e : Exception do begin
|
|
|
|
Result := False;
|
|
|
|
errStr := e.Message;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-08-26 00:35:42 +00:00
|
|
|
function ProcessFile():Boolean;
|
|
|
|
Var
|
|
|
|
mtdaFS: TMemoryStream;
|
|
|
|
g : TBaseGenerator;
|
|
|
|
mg : TMetadataGenerator;
|
|
|
|
rsrcStrm : TMemoryStream;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
rsrcStrm := nil;
|
|
|
|
mtdaFS := nil;
|
|
|
|
mg := nil;
|
|
|
|
g := Nil;
|
2007-03-23 23:22:35 +00:00
|
|
|
try
|
|
|
|
try
|
|
|
|
if ( cloInterface in AppOptions ) then begin
|
|
|
|
WriteLn('Interface file generation...');
|
|
|
|
g := TInftGenerator.Create(symtable,srcMngr);
|
|
|
|
g.Execute();
|
|
|
|
FreeAndNil(g);
|
|
|
|
end;
|
|
|
|
|
2006-08-26 00:35:42 +00:00
|
|
|
If ( cloProxy in AppOptions ) Then Begin
|
2007-03-23 23:22:35 +00:00
|
|
|
WriteLn('Proxy file generation...');
|
|
|
|
g := TProxyGenerator.Create(symtable,srcMngr);
|
2006-08-26 00:35:42 +00:00
|
|
|
g.Execute();
|
|
|
|
FreeAndNil(g);
|
|
|
|
End;
|
2007-03-23 23:22:35 +00:00
|
|
|
|
2006-08-26 00:35:42 +00:00
|
|
|
If ( cloBinder in AppOptions ) Then Begin
|
2007-03-23 23:22:35 +00:00
|
|
|
WriteLn('Binder file generation...');
|
|
|
|
g := TBinderGenerator.Create(symtable,srcMngr);
|
2006-08-26 00:35:42 +00:00
|
|
|
g.Execute();
|
|
|
|
FreeAndNil(g);
|
|
|
|
End;
|
|
|
|
|
|
|
|
If ( cloImp in AppOptions ) Then Begin
|
2007-03-23 23:22:35 +00:00
|
|
|
WriteLn('Implementation file generation...');
|
|
|
|
g := TImplementationGenerator.Create(symtable,srcMngr);
|
2006-08-26 00:35:42 +00:00
|
|
|
g.Execute();
|
|
|
|
FreeAndNil(g);
|
|
|
|
End;
|
|
|
|
|
|
|
|
if ( [cloBinder,cloProxy]*AppOptions <> [] ) then begin
|
2007-03-23 23:22:35 +00:00
|
|
|
WriteLn('Metadata file generation...');
|
2006-08-26 00:35:42 +00:00
|
|
|
mtdaFS := TMemoryStream.Create();
|
2007-03-23 23:22:35 +00:00
|
|
|
mg := TMetadataGenerator.Create(symtable,CreateBinaryWriter(mtdaFS));
|
2006-08-26 00:35:42 +00:00
|
|
|
mg.Execute();
|
|
|
|
mtdaFS.SaveToFile(ChangeFileExt(inFileName,'.' + sWST_META));
|
|
|
|
rsrcStrm := TMemoryStream.Create();
|
|
|
|
mtdaFS.Position := 0;
|
2007-03-23 23:22:35 +00:00
|
|
|
BinToWstRessource(UpperCase(symtable.Name),mtdaFS,rsrcStrm);
|
2006-11-12 13:31:22 +00:00
|
|
|
rsrcStrm.SaveToFile(outPath + ChangeFileExt(ExtractFileName(inFileName),'.' + sWST_EXTENSION));
|
2006-08-26 00:35:42 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
Result := True;
|
2007-03-23 23:22:35 +00:00
|
|
|
except
|
|
|
|
on E : Exception do begin
|
2006-08-26 00:35:42 +00:00
|
|
|
Result := False;
|
2007-03-23 23:22:35 +00:00
|
|
|
errStr := E.Message;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
2006-08-26 00:35:42 +00:00
|
|
|
rsrcStrm.Free();
|
|
|
|
mg.Free();;
|
|
|
|
mtdaFS.Free();;
|
|
|
|
g.Free();
|
2007-03-23 23:22:35 +00:00
|
|
|
end;
|
2006-08-26 00:35:42 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
2007-03-23 23:22:35 +00:00
|
|
|
symtable := nil;
|
|
|
|
try
|
|
|
|
try
|
|
|
|
Writeln(sCOPYRIGHT);
|
|
|
|
If ( ParamCount = 0 ) Then Begin
|
|
|
|
WriteLn(sUSAGE);
|
|
|
|
Exit;
|
|
|
|
End;
|
|
|
|
|
|
|
|
if not ProcessCmdLine() then begin
|
|
|
|
WriteLn(errStr);
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
symtable := TSymbolTable.Create(ChangeFileExt(ExtractFileName(inFileName),''));
|
|
|
|
srcMngr := CreateSourceManager();
|
|
|
|
|
|
|
|
if not GenerateSymbolTable() then begin
|
|
|
|
WriteLn(errStr);
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
If Not ProcessFile() Then Begin
|
|
|
|
WriteLn(errStr);
|
|
|
|
Exit;
|
|
|
|
End;
|
|
|
|
|
|
|
|
srcMngr.SaveToFile(outPath);
|
|
|
|
WriteLn(Format('File "%s" parsed succesfully.',[inFileName]));
|
|
|
|
except
|
|
|
|
on e:exception Do
|
|
|
|
Writeln('Exception : ' + e.Message)
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FreeAndNil(symtable);
|
2006-08-26 00:35:42 +00:00
|
|
|
end;
|
|
|
|
end.
|