1 18 package org.apache.beehive.controls.system.ejb; 19 20 import org.apache.beehive.controls.api.ControlException; 21 22 import javax.ejb.EJBLocalHome ; 23 import javax.ejb.FinderException ; 24 import java.util.HashMap ; 25 import java.util.Vector ; 26 import java.lang.reflect.Method ; 27 28 34 public class EJBInfo 35 { 36 public String _refName; 37 public Class _homeInterface; 38 public Class _beanInterface; 39 public String _beanType; 40 public boolean _isLocal; 41 42 public String toString() 43 { 44 return "{refname=" + _refName + " home=" + _homeInterface.getName() + " remote=" + _beanInterface.getName() + 45 " type=" + _beanType + " local=" + _isLocal + "}"; 46 } 47 48 51 public EJBInfo(Class controlInterface) 52 { 53 _refName = getEJBRefName( controlInterface ); 54 55 Class localHome = null; 56 Class localBean = null; 57 Class remoteHome = null; 58 Class remoteBean = null; 59 60 Vector checkList = new Vector (); 66 Class [] subintfs = controlInterface.getInterfaces(); 67 for (int i = 0; i < subintfs.length; i++) 68 checkList.add(subintfs[i]); 69 70 HashMap derivesFrom = new HashMap (); 71 for (int i = 0; i < checkList.size(); i++) 72 { 73 Class intf = (Class )checkList.elementAt(i); 74 75 if (javax.ejb.EJBHome .class.isAssignableFrom(intf)) 76 remoteHome = intf; 77 else if (javax.ejb.EJBLocalHome .class.isAssignableFrom(intf)) 78 localHome = intf; 79 else if (javax.ejb.EJBObject .class.isAssignableFrom(intf)) 80 remoteBean = intf; 81 else if (javax.ejb.EJBLocalObject .class.isAssignableFrom(intf)) 82 localBean = intf; 83 else 84 { 85 subintfs = intf.getInterfaces(); 90 for (int j = 0; j < subintfs.length; j++) 91 { 92 if (!checkList.contains(subintfs[j])) 93 { 94 checkList.add(subintfs[j]); 95 derivesFrom.put(subintfs[j], intf); 96 } 97 } 98 } 99 } 100 101 if (remoteHome != null) 105 { 106 if (localHome != null) 107 { 108 throw new ControlException(controlInterface + 109 " extends multiple EJB home interfaces."); 110 } 111 _homeInterface = getRoot(remoteHome, derivesFrom); 112 } 113 else if (localHome != null) 114 { 115 _homeInterface = getRoot(localHome, derivesFrom); 116 } 117 else 118 { 119 throw new ControlException(controlInterface + 120 " does not extend the EJBHome or EJBLocalHome interfaces"); 121 } 122 123 if (remoteBean != null) 124 { 125 if (localBean != null) 126 { 127 throw new ControlException("Interface " + controlInterface + 128 " extends multiple EJB object interfaces."); 129 } 130 _beanInterface = getRoot(remoteBean, derivesFrom); 131 } 132 else if (localBean != null) 133 { 134 _beanInterface = getRoot(localBean, derivesFrom); 135 } 136 else 137 { 138 throw new ControlException("Interface " + controlInterface + 139 " does not extend the EJBObject or EJBLocalObject interfaces"); 140 } 141 142 _beanType = "Session"; 144 Method [] homeMethods = _homeInterface.getMethods(); 145 for (int i = 0; i < homeMethods.length; i++) 146 { 147 if (isFinderMethod(homeMethods[i])) 148 { 149 _beanType = "Entity"; 150 break; 151 } 152 } 153 154 _isLocal = (EJBLocalHome .class.isAssignableFrom(_homeInterface)); 155 } 156 157 161 public Class getRoot(Class clazz, HashMap derivesFrom) 162 { 163 while (derivesFrom.containsKey(clazz)) 164 clazz = (Class )derivesFrom.get(clazz); 165 return clazz; 166 } 167 168 static protected boolean isFinderMethod(Method m) 169 { 170 if (!m.getName().startsWith("find")) return false; 172 return methodThrows(m, FinderException .class); 173 } 174 175 static protected boolean methodThrows(Method m, Class exceptionClass) 176 { 177 Class [] exceptions = m.getExceptionTypes(); 178 for (int j = 0; j < exceptions.length; j++) 179 if (exceptionClass.isAssignableFrom(exceptions[j])) 180 return true; 181 return false; 182 } 183 184 187 static public String getEJBRefName(Class jcxClass) 188 { 189 return jcxClass.getName() + ".jcx"; 190 } 191 192 } 193 194 | Popular Tags |