User: juha
Date: 00/11/14 11:54:33
Modified: src/main/org/jboss/verifier/strategy EJBVerifier11.java
AbstractVerifier.java
Log:
9.2.8 Finders for entity home interface
Revision Changes Path
1.24 +64 -3 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.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- EJBVerifier11.java 2000/11/05 19:02:36 1.23
+++ EJBVerifier11.java 2000/11/14 19:54:33 1.24
@@ -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: EJBVerifier11.java,v 1.23 2000/11/05 19:02:36 juha Exp $
+ * $Id: EJBVerifier11.java,v 1.24 2000/11/14 19:54:33 juha Exp $
*/
@@ -54,7 +54,7 @@
* @author Juha Lindfors ([EMAIL PROTECTED])
* @author Aaron Mulder ([EMAIL PROTECTED])
*
- * @version $Revision: 1.23 $
+ * @version $Revision: 1.24 $
* @since JDK 1.3
*/
public class EJBVerifier11 extends AbstractVerifier {
@@ -875,10 +875,71 @@
}
catch (ClassNotFoundException ignored) {}
-
- /* [TODO] finders */
+ /*
+ * Each finder method MUST match one of the ejbFind<METHOD> methods
+ * defined in the entity bean class.
+ *
+ * The matching ejbFind<METHOD> method MUST have the same number and
+ * types of arguments.
+ *
+ * The return type for a find<METHOD> method MUST be the entity
+ * bean's remote interface type (single-object finder) or a
+ * collection thereof (for a multi-object finder).
+ *
+ * All the exceptions defined in the throws clause of an ejbFind
+ * method of the entity bean class MUST be included in the throws
+ * clause of the matching find method of the home interface.
+ *
+ * The throws clause of a finder method MUST include the
+ * javax.ejb.FinderException.
+ *
+ * Spec 9.2.8
+ */
+ Iterator finderMethods = getFinderMethods(home);
+ try {
+ String beanClass = entity.getEjbClass();
+ Class bean = classloader.loadClass(beanClass);
+
+ while (finderMethods.hasNext()) {
+
+ Method finder = (Method)finderMethods.next();
+
+ if ((entity.isBMP()) && (!hasMatchingEJBFind(bean, finder))) {
+
+ fireSpecViolationEvent(entity, finder, new
Section("9.2.8.j"));
+
+ status = false;
+ }
+
+ if (!(hasRemoteReturnType(entity, finder) ||
isMultiObjectFinder(finder))) {
+
+ fireSpecViolationEvent(entity, finder, new
Section("9.2.8.k"));
+
+ status = false;
+ }
+
+ if ((entity.isBMP()) && (hasMatchingEJBFind(bean, finder))) {
+
+ Method ejbFind = getMatchingEJBFind(bean, finder);
+
+ if ( !(hasMatchingExceptions(ejbFind, finder)))
+ fireSpecViolationEvent(entity, finder, new
Section("9.2.8.l"));
+
+ }
+
+ if (!throwsFinderException(finder)) {
+
+ fireSpecViolationEvent(entity, finder, new
Section("9.2.8.m"));
+
+ status = false;
+ }
+ }
+ }
+ catch (ClassNotFoundException ignored) {}
+
+
}
catch (ClassNotFoundException e) {
@@ -1314,7 +1375,7 @@
*/
if (hasFinderMethod(bean)) {
- Iterator it = getFinderMethods(bean);
+ Iterator it = getEJBFindMethods(bean);
while (it.hasNext()) {
1.15 +57 -2 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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- AbstractVerifier.java 2000/11/05 19:02:36 1.14
+++ AbstractVerifier.java 2000/11/14 19:54:33 1.15
@@ -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.14 2000/11/05 19:02:36 juha Exp $
+ * $Id: AbstractVerifier.java,v 1.15 2000/11/14 19:54:33 juha Exp $
*/
// standard imports
@@ -61,7 +61,7 @@
* @author Juha Lindfors ([EMAIL PROTECTED])
* @author Aaron Mulder ([EMAIL PROTECTED])
*
- * @version $Revision: 1.14 $
+ * @version $Revision: 1.15 $
* @since JDK 1.3
*/
public abstract class AbstractVerifier implements VerificationStrategy {
@@ -179,7 +179,21 @@
return false;
}
-
+ /*
+ * checks if the methods includes javax.ejb.FinderException in its
+ * throws clause.
+ */
+ public boolean throwsFinderException(Method method) {
+
+ Class[] exception = method.getExceptionTypes();
+
+ for (int i = 0; i < exception.length; ++i)
+ if (javax.ejb.FinderException.class.isAssignableFrom(exception[i]))
+ return true;
+
+ return false;
+ }
+
/*
* checks if a class's member (method, constructor or field) has a 'static'
@@ -509,7 +523,7 @@
/*
* returns the ejbFind<METHOD> methods of a bean
*/
- public Iterator getFinderMethods(Class c) {
+ public Iterator getEJBFindMethods(Class c) {
List finders = new LinkedList();
@@ -526,6 +540,24 @@
/*
+ * returns the finder methods of a home interface
+ */
+ public Iterator getFinderMethods(Class home) {
+
+ List finders = new LinkedList();
+
+ Method[] method = home.getMethods();
+
+ for (int i = 0; i < method.length; ++i) {
+
+ if (method[i].getName().startsWith("find"))
+ finders.add(method[i]);
+ }
+
+ return finders.iterator();
+ }
+
+ /*
* Returns the ejbCreate(...) methods of a bean
*/
public Iterator getEJBCreateMethods(Class c) {
@@ -624,6 +656,7 @@
}
}
+
public boolean hasMatchingEJBCreate(Class bean, Method create) {
try {
return (bean.getMethod(EJB_CREATE_METHOD, create.getParameterTypes())
!= null);
@@ -653,6 +686,28 @@
}
}
+ public boolean hasMatchingEJBFind(Class bean, Method finder) {
+ try {
+ String methodName = "ejbF" + finder.getName().substring(1);
+
+ return (bean.getMethod(methodName, finder.getParameterTypes()) != null);
+ }
+ catch (NoSuchMethodException e) {
+ return false;
+ }
+ }
+
+ public Method getMatchingEJBFind(Class bean, Method finder) {
+ try {
+ String methodName = "ejbF" + finder.getName().substring(1);
+
+ return bean.getMethod(methodName, finder.getParameterTypes());
+ }
+ catch (NoSuchMethodException e) {
+ return null;
+ }
+ }
+
/*
*************************************************************************
*