All Manuals > Developing Component Software with CORBA > 5 The Bank Client > 5.4 Defining the interfaces

NextPrevUpTopContentsIndex

5.4.1 Initializing and exiting account frames

Each time we make a new account interface we want to ensure two things:

An easy way to do this is to add an initialize-instance after method specialized on account-interface . (In Common Lisp, each call to make an instance of a given class is automatically followed by a call to initialize that instance; you are free to specialize the initialize-instance generic function on particular classes.)

(defmethod initialize-instance :after ((self account-interface)     &key)
  (with-slots (account-ref balance-field) self
    (when account-ref
      (setf (capi:display-pane-text balance-field)
            (format nil "~A" (op:balance account-ref))))))

Here, we encounter our first example of invoking a CORBA operation on a CORBA object. The Common Lisp variable account-ref , of class BankingDemo:account , contains a proxy for a CORBA account object on the server. The application (op:balance account-ref) invokes a stub method specialized on the proxy's class. The stub method forwards the request across the ORB to the actual object on the server.

The request is executed on the object in the server and the result passed back across the ORB to the stub method, which returns the value to the client as a corba:long . This value is then used to set the initial value of the balance field.

We can initialize the interface for a checking account in a similar way:

(defmethod initialize-instance :after (
     (self checking-account-interface)  &key)
  (with-slots (account-ref limit-field) self
    (when account-ref
      (setf (capi:display-pane-text limit-field)
            (format nil "~A" (op:limit account-ref))))))

Inheritance ensures that the method on account-interface is called which registers the interface and sets up its balance field; a call to the op:limit stub determines the initial value of its limit field.

For convenience, we define a generic function make-account-frame that makes the correct class of frame for a given account object reference:

(defmethod make-account-frame ((self BankingDemo:account) 
                                &key bank-interface title)
  (push-new-item bank-interface
                 title
                 (make-instance 'account-interface 
                                :account-ref self
                                :account-name title
                                :owner bank-interface)))
(defmethod make-account-frame ((self BankingDemo:checkingAccount)
                                &key bank-interface title)
  (push-new-item bank-interface
                 title
                 (make-instance 'checking-account-interface 
                                :account-ref self
                                :account-name title
                                :owner bank-interface)))

These methods simply dispatch on the class of the object reference to make an account-interface or checkingAccount-interface as appropriate.


Developing Component Software with CORBA - 29 Jul 2010

NextPrevUpTopContentsIndex