1 23 24 package com.sun.enterprise.deployment; 25 26 import java.util.logging.*; 27 import com.sun.logging.*; 28 29 import java.util.Map ; 30 import java.util.HashMap ; 31 import java.util.HashSet ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 import java.util.LinkedList ; 35 import java.util.Set ; 36 37 import com.sun.enterprise.util.LocalStringManagerImpl; 38 import com.sun.enterprise.deployment.types.EjbReference; 39 import com.sun.enterprise.deployment.types.EjbReferenceContainer; 40 import com.sun.enterprise.deployment.types.MessageDestinationReferenceContainer; 41 import com.sun.enterprise.deployment.types.ResourceReferenceContainer; 42 import com.sun.enterprise.deployment.util.LogDomains; 43 import static com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType; 44 45 48 49 public abstract class JndiEnvironmentRefsGroupDescriptor extends Descriptor 50 implements EjbReferenceContainer, ResourceReferenceContainer, 51 MessageDestinationReferenceContainer, WritableJndiNameEnvironment 52 { 53 private static LocalStringManagerImpl localStrings = 54 new LocalStringManagerImpl(JndiEnvironmentRefsGroupDescriptor.class); 55 56 private static final Logger _logger = LogDomains.getLogger(LogDomains.DPL_LOGGER); 57 58 protected Map <CallbackType, 59 Set <LifecycleCallbackDescriptor>> callbackDescriptors 60 = new HashMap <CallbackType, Set <LifecycleCallbackDescriptor>>(); 61 62 protected EjbBundleDescriptor bundleDescriptor; 63 64 protected Set environmentProperties; 65 protected Set ejbReferences; 66 protected Set jmsDestReferences; 67 protected Set messageDestReferences; 68 protected Set resourceReferences; 69 protected Set serviceReferences; 70 protected Set <EntityManagerFactoryReferenceDescriptor> 71 entityManagerFactoryReferences; 72 protected Set <EntityManagerReferenceDescriptor> 73 entityManagerReferences; 74 75 public void addCallbackDescriptor(CallbackType type, 77 LifecycleCallbackDescriptor llcDesc) { 78 Set <LifecycleCallbackDescriptor> llcDescs = 79 getCallbackDescriptors(type); 80 boolean found = false; 81 for (LifecycleCallbackDescriptor llcD : llcDescs) { 82 if ((llcDesc.getLifecycleCallbackClass() != null) && 83 llcDesc.getLifecycleCallbackClass().equals( 84 llcD.getLifecycleCallbackClass())) { 85 found = true; 86 } 87 } 88 89 if (!found) { 90 llcDescs.add(llcDesc); 91 } 92 } 93 94 public void addCallbackDescriptors(CallbackType type, 95 Set <LifecycleCallbackDescriptor> lccSet) { 96 for (LifecycleCallbackDescriptor lcc : lccSet) { 97 addCallbackDescriptor(type, lcc); 98 } 99 } 100 101 public Set <LifecycleCallbackDescriptor> getCallbackDescriptors( 102 CallbackType type) 103 { 104 Set <LifecycleCallbackDescriptor> lccDescs = 105 callbackDescriptors.get(type); 106 if (lccDescs == null) { 107 lccDescs = new HashSet <LifecycleCallbackDescriptor>(); 108 callbackDescriptors.put(type, lccDescs); 109 } 110 return lccDescs; 111 } 112 113 public boolean hasCallbackDescriptor(CallbackType type) { 114 return (getCallbackDescriptors(type).size() > 0); 115 } 116 117 public void addPostConstructDescriptor(LifecycleCallbackDescriptor lcDesc) { 118 addCallbackDescriptor(CallbackType.POST_CONSTRUCT, lcDesc); 119 } 120 121 public LifecycleCallbackDescriptor getPostConstructDescriptorByClass(String className) { 122 throw new UnsupportedOperationException (); 123 } 124 125 public Set <LifecycleCallbackDescriptor> getPostConstructDescriptors() { 126 return getCallbackDescriptors(CallbackType.POST_CONSTRUCT); 127 } 128 129 public void addPreDestroyDescriptor(LifecycleCallbackDescriptor lcDesc) { 130 addCallbackDescriptor(CallbackType.PRE_DESTROY, lcDesc); 131 } 132 133 public LifecycleCallbackDescriptor getPreDestroyDescriptorByClass(String className) { 134 throw new UnsupportedOperationException (); 135 } 136 137 public Set <LifecycleCallbackDescriptor> getPreDestroyDescriptors() { 138 return getCallbackDescriptors(CallbackType.PRE_DESTROY); 139 } 140 141 142 public EjbBundleDescriptor getEjbBundleDescriptor() { 143 return this.bundleDescriptor; 144 } 145 146 public void setEjbBundleDescriptor(EjbBundleDescriptor bundleDescriptor) { 147 this.bundleDescriptor = bundleDescriptor; 148 } 149 150 public void addEjbReferenceDescriptor(EjbReference ejbReference) { 152 this.getEjbReferenceDescriptors().add(ejbReference); 153 ejbReference.setReferringBundleDescriptor(getEjbBundleDescriptor()); 154 } 155 156 public EjbReference getEjbReference(String name) { 157 for (Iterator itr = this.getEjbReferenceDescriptors().iterator(); itr.hasNext();) { 158 EjbReference er = (EjbReference) itr.next(); 159 if (er.getName().equals(name)) { 160 return er; 161 } 162 } 163 throw new IllegalArgumentException (localStrings.getLocalString( 164 "enterprise.deployment.exceptionhasnoejbrefbyname", 165 "This class has no ejb reference by the name of {0}", 166 new Object [] {name})); 167 } 168 169 public Set getEjbReferenceDescriptors() { 170 if (this.ejbReferences == null) { 171 this.ejbReferences = new OrderedSet(); 172 } 173 return this.ejbReferences = new OrderedSet(this.ejbReferences); 174 } 175 176 public void removeEjbReferenceDescriptor(EjbReference ejbReference) { 177 this.getEjbReferenceDescriptors().remove(ejbReference); 178 ejbReference.setReferringBundleDescriptor(null); 179 } 180 181 public void addMessageDestinationReferenceDescriptor(MessageDestinationReferenceDescriptor msgDestReference) { 183 if( getEjbBundleDescriptor() != null ) { 184 msgDestReference.setReferringBundleDescriptor 185 (getEjbBundleDescriptor()); 186 } 187 this.getMessageDestinationReferenceDescriptors().add(msgDestReference); 188 } 189 190 public MessageDestinationReferenceDescriptor getMessageDestinationReferenceByName(String name) { 191 for (Iterator itr = 192 this.getMessageDestinationReferenceDescriptors().iterator(); 193 itr.hasNext();) { 194 MessageDestinationReferenceDescriptor mdr = 195 (MessageDestinationReferenceDescriptor) itr.next(); 196 if (mdr.getName().equals(name)) { 197 return mdr; 198 } 199 } 200 throw new IllegalArgumentException (localStrings.getLocalString( 201 "enterprise.deployment.exceptionhasnomsgdestrefbyname", 202 "This class has no message destination reference by the name of {0}", 203 new Object [] {name})); 204 } 205 206 public Set getMessageDestinationReferenceDescriptors() { 207 if( this.messageDestReferences == null ) { 208 this.messageDestReferences = new OrderedSet(); 209 } 210 return this.messageDestReferences = 211 new OrderedSet(this.messageDestReferences); 212 } 213 214 public void removeMessageDestinationReferenceDescriptor 215 (MessageDestinationReferenceDescriptor msgDestRef) { 216 this.getMessageDestinationReferenceDescriptors().remove(msgDestRef); 217 } 218 219 public void addEnvironmentProperty(EnvironmentProperty environmentProperty) { 221 this.getEnvironmentProperties().add(environmentProperty); 222 } 223 224 public Set getEnvironmentProperties() { 225 if (this.environmentProperties == null) { 226 this.environmentProperties = new OrderedSet(); 227 } 228 return this.environmentProperties = new OrderedSet(this.environmentProperties); 229 } 230 231 public EnvironmentProperty getEnvironmentPropertyByName(String name) { 232 for (Iterator itr = this.getEnvironmentProperties().iterator(); itr.hasNext();) { 233 EnvironmentProperty ev = (EnvironmentProperty) itr.next(); 234 if (ev.getName().equals(name)) { 235 return ev; 236 } 237 } 238 throw new IllegalArgumentException (localStrings.getLocalString( 239 "enterprise.deployment.exceptionhasnoenvpropertybyname", 240 "This class has no environment property by the name of {0}", 241 new Object [] {name})); 242 } 243 244 public void removeEnvironmentProperty( 245 EnvironmentProperty environmentProperty) { 246 this.getEnvironmentProperties().remove(environmentProperty); 247 } 248 249 public void addServiceReferenceDescriptor( 251 ServiceReferenceDescriptor serviceReference) { 252 serviceReference.setBundleDescriptor(getEjbBundleDescriptor()); 253 this.getServiceReferenceDescriptors().add(serviceReference); 254 } 255 256 public Set getServiceReferenceDescriptors() { 257 if( this.serviceReferences == null ) { 258 this.serviceReferences = new OrderedSet(); 259 } 260 return this.serviceReferences = new OrderedSet(this.serviceReferences); 261 } 262 263 public ServiceReferenceDescriptor getServiceReferenceByName(String name) { 264 for (Iterator itr = this.getServiceReferenceDescriptors().iterator(); 265 itr.hasNext();) { 266 ServiceReferenceDescriptor srd = (ServiceReferenceDescriptor) 267 itr.next(); 268 if (srd.getName().equals(name)) { 269 return srd; 270 } 271 } 272 throw new IllegalArgumentException (localStrings.getLocalString( 273 "enterprise.deployment.exceptionhasnoservicerefbyname", 274 "This class has no service reference by the name of {0}", 275 new Object [] {name})); 276 } 277 278 public void removeServiceReferenceDescriptor( 279 ServiceReferenceDescriptor serviceReference) { 280 this.getServiceReferenceDescriptors().remove(serviceReference); 281 } 282 283 public void addResourceReferenceDescriptor( 285 ResourceReferenceDescriptor resourceReference) { 286 this.getResourceReferenceDescriptors().add(resourceReference); 287 } 288 289 public Set getResourceReferenceDescriptors() { 290 if (this.resourceReferences == null) { 291 this.resourceReferences = new OrderedSet(); 292 } 293 return this.resourceReferences = new OrderedSet(this.resourceReferences); 294 } 295 296 public ResourceReferenceDescriptor getResourceReferenceByName(String name) { 297 for (Iterator itr = this.getResourceReferenceDescriptors().iterator(); itr.hasNext();) { 298 ResourceReferenceDescriptor next = (ResourceReferenceDescriptor) itr.next(); 299 if (next.getName().equals(name)) { 300 return next; 301 } 302 } 303 throw new IllegalArgumentException (localStrings.getLocalString( 304 "enterprise.deployment.exceptionhasnoresourcerefbyname", 305 "This class has no resource reference by the name of {0}", 306 new Object [] {name})); 307 } 308 309 public void removeResourceReferenceDescriptor( 310 ResourceReferenceDescriptor resourceReference) { 311 this.getResourceReferenceDescriptors().remove(resourceReference); 312 } 313 314 public void addJmsDestinationReferenceDescriptor( 316 JmsDestinationReferenceDescriptor jmsDestinationReference) { 317 this.getJmsDestinationReferenceDescriptors().add(jmsDestinationReference); 318 } 319 320 public Set getJmsDestinationReferenceDescriptors() { 321 if (this.jmsDestReferences == null) { 322 this.jmsDestReferences = new OrderedSet(); 323 } 324 return this.jmsDestReferences = new OrderedSet(this.jmsDestReferences); 325 } 326 327 public JmsDestinationReferenceDescriptor getJmsDestinationReferenceByName(String name) { 328 for (Iterator itr = this.getJmsDestinationReferenceDescriptors().iterator(); itr.hasNext();) { 329 JmsDestinationReferenceDescriptor jdr = (JmsDestinationReferenceDescriptor) itr.next(); 330 if (jdr.getName().equals(name)) { 331 return jdr; 332 } 333 } 334 throw new IllegalArgumentException (localStrings.getLocalString( 335 "enterprise.deployment.exceptionhasnojmsdestrefbyname", 336 "This class has no JMS destination reference by the name of {0}", 337 new Object [] {name})); 338 } 339 340 public void removeJmsDestinationReferenceDescriptor( 341 JmsDestinationReferenceDescriptor jmsDestinationReference) { 342 this.getJmsDestinationReferenceDescriptors().remove(jmsDestinationReference); 343 } 344 345 public void addEntityManagerFactoryReferenceDescriptor( 347 EntityManagerFactoryReferenceDescriptor reference) { 348 if( getEjbBundleDescriptor() != null ) { 349 reference.setReferringBundleDescriptor 350 (getEjbBundleDescriptor()); 351 } 352 this.getEntityManagerFactoryReferenceDescriptors().add(reference); 353 } 354 355 public Set <EntityManagerFactoryReferenceDescriptor> getEntityManagerFactoryReferenceDescriptors() { 356 if( this.entityManagerFactoryReferences == null ) { 357 this.entityManagerFactoryReferences = 358 new HashSet <EntityManagerFactoryReferenceDescriptor>(); 359 } 360 return this.entityManagerFactoryReferences = 361 new HashSet <EntityManagerFactoryReferenceDescriptor> 362 (entityManagerFactoryReferences); 363 } 364 365 public EntityManagerFactoryReferenceDescriptor getEntityManagerFactoryReferenceByName(String name) { 366 for (EntityManagerFactoryReferenceDescriptor next : 367 getEntityManagerFactoryReferenceDescriptors()) { 368 369 if (next.getName().equals(name)) { 370 return next; 371 } 372 } 373 throw new IllegalArgumentException (localStrings.getLocalString( 374 "enterprise.deployment.exceptionhasnoentitymgrfactoryrefbyname", 375 "This class has no entity manager factory reference by the name of {0}", 376 new Object [] {name})); 377 } 378 379 public void addEntityManagerReferenceDescriptor( 381 EntityManagerReferenceDescriptor reference) { 382 if( getEjbBundleDescriptor() != null ) { 383 reference.setReferringBundleDescriptor 384 (getEjbBundleDescriptor()); 385 } 386 this.getEntityManagerReferenceDescriptors().add(reference); 387 } 388 389 public Set <EntityManagerReferenceDescriptor> getEntityManagerReferenceDescriptors() { 390 if( this.entityManagerReferences == null ) { 391 this.entityManagerReferences = 392 new HashSet <EntityManagerReferenceDescriptor>(); 393 } 394 return this.entityManagerReferences = 395 new HashSet <EntityManagerReferenceDescriptor> 396 (this.entityManagerReferences); 397 } 398 399 public EntityManagerReferenceDescriptor getEntityManagerReferenceByName(String name) { 400 for (EntityManagerReferenceDescriptor next : 401 getEntityManagerReferenceDescriptors()) { 402 403 if (next.getName().equals(name)) { 404 return next; 405 } 406 } 407 throw new IllegalArgumentException (localStrings.getLocalString( 408 "enterprise.deployment.exceptionhasnoentitymgrrefbyname", 409 "This class has no entity manager reference by the name of {0}", 410 new Object [] {name})); 411 } 412 413 public List <InjectionCapable> getInjectableResourcesByClass(String className) { 414 throw new UnsupportedOperationException (); 415 } 416 417 public InjectionInfo getInjectionInfoByClass(String className) { 418 throw new UnsupportedOperationException (); 419 } 420 } 421 | Popular Tags |