You call the Session::lookup method to return a factory for proxy object references. The signature of Session::lookup is:
SessionManager::Factory_var lookup("name")
Session::lookup takes a string that specifies
the name of the component to instantiate. A component’s
default name is the EAServer package name and the component name,
separated by a slash as in calculator/calc.
However, a different name can be specified with the component’s com.sybase.jaguar.component.naming
property.
For example, you can specify a logical name, such as USA/MyCompany/FinanceServer/Payroll.
For more information on configuring the naming service, see Chapter
5, “Naming Services,” in the EAServer
System Administration Guide.
Session::lookup returns a factory for component proxies. Call the Factory::create method to obtain proxies for the component. This method returns a org.omg.CORBA.Object reference. Call _narrow to convert the object reference into an instance of the stub class for the component.
The code to call Session::factory and Factory::create looks like this:
... // In this example, the component is named // Repository and is installed in // the EAServer package. Object_var obj = session->lookup("Jaguar/Repository"); SessionManager::Factory_var repoFactory = SessionManager::Factory::_narrow(obj); obj = repoFactory->create(); Jaguar::Repository_var repository = Jaguar::Repository::_narrow(obj); // Verify that we really have an instance. if (CORBA::is_nil(repository)) { cout << "ERROR: Null instance for component."; }
Calling Session.lookup in server code
When called from server code, Session::lookup resolves
the component name by calling the name service, which gives preference
to a local component instance if the component is installed on the
same server. However, the use of a locally installed component is
not guaranteed. To ensure that a local implementation is used, specify
the name as local:package/component
, where package is
the package name and component is the component
name, for example, local:CtsSecurity/SessionInfo
.
When you specify the local: prefix, the lookup call
bypasses the name service and returns a local instance if the component
is installed in the same server. The call fails if the specified component
is not installed in the same server..
Copyright © 2005. Sybase Inc. All rights reserved. |