A Java stub implements the Java version for one of the EAServer component’s IDL interfaces. Call the Session.lookup method to obtain a factory for stub instances. The signature of Session.lookup is:
SessionManager.Factory lookup(String 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. You must call the narrow method in the IDL interface’s generated helper class to convert this to an instance of the stub class for the component’s IDL interface. If the component instance does not implement the requested interface, the narrow method returns a null object reference.
Session.lookup can throw these CORBA standard exceptions:
NO_PERMISSION The user is not authorized to instantiate the requested component.
OBJECT_NOT_EXIST The server component cannot be instantiated. Verify that:
The specified component is installed in the specified package.
The specified package is listed in the server’s Start Modules property.
The Java class, Windows DLL, or UNIX shared library that implements the component is available.
The code to call Session.lookup and Factory.create looks like this:
import org.omg.CORBA.*; import SessionManager.*; import java.awt.*; import Calculator.*; // Package for Java stubs // for this example, matches // IDL module name for the // component’s interface. public class myApplet extends Applet { Session session; ... deleted code that created Session instance ... // // In this example, the component is named calc // and is installed in the EAServer package // calculator. calcHelper.narrow() verifies that // the returned object is of the appropriate // type, then returns a Calculator.Calc instance // try { Factory fact = FactoryHelper.narrow( session.lookup("calculator/calc")); Calc c =
CalcHelper.narrow(fact.create()); } catch (org.omg.CORBA.OBJECT_NOT_EXIST one) {
// Tell the user to contact the server // administrator ... report the error ... } catch (org.omg.CORBA.NO_PERMISSION np) { // Tell the user they are not authorized ... report the error ... } catch (org.omg.CORBA.SystemException se) { // Catch-all clause for any CORBA system // exception that was not explicitly caught // above. ... report the error ... }
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..