summaryrefslogtreecommitdiff
path: root/rb/demo/Ice/value/Client.rb
diff options
context:
space:
mode:
Diffstat (limited to 'rb/demo/Ice/value/Client.rb')
-rw-r--r--rb/demo/Ice/value/Client.rb266
1 files changed, 133 insertions, 133 deletions
diff --git a/rb/demo/Ice/value/Client.rb b/rb/demo/Ice/value/Client.rb
index ced5ef20c97..51f5d210e66 100644
--- a/rb/demo/Ice/value/Client.rb
+++ b/rb/demo/Ice/value/Client.rb
@@ -14,7 +14,7 @@ Ice::loadSlice('Value.ice')
module PrinterI_mixin
def printBackwards(current=nil)
- puts message.reverse
+ puts message.reverse
end
end
@@ -26,25 +26,25 @@ class DerivedPrinterI < Demo::DerivedPrinter
include PrinterI_mixin
def printUppercase(current=nil)
- puts derivedMessage.upcase
+ puts derivedMessage.upcase
end
end
class ObjectFactory
def create(type)
- if type == "::Demo::Printer"
- return PrinterI.new
- end
+ if type == "::Demo::Printer"
+ return PrinterI.new
+ end
- if type == "::Demo::DerivedPrinter"
- return DerivedPrinterI.new
- end
+ if type == "::Demo::DerivedPrinter"
+ return DerivedPrinterI.new
+ end
- fail "unknown type"
+ fail "unknown type"
end
def destroy
- # Nothing to do
+ # Nothing to do
end
end
@@ -65,129 +65,129 @@ class Client < Ice::Application
#
Ice::Application::callbackOnInterrupt
- base = Ice::Application::communicator().propertyToProxy('Value.Initial')
- initial = Demo::InitialPrx::checkedCast(base)
- if not initial
- puts $0 + ": invalid proxy"
- return false
- end
-
- puts "\n"\
- "Let's first transfer a simple object, for a class without\n"\
- "operations, and print its contents. No factory is required\n"\
- "for this.\n"\
- "[press enter]"
- STDIN.readline
-
- simple = initial.getSimple()
- puts "==> " + simple.message
-
- puts "\n"\
- "Yes, this worked. Now let's try to transfer an object for a class\n"\
- "with operations as type ::Demo::Printer, without installing a factory\n"\
- "first. This should give us a `no factory' exception.\n"\
- "[press enter]"
- STDIN.readline
-
- begin
- printer, printerProxy = initial.getPrinter()
- puts $0 + ": Did not get the expected NoObjectFactoryException!"
- exit(false)
- rescue Ice::NoObjectFactoryException => ex
- puts "==> " + ex
- end
-
- puts "\n"\
- "Yep, that's what we expected. Now let's try again, but with\n"\
- "installing an appropriate factory first. If successful, we print\n"\
- "the object's content.\n"\
- "[press enter]"
- STDIN.readline
-
- factory = ObjectFactory.new
- Ice::Application::communicator().addObjectFactory(factory, "::Demo::Printer")
-
- printer, printerProxy = initial.getPrinter()
- puts "==> " + printer.message
-
- puts "\n"\
- "Cool, it worked! Let's try calling the printBackwards() method\n"\
- "on the object we just received locally.\n"\
- "[press enter]"
- STDIN.readline
-
- print "==> "
- printer.printBackwards()
-
- puts "\n"\
- "Now we call the same method, but on the remote object. Watch the\n"\
- "server's output.\n"\
- "[press enter]"
- STDIN.readline
-
- printerProxy.printBackwards()
-
- puts "\n"\
- "Next, we transfer a derived object from the server as a base\n"\
- "object. Since we haven't yet installed a factory for the derived\n"\
- "class, the derived class (::Demo::DerivedPrinter) is sliced\n"\
- "to its base class (::Demo::Printer).\n"\
- "[press enter]"
- STDIN.readline
-
- derivedAsBase = initial.getDerivedPrinter()
- puts "==> The type ID of the received object is \"" + derivedAsBase.ice_id() + "\""
- fail unless derivedAsBase.ice_id() == "::Demo::Printer"
-
- puts "\n"\
- "Now we install a factory for the derived class, and try again.\n"\
- "Because we receive the derived object as a base object, we\n"\
- "we need to do a dynamic_cast<> to get from the base to the derived object.\n"\
- "[press enter]"
- STDIN.readline
-
- Ice::Application::communicator().addObjectFactory(factory, "::Demo::DerivedPrinter")
-
- derived = initial.getDerivedPrinter()
- puts "==> The type ID of the received object is \"" + derived.ice_id() + "\""
-
- puts "\n"\
- "Let's print the message contained in the derived object, and\n"\
- "call the operation printUppercase() on the derived object\n"\
- "locally.\n"\
- "[press enter]"
- STDIN.readline
-
- puts "==> " + derived.derivedMessage
- print "==> "
- derived.printUppercase()
-
- puts "\n"\
- "Finally, we try the same again, but instead of returning the\n"\
- "derived object, we throw an exception containing the derived\n"\
- "object.\n"\
- "[press enter]"
- STDIN.readline
-
- begin
- initial.throwDerivedPrinter()
- puts $0 + "Did not get the expected DerivedPrinterException!"
- exit(false)
- rescue Demo::DerivedPrinterException => ex
- derived = ex.derived
- fail unless derived
- end
-
- puts "==> " + derived.derivedMessage
- print "==> "
- derived.printUppercase()
-
- puts "\n"\
- "That's it for this demo. Have fun with Ice!"
-
- initial.shutdown()
-
- return true
+ base = Ice::Application::communicator().propertyToProxy('Value.Initial')
+ initial = Demo::InitialPrx::checkedCast(base)
+ if not initial
+ puts $0 + ": invalid proxy"
+ return false
+ end
+
+ puts "\n"\
+ "Let's first transfer a simple object, for a class without\n"\
+ "operations, and print its contents. No factory is required\n"\
+ "for this.\n"\
+ "[press enter]"
+ STDIN.readline
+
+ simple = initial.getSimple()
+ puts "==> " + simple.message
+
+ puts "\n"\
+ "Yes, this worked. Now let's try to transfer an object for a class\n"\
+ "with operations as type ::Demo::Printer, without installing a factory\n"\
+ "first. This should give us a `no factory' exception.\n"\
+ "[press enter]"
+ STDIN.readline
+
+ begin
+ printer, printerProxy = initial.getPrinter()
+ puts $0 + ": Did not get the expected NoObjectFactoryException!"
+ exit(false)
+ rescue Ice::NoObjectFactoryException => ex
+ puts "==> " + ex
+ end
+
+ puts "\n"\
+ "Yep, that's what we expected. Now let's try again, but with\n"\
+ "installing an appropriate factory first. If successful, we print\n"\
+ "the object's content.\n"\
+ "[press enter]"
+ STDIN.readline
+
+ factory = ObjectFactory.new
+ Ice::Application::communicator().addObjectFactory(factory, "::Demo::Printer")
+
+ printer, printerProxy = initial.getPrinter()
+ puts "==> " + printer.message
+
+ puts "\n"\
+ "Cool, it worked! Let's try calling the printBackwards() method\n"\
+ "on the object we just received locally.\n"\
+ "[press enter]"
+ STDIN.readline
+
+ print "==> "
+ printer.printBackwards()
+
+ puts "\n"\
+ "Now we call the same method, but on the remote object. Watch the\n"\
+ "server's output.\n"\
+ "[press enter]"
+ STDIN.readline
+
+ printerProxy.printBackwards()
+
+ puts "\n"\
+ "Next, we transfer a derived object from the server as a base\n"\
+ "object. Since we haven't yet installed a factory for the derived\n"\
+ "class, the derived class (::Demo::DerivedPrinter) is sliced\n"\
+ "to its base class (::Demo::Printer).\n"\
+ "[press enter]"
+ STDIN.readline
+
+ derivedAsBase = initial.getDerivedPrinter()
+ puts "==> The type ID of the received object is \"" + derivedAsBase.ice_id() + "\""
+ fail unless derivedAsBase.ice_id() == "::Demo::Printer"
+
+ puts "\n"\
+ "Now we install a factory for the derived class, and try again.\n"\
+ "Because we receive the derived object as a base object, we\n"\
+ "we need to do a dynamic_cast<> to get from the base to the derived object.\n"\
+ "[press enter]"
+ STDIN.readline
+
+ Ice::Application::communicator().addObjectFactory(factory, "::Demo::DerivedPrinter")
+
+ derived = initial.getDerivedPrinter()
+ puts "==> The type ID of the received object is \"" + derived.ice_id() + "\""
+
+ puts "\n"\
+ "Let's print the message contained in the derived object, and\n"\
+ "call the operation printUppercase() on the derived object\n"\
+ "locally.\n"\
+ "[press enter]"
+ STDIN.readline
+
+ puts "==> " + derived.derivedMessage
+ print "==> "
+ derived.printUppercase()
+
+ puts "\n"\
+ "Finally, we try the same again, but instead of returning the\n"\
+ "derived object, we throw an exception containing the derived\n"\
+ "object.\n"\
+ "[press enter]"
+ STDIN.readline
+
+ begin
+ initial.throwDerivedPrinter()
+ puts $0 + "Did not get the expected DerivedPrinterException!"
+ exit(false)
+ rescue Demo::DerivedPrinterException => ex
+ derived = ex.derived
+ fail unless derived
+ end
+
+ puts "==> " + derived.derivedMessage
+ print "==> "
+ derived.printUppercase()
+
+ puts "\n"\
+ "That's it for this demo. Have fun with Ice!"
+
+ initial.shutdown()
+
+ return true
end
end