Java Reference
In-Depth Information
objects? The simple answer is that the server will create a factory object for
each factory interface and register that object with the ORB. Clients can then
get a reference to the factory object and use the creation method of this object
to create CORBA application objects. Assuming that a client has obtained a
reference to the AccountFactory object created by the server and that this refer-
ence is held in the variable acctFactoryRef , the client could create an Account
object with account number 12345 and account name 'John Andrews' with the
following code:
Account acct = acctFactoryRef.createAccount(
12345,"John Andrews");
For non-persistent objects, methods to destroy CORBA objects should also be
defi ned (though we shall not be doing so).
To illustrate the use of factory interfaces and their associated factory objects, the
rest of this section will be taken up by a specifi c example.
We shall consider how Java IDL may be used to provide platform-independent
access to stock items. Although only one item of stock will be used for illustration
purposes, this could easily be extended to as many items of stock as might be
required by a real-world application. The same basic steps will be required here as
were used in the simple CORBA application of the last section, and the same num-
bering will be used here to indicate those steps.
1. Create the IDL fi le.
The fi le will be called StockItem.idl and will hold a module called Sales . This module
will contain interfaces called StockItem and StockItemFactory . The former will hold
the attributes and operations associated with an individual item of stock. For simplic-
ity's sake, the attributes will be stock code and current level, while the operations will
be ones to increase and decrease the stock level of this particular stock item. Since the
stock code should never be changed, it will be declared read- only. The StockItemFactory
interface will hold method createStockItem , which will be used to create a StockItem
object with specifi ed stock code and stock level (as indicated by the parameters of this
operation). The contents of StockItem.idl are shown below.
module Sales
interface StockItem
readonly attribute string code;
attribute long currentLevel;
long addStock(in long incNumber);
long removeStock(in long decNumber);
interface StockItemFactory
Search WWH ::

Custom Search