1 17 18 19 package org.apache.catalina.deploy; 20 21 22 import java.beans.PropertyChangeListener ; 23 import java.beans.PropertyChangeSupport ; 24 import java.util.HashMap ; 25 import java.util.Hashtable ; 26 import java.io.Serializable ; 27 28 29 36 37 public class NamingResources implements Serializable { 38 39 40 42 43 46 public NamingResources() { 47 } 48 49 50 52 53 56 private Object container = null; 57 58 59 63 private Hashtable entries = new Hashtable (); 64 65 66 69 private HashMap ejbs = new HashMap (); 70 71 72 75 private HashMap envs = new HashMap (); 76 77 78 82 private HashMap localEjbs = new HashMap (); 83 84 85 89 private HashMap mdrs = new HashMap (); 90 91 92 96 private HashMap resourceEnvRefs = new HashMap (); 97 98 99 102 private HashMap resources = new HashMap (); 103 104 105 108 private HashMap resourceLinks = new HashMap (); 109 110 111 114 private HashMap services = new HashMap (); 115 116 117 120 private ContextTransaction transaction = null; 121 122 123 126 protected PropertyChangeSupport support = new PropertyChangeSupport (this); 127 128 129 131 132 135 public Object getContainer() { 136 return container; 137 } 138 139 140 143 public void setContainer(Object container) { 144 this.container = container; 145 } 146 147 148 151 public void setTransaction(ContextTransaction transaction) { 152 this.transaction = transaction; 153 } 154 155 156 159 public ContextTransaction getTransaction() { 160 return transaction; 161 } 162 163 164 169 public void addEjb(ContextEjb ejb) { 170 171 if (entries.containsKey(ejb.getName())) { 172 return; 173 } else { 174 entries.put(ejb.getName(), ejb.getType()); 175 } 176 177 synchronized (ejbs) { 178 ejb.setNamingResources(this); 179 ejbs.put(ejb.getName(), ejb); 180 } 181 support.firePropertyChange("ejb", null, ejb); 182 183 } 184 185 186 191 public void addEnvironment(ContextEnvironment environment) { 192 193 if (entries.containsKey(environment.getName())) { 194 if (findEnvironment(environment.getName()).getOverride()) { 195 removeEnvironment(environment.getName()); 196 } else { 197 return; 198 } 199 } 200 201 entries.put(environment.getName(), environment.getType()); 202 203 synchronized (envs) { 204 environment.setNamingResources(this); 205 envs.put(environment.getName(), environment); 206 } 207 support.firePropertyChange("environment", null, environment); 208 209 } 210 211 212 217 public void addLocalEjb(ContextLocalEjb ejb) { 218 219 if (entries.containsKey(ejb.getName())) { 220 return; 221 } else { 222 entries.put(ejb.getName(), ejb.getType()); 223 } 224 225 synchronized (localEjbs) { 226 ejb.setNamingResources(this); 227 localEjbs.put(ejb.getName(), ejb); 228 } 229 support.firePropertyChange("localEjb", null, ejb); 230 231 } 232 233 234 239 public void addMessageDestinationRef(MessageDestinationRef mdr) { 240 241 if (entries.containsKey(mdr.getName())) { 242 return; 243 } else { 244 entries.put(mdr.getName(), mdr.getType()); 245 } 246 247 synchronized (mdrs) { 248 mdr.setNamingResources(this); 249 mdrs.put(mdr.getName(), mdr); 250 } 251 support.firePropertyChange("messageDestinationRef", null, mdr); 252 253 } 254 255 256 261 public void addPropertyChangeListener(PropertyChangeListener listener) { 262 263 support.addPropertyChangeListener(listener); 264 265 } 266 267 268 273 public void addResource(ContextResource resource) { 274 275 if (entries.containsKey(resource.getName())) { 276 return; 277 } else { 278 entries.put(resource.getName(), resource.getType()); 279 } 280 281 synchronized (resources) { 282 resource.setNamingResources(this); 283 resources.put(resource.getName(), resource); 284 } 285 support.firePropertyChange("resource", null, resource); 286 287 } 288 289 290 295 public void addResourceEnvRef(ContextResourceEnvRef resource) { 296 297 if (entries.containsKey(resource.getName())) { 298 return; 299 } else { 300 entries.put(resource.getName(), resource.getType()); 301 } 302 303 synchronized (localEjbs) { 304 resource.setNamingResources(this); 305 resourceEnvRefs.put(resource.getName(), resource); 306 } 307 support.firePropertyChange("resourceEnvRef", null, resource); 308 309 } 310 311 312 317 public void addResourceLink(ContextResourceLink resourceLink) { 318 319 if (entries.containsKey(resourceLink.getName())) { 320 return; 321 } else { 322 Object value = resourceLink.getType(); 323 if (value == null) { 324 value = ""; 325 } 326 entries.put(resourceLink.getName(), value); 327 } 328 329 synchronized (resourceLinks) { 330 resourceLink.setNamingResources(this); 331 resourceLinks.put(resourceLink.getName(), resourceLink); 332 } 333 support.firePropertyChange("resourceLink", null, resourceLink); 334 335 } 336 337 338 343 public void addService(ContextService service) { 344 345 if (entries.containsKey(service.getName())) { 346 return; 347 } else { 348 entries.put(service.getName(), service.getServiceinterface()); 349 } 350 351 synchronized (services) { 352 service.setNamingResources(this); 353 services.put(service.getName(), service); 354 } 355 support.firePropertyChange("service", null, service); 356 357 } 358 359 360 366 public ContextEjb findEjb(String name) { 367 368 synchronized (ejbs) { 369 return ((ContextEjb) ejbs.get(name)); 370 } 371 372 } 373 374 375 379 public ContextEjb[] findEjbs() { 380 381 synchronized (ejbs) { 382 ContextEjb results[] = new ContextEjb[ejbs.size()]; 383 return ((ContextEjb[]) ejbs.values().toArray(results)); 384 } 385 386 } 387 388 389 395 public ContextEnvironment findEnvironment(String name) { 396 397 synchronized (envs) { 398 return ((ContextEnvironment) envs.get(name)); 399 } 400 401 } 402 403 404 409 public ContextEnvironment[] findEnvironments() { 410 411 synchronized (envs) { 412 ContextEnvironment results[] = new ContextEnvironment[envs.size()]; 413 return ((ContextEnvironment[]) envs.values().toArray(results)); 414 } 415 416 } 417 418 419 425 public ContextLocalEjb findLocalEjb(String name) { 426 427 synchronized (localEjbs) { 428 return ((ContextLocalEjb) localEjbs.get(name)); 429 } 430 431 } 432 433 434 438 public ContextLocalEjb[] findLocalEjbs() { 439 440 synchronized (localEjbs) { 441 ContextLocalEjb results[] = new ContextLocalEjb[localEjbs.size()]; 442 return ((ContextLocalEjb[]) localEjbs.values().toArray(results)); 443 } 444 445 } 446 447 448 454 public MessageDestinationRef findMessageDestinationRef(String name) { 455 456 synchronized (mdrs) { 457 return ((MessageDestinationRef) mdrs.get(name)); 458 } 459 460 } 461 462 463 467 public MessageDestinationRef[] findMessageDestinationRefs() { 468 469 synchronized (mdrs) { 470 MessageDestinationRef results[] = 471 new MessageDestinationRef[mdrs.size()]; 472 return ((MessageDestinationRef[]) mdrs.values().toArray(results)); 473 } 474 475 } 476 477 478 484 public ContextResource findResource(String name) { 485 486 synchronized (resources) { 487 return ((ContextResource) resources.get(name)); 488 } 489 490 } 491 492 493 499 public ContextResourceLink findResourceLink(String name) { 500 501 synchronized (resourceLinks) { 502 return ((ContextResourceLink) resourceLinks.get(name)); 503 } 504 505 } 506 507 508 512 public ContextResourceLink[] findResourceLinks() { 513 514 synchronized (resourceLinks) { 515 ContextResourceLink results[] = 516 new ContextResourceLink[resourceLinks.size()]; 517 return ((ContextResourceLink[]) resourceLinks.values() 518 .toArray(results)); 519 } 520 521 } 522 523 524 528 public ContextResource[] findResources() { 529 530 synchronized (resources) { 531 ContextResource results[] = new ContextResource[resources.size()]; 532 return ((ContextResource[]) resources.values().toArray(results)); 533 } 534 535 } 536 537 538 544 public ContextResourceEnvRef findResourceEnvRef(String name) { 545 546 synchronized (resourceEnvRefs) { 547 return ((ContextResourceEnvRef) resourceEnvRefs.get(name)); 548 } 549 550 } 551 552 553 558 public ContextResourceEnvRef[] findResourceEnvRefs() { 559 560 synchronized (resourceEnvRefs) { 561 ContextResourceEnvRef results[] = new ContextResourceEnvRef[resourceEnvRefs.size()]; 562 return ((ContextResourceEnvRef[]) resourceEnvRefs.values().toArray(results)); 563 } 564 565 } 566 567 568 574 public ContextService findService(String name) { 575 576 synchronized (services) { 577 return ((ContextService) services.get(name)); 578 } 579 580 } 581 582 583 587 public ContextService[] findServices() { 588 589 synchronized (services) { 590 ContextService results[] = new ContextService[services.size()]; 591 return ((ContextService[]) services.values().toArray(results)); 592 } 593 594 } 595 596 597 600 public boolean exists(String name) { 601 602 return (entries.containsKey(name)); 603 604 } 605 606 607 612 public void removeEjb(String name) { 613 614 entries.remove(name); 615 616 ContextEjb ejb = null; 617 synchronized (ejbs) { 618 ejb = (ContextEjb) ejbs.remove(name); 619 } 620 if (ejb != null) { 621 support.firePropertyChange("ejb", ejb, null); 622 ejb.setNamingResources(null); 623 } 624 625 } 626 627 628 633 public void removeEnvironment(String name) { 634 635 entries.remove(name); 636 637 ContextEnvironment environment = null; 638 synchronized (envs) { 639 environment = (ContextEnvironment) envs.remove(name); 640 } 641 if (environment != null) { 642 support.firePropertyChange("environment", environment, null); 643 environment.setNamingResources(null); 644 } 645 646 } 647 648 649 654 public void removeLocalEjb(String name) { 655 656 entries.remove(name); 657 658 ContextLocalEjb localEjb = null; 659 synchronized (localEjbs) { 660 localEjb = (ContextLocalEjb) ejbs.remove(name); 661 } 662 if (localEjb != null) { 663 support.firePropertyChange("localEjb", localEjb, null); 664 localEjb.setNamingResources(null); 665 } 666 667 } 668 669 670 675 public void removeMessageDestinationRef(String name) { 676 677 entries.remove(name); 678 679 MessageDestinationRef mdr = null; 680 synchronized (mdrs) { 681 mdr = (MessageDestinationRef) mdrs.remove(name); 682 } 683 if (mdr != null) { 684 support.firePropertyChange("messageDestinationRef", 685 mdr, null); 686 mdr.setNamingResources(null); 687 } 688 689 } 690 691 692 697 public void removePropertyChangeListener(PropertyChangeListener listener) { 698 699 support.removePropertyChangeListener(listener); 700 701 } 702 703 704 709 public void removeResource(String name) { 710 711 entries.remove(name); 712 713 ContextResource resource = null; 714 synchronized (resources) { 715 resource = (ContextResource) resources.remove(name); 716 } 717 if (resource != null) { 718 support.firePropertyChange("resource", resource, null); 719 resource.setNamingResources(null); 720 } 721 722 } 723 724 725 730 public void removeResourceEnvRef(String name) { 731 732 entries.remove(name); 733 734 String type = null; 735 synchronized (resourceEnvRefs) { 736 type = (String ) resourceEnvRefs.remove(name); 737 } 738 if (type != null) { 739 support.firePropertyChange("resourceEnvRef", 740 name + ":" + type, null); 741 } 742 743 } 744 745 746 751 public void removeResourceLink(String name) { 752 753 entries.remove(name); 754 755 ContextResourceLink resourceLink = null; 756 synchronized (resourceLinks) { 757 resourceLink = (ContextResourceLink) resourceLinks.remove(name); 758 } 759 if (resourceLink != null) { 760 support.firePropertyChange("resourceLink", resourceLink, null); 761 resourceLink.setNamingResources(null); 762 } 763 764 } 765 766 767 772 public void removeService(String name) { 773 774 entries.remove(name); 775 776 ContextService service = null; 777 synchronized (services) { 778 service = (ContextService) services.remove(name); 779 } 780 if (service != null) { 781 support.firePropertyChange("service", service, null); 782 service.setNamingResources(null); 783 } 784 785 } 786 787 788 } 789 | Popular Tags |