Methods Summary |
---|
public static java.lang.Object | autoConnect(java.lang.Object obj, org.omg.CORBA.ORB orb, boolean convertToStub)Ensure that stubs, ties, and implementation objects
are 'connected' to the runtime. Converts implementation
objects to a type suitable for sending on the wire.
if (obj == null) {
return obj;
}
if (StubAdapter.isStub(obj)) {
try {
StubAdapter.getDelegate(obj) ;
} catch (BAD_OPERATION okay) {
try {
StubAdapter.connect( obj, orb ) ;
} catch (RemoteException e) {
// The stub could not be connected because it
// has an invalid IOR...
throw wrapper.objectNotConnected( e,
obj.getClass().getName() ) ;
}
}
return obj;
}
if (obj instanceof Remote) {
Remote remoteObj = (Remote)obj;
Tie theTie = Util.getTie(remoteObj);
if (theTie != null) {
try {
theTie.orb();
} catch (SystemException okay) {
theTie.orb(orb);
}
if (convertToStub) {
Object result = loadStub(theTie,null,null,true);
if (result != null) {
return result;
} else {
throw wrapper.couldNotLoadStub(obj.getClass().getName());
}
} else {
return StubAdapter.activateTie( theTie );
}
} else {
// This is an implementation object which has not been
// exported to IIOP OR is a JRMP stub or implementation
// object which cannot be marshalled into an ORB stream...
throw wrapper.objectNotExported( obj.getClass().getName() ) ;
}
}
// Didn't need to do anything, just return the input...
return obj;
|
public static void | clearCaches()
synchronized (tieToStubCache) {
tieToStubCache.clear();
}
synchronized (tieCache) {
tieCache.clear();
}
synchronized (stubToTieCache) {
stubToTieCache.clear();
}
|
public static java.lang.String | dynamicStubName(java.lang.String className)
return stubName( className, true ) ;
|
public static javax.rmi.CORBA.Tie | getAndForgetTie(org.omg.CORBA.Object stub)
synchronized (stubToTieCache) {
return (Tie) stubToTieCache.remove(stub);
}
|
public static org.omg.CORBA.portable.ValueFactory | getFactory(java.lang.Class clazz, java.lang.String codebase, org.omg.CORBA.ORB orb, java.lang.String repId)Get the factory for an IDLValue
Throws MARSHAL exception if no factory found.
ValueFactory factory = null;
if ((orb != null) && (repId != null)) {
try {
factory = ((org.omg.CORBA_2_3.ORB)orb).lookup_value_factory(
repId);
} catch (org.omg.CORBA.BAD_PARAM ex) {
// Try other way
}
}
String className = null;
if (clazz != null) {
className = clazz.getName();
if (codebase == null)
codebase = Util.getCodebase(clazz);
} else {
if (repId != null)
className = RepositoryId.cache.getId(repId).getClassName();
if (className == null) // no repId or unrecognized repId
throw omgWrapper.unableLocateValueFactory(
CompletionStatus.COMPLETED_MAYBE);
}
// if earlier search found a non-default factory, or the same default
// factory that loadClassForClass would return, bale out now...
if (factory != null &&
(!factory.getClass().getName().equals(className+"DefaultFactory") ||
(clazz == null && codebase == null)))
return factory;
try {
ClassLoader clazzLoader =
(clazz == null ? null : clazz.getClassLoader());
Class factoryClass =
loadClassForClass(className+"DefaultFactory", codebase,
clazzLoader, clazz, clazzLoader);
return (ValueFactory)factoryClass.newInstance();
} catch (ClassNotFoundException cnfe) {
throw omgWrapper.unableLocateValueFactory(
CompletionStatus.COMPLETED_MAYBE, cnfe);
} catch (IllegalAccessException iae) {
throw omgWrapper.unableLocateValueFactory(
CompletionStatus.COMPLETED_MAYBE, iae);
} catch (InstantiationException ie) {
throw omgWrapper.unableLocateValueFactory(
CompletionStatus.COMPLETED_MAYBE, ie);
} catch (ClassCastException cce) {
throw omgWrapper.unableLocateValueFactory(
CompletionStatus.COMPLETED_MAYBE, cce);
}
|
public static org.omg.CORBA.portable.BoxedValueHelper | getHelper(java.lang.Class clazz, java.lang.String codebase, java.lang.String repId)Get the helper for an IDLValue
Throws MARSHAL exception if no helper found.
String className = null;
if (clazz != null) {
className = clazz.getName();
if (codebase == null)
codebase = Util.getCodebase(clazz);
} else {
if (repId != null)
className = RepositoryId.cache.getId(repId).getClassName();
if (className == null) // no repId or unrecognized repId
throw wrapper.unableLocateValueHelper(
CompletionStatus.COMPLETED_MAYBE);
}
try {
ClassLoader clazzLoader =
(clazz == null ? null : clazz.getClassLoader());
Class helperClass =
loadClassForClass(className+"Helper", codebase, clazzLoader,
clazz, clazzLoader);
return (BoxedValueHelper)helperClass.newInstance();
} catch (ClassNotFoundException cnfe) {
throw wrapper.unableLocateValueHelper( CompletionStatus.COMPLETED_MAYBE,
cnfe );
} catch (IllegalAccessException iae) {
throw wrapper.unableLocateValueHelper( CompletionStatus.COMPLETED_MAYBE,
iae );
} catch (InstantiationException ie) {
throw wrapper.unableLocateValueHelper( CompletionStatus.COMPLETED_MAYBE,
ie );
} catch (ClassCastException cce) {
throw wrapper.unableLocateValueHelper( CompletionStatus.COMPLETED_MAYBE,
cce );
}
|
static int | hexOf(char x)Converts an Ascii Character into Hexadecimal digit
int val;
val = x - '0";
if (val >=0 && val <= 9)
return val;
val = (x - 'a") + 10;
if (val >= 10 && val <= 15)
return val;
val = (x - 'A") + 10;
if (val >= 10 && val <= 15)
return val;
throw wrapper.badHexDigit() ;
|
public static java.lang.String | idlStubName(java.lang.String className)Create an IDL stub name.
String result = null;
int index = className.lastIndexOf('.");
if (index > 0) {
result = className.substring(0,index+1) +
STUB_PREFIX +
className.substring(index+1) +
IDL_STUB_SUFFIX;
} else {
result = STUB_PREFIX +
className +
IDL_STUB_SUFFIX;
}
return result;
|
public static java.lang.Class | loadClassForClass(java.lang.String className, java.lang.String remoteCodebase, java.lang.ClassLoader loader, java.lang.Class relatedType, java.lang.ClassLoader relatedTypeClassLoader)
if (relatedType == null)
return Util.loadClass(className, remoteCodebase, loader);
Class loadedClass = null;
try {
loadedClass = Util.loadClass(className, remoteCodebase, loader);
} catch (ClassNotFoundException cnfe) {
if (relatedType.getClassLoader() == null)
throw cnfe;
}
// If no class was not loaded, or if the loaded class is not of the
// correct type, make a further attempt to load the correct class
// using the classloader of the related type.
// _REVISIT_ Is this step necessary, or should the Util,loadClass
// algorithm always produce a valid class if the setup is correct?
// Does the OMG standard algorithm need to be changed to include
// this step?
if (loadedClass == null ||
(loadedClass.getClassLoader() != null &&
loadedClass.getClassLoader().loadClass(relatedType.getName()) !=
relatedType))
{
if (relatedType.getClassLoader() != relatedTypeClassLoader)
throw new IllegalArgumentException(
"relatedTypeClassLoader not class loader of relatedType.");
if (relatedTypeClassLoader != null)
loadedClass = relatedTypeClassLoader.loadClass(className);
}
return loadedClass;
|
static java.lang.Class | loadClassOfType(java.lang.String className, java.lang.String remoteCodebase, java.lang.ClassLoader loader, java.lang.Class expectedType, java.lang.ClassLoader expectedTypeClassLoader)
Class loadedClass = null;
try {
//Sequence finding of the stubs according to spec
try{
//If-else is put here for speed up of J2EE.
//According to the OMG spec, the if clause is not dead code.
//It can occur if some compiler has allowed generation
//into org.omg.stub hierarchy for non-offending
//classes. This will encourage people to
//produce non-offending class stubs in their own hierarchy.
if (!PackagePrefixChecker.hasOffendingPrefix(
PackagePrefixChecker.withoutPackagePrefix(className))){
loadedClass = Util.loadClass(
PackagePrefixChecker.withoutPackagePrefix(className),
remoteCodebase,
loader);
} else {
loadedClass = Util.loadClass(className, remoteCodebase,
loader);
}
} catch (ClassNotFoundException cnfe) {
loadedClass = Util.loadClass(className, remoteCodebase,
loader);
}
if (expectedType == null)
return loadedClass;
} catch (ClassNotFoundException cnfe) {
if (expectedType == null)
throw cnfe;
}
// If no class was loaded, or if the loaded class is not of the
// correct type, make a further attempt to load the correct class
// using the classloader of the expected type.
// _REVISIT_ Is this step necessary, or should the Util,loadClass
// algorithm always produce a valid class if the setup is correct?
// Does the OMG standard algorithm need to be changed to include
// this step?
if (loadedClass == null || !expectedType.isAssignableFrom(loadedClass)){
if (expectedType.getClassLoader() != expectedTypeClassLoader)
throw new IllegalArgumentException(
"expectedTypeClassLoader not class loader of " +
"expected Type.");
if (expectedTypeClassLoader != null)
loadedClass = expectedTypeClassLoader.loadClass(className);
else {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null)
cl = ClassLoader.getSystemClassLoader();
loadedClass = cl.loadClass(className);
}
}
return loadedClass;
|
public static java.rmi.Remote | loadStub(org.omg.CORBA.Object narrowFrom, java.lang.Class narrowTo)
Remote result = null;
try {
// Get the codebase from the delegate to use when loading
// the new stub, if possible...
String codebase = null;
try {
// We can't assume that narrowFrom is a CORBA_2_3 stub, yet
// it may have a 2_3 Delegate that provides a codebase. Swallow
// the ClassCastException otherwise.
Delegate delegate = StubAdapter.getDelegate( narrowFrom ) ;
codebase = ((org.omg.CORBA_2_3.portable.Delegate)delegate).
get_codebase(narrowFrom);
} catch (ClassCastException e) {
wrapper.classCastExceptionInLoadStub( e ) ;
}
PresentationManager.StubFactoryFactory sff =
com.sun.corba.se.spi.orb.ORB.getStubFactoryFactory() ;
PresentationManager.StubFactory sf = sff.createStubFactory(
narrowTo.getName(), false, codebase, narrowTo,
narrowTo.getClassLoader() ) ;
result = (Remote)sf.makeStub() ;
StubAdapter.setDelegate( result,
StubAdapter.getDelegate( narrowFrom ) ) ;
} catch (Exception err) {
wrapper.exceptionInLoadStub( err ) ;
}
return result;
|
public static java.rmi.Remote | loadStub(javax.rmi.CORBA.Tie tie, PresentationManager.StubFactory stubFactory, java.lang.String remoteCodebase, boolean onlyMostDerived)
StubEntry entry = null;
// Do we already have it cached?
synchronized (tieToStubCache) {
Object cached = tieToStubCache.get(tie);
if (cached == null) {
// No, so go try to load it...
entry = loadStubAndUpdateCache(
tie, stubFactory, remoteCodebase, onlyMostDerived);
} else {
// Yes, is it a stub? If not, it was a miss last
// time, so return null again...
if (cached != CACHE_MISS) {
// It's a stub.
entry = (StubEntry) cached;
// Does the cached stub meet the requirements
// of the caller? If the caller does not require
// the most derived stub and does not require
// a specific stub type, we don't have to check
// any further because the cached type is good
// enough...
if (!entry.mostDerived && onlyMostDerived) {
// We must reload because we do not have
// the most derived cached already...
// The stubFactory arg must be null here
// to force onlyMostDerived=true to work
// correctly.
entry = loadStubAndUpdateCache(tie,null,
remoteCodebase,true);
} else if (stubFactory != null &&
!StubAdapter.getTypeIds(entry.stub)[0].equals(
stubFactory.getTypeIds()[0]) )
{
// We do not have exactly the right stub. First, try to
// upgrade the cached stub by forcing it to the most
// derived stub...
entry = loadStubAndUpdateCache(tie,null,
remoteCodebase,true);
// If that failed, try again with the exact type
// we need...
if (entry == null) {
entry = loadStubAndUpdateCache(tie,stubFactory,
remoteCodebase,onlyMostDerived);
}
} else {
// Use the cached stub. Is the delegate set?
try {
Delegate stubDel = StubAdapter.getDelegate(
entry.stub ) ;
} catch (Exception e2) {
// No, so set it if we can...
try {
Delegate del = StubAdapter.getDelegate(
tie ) ;
StubAdapter.setDelegate( entry.stub,
del ) ;
} catch (Exception e) {}
}
}
}
}
}
if (entry != null) {
return (Remote)entry.stub;
} else {
return null;
}
|
private static com.sun.corba.se.impl.util.StubEntry | loadStubAndUpdateCache(javax.rmi.CORBA.Tie tie, PresentationManager.StubFactory stubFactory, java.lang.String remoteCodebase, boolean onlyMostDerived)
org.omg.CORBA.Object stub = null;
StubEntry entry = null;
boolean tieIsStub = StubAdapter.isStub( tie ) ;
if (stubFactory != null) {
try {
stub = stubFactory.makeStub();
} catch (Throwable e) {
wrapper.stubFactoryCouldNotMakeStub( e ) ;
if (e instanceof ThreadDeath) {
throw (ThreadDeath) e;
}
}
} else {
String[] ids = null;
if (tieIsStub) {
ids = StubAdapter.getTypeIds( tie ) ;
} else {
// This will throw an exception if the tie
// is not a Servant. XXX Handle this better?
ids = ((org.omg.PortableServer.Servant)tie).
_all_interfaces( null, null );
}
if (remoteCodebase == null) {
remoteCodebase = Util.getCodebase(tie.getClass());
}
if (ids.length == 0) {
stub = new org.omg.stub.java.rmi._Remote_Stub();
} else {
// Now walk all the RepIDs till we find a stub or fail...
for (int i = 0; i < ids.length; i++) {
if (ids[i].length() == 0) {
stub = new org.omg.stub.java.rmi._Remote_Stub();
break;
}
try {
PresentationManager.StubFactoryFactory stubFactoryFactory =
com.sun.corba.se.spi.orb.ORB.getStubFactoryFactory();
RepositoryId rid = RepositoryId.cache.getId( ids[i] ) ;
String className = rid.getClassName() ;
boolean isIDLInterface = rid.isIDLType() ;
stubFactory = stubFactoryFactory.createStubFactory(
className, isIDLInterface, remoteCodebase, null,
tie.getClass().getClassLoader() ) ;
stub = stubFactory.makeStub();
break;
} catch (Exception e) {
wrapper.errorInMakeStubFromRepositoryId( e ) ;
}
if (onlyMostDerived)
break;
}
}
}
if (stub == null) {
// Stub == null, so cache the miss...
tieToStubCache.put(tie,CACHE_MISS);
} else {
if (tieIsStub) {
try {
Delegate del = StubAdapter.getDelegate( tie ) ;
StubAdapter.setDelegate( stub, del ) ;
} catch( Exception e1 ) {
// The tie does not have a delegate set, so stash
// this tie away using the stub as a key so that
// later, when the stub is connected, we can find
// and connect the tie as well...
synchronized (stubToTieCache) {
stubToTieCache.put(stub,tie);
}
}
} else {
// Tie extends Servant
try {
Delegate delegate = StubAdapter.getDelegate( tie ) ;
StubAdapter.setDelegate( stub, delegate ) ;
} catch( org.omg.CORBA.BAD_INV_ORDER bad) {
synchronized (stubToTieCache) {
stubToTieCache.put(stub,tie);
}
} catch( Exception e ) {
// Exception is caught because of any of the
// following reasons
// 1) POA is not associated with the TIE
// 2) POA Policies for the tie-associated POA
// does not support _this_object() call.
throw wrapper.noPoa( e ) ;
}
}
// Update the cache...
entry = new StubEntry(stub,onlyMostDerived);
tieToStubCache.put(tie,entry);
}
return entry;
|
public static java.lang.Class | loadStubClass(java.lang.String repID, java.lang.String remoteCodebase, java.lang.Class expectedType)
// Get the repID and check for "" special case.
// We should never be called with it (See CDRInputStream
// and the loadStub() method)...
if (repID.length() == 0) {
throw new ClassNotFoundException();
}
// Get the stubname from the repID and load
// the class. If we have a valid 'sender', fall
// back to using its codebase if we need to...
String className = Utility.stubNameFromRepID(repID);
ClassLoader expectedTypeClassLoader = (expectedType == null ? null :
expectedType.getClassLoader());
try {
return loadClassOfType(className,
remoteCodebase,
expectedTypeClassLoader,
expectedType,
expectedTypeClassLoader);
} catch (ClassNotFoundException e) {
return loadClassOfType(PackagePrefixChecker.packagePrefix() + className,
remoteCodebase,
expectedTypeClassLoader,
expectedType,
expectedTypeClassLoader);
}
|
public static javax.rmi.CORBA.Tie | loadTie(java.rmi.Remote obj)
Tie result = null;
Class objClass = obj.getClass();
// Have we tried to find this guy before?
synchronized (tieCache) {
Object it = tieCache.get(obj);
if (it == null) {
// No, so try it...
try {
// First try the classname...
result = loadTie(objClass);
// If we don't have a valid tie at this point,
// walk up the parent chain until we either
// load a tie or encounter PortableRemoteObject
// or java.lang.Object...
while (result == null &&
(objClass = objClass.getSuperclass()) != null &&
objClass != PortableRemoteObject.class &&
objClass != Object.class) {
result = loadTie(objClass);
}
} catch (Exception ex) {
wrapper.loadTieFailed( ex, objClass.getName() ) ;
}
// Did we get it?
if (result == null) {
// Nope, so cache that fact...
tieCache.put(obj,CACHE_MISS);
} else {
// Yes, so cache it...
tieCache.put(obj,result);
}
} else {
// Yes, return a new instance or fail again if
// it was a miss last time...
if (it != CACHE_MISS) {
try {
result = (Tie) it.getClass().newInstance();
} catch (Exception e) {
}
}
}
}
return result;
|
private static javax.rmi.CORBA.Tie | loadTie(java.lang.Class theClass)
return com.sun.corba.se.spi.orb.ORB.getStubFactoryFactory().
getTie( theClass ) ;
|
public static void | printStackTrace()
Throwable thr = new Throwable( "Printing stack trace:" ) ;
thr.fillInStackTrace() ;
thr.printStackTrace() ;
|
public static void | purgeStubForTie(javax.rmi.CORBA.Tie tie)
StubEntry entry;
synchronized (tieToStubCache) {
entry = (StubEntry)tieToStubCache.remove(tie);
}
if (entry != null) {
synchronized (stubToTieCache) {
stubToTieCache.remove(entry.stub);
}
}
|
public static void | purgeTieAndServant(javax.rmi.CORBA.Tie tie)
synchronized (tieCache) {
Object target = tie.getTarget();
if (target != null)
tieCache.remove(target);
}
|
public static java.lang.Object | readAbstractAndNarrow(org.omg.CORBA_2_3.portable.InputStream in, java.lang.Class narrowTo)Read an abstract interface type from the input stream and narrow
it to the desired type.
Object result = in.read_abstract_interface();
if (result != null)
return PortableRemoteObject.narrow(result, narrowTo);
else
return null;
|
public static java.lang.Object | readObjectAndNarrow(org.omg.CORBA.portable.InputStream in, java.lang.Class narrowTo)Read an object reference from the input stream and narrow
it to the desired type.
Object result = in.read_Object();
if (result != null)
return PortableRemoteObject.narrow(result, narrowTo);
else
return null;
|
public static java.lang.String | stubName(java.lang.String className)Create an RMI stub name.
return stubName( className, false ) ;
|
private static java.lang.String | stubName(java.lang.String className, boolean isDynamic)
String name = stubNameForCompiler( className, isDynamic ) ;
if (PackagePrefixChecker.hasOffendingPrefix( name ))
name = PackagePrefixChecker.packagePrefix() + name ;
return name ;
|
public static java.lang.String | stubNameForCompiler(java.lang.String className)
return stubNameForCompiler( className, false ) ;
|
private static java.lang.String | stubNameForCompiler(java.lang.String className, boolean isDynamic)
int index = className.indexOf('$");
if (index < 0) {
index = className.lastIndexOf('.");
}
String suffix = isDynamic ? DYNAMIC_STUB_SUFFIX :
RMI_STUB_SUFFIX ;
if (index > 0) {
return className.substring(0,index+1) + STUB_PREFIX +
className.substring(index+1) + suffix;
} else {
return STUB_PREFIX + className + suffix;
}
|
public static java.lang.String | stubNameFromRepID(java.lang.String repID)
// Convert the typeid to a RepositoryId instance, get
// the className and mangle it as needed...
RepositoryId id = RepositoryId.cache.getId(repID);
String className = id.getClassName();
if (id.isIDLType()) {
className = idlStubName(className);
} else {
className = stubName(className);
}
return className;
|
public static void | throwNotSerializableForCorba(java.lang.String className)Throws the CORBA equivalent of a java.io.NotSerializableException
throw omgWrapper.notSerializable( CompletionStatus.COMPLETED_MAYBE,
className ) ;
|
public static java.lang.String | tieName(java.lang.String className)Create an RMI tie name.
return
PackagePrefixChecker.hasOffendingPrefix(tieNameForCompiler(className)) ?
PackagePrefixChecker.packagePrefix() + tieNameForCompiler(className) :
tieNameForCompiler(className);
|
public static java.lang.String | tieNameForCompiler(java.lang.String className)
int index = className.indexOf('$");
if (index < 0) {
index = className.lastIndexOf('.");
}
if (index > 0) {
return className.substring(0,index+1) +
STUB_PREFIX +
className.substring(index+1) +
TIE_SUFIX;
} else {
return STUB_PREFIX +
className +
TIE_SUFIX;
}
|