1 23 24 package com.sun.enterprise.deployment.util; 25 26 import java.util.Iterator ; 27 import java.lang.reflect.Method ; 28 import java.lang.reflect.Field ; 29 30 import com.sun.enterprise.deployment.Descriptor; 31 import com.sun.enterprise.deployment.Application; 32 import com.sun.enterprise.deployment.BundleDescriptor; 33 import com.sun.enterprise.deployment.EjbBundleDescriptor; 34 import com.sun.enterprise.deployment.EjbDescriptor; 35 import com.sun.enterprise.deployment.MethodPermission; 36 import com.sun.enterprise.deployment.MethodDescriptor; 37 import com.sun.enterprise.deployment.WebService; 38 import com.sun.enterprise.deployment.ContainerTransaction; 39 import com.sun.enterprise.deployment.types.EjbReference; 40 import com.sun.enterprise.deployment.types.MessageDestinationReferencer; 41 import com.sun.enterprise.deployment.ServiceReferenceDescriptor; 42 import com.sun.enterprise.deployment.JmsDestinationReferenceDescriptor; 43 import com.sun.enterprise.deployment.MessageDestinationDescriptor; 44 import com.sun.enterprise.deployment.MessageDestinationReferenceDescriptor; 45 import com.sun.enterprise.deployment.ResourceReferenceDescriptor; 46 import com.sun.enterprise.deployment.RoleReference; 47 import com.sun.enterprise.deployment.EnvironmentProperty; 48 import com.sun.enterprise.deployment.FieldDescriptor; 49 import com.sun.enterprise.deployment.QueryDescriptor; 50 import com.sun.enterprise.deployment.RelationshipDescriptor; 51 import com.sun.enterprise.deployment.ConnectorDescriptor; 52 import com.sun.enterprise.deployment.WebBundleDescriptor; 53 import com.sun.enterprise.deployment.ApplicationClientDescriptor; 54 import com.sun.enterprise.deployment.WebComponentDescriptor; 55 import com.sun.enterprise.deployment.InjectionCapable; 56 import com.sun.enterprise.deployment.InjectionTarget; 57 import com.sun.enterprise.util.TypeUtil; 58 59 65 66 public class DefaultDOLVisitor implements ApplicationVisitor, EjbBundleVisitor, EjbVisitor, ConnectorVisitor, WebBundleVisitor, AppClientVisitor { 67 protected BundleDescriptor bundleDescriptor = null; 68 69 70 public DefaultDOLVisitor() { 71 } 72 73 77 public void accept(Application application) { 78 } 79 80 84 public void accept(EjbBundleDescriptor bundleDescriptor) { 85 this.bundleDescriptor = bundleDescriptor; 86 } 87 88 92 public void accept(EjbDescriptor ejb) { 93 } 94 95 99 public void accept(ConnectorDescriptor conDesc) { 100 } 101 102 public void accept(InjectionCapable injectable) { 103 } 104 105 109 public void accept(EjbReference ejbRef) { 110 } 111 112 public void accept(MessageDestinationReferencer msgDestReferencer) { 113 } 114 115 119 public void accept(ServiceReferenceDescriptor serviceRef) { 120 } 121 122 126 public void accept(WebService webService) { 127 } 128 129 134 public void accept(MethodPermission pm, Iterator methods) { 135 } 136 137 141 public void accept(RoleReference roleRef) { 142 } 143 144 149 public void accept(MethodDescriptor method, ContainerTransaction ct) { 150 } 151 152 156 public void accept(EnvironmentProperty envEntry) { 157 } 158 159 163 public void accept(ResourceReferenceDescriptor resRef) { 164 } 165 166 170 public void accept(JmsDestinationReferenceDescriptor jmsDestRef) { 171 } 172 173 177 public void accept(MessageDestinationReferenceDescriptor msgDestRef) { 178 } 179 180 184 public void accept(MessageDestinationDescriptor msgDest) { 185 } 186 187 191 public void accept(ApplicationClientDescriptor appclientdescriptor) { 192 bundleDescriptor = appclientdescriptor; 193 } 194 195 199 public EjbBundleVisitor getEjbBundleVisitor() { 200 return this; 201 } 202 203 206 public EjbVisitor getEjbVisitor() { 207 return this; 208 } 209 210 213 public ConnectorVisitor getConnectorVisitor() { 214 return this; 215 } 216 217 220 public AppClientVisitor getAppClientVisitor() { 221 return this; 222 } 223 224 228 public void accept(FieldDescriptor fd) { 229 } 230 231 236 public void accept(MethodDescriptor method, QueryDescriptor qd) { 237 } 238 239 243 public void accept(RelationshipDescriptor descriptor) { 244 } 245 246 250 public void accept(Descriptor descriptor) { 251 } 252 253 257 public WebBundleVisitor getWebBundleVisitor() { 258 return this; 259 } 260 261 266 public void accept(WebBundleDescriptor descriptor) { 267 this.bundleDescriptor = descriptor; 268 } 269 270 275 public void accept(WebComponentDescriptor descriptor) { 276 } 277 278 279 284 protected void acceptWithCL(InjectionCapable injectable) { 285 for (InjectionTarget target : injectable.getInjectionTargets()) { 289 if( (target.getFieldName() == null) && 290 (target.getMethodName() == null) ) { 291 292 String injectTargetName = target.getTargetName(); 293 String targetClassName = target.getClassName(); 294 ClassLoader classLoader = getBundleDescriptor().getClassLoader(); 295 296 Class targetClazz = null; 297 298 try { 299 300 targetClazz = classLoader.loadClass(targetClassName); 301 302 } catch(ClassNotFoundException cnfe) { 303 DOLUtils.getDefaultLogger().fine 311 ("Injection class " + targetClassName + " not found for " + 312 injectable); 313 return; 314 } 315 316 boolean matched = false; 318 319 324 String setterMethodName = TypeUtil. 325 propertyNameToSetterMethod(injectTargetName); 326 327 for(Method next : targetClazz.getDeclaredMethods()) { 329 if( next.getName().equals(setterMethodName)) { 330 331 target.setMethodName(next.getName()); 332 if( injectable.getInjectResourceType() == null ) { 333 Class [] paramTypes = next.getParameterTypes(); 334 if (paramTypes.length == 1) { 335 String resourceType = paramTypes[0].getName(); 336 injectable.setInjectResourceType(resourceType); 337 } 338 } 339 matched = true; 340 break; 341 } 342 } 343 344 if( !matched ) { 345 346 try { 349 Field f = targetClazz.getDeclaredField(injectTargetName); 350 target.setFieldName(injectTargetName); 351 if( injectable.getInjectResourceType() == null ) { 352 String resourceType = f.getType().getName(); 353 injectable.setInjectResourceType(resourceType); 354 } 355 matched = true; 356 } catch(NoSuchFieldException nsfe) { 357 String msg = "No matching injection setter method or " + 358 "injection field found for injection property " + 359 injectTargetName + " on class " + targetClassName + 360 " for component dependency " + injectable; 361 362 throw new RuntimeException (msg, nsfe); 363 } 364 } 365 } 366 } 367 } 368 369 protected void acceptWithoutCL(InjectionCapable injectable) { 370 if("javax.transaction.UserTransaction".equals(injectable.getInjectResourceType())) { 372 if (injectable instanceof ResourceReferenceDescriptor) { 375 ResourceReferenceDescriptor resRef = 376 (ResourceReferenceDescriptor) injectable; 377 resRef.setJndiName("java:comp/UserTransaction"); 378 } 379 } else if("org.omg.CORBA.ORB".equals(injectable.getInjectResourceType())) { 380 if (injectable instanceof ResourceReferenceDescriptor) { 383 ResourceReferenceDescriptor resRef = 384 (ResourceReferenceDescriptor) injectable; 385 resRef.setJndiName("java:comp/ORB"); 386 } 387 } 388 } 389 390 393 protected BundleDescriptor getBundleDescriptor() { 394 return bundleDescriptor; 395 } 396 } 397 | Popular Tags |