2
# Defines ParserWriterChooseMixin, which makes it possible to choose a
3
# different XML writer and/or XML parser then the default one.
4
# The Mixin is used in client.rb (class Client) and server.rb (class
7
# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
9
# $Id: utils.rb 11708 2007-02-12 23:01:19Z shyouhei $
15
# This module enables a user-class to be marshalled
16
# by XML-RPC for Ruby into a Hash, with one additional
17
# key/value pair "___class___" => ClassName
23
module ParserWriterChooseMixin
25
def set_writer(writer)
26
@create = Create.new(writer)
30
def set_parser(parser)
38
# if set_writer was not already called then call it now
40
set_writer(Config::DEFAULT_WRITER.new)
46
# if set_parser was not already called then call it now
48
set_parser(Config::DEFAULT_PARSER.new)
53
end # module ParserWriterChooseMixin
59
# base class for Service Interface definitions, used
60
# by BasicServer#add_handler
64
attr_reader :prefix, :methods
66
def initialize(prefix)
71
def add_method(sig, help=nil, meth_name=nil)
73
sig = [sig] if sig.kind_of? String
75
sig = sig.collect do |s|
76
name, si = parse_sig(s)
77
raise "Wrong signatures!" if mname != nil and name != mname
82
@methods << [mname, meth_name || mname, sig, help]
85
private # ---------------------------------
89
if sig =~ /^\s*(\w+)\s+([^(]+)(\(([^)]*)\))?\s*$/
92
$4.split(",").each {|i| params << i.strip} if $4 != nil
95
raise "Syntax error in signature"
99
end # class BasicInterface
102
# class which wraps a Service Interface definition, used
103
# by BasicServer#add_handler
105
class Interface < BasicInterface
106
def initialize(prefix, &p)
107
raise "No interface specified" if p.nil?
112
def get_methods(obj, delim=".")
113
prefix = @prefix + delim
114
@methods.collect { |name, meth, sig, help|
115
[prefix + name, obj.method(meth).to_proc, sig, help]
119
private # ---------------------------------
125
end # class Interface
127
class PublicInstanceMethodsInterface < BasicInterface
128
def initialize(prefix)
132
def get_methods(obj, delim=".")
133
prefix = @prefix + delim
134
obj.class.public_instance_methods(false).collect { |name|
135
[prefix + name, obj.method(name).to_proc, nil, nil]
145
# short-form to create a Service::Interface
147
def self.interface(prefix, &p)
148
Service::Interface.new(prefix, &p)
151
# short-cut for creating a PublicInstanceMethodsInterface
152
def self.iPIMethods(prefix)
153
Service::PublicInstanceMethodsInterface.new(prefix)
157
module ParseContentType
158
def parse_content_type(str)
159
a, *b = str.split(";")