📄 utility.java
字号:
if (onlyMostDerived) { // Stop here. break; } } } // Did we get it? if (stub != null) { // If the tie has a delegate set, grab it // and stuff it in the stub... if( isObjectImpl ) { // Tie extends ObjectImpl try { Delegate del = ((ObjectImpl)tie)._get_delegate(); ((ObjectImpl)stub)._set_delegate(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 { org.omg.CORBA.Object ref = ((org.omg.PortableServer.Servant)tie). _this_object( ); ((ObjectImpl)stub)._set_delegate( ((ObjectImpl)ref)._get_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 new BAD_PARAM(MinorCodes.NO_POA, CompletionStatus.COMPLETED_NO); } } // Update the cache... entry = new StubEntry(stub,onlyMostDerived); tieToStubCache.put(tie,entry); } else { // Stub == null, so cache the miss... tieToStubCache.put(tie,CACHE_MISS); } return entry; } /* * If we loadStub(Tie,...) stashed away a tie which was * not connected, remove it from the cache and return * it. */ public static Tie getAndForgetTie (Stub stub) { synchronized (stubToTieCache) { return (Tie) stubToTieCache.remove(stub); } } /* * Remove any cached Stub for the given tie. */ public static void purgeStubForTie (Tie tie) { StubEntry entry; synchronized (tieToStubCache) { entry = (StubEntry)tieToStubCache.remove(tie); } if (entry != null) { synchronized (stubToTieCache) { stubToTieCache.remove(entry.stub); } } } /* * Remove cached tie/servant pair. */ public static void purgeTieAndServant (Tie tie) { synchronized (tieCache) { Object target = tie.getTarget(); if (target != null) tieCache.remove(target); } } /* * Convert a RepId to a stubName... */ public static String stubNameFromRepID (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; } /* * Load an RMI-IIOP Stub. */ public static Stub loadStub (ObjectImpl narrowFrom, Class narrowTo) { Stub 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 ObjectImpl, yet // it may have a 2_3 Delegate that provides a codebase. Swallow // the ClassCastException otherwise. Delegate delegate = narrowFrom._get_delegate(); codebase = ((org.omg.CORBA_2_3.portable.Delegate)delegate).get_codebase(narrowFrom); } catch (ClassCastException e) { } String stubName = stubName(narrowTo.getName()); // _REVISIT_ Should the narrowFrom or narrowTo class be used as the // loadingContext in the following call? The spec says narrowFrom, // but this does not seem correct... Class resultClass = null; try { resultClass = loadClassOfType(stubName, codebase, narrowFrom.getClass().getClassLoader(), narrowTo, narrowTo.getClassLoader()); } catch(ClassNotFoundException cnfe) { resultClass = loadClassOfType(STUB_PACKAGE_PREFIX + stubName, codebase, narrowFrom.getClass().getClassLoader(), narrowTo, narrowTo.getClassLoader()); } // Create a stub instance and set the delegate... result = (Stub) resultClass.newInstance(); ((ObjectImpl)result)._set_delegate(narrowFrom._get_delegate()); } catch (Exception err) { } return result; } /* * Load an RMI-IIOP Stub class. */ //d11638 removed unused "CodeBase sender" parameter public static Class loadStubClass(String repID, String remoteCodebase, Class expectedType) throws ClassNotFoundException { // 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(STUB_PACKAGE_PREFIX + className, remoteCodebase, expectedTypeClassLoader, expectedType, expectedTypeClassLoader); } } /** * Create an RMI stub name. */ public static String stubName (String className) { return PackagePrefixChecker.hasOffendingPrefix(stubNameForCompiler(className)) ? PackagePrefixChecker.packagePrefix() + stubNameForCompiler(className) : stubNameForCompiler(className); } public static String stubNameForCompiler (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) + RMI_STUB_SUFFIX; } else { return STUB_PREFIX + className + RMI_STUB_SUFFIX; } } /** * Create an RMI tie name. */ public static String tieName (String className) { return PackagePrefixChecker.hasOffendingPrefix(tieNameForCompiler(className)) ? PackagePrefixChecker.packagePrefix() + tieNameForCompiler(className) : tieNameForCompiler(className); } public static String tieNameForCompiler (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; } } /** * Throws the CORBA equivalent of a java.io.NotSerializableException */ public static void throwNotSerializableForCorba(String className) { throw new BAD_PARAM(className, MinorCodes.NOT_SERIALIZABLE, CompletionStatus.COMPLETED_MAYBE); } /** * Create an IDL stub name. */ public static String idlStubName(String className) { 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 void printStackTrace() { Throwable thr = new Throwable( "Printing stack trace:" ) ; thr.fillInStackTrace() ; thr.printStackTrace() ; } /** * Read an object reference from the input stream and narrow * it to the desired type. * @param in the stream to read from. * @throws ClassCastException if narrowFrom cannot be cast to narrowTo. */ public static Object readObjectAndNarrow(InputStream in, Class narrowTo) throws ClassCastException { Object result = in.read_Object(); if (result != null) return PortableRemoteObject.narrow(result, narrowTo); else return null; } /** * Read an abstract interface type from the input stream and narrow * it to the desired type. * @param in the stream to read from. * @throws ClassCastException if narrowFrom cannot be cast to narrowTo. */ public static Object readAbstractAndNarrow(org.omg.CORBA_2_3.portable.InputStream in, Class narrowTo) throws ClassCastException { Object result = in.read_abstract_interface(); if (result != null) return PortableRemoteObject.narrow(result, narrowTo); else return null; } /** Converts an Ascii Character into Hexadecimal digit */ static int hexOf( char x ) { 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 new DATA_CONVERSION(MinorCodes.BAD_HEX_DIGIT, CompletionStatus.COMPLETED_NO); }}class StubEntry { Stub stub; boolean mostDerived; StubEntry(Stub stub, boolean mostDerived) { this.stub = stub; this.mostDerived = mostDerived; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -