Chapter 34 Creating and Using Jaguar Pseudocomponents


Instantiating pseudocomponents

To instantiate a pseudocomponent, call the ORB.object_to_string method, passing a URL that specifies the information required to load the component. Java, C++, and ActiveX all use a variation of this method.

Pseudocomponent object URLs

The object URL for a pseudocomponent specifies the shared library file or Java class that contains the implementation, the Jaguar package name, and the Jaguar component name.

Identifying a C++ pseudocomponent

To identify a C++ pseudocomponent, format a URL as follows:

pseudo://cpp/library/package/component
Where:

Identifying a Java pseudocomponent

To identify a Java pseudocomponent, format a URL as follows:

pseudo://java/java-package/jaguar-package/component
Where:

Instantiating pseudocomponents from Java

Java applications or Jaguar Java components can instantiate pseudocomponents implemented in Java or C++. Java applets cannot instantiate pseudocomponents. In order to instantiate a C++ pseudocomponent, the environment for a Java application must include all the settings required by the Jaguar C++ client runtime, and the location of the library must be specified in the system's library search path. Java stub classes for the pseudocomponent must be available.

You can instantiate a pseudocomponent any time after initializing and instantiating an ORB instance. Call the ORB.string_to_object method, passing a URL formatted as described in "Pseudocomponent object URLs". Narrow the returned object to an interface supported by the component. See Chapter 13, "Creating CORBA-Compatible Java Clients" for more information on the ORB interface and narrowing objects to an interface.

Example: instantiating a C++ pseudocomponent

The following fragment instantiates a pseudocomponent proxy for a C++ component in the DLL CppPseudo.dll that is installed in the package Demo and has component name PseudoCpp. The returned object is narrowed to Arithmetic interface. On UNIX platforms, this syntax also works for a shared library with base name "CppPseudo", as in CppPseudo.so.

String url = "pseudo://cpp/CppPseudo/Demo/PseudoCPP";
_comp = ArithmeticHelper.narrow(
orb.string_to_object(url) );

Example: instantiating a Java pseudocomponent

The following fragment instantiates a pseudocomponent proxy for a Java component. The implementation class and skeleton class are in the Java package Sample.PseudoComponents. The component is installed in the Jaguar package Demo and has component name PseudoJava. The returned object is narrowed to Arithmetic interface.

String url =   "pseudo://java/Sample.PseudoComponents/Demo/PseudoJava";
_comp = ArithmeticHelper.narrow(
orb.string_to_object(url) );

Instantiating pseudocomponents from C++

C++ standalone programs or Jaguar components can instantiate pseudocomponents implemented in C++. Pseudocomponents implemented in Java can be instantiated only by C++ components that are executing in a Jaguar server.

In order to instantiate a C++ pseudocomponent in a standalone program, the environment must include all the settings required by the Jaguar C++ client runtime, and the location of the library must be specified in the system's library search path.

You can instantiate a pseudocomponent any time after initializing and instantiating an ORB instance. Call the ORB.string_to_object method, passing a URL formatted as described in "Pseudocomponent object URLs". Narrow the returned object to an interface supported by the component. See Chapter 17, "Creating CORBA C++ Clients" for more information on the ORB interface and narrowing objects to an interface.

Example: instantiating a C++ pseudocomponent

The following fragment instantiates a pseudocomponent proxy for a C++ component in the DLL CppPseudo.dll that is installed in the package Demo and has component name PseudoCpp. The returned object is narrowed to PseudocomponentDemo::Arithmetic interface. On UNIX platforms, this syntax also works for a shared library with base name "CppPseudo", as in CppPseudo.so.

String url = "pseudo://cpp/CppPseudo/Demo/PseudoCPP";
obj = orb->string_to_object(url);
PseudocomponentDemo::Arithmetic_var arith =
PseudocomponentDemo::Arithmetic::_narrow(obj);

Example: instantiating a Java pseudocomponent

The following fragment instantiates a pseudocomponent proxy for a Java component. The implementation class and skeleton class are in the Java package Sample.PseudoComponents. The component is installed in the Jaguar package Demo and has component name PseudoJava. The returned object is narrowed to PseudocomponentDemo::Arithmetic interface.

String url =   "pseudo://java/Sample.PseudoComponents/Demo/PseudoJava";
obj = orb->string_to_object(url);
PseudocomponentDemo::Arithmetic_var arith =
PseudocomponentDemo::Arithmetic::_narrow(obj);

Debugging C++ pseudocomponents

Once loaded in your debugger, a C++ pseudocomponent can be debugged like any other shared library or DLL. However, since the library is not loaded until a client program instantiates the pseudocomponent, setting breakpoints is tricky. The procedure below allows you to set breakpoints and step into your method code.

Steps Debugging a C++ pseudocomponent

  1. Verify that the process is using the debug versions of the Jaguar libraries. For pseudocomponents executing in a Jaguar server, start the debug version of the server executable. For standalone programs, verify that the debug DLLs or libraries are ahead of the non-debug libraries in your system's library search path. (On UNIX platforms, the debug libraries are in the lib/debug directory of your client installation. On Windows, they are in the dll/debug directory.)

  2. Attach the program that is instantiating the pseudocomponent with your debugger. This can be a standalone client executable, or Jaguar server process.

    Alternatively, start the debugger to load the executable. For example, on UNIX, this command starts the dbx debugger and loads the debug server executable:
    dbx $JAGUAR/devbin/jagsrv ServerName


    As another example, on Windows NT this command starts the Microsoft Visual C++ debugger and loads the debug server executable:
    msdev %JAGUAR%\devbin\jagsrv ServerName


    In these examples, ServerName is the name of the Jaguar server. If you are using the preconfigured server rather than one that you created yourself, use "Jaguar".

  3. Set a breakpoint on the function jag_client_dbg_stop. This function executes every time the client runtime constructs a pseudocomponent instance. The jag_client_dbg_stop prototype is:
    void jag_client_dbg_stop(char *compName)


    The compName parameter specifies the name of the library or shared library that was just started. Several pseudocomponents may be loaded before yours. In the debugger, display the compName value when the jag_client_dbg_stop breakpoint is tripped, and monitor the value to determine when your component is loaded.

    Note   Make sure the jag_client_dbg_stop breakpoint is set before your client application instantiates any pseudocomponents.

  4. When your pseudocomponent's DLL is loaded, you can specify the method names as breakpoints and step into the method's code when it is invoked.


 


Copyright © 2000 Sybase, Inc. All rights reserved.