From 472fee7c6b6526b2f80d13cbc35a417f3d9a04cf Mon Sep 17 00:00:00 2001 From: inoussa Date: Wed, 11 May 2016 17:14:23 +0000 Subject: [PATCH] Java Language interface files generation. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4645 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- wst/trunk/ws_helper/command_line_parser.pas | 5 +- wst/trunk/ws_helper/generator.pas | 197 +------ wst/trunk/ws_helper/generatorbase.pas | 153 +++++ wst/trunk/ws_helper/generatorj.pas | 620 ++++++++++++++++++++ wst/trunk/ws_helper/pascal_parser_intf.pas | 273 ++++++--- wst/trunk/ws_helper/source_utils.pas | 11 +- wst/trunk/ws_helper/ws_helper.pas | 2 +- wst/trunk/ws_helper/ws_helper_prog.inc | 14 +- 8 files changed, 1011 insertions(+), 264 deletions(-) create mode 100644 wst/trunk/ws_helper/generatorbase.pas create mode 100644 wst/trunk/ws_helper/generatorj.pas diff --git a/wst/trunk/ws_helper/command_line_parser.pas b/wst/trunk/ws_helper/command_line_parser.pas index 561552487..a6dd4a8e9 100644 --- a/wst/trunk/ws_helper/command_line_parser.pas +++ b/wst/trunk/ws_helper/command_line_parser.pas @@ -21,7 +21,7 @@ uses Type TComandLineOption = ( - cloInterface, cloProxy, cloImp, cloBinder, cloWsdl, cloXsd, + cloInterface, cloProxy, cloImp, cloBinder, cloWsdl, cloXsd, cloJava, cloOutPutDirRelative, cloOutPutDirAbsolute, cloHandleWrappedParameters, cloGenerateDocAsComments, cloGenerateObjectCollection, cloFileRenaming, cloPrefixEnum, cloParserCaseSensitive, @@ -50,7 +50,7 @@ begin AAppOptions := []; c := #0; repeat - c := GetOpt('u:pibo:a:wxydg:f:c:'); + c := GetOpt('u:pibo:a:wxydg:f:c:j'); case c of 'u' : begin @@ -100,6 +100,7 @@ begin Include(AAppOptions,cloParserCaseSensitive); OptionsArgsMAP[cloParserCaseSensitive] := OptArg; end; + 'j' : Include(AAppOptions,cloJava); end; until ( c = EndOfOptions ); Result := OptInd; diff --git a/wst/trunk/ws_helper/generator.pas b/wst/trunk/ws_helper/generator.pas index 679cdaea0..0776f8dab 100644 --- a/wst/trunk/ws_helper/generator.pas +++ b/wst/trunk/ws_helper/generator.pas @@ -19,57 +19,13 @@ interface uses Classes, SysUtils, PasTree, - pascal_parser_intf, source_utils, wst_types; + pascal_parser_intf, source_utils, wst_types, generatorbase; const sWST_EXTENSION = 'wst'; type - TGeneratorOption = ( - goDocumentWrappedParameter { .Net style wrapped parameters }, - goGenerateDocAsComments { Documentation include in the XSD/WSDL schema will be generated as comments }, - goGenerateObjectCollection { Generate object "collection" instead of "array" }, - goCreateChoiceFieldsInConstructor - ); - TGeneratorOptions = set of TGeneratorOption; - - { TBaseGenerator } - - TBaseGenerator = class - Private - FOptions : TGeneratorOptions; - FSrcMngr : ISourceManager; - FCurrentStream : ISourceStream; - FSymbolTable: TwstPasTreeContainer; - FMainModule : TPasModule; - Protected - procedure SetCurrentStream(AStream : ISourceStream); - procedure Indent(); - function IncIndent():Integer; - function DecIndent():Integer; - procedure BeginAutoIndent(); - procedure EndAutoIndent(); - procedure Write(AText : String);overload; - procedure Write(AText : String; Const AArgs : array of const);overload; - procedure WriteLn(AText : String);overload; - procedure WriteLn(AText : String; Const AArgs : array of const);overload; - procedure NewLine(); - - function ExtractserviceName(AIntf : TPasElement):String; - function GenerateExtraUses() : string; - Public - constructor Create( - ASymTable : TwstPasTreeContainer; - ASrcMngr : ISourceManager - ); - procedure Execute();virtual;abstract; - property SymbolTable : TwstPasTreeContainer Read FSymbolTable; - property SrcMngr : ISourceManager Read FSrcMngr; - property Options : TGeneratorOptions read FOptions write FOptions; - property MainModule : TPasModule read FMainModule; - End; - { TProxyGenerator } TProxyGenerator = class(TBaseGenerator) @@ -473,7 +429,7 @@ begin end; end; GenerateUnitImplementationFooter(); - FSrcMngr.Merge(GetDestUnitName() + '.pas',[FDecStream,FDecProcStream,FImpStream]); + SrcMngr.Merge(GetDestUnitName() + '.pas',[FDecStream,FDecProcStream,FImpStream]); FDecStream := nil; FImpStream := nil; end; @@ -493,13 +449,13 @@ var begin locModule := FindModule(AIntf); if (locModule = nil) then - locModule := FSymbolTable.CurrentModule; + locModule := SymbolTable.CurrentModule; Indent(); Write('%s=class(%s,%s.%s',[GenerateClassName(AIntf),sPROXY_BASE_CLASS, locModule.Name, AIntf.Name]); if HandleEasyIntf then begin locModule := FindModule(AIntf); if (locModule = nil) then - locModule := FSymbolTable.CurrentModule; + locModule := SymbolTable.CurrentModule; Write(',%s.%s',[locModule.Name, AEasyIntf.Name]); end; WriteLn(')'); @@ -958,7 +914,7 @@ Var Indent();WriteLn('Result := Nil;'); end; end; - Indent();WriteLn('%s := %s;',[sPRM_NAME,QuotedStr(FSymbolTable.GetExternalName(resPrm))]); + Indent();WriteLn('%s := %s;',[sPRM_NAME,QuotedStr(SymbolTable.GetExternalName(resPrm))]); Indent();WriteLn('%s.Get(TypeInfo(%s), %s, %s);',[sLOC_SERIALIZER,resPrm.ResultType.Name,sPRM_NAME,'Result']); end; //-------------------------------- @@ -1003,7 +959,7 @@ Var begin locModule := FindModule(AIntf); if (locModule = nil) then - locModule := FSymbolTable.CurrentModule; + locModule := SymbolTable.CurrentModule; NewLine(); WriteLn('class function %s.GetServiceType() : PTypeInfo;',[strClassName]); WriteLn('begin'); @@ -1057,119 +1013,6 @@ begin WriteMethods(); end; - -{ TBaseGenerator } - -procedure TBaseGenerator.SetCurrentStream(AStream: ISourceStream); -begin - FCurrentStream := AStream; -end; - -procedure TBaseGenerator.Indent(); -begin - FCurrentStream.Indent(); -end; - -function TBaseGenerator.IncIndent():Integer; -begin - Result := FCurrentStream.IncIndent(); -end; - -function TBaseGenerator.DecIndent():Integer; -begin - Result := FCurrentStream.DecIndent(); -end; - -procedure TBaseGenerator.BeginAutoIndent(); -begin - FCurrentStream.BeginAutoIndent(); -end; - -procedure TBaseGenerator.EndAutoIndent(); -begin - FCurrentStream.EndAutoIndent(); -end; - -procedure TBaseGenerator.Write(AText: String); -begin - FCurrentStream.Write(AText); -end; - -procedure TBaseGenerator.Write(AText: String; const AArgs: array of const); -begin - Write(Format(AText,AArgs)); -end; - -procedure TBaseGenerator.WriteLn(AText: String); -begin - Write(AText+sNEW_LINE); -end; - -procedure TBaseGenerator.WriteLn(AText: String; const AArgs: array of const); -begin - Write(AText+sNEW_LINE,AArgs); -end; - -procedure TBaseGenerator.NewLine(); -begin - WriteLn(''); -end; - -function TBaseGenerator.ExtractserviceName(AIntf: TPasElement): String; -begin - Result := AIntf.Name; - If upCase(Result[1]) = 'I' Then - Delete(Result,1,1); -end; - -{function TBaseGenerator.GenerateExtraUses() : string; -var - m : TPasModule; - k, currentModuleIndex : Integer; - mdlList : TList2; - mdl : TPasModule; -begin - Result := ''; - mdlList := SymbolTable.Package.Modules; - currentModuleIndex := mdlList.IndexOf(MainModule); - for k := 0 to Pred(mdlList.Count) do begin - if ( k <> currentModuleIndex ) then begin - mdl := TPasModule(mdlList[k]); - if ( mdl <> SymbolTable.CurrentModule ) and ( not mdl.InheritsFrom(TPasNativeModule) ) then - Result := Result + ', ' + mdl.Name; - end; - end; - if ( Length(Result) > 0 ) then - Delete(Result,1,2); -end;} -function TBaseGenerator.GenerateExtraUses() : string; -var - locUsesList : TList2; - locModule : TPasElement; - i : Integer; -begin - Result := ''; - locUsesList := SymbolTable.CurrentModule.InterfaceSection.UsesList; - if (locUsesList.Count > 0) then begin - for i := 0 to Pred(locUsesList.Count) do begin - locModule := TPasElement(locUsesList[i]); - Result := Result + ', ' + locModule.Name; - end; - if ( Length(Result) > 0 ) then - Delete(Result,1,2); - end; -end; - -constructor TBaseGenerator.Create(ASymTable: TwstPasTreeContainer; ASrcMngr: ISourceManager); -begin - Assert(Assigned(ASymTable)); - Assert(Assigned(ASrcMngr)); - FSrcMngr :=ASrcMngr; - FCurrentStream := Nil; - FSymbolTable := ASymTable; - FMainModule := FSymbolTable.CurrentModule; -end; - { TBinderGenerator } function TBinderGenerator.GenerateClassName(AIntf: TPasElement): String; @@ -1483,7 +1326,7 @@ Var mtd := TPasProcedure(mtds[k]); WriteLn( 'RegisterVerbHandler(%s,{$IFDEF FPC}@{$ENDIF}%sHandler);', - [QuotedStr(FSymbolTable.GetExternalName(mtd)),mtd.Name]); + [QuotedStr(SymbolTable.GetExternalName(mtd)),mtd.Name]); end; end; EndAutoIndent(); @@ -1559,7 +1402,7 @@ Var IncIndent(); WriteLn( 'GetServerServiceRegistry().Register(%s,T%s_ServiceBinderFactory.Create() as IItemFactory);', - [QuotedStr(FSymbolTable.GetExternalName(AIntf)),strBuff] + [QuotedStr(SymbolTable.GetExternalName(AIntf)),strBuff] ); DecIndent(); WriteLn('End;'); @@ -1612,7 +1455,7 @@ begin end; end; GenerateUnitImplementationFooter(); - FSrcMngr.Merge(GetDestUnitName() + '.pas',[FDecStream,FImpStream]); + SrcMngr.Merge(GetDestUnitName() + '.pas',[FDecStream,FImpStream]); FDecStream := nil; FImpStream := nil; end; @@ -1902,7 +1745,7 @@ begin end; end; GenerateUnitImplementationFooter(); - FSrcMngr.Merge(GetDestUnitName() + '.pas',[FDecStream,FImpStream]); + SrcMngr.Merge(GetDestUnitName() + '.pas',[FDecStream,FImpStream]); FDecStream := nil; FImpStream := nil; end; @@ -1915,7 +1758,7 @@ var docString : string; i : Integer; begin - pl := FSymbolTable.Properties.FindList(AElement); + pl := SymbolTable.Properties.FindList(AElement); if ( pl <> nil ) then begin i := pl.IndexOfName(sDOCUMENTATION); if ( i >= 0 ) then begin @@ -2205,8 +2048,8 @@ begin IncIndent(); WriteLn(''); WriteLn('const'); - Indent();WriteLn('sNAME_SPACE = %s;',[QuotedStr(SymbolTable.GetExternalName(FSymbolTable.CurrentModule))]); - Indent();WriteLn('sUNIT_NAME = %s;',[QuotedStr(FSymbolTable.CurrentModule.Name)]); + Indent();WriteLn('sNAME_SPACE = %s;',[QuotedStr(SymbolTable.GetExternalName(SymbolTable.CurrentModule))]); + Indent();WriteLn('sUNIT_NAME = %s;',[QuotedStr(SymbolTable.CurrentModule.Name)]); DecIndent(); if AIncludeTypeSection then begin @@ -2606,7 +2449,7 @@ var WriteLn('begin'); IncIndent(); Indent(); - pte := FindActualType(p.VarType,FSymbolTable); + pte := FindActualType(p.VarType,SymbolTable); if ( pte <> nil ) and pte.InheritsFrom(TPasType) then begin pt := pte as TPasType; pt := GetUltimeType(pt,SymbolTable); @@ -2758,7 +2601,7 @@ begin if classItemArray then begin if ( goGenerateObjectCollection in Options ) or - FSymbolTable.IsCollection(ASymbol) + SymbolTable.IsCollection(ASymbol) then WriteObjectCollection(ASymbol) else @@ -3230,7 +3073,7 @@ begin for j := 0 to k do begin clssTyp := objLst[k-j] as TPasClassType; if ( gnrClssLst.IndexOf(clssTyp) = -1 ) then begin - if ( FSymbolTable.CurrentModule.InterfaceSection.Declarations.IndexOf(clssTyp) <> -1 ) then begin + if ( SymbolTable.CurrentModule.InterfaceSection.Declarations.IndexOf(clssTyp) <> -1 ) then begin GenerateClass(clssTyp); gnrClssLst.Add(clssTyp); end; @@ -3256,15 +3099,15 @@ begin end; if ( goDocumentWrappedParameter in Self.Options ) then begin - c := FSymbolTable.BindingCount; + c := SymbolTable.BindingCount; if ( c > 0 ) then begin for i := 0 to ( c - 1 ) do begin - locBinding := FSymbolTable.Binding[i]; + locBinding := SymbolTable.Binding[i]; if (typeList.IndexOf(locBinding.Intf) >= 0) and (locBinding.BindingStyle = bsDocument) then begin if (locBinding.EasyIntf = nil) then begin - locBinding.EasyIntf := DeduceEasyInterfaceForDocStyle(locBinding.Intf,FSymbolTable); + locBinding.EasyIntf := DeduceEasyInterfaceForDocStyle(locBinding.Intf,SymbolTable); if (locBinding.EasyIntf <> nil) then locBinding.EasyIntf.Release(); end; @@ -3287,7 +3130,7 @@ begin FImpFirstStream.NewLine(); FImpLastStream.NewLine(); GenerateUnitImplementationFooter(); - FSrcMngr.Merge( + SrcMngr.Merge( GetDestUnitName() + '.pas', [FDecStream,FImpStream,FRttiFunc,FImpFirstStream,FImpTempStream,FImpLastStream] ); diff --git a/wst/trunk/ws_helper/generatorbase.pas b/wst/trunk/ws_helper/generatorbase.pas new file mode 100644 index 000000000..14b52f506 --- /dev/null +++ b/wst/trunk/ws_helper/generatorbase.pas @@ -0,0 +1,153 @@ +unit generatorbase; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, PasTree, + source_utils, pascal_parser_intf, parserutils; + +type + + TGeneratorOption = ( + goDocumentWrappedParameter { .Net style wrapped parameters }, + goGenerateDocAsComments { Documentation include in the XSD/WSDL schema will be generated as comments }, + goGenerateObjectCollection { Generate object "collection" instead of "array" }, + goCreateChoiceFieldsInConstructor + ); + TGeneratorOptions = set of TGeneratorOption; + + { TBaseGenerator } + + TBaseGenerator = class + Private + FOptions : TGeneratorOptions; + FSrcMngr : ISourceManager; + FCurrentStream : ISourceStream; + FSymbolTable: TwstPasTreeContainer; + FMainModule : TPasModule; + Protected + procedure SetCurrentStream(AStream : ISourceStream); + procedure Indent(); + function IncIndent():Integer; + function DecIndent():Integer; + procedure BeginAutoIndent(); + procedure EndAutoIndent(); + procedure Write(AText : String);overload; + procedure Write(AText : String; Const AArgs : array of const);overload; + procedure WriteLn(AText : String);overload; + procedure WriteLn(AText : String; Const AArgs : array of const);overload; + procedure NewLine(); + + function ExtractserviceName(AIntf : TPasElement):String; + function GenerateExtraUses() : string; + Public + constructor Create( + ASymTable : TwstPasTreeContainer; + ASrcMngr : ISourceManager + ); + procedure Execute();virtual;abstract; + property SymbolTable : TwstPasTreeContainer Read FSymbolTable; + property SrcMngr : ISourceManager Read FSrcMngr; + property Options : TGeneratorOptions read FOptions write FOptions; + property MainModule : TPasModule read FMainModule; + End; + +implementation + + +{ TBaseGenerator } + +procedure TBaseGenerator.SetCurrentStream(AStream: ISourceStream); +begin + FCurrentStream := AStream; +end; + +procedure TBaseGenerator.Indent(); +begin + FCurrentStream.Indent(); +end; + +function TBaseGenerator.IncIndent():Integer; +begin + Result := FCurrentStream.IncIndent(); +end; + +function TBaseGenerator.DecIndent():Integer; +begin + Result := FCurrentStream.DecIndent(); +end; + +procedure TBaseGenerator.BeginAutoIndent(); +begin + FCurrentStream.BeginAutoIndent(); +end; + +procedure TBaseGenerator.EndAutoIndent(); +begin + FCurrentStream.EndAutoIndent(); +end; + +procedure TBaseGenerator.Write(AText: String); +begin + FCurrentStream.Write(AText); +end; + +procedure TBaseGenerator.Write(AText: String; const AArgs: array of const); +begin + Write(Format(AText,AArgs)); +end; + +procedure TBaseGenerator.WriteLn(AText: String); +begin + Write(AText+sNEW_LINE); +end; + +procedure TBaseGenerator.WriteLn(AText: String; const AArgs: array of const); +begin + Write(AText+sNEW_LINE,AArgs); +end; + +procedure TBaseGenerator.NewLine(); +begin + WriteLn(''); +end; + +function TBaseGenerator.ExtractserviceName(AIntf: TPasElement): String; +begin + Result := AIntf.Name; + If upCase(Result[1]) = 'I' Then + Delete(Result,1,1); +end; + +function TBaseGenerator.GenerateExtraUses() : string; +var + locUsesList : TList2; + locModule : TPasElement; + i : Integer; +begin + Result := ''; + locUsesList := SymbolTable.CurrentModule.InterfaceSection.UsesList; + if (locUsesList.Count > 0) then begin + for i := 0 to Pred(locUsesList.Count) do begin + locModule := TPasElement(locUsesList[i]); + Result := Result + ', ' + locModule.Name; + end; + if ( Length(Result) > 0 ) then + Delete(Result,1,2); + end; +end; + +constructor TBaseGenerator.Create(ASymTable: TwstPasTreeContainer; ASrcMngr: ISourceManager); +begin + Assert(Assigned(ASymTable)); + Assert(Assigned(ASrcMngr)); + FSrcMngr :=ASrcMngr; + FCurrentStream := Nil; + FSymbolTable := ASymTable; + FMainModule := FSymbolTable.CurrentModule; +end; + +end. + diff --git a/wst/trunk/ws_helper/generatorj.pas b/wst/trunk/ws_helper/generatorj.pas new file mode 100644 index 000000000..2ab750f97 --- /dev/null +++ b/wst/trunk/ws_helper/generatorj.pas @@ -0,0 +1,620 @@ +{ + This file is part of the Web Service Toolkit + Copyright (c) 2015 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. +} + +{$INCLUDE wst_global.inc} +unit generatorj; + +interface + +uses + Classes, SysUtils, + PasTree, + pascal_parser_intf, source_utils, wst_types, generatorbase; + +type + + { TInftGenerator } + + TInftGenerator = class(TBaseGenerator) + private + FStream : ISourceStream; + private + function GenerateIntfName(AIntf : TPasElement):string; + function GenerateTypeText(AType : TPasType) : string; + + procedure GenerateIntfProcParamsTypes(AProc : TPasProcedure); + procedure GenerateIntf(AIntf : TPasClassType); + procedure GenerateIntfProxy(AIntf : TPasClassType); + procedure GenerateClass(ASymbol : TPasClassType); + procedure GenerateEnum(ASymbol : TPasEnumType); + function GetDestUnitName():string; + + procedure GenerateEnums(); + procedure PrepareModule(); + procedure InternalExecute(); + public + procedure Execute();override; + end; + +implementation +uses + contnrs, + parserutils, logger_intf; + +{ TInftGenerator } + +function TInftGenerator.GenerateIntfName(AIntf : TPasElement) : string; +begin + Result := AIntf.Name; +end; + +function TInftGenerator.GenerateTypeText(AType : TPasType) : string; +var + t : TPasType; +begin + t := GetUltimeType(AType); + if not t.InheritsFrom(TPasArrayType) then begin + Result := t.Name; + end else begin + t := GetUltimeType(TPasArrayType(t).ElType); + Result := Format('java.util.List<%s>',[t.Name]); + end; +end; + +procedure TInftGenerator.GenerateIntfProcParamsTypes(AProc : TPasProcedure); +var + locName : string; + + procedure WriteRequestConstructor(); + var + prmCnt,k : Integer; + prm : TPasArgument; + prms : TList2; + begin + Indent(); + Write('public %s(',[locName]); + prms := AProc.ProcType.Args; + prmCnt := prms.Count; + if ( prmCnt > 0 ) then begin + IncIndent(); + for k := 0 to Pred(prmCnt) do begin + prm := TPasArgument(prms[k]); + if (k > 0 ) then + Write(', '); + NewLine(); + Indent(); + Write('%s %s',[GenerateTypeText(prm.ArgType),prm.Name]); + end; + DecIndent(); + NewLine(); + Indent(); + end; + WriteLn('){'); + IncIndent(); + if (prmCnt = 0) then begin + Indent(); + WriteLn('super("%s", null);',[AProc.Name]); + end else begin + Indent(); + Write('super("%s", new Object[] {',[AProc.Name]); + for k := 0 to Pred(prmCnt) do begin + prm := TPasArgument(prms[k]); + if (k > 0 ) then + Write(', '); + Write(prm.Name); + end; + WriteLn('});'); + end; + DecIndent(); + Indent(); + WriteLn('}'); + end; + + procedure WriteResponseFields(); + var + pt : TPasType; + begin + if AProc.InheritsFrom(TPasFunction) then begin + Indent(); + pt := GetUltimeType(TPasFunctionType(AProc.ProcType).ResultEl.ResultType); + Write('public %s result',[GenerateTypeText(pt)]); + if pt.InheritsFrom(TPasArrayType) then + Write(' = new java.util.ArrayList<>()'); + WriteLn(';'); + end; + end; + +var + locUnitName, s : string; +begin + locUnitName := GetDestUnitName(); + locName := Format('%sInParamsEnv_Type',[AProc.Name]); + s := locUnitName + PathDelim + locName+ '.java'; + FStream := SrcMngr.CreateItem(s); + SetCurrentStream(FStream); + WriteLn('package %s;',[locUnitName]); + NewLine(); + WriteLn('public class %s extends wst.BaseRemoteRequest {',[locName]); + IncIndent(); + WriteRequestConstructor(); + DecIndent(); + WriteLn('}'); + + locName := Format('%sOutParamsEnv_Type',[AProc.Name]); + s := locUnitName + PathDelim + locName+ '.java'; + FStream := SrcMngr.CreateItem(s); + SetCurrentStream(FStream); + WriteLn('package %s;',[locUnitName]); + NewLine(); + WriteLn('public class %s extends wst.BaseRemoteResponse {',[locName]); + IncIndent(); + WriteResponseFields(); + DecIndent(); + WriteLn('}'); +end; + +procedure TInftGenerator.GenerateIntf(AIntf : TPasClassType); +var + locName : string; + + procedure WriteMethod(AMthd : TPasProcedure); + var + prmCnt,k : Integer; + prm : TPasArgument; + prms : TList2; + pt : TPasType; + begin + Indent(); + Write('public '); + prms := AMthd.ProcType.Args; + prmCnt := prms.Count; + if AMthd.InheritsFrom(TPasFunction) then begin + pt := TPasFunctionType(AMthd.ProcType).ResultEl.ResultType; + Write(GenerateTypeText(pt) + ' '); + end else begin + Write('void '); + end; + Write('%s(',[AMthd.Name]); + + if ( prmCnt > 0 ) then begin + IncIndent(); + for k := 0 to Pred(prmCnt) do begin + prm := TPasArgument(prms[k]); + if (k > 0 ) then + Write(', '); + NewLine(); + Indent(); + Write('%s %s',[GenerateTypeText(prm.ArgType),prm.Name]); + end; + DecIndent(); + NewLine(); + Indent(); + end; + + WriteLn(') throws java.io.IOException, wst.RemoteException;'); + end; + + procedure WriteMethods(); + var + k, kc : Integer; + mbrs : TList2; + elt : TPasElement; + begin + IncIndent(); + mbrs := AIntf.Members; + kc := 0; + for k := 0 to Pred(mbrs.Count) do begin + elt := TPasElement(mbrs[k]); + if elt.InheritsFrom(TPasProcedure) then begin + if (kc > 0) then + NewLine(); + kc := kc+1; + WriteMethod(TPasProcedure(elt)); + end; + end; + DecIndent(); + end; + + procedure WriteMethodEnvs(); + var + k : Integer; + mbrs : TList2; + elt : TPasElement; + begin + mbrs := AIntf.Members; + for k := 0 to Pred(mbrs.Count) do begin + elt := TPasElement(mbrs[k]); + if elt.InheritsFrom(TPasProcedure) then + GenerateIntfProcParamsTypes(TPasProcedure(elt)); + end; + end; + +var + locUnitName, s : string; +begin + locUnitName := GetDestUnitName(); + s := locUnitName + PathDelim + SymbolTable.GetExternalName(AIntf)+ '.java'; + FStream := SrcMngr.CreateItem(s); + SetCurrentStream(FStream); + WriteLn('package %s;',[locUnitName]); + NewLine(); + locName := GenerateIntfName(AIntf); + WriteLn('public interface %s {',[locName]); + IncIndent(); + WriteMethods(); + DecIndent(); + WriteLn('}'); + WriteMethodEnvs(); +end; + +procedure TInftGenerator.GenerateIntfProxy(AIntf : TPasClassType); +var + locProxyName : string; + + procedure WriteMethod(AMthd : TPasProcedure); + var + prmCnt,k : Integer; + prm : TPasArgument; + prms : TList2; + s : string; + pt : TPasType; + begin + Indent(); + Write('public '); + prms := AMthd.ProcType.Args; + prmCnt := prms.Count; + if AMthd.InheritsFrom(TPasFunction) then begin + pt := TPasFunctionType(AMthd.ProcType).ResultEl.ResultType; + Write(GenerateTypeText(pt) + ' '); + end else begin + Write('void '); + end; + Write('%s(',[AMthd.Name]); + + if ( prmCnt > 0 ) then begin + IncIndent(); + for k := 0 to Pred(prmCnt) do begin + prm := TPasArgument(prms[k]); + if (k > 0 ) then + Write(', '); + NewLine(); + Indent(); + Write('%s %s',[GenerateTypeText(prm.ArgType),prm.Name]); + end; + DecIndent(); + NewLine(); + Indent(); + end; + WriteLn(') throws java.io.IOException, wst.RemoteException{'); + IncIndent(); + s := Format('%sInParamsEnv_Type',[AMthd.Name]); + Indent(); + Write('%s request = new %s(',[s,s]); + for k := 0 to Pred(prmCnt) do begin + prm := TPasArgument(prms[k]); + if (k > 0 ) then + Write(', '); + Write(prm.Name); + end; + WriteLn(');'); + s := Format('%sOutParamsEnv_Type',[AMthd.Name]); + Indent(); + WriteLn('%s response = (%s)MakeCall(request, %s.class);',[s,s,s]); + Indent(); + WriteLn('if (response.error != null){ '); + IncIndent(); + Indent(); + WriteLn('throw new wst.RemoteException(response.error.message,response.error.code,response.error.name);'); + DecIndent(); + Indent(); + WriteLn('}'); + if AMthd.InheritsFrom(TPasFunction) then begin + Indent(); + WriteLn('return response.result;'); + end; + DecIndent(); + Indent(); + WriteLn('};'); + end; + + procedure WriteMethods(); + var + k : Integer; + mbrs : TList2; + elt : TPasElement; + begin + IncIndent(); + mbrs := AIntf.Members; + for k := 0 to Pred(mbrs.Count) do begin + elt := TPasElement(mbrs[k]); + if elt.InheritsFrom(TPasProcedure) then begin + NewLine(); + WriteMethod(TPasProcedure(elt)); + end; + end; + DecIndent(); + end; + +var + locUnitName, s : string; +begin + locUnitName := GetDestUnitName(); + locProxyName := ExtractserviceName(AIntf); + locProxyName := Format('%sProxy',[locProxyName]); + s := locUnitName + PathDelim + locProxyName + '.java'; + FStream := SrcMngr.CreateItem(s); + SetCurrentStream(FStream); + WriteLn('package %s;',[locUnitName]); + NewLine(); + WriteLn('public class %s extends wst.BaseProxy implements %s {',[locProxyName,AIntf.Name]); + IncIndent(); + Indent(); + WriteLn('public %s(String serviceAddress){',[locProxyName]); + IncIndent(); + Indent(); + WriteLn('super(serviceAddress);'); + DecIndent(); + Indent(); + WriteLn('}'); + DecIndent(); + WriteMethods(); + WriteLn('}'); +end; + +procedure TInftGenerator.GenerateClass(ASymbol : TPasClassType); + + procedure WriteDec(); + var + decBuffer, s : string; + elt : TPasElement; + ultimAnc, trueAncestor : TPasType; + begin + s := ''; + if Assigned(ASymbol.AncestorType) then begin + trueAncestor := ASymbol.AncestorType; + if trueAncestor.InheritsFrom(TPasUnresolvedTypeRef) then begin + elt := SymbolTable.FindElement(SymbolTable.GetExternalName(trueAncestor)); + if (elt = nil) or (not elt.InheritsFrom(TPasType)) then + trueAncestor := nil + else + trueAncestor := TPasType(elt); + end; + if (trueAncestor <> nil) then begin + trueAncestor := GetUltimeType(trueAncestor); + if trueAncestor.InheritsFrom(TPasNativeSimpleType) and + Assigned(TPasNativeSimpleType(trueAncestor).ExtendableType) + then begin + trueAncestor := TPasNativeSimpleType(trueAncestor).ExtendableType; + end; + if not(trueAncestor.InheritsFrom(TPasNativeClassType)) or (trueAncestor.Name <> 'Object') then + s := Format('%s',[trueAncestor.Name]); + end; + end; + if IsStrEmpty(s) then + decBuffer := '' + else + decBuffer := Format(' extends %s',[s]); + Indent(); + WriteLn('public class %s%s {',[ASymbol.Name,decBuffer]); + end; + + procedure WriteProperty(AProp : TPasProperty; AActualPropType : TPasType); + var + locLine : string; + locType : TPasType; + locIsArray : Boolean; + begin + locType := GetUltimeType(AActualPropType); + locIsArray := SymbolTable.IsOfType(locType,TPasArrayType); + if not locIsArray then begin + locLine := Format('public %s %s',[GenerateTypeText(locType),SymbolTable.GetExternalName(AProp)]); + if SymbolTable.IsOfType(locType,TPasClassType) then + locLine := Format('%s = new %s()',[locLine,GenerateTypeText(locType)]); + locLine := locLine+';'; + end else begin + locType := GetUltimeType(TPasArrayType(locType).ElType); + locLine := Format('public java.util.List<%s> %s = new java.util.ArrayList<>();',[GenerateTypeText(locType),SymbolTable.GetExternalName(AProp)]); + end; + Indent(); WriteLn(locLine); + end; + + procedure WriteProperties(); + var + k : Integer; + p : TPasProperty; + elt : TPasElement; + begin + Indent(); + IncIndent(); + for k := 0 to Pred(ASymbol.Members.Count) do begin + elt := TPasElement(ASymbol.Members[k]); + if elt.InheritsFrom(TPasProperty) then begin + p := TPasProperty(elt); + WriteProperty(p,FindActualType(p.VarType,SymbolTable)); + end; + end; + DecIndent(); + end; + +begin + try + NewLine(); + WriteDec(); + WriteProperties(); + WriteLn('}'); + except + on e : Exception do begin + GetLogger.Log(mtError,'TInftGenerator.GenerateClass()=',[ASymbol.Name, ' ;; ', e.Message]); + raise; + end; + end; +end; + +procedure TInftGenerator.GenerateEnum(ASymbol : TPasEnumType); +var + i : Integer; + itm : TPasEnumValue; + s : string; +begin + NewLine(); + WriteLn('public enum %s {',[SymbolTable.GetExternalName(ASymbol)]); + IncIndent(); + for i := 0 to Pred(ASymbol.Values.Count) do begin + itm := TPasEnumValue(ASymbol.Values[i]); + Indent(); + s := SymbolTable.GetExternalName(itm); + if ( i > 0 ) then + WriteLn(',%s',[s]) + else + WriteLn('%s',[s]); + end; + DecIndent(); + WriteLn('}'); +end; + +function TInftGenerator.GetDestUnitName(): string; +begin + Result := SymbolTable.CurrentModule.Name; +end; + +procedure TInftGenerator.GenerateEnums(); +var + typeList : TList2; + locUnitName, s : string; + i, c : Integer; + elt : TPasElement; +begin + typeList := SymbolTable.CurrentModule.InterfaceSection.Declarations; + c := typeList.Count; + for i := 0 to c-1 do begin + elt := TPasElement(typeList[i]); + if elt.InheritsFrom(TPasEnumType) then begin + locUnitName := GetDestUnitName(); + s := locUnitName + PathDelim + SymbolTable.GetExternalName(elt)+ '.java'; + FStream := SrcMngr.CreateItem(s); + SetCurrentStream(FStream); + WriteLn('package %s;',[locUnitName]); + GenerateEnum(TPasEnumType(elt)); + end; + end; +end; + +procedure TInftGenerator.PrepareModule(); +begin + +end; + +procedure TInftGenerator.InternalExecute(); +var + i, c, j, k : Integer; + clssTyp : TPasClassType; + gnrClssLst : TObjectList; + objLst : TObjectList; + typeList : TList2; + elt : TPasElement; + classAncestor : TPasElement; + s, locUnitName : string; +begin + GenerateEnums(); + + objLst := nil; + gnrClssLst := TObjectList.Create(False); + try + locUnitName := GetDestUnitName(); + typeList := SymbolTable.CurrentModule.InterfaceSection.Declarations; + c := Pred(typeList.Count); + + objLst := TObjectList.Create(); + objLst.OwnsObjects := False; + for i := 0 to c do begin + elt := TPasElement(typeList[i]); + if elt.InheritsFrom(TPasClassType) and ( TPasClassType(elt).ObjKind = okClass ) then begin + clssTyp := TPasClassType(elt); + if ( gnrClssLst.IndexOf(clssTyp) = -1 ) then begin + objLst.Clear(); + while Assigned(clssTyp) and ( objLst.IndexOf(clssTyp) = -1 ) do begin + objLst.Add(clssTyp); + classAncestor := clssTyp.AncestorType; + if Assigned(classAncestor) and classAncestor.InheritsFrom(TPasUnresolvedTypeRef) then begin + classAncestor := SymbolTable.FindElement(SymbolTable.GetExternalName(classAncestor)); + end; + if Assigned(classAncestor) and classAncestor.InheritsFrom(TPasClassType) then begin + clssTyp := classAncestor as TPasClassType; + end else begin + clssTyp := nil; + end; + end; + + k := Pred(objLst.Count); + for j := 0 to k do begin + clssTyp := objLst[k-j] as TPasClassType; + if ( gnrClssLst.IndexOf(clssTyp) = -1 ) then begin + if ( SymbolTable.CurrentModule.InterfaceSection.Declarations.IndexOf(clssTyp) <> -1 ) then begin + s := locUnitName + PathDelim + SymbolTable.GetExternalName(clssTyp)+ '.java'; + FStream := SrcMngr.CreateItem(s); + SetCurrentStream(FStream); + WriteLn('package %s;',[locUnitName]); + GenerateClass(clssTyp); + gnrClssLst.Add(clssTyp); + end; + end; + end; + end; + end; + end; + + for i := 0 to c do begin + elt := TPasElement(typeList[i]); + if elt.InheritsFrom(TPasClassType) and ( TPasClassType(elt).ObjKind = okInterface ) then begin + GenerateIntf(TPasClassType(elt)); + GenerateIntfProxy(TPasClassType(elt)); + end; + end; + finally + FreeAndNil(objLst); + FreeAndNil(gnrClssLst); + end; +end; + +procedure TInftGenerator.Execute(); +var + oldCurrent, mdl : TPasModule; + i : Integer; + mdlList : TList2; + oldCS : Boolean; + oldNamesKinds : TElementNameKinds; +begin + oldCS := SymbolTable.CaseSensitive; + oldNamesKinds := SymbolTable.DefaultSearchNameKinds; + oldCurrent := SymbolTable.CurrentModule; + try + SymbolTable.CaseSensitive := True; + SymbolTable.DefaultSearchNameKinds := [elkDeclaredName]; + mdlList := SymbolTable.Package.Modules; + for i := 0 to Pred(mdlList.Count) do begin + mdl := TPasModule(mdlList[i]); + if not mdl.InheritsFrom(TPasNativeModule) then begin + SymbolTable.SetCurrentModule(mdl); + PrepareModule(); + InternalExecute(); + end; + end; + finally + SymbolTable.SetCurrentModule(oldCurrent); + SymbolTable.CaseSensitive := oldCS; + SymbolTable.DefaultSearchNameKinds := oldNamesKinds; + end; +end; + +end. + diff --git a/wst/trunk/ws_helper/pascal_parser_intf.pas b/wst/trunk/ws_helper/pascal_parser_intf.pas index acc6a9cfb..f57d3baf1 100644 --- a/wst/trunk/ws_helper/pascal_parser_intf.pas +++ b/wst/trunk/ws_helper/pascal_parser_intf.pas @@ -262,6 +262,7 @@ type function MakeInternalSymbolNameFrom(const AName : string) : string ; function CreateWstInterfaceSymbolTable(AContainer : TwstPasTreeContainer) : TPasModule; + function JavaCreateWstInterfaceSymbolTable(AContainer : TwstPasTreeContainer) : TPasModule; procedure CreateDefaultBindingForIntf(ATree : TwstPasTreeContainer); implementation @@ -302,6 +303,75 @@ const ('AnsiChar', 'TComplexAnsiCharContentRemotable', 'string'), ('WideChar', 'TComplexWideCharContentRemotable', 'string') ); +// JAVA + JAVA_SIMPLE_TYPES_COUNT = 11; + JAVA_SIMPLE_TYPES : Array[0..Pred(JAVA_SIMPLE_TYPES_COUNT)] Of array[0..2] of string = ( + ('char', '', ''), + ('byte', '', ''), + ('short', '', ''), + ('int', '', ''), + ('long', '', ''), + ('float', '', ''), + ('double', '', ''), + ('boolean', '', ''), + ('String', '', 'string'), + ('wst.DateTime', '', 'dateTime') , //('java.util.OffsetDateTime', '', 'dateTime') , + //('java.time.OffsetTime', '', 'time') , + //('java.time.Duration', '', 'duration') , + ('java.math.BigDecimal', '', 'decimal') + ); + + +procedure JavaRegisterSimpleTypes( + ADest : TPasModule; + AContainer : TwstPasTreeContainer +); +var + i : Integer; + splTyp : TPasNativeSimpleType; + syb : TPasNativeSimpleContentClassType; + s : string; + typlst : array[0..Pred(JAVA_SIMPLE_TYPES_COUNT)] of TPasNativeSimpleType; +begin + for i := Low(JAVA_SIMPLE_TYPES) to High(JAVA_SIMPLE_TYPES) do begin + splTyp := TPasNativeSimpleType( + AContainer.CreateElement( + TPasNativeSimpleType,JAVA_SIMPLE_TYPES[i][0], + ADest.InterfaceSection,visPublic,'',0 + ) + ); + ADest.InterfaceSection.Declarations.Add(splTyp); + ADest.InterfaceSection.Types.Add(splTyp); + typlst[i] := splTyp; + end; + for i := Low(JAVA_SIMPLE_TYPES) to High(JAVA_SIMPLE_TYPES) do begin + s := JAVA_SIMPLE_TYPES[i][1]; + if not IsStrEmpty(s) then begin + syb := AContainer.FindElementInModule(JAVA_SIMPLE_TYPES[i][1],ADest) + as TPasNativeSimpleContentClassType; + if not Assigned(syb) then begin + syb := TPasNativeSimpleContentClassType( + AContainer.CreateElement( + TPasNativeSimpleContentClassType,s, + ADest.InterfaceSection,visDefault,'',0 + ) + ); + ADest.InterfaceSection.Declarations.Add(syb); + ADest.InterfaceSection.Types.Add(syb); + end; + typlst[i].SetExtendableType(syb); + end; + end; + for i := Low(JAVA_SIMPLE_TYPES) to High(JAVA_SIMPLE_TYPES) do begin + splTyp := typlst[i]; + if not IsStrEmpty(JAVA_SIMPLE_TYPES[i][2]) then begin + AContainer.RegisterExternalAlias(splTyp,JAVA_SIMPLE_TYPES[i][2]); + if ( splTyp.ExtendableType <> nil ) then begin + AContainer.RegisterExternalAlias(splTyp.ExtendableType,JAVA_SIMPLE_TYPES[i][2]); + end; + end; + end; +end; procedure AddSystemSymbol( ADest : TPasModule; @@ -443,44 +513,89 @@ begin RegisterBoxedTypes(); end; +function AddAlias( + AContainer : TwstPasTreeContainer; + const AName, + ABaseType : string; + ATable : TPasModule +) : TPasTypeAliasType; +begin + Result := TPasTypeAliasType(AContainer.CreateElement(TPasAliasType,AName,ATable.InterfaceSection,visPublic,'',0)); + Result.DestType := AContainer.FindElementInModule(ABaseType,ATable) as TPasType; + if Assigned(Result.DestType) then + Result.DestType.AddRef(); + ATable.InterfaceSection.Declarations.Add(Result); + ATable.InterfaceSection.Classes.Add(Result); + ATable.InterfaceSection.Types.Add(Result); +end; + +function AddClassDef( + AContainer : TwstPasTreeContainer; + ATable : TPasModule; + const AClassName, + AParentName : string; + const AClassType : TPasClassTypeClass = nil +):TPasClassType; +var + locClassType : TPasClassTypeClass; +begin + if Assigned(AClassType) then begin + locClassType := AClassType; + end else begin + locClassType := TPasClassType; + end; + Result := TPasClassType(AContainer.CreateElement(locClassType,AClassName,ATable.InterfaceSection,visDefault,'',0)); + if not IsStrEmpty(AParentName) then begin + Result.AncestorType := AContainer.FindElementInModule(AParentName,ATable) as TPasType; + if Assigned(Result.AncestorType) then + Result.AncestorType.AddRef(); + end; + ATable.InterfaceSection.Classes.Add(Result); + ATable.InterfaceSection.Declarations.Add(Result); + ATable.InterfaceSection.Types.Add(Result); +end; + +function JavaCreateWstInterfaceSymbolTable(AContainer : TwstPasTreeContainer) : TPasModule; +var + locOldNameKinds : TElementNameKinds; +begin + locOldNameKinds := AContainer.DefaultSearchNameKinds; + AContainer.DefaultSearchNameKinds := [elkDeclaredName,elkName]; + try + Result := TPasNativeModule(AContainer.CreateElement(TPasNativeModule,'base_service_intf',AContainer.Package,visPublic,'',0)); + try + AContainer.Package.Modules.Add(Result); + AContainer.RegisterExternalAlias(Result,sXSD_NS); + Result.InterfaceSection := TInterfaceSection(AContainer.CreateElement(TInterfaceSection,'',Result,visDefault,'',0)); + JavaRegisterSimpleTypes(Result,AContainer); + AddClassDef(AContainer,Result,'Object','',TPasNativeClassType); + AddAlias(AContainer,'TBaseComplexRemotable','Object',Result); + AddAlias(AContainer,'UnicodeString','string',Result); + AddAlias(AContainer,'token','string',Result); + AddAlias(AContainer,'language','string',Result); + AddAlias(AContainer,'anyURI','string',Result); + AddAlias(AContainer,'ID','string',Result); + AddAlias(AContainer,'base64Binary','string',Result); + AddAlias(AContainer,'hexBinary','string',Result); + AddAlias(AContainer,'integer','int',Result); + AddAlias(AContainer,'nonNegativeInteger','int',Result); + AddAlias(AContainer,'positiveInteger','int',Result); + AddAlias(AContainer,'unsignedInt','int',Result); + AddAlias(AContainer,'unsignedByte','int',Result); + AddAlias(AContainer,'unsignedShort','int',Result); + AddAlias(AContainer,'unsignedLong','long',Result); + AddAlias(AContainer,'Currency','decimal',Result); + AddAlias(AContainer,'date','dateTime',Result); + except + FreeAndNil(Result); + raise; + end; + finally + AContainer.DefaultSearchNameKinds := locOldNameKinds; + end; +end; + function CreateWstInterfaceSymbolTable(AContainer : TwstPasTreeContainer) : TPasModule; - - function AddClassDef( - ATable : TPasModule; - const AClassName, - AParentName : string; - const AClassType : TPasClassTypeClass = nil - ):TPasClassType; - var - locClassType : TPasClassTypeClass; - begin - if Assigned(AClassType) then begin - locClassType := AClassType; - end else begin - locClassType := TPasClassType; - end; - Result := TPasClassType(AContainer.CreateElement(locClassType,AClassName,ATable.InterfaceSection,visDefault,'',0)); - if not IsStrEmpty(AParentName) then begin - Result.AncestorType := AContainer.FindElementInModule(AParentName,ATable) as TPasType; - if Assigned(Result.AncestorType) then - Result.AncestorType.AddRef(); - end; - ATable.InterfaceSection.Classes.Add(Result); - ATable.InterfaceSection.Declarations.Add(Result); - ATable.InterfaceSection.Types.Add(Result); - end; - - function AddAlias(const AName, ABaseType : string; ATable : TPasModule) : TPasTypeAliasType; - begin - Result := TPasTypeAliasType(AContainer.CreateElement(TPasAliasType,AName,ATable.InterfaceSection,visPublic,'',0)); - Result.DestType := AContainer.FindElementInModule(ABaseType,ATable) as TPasType; - if Assigned(Result.DestType) then - Result.DestType.AddRef(); - ATable.InterfaceSection.Declarations.Add(Result); - ATable.InterfaceSection.Classes.Add(Result); - ATable.InterfaceSection.Types.Add(Result); - end; - var loc_TBaseComplexSimpleContentRemotable : TPasClassType; locOldNameKinds : TElementNameKinds; @@ -494,60 +609,60 @@ begin AContainer.RegisterExternalAlias(Result,sXSD_NS); Result.InterfaceSection := TInterfaceSection(AContainer.CreateElement(TInterfaceSection,'',Result,visDefault,'',0)); AddSystemSymbol(Result,AContainer,AContainer.XsdStringMaping); - AddClassDef(Result,'TBaseRemotable','',TPasNativeClassType); - AddClassDef(Result,'TStringBufferRemotable','TBaseRemotable',TPasNativeClassType); - AContainer.RegisterExternalAlias(AddClassDef(Result,'anyType_Type','TBaseRemotable',TPasNativeClassType),'anyType'); - AddClassDef(Result,'TAbstractSimpleRemotable','TBaseRemotable',TPasNativeClassType); - AContainer.RegisterExternalAlias(AddClassDef(Result,'schema_Type','TAbstractSimpleRemotable'),'schema'); - AContainer.RegisterExternalAlias(AddClassDef(Result,'TDateRemotable','TAbstractSimpleRemotable'),'date'); - AContainer.RegisterExternalAlias(AddClassDef(Result,'TDateTimeRemotable','TAbstractSimpleRemotable'),'dateTime'); + AddClassDef(AContainer,Result,'TBaseRemotable','',TPasNativeClassType); + AddClassDef(AContainer,Result,'TStringBufferRemotable','TBaseRemotable',TPasNativeClassType); + AContainer.RegisterExternalAlias(AddClassDef(AContainer,Result,'anyType_Type','TBaseRemotable',TPasNativeClassType),'anyType'); + AddClassDef(AContainer,Result,'TAbstractSimpleRemotable','TBaseRemotable',TPasNativeClassType); + AContainer.RegisterExternalAlias(AddClassDef(AContainer,Result,'schema_Type','TAbstractSimpleRemotable'),'schema'); + AContainer.RegisterExternalAlias(AddClassDef(AContainer,Result,'TDateRemotable','TAbstractSimpleRemotable'),'date'); + AContainer.RegisterExternalAlias(AddClassDef(AContainer,Result,'TDateTimeRemotable','TAbstractSimpleRemotable'),'dateTime'); {$IFDEF WST_HAS_TDURATIONREMOTABLE} - AContainer.RegisterExternalAlias(AddClassDef(Result,'TDurationRemotable','TAbstractSimpleRemotable'),'duration'); + AContainer.RegisterExternalAlias(AddClassDef(AContainer,Result,'TDurationRemotable','TAbstractSimpleRemotable'),'duration'); {$ENDIF WST_HAS_TDURATIONREMOTABLE} - AContainer.RegisterExternalAlias(AddClassDef(Result,'TTimeRemotable','TAbstractSimpleRemotable'),'time'); + AContainer.RegisterExternalAlias(AddClassDef(AContainer,Result,'TTimeRemotable','TAbstractSimpleRemotable'),'time'); - AddClassDef(Result,'TAbstractComplexRemotable','TBaseRemotable',TPasNativeClassType); - loc_TBaseComplexSimpleContentRemotable := AddClassDef(Result,'TBaseComplexSimpleContentRemotable','TAbstractComplexRemotable',TPasNativeClassType); + AddClassDef(AContainer,Result,'TAbstractComplexRemotable','TBaseRemotable',TPasNativeClassType); + loc_TBaseComplexSimpleContentRemotable := AddClassDef(AContainer,Result,'TBaseComplexSimpleContentRemotable','TAbstractComplexRemotable',TPasNativeClassType); (AContainer.FindElementInModule('TComplexInt16SContentRemotable',Result) as TPasClassType).AncestorType := loc_TBaseComplexSimpleContentRemotable; (AContainer.FindElementInModule('TComplexFloatDoubleContentRemotable',Result) as TPasClassType).AncestorType := loc_TBaseComplexSimpleContentRemotable; loc_TBaseComplexSimpleContentRemotable.AddRef(); loc_TBaseComplexSimpleContentRemotable.AddRef(); - AddClassDef(Result,'TBaseComplexRemotable','TAbstractComplexRemotable',TPasNativeClassType); - AddClassDef(Result,'THeaderBlock','TBaseComplexRemotable',TPasNativeClassType); - AddClassDef(Result,'TSimpleContentHeaderBlock','THeaderBlock',TPasNativeClassType); - AddClassDef(Result,'TBaseArrayRemotable','TAbstractComplexRemotable',TPasNativeClassType); - AddClassDef(Result,'TBaseObjectArrayRemotable','TBaseArrayRemotable',TPasNativeClassType); - AddClassDef(Result,'TBaseSimpleTypeArrayRemotable','TBaseArrayRemotable',TPasNativeClassType); - AddClassDef(Result,'TArrayOfStringRemotable','TBaseSimpleTypeArrayRemotable'); - AddClassDef(Result,'TArrayOfBooleanRemotable','TBaseSimpleTypeArrayRemotable'); - AddClassDef(Result,'TArrayOfInt8URemotable','TBaseSimpleTypeArrayRemotable'); - AddClassDef(Result,'TArrayOfInt8SRemotable','TBaseSimpleTypeArrayRemotable'); - AddClassDef(Result,'TArrayOfInt16SRemotable','TBaseSimpleTypeArrayRemotable'); - AddClassDef(Result,'TArrayOfInt16URemotable','TBaseSimpleTypeArrayRemotable'); - AddClassDef(Result,'TArrayOfInt32URemotable','TBaseSimpleTypeArrayRemotable'); - AddClassDef(Result,'TArrayOfInt32SRemotable','TBaseSimpleTypeArrayRemotable'); - AddClassDef(Result,'TArrayOfInt64SRemotable','TBaseSimpleTypeArrayRemotable'); - AddClassDef(Result,'TArrayOfInt64URemotable','TBaseSimpleTypeArrayRemotable'); - AddClassDef(Result,'TArrayOfFloatSingleRemotable','TBaseSimpleTypeArrayRemotable'); - AddClassDef(Result,'TArrayOfFloatDoubleRemotable','TBaseSimpleTypeArrayRemotable'); - AddClassDef(Result,'TArrayOfFloatExtendedRemotable','TBaseSimpleTypeArrayRemotable'); - AddClassDef(Result,'TArrayOfFloatCurrencyRemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TBaseComplexRemotable','TAbstractComplexRemotable',TPasNativeClassType); + AddClassDef(AContainer,Result,'THeaderBlock','TBaseComplexRemotable',TPasNativeClassType); + AddClassDef(AContainer,Result,'TSimpleContentHeaderBlock','THeaderBlock',TPasNativeClassType); + AddClassDef(AContainer,Result,'TBaseArrayRemotable','TAbstractComplexRemotable',TPasNativeClassType); + AddClassDef(AContainer,Result,'TBaseObjectArrayRemotable','TBaseArrayRemotable',TPasNativeClassType); + AddClassDef(AContainer,Result,'TBaseSimpleTypeArrayRemotable','TBaseArrayRemotable',TPasNativeClassType); + AddClassDef(AContainer,Result,'TArrayOfStringRemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TArrayOfBooleanRemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TArrayOfInt8URemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TArrayOfInt8SRemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TArrayOfInt16SRemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TArrayOfInt16URemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TArrayOfInt32URemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TArrayOfInt32SRemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TArrayOfInt64SRemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TArrayOfInt64URemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TArrayOfFloatSingleRemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TArrayOfFloatDoubleRemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TArrayOfFloatExtendedRemotable','TBaseSimpleTypeArrayRemotable'); + AddClassDef(AContainer,Result,'TArrayOfFloatCurrencyRemotable','TBaseSimpleTypeArrayRemotable'); - AddAlias('token','string',Result); - AddAlias('language','string',Result); - AddAlias('anyURI','string',Result); - AddAlias('ID','string',Result); - AddAlias('NCName','string',Result); - //AddAlias('float','Single',Result); - AddAlias('integer','int',Result); - AddAlias('nonNegativeInteger','LongWord',Result); - AddAlias('positiveInteger','nonNegativeInteger',Result); + AddAlias(AContainer,'token','string',Result); + AddAlias(AContainer,'language','string',Result); + AddAlias(AContainer,'anyURI','string',Result); + AddAlias(AContainer,'ID','string',Result); + AddAlias(AContainer,'NCName','string',Result); + //AddAlias(AContainer,'float','Single',Result); + AddAlias(AContainer,'integer','int',Result); + AddAlias(AContainer,'nonNegativeInteger','LongWord',Result); + AddAlias(AContainer,'positiveInteger','nonNegativeInteger',Result); {$IFNDEF WST_HAS_TDURATIONREMOTABLE} - AddAlias('duration','string',Result); + AddAlias(AContainer,'duration','string',Result); {$ENDIF WST_HAS_TDURATIONREMOTABLE} {$IFNDEF WST_HAS_TTIMEREMOTABLE} - AddAlias('time','string',Result); + AddAlias(AContainer,'time','string',Result); {$ENDIF WST_HAS_TTIMEREMOTABLE} except FreeAndNil(Result); diff --git a/wst/trunk/ws_helper/source_utils.pas b/wst/trunk/ws_helper/source_utils.pas index c1b2f4183..44d510af8 100644 --- a/wst/trunk/ws_helper/source_utils.pas +++ b/wst/trunk/ws_helper/source_utils.pas @@ -226,12 +226,15 @@ end; procedure TSourceStream.SaveToFile(const APath: string); var - s: string; + locDir,locFileName: string; begin - s := IncludeTrailingPathDelimiter(APath) + GetFileName(); - FStream.SaveToFile(s); + locFileName := IncludeTrailingPathDelimiter(APath) + GetFileName(); + locDir := ExtractFileDir(locFileName); + if not DirectoryExists(locDir) then + ForceDirectories(locDir); + FStream.SaveToFile(locFileName); {$IFDEF WST_IDE} - LazFileUtils.InvalidateFileStateCache(s); + LazFileUtils.InvalidateFileStateCache(locFileName); {$ENDIF} end; diff --git a/wst/trunk/ws_helper/ws_helper.pas b/wst/trunk/ws_helper/ws_helper.pas index 6b2672e0a..744cf18d1 100644 --- a/wst/trunk/ws_helper/ws_helper.pas +++ b/wst/trunk/ws_helper/ws_helper.pas @@ -20,7 +20,7 @@ uses Classes, SysUtils, wst_resources_utils, - generator, + generatorbase, generatorj, generator, parserutils, source_utils, command_line_parser, diff --git a/wst/trunk/ws_helper/ws_helper_prog.inc b/wst/trunk/ws_helper/ws_helper_prog.inc index 2df5d7689..979e5fb24 100644 --- a/wst/trunk/ws_helper/ws_helper_prog.inc +++ b/wst/trunk/ws_helper/ws_helper_prog.inc @@ -35,6 +35,7 @@ resourcestring ' -c Indicate the parser''s case sensitivity : ' + sNEW_LINE + ' S : the paser is case sensitive' + sNEW_LINE + ' I : the paser is not case sensitive' + sNEW_LINE + + ' -j Generate Java Language interface files for' + sNEW_LINE + ' -f Specify unit(s) renaming option : oldName= NewName(;oldName= NewName)* '; sCOPYRIGHT = 'ws_helper, Web Service Toolkit 0.6 Copyright (c) 2006-2014 by Inoussa OUEDRAOGO'; @@ -359,6 +360,15 @@ var end; end; + If ( cloJava in AppOptions ) Then Begin + WriteLn('Java file generation...'); + g := generatorj.TInftGenerator.Create(symtable,srcMngr); + //if wrappedParams then + //g.Options := g.Options + [goDocumentWrappedParameter]; + g.Execute(); + FreeAndNil(g); + End; + Result := True; except on E : Exception do begin @@ -406,7 +416,9 @@ begin Error(errStr); end; symtable := TwstPasTreeContainer.Create(); - symtable.CaseSensitive := cloParserCaseSensitive in AppOptions; + symtable.CaseSensitive := (([cloParserCaseSensitive,cloJava]*AppOptions) <>[]); + if (cloJava in AppOptions) then + JavaCreateWstInterfaceSymbolTable(symtable); if (cloStringMaping in AppOptions) then begin tmpString := Trim(GetOptionArg(cloStringMaping)); tmpString := UpperCase(Copy(tmpString,2,Length(tmpString)));