1 22 package org.jboss.verifier.strategy; 23 24 26 import org.jboss.metadata.EntityMetaData; 27 import org.jboss.metadata.QueryMetaData; 28 import org.jboss.util.Classes; 29 30 import java.lang.reflect.Method ; 31 import java.util.Iterator ; 32 import java.util.LinkedList ; 33 import java.util.List ; 34 35 41 42 public abstract class AbstractEJB2xVerifier extends AbstractVerifier 43 { 44 protected EJBVerifier11 cmp1XVerifier; 45 46 protected Class bean; 48 protected Class home; 49 protected Class remote; 50 protected Class localHome; 51 protected Class local; 52 protected Class serviceEndpointInterface; 53 54 57 public AbstractEJB2xVerifier(VerificationContext context) 58 { 59 super(context); 60 cmp1XVerifier = new EJBVerifier11(context); 61 } 62 63 66 public boolean isCreateMethod(Method m) 67 { 68 return m.getName().startsWith(CREATE_METHOD); 69 } 70 71 public boolean isEjbCreateMethod(Method m) 72 { 73 return m.getName().startsWith(EJB_CREATE_METHOD); 74 } 75 76 public boolean isEjbRemoveMethod(Method m) 77 { 78 return m.getName().startsWith(EJB_REMOVE_METHOD); 79 } 80 81 public boolean isEjbSelectMethod(Method m) 82 { 83 return m.getName().startsWith(EJB_SELECT_METHOD); 84 } 85 86 public boolean isEjbHomeMethod(Method m) 87 { 88 return m.getName().startsWith(EJB_HOME_METHOD); 89 } 90 91 93 public boolean hasRemoteInterface(Class c) 94 { 95 return isAssignableFrom("java.rmi.Remote", c); 96 } 97 98 101 public Iterator getEjbSelectMethods(Class c) 102 { 103 List selects = new LinkedList (); 104 Method [] method = c.getMethods(); 105 106 for (int i = 0; i < method.length; ++i) 107 { 108 if (isEjbSelectMethod(method[i])) 109 { 110 selects.add(method[i]); 111 } 112 } 113 114 return selects.iterator(); 115 } 116 117 120 public boolean hasEJBRemoveMethod(Class c) 121 { 122 Method [] method = c.getMethods(); 123 for (int i = 0; i < method.length; ++i) 124 { 125 if (isEjbRemoveMethod(method[i])) 126 return true; 127 } 128 129 return false; 130 } 131 132 135 public Iterator getEJBRemoveMethods(Class c) 136 { 137 List ejbRemoves = new LinkedList (); 138 Method [] method = c.getMethods(); 139 140 for (int i = 0; i < method.length; ++i) 141 { 142 if (isEjbRemoveMethod(method[i])) 143 ejbRemoves.add(method[i]); 144 } 145 146 return ejbRemoves.iterator(); 147 } 148 149 153 public Iterator getHomeMethods(Class c) 154 { 155 List homes = new LinkedList (); 156 Method [] method = c.getMethods(); 157 158 for (int i = 0; i < method.length; ++i) 159 { 160 if (!isCreateMethod(method[i]) && !isFinderMethod(method[i])) 161 homes.add(method[i]); 162 } 163 164 return homes.iterator(); 165 } 166 167 public Iterator getEjbHomeMethods(Class c) 168 { 169 List homes = new LinkedList (); 170 Method [] method = c.getMethods(); 171 172 for (int i = 0; i < method.length; ++i) 173 { 174 if (isEjbHomeMethod(method[i])) 175 homes.add(method[i]); 176 } 177 178 return homes.iterator(); 179 } 180 181 191 protected boolean hasMatchingQuery(Method m, EntityMetaData e) 192 { 193 boolean result = false; 194 195 Iterator qIt = e.getQueries(); 196 while (qIt.hasNext()) 197 { 198 QueryMetaData qmd = (QueryMetaData)qIt.next(); 199 200 if (!qmd.getMethodName().equals(m.getName())) 202 { 203 continue; 204 } 205 206 Class [] methodParameter = m.getParameterTypes(); 207 Class [] queryParameter = null; 208 209 try 210 { 211 queryParameter = Classes.convertToJavaClasses(qmd.getMethodParams(), classloader); 212 } 213 catch (ClassNotFoundException cnfe) 214 { 215 continue; 219 } 220 221 if (methodParameter.length != queryParameter.length) 223 { 224 continue; 225 } 226 227 boolean parametersMatch = true; 229 for (int i = 0; i < methodParameter.length; i++) 230 { 231 if (!methodParameter[i].equals(queryParameter[i])) 232 { 233 parametersMatch = false; 234 break; 235 } 236 } 237 238 if (parametersMatch) 239 { 240 result = true; 241 break; 242 } 243 } 244 245 return result; 246 } 247 } 248 | Popular Tags |