📄 biwsdlbiappcodegen.py
字号:
from BiWsdlJsCodeGen import *from BiWsdlBiJsStubCodeGen import *import reimport itertoolsimport stringimport os.path"""<summary>BiWsdiBiAppCodeGen is a class for generating sample Bindows applications for using BiWsl stubs.</summary>"""class BiWsdlBiAppCodeGen (BiWsdlJsCodeGen): """ <summary> Constructor </summary> <param name="aDefaultWsdl"> URL from which the generated application will obtain the operated service's WSDL. </param> <param name="aStubPath"> Path to a JavaScript file containing a definition of webservice stubs generated by BiWsdlBiJsStubCodeGen for the webservice operated by the application.</param> """ def __init__(self, aDefaultWsdl, aStubPath): super(BiWsdlBiAppCodeGen, self).__init__() self.__defaultWsdl = aDefaultWsdl self.__stubPath = aStubPath self.__genAsyncCalls = True self.__genSyncCalls = True self.__oldWs = False; self.__bindowsPath = os.path.join(os.path.dirname(__file__), "../..") def startGen(self): # Generate header comment super(BiWsdlBiAppCodeGen, self).startGen() self.__serviceTabPaneClasses = {} self.emitIndentedCommentLine("/// <summary>"); self.emitIndentedCommentLine("/// This file implements a sample client for testing Web-Service stub operation. File was automatically generated"); self.emitIndentedCommentLine("/// by BiWsdl2Js."); self.emitIndentedCommentLine("/// </summary>"); self.emitLine(""); # Generate DEFAULT_WSDL_PATH declaration self.emitIndentedLine("DEFAULT_WSDL_PATH = \"" + self.__defaultWsdl + "\";") self.emitIndentedLine("") # Generate infra types self.genDlgSep() self.genWsPortTabPage() self.genWsOpInvoker() def endGen(self): lAdfFile = self.getAdfFilePath() lAppClass = string.split(os.path.basename(lAdfFile), ".")[0] # Create main application class: self.startClassCtor(lAppClass, [], "BiObject", "Main web-service application class.") self.emitIndentedLine("BiObject.call(this);") self.emitIndentedLine("this._serviceForms = [];") self.emitIndentedLine("") # Build welcome notice, lWelcomeBannerTitle = "Web-Service Test Client" lWelcomeBannerText = """<P>This test application allows you to experiment with a Bindows web-service stub generated automatically by <B>Wsdl2BiJs</B> with the <B>--app [name]</B> option. The <A href=\"%(stub_url)s\">stub</A> tested by this application is based on a <A target=\"_blank\" href=\"http://www.w3.org/TR/wsdl\">WSDL</A> file obtained from <A TARGET=\"_blank\" href=\"%(wsdl)s\">%(wsdl)s</A>. The code for this application resides in <A TARGET=\"BLANK\" href=\"%(app)s\">%(app_abs)s</A>. It provides a good example to writing web-service client applications.</P><P>Select a web-service to operate from the listbox on the left, and a form for operating the service will appear to the right of the screen. This form consists of tabs, one for each port supported by the service. In each tab, you can input parameters and invoke operations of its corresponding port. To invoke an operation, first input invocation parameters in the designated fields -- as <A TARGET=\"_blank\" href=\"http://www.ecma-international.org/publications/standards/Ecma-262.htm\">JavaScript</A> expressions. After inputing all of the operation's required parameters, click on an invocation button to invoke the operation and watch the result.</P>""" % { "wsdl": self.__defaultWsdl, "stub_url": self.__stubPath, "app": self.getOutput(), "app_abs": os.path.abspath(self.getOutput())} lWelcomeBannerText = self.escapeJsString(lWelcomeBannerText) # Emit constructor: # Constructor sets up a main window with list of services at the left, and a 'welcome banner' at the top: self.emitIndentedCommentLine("// Create welcome banner") self.emitIndentedLine("this._serviceHello = new BiLabel();") self.emitIndentedLine("var lBorder = new BiBorder();") self.emitIndentedLine("lBorder.setBottomStyle(\"groove\");") self.emitIndentedLine("lBorder.setBottomWidth(2);") self.emitIndentedLine("this._serviceHello.setBorder(lBorder);") self.emitIndentedLine("this._serviceHello.setPadding(5,5);") self.emitIndentedLine("this._serviceHello.setBackColor(\"white\");") self.emitIndentedLine("this._serviceHello.setLocation(0,0);") self.emitIndentedLine("this._serviceHello.setRight(0);") self.emitIndentedLine("this._serviceHello.setHeight(170);") self.emitIndentedLine("this._serviceHello.setWrap(true);") self.emitIndentedLine("this._serviceHello.setOverflowY(\"auto\");") self.emitIndentedLine("this._serviceHello.setHtml(\"<H2><FONT COLOR=\\\"DARKGRAY\\\">" + lWelcomeBannerTitle + "</FONT></H2>" + lWelcomeBannerText + "\");"); self.emitIndentedLine("application.getWindow().add(this._serviceHello);") self.emitIndentedLine("") self.emitIndentedCommentLine("// Create services list box") self.emitIndentedLine("this._serviceList = new BiList();") self.emitIndentedLine("this._serviceList.setLocation(0, 175);") self.emitIndentedLine("this._serviceList.setWidth(290);") self.emitIndentedLine("this._serviceList.setBottom(0);") self.emitIndentedLine("this._serviceList.addEventListener(\"change\", this._handleServiceFormChange, this);") self.emitIndentedLine("application.getWindow().add(this._serviceList);") self.emitIndentedLine("") # Emit code to create the web service if self.__oldWs: self.emitIndentedLine("this._webService = new BiWebService();") self.emitIndentedLine("var lThis = this;") self.emitIndentedLine("this._webService.onreadystatechange = function () { lThis.onWebServiceStateChanged(); };") else: self.emitIndentedLine("this._webService = new BiWebService2();") self.emitIndentedLine("this._loadServices();"); self.emitIndentedLine("") self.endClassCtor() # Emit WebService component state change event handler, to start loading web services when the component is # done loading. if self.__oldWs: self.startClassMethod("onWebServiceStateChanged", [], "Handle a notification from the WebService component that it's loaded and ready for work; " + "start loading web services.") self.emitIndentedCommentLine("// If we've switched to a ready-to-run state,") self.emitIndentedLine("if ( this._webService.readyState == \"complete\" )") self.startBlock() else: self.startClassMethod("_loadServices", [], "Start loading web services.") # Emit code to add service forms to the list; these were accumulated in __serviceTabPaneClasses # during code generation self.emitIndentedCommentLine("// Fill services list box") for lServiceForm in self.__serviceTabPaneClasses.keys(): lServiceFormClass = self.__serviceTabPaneClasses[lServiceForm] self.emitIndentedLine("this.addServiceForm(new " + lServiceFormClass + "(this._webService), \"" + lServiceForm + "\");") if self.__oldWs: self.endBlock() self.endClassMethod() # Generate the on-change event handler for the services list self.startClassMethod("_handleServiceFormChange", [("aEvt", "Event to handle")], "Event handler for service form listbox change event.") self.emitIndentedCommentLine("// Hide all service forms, ") self.emitIndentedLine("for(var lFormIdx=0; lFormIdx<this._serviceForms.length; lFormIdx++)") self.startBlock() self.emitIndentedLine("this._serviceForms[lFormIdx].setVisible(false);") self.endBlock() self.emitIndentedLine("") self.emitIndentedCommentLine("// Except the newly selected one.") self.emitIndentedLine("this._serviceList.getSelectedItem()._form.setVisible(true);") self.endClassMethod() # Generate addServiceForm -- a method for register a service form and adding it to the main application # window self.startClassMethod("addServiceForm", [ ("aForm", "Form to add to list of forms"), ("aService", "Name of service for which form was added") ], "Add a form for operating a WebService to the window and to the forms selection list.") self.emitIndentedCommentLine("// Layout service form") self.emitIndentedLine("aForm.setLocation(300, 175);") self.emitIndentedLine("aForm.setRight(0); aForm.setBottom(0);") self.emitIndentedLine("aForm.setVisible(false);") self.emitIndentedLine("") self.emitIndentedCommentLine("// Add and register service form") self.emitIndentedLine("application.getWindow().add(aForm);") self.emitIndentedLine("this._serviceForms.unshift(aForm);") self.emitIndentedLine("") self.emitIndentedCommentLine("// Add service entry to services list box") self.emitIndentedLine("var lFormItem = new BiListItem(aService);") self.emitIndentedLine("lFormItem._form = aForm;") self.emitIndentedLine("this._serviceList.add(lFormItem);") self.endClassMethod() self.emitIndentedLine("") # Generate the "main" function of our application self.emitIndentedLine(lAppClass + ".main = function() { new " + lAppClass + "(); }") # Create ADF file referring to sub and self self.genAdfFile() # Create HTML file to launch the ADF file. self.genHtmlFile() super(BiWsdlBiAppCodeGen, self).endGen() def startService(self, aServiceName): super(BiWsdlBiAppCodeGen, self).startService(aServiceName) self.__currentSvcFormName = "BiWsApp" + self.convertQNameToJName(aServiceName) + "Form" self.__currentSvcPortPages = [] # Start region in code; we don't emit any real code but rather accumulate a list of # ports in the service; endService does the real job self.emitIndentedLine("// #region Components for service " + aServiceName + " UI") self.emitIndentedLine("") def startPort(self, aPortName): super(BiWsdlBiAppCodeGen, self).startPort(aPortName) self.__currentSvcPortPageClass = "BiWsApp" + self.convertQNameToJName(self.getCurrentService()) + "_" + self.convertQNameToJName(aPortName) + "Page" self.__portMethodInvokerClasses = [] # Start region in code; we don't emit any real code but rather accumulate a list of # methods in the service; endPort does the real job self.emitIndentedLine("// #region Components for Port " + aPortName); self.emitIndentedLine(""); def endPort(self, aPortName): super(BiWsdlBiAppCodeGen, self).endPort(aPortName) # Generate port page class for port: self.startClassCtor(self.__currentSvcPortPageClass, [ ("aBiWs", "Web service stub to use for invoking methods") ], "WsPortTabPage", self.__currentSvcPortPageClass + " implements a tab page for invoking operations " + "of the " + aPortName + " port of the " + self.getCurrentService() + " service.") self.emitIndentedLine("WsPortTabPage.call(this, \"" + aPortName + "\", aBiWs);") self.emitIndentedLine("") # Add method invokers in constructor self.emitIndentedCommentLine("// Add method invokers.") for lMethodInvoker in self.__portMethodInvokerClasses: self.emitIndentedLine("this.addMethodInvoker(new " + lMethodInvoker + "(aBiWs));") self.endClassCtor() self.emitIndentedLine("// #endregion"); self.emitLine(""); # Record port page in list of port pages for service tab pane. self.__currentSvcPortPages.append(self.__currentSvcPortPageClass) def endService(self, aServiceName): super(BiWsdlBiAppCodeGen, self).endService(aServiceName) # Generate a service invocation form (based on a tab pane) for the service: self.startClassCtor(self.__currentSvcFormName, [("aBiWs","BiWebService instance to use to access the service.")], "BiTabPane", "A component presenting UI allowing the user to operate the " + aServiceName + " service.") self.emitIndentedLine("BiTabPane.call(this);") self.emitIndentedLine(""); self.emitIndentedLine("this._ws = new " + BiWsdlBiJsStubCodeGen.getStubClassName(aServiceName) + "(aBiWs, DEFAULT_WSDL_PATH);") self.emitIndentedLine(""); # Add port invocation pages generated for this service in constructor self.emitIndentedCommentLine("// Add pages for ports") for lPortClass in self.__currentSvcPortPages: self.emitIndentedLine("this.add(new " + lPortClass + "(this._ws))") self.endClassCtor() self.__serviceTabPaneClasses[aServiceName] = self.__currentSvcFormName def genMethod(self, aName, aArgs, aArgTypes): lClassName = self.convertQNameToJName(self.getCurrentService()) + "_" + self.convertQNameToJName(self.getCurrentPort()) + "_" + self.convertQNameToJName(aName) + "_Invoker" lHeight = 0; # Generate an operation invoker component, encapsulating all MMI controls that allow the user to invoke # a single port operations. self.startClassCtor(lClassName, [("aBiWs", "Web service stub to use to invoke the " + aName + " operation.")], "WsOpInvoker", "A component encapsulating the necessary MMI for invoking the " + aName + " operation.") self.emitIndentedLine("WsOpInvoker.call(this);") self.emitIndentedLine("") self.emitIndentedLine("var lCurrentY = 0;") # Add title component to invoker self.emitIndentedCommentLine("// Add title for operation controls") self.emitIndentedLine("var lTitle=new BiDlgSep(\"" + aName + " \");")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -