2007-07-07 20:56:01 +00:00
|
|
|
unit wstimportdlg;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
|
|
|
ExtCtrls, Buttons, ActnList, logger_intf;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
TGenOption = (
|
2009-07-09 18:07:33 +00:00
|
|
|
xgoInterface, xgoInterfaceALL,
|
|
|
|
xgoProxy, xgoImp, xgoBinder,
|
|
|
|
xgoWrappedParameter, xgoDocAsComments, xgoGenerateObjectCollection
|
2007-07-07 20:56:01 +00:00
|
|
|
);
|
|
|
|
TGenOptions = set of TGenOption;
|
|
|
|
|
|
|
|
TOnParserMessage = procedure (const AMsgType : TMessageType; const AMsg : string) of object;
|
|
|
|
|
|
|
|
{ TformImport }
|
|
|
|
|
|
|
|
TformImport = class(TForm)
|
|
|
|
actOpenDir: TAction;
|
|
|
|
actOpenFile: TAction;
|
|
|
|
actOK: TAction;
|
|
|
|
AL: TActionList;
|
|
|
|
Button1: TButton;
|
|
|
|
Button2: TButton;
|
|
|
|
Button3: TButton;
|
|
|
|
Button4: TButton;
|
2009-07-09 18:07:33 +00:00
|
|
|
edtGenCollection : TCheckBox;
|
2008-08-18 18:19:00 +00:00
|
|
|
edtDocAsComments : TCheckBox;
|
2007-07-07 20:56:01 +00:00
|
|
|
edtAddToProject : TCheckBox;
|
|
|
|
edtOptionIntfALL: TCheckBox;
|
|
|
|
edtOptionIntf: TCheckBox;
|
|
|
|
edtOptionProxy: TCheckBox;
|
|
|
|
edtOptionBinder: TCheckBox;
|
|
|
|
edtOptionImp: TCheckBox;
|
|
|
|
edtInputFile: TEdit;
|
|
|
|
edtOutputDir: TEdit;
|
2008-07-03 16:15:03 +00:00
|
|
|
edtOptionWrappedParams : TCheckBox;
|
2007-07-07 20:56:01 +00:00
|
|
|
GroupBox1: TGroupBox;
|
|
|
|
GroupBox2: TGroupBox;
|
|
|
|
GroupBox3: TGroupBox;
|
|
|
|
Label1: TLabel;
|
|
|
|
Label2: TLabel;
|
|
|
|
mmoLog: TMemo;
|
|
|
|
OD: TOpenDialog;
|
|
|
|
Panel1: TPanel;
|
|
|
|
Panel2: TPanel;
|
|
|
|
SDD: TSelectDirectoryDialog;
|
|
|
|
procedure actOKExecute(Sender: TObject);
|
|
|
|
procedure actOKUpdate(Sender: TObject);
|
|
|
|
procedure actOpenDirExecute(Sender: TObject);
|
|
|
|
procedure actOpenFileExecute(Sender: TObject);
|
|
|
|
procedure edtOptionIntfALLClick(Sender: TObject);
|
|
|
|
procedure edtOptionIntfClick(Sender: TObject);
|
|
|
|
private
|
|
|
|
FStatusMessageTag : Integer;
|
|
|
|
procedure ShowStatusMessage(const AMsgType : TMessageType;const AMsg : string);
|
|
|
|
public
|
|
|
|
function GetOptions() : TGenOptions;
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
formImport: TformImport;
|
|
|
|
|
|
|
|
implementation
|
2014-06-16 19:01:27 +00:00
|
|
|
|
|
|
|
{$R *.lfm}
|
|
|
|
|
2014-05-07 12:55:34 +00:00
|
|
|
uses DOM, XMLRead, wst_fpc_xml, pastree, pascal_parser_intf, wsdl_parser, source_utils,
|
2007-07-07 20:56:01 +00:00
|
|
|
generator, metadata_generator, binary_streamer, wst_resources_utils
|
2014-05-07 12:55:34 +00:00
|
|
|
{$IFDEF WST_IDE},LazIDEIntf{$ENDIF},locators,xsd_parser;
|
2007-07-07 20:56:01 +00:00
|
|
|
|
|
|
|
type
|
2009-07-09 18:07:33 +00:00
|
|
|
TSourceType = xgoInterface .. xgoBinder;
|
2007-07-07 20:56:01 +00:00
|
|
|
TSourceTypes = set of TSourceType;
|
|
|
|
|
|
|
|
function ParseWsdlFile(
|
|
|
|
const AFileName : string;
|
|
|
|
const ANotifier : TOnParserMessage
|
|
|
|
):TwstPasTreeContainer;
|
|
|
|
var
|
|
|
|
locDoc : TXMLDocument;
|
2008-06-06 15:11:41 +00:00
|
|
|
prsr : IParser;
|
2007-07-07 20:56:01 +00:00
|
|
|
symName : string;
|
2014-05-07 12:55:34 +00:00
|
|
|
prsrCtx : IParserContext;
|
2007-07-07 20:56:01 +00:00
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
if FileExists(AFileName) then begin
|
|
|
|
symName := ChangeFileExt(ExtractFileName(AFileName),'');
|
|
|
|
if ( symName[Length(symName)] = '.' ) then begin
|
|
|
|
Delete(symName,Length(symName),1);
|
|
|
|
end;
|
2014-05-07 12:55:34 +00:00
|
|
|
locDoc := ReadXMLFile(AFileName);
|
2007-07-07 20:56:01 +00:00
|
|
|
try
|
|
|
|
Result := TwstPasTreeContainer.Create();
|
|
|
|
try
|
2008-06-06 15:11:41 +00:00
|
|
|
prsr := TWsdlParser.Create(locDoc,Result,ANotifier);
|
2014-05-07 12:55:34 +00:00
|
|
|
prsrCtx := prsr as IParserContext;
|
|
|
|
prsrCtx.SetDocumentLocator(TFileDocumentLocator.Create(ExtractFilePath(ExpandFileName(AFileName))));
|
2008-06-06 15:11:41 +00:00
|
|
|
prsr.Execute(pmAllTypes,symName);
|
2007-07-07 20:56:01 +00:00
|
|
|
except
|
|
|
|
FreeAndNil(Result);
|
|
|
|
raise;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FreeAndNil(locDoc);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
type TOutputType = ( otMemory, otFileSystem );
|
|
|
|
function GenerateSource(
|
|
|
|
ASymbolTable : TwstPasTreeContainer;
|
|
|
|
AOptions : TSourceTypes;
|
|
|
|
const AOutputType : TOutputType;
|
|
|
|
const AOutPath : string;
|
2008-07-03 16:15:03 +00:00
|
|
|
const ANotifier : TOnParserMessage;
|
2009-07-09 18:07:33 +00:00
|
|
|
const AGenOptions : TGenOptions
|
2007-07-07 20:56:01 +00:00
|
|
|
) : ISourceManager;
|
|
|
|
|
|
|
|
procedure Notify(const AMsg : string);
|
|
|
|
begin
|
|
|
|
if Assigned(ANotifier) then begin
|
|
|
|
ANotifier(mtInfo, AMsg);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
mtdaFS: TMemoryStream;
|
|
|
|
g : TBaseGenerator;
|
|
|
|
mg : TMetadataGenerator;
|
|
|
|
rsrcStrm : TMemoryStream;
|
2008-07-03 16:15:03 +00:00
|
|
|
wrappedParams : Boolean;
|
2007-07-07 20:56:01 +00:00
|
|
|
begin
|
2009-07-09 18:07:33 +00:00
|
|
|
wrappedParams := ( xgoWrappedParameter in AGenOptions );
|
2007-07-07 20:56:01 +00:00
|
|
|
Result := CreateSourceManager();
|
|
|
|
rsrcStrm := nil;
|
|
|
|
mtdaFS := nil;
|
|
|
|
mg := nil;
|
|
|
|
g := Nil;
|
|
|
|
try
|
|
|
|
|
2009-07-09 18:07:33 +00:00
|
|
|
if ( ( [xgoInterface,xgoInterfaceALL] * AOptions ) <> [] ) then begin
|
2007-07-07 20:56:01 +00:00
|
|
|
Notify('Interface file generation...');
|
|
|
|
g := TInftGenerator.Create(ASymbolTable,Result);
|
2008-07-03 16:15:03 +00:00
|
|
|
if wrappedParams then
|
|
|
|
g.Options := g.Options + [goDocumentWrappedParameter];
|
2009-07-09 18:07:33 +00:00
|
|
|
if ( xgoDocAsComments in AGenOptions ) then
|
2008-08-18 18:19:00 +00:00
|
|
|
g.Options := g.Options + [goGenerateDocAsComments];
|
2009-07-09 18:07:33 +00:00
|
|
|
if ( xgoGenerateObjectCollection in AGenOptions ) then
|
|
|
|
g.Options := g.Options + [goGenerateObjectCollection];
|
2007-07-07 20:56:01 +00:00
|
|
|
g.Execute();
|
|
|
|
FreeAndNil(g);
|
|
|
|
end;
|
|
|
|
|
2009-07-09 18:07:33 +00:00
|
|
|
if ( xgoProxy in AOptions ) then begin
|
2007-07-07 20:56:01 +00:00
|
|
|
Notify('Proxy file generation...');
|
|
|
|
g := TProxyGenerator.Create(ASymbolTable,Result);
|
2008-07-03 16:15:03 +00:00
|
|
|
if wrappedParams then
|
|
|
|
g.Options := g.Options + [goDocumentWrappedParameter];
|
2007-07-07 20:56:01 +00:00
|
|
|
g.Execute();
|
|
|
|
FreeAndNil(g);
|
|
|
|
end;
|
|
|
|
|
2009-07-09 18:07:33 +00:00
|
|
|
if ( xgoBinder in AOptions ) then begin
|
2007-07-07 20:56:01 +00:00
|
|
|
Notify('Binder file generation...');
|
|
|
|
g := TBinderGenerator.Create(ASymbolTable,Result);
|
2008-07-03 16:15:03 +00:00
|
|
|
if wrappedParams then
|
|
|
|
g.Options := g.Options + [goDocumentWrappedParameter];
|
2007-07-07 20:56:01 +00:00
|
|
|
g.Execute();
|
|
|
|
FreeAndNil(g);
|
|
|
|
end;
|
|
|
|
|
2009-07-09 18:07:33 +00:00
|
|
|
if ( xgoImp in AOptions ) then begin
|
2007-07-07 20:56:01 +00:00
|
|
|
Notify('Implementation file generation...');
|
|
|
|
g := TImplementationGenerator.Create(ASymbolTable,Result);
|
|
|
|
g.Execute();
|
|
|
|
FreeAndNil(g);
|
|
|
|
end;
|
|
|
|
|
2009-07-09 18:07:33 +00:00
|
|
|
if ( AOutputType = otFileSystem ) and ( [xgoBinder,xgoProxy]*AOptions <> [] ) then begin
|
2007-07-07 20:56:01 +00:00
|
|
|
Notify('Metadata file generation...');
|
|
|
|
mtdaFS := TMemoryStream.Create();
|
|
|
|
mg := TMetadataGenerator.Create(ASymbolTable,CreateBinaryWriter(mtdaFS));
|
|
|
|
mg.Execute();
|
|
|
|
rsrcStrm := TMemoryStream.Create();
|
|
|
|
mtdaFS.Position := 0;
|
|
|
|
BinToWstRessource(UpperCase(ASymbolTable.CurrentModule.Name),mtdaFS,rsrcStrm);
|
|
|
|
rsrcStrm.SaveToFile(AOutPath + Format('%s.%s',[ASymbolTable.CurrentModule.Name,sWST_EXTENSION]));
|
|
|
|
end;
|
|
|
|
|
|
|
|
if ( AOutputType = otFileSystem ) then begin
|
|
|
|
Result.SaveToFile(AOutPath);
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
rsrcStrm.Free();
|
|
|
|
mg.Free();;
|
|
|
|
mtdaFS.Free();;
|
|
|
|
g.Free();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TformImport }
|
|
|
|
|
|
|
|
procedure TformImport.actOpenFileExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if OD.Execute() then begin
|
|
|
|
edtInputFile.Text := OD.FileName;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TformImport.edtOptionIntfALLClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if edtOptionIntfALL.Checked and ( not edtOptionIntf.Checked ) then
|
|
|
|
edtOptionIntf.Checked := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TformImport.edtOptionIntfClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if ( not edtOptionIntf.Checked ) and edtOptionIntfALL.Checked then
|
|
|
|
edtOptionIntfALL.Checked := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TformImport.ShowStatusMessage(const AMsgType: TMessageType;const AMsg: string);
|
|
|
|
begin
|
|
|
|
mmoLog.Lines.Add(Format('%s : %s',[MessageTypeNames[AMsgType],AMsg]));
|
|
|
|
Inc(FStatusMessageTag);
|
|
|
|
if ( (FStatusMessageTag) > 23 ) then begin
|
|
|
|
FStatusMessageTag := 0;
|
|
|
|
Application.ProcessMessages();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TformImport.GetOptions(): TGenOptions;
|
|
|
|
begin
|
|
|
|
Result := [];
|
|
|
|
if edtOptionIntf.Checked then begin
|
2009-07-09 18:07:33 +00:00
|
|
|
Result := Result + [xgoInterface];
|
2007-07-07 20:56:01 +00:00
|
|
|
if edtOptionIntfALL.Checked then begin
|
2009-07-09 18:07:33 +00:00
|
|
|
Result := Result + [xgoInterfaceALL];
|
2007-07-07 20:56:01 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if edtOptionProxy.Checked then
|
2009-07-09 18:07:33 +00:00
|
|
|
Include(Result,xgoProxy);
|
2007-07-07 20:56:01 +00:00
|
|
|
if edtOptionBinder.Checked then
|
2009-07-09 18:07:33 +00:00
|
|
|
Include(Result,xgoBinder);
|
2007-07-07 20:56:01 +00:00
|
|
|
if edtOptionImp.Checked then
|
2009-07-09 18:07:33 +00:00
|
|
|
Include(Result,xgoImp);
|
2008-07-03 16:15:03 +00:00
|
|
|
if edtOptionWrappedParams.Checked then
|
2009-07-09 18:07:33 +00:00
|
|
|
Include(Result,xgoWrappedParameter);
|
2008-08-18 18:19:00 +00:00
|
|
|
if edtDocAsComments.Checked then
|
2009-07-09 18:07:33 +00:00
|
|
|
Include(Result,xgoDocAsComments);
|
|
|
|
if edtGenCollection.Checked then
|
|
|
|
Include(Result,xgoGenerateObjectCollection);
|
2007-07-07 20:56:01 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TformImport.actOpenDirExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if SDD.Execute() then begin
|
|
|
|
if not DirectoryExists(SDD.FileName) then
|
|
|
|
ForceDirectories(SDD.FileName);
|
|
|
|
edtOutputDir.Text := SDD.FileName;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TformImport.actOKUpdate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
TAction(Sender).Enabled := FileExists(edtInputFile.Text) and
|
|
|
|
DirectoryExists(edtOutputDir.Text) and
|
2009-07-09 18:07:33 +00:00
|
|
|
( ( GetOptions() - [xgoWrappedParameter,xgoDocAsComments] ) <> [] );
|
2007-07-07 20:56:01 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TformImport.actOKExecute(Sender: TObject);
|
|
|
|
var
|
|
|
|
tree : TwstPasTreeContainer;
|
|
|
|
oldCursor : TCursor;
|
|
|
|
srcMgnr : ISourceManager;
|
|
|
|
i : Integer;
|
2008-07-03 16:15:03 +00:00
|
|
|
genOptions : TGenOptions;
|
|
|
|
fileSet : TSourceTypes;
|
2007-07-07 20:56:01 +00:00
|
|
|
{$IFDEF WST_IDE}
|
|
|
|
j, c : Integer;
|
|
|
|
srcItm : ISourceStream;
|
|
|
|
trueOpenFlags, openFlags : TOpenFlags;
|
|
|
|
destPath : string;
|
|
|
|
{$ENDIF}
|
|
|
|
begin
|
|
|
|
oldCursor := Screen.Cursor;
|
|
|
|
Screen.Cursor := crHourGlass;
|
|
|
|
try
|
|
|
|
tree := ParseWsdlFile(edtInputFile.Text,@ShowStatusMessage);
|
|
|
|
try
|
2008-07-03 16:15:03 +00:00
|
|
|
genOptions := GetOptions();
|
2009-07-09 18:07:33 +00:00
|
|
|
fileSet := genOptions - [xgoWrappedParameter,xgoDocAsComments];
|
2008-08-18 18:19:00 +00:00
|
|
|
srcMgnr := GenerateSource(
|
|
|
|
tree,fileSet,otFileSystem,IncludeTrailingPathDelimiter(edtOutputDir.Text),
|
|
|
|
@ShowStatusMessage,
|
2009-07-09 18:07:33 +00:00
|
|
|
genOptions
|
2008-08-18 18:19:00 +00:00
|
|
|
);
|
2007-07-07 20:56:01 +00:00
|
|
|
ShowStatusMessage(mtInfo,'');
|
|
|
|
{$IFDEF WST_IDE}
|
2014-05-07 12:55:34 +00:00
|
|
|
{openFlags := [ofRevert];
|
2007-07-07 20:56:01 +00:00
|
|
|
if edtAddToProject.Checked then begin
|
|
|
|
Include(openFlags,ofAddToProject);
|
|
|
|
end;
|
|
|
|
destPath := IncludeTrailingPathDelimiter(edtOutputDir.Text);
|
|
|
|
c := srcMgnr.GetCount();
|
|
|
|
for i := 0 to Pred(c) do begin
|
|
|
|
srcItm := srcMgnr.GetItem(i);
|
|
|
|
trueOpenFlags := openFlags;
|
|
|
|
for j := 0 to Pred(LazarusIDE.ActiveProject.FileCount) do begin
|
|
|
|
if AnsiSameText(srcItm.GetFileName(),ExtractFileName(LazarusIDE.ActiveProject.Files[j].Filename)) then
|
|
|
|
trueOpenFlags := trueOpenFlags - [ofAddToProject];
|
|
|
|
end;
|
|
|
|
LazarusIDE.DoOpenEditorFile(destPath + srcItm.GetFileName(),-1,trueOpenFlags);
|
2014-05-07 12:55:34 +00:00
|
|
|
end;}
|
2007-07-07 20:56:01 +00:00
|
|
|
{$ENDIF}
|
|
|
|
finally
|
|
|
|
srcMgnr := nil;
|
|
|
|
tree.Free();
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
Screen.Cursor := oldCursor;
|
|
|
|
end;
|
|
|
|
ShowMessage('File parsed succefully.');
|
|
|
|
Self.Close();
|
|
|
|
ModalResult := mrOK;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|