source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/wsdl/soap/standaloneServerStubCreator.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 2.5 KB
Line 
1# WSDL4R - Creating standalone server stub code from WSDL.
2# Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <[email protected]>.
3
4# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5# redistribute it and/or modify it under the same terms of Ruby's license;
6# either the dual license version in 2003, or any later version.
7
8
9require 'wsdl/info'
10require 'wsdl/soap/mappingRegistryCreator'
11require 'wsdl/soap/methodDefCreator'
12require 'wsdl/soap/classDefCreatorSupport'
13
14
15module WSDL
16module SOAP
17
18
19class StandaloneServerStubCreator
20 include ClassDefCreatorSupport
21
22 attr_reader :definitions
23
24 def initialize(definitions)
25 @definitions = definitions
26 end
27
28 def dump(service_name)
29 warn("- Standalone stub can have only 1 port for now. So creating stub for the first port and rests are ignored.")
30 warn("- Standalone server stub ignores port location defined in WSDL. Location is http://localhost:10080/ by default. Generated client from WSDL must be configured to point this endpoint manually.")
31 port = @definitions.service(service_name).ports[0]
32 dump_porttype(port.porttype.name)
33 end
34
35private
36
37 def dump_porttype(name)
38 class_name = create_class_name(name)
39 methoddef, types = MethodDefCreator.new(@definitions).dump(name)
40 mr_creator = MappingRegistryCreator.new(@definitions)
41
42 c1 = XSD::CodeGen::ClassDef.new(class_name)
43 c1.def_require("soap/rpc/standaloneServer")
44 c1.def_require("soap/mapping/registry")
45 c1.def_const("MappingRegistry", "::SOAP::Mapping::Registry.new")
46 c1.def_code(mr_creator.dump(types))
47 c1.def_code <<-EOD
48Methods = [
49#{methoddef.gsub(/^/, " ")}
50]
51 EOD
52 c2 = XSD::CodeGen::ClassDef.new(class_name + "App",
53 "::SOAP::RPC::StandaloneServer")
54 c2.def_method("initialize", "*arg") do
55 <<-EOD
56 super(*arg)
57 servant = #{class_name}.new
58 #{class_name}::Methods.each do |definitions|
59 opt = definitions.last
60 if opt[:request_style] == :document
61 @router.add_document_operation(servant, *definitions)
62 else
63 @router.add_rpc_operation(servant, *definitions)
64 end
65 end
66 self.mapping_registry = #{class_name}::MappingRegistry
67 EOD
68 end
69 c1.dump + "\n" + c2.dump + format(<<-EOD)
70
71 if $0 == __FILE__
72 # Change listen port.
73 server = #{class_name}App.new('app', nil, '0.0.0.0', 10080)
74 trap(:INT) do
75 server.shutdown
76 end
77 server.start
78 end
79 EOD
80 end
81end
82
83
84end
85end
Note: See TracBrowser for help on using the repository browser.