1 22 package org.jboss.metadata; 23 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 import java.util.HashSet ; 28 29 import org.w3c.dom.Element ; 30 31 import org.jboss.deployment.DeploymentException; 32 import org.jboss.invocation.InvocationType; 33 34 59 public class MethodMetaData extends MetaData 60 { 61 public static final int ANY_METHOD = -1; 64 public static String HOME_TYPE = "Home"; 65 public static String LOCAL_HOME_TYPE = "LocalHome"; 66 public static String REMOTE_TYPE = "Remote"; 67 public static String LOCAL_TYPE = "Local"; 68 public static String SERVICE_ENDPOINT_TYPE = "ServiceEndpoint"; 69 70 private static final ArrayList EMPTY_PARAM_LIST = new ArrayList (); 71 72 78 private String methodName; 79 81 private String ejbName; 82 83 95 private boolean intf = false; 96 98 private InvocationType methodType = null; 99 private boolean param = false; 100 104 private boolean unchecked = false; 105 110 private boolean excluded = false; 111 114 private ArrayList paramList = EMPTY_PARAM_LIST; 115 126 private byte transactionType; 127 128 private Set roles = new HashSet (); 129 130 132 public MethodMetaData() 134 { 135 } 136 137 139 public String getMethodName() 140 { 141 return methodName; 142 } 143 144 public void setMethodName(String methodName) 145 { 146 this.methodName = methodName; 147 } 148 149 public String getEjbName() 150 { 151 return ejbName; 152 } 153 154 public void setEjbName(String ejbName) 155 { 156 this.ejbName = ejbName; 157 } 158 159 public boolean isHomeMethod() 160 { 161 return methodType == InvocationType.HOME; 162 } 163 164 public boolean isRemoteMethod() 165 { 166 return methodType == InvocationType.REMOTE; 167 } 168 169 public boolean isLocalHomeMethod() 170 { 171 return methodType == InvocationType.LOCALHOME; 172 } 173 174 public boolean isLocalMethod() 175 { 176 return methodType == InvocationType.LOCAL; 177 } 178 179 public boolean isServiceEndpointMethod() 180 { 181 return methodType == InvocationType.SERVICE_ENDPOINT; 182 } 183 184 189 public String getInterfaceType() 190 { 191 String type = null; 192 if( isHomeMethod() ) 193 type = HOME_TYPE; 194 if( isLocalHomeMethod() ) 195 type = LOCAL_HOME_TYPE; 196 if( isRemoteMethod() ) 197 type = REMOTE_TYPE; 198 if( isLocalMethod() ) 199 type = LOCAL_TYPE; 200 if( isServiceEndpointMethod() ) 201 type = SERVICE_ENDPOINT_TYPE; 202 return type; 203 } 204 205 public void setInterfaceType(String methodIntf) 206 { 207 if (methodIntf.equals("Home")) 208 { 209 methodType = InvocationType.HOME; 210 } 211 else if (methodIntf.equals("Remote")) 212 { 213 methodType = InvocationType.REMOTE; 214 } 215 else if (methodIntf.equals("LocalHome")) 216 { 217 methodType = InvocationType.LOCALHOME; 218 } 219 else if (methodIntf.equals("Local")) 220 { 221 methodType = InvocationType.LOCAL; 222 } 223 else if (methodIntf.equals("ServiceEndpoint")) 224 { 225 methodType = InvocationType.SERVICE_ENDPOINT; 226 } 227 else 228 { 229 throw new IllegalStateException ("method-intf tag should be one of: 'Home', 'Remote', 'LocalHome', 'Local', 'ServiceEndpoint'"); 230 } 231 intf = true; 232 } 233 234 public boolean isUnchecked() 235 { 236 return unchecked; 237 } 238 239 public boolean isExcluded() 240 { 241 return excluded; 242 } 243 244 public boolean isIntfGiven() 245 { 246 return intf; 247 } 248 249 public boolean isParamGiven() 250 { 251 return param; 252 } 253 254 257 public Iterator getParams() 258 { 259 return paramList.iterator(); 260 } 261 265 public String [] getMethodParams() 266 { 267 String [] params = new String [paramList.size()]; 268 paramList.toArray(params); 269 return params; 270 } 271 272 public byte getTransactionType() 273 { 274 return transactionType; 275 } 276 277 public void setTransactionType(byte type) 278 { 279 transactionType = type; 280 } 281 282 public Set getRoles() 283 { 284 return roles; 285 } 286 287 public void setRoles(Set perm) 288 { 289 roles = perm; 290 } 291 292 public void setUnchecked() 293 { 294 unchecked = true; 295 } 296 297 public void setExcluded() 298 { 299 excluded = true; 300 } 301 302 public boolean patternMatches(String name, Class [] arg, InvocationType iface) 303 { 304 return patternMatches(name, getClassNames(arg), iface); 305 } 306 307 public boolean patternMatches(String name, String [] arg, InvocationType iface) 308 { 309 if (getMethodName().equals("*")) 311 { 312 if (methodType != null && methodType != iface) 313 return false; 314 return true; 315 } 316 317 if (getMethodName().equals(name) == false) 318 { 319 return false; 321 } 322 else 323 { 324 if (methodType != null && methodType != iface) 326 return false; 327 328 if (isParamGiven() == false) 329 { 330 return true; 332 } 333 else 334 { 335 return sameParams(arg); 337 } 338 } 339 } 340 341 public void addParam(String param) 342 { 343 if(paramList == null) 344 { 345 this.param = true; 346 paramList = new ArrayList (); 347 } 348 paramList.add(param); 349 } 350 351 354 public void importEjbJarXml(Element element) throws DeploymentException 355 { 356 methodName = getElementContent(getUniqueChild(element, "method-name")); 357 ejbName = getElementContent(getUniqueChild(element, "ejb-name")); 358 359 Element intfElement = getOptionalChild(element, "method-intf"); 360 if (intfElement != null) 361 { 362 String methodIntf = getElementContent(intfElement); 363 setInterfaceType(methodIntf); 364 } 365 366 Element paramsElement = getOptionalChild(element, "method-params"); 367 if (paramsElement != null) 368 { 369 param = true; 370 paramList = new ArrayList (); 371 Iterator paramsIterator = getChildrenByTagName(paramsElement, "method-param"); 372 while (paramsIterator.hasNext()) 373 { 374 paramList.add(getElementContent((Element ) paramsIterator.next())); 375 } 376 } 377 } 378 379 381 383 private static String [] getClassNames(Class [] source) 385 { 386 String out[] = new String [source.length]; 387 for (int i = 0; i < out.length; i++) 388 { 389 String brackets = ""; 390 Class cls = source[i]; 391 while (cls.isArray()) 392 { 393 brackets += "[]"; 394 cls = cls.getComponentType(); 395 } 396 out[i] = cls.getName() + brackets; 397 } 398 return out; 399 } 400 401 private boolean sameParams(String [] arg) 402 { 403 if (arg.length != paramList.size()) return false; 404 for (int i = 0; i < arg.length; i++) 405 if (!arg[i].equals(paramList.get(i))) 406 return false; 407 return true; 408 } 409 410 public static byte getTransactionAttribute(String type) 411 { 412 if (type.equalsIgnoreCase("NotSupported") || 413 type.equalsIgnoreCase("Not_Supported")) 414 { 415 return TX_NOT_SUPPORTED; 416 } 417 else if (type.equalsIgnoreCase("Supports")) 418 { 419 return TX_SUPPORTS; 420 } 421 else if (type.equalsIgnoreCase("Required")) 422 { 423 return TX_REQUIRED; 424 } 425 else if (type.equalsIgnoreCase("RequiresNew") || 426 type.equalsIgnoreCase("Requires_New")) 427 { 428 return TX_REQUIRES_NEW; 429 } 430 else if (type.equalsIgnoreCase("Mandatory")) 431 { 432 return TX_MANDATORY; 433 } 434 else if (type.equalsIgnoreCase("Never")) 435 { 436 return TX_NEVER; 437 } 438 439 throw new IllegalStateException ("invalid <transaction-attribute> : " + type); 440 } 441 442 } 444 | Popular Tags |