/[papo]/gnue/common/src/commdrivers/xmlrpc/RpcDoc.py
ViewVC logotype

Diff of /gnue/common/src/commdrivers/xmlrpc/RpcDoc.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by charlie, Fri Jun 28 19:43:51 2002 UTC revision 1.2 by styxman, Fri Nov 15 15:32:55 2002 UTC
# Line 52  Commands: doc       list all methods and Line 52  Commands: doc       list all methods and
52                      of the .grpc file in c                      of the .grpc file in c
53            doc-php   create example code for all methods and objects            doc-php   create example code for all methods and objects
54                      of the .grpc file in PHP                      of the .grpc file in PHP
55              js-stub   creates stub file to allow direct access to all methods
56                        and objects defined in the .grpc file by an Javascript
57                        client
58            help      prints this help message            help      prints this help message
59                        
60  """    """  
# Line 96  Commands: doc       list all methods and Line 99  Commands: doc       list all methods and
99        rpcdef = GComm.loadDefinition(arguments[0])        rpcdef = GComm.loadDefinition(arguments[0])
100    
101      except IndexError:      except IndexError:
102        print _("'doc' command expects a .grpc file as its argument.")        print _("'doc-php' command expects a .grpc file as its argument.")
103        sys.exit()        sys.exit()
104    
105      gendoc(rpcdef, outfile)      print "PHP code generation not implemented yet."
106    #    gendoc(rpcdef, outfile)
107    
108      elif command == 'js-stub':
109    
110        try:
111          rpcdef = GComm.loadDefinition(arguments[0])
112    
113        except IndexError:
114          print _("'js-stub' command expects a .grpc file as its argument.")
115          sys.exit()
116    
117        gendocJS(rpcdef, outfile)
118            
119    else:    else:
120      raise StandardError, _("Unrecognized XML-RPC doc command: %s") % command      raise StandardError, _("Unrecognized XML-RPC doc command: %s") % command
# Line 176  def _genC(object): Line 191  def _genC(object):
191      name=""                      name=""                
192    gloutfile.write(name + "\n")    gloutfile.write(name + "\n")
193    
194    ##
195    ##  Create Javascript exsample
196    ##
197    def gendocJS(rpcdef, outfile):
198    
199      outfile.write("// Javascript example\n")
200      outfile.write("// ==================\n\n")
201      outfile.write("include ( 'vcXMLRPC.js')\n")
202      
203      gloutfile= outfile
204      _genJs(rpcdef)
205    
206    
207    def _genJs(object):
208      if hasattr(object,'name'):
209        name=object.name
210        if hasattr(object,'_path'): # and hasattr(object._parent,'name'):
211          name=object._path+'_'+name
212      else:
213        name=""
214      if object._type=="RpObject" or object._type=="RpService":
215        gloutfile.write("function %s(host,handle) {\n" % name[1:])
216        gloutfile.write("     this.host=host\n")
217        gloutfile.write("     this.handle=handle\n")
218        if hasattr(object,'_children'):
219          for child in object._children:
220            child._path=name
221            if child._type=="RpMethod" or child._type=="RpAttribute":
222              _genJs(child)
223        gloutfile.write("}\n")
224        if hasattr(object,'_children'):
225          for child in object._children:
226            child._path=name
227            if child._type=="RpObject" or child._type=="RpService":
228              _genJs(child)
229        
230      elif object._type=="RpGnuRpc":
231        if hasattr(object,'_children'):
232          for child in object._children:
233            child._path=name
234            _genJs(child)
235        
236      elif object._type=="RpMethod":
237        # build attribut list
238        attr=""
239        delim=""
240        if hasattr(object,'_children'):
241          for child in object._children:
242            attr=attr+delim+child.name
243            delim=","
244            
245        gloutfile.write("     self.%s = function (%s) {\n" % (object.name,attr) )
246    
247        if object._parent._type=="RpObject":
248          procname="'['+this.handle+'].%s'" % object.name
249        else:
250          procname="'%s'" % string.join(string.split(name[1:],"_"),".")
251        
252        if len(attr):
253          procname=procname+","+attr
254          
255        ret="nothing"
256        if hasattr(object,"return"):
257          ret=getattr(object,"return")
258          
259        if ret[:1]=="<" and ret[-1:]==">":
260          
261          gloutfile.write("         handle=XMLRPC.call(this.host,%s);\n"
262                                    % procname)      
263          gloutfile.write("         return new %s(host,handle)" %
264                          string.join(string.split(ret[1:-1],"."),"_"))
265          
266        else:
267          gloutfile.write("         return XMLRPC.call(this.host,%s);\n"
268                                    % procname)
269          
270        gloutfile.write("     }\n")
271    
272    
273    
274  if __name__ == '__main__':  if __name__ == '__main__':
275    if len(sys.argv)<2:    if len(sys.argv)<2:

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26