FileDocCategorySizeDatePackage
DynamicMethodMarshallerImpl.javaAPI DocJava SE 5 API11253Fri Aug 26 14:54:30 BST 2005com.sun.corba.se.impl.presentation.rmi

DynamicMethodMarshallerImpl

public class DynamicMethodMarshallerImpl extends Object implements DynamicMethodMarshaller

Fields Summary
Method
method
ExceptionHandler
ehandler
boolean
hasArguments
boolean
hasVoidResult
boolean
needsArgumentCopy
boolean
needsResultCopy
ReaderWriter[]
argRWs
ReaderWriter
resultRW
private static ReaderWriter
booleanRW
private static ReaderWriter
byteRW
private static ReaderWriter
charRW
private static ReaderWriter
shortRW
private static ReaderWriter
intRW
private static ReaderWriter
longRW
private static ReaderWriter
floatRW
private static ReaderWriter
doubleRW
private static ReaderWriter
corbaObjectRW
private static ReaderWriter
anyRW
private static ReaderWriter
abstractInterfaceRW
Constructors Summary
public DynamicMethodMarshallerImpl(Method method)

	this.method = method ;
	ehandler = new ExceptionHandlerImpl( method.getExceptionTypes() ) ;
	needsArgumentCopy = false ;
		
	Class[] argTypes = method.getParameterTypes() ;
	hasArguments = argTypes.length > 0 ;
	if (hasArguments) {
	    argRWs = new ReaderWriter[ argTypes.length ] ;
	    for (int ctr=0; ctr<argTypes.length; ctr++ ) {
		// This could be further optimized to avoid
		// copying if argTypes contains at most one
		// immutable object type.
		if (!argTypes[ctr].isPrimitive())
		    needsArgumentCopy = true ;
		argRWs[ctr] = makeReaderWriter( argTypes[ctr] ) ;
	    }
	}

	Class resultType = method.getReturnType() ;
	needsResultCopy = false ;
	hasVoidResult = resultType.equals( void.class ) ;
	if (!hasVoidResult) {
	    needsResultCopy = !resultType.isPrimitive() ;
	    resultRW = makeReaderWriter( resultType ) ;
	}
    
Methods Summary
private static booleanallMethodsThrowRemoteException(java.lang.Class cls)

	Method[] methods = cls.getMethods() ;

	// Check that all methods (other than those declared in java.lang.Object)
	// throw an exception that is a subclass of RemoteException.
	for (int ctr=0; ctr<methods.length; ctr++) {
	    Method method = methods[ctr] ;
	    if (method.getDeclaringClass() != Object.class)
		if (!throwsRemote( method ))
		    return false ;
	}	

	return true ;
    
public java.lang.Object[]copyArguments(java.lang.Object[] args, com.sun.corba.se.spi.orb.ORB orb)

	if (needsArgumentCopy)
	    return Util.copyObjects( args, orb ) ;
	else
	    return args ;
    
public java.lang.ObjectcopyResult(java.lang.Object result, com.sun.corba.se.spi.orb.ORB orb)

	if (needsResultCopy)
	    return Util.copyObject( result, orb ) ;
	else 
	    return result ;
    
public java.lang.reflect.MethodgetMethod()

	return method ;
    
private static booleanisAbstractInterface(java.lang.Class cls)

	// Either cls is an interface that extends IDLEntity, or else
	// cls does not extend java.rmi.Remote and all of its methods
	// throw RemoteException.
	if (IDLEntity.class.isAssignableFrom( cls ))
	    return cls.isInterface() ;
	else 
	    return cls.isInterface() && allMethodsThrowRemoteException( cls ) ;
    
private static booleanisAnyClass(java.lang.Class cls)


          
    
	return cls.equals( Object.class ) || cls.equals( Serializable.class ) ||
	    cls.equals( Externalizable.class ) ;
    
public booleanisDeclaredException(java.lang.Throwable thr)

	return ehandler.isDeclaredException( thr.getClass() ) ;
    
public static com.sun.corba.se.impl.presentation.rmi.DynamicMethodMarshallerImpl$ReaderWritermakeReaderWriter(java.lang.Class cls)


 
            
    
	if (cls.equals( boolean.class ))
	    return booleanRW ;
	else if (cls.equals( byte.class ))
	    return byteRW ;
	else if (cls.equals( char.class ))
	    return charRW ;
	else if (cls.equals( short.class ))
	    return shortRW ;
	else if (cls.equals( int.class ))
	    return intRW ;
	else if (cls.equals( long.class ))
	    return longRW ;
	else if (cls.equals( float.class ))
	    return floatRW ;
	else if (cls.equals( double.class ))
	    return doubleRW ;
	else if (java.rmi.Remote.class.isAssignableFrom( cls ))
	    return new ReaderWriterBase( "remote(" + cls.getName() + ")" ) 
	    {
		public Object read( InputStream is ) 
		{
		    return PortableRemoteObject.narrow( is.read_Object(), 
			cls ) ;
		}

		public void write( OutputStream os, Object value ) 
		{
		    Util.writeRemoteObject( os, value ) ;
		}
	    } ;
	else if (cls.equals(org.omg.CORBA.Object.class))
	    return corbaObjectRW ;
	else if (org.omg.CORBA.Object.class.isAssignableFrom( cls ))
	    return new ReaderWriterBase( "org.omg.CORBA.Object(" + 
		cls.getName() + ")" ) 
	    {
		public Object read( InputStream is ) 
		{
		    return is.read_Object(cls) ;
		}
	    
		public void write( OutputStream os, Object value ) 
		{
		    os.write_Object( (org.omg.CORBA.Object)value ) ;
		}
	    } ;
	else if (isAnyClass(cls))
	    return anyRW ;
	else if (isAbstractInterface(cls))
	    return abstractInterfaceRW ;

	// For anything else, just read it as a value type.
	return new ReaderWriterBase( "value(" + cls.getName() + ")" ) 
	{
	    public Object read( InputStream is ) 
	    {
		return is.read_value(cls) ;
	    }

	    public void write( OutputStream os, Object value )
	    {
		os.write_value( (Serializable)value, cls ) ;
	    }
	} ;
    
public java.lang.Object[]readArguments(org.omg.CORBA_2_3.portable.InputStream is)

	Object[] result = null ;

	if (hasArguments) {
	    result = new Object[ argRWs.length ] ;
	    for (int ctr=0; ctr<argRWs.length; ctr++ ) 
		result[ctr] = argRWs[ctr].read( is ) ;
	}

	return result ;
    
public java.lang.ExceptionreadException(org.omg.CORBA.portable.ApplicationException ae)

	return ehandler.readException( ae ) ;
    
public java.lang.ObjectreadResult(org.omg.CORBA_2_3.portable.InputStream is)

	if (hasVoidResult)
	    return null ;
	else
	    return resultRW.read( is ) ;
    
private static booleanthrowsRemote(java.lang.reflect.Method method)

	Class[] exceptionTypes = method.getExceptionTypes() ;

	// Check that some exceptionType is a subclass of RemoteException
	for (int ctr=0; ctr<exceptionTypes.length; ctr++) {
	    Class exceptionType = exceptionTypes[ctr] ;
	    if (java.rmi.RemoteException.class.isAssignableFrom( exceptionType ))
		return true ;
	}

	return false ;
    
public voidwriteArguments(org.omg.CORBA_2_3.portable.OutputStream os, java.lang.Object[] args)

	if (hasArguments) {
	    if (args.length != argRWs.length)
		throw new IllegalArgumentException( "Expected " + argRWs.length +
		    " arguments, but got " + args.length + " arguments." ) ;

	    for (int ctr=0; ctr<argRWs.length; ctr++ ) 
		argRWs[ctr].write( os, args[ctr] ) ;
	}
    
public voidwriteException(org.omg.CORBA_2_3.portable.OutputStream os, java.lang.Exception ex)

	ehandler.writeException( os, ex ) ;
    
public voidwriteResult(org.omg.CORBA_2_3.portable.OutputStream os, java.lang.Object result)

	if (!hasVoidResult)
	    resultRW.write( os, result ) ;