@ Override @ FFDCIgnore ( BAD_OPERATION . class ) public Object narrow ( Object narrowFrom , @ SuppressWarnings ( "rawtypes" ) Class narrowTo ) throws ClassCastException { if ( narrowFrom == null ) { return null ; } if ( narrowTo . isInstance ( narrowFrom ) ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) Tr . debug ( tc , "object is already an instance" ) ; return narrowFrom ; } if ( ! ! ! ( narrowFrom instanceof ObjectImpl ) ) throw new ClassCastException ( narrowTo . getName ( ) ) ; if ( IDLEntity . class . isAssignableFrom ( narrowTo ) ) return super . narrow ( narrowFrom , narrowTo ) ; Class < ? > stubClass = loadStubClass ( narrowTo ) ; if ( stubClass == null ) { // The stub class could not be loaded. Fallback to the default // implementation to allow it to dynamically generate one. return super . narrow ( narrowFrom , narrowTo ) ; } Object stubObject ; try { stubObject = stubClass . newInstance ( ) ; } catch ( Throwable t ) { // This will fail if the stub class is "invalid" (missing default // constructor, non-public default constructor, logic in the // constructor that throws, etc.). ClassCastException e = new ClassCastException ( narrowTo . getName ( ) ) ; e . initCause ( t ) ; throw e ; } // This will fail if the loaded class does not actually extend Stub. Stub stub = ( Stub ) stubObject ; try { stub . _set_delegate ( ( ( ObjectImpl ) narrowFrom ) . _get_delegate ( ) ) ; } catch ( org . omg . CORBA . BAD_OPERATION e ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) Tr . debug ( tc , "unable to copy delegate" , e ) ; } // This will fail if the loaded stub class does not implement the // interface. For example, narrow was called with one version of the // interface, but the context class loader loaded a stub that // implemented a different version of the interface. return narrowTo . cast ( stub ) ; }
An implementation of narrow that always attempts to load stub classes from the class loader before dynamically generating a stub class .