package org.jboss.iiop.rmi;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.lang.reflect.Method;
import java.util.ArrayList;
public class OperationAnalysis
extends AbstractAnalysis
{
private static final org.jboss.logging.Logger logger =
org.jboss.logging.Logger.getLogger(OperationAnalysis.class);
OperationAnalysis(Method method)
throws RMIIIOPViolationException
{
super(method.getName());
logger.debug("new OperationAnalysis: " + method.getName());
this.method = method;
Class retCls = method.getReturnType();
if (retCls.isInterface() && Remote.class.isAssignableFrom(retCls))
Util.isValidRMIIIOP(retCls);
Class[] ex = method.getExceptionTypes();
boolean gotRemoteException = false;
ArrayList a = new ArrayList();
for (int i = 0; i < ex.length; ++i) {
if (ex[i].isAssignableFrom(java.rmi.RemoteException.class))
gotRemoteException = true;
if (Exception.class.isAssignableFrom(ex[i]) &&
!RuntimeException.class.isAssignableFrom(ex[i]) &&
!RemoteException.class.isAssignableFrom(ex[i]) )
a.add(ExceptionAnalysis.getExceptionAnalysis(ex[i])); }
if (!gotRemoteException &&
Remote.class.isAssignableFrom(method.getDeclaringClass()))
throw new RMIIIOPViolationException(
"All interface methods must throw java.rmi.RemoteException, " +
"or a superclass of java.rmi.RemoteException, but method " +
getJavaName() + " of interface " +
method.getDeclaringClass().getName() + " does not.", "1.2.3");
mappedExceptions = new ExceptionAnalysis[a.size()];
mappedExceptions = (ExceptionAnalysis[])a.toArray(mappedExceptions);
Class[] params = method.getParameterTypes();
parameters = new ParameterAnalysis[params.length];
for (int i = 0; i < params.length; ++i) {
logger.debug("OperationAnalysis: " + method.getName() +
" has parameter [" + params[i].getName() + "]");
parameters[i] = new ParameterAnalysis("param" + (i+1), params[i]);
}
}
public Class getReturnType()
{
return method.getReturnType();
}
public Method getMethod()
{
return method;
}
public ExceptionAnalysis[] getMappedExceptions()
{
return (ExceptionAnalysis[])mappedExceptions.clone();
}
public ParameterAnalysis[] getParameters()
{
return (ParameterAnalysis[])parameters.clone();
}
private Method method;
private ExceptionAnalysis[] mappedExceptions;
private ParameterAnalysis[] parameters;
}