You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by cs...@apache.org on 2006/05/17 17:22:07 UTC
svn commit: r407282 -
/beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EJBControlImpl.java
Author: cschoett
Date: Wed May 17 08:22:06 2006
New Revision: 407282
URL: http://svn.apache.org/viewvc?rev=407282&view=rev
Log:
A bit of cleanup to remove the NoSuchMethod exception from the mapping from a control bean method to an ejb method.
Modified:
beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EJBControlImpl.java
Modified: beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EJBControlImpl.java
URL: http://svn.apache.org/viewvc/beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EJBControlImpl.java?rev=407282&r1=407281&r2=407282&view=diff
==============================================================================
--- beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EJBControlImpl.java (original)
+++ beehive/trunk/system-controls/src/ejb/org/apache/beehive/controls/system/ejb/EJBControlImpl.java Wed May 17 08:22:06 2006
@@ -115,22 +115,59 @@
return m.getDeclaringClass().isAssignableFrom(context.getControlBean().getClass());
}
- // todo: finish this method
- protected Method mapControlBeanMethodToEJB(Method m) throws NoSuchMethodException {
- try {
- return _homeInterface.getMethod(m.getName(), m.getParameterTypes());
- }
- catch (NoSuchMethodException e) {
- // not an error, check remote and bean interface
+ /**
+ * Map a control bean method to an EJB method.
+ *
+ * @param m The control bean method.
+ * @return The corresponding method of the EJB.
+ */
+ protected Method mapControlBeanMethodToEJB(Method m) {
+ Method ejbMethod = findEjbMethod(m, _homeInterface);
+ if (ejbMethod == null) {
+ if (_beanInstance == null) {
+ _beanInstance = resolveBeanInstance();
+ if (_beanInstance == null) {
+ throw new ControlException("Unable to resolve bean instance");
+ }
+ }
+ ejbMethod = findEjbMethod(m, _beanInstance.getClass());
+ if (ejbMethod == null) {
+ throw new ControlException("Unable to map ejb control interface method to EJB method: " + m.getName());
+ }
}
+ return ejbMethod;
+ }
- if (_beanInstance == null) {
- _beanInstance = resolveBeanInstance();
- if (_beanInstance == null) {
- throw new ControlException("Unable to resolve bean instance");
+ /**
+ * Find the method which has the same signature in the specified class.
+ *
+ * @param controlBeanMethod Method signature find.
+ * @param ejbInterface Class to search for method signature.
+ * @return Method from ejbInterface if found, null if not found.
+ */
+ protected Method findEjbMethod(Method controlBeanMethod, Class ejbInterface) {
+ final String cbMethodName = controlBeanMethod.getName();
+ final Class cbMethodReturnType = controlBeanMethod.getReturnType();
+ final Class[] cbMethodParams = controlBeanMethod.getParameterTypes();
+
+ Method[] ejbMethods = ejbInterface.getMethods();
+ for (Method m : ejbMethods) {
+ if (!cbMethodName.equals(m.getName())
+ || !cbMethodReturnType.equals(m.getReturnType())) {
+ continue;
+ }
+
+ Class[] params = m.getParameterTypes();
+ if (cbMethodParams.length == params.length) {
+ int i;
+ for (i = 0; i < cbMethodParams.length; i++) {
+ if (cbMethodParams[i] != params[i]) break;
+ }
+ if (i == cbMethodParams.length)
+ return m;
}
}
- return _beanInstance.getClass().getMethod(m.getName(), m.getParameterTypes());
+ return null;
}
protected static boolean isCreateMethod(Method m) {