Java Reference
In-Depth Information
//'Downcast' the context reference…
NamingContext namingContext =
NamingContextHelper.narrow(objectRef);
//Create a NameComponent object for the
// StockItem interface…
NameComponent nameComp =
new NameComponent("Stock", "");
//Specify the path to the interface…
NameComponent[] stockPath = {nameComp};
//Get a reference to the interface (reusing
//existing reference)…
objectRef = namingContext.resolve(stockPath);
//'Downcast' the reference…
StockItem stockRef1 =
StockItemHelper.narrow(objectRef);
//Now use this reference to call methods of the
// StockItem object…
System.out.println("\nStock code: "
+ stockRef1.code());
System.out.println("Current level: "
+ stockRef1.currentLevel());
stockRef1.addStock(58);
System.out.println("\nNew level: "
+ stockRef1.currentLevel());
//Create a NameComponent object for the
// StockFactory interface…
NameComponent factoryNameComp =
new NameComponent("StockFactory", "");
//Specify the path to the interface…
NameComponent[] factoryPath =
{factoryNameComp};
//Get a reference to the interface (reusing
//existing reference)…
objectRef = namingContext.resolve(factoryPath);
//'Downcast' the reference…
StockItemFactory stockFactoryRef =
StockItemFactoryHelper.narrow(objectRef);
Search WWH ::




Custom Search