User: juha
Date: 00/09/24 08:21:50
Modified: src/main/org/jboss/verifier/strategy AbstractVerifier.java
EJBVerifier11.java
Log:
- Fixed some TODO's in the code.
- Implemented the RMI/IIOP type checking
- Implemented Entity home interface verification:
i) must extend EJBHome interface
ii) must follow RMI-IIOP rules and throw RemoteException
iii) each method defined in home must be either create or finder method
iv) return type of create(...) methods must be remote interface type
v) create(...) methods must have matching ejbCreates
vi) create(...) methods must throw all the exceptions of the matching
ejbCreate(...) and ejbPostCreate(...) methods
- Implemented Entuty remote interface verification
i) must extend EJBObject
ii) each method must follow RMI-IIOP type rules and throw RemoteException
iii) must have matching methods in the bean class
Revision Changes Path
1.11 +382 -282 jboss/src/main/org/jboss/verifier/strategy/AbstractVerifier.java
Index: AbstractVerifier.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/verifier/strategy/AbstractVerifier.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- AbstractVerifier.java 2000/09/12 01:51:48 1.10
+++ AbstractVerifier.java 2000/09/24 15:21:50 1.11
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* This package and its source code is available at www.jboss.org
- * $Id: AbstractVerifier.java,v 1.10 2000/09/12 01:51:48 mulder Exp $
+ * $Id: AbstractVerifier.java,v 1.11 2000/09/24 15:21:50 juha Exp $
*/
// standard imports
@@ -33,12 +33,13 @@
import java.util.Iterator;
import java.util.Arrays;
+
+// non-standard class dependencies
import org.jboss.metadata.ApplicationMetaData;
import org.jboss.metadata.BeanMetaData;
import org.jboss.metadata.EntityMetaData;
import org.jboss.metadata.SessionMetaData;
-// non-standard class dependencies
/**
@@ -50,80 +51,65 @@
* @see org.jboss.verifier.strategy.VerificationStrategy
*
* @author Juha Lindfors ([EMAIL PROTECTED])
- * @version $Revision: 1.10 $
+ * @author Aaron Mulder ([EMAIL PROTECTED])
+ *
+ * @version $Revision: 1.11 $
* @since JDK 1.3
*/
public abstract class AbstractVerifier implements VerificationStrategy {
-
-
- public boolean hasLegalRMIIIOPReturnType(Method method) {
-
- // [TODO]
+ protected final static String EJB_OBJECT_INTERFACE =
+ "javax.ejb.EJBObject";
- return true;
- }
+ protected final static String EJB_HOME_INTERFACE =
+ "javax.ejb.EJBHome";
+
public boolean hasLegalRMIIIOPArguments(Method method) {
-
- // [TODO]
-
-
- return true;
-
-
- /*
- * ftp://ftp.omg.org/pub/docs/ptc/99-03-09.pdf
- *
- * A conforming RMI/IDL type is a Java type whose values
- * may be transmitted across an RMI/IDL remote interface at
- * run-time. A Java data type is a conforming RMI/IDL type
- * if it is:
- *
- * - one of the Java primitive types (see Primitive Types on page 28-2).
- * - a conforming remote interface (as defined in RMI/IDL Remote
Interfaces on page 28-2).
- * - a conforming value type (as defined in RMI/IDL Value Types on page
28-4).
- * - an array of conforming RMI/IDL types (see RMI/IDL Arrays on page
28-5).
- * - a conforming exception type (see RMI/IDL Exception Types on page
28-5).
- * - a conforming CORBA object reference type (see CORBA Object Reference
Types on page 28-6).
- * - a conforming IDL entity type see IDL Entity Types on page 28-6).
- *
- *
-
Class[] params = method.getParameterTypes();
-
- for (int i = 0; i < params.length; ++i) {
-
- if (params[i].isPrimitive())
- continue;
-
- if (!isSerializable(params[i]))
+
+ for (int i = 0; i < params.length; ++i)
+ if (!isRMIIIOPType(params[i]))
return false;
- }
-
+
return true;
-
- */
}
+ public boolean hasLegalRMIIIOPReturnType(Method method) {
+ return isRMIIIOPType(method.getReturnType());
+ }
+
/*
- * checks if the method includes java.rmi.RemoteException in its
- * throws clause.
+ * checks if the method includes java.rmi.RemoteException or its
+ * subclass in its throws clause.
*/
public boolean throwsRemoteException(Method method) {
Class[] exception = method.getExceptionTypes();
-
- for (int i = 0; i < exception.length; ++i) {
- if (exception[i].getName().equals(REMOTE_EXCEPTION))
+ for (int i = 0; i < exception.length; ++i)
+ if (java.rmi.RemoteException.class.isAssignableFrom(exception[i]))
return true;
- }
return false;
}
+
+ /*
+ * checks if the method includes java.ejb.CreateException in its
+ * throws clause.
+ */
+ public boolean throwsCreateException(Method method) {
+
+ Class[] exception = method.getExceptionTypes();
+
+ for (int i = 0; i < exception.length; ++i)
+ if (javax.ejb.CreateException.class.isAssignableFrom(exception[i]))
+ return true;
+
+ return false;
+ }
@@ -136,6 +122,13 @@
}
/*
+ * checks if the given class is declared as static (inner classes only)
+ */
+ public boolean isStatic(Class c) {
+ return (Modifier.isStatic(c.getModifiers()));
+ }
+
+ /*
* checks if a class's member (method, constructor or field) has a 'final'
* modifier.
*/
@@ -168,7 +161,7 @@
/**
* Checks whether all the fields in the class are declared as public.
*/
- public static boolean isAllFieldsPublic(Class c) {
+ public boolean isAllFieldsPublic(Class c) {
try {
Field list[] = c.getFields();
for(int i=0; i<list.length; i++)
@@ -188,13 +181,6 @@
}
/*
- * Checks if class implements the java.io.Serializable interface
- */
- public boolean isSerializable(Class c) {
- return hasInterface(c, SERIALIZATION_INTERFACE);
- }
-
- /*
* checks if finder returns the primary key type
*/
public boolean isSingleObjectFinder(EntityMetaData entity, Method finder) {
@@ -205,8 +191,8 @@
* checks if finder method returns either Collection or Enumeration
*/
public boolean isMultiObjectFinder(Method finder) {
- return (finder.getReturnType().getName().equals(COLLECTION_INTERFACE)
- || finder.getReturnType().getName().equals(ENUMERATION_INTERFACE));
+ return (java.util.Collection.class.isAssignableFrom(finder.getReturnType())
+ ||
java.util.Enumeration.class.isAssignableFrom(finder.getReturnType()));
}
/*
@@ -227,46 +213,43 @@
* Finds java.ejb.SessionBean interface from the class
*/
public boolean hasSessionBeanInterface(Class c) {
- return hasInterface(c, SESSION_BEAN_INTERFACE);
+ return javax.ejb.SessionBean.class.isAssignableFrom(c);
}
/*
* Finds java.ejb.EntityBean interface from the class
*/
public boolean hasEntityBeanInterface(Class c) {
- return hasInterface(c, ENTITY_BEAN_INTERFACE);
+ return javax.ejb.EntityBean.class.isAssignableFrom(c);
}
/*
* Finds java.ejb.EJBObject interface from the class
*/
public boolean hasEJBObjectInterface(Class c) {
- return hasInterface(c, EJB_OBJECT_INTERFACE);
+ return javax.ejb.EJBObject.class.isAssignableFrom(c);
}
/*
* Finds javax.ejb.EJBHome interface from the class or its superclasses
*/
public boolean hasEJBHomeInterface(Class c) {
- return hasInterface(c, EJB_HOME_INTERFACE);
+ return javax.ejb.EJBHome.class.isAssignableFrom(c);
}
/*
* Finds javax.ejb.SessionSynchronization interface from the class
*/
public boolean hasSessionSynchronizationInterface(Class c) {
- return hasInterface(c, SESSION_SYNCHRONIZATION_INTERFACE);
+ return javax.ejb.SessionSynchronization.class.isAssignableFrom(c);
}
/*
* Checks if a class has a default (no args) constructor
*/
public boolean hasDefaultConstructor(Class c) {
-
try {
-
c.newInstance();
-
}
catch(Exception e) {
return false;
@@ -279,19 +262,12 @@
* Checks of the class defines a finalize() method
*/
public boolean hasFinalizer(Class c) {
-
try {
-
Method finalizer = c.getDeclaredMethod(FINALIZE_METHOD, new Class[0]);
-
}
catch (NoSuchMethodException e) {
return false;
}
- catch (SecurityException e) {
- System.err.println(e);
- return false;
- }
return true;
}
@@ -300,36 +276,40 @@
* check if a class has one or more finder methods
*/
public boolean hasFinderMethod(Class c) {
+ Method[] method = c.getMethods();
- try {
- Method[] method = c.getMethods();
-
- for (int i = 0; i < method.length; ++i) {
+ for (int i = 0; i < method.length; ++i) {
- String name = method[i].getName();
+ String name = method[i].getName();
- if (name.startsWith("ejbFind"))
- return true;
- }
- }
- catch (SecurityException e) {
- System.err.println(e);
+ if (name.startsWith("ejbFind"))
+ return true;
}
return false;
}
+ public boolean isFinderMethod(Method m) {
+ return (m.getName().startsWith("find"));
+ }
+
+ public boolean isCreateMethod(Method m) {
+ return (m.getName().equals(CREATE_METHOD));
+ }
+
+
/**
* Checks for at least one non-static field.
*/
- public static boolean hasANonStaticField(Class c) {
+ public boolean hasANonStaticField(Class c) {
try {
Field list[] = c.getFields();
for(int i=0; i<list.length; i++)
if(!Modifier.isStatic(list[i].getModifiers()))
return true;
- } catch(Exception e) {
- }
+ }
+ catch(Exception ignored) {}
+
return false;
}
@@ -338,19 +318,14 @@
*/
public boolean hasCreateMethod(Class c) {
- try {
- Method[] method = c.getMethods();
+ Method[] method = c.getMethods();
- for (int i = 0; i < method.length; ++i) {
+ for (int i = 0; i < method.length; ++i) {
- String name = method[i].getName();
+ String name = method[i].getName();
- if (name.equals(CREATE_METHOD))
- return true;
- }
- }
- catch (SecurityException e) {
- System.err.println(e);
+ if (name.equals(CREATE_METHOD))
+ return true;
}
return false;
@@ -361,26 +336,21 @@
*/
public boolean hasEJBCreateMethod(Class c, boolean isSession) {
- try {
- Method[] method = c.getMethods();
+ Method[] method = c.getMethods();
- for (int i = 0; i < method.length; ++i) {
+ for (int i = 0; i < method.length; ++i) {
- String name = method[i].getName();
+ String name = method[i].getName();
- if (name.equals(EJB_CREATE_METHOD))
- if (!isStatic(method[i])
- && !isFinal(method[i])
- && ((isSession && hasVoidReturnType(method[i]))
- || (!isSession)
- )
- )
+ if (name.equals(EJB_CREATE_METHOD))
+ if (!isStatic(method[i])
+ && !isFinal(method[i])
+ && ((isSession && hasVoidReturnType(method[i]))
+ || (!isSession)
+ )
+ )
- return true;
- }
- }
- catch (SecurityException e) {
- System.err.println(e);
+ return true;
}
return false;
@@ -393,24 +363,19 @@
*/
public boolean hasDefaultCreateMethod(Class home) {
- try {
- Method[] method = home.getMethods();
+ Method[] method = home.getMethods();
- for (int i = 0; i < method.length; ++i) {
+ for (int i = 0; i < method.length; ++i) {
- String name = method[i].getName();
+ String name = method[i].getName();
- if (name.equals(CREATE_METHOD)) {
- Class[] params = method[i].getParameterTypes();
+ if (name.equals(CREATE_METHOD)) {
+ Class[] params = method[i].getParameterTypes();
- if (params.length == 0)
- return true;
- }
+ if (params.length == 0)
+ return true;
}
}
- catch (SecurityException e) {
- System.err.println(e);
- }
return false;
}
@@ -420,19 +385,14 @@
*/
public boolean hasEJBFindByPrimaryKey(Class c) {
- try {
- Method[] method = c.getMethods();
+ Method[] method = c.getMethods();
- for (int i = 0; i < method.length; ++i) {
+ for (int i = 0; i < method.length; ++i) {
- String name = method[i].getName();
+ String name = method[i].getName();
- if (name.equals(EJB_FIND_BY_PRIMARY_KEY))
- return true;
- }
- }
- catch (SecurityException e) {
- System.err.println(e);
+ if (name.equals(EJB_FIND_BY_PRIMARY_KEY))
+ return true;
}
return false;
@@ -445,9 +405,6 @@
return (m.getReturnType().getName().equals(entity.getPrimaryKeyClass()));
}
-
-
-
/*
* Returns the default create method. Return null if not found.
*/
@@ -456,52 +413,27 @@
Method method = null;
try {
-
method = c.getMethod(CREATE_METHOD, null);
-
}
- catch (SecurityException e) {
- System.err.println(e);
- }
catch (NoSuchMethodException ignored) {}
return method;
}
-/* Method[] method = c.getMethods();
-
- for (int i = 0; i < method.length; ++i) {
-
- String name = method[i].getName();
-
- if (name.equals(CREATE_METHOD)) {
- Class[] params = method[i].getParameterTypes();
-
- if (params.length == 0)
- return method[i];
- }
- }
-*/
-
/*
* Returns the ejbFindByPrimaryKey method
*/
public Method getEJBFindByPrimaryKey(Class c) {
- try {
- Method[] method = c.getMethods();
+ Method[] method = c.getMethods();
- for (int i = 0; i < method.length; ++i) {
+ for (int i = 0; i < method.length; ++i) {
- String name = method[i].getName();
+ String name = method[i].getName();
- if (name.equals(EJB_FIND_BY_PRIMARY_KEY))
- return method[i];
- }
+ if (name.equals(EJB_FIND_BY_PRIMARY_KEY))
+ return method[i];
}
- catch (SecurityException e) {
- System.err.println(e);
- }
return null;
}
@@ -513,17 +445,12 @@
List finders = new LinkedList();
- try {
- Method[] method = c.getMethods();
+ Method[] method = c.getMethods();
- for (int i = 0; i < method.length; ++i) {
+ for (int i = 0; i < method.length; ++i) {
- if (method[i].getName().startsWith("ejbFind"))
- finders.add(method[i]);
- }
- }
- catch (SecurityException e) {
- System.err.println(e);
+ if (method[i].getName().startsWith("ejbFind"))
+ finders.add(method[i]);
}
return finders.iterator();
@@ -537,107 +464,127 @@
List ejbCreates = new LinkedList();
- try {
- Method[] method = c.getMethods();
+ Method[] method = c.getMethods();
- for (int i = 0; i < method.length; ++i) {
+ for (int i = 0; i < method.length; ++i)
+ if (method[i].getName().equals(EJB_CREATE_METHOD))
+ ejbCreates.add(method[i]);
- if (method[i].getName().equals(EJB_CREATE_METHOD))
- ejbCreates.add(method[i]);
- }
- }
- catch (SecurityException e) {
- System.err.println(e);
- }
-
return ejbCreates.iterator();
}
-
- /*
- * Returns all methods of a class in an iterator
- */
- public Iterator getMethods(Class c) {
-
- try {
- Method[] method = c.getMethods();
- return Arrays.asList(method).iterator();
- }
- catch (SecurityException e) {
- System.err.println(e);
+ public Iterator getCreateMethods(Class c) {
+
+ List creates = new LinkedList();
+
+ Method[] method = c.getMethods();
+
+ for (int i = 0; i < method.length; ++i)
+ if (isCreateMethod(method[i]))
+ creates.add(method[i]);
- return null;
- }
+ return creates.iterator();
}
-
-
+
public boolean hasMoreThanOneCreateMethods(Class c) {
int count = 0;
- try {
- Method[] method = c.getMethods();
+ Method[] method = c.getMethods();
- for (int i = 0; i < method.length; ++i) {
+ for (int i = 0; i < method.length; ++i) {
- String name = method[i].getName();
+ String name = method[i].getName();
- if (name.equals(CREATE_METHOD)) {
- ++count;
- }
+ if (name.equals(CREATE_METHOD)) {
+ ++count;
}
}
- catch (SecurityException e) {
- System.err.println(e);
- }
return (count > 1);
}
-
- public boolean hasMatchingMethodNames(Class a, Class b) {
- // [TODO]
+
+ public boolean hasMatchingExceptions(Method source, Method target) {
+ // target must be a superset of source
+
+ Class[] a = source.getExceptionTypes();
+ Class[] b = source.getExceptionTypes();
+
+ for (int i = 0; i < a.length; ++i) {
+
+ boolean found = false;
+
+ for (int j = 0; j < b.length; ++j)
+ if (a[i] == b[j]) {
+ found = true;
+ break;
+ }
+
+ if (!found)
+ return false;
+ }
return true;
}
-
- public boolean hasMatchingMethodArgs(Class a, Class b) {
- // [TODO]
+ public boolean hasMatchingMethod(Class bean, Method remote) {
+
+ String methodName = remote.getName();
-
- return true;
+ try {
+ bean.getMethod(methodName, remote.getParameterTypes());
+
+ return true;
+ }
+ catch (NoSuchMethodException e) {
+ return false;
+ }
}
-
- public boolean hasMatchingMethodExceptions(Class a, Class b) {
-
- // [TODO]
-
-
- return true;
+
+ public boolean hasMatchingReturnType(Method a, Method b) {
+ return (a.getReturnType() == b.getReturnType());
}
-
+
public boolean hasMatchingEJBPostCreate(Class bean, Method ejbCreate) {
try {
- return (bean.getMethod(EJB_POST_CREATE, ejbCreate.getParameterTypes())
!= null);
+ return (bean.getMethod(EJB_POST_CREATE_METHOD,
ejbCreate.getParameterTypes()) != null);
}
catch (NoSuchMethodException e) {
return false;
}
}
-
+ public boolean hasMatchingEJBCreate(Class bean, Method create) {
+ try {
+ return (bean.getMethod(EJB_CREATE_METHOD, create.getParameterTypes())
!= null);
+ }
+ catch (NoSuchMethodException e) {
+ return false;
+ }
+ }
+
public Method getMatchingEJBPostCreate(Class bean, Method ejbCreate) {
try {
- return bean.getMethod(EJB_POST_CREATE, ejbCreate.getParameterTypes());
+ return bean.getMethod(EJB_POST_CREATE_METHOD,
ejbCreate.getParameterTypes());
}
catch (NoSuchMethodException e) {
return null;
}
}
+ public Method getMatchingEJBCreate(Class bean, Method create) {
+
+ try {
+ return bean.getMethod(EJB_CREATE_METHOD, create.getParameterTypes());
+ }
+ catch (NoSuchMethodException e) {
+ return null;
+ }
+ }
+
/*
*************************************************************************
@@ -664,16 +611,196 @@
*************************************************************************
*/
- private boolean hasInterface(Class c, String name) {
- try {
- Class intClass = Class.forName(name);
- return intClass.isAssignableFrom(c);
- } catch(Exception e) {}
+ private boolean isRMIIIOPType(Class type) {
+
+ /*
+ * Java Language to IDL Mapping
+ * ftp://ftp.omg.org/pub/docs/ptc/99-03-09.pdf
+ *
+ * A conforming RMI/IDL type is a Java type whose values
+ * may be transmitted across an RMI/IDL remote interface at
+ * run-time. A Java data type is a conforming RMI/IDL type
+ * if it is:
+ *
+ * - one of the Java primitive types (see Primitive Types on page 28-2).
+ * - a conforming remote interface (as defined in RMI/IDL Remote
Interfaces on page 28-2).
+ * - a conforming value type (as defined in RMI/IDL Value Types on page
28-4).
+ * - an array of conforming RMI/IDL types (see RMI/IDL Arrays on page
28-5).
+ * - a conforming exception type (see RMI/IDL Exception Types on page
28-5).
+ * - a conforming CORBA object reference type (see CORBA Object Reference
Types on page 28-6).
+ * - a conforming IDL entity type see IDL Entity Types on page 28-6).
+ */
+
+ /*
+ * Primitive types.
+ *
+ * Spec 28.2.2
+ */
+ if (type.isPrimitive())
+ return true;
+
+ /*
+ * Conforming array.
+ *
+ * Spec 28.2.5
+ */
+ if (type.isArray())
+ return isRMIIIOPType(type.getComponentType());
+
+ /*
+ * Conforming CORBA reference type
+ *
+ * Spec 28.2.7
+ */
+ if (org.omg.CORBA.Object.class.isAssignableFrom(type))
+ return true;
+
+ /*
+ * Conforming IDL Entity type
+ *
+ * Spec 28.2.8
+ */
+ if (org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(type))
+ return true;
+
+ /*
+ * Conforming remote interface.
+ *
+ * Spec 28.2.3
+ */
+ if (isRMIIDLRemoteInterface(type))
+ return true;
+
+ /*
+ * Conforming exception.
+ *
+ * Spec 28.2.6
+ */
+ if (isRMIIDLExceptionType(type))
+ return true;
+
+ /*
+ * Conforming value type.
+ *
+ * Spec 28.2.4
+ */
+ if (isRMIIDLValueType(type))
+ return true;
+
return false;
}
+
+ private boolean isRMIIDLRemoteInterface(Class type) {
+
+ if (!java.rmi.Remote.class.isAssignableFrom(type))
+ return false;
+
+ Iterator methodIterator = Arrays.asList(type.getMethods()).iterator();
+
+ while (methodIterator.hasNext()) {
+ Method m = (Method)methodIterator.next();
+
+ /*
+ * All methods in the interface MUST throw
+ * java.rmi.RemoteException or its subclass.
+ *
+ * Spec 28.2.3 (2)
+ */
+ if (!throwsRemoteException(m))
+ return false;
+
+ /*
+ * 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(m.getExceptionTypes()).iterator();
+
+ while (it.hasNext()) {
+ Class exception = (Class)it.next();
+
+ if (!isRMIIDLExceptionType(exception))
+ return false;
+ }
+ }
+
+ /*
+ * The constant values defined in the interface MUST be
+ * compile-time types of RMI/IDL primitive types or String.
+ *
+ * Spec 28.2.3 (6)
+ */
+ Iterator fieldIterator = Arrays.asList(type.getFields()).iterator();
+
+ while (fieldIterator.hasNext()) {
+
+ Field f = (Field)fieldIterator.next();
+
+ if (f.getType().isPrimitive())
+ continue;
+
+ if (f.getType().equals("java.lang.String"))
+ continue;
+
+ return false;
+ }
+
+ return true;
+ }
+
+
+ private boolean isRMIIDLExceptionType(Class type) {
+
+ /*
+ * A conforming RMI/IDL Exception class MUST be a checked
+ * exception class and MUST be a valid RMI/IDL value type.
+ *
+ * Spec 28.2.6
+ */
+ if (!Throwable.class.isAssignableFrom(type))
+ return false;
+
+ if (Error.class.isAssignableFrom(type))
+ return false;
+
+ if (RuntimeException.class.isAssignableFrom(type))
+ return false;
+
+ if (!isRMIIDLValueType(type))
+ return false;
+
+ return true;
+ }
+
+ private boolean isRMIIDLValueType(Class type) {
+
+ /*
+ * A value type MUST NOT either directly or indirectly implement the
+ * java.rmi.Remote interface.
+ *
+ * Spec 28.2.4 (4)
+ */
+ if (java.rmi.Remote.class.isAssignableFrom(type))
+ return false;
+
+ /*
+ * If class is a non-static inner class then its containing class must
+ * also be a conforming RMI/IDL value type.
+ *
+ * Spec 2.8.4 (3)
+ */
+ if (type.getDeclaringClass() != null && isStatic(type))
+ if (!isRMIIDLValueType(type.getDeclaringClass()))
+ return false;
+
+ return true;
+ }
+
/*
*************************************************************************
*
@@ -685,12 +812,6 @@
/*
* Ejb-jar DTD
*/
- public final static String DTD_EJB_CLASS =
- "Deployment descriptor DTD: ejb-class";
-
- public final static String DTD_HOME =
- "Deployment descriptor DTD: home";
-
public final static String BEAN_MANAGED_TX =
"Bean";
@@ -704,40 +825,7 @@
"Stateless";
-
/*
- * class names
- */
- private final static String SESSION_BEAN_INTERFACE =
- "javax.ejb.SessionBean";
-
- private final static String SESSION_SYNCHRONIZATION_INTERFACE =
- "javax.ejb.SessionSynchronization";
-
- private final static String ENTITY_BEAN_INTERFACE =
- "javax.ejb.EntityBean";
-
- private final static String SERIALIZATION_INTERFACE =
- "java.io.Serializable";
-
- private final static String COLLECTION_INTERFACE =
- "java.util.Collection";
-
- private final static String ENUMERATION_INTERFACE =
- "java.util.Enumeration";
-
- private final static String REMOTE_EXCEPTION =
- "java.rmi.RemoteException";
-
- private final static String EJB_OBJECT_INTERFACE =
- "javax.ejb.EJBObject";
-
- private final static String EJB_HOME_INTERFACE =
- "javax.ejb.EJBHome";
-
-
-
- /*
* method names
*/
private final static String EJB_FIND_BY_PRIMARY_KEY =
@@ -746,15 +834,27 @@
private final static String EJB_CREATE_METHOD =
"ejbCreate";
- private final static String EJB_POST_CREATE =
+ private final static String EJB_POST_CREATE_METHOD =
"ejbPostCreate";
+ private final static String EJB_POST_METHOD =
+ "ejbCreate";
+
private final static String CREATE_METHOD =
"create";
private final static String FINALIZE_METHOD =
"finalize";
+ private final static String REMOVE_METHOD =
+ "remove";
+
+ private final static String GET_HOME_HANDLE_METHOD =
+ "getHomeHandle";
+
+ private final static String GET_EJB_METADATA_METHOD =
+ "getEJBMetaData";
+
}
1.16 +317 -33 jboss/src/main/org/jboss/verifier/strategy/EJBVerifier11.java
Index: EJBVerifier11.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/verifier/strategy/EJBVerifier11.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- EJBVerifier11.java 2000/09/12 01:51:48 1.15
+++ EJBVerifier11.java 2000/09/24 15:21:50 1.16
@@ -19,12 +19,13 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* This package and its source code is available at www.jboss.org
- * $Id: EJBVerifier11.java,v 1.15 2000/09/12 01:51:48 mulder Exp $
+ * $Id: EJBVerifier11.java,v 1.16 2000/09/24 15:21:50 juha Exp $
*/
// standard imports
import java.util.Iterator;
+import java.util.Arrays;
import java.net.URL;
import java.net.URLClassLoader;
import java.lang.reflect.Member;
@@ -58,7 +59,9 @@
* @see org.jboss.verifier.strategy.AbstractVerifier
*
* @author Juha Lindfors ([EMAIL PROTECTED])
- * @version $Revision: 1.15 $
+ * @author Aaron Mulder ([EMAIL PROTECTED])
+ *
+ * @version $Revision: 1.16 $
* @since JDK 1.3
*/
public class EJBVerifier11 extends AbstractVerifier {
@@ -232,7 +235,7 @@
*
* Spec 6.10.6
*/
- Iterator it = getMethods(home);
+ Iterator it = Arrays.asList(home.getMethods()).iterator();
while (it.hasNext()) {
@@ -339,7 +342,7 @@
*
* Spec 6.10.5
*/
- Iterator it = getMethods(remote);
+ Iterator it = Arrays.asList(remote.getMethods()).iterator();
while (it.hasNext()) {
@@ -381,34 +384,57 @@
*
* Spec 6.10.5
*/
- try {
- String beanName = session.getEjbClass();
- Class bean = classloader.loadClass(beanName);
-
- if (!hasMatchingMethodNames(remote, bean)) {
+ String beanName = session.getEjbClass();
+ Class bean = classloader.loadClass(beanName);
- fireSpecViolationEvent(session, new Section("6.10.5.e"));
+ //Iterator iterator = getMethods(remote);
+ Iterator iterator =
Arrays.asList(remote.getDeclaredMethods()).iterator();
+
+ while (iterator.hasNext()) {
+
+ Method remoteMethod = (Method)iterator.next();
+ //Class[] remoteParams = remoteMethod.getParameterTypes();
+
+// try {
+ //String remoteName = remoteMethod.getName();
+
+ if (!hasMatchingMethod(bean, remoteMethod)) {
+
+ fireSpecViolationEvent(session, new Section("6.10.5.e"));
- status = false;
- }
-
- if (!hasMatchingMethodArgs(remote, bean)) {
-
- fireSpecViolationEvent(session, new Section("6.10.5.f"));
-
- status = false;
- }
-
- if (!hasMatchingMethodExceptions(remote, bean)) {
-
- fireSpecViolationEvent(session, new Section("6.10.5.g"));
-
- status = false;
+ status = false;
+ }
+// Method beanMethod = bean.getMethod(remoteMethodName,
remoteParams);
+
+ if (hasMatchingMethod(bean, remoteMethod)) {
+
+ try {
+ Method beanMethod = bean.getMethod(remoteMethod.getName(),
remoteMethod.getParameterTypes());
+
+ if (!hasMatchingReturnType(remoteMethod, beanMethod)) {
+
+ fireSpecViolationEvent(session, new Section("6.10.5.f"));
+
+ status = false;
+ }
+
+ if (!hasMatchingExceptions(remoteMethod, beanMethod)) {
+
+ fireSpecViolationEvent(session, new Section("6.10.5.g"));
+
+ status = false;
+ }
+ } catch (NoSuchMethodException ignored) {}
}
+// }
+// catch (NoSuchMethodException e) {
+
+ //fireSpecViolationEvent(session, new Section("6.10.5.e"));
+
+// status = false;
+// }
}
- catch (ClassNotFoundException ignored) {}
-
}
catch (ClassNotFoundException e) {
@@ -662,8 +688,158 @@
try {
Class home = classloader.loadClass(name);
+ /*
+ * Entity bean's home interface MUST extend the javax.ejb.EJBHome
+ * interface.
+ *
+ * Spec 9.2.8
+ */
+ if (!hasEJBHomeInterface(home)) {
+
+ fireSpecViolationEvent(entity, new Section("9.2.8.a"));
+
+ status = false;
+ }
+
+ /*
+ * The methods defined in the entity bean's home interface MUST
+ * have valid RMI-IIOP argument types.
+ *
+ * The methods defined in the entity bean's home interface MUST
+ * have valid RMI-IIOP return types.
+ *
+ * The methods defined in the entity bean's home interface MUST
+ * have java.rmi.RemoteException in their throws clause.
+ *
+ * Spec 9.2.8
+ */
+ Iterator homeMethods = Arrays.asList(home.getMethods()).iterator();
+
+ while (homeMethods.hasNext()) {
+ Method method = (Method)homeMethods.next();
+ if (!hasLegalRMIIIOPArguments(method)) {
+
+ fireSpecViolationEvent(entity, new Section("9.2.8.b"));
+
+ status = false;
+ }
+
+ if (!hasLegalRMIIIOPReturnType(method)) {
+
+ fireSpecViolationEvent(entity, new Section("9.2.8.c"));
+
+ status = false;
+ }
+
+ if (!throwsRemoteException(method)) {
+
+ fireSpecViolationEvent(entity, new Section("9.2.8.d"));
+
+ status = false;
+ }
+ }
+
+ /*
+ * Each method defined in the entity bean's home interface must be
+ * one of the following:
+ *
+ * - a create method
+ * - a finder method
+ *
+ * Spec 9.2.8
+ */
+ homeMethods = Arrays.asList(home.getMethods()).iterator();
+
+ while (homeMethods.hasNext()) {
+
+ Method method = (Method)homeMethods.next();
+
+ // Do not check the methods of the javax.ejb.EJBHome interface
+ if (method.getDeclaringClass().getName().equals(EJB_HOME_INTERFACE))
+ continue;
+
+ if (! (isCreateMethod(method) || isFinderMethod(method)) ) {
+
+ fireSpecViolationEvent(entity, new Section("9.2.8.e"));
+
+ status = false;
+ }
+ }
+
+ /*
+ * Each create(...) method in the entity bean's home interface MUST
+ * have a matching ejbCreate(...) method in the entity bean's class.
+ *
+ * Each create(...) method in the entity bean's home interface MUST
+ * have the same number and types of arguments to its matching
+ * ejbCreate(...) method.
+ *
+ * The return type for a create(...) method MUST be the entity
+ * bean's remote interface type.
+ *
+ * All the exceptions defined in the throws clause of the matching
+ * ejbCreate(...) and ejbPostCreate(...) methods of the enterprise
+ * bean class MUST be included in the throws clause of a matching
+ * create(...) method.
+ *
+ * The throws clause of a create(...) method MUST include the
+ * javax.ejb.CreateException.
+ *
+ * Spec 9.2.8
+ */
+ Iterator createMethods = getCreateMethods(home);
+
+ try {
+ String beanClass = entity.getEjbClass();
+ Class bean = classloader.loadClass(beanClass);
+
+ while (createMethods.hasNext()) {
+
+ Method create = (Method)createMethods.next();
+
+ if (!hasMatchingEJBCreate(bean, create)) {
+
+ fireSpecViolationEvent(entity, new Section("9.2.8.f"));
+
+ status = false;
+ }
+
+ if (!hasRemoteReturnType(entity, create)) {
+
+ fireSpecViolationEvent(entity, new Section("9.2.8.g"));
+
+ status = false;
+ }
+
+ if (hasMatchingEJBCreate(bean, create) &&
+ hasMatchingEJBPostCreate(bean, create)) {
+
+ Method ejbCreate = getMatchingEJBCreate(bean, create);
+ Method ejbPostCreate = getMatchingEJBPostCreate(bean,
create);
+
+ if ( !(hasMatchingExceptions(ejbCreate, create) &&
+ hasMatchingExceptions(ejbPostCreate, create)) ) {
+
+ fireSpecViolationEvent(entity, new Section("9.2.8.h"));
+ }
+ }
+
+ if (!throwsCreateException(create)) {
+
+ fireSpecViolationEvent(entity, new Section("9.2.8.i"));
+
+ status = false;
+ }
+ }
+ }
+ catch (ClassNotFoundException ignored) {}
+
+
+ /* [TODO] finders */
+
+
}
catch (ClassNotFoundException e) {
@@ -679,7 +855,6 @@
}
return status;
-
}
@@ -703,9 +878,122 @@
try {
- Class home = classloader.loadClass(name);
+ Class remote = classloader.loadClass(name);
+
+ /*
+ * Entity bean's remote interface MUST extend
+ * the javax.ejb.EJBObject interface.
+ *
+ * Spec 9.2.7
+ */
+ if (!hasEJBObjectInterface(remote)) {
+
+ fireSpecViolationEvent(entity, new Section("9.2.7.a"));
+
+ status = false;
+ }
+
+ /*
+ * The methods defined in the entity bean's remote interface MUST
+ * have valid RMI-IIOP argument types.
+ *
+ * The methods defined in the entity bean's home interface MUST
+ * have valid RMI-IIOP return types.
+ *
+ * The methods defined in the entity bean's home interface MUST
+ * have java.rmi.RemoteException in their throws clause.
+ *
+ * Spec 9.2.7
+ */
+ Iterator remoteMethods = Arrays.asList(remote.getMethods()).iterator();
+
+ while (remoteMethods.hasNext()) {
+
+ Method method = (Method)remoteMethods.next();
+
+ if (!hasLegalRMIIIOPArguments(method)) {
+ fireSpecViolationEvent(entity, new Section("9.2.7.b"));
+ status = false;
+ }
+
+ if (!hasLegalRMIIIOPReturnType(method)) {
+
+ fireSpecViolationEvent(entity, new Section("9.2.7.c"));
+
+ status = false;
+ }
+
+ if (!throwsRemoteException(method)) {
+
+ fireSpecViolationEvent(entity, new Section("9.2.7.d"));
+
+ status = false;
+ }
+ }
+
+ /*
+ * For each method defined in the remote interface, there MUST be
+ * a matching method in the entity bean's class. The matching
+ * method MUST have:
+ *
+ * - The same name.
+ * - The same number and types of its arguments.
+ * - The same return type.
+ * - All the exceptions defined in the throws clause of the
+ * matching method of the enterprise Bean class must be
+ * defined in the throws clause of the method of the remote
+ * interface.
+ *
+ * Spec 9.2.7
+ */
+ remoteMethods = Arrays.asList(remote.getMethods()).iterator();
+
+ try {
+ String beanClass = entity.getEjbClass();
+ Class bean = classloader.loadClass(beanClass);
+
+ while (remoteMethods.hasNext()) {
+
+ Method method = (Method)remoteMethods.next();
+
+ // Do not check the methods of the javax.ejb.EJBObject interface
+ if
(method.getDeclaringClass().getName().equals(EJB_OBJECT_INTERFACE))
+ continue;
+
+ if (!hasMatchingMethod(bean, method)) {
+
+ fireSpecViolationEvent(entity, new Section("9.2.7.e"));
+
+ status = false;
+ }
+
+ if (hasMatchingMethod(bean, method)) {
+
+ try {
+ Method beanMethod = bean.getMethod(method.getName(),
method.getParameterTypes());
+
+ if (!hasMatchingReturnType(beanMethod, method)) {
+
+ fireSpecViolationEvent(entity, new
Section("9.2.7.f"));
+
+ status = false;
+ }
+
+ if (!hasMatchingExceptions(beanMethod, method)) {
+
+ fireSpecViolationEvent(entity, new
Section("9.2.7.g"));
+
+ status = false;
+ }
+ }
+ catch (NoSuchMethodException ignored) {}
+ }
+ }
+ }
+ catch (ClassNotFoundException ignored) {}
+
}
catch (ClassNotFoundException e) {
@@ -944,10 +1232,6 @@
* Spec 9.2.5
*/
if (entity.isBMP() && (!hasEJBFindByPrimaryKey(bean))) {
- /* Even though the spec states that all entities must have the
- * ejbFindByPrimaryKey() implementation, we only check BMP.
- * For CMP it is the responsibility of the container to
- * provide the implementation. */
fireSpecViolationEvent(entity, new Section("9.2.5.a"));