⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utility.java

📁 java jdk 1.4的源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     */    public static Class loadClassForClass (String className,                                           String remoteCodebase,                                           ClassLoader loader,					   Class relatedType,                                           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 new org.omg.CORBA.MARSHAL(                    MinorCodes.UNABLE_LOCATE_VALUE_HELPER,                    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 new org.omg.CORBA.MARSHAL(cnfe.toString(),                MinorCodes.UNABLE_LOCATE_VALUE_HELPER,                CompletionStatus.COMPLETED_MAYBE);        } catch (IllegalAccessException iae) {            throw new org.omg.CORBA.MARSHAL(iae.toString(),                MinorCodes.UNABLE_LOCATE_VALUE_HELPER,                CompletionStatus.COMPLETED_MAYBE);        } catch (InstantiationException ie) {            throw new org.omg.CORBA.MARSHAL(ie.toString(),                MinorCodes.UNABLE_LOCATE_VALUE_HELPER,                CompletionStatus.COMPLETED_MAYBE);        } catch (ClassCastException cce) {            throw new org.omg.CORBA.MARSHAL(cce.toString(),                MinorCodes.UNABLE_LOCATE_VALUE_HELPER,                CompletionStatus.COMPLETED_MAYBE);        }        }    /**     * 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 new org.omg.CORBA.MARSHAL(                    MinorCodes.UNABLE_LOCATE_VALUE_FACTORY,                    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 new org.omg.CORBA.MARSHAL(cnfe.toString(),                MinorCodes.UNABLE_LOCATE_VALUE_FACTORY,                CompletionStatus.COMPLETED_MAYBE);        } catch (IllegalAccessException iae) {            throw new org.omg.CORBA.MARSHAL(iae.toString(),                MinorCodes.UNABLE_LOCATE_VALUE_FACTORY,                 CompletionStatus.COMPLETED_MAYBE);        } catch (InstantiationException ie) {            throw new org.omg.CORBA.MARSHAL(ie.toString(),                MinorCodes.UNABLE_LOCATE_VALUE_FACTORY,                CompletionStatus.COMPLETED_MAYBE);        } catch (ClassCastException cce) {            throw new org.omg.CORBA.MARSHAL(cce.toString(),                MinorCodes.UNABLE_LOCATE_VALUE_FACTORY,                CompletionStatus.COMPLETED_MAYBE);        }        }    /*     * 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,                                   Class stubClass,                                   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,stubClass,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...                                                    entry =                            loadStubAndUpdateCache(tie,null,remoteCodebase,true);                                                   } else if (stubClass != null                               && entry.stub.getClass() != stubClass)                     {                                                        // 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,stubClass,                                    remoteCodebase,onlyMostDerived);                        }                                        } else {                                                                    // Use the cached stub. Is the delegate set?                                                try {                            Delegate stubDel =                                 ((ObjectImpl)entry.stub)._get_delegate();                        } catch (Exception e2) {                                                        // No, so set it if we can...                                                        try {                                            Delegate del =                                     ((ObjectImpl)tie)._get_delegate();                                ((ObjectImpl)entry.stub)._set_delegate(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 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 StubEntry or null if not found.     */     private static StubEntry loadStubAndUpdateCache (Tie tie,						     Class stubClass,						     String remoteCodebase,						     boolean onlyMostDerived)     {        Stub stub = null;        StubEntry entry = null;        boolean isObjectImpl = (tie instanceof ObjectImpl);        // Were we given a stub class?                        if (stubClass != null) {                                // Yes, so try to instantiate it...                                try {                stub = (Stub) stubClass.newInstance();            } catch (Throwable e) {                if (e instanceof ThreadDeath) {                    throw (ThreadDeath) e;                }            }        } else {                                // Nope, so we must find it. First, get the list            // of ids from the tie...                                String[] ids = null;            if( isObjectImpl ) {                ids = ((ObjectImpl)tie)._ids();            } else {                // If Tie is extending Servant, Then the                // Repository Id can be obtained from all_interfaces()                // method.                ids = ((org.omg.PortableServer.Servant)tie).                      _all_interfaces( null, null );            }                                            // If we were not given a remoteCodebase,            // get one from the tie...                        if (remoteCodebase == null) {                remoteCodebase = Util.getCodebase(tie.getClass());            }                                // Now walk all the RepIDs till we find it or fail...                                for (int i = 0; i < ids.length; i++) {            	            	        // Check for the java.rmi.Remote special case...                 	        if (ids[i].length() == 0) {    	            stub = new org.omg.stub.java.rmi._Remote_Stub();    	            break;    	        }            	            	        // Get the classname from the RepID...            	            	        String className = stubNameFromRepID(ids[i]);    	        // Now try to load it...            	            	        try {                    // _REVISIT_ The spec does not specify a                     // loadingContext parameter for the following call.                    Class resultClass = null;                    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 the 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))){                            resultClass = Util.loadClass                            (PackagePrefixChecker.withoutPackagePrefix(                                 className),                                  remoteCodebase,                                  tie.getClass().getClassLoader());                        } else {                            resultClass = Util.loadClass                                (className,                                  remoteCodebase,                                  tie.getClass().getClassLoader());                        }                    } catch (ClassNotFoundException cnfe){                        resultClass = Util.loadClass                            (className,                              remoteCodebase,                              tie.getClass().getClassLoader());                    }                    stub = (Stub) resultClass.newInstance();                    break;    	        } catch (Exception e){}            	            	        // If we failed to load it, see if we should continue...            	        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -