org.jboss.iiop.rmi.RmiIdlUtil Maven / Gradle / Ivy
The newest version!
/*
* JBoss, Home of Professional Open Source.
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.iiop.rmi;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Iterator;
/**
* This class contains a bunch of methods taken from
* org.jboss.verifier.strategy.AbstractVerifier. There they are declared
* as instance methods. I copied them to this class and made them static here
* in order to call them as utility methods, without having to create a
* verifier instance,
*
* @author Juha Lindfors
* @author Aaron Mulder ([email protected])
* @author Vinay Menon ([email protected])
* @author Francisco Reverbel
* @version $Revision: 81018 $
*/
public class RmiIdlUtil {
public static boolean hasLegalRMIIIOPArguments(Method method) {
Class[] params = method.getParameterTypes();
for (int i = 0; i < params.length; ++i)
if (!isRMIIIOPType(params[i]))
return false;
return true;
}
public static boolean hasLegalRMIIIOPReturnType(Method method) {
return isRMIIIOPType(method.getReturnType());
}
public static boolean hasLegalRMIIIOPExceptionTypes(Method method) {
/*
* All checked exception classes used in method declarations
* (other than java.rmi.RemoteException) MUST be conforming
* RMI/IDL exception types.
*
* Spec 28.2.3 (4)
*/
Iterator it = Arrays.asList(method.getExceptionTypes()).iterator();
while (it.hasNext()) {
Class exception = (Class)it.next();
if (!isRMIIDLExceptionType(exception))
return false;
}
return true;
}
/*
* checks if the method's throws clause includes java.rmi.RemoteException
* or a superclass of it.
*/
public static boolean throwsRemoteException(Method method) {
Class[] exception = method.getExceptionTypes();
for (int i = 0; i < exception.length; ++i)
if (exception[i].isAssignableFrom(java.rmi.RemoteException.class))
return true;
return false;
}
/*
* checks if a class's member (method, constructor or field) has a 'static'
* modifier.
*/
public static boolean isStatic(Member member) {
return (Modifier.isStatic(member.getModifiers()));
}
/*
* checks if the given class is declared as static (inner classes only)
*/
public static boolean isStatic(Class c) {
return (Modifier.isStatic(c.getModifiers()));
}
/*
* checks if a class's member (method, constructor or field) has a 'final'
* modifier.
*/
public static boolean isFinal(Member member) {
return (Modifier.isFinal(member.getModifiers()));
}
/*
* checks if the given class is declared as final
*/
public static boolean isFinal(Class c) {
return (Modifier.isFinal(c.getModifiers()));
}
/*
* checks if a class's memeber (method, constructor or field) has a 'public'
* modifier.
*/
public static boolean isPublic(Member member) {
return (Modifier.isPublic(member.getModifiers()));
}
/*
* checks if the given class is declared as public
*/
public static boolean isPublic(Class c) {
return (Modifier.isPublic(c.getModifiers()));
}
/**
* Checks whether all the fields in the class are declared as public.
*/
public static boolean isAllFieldsPublic(Class c) {
try {
Field list[] = c.getFields();
for(int i=0; i