org.openorb.orb.rmi
Class UtilDelegateImpl

java.lang.Object
  |
  +--org.openorb.orb.rmi.UtilDelegateImpl
All Implemented Interfaces:
org.apache.avalon.framework.logger.LogEnabled, javax.rmi.CORBA.UtilDelegate

public class UtilDelegateImpl
extends java.lang.Object
implements javax.rmi.CORBA.UtilDelegate, org.apache.avalon.framework.logger.LogEnabled

This class provides a default implementation for javax.rmi.CORBA.UtilDelegate

Author:
Chris Wood

Constructor Summary
UtilDelegateImpl()
          Empty default constructor.
 
Method Summary
 java.lang.Object copyObject(java.lang.Object obj, org.omg.CORBA.ORB orb)
          The copyObject method is used by local stubs to copy an actual parameter, result object, or exception.
 java.lang.Object[] copyObjects(java.lang.Object[] obj, org.omg.CORBA.ORB orb)
          The copyObjects method is used by local stubs to copy any number of actual parameters, preserving sharing across parameters as necessary to support RMI/IDL semantics.
static javax.rmi.CORBA.UtilDelegate createUtilDelegate()
          This method creates one instance of the class per process.
 javax.rmi.CORBA.ValueHandler createValueHandler()
          This method returns a singleton instance of a class that implements the ValueHandler interface.
 void enableLogging(org.apache.avalon.framework.logger.Logger logger)
           
 java.lang.String getCodebase(java.lang.Class clz)
          The getCodebase method returns the Java codebase for the Class object clz as a space-separated list of URLs.
static boolean getCopyLocalObjects()
          Get the copyLocalObjects flag.
static boolean getIsLocalResult()
          Get the isLocalResult flag.
static boolean getLocalCodebaseOnly()
          Get the RMIClassloader flag.
 org.apache.avalon.framework.logger.Logger getLogger()
           
static boolean getProhibitIsLocalTest()
          Get the prohibitIsLocalTest flag.
 javax.rmi.CORBA.Tie getTie(java.rmi.Remote target)
          This method return the Tie object for an implementation object target, or null if no Tie is registered for the target object.
 boolean isLocal(javax.rmi.CORBA.Stub s)
          This method has the same semantics as the ObjectImpl's _is_local() method, except that it can throw a RemoteException.
 java.lang.Class loadClass(java.lang.String className, java.lang.String remoteCodebase, java.lang.Class loadingContext)
          The loadClass method loads a Java class object for the Java class name className, using additional information passed in the remoteCodebase and loader parameters.
 java.lang.Class loadClass(java.lang.String className, java.lang.String remoteCodebase, java.lang.ClassLoader loadingContext)
          The loadClass method loads a Java class object for the Java class name className, using additional information passed in the remoteCodebase and loader parameters.
static org.omg.CORBA.TypeCode lookupRuntimeTypeCode(java.lang.Object obj)
          Create typecode from runtime class.
 java.rmi.RemoteException mapSystemException(org.omg.CORBA.SystemException ex)
          The mapSystemException method maps a CORBA system exception to a java.rmi.RemoteException or a java.rmi.RuntimeException.The mapping is described in Section 1.4.8, Mapping CORBA System Exceptions to RMI Exceptions, on page 1-34.
 java.lang.Object readAny(org.omg.CORBA.portable.InputStream in)
          The readAny method reads a GIOP any from the input stream in and unmarshals it as a Java object, which is returned.
 void registerTarget(javax.rmi.CORBA.Tie tie, java.rmi.Remote target)
          The registerTarget method is needed to support unexportObject.
static void setCopyLocalObjects(boolean copy_local_objects)
          Set the copyLocalObjects flag.
static void setIsLocalResult(boolean is_local_result)
          Set the isLocalResult flag.
static void setLocalCodebaseOnly(boolean local_codebase_only)
          Set the RMIClassloader flag.
static void setProhibitIsLocalTest(boolean prohibit_is_local_test)
          Set the prohibitIsLocalTest flag.
 void unexportObject(java.rmi.Remote target)
          The unexportObject method deactivates an implementation object and removes its associated Tie from the table maintained by the Util class.
 java.rmi.RemoteException wrapException(java.lang.Throwable obj)
          The wrapException method wraps an exception thrown by an implementation method.
 void writeAbstractObject(org.omg.CORBA.portable.OutputStream out, java.lang.Object obj)
          The writeAbstractObject method is another similar utility method for use by stubs.
 void writeAny(org.omg.CORBA.portable.OutputStream out, java.lang.Object obj)
          The writeAny method writes the Java object obj to the output stream out in the form of a GIOP any.
 void writeRemoteObject(org.omg.CORBA.portable.OutputStream out, java.lang.Object obj)
          The writeRemoteObject method is a utility method for use by stubs when writing an RMI/IDL object reference to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UtilDelegateImpl

public UtilDelegateImpl()
Empty default constructor. Thi smust be provided because an instance is constructed from javax.rmi.CORBA.UtilDelegate.
Method Detail

createUtilDelegate

public static javax.rmi.CORBA.UtilDelegate createUtilDelegate()
This method creates one instance of the class per process.
Returns:
The UtilDelegate instance.

enableLogging

public void enableLogging(org.apache.avalon.framework.logger.Logger logger)
Specified by:
enableLogging in interface org.apache.avalon.framework.logger.LogEnabled

getLogger

public org.apache.avalon.framework.logger.Logger getLogger()

mapSystemException

public java.rmi.RemoteException mapSystemException(org.omg.CORBA.SystemException ex)
The mapSystemException method maps a CORBA system exception to a java.rmi.RemoteException or a java.rmi.RuntimeException.The mapping is described in Section 1.4.8, Mapping CORBA System Exceptions to RMI Exceptions, on page 1-34. If the mapped exception is an instance of java.rmi.RemoteException or a subclass, the mapped exception is returned; otherwise, it is thrown.
Specified by:
mapSystemException in interface javax.rmi.CORBA.UtilDelegate
Parameters:
ex - The CORBA system exception to map.
Returns:
The RemoteException to which the system exception is mapped.

writeAny

public void writeAny(org.omg.CORBA.portable.OutputStream out,
                     java.lang.Object obj)
The writeAny method writes the Java object obj to the output stream out in the form of a GIOP any. The contents of the GIOP any are determined by applying the Java to IDL mapping rules to the actual runtime type of obj. If obj is null, then it is written as follows: the TypeCode is tk_abstract_interface, the repository ID is IDL:omg.org/CORBA/AbstractBase:1.0, the name string is ???, and the any's value is a null abstract interface type (encoded as a boolean discriminant of false followed by along value of 0x00000000). This method writes the java object obj to the output stream out in the form of a GIOP any.
Specified by:
writeAny in interface javax.rmi.CORBA.UtilDelegate
Parameters:
out - The output stream to which the object is written.
obj - The object to be written to the stream.

readAny

public java.lang.Object readAny(org.omg.CORBA.portable.InputStream in)
The readAny method reads a GIOP any from the input stream in and unmarshals it as a Java object, which is returned. The following TypeCodes are valid for the GIOP any: tk_value, tk_value_box, tk_objref, and tk_abstract_interface. For each of these types, both null and non-null values are valid. If the TypeCode is anything other than these, a MARSHAL exception is thrown.
Specified by:
readAny in interface javax.rmi.CORBA.UtilDelegate
Parameters:
in - The input stream from which to read the object.
Returns:
The object read from the stream.

writeRemoteObject

public void writeRemoteObject(org.omg.CORBA.portable.OutputStream out,
                              java.lang.Object obj)
The writeRemoteObject method is a utility method for use by stubs when writing an RMI/IDL object reference to an output stream. If obj is a stub object, writeRemoteObject simply writes obj to out.write_Object. However, if obj is an exported RMI/IDL implementation object, then writeRemoteObject allocates (or reuses) a suitable Tie (see Section 1.4.4, Allocating Ties for Remote Values, on page 1-32), plugs together the tie with obj, and writes the object reference for the tie to out.write_Object. This method cannot be used to write a JRMP object reference to an output stream.
Specified by:
writeRemoteObject in interface javax.rmi.CORBA.UtilDelegate
Parameters:
out - The output stream to which to write the object to.
obj - The object to write to the stream.

writeAbstractObject

public void writeAbstractObject(org.omg.CORBA.portable.OutputStream out,
                                java.lang.Object obj)
The writeAbstractObject method is another similar utility method for use by stubs. If obj is a value object, or a stub object, writeAbstractObject simply writes obj to out.write_abstract_interface. However,ifobj is an exported RMI/IDL implementation object, then writeAbstractObject allocates (or reuses) a suitable Tie (see Section 1.4.4, Allocating Ties for Remote Values, on page 1-32), plugs together the tie with obj, and writes the object reference for the tie to the out.write_abstract_interface. This method cannot be used to write a JRMP object reference to an output stream.
Specified by:
writeAbstractObject in interface javax.rmi.CORBA.UtilDelegate
Parameters:
out - The output stream to which to write the obejct to.
obj - The object to be written to the stream.

registerTarget

public void registerTarget(javax.rmi.CORBA.Tie tie,
                           java.rmi.Remote target)
The registerTarget method is needed to support unexportObject. Because unexportObject takes a target implementation object as its parameter, it is necessary for the Util class to maintain a table mapping target objects back to their associated Ties. It is the responsibility of the code that allocates a Tie to also call the registerTarget method to notify the Util class of the target object for a given tie. The registerTarget method will call the Tie.setTarget method to notify the tie object of its target object.
Specified by:
registerTarget in interface javax.rmi.CORBA.UtilDelegate
Parameters:
tie - The tie that is connected to the target object.
target - The target object.

unexportObject

public void unexportObject(java.rmi.Remote target)
The unexportObject method deactivates an implementation object and removes its associated Tie from the table maintained by the Util class. If the object is not currently exported or could not be deactivated, a NoSuchObjectException is thrown.
Specified by:
unexportObject in interface javax.rmi.CORBA.UtilDelegate
Parameters:
target - The target object to deactivate.

getTie

public javax.rmi.CORBA.Tie getTie(java.rmi.Remote target)
This method return the Tie object for an implementation object target, or null if no Tie is registered for the target object.
Specified by:
getTie in interface javax.rmi.CORBA.UtilDelegate
Parameters:
target - The target object to get the tie for.
Returns:
The tie for the target object.

createValueHandler

public javax.rmi.CORBA.ValueHandler createValueHandler()
This method returns a singleton instance of a class that implements the ValueHandler interface.
Specified by:
createValueHandler in interface javax.rmi.CORBA.UtilDelegate
Returns:
The created value handler implementation.

wrapException

public java.rmi.RemoteException wrapException(java.lang.Throwable obj)
The wrapException method wraps an exception thrown by an implementation method. It returns the corresponding client-side exception. See Section 1.4.8.1, Mapping of UnknownExceptionInfo Service Context, on page 1-35 for details.
Specified by:
wrapException in interface javax.rmi.CORBA.UtilDelegate
Parameters:
obj - The throwable object to wrap into a RemoteException.
Returns:
The RemoteException by which the Throwable is wrapped.

copyObject

public java.lang.Object copyObject(java.lang.Object obj,
                                   org.omg.CORBA.ORB orb)
                            throws java.rmi.RemoteException
The copyObject method is used by local stubs to copy an actual parameter, result object, or exception. The copyObject and copyObjects methods ensure that remote call semantics are observed for local calls. They observe copy semantics for value objects that are equivalent to marshaling, and they handle remote objects correctly. Stubs must either call these methods or generate inline code to provide equivalent semantics.
Specified by:
copyObject in interface javax.rmi.CORBA.UtilDelegate
Parameters:
obj - The object to copy.
orb - The ORB where the object is running on.
Returns:
The copy of the object obj.
Throws:
java.rmi.RemoteException - When an error occurs.

copyObjects

public java.lang.Object[] copyObjects(java.lang.Object[] obj,
                                      org.omg.CORBA.ORB orb)
                               throws java.rmi.RemoteException
The copyObjects method is used by local stubs to copy any number of actual parameters, preserving sharing across parameters as necessary to support RMI/IDL semantics. The actual parameter Object[] array holds the method parameter objects that need to be copied, and the result Object[] array holds the copied results.
Specified by:
copyObjects in interface javax.rmi.CORBA.UtilDelegate
Parameters:
obj - An array of objects to copy.
orb - The orb on which the objects are running.
Returns:
The copies of the objects obj.
Throws:
java.rmi.RemoteException - When an error occurs.

isLocal

public boolean isLocal(javax.rmi.CORBA.Stub s)
                throws java.rmi.RemoteException
This method has the same semantics as the ObjectImpl's _is_local() method, except that it can throw a RemoteException.
Specified by:
isLocal in interface javax.rmi.CORBA.UtilDelegate
Parameters:
s - The stub to check.
Returns:
True if the object is a local object, false otherwise.
Throws:
java.rmi.RemoteException - When an error occurs.

getCodebase

public java.lang.String getCodebase(java.lang.Class clz)
The getCodebase method returns the Java codebase for the Class object clz as a space-separated list of URLs. See Section 1.4.9.2, Codebase Selection, on page 1-35 for details.
Specified by:
getCodebase in interface javax.rmi.CORBA.UtilDelegate
Parameters:
clz - The class for which to get the codebase.
Returns:
A string separated list or URLs.

loadClass

public java.lang.Class loadClass(java.lang.String className,
                                 java.lang.String remoteCodebase,
                                 java.lang.Class loadingContext)
                          throws java.lang.ClassNotFoundException
The loadClass method loads a Java class object for the Java class name className, using additional information passed in the remoteCodebase and loader parameters. See Section 1.4.9.5, Codebase Usage, on page 1-37 for details. This method also checks that the loaded class is compatable with the class argument.
Specified by:
loadClass in interface javax.rmi.CORBA.UtilDelegate
Parameters:
className - The class to load.
remoteCodebase - A list of URLs.
loadingContext - The loading context.
Returns:
The loaded class type.
Throws:
java.lang.ClassNotFoundException - When the class could not be loaded.

loadClass

public java.lang.Class loadClass(java.lang.String className,
                                 java.lang.String remoteCodebase,
                                 java.lang.ClassLoader loadingContext)
                          throws java.lang.ClassNotFoundException
The loadClass method loads a Java class object for the Java class name className, using additional information passed in the remoteCodebase and loader parameters. See Section 1.4.9.5, Codebase Usage, on page 1-37 for details.
Specified by:
loadClass in interface javax.rmi.CORBA.UtilDelegate
Parameters:
className - The class to load.
remoteCodebase - A list of URLs.
loadingContext - The loading context.
Returns:
The loaded class type.
Throws:
java.lang.ClassNotFoundException - When the class could not be loaded.

lookupRuntimeTypeCode

public static org.omg.CORBA.TypeCode lookupRuntimeTypeCode(java.lang.Object obj)
                                                    throws java.io.InvalidClassException
Create typecode from runtime class. This will only successfully return typecodes for types which can be marshalled.
Parameters:
obj - The object for which to look the type code up.
Returns:
the target object's typecode, or null if the target object is not serializable.
Throws:
java.io.InvalidClassException - When the type() method could not be invoked on the helper class.

getIsLocalResult

public static boolean getIsLocalResult()
Get the isLocalResult flag.
Returns:
The value of the flag.

setIsLocalResult

public static void setIsLocalResult(boolean is_local_result)
Set the isLocalResult flag.
Parameters:
is_local_result - The new value of the flag.

getProhibitIsLocalTest

public static boolean getProhibitIsLocalTest()
Get the prohibitIsLocalTest flag.
Returns:
The value of the flag.

setProhibitIsLocalTest

public static void setProhibitIsLocalTest(boolean prohibit_is_local_test)
Set the prohibitIsLocalTest flag.
Parameters:
prohibit_is_local_test - The new value of the flag.

getLocalCodebaseOnly

public static boolean getLocalCodebaseOnly()
Get the RMIClassloader flag.
Returns:
The value of the flag.

setLocalCodebaseOnly

public static void setLocalCodebaseOnly(boolean local_codebase_only)
Set the RMIClassloader flag.
Parameters:
local_codebase_only - The new value of the flag.

getCopyLocalObjects

public static boolean getCopyLocalObjects()
Get the copyLocalObjects flag.
Returns:
The value of the flag.

setCopyLocalObjects

public static void setCopyLocalObjects(boolean copy_local_objects)
Set the copyLocalObjects flag.
Parameters:
copy_local_objects - The new value of the flag.