📄 utility.java
字号:
ClassLoader relatedTypeClassLoader) throws ClassNotFoundException { 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; } /** * Get the helper for an IDLValue * * Throws MARSHAL exception if no helper found. */ public static BoxedValueHelper getHelper(Class clazz, String codebase, String repId) { 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 ); } } /** * Get the factory for an IDLValue * * Throws MARSHAL exception if no factory found. */ public static ValueFactory getFactory(Class clazz, String codebase, ORB orb, String repId) { 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); } } /* * Load an RMI-IIOP Stub given a Tie. * @param tie the tie. * @param stubClass the stub class. May be null. * @param remoteCodebase the codebase to use. May be null. * @param onlyMostDerived if true, will fail if cannot load a stub for the * first repID in the tie. If false, will walk all repIDs. * @return the stub or null if not found. */ public static Remote loadStub(Tie tie, PresentationManager.StubFactory stubFactory, 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; } } /* * Load an RMI-IIOP Stub given a Tie, but do not look in the cache. * This method must be called with the lock held for tieToStubCache. * @param tie the tie. * @param stubFactory the stub factory. May be null. * @param remoteCodebase the codebase to use. May be null. * @param onlyMostDerived if true, will fail if cannot load a stub for the * first repID in the tie. If false, will walk all repIDs. * @return the StubEntry or null if not found. */ private static StubEntry loadStubAndUpdateCache ( Tie tie, PresentationManager.StubFactory stubFactory, 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); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -