org.objectweb.carol.util.delegate
Class UtilDelegateImpl

java.lang.Object
  extended by org.objectweb.carol.util.delegate.UtilDelegateImpl
All Implemented Interfaces:
javax.rmi.CORBA.UtilDelegate

public final class UtilDelegateImpl
extends java.lang.Object
implements javax.rmi.CORBA.UtilDelegate

This class smoothes out incompatibilities between JDKs provided by different vendors.

Since:
2005-04-12
Author:
Vadim Nasardinov (vadimn@redhat.com)

Constructor Summary
UtilDelegateImpl()
          Default constructor.
Build a proxied object which is map to the JVM implementation of UtilDelegate interface.
 
Method Summary
 java.lang.Object copyObject(java.lang.Object obj, org.omg.CORBA.ORB orb)
          Copies or connects an object.
 java.lang.Object[] copyObjects(java.lang.Object[] objs, org.omg.CORBA.ORB orb)
          Copies or connects an array of objects.
 javax.rmi.CORBA.ValueHandler createValueHandler()
          Returns a singleton instance of a class that implements the interface.
 java.lang.String getCodebase(java.lang.Class clz)
          Returns the codebase, if any, for the given class.
 javax.rmi.CORBA.Tie getTie(java.rmi.Remote target)
          Returns the tie (if any) for a given target object.
 boolean isLocal(javax.rmi.CORBA.Stub stub)
          The _is_local() method is provided so that stubs may determine if a particular object is implemented by a local servant and hence local invocation APIs may be used.
 java.lang.Class loadClass(java.lang.String className, java.lang.String remoteCodebase, java.lang.ClassLoader loader)
          Returns a class instance for the specified class.
 java.rmi.RemoteException mapSystemException(org.omg.CORBA.SystemException ex)
          Maps a SystemException to a RemoteException.
 java.lang.Object readAny(org.omg.CORBA.portable.InputStream in)
          Reads a java.lang.Object as a CORBA any.
 void registerTarget(javax.rmi.CORBA.Tie tie, java.rmi.Remote target)
          Registers a target for a tie.
 void unexportObject(java.rmi.Remote target)
          Removes the associated tie from an internal table and calls Tie.deactivate() to deactivate the object.
 java.rmi.RemoteException wrapException(java.lang.Throwable orig)
          Wraps an exception thrown by an implementation method.
 void writeAbstractObject(org.omg.CORBA.portable.OutputStream out, java.lang.Object obj)
          Writes a java.lang.Object as either a value or a CORBA Object.
 void writeAny(org.omg.CORBA.portable.OutputStream out, java.lang.Object obj)
          Writes any java.lang.Object as a CORBA any.
 void writeRemoteObject(org.omg.CORBA.portable.OutputStream out, java.lang.Object obj)
          Writes a java.lang.Object as a CORBA Object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UtilDelegateImpl

public UtilDelegateImpl()
Default constructor.
Build a proxied object which is map to the JVM implementation of UtilDelegate interface.

Method Detail

copyObject

public java.lang.Object copyObject(java.lang.Object obj,
                                   org.omg.CORBA.ORB orb)
                            throws java.rmi.RemoteException
Copies or connects an object. Used by local stubs to copy an actual parameter, result object, or exception.

Specified by:
copyObject in interface javax.rmi.CORBA.UtilDelegate
Parameters:
obj - the object to copy.
orb - the ORB.
Returns:
the copy or connected object.
Throws:
java.rmi.RemoteException - if the object could not be copied or connected.

copyObjects

public java.lang.Object[] copyObjects(java.lang.Object[] objs,
                                      org.omg.CORBA.ORB orb)
                               throws java.rmi.RemoteException
Copies or connects an array of objects. Used by local stubs to copy any number of actual parameters, preserving sharing across parameters as necessary to support RMI semantics.

Specified by:
copyObjects in interface javax.rmi.CORBA.UtilDelegate
Parameters:
objs - the objects to copy or connect.
orb - the ORB.
Returns:
the copied or connected objects.
Throws:
java.rmi.RemoteException - if any object could not be copied or connected.

createValueHandler

public javax.rmi.CORBA.ValueHandler createValueHandler()
Returns a singleton instance of a class that implements the interface.

Specified by:
createValueHandler in interface javax.rmi.CORBA.UtilDelegate
Returns:
a class which implements the ValueHandler interface.

getCodebase

public java.lang.String getCodebase(java.lang.Class clz)
Returns the codebase, if any, for the given class.

Specified by:
getCodebase in interface javax.rmi.CORBA.UtilDelegate
Parameters:
clz - the class to get a codebase for.
Returns:
a space-separated list of URLs, or null.

getTie

public javax.rmi.CORBA.Tie getTie(java.rmi.Remote target)
Returns the tie (if any) for a given target object.

Specified by:
getTie in interface javax.rmi.CORBA.UtilDelegate
Parameters:
target - the given target from which we want the tie
Returns:
the tie or null if no tie is registered for the given target.

isLocal

public boolean isLocal(javax.rmi.CORBA.Stub stub)
                throws java.rmi.RemoteException
The _is_local() method is provided so that stubs may determine if a particular object is implemented by a local servant and hence local invocation APIs may be used.

Specified by:
isLocal in interface javax.rmi.CORBA.UtilDelegate
Parameters:
stub - the stub to test.
Returns:
true if the servant incarnating the object is located in the same process as the stub and they both share the same ORB instance. The _is_local() method returns false otherwise. The default behavior of _is_local() is to return false.
Throws:
java.rmi.RemoteException - The Java to IDL specification does not specify the conditions that cause a RemoteException to be thrown.

loadClass

public java.lang.Class loadClass(java.lang.String className,
                                 java.lang.String remoteCodebase,
                                 java.lang.ClassLoader loader)
                          throws java.lang.ClassNotFoundException
Returns a class instance for the specified class. This provides an implementation of Util#loadClass(String,String,ClassLoader) that eliminates an incompatibility between Sun's and IBM's interpretation of Section 1.4.6 Locating Stubs and Ties of Java to IDL Language Mapping, v1.3.

Specified by:
loadClass in interface javax.rmi.CORBA.UtilDelegate
Parameters:
className - the name of the class.
remoteCodebase - a space-separated list of URLs at which the class might be found. May be null.
loader - a ClassLoader that may be used to load the class if all other methods fail.
Returns:
the Class object representing the loaded class.
Throws:
java.lang.ClassNotFoundException - if class cannot be loaded.

mapSystemException

public java.rmi.RemoteException mapSystemException(org.omg.CORBA.SystemException ex)
Maps a SystemException to a RemoteException.

Specified by:
mapSystemException in interface javax.rmi.CORBA.UtilDelegate
Parameters:
ex - the SystemException to map.
Returns:
the mapped exception.

readAny

public java.lang.Object readAny(org.omg.CORBA.portable.InputStream in)
Reads a java.lang.Object as a CORBA any.

Specified by:
readAny in interface javax.rmi.CORBA.UtilDelegate
Parameters:
in - the stream from which to read the any.
Returns:
the object read from the stream.

registerTarget

public void registerTarget(javax.rmi.CORBA.Tie tie,
                           java.rmi.Remote target)
Registers a target for a tie. Adds the tie to an internal table and calls Tie.setTarget(java.rmi.Remote) on the tie object.

Specified by:
registerTarget in interface javax.rmi.CORBA.UtilDelegate
Parameters:
tie - the tie to register.
target - the target for the tie.

unexportObject

public void unexportObject(java.rmi.Remote target)
                    throws java.rmi.NoSuchObjectException
Removes the associated tie from an internal table and calls Tie.deactivate() to deactivate the object.

Specified by:
unexportObject in interface javax.rmi.CORBA.UtilDelegate
Parameters:
target - the object to unexport.
Throws:
java.rmi.NoSuchObjectException - if the object cannot be unexported

wrapException

public java.rmi.RemoteException wrapException(java.lang.Throwable orig)
Wraps an exception thrown by an implementation method. It returns the corresponding client-side exception.

Specified by:
wrapException in interface javax.rmi.CORBA.UtilDelegate
Parameters:
orig - the exception to wrap.
Returns:
the wrapped exception.

writeAbstractObject

public void writeAbstractObject(org.omg.CORBA.portable.OutputStream out,
                                java.lang.Object obj)
Writes a java.lang.Object as either a value or a CORBA Object. If obj is a value object or a stub object, it is written to out.write_abstract_interface(java.lang.Object). If obj is an exported RMI-IIOP server object, the tie is found and wired to obj, then written to out.write_abstract_interface(java.lang.Object).

Specified by:
writeAbstractObject in interface javax.rmi.CORBA.UtilDelegate
Parameters:
out - the stream in which to write the object.
obj - the object to write.

writeAny

public void writeAny(org.omg.CORBA.portable.OutputStream out,
                     java.lang.Object obj)
Writes any java.lang.Object as a CORBA any.

Specified by:
writeAny in interface javax.rmi.CORBA.UtilDelegate
Parameters:
out - the stream in which to write the any.
obj - the object to write as an any.

writeRemoteObject

public void writeRemoteObject(org.omg.CORBA.portable.OutputStream out,
                              java.lang.Object obj)
Writes a java.lang.Object as a CORBA Object. If obj is an exported RMI-IIOP server object, the tie is found and wired to obj, then written to out.write_Object(org.omg.CORBA.Object). If obj is a CORBA Object, it is written to out.write_Object(org.omg.CORBA.Object).

Specified by:
writeRemoteObject in interface javax.rmi.CORBA.UtilDelegate
Parameters:
out - the stream in which to write the object.
obj - the object to write.