1 25 26 package org.objectweb.petals.jbi.registry; 27 28 import java.util.ArrayList ; 29 import java.util.List ; 30 31 import javax.jbi.JBIException; 32 import javax.jbi.servicedesc.ServiceEndpoint; 33 import javax.naming.Binding ; 34 import javax.naming.Context ; 35 import javax.naming.InitialContext ; 36 import javax.naming.LinkRef ; 37 import javax.naming.Name ; 38 import javax.naming.NameClassPair ; 39 import javax.naming.NamingEnumeration ; 40 import javax.naming.NamingException ; 41 import javax.naming.NotContextException ; 42 import javax.xml.namespace.QName ; 43 44 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 45 import org.objectweb.fractal.fraclet.annotation.FractalComponent; 46 import org.objectweb.fractal.fraclet.annotation.Interface; 47 import org.objectweb.fractal.fraclet.annotation.LifeCycle; 48 import org.objectweb.fractal.fraclet.annotation.LifeCycleType; 49 import org.objectweb.fractal.fraclet.annotation.Monolog; 50 import org.objectweb.fractal.fraclet.annotation.Provides; 51 import org.objectweb.petals.util.JNDIUtil; 52 import org.objectweb.petals.util.LoggingUtil; 53 import org.objectweb.petals.util.NamingHelper; 54 import org.objectweb.petals.util.PropertyUtil; 55 import org.objectweb.petals.util.StringHelper; 56 import org.objectweb.util.monolog.api.Logger; 57 58 66 @FractalComponent 67 @Provides(interfaces=@Interface(name="service",signature=org.objectweb.petals.jbi.registry.Registry.class)) 68 public class JNDIRegistry implements Registry { 69 70 73 public static final String ENDPOINTS_REF = "endpoints"; 74 75 78 public static final String INTERFACES_REF = "interfaces"; 79 80 83 public static final String NEW_ENDPOINTS_REF = "new-endpoints"; 84 85 88 public static final String SERVICES_REF = "services"; 89 90 93 public static final String USERS_REF = "users"; 94 95 98 protected Context endpointsContext; 99 100 103 protected Context interfacesContext; 104 105 108 protected LoggingUtil log; 109 110 113 @Monolog(name="logger") 114 protected Logger logger; 115 116 119 protected Context newEndpointContext; 120 121 124 protected InitialContext rootContext; 125 126 129 protected Context servicesContext; 130 131 134 protected String state; 135 136 139 protected Context usersContext; 140 141 144 public void cleanNewEndpoints() throws RegistryException { 145 try { 146 NamingEnumeration <NameClassPair > names = rootContext 147 .list(NEW_ENDPOINTS_REF); 148 while (names.hasMore()) { 149 NameClassPair nameClassPair = (NameClassPair ) names.next(); 150 newEndpointContext.unbind(nameClassPair.getName()); 151 } 152 } catch (NamingException e) { 153 log.error("Problem while cleaning new endpoints context", e); 154 throw new RegistryException( 155 "Problem while cleaning new endpoints context", e); 156 } 157 } 158 159 162 public void deregisterConnection(LinkedEndpoint linkedEndpoint) 163 throws RegistryException { 164 log.start(); 165 if (linkedEndpoint == null) { 166 throw new IllegalArgumentException ( 167 "The connection must be non null"); 168 } 169 if (linkedEndpoint.getInterfaces() != null) { 170 Name interf = NamingHelper.qNameToName(linkedEndpoint 171 .getInterfaces()[0]); 172 if (!JNDIUtil.isBound(rootContext, INTERFACES_REF, interf)) { 173 log.error("The connection interface name " 174 + linkedEndpoint.getInterfaces()[0] 175 + " is not registered"); 176 throw new RegistryException("The connection interface name " 177 + linkedEndpoint.getInterfaces()[0] 178 + " is not registered"); 179 } else { 180 181 try { 182 if (JNDIUtil.isBound(rootContext, NEW_ENDPOINTS_REF, 186 linkedEndpoint.getToEndpointName())) { 187 Context interfaceCtx = (Context ) interfacesContext 188 .lookup(interf); 189 190 interfaceCtx.unbind(linkedEndpoint.getToEndpointName()); 191 } else { 192 InternalEndpoint internalEndpoint = (InternalEndpoint) getInternalEndpoint( 195 linkedEndpoint.getToServiceName(), 196 linkedEndpoint.getToEndpointName()); 197 boolean isNotInInt = true; 198 for (QName i : internalEndpoint.getInterfaces()) { 199 if (linkedEndpoint.getInterfaces()[0].equals(i)) { 200 isNotInInt = false; 201 } 202 } 203 if (isNotInInt) { 204 Context interfaceCtx = (Context ) interfacesContext 205 .lookup(interf); 206 interfaceCtx.unbind(linkedEndpoint 207 .getToEndpointName()); 208 if (!interfacesContext.list(interf) 209 .hasMoreElements()) { 210 interfacesContext.destroySubcontext(interf); 211 } 212 } 213 } 214 215 } catch (NamingException e) { 216 log.error(e.getMessage() ,e); 217 throw new RegistryException( 218 "problem while unregistering connection with interfacename " 219 + linkedEndpoint.getInterfaces()[0] 220 + " to " 221 + linkedEndpoint.getToEndpointName() + " "); 222 } 223 } 224 } else { 225 try { 226 if (!JNDIUtil.isBound(rootContext, ENDPOINTS_REF, 227 linkedEndpoint.getEndpointName())) { 228 log.error("The provider endpoint " 229 + linkedEndpoint.getEndpointName() 230 + " is not registered in the endpoints"); 231 throw new RegistryException("The provider endpoint " 232 + linkedEndpoint.getEndpointName() 233 + " is not registered in the endpoints"); 234 } 235 236 if (!linkedEndpoint.getToServiceName().equals( 239 linkedEndpoint.getServiceName())) { 240 retrieveServiceContext( 241 NamingHelper.qNameToName(linkedEndpoint 242 .getServiceName())).unbind( 243 linkedEndpoint.getEndpointName()); 244 Name serviceName = NamingHelper.qNameToName(linkedEndpoint 246 .getServiceName()); 247 if (!servicesContext.list(serviceName).hasMore()) { 248 servicesContext.destroySubcontext(serviceName); 249 } 250 } 251 252 if (!linkedEndpoint.getEndpointName().equals( 255 linkedEndpoint.getToEndpointName())) { 256 endpointsContext.unbind(linkedEndpoint.getEndpointName()); 257 } 258 259 } catch (NamingException e) { 260 log.error(e.getMessage(), e); 261 throw new RegistryException( 262 "problem while registering connection with service name " 263 + linkedEndpoint.getServiceName() 264 + " and endpoint name " 265 + linkedEndpoint.getEndpointName() + " to " 266 + linkedEndpoint.getToEndpointName() + " "); 267 } 268 } 269 log.end(); 270 } 271 272 276 public void deregisterExternalEndpoint(ServiceEndpoint externalEndpoint) 277 throws RegistryException { 278 log.start(); 279 if (externalEndpoint == null) { 280 throw new IllegalArgumentException ( 281 "The external endpoint must be non null"); 282 } 283 deregisterInternalEndpoint((AbstractEndpoint) externalEndpoint); 284 log.end(); 285 } 286 287 301 public void deregisterInternalEndpoint(AbstractEndpoint address) 302 throws RegistryException { 303 log.start(); 304 if (address == null) { 305 throw new IllegalArgumentException ("The endpoint must be non null"); 306 } 307 try { 308 if (!JNDIUtil.isBound(rootContext, ENDPOINTS_REF, address 311 .getEndpointName())) { 312 throw new RegistryException("The endpoint " 313 + address.getEndpointName() 314 + " must be previously registered"); 315 } 316 317 if (address.getInterfaces() != null) { 320 for (QName interfaceName : address.getInterfaces()) { 321 Name name = NamingHelper.qNameToName(interfaceName); 322 if (JNDIUtil.isBound(rootContext, INTERFACES_REF, name)) { 323 Context interfaceCtx = (Context ) interfacesContext 324 .lookup(name); 325 326 interfaceCtx.unbind(address.getEndpointName()); 327 328 if (!interfacesContext.list(name).hasMoreElements()) { 329 interfacesContext.destroySubcontext(name); 330 } 331 } else { 332 log.error("Could not deregister internal endpoint " 333 + address.getEndpointName() + " its interface " 334 + interfaceName + " is not registered"); 335 throw new RegistryException( 336 "Could not deregister internal endpoint " 337 + address.getEndpointName() 338 + " its interface " + interfaceName 339 + " is not registered"); 340 } 341 } 342 } 343 344 if (!StringHelper.isEmpty(NamingHelper.qNameToString(address 347 .getServiceName()))) { 348 Name serviceName = NamingHelper.qNameToName(address 349 .getServiceName()); 350 351 if (JNDIUtil.isBound(rootContext, SERVICES_REF, serviceName)) { 352 Context serviceCtx = (Context ) servicesContext 353 .lookup(serviceName); 354 355 serviceCtx.unbind(address.getEndpointName()); 356 357 if (!servicesContext.list(serviceName).hasMore()) { 361 servicesContext.destroySubcontext(serviceName); 362 } 363 } else { 364 log.error("Could not deregister internal endpoint " 365 + address.getEndpointName() + " its service " 366 + address.getServiceName() + " is not registered"); 367 throw new RegistryException( 368 "Could not deregister internal endpoint " 369 + address.getEndpointName() 370 + " its service " 371 + address.getServiceName() 372 + " is not registered"); 373 } 374 } 375 376 endpointsContext.unbind(address.getEndpointName()); 379 380 if (JNDIUtil.isBound(rootContext, NEW_ENDPOINTS_REF, address 382 .getEndpointName())) { 383 newEndpointContext.unbind(address.getEndpointName()); 384 } 385 386 } catch (Exception e) { 387 log.error(e.getMessage(), e); 388 throw new RegistryException(e); 389 } 390 log.end(); 391 } 392 393 396 public AbstractEndpoint getExternalEndpoint(QName service, String name) 397 throws RegistryException { 398 log.call(); 399 return retrieveEndpoint(service, name, ExternalEndpoint.class.getName()); 400 } 401 402 405 public AbstractEndpoint[] getExternalEndpointsForInterface( 406 QName interfaceName) throws RegistryException { 407 log.call(); 408 return retrieveEndpointsForInterface(interfaceName, 409 ExternalEndpoint.class.getName()); 410 } 411 412 415 public AbstractEndpoint[] getExternalEndpointsForService(QName serviceName) { 416 log.call(); 417 return retrieveEndpointsForService(serviceName, ExternalEndpoint.class 418 .getName()); 419 } 420 421 424 public AbstractEndpoint getInternalEndpoint(QName service, String name) 425 throws RegistryException { 426 log.call(); 427 return retrieveEndpoint(service, name, InternalEndpoint.class.getName()); 428 } 429 430 433 public AbstractEndpoint getInternalEndpoint(QName service, String name, 434 boolean resolveLink) throws RegistryException { 435 log.call(); 436 return retrieveEndpoint(service, name, 437 InternalEndpoint.class.getName(), resolveLink); 438 } 439 440 446 public AbstractEndpoint[] getInternalEndpointsForInterface( 447 QName interfaceName) throws RegistryException { 448 log.call(); 449 return retrieveEndpointsForInterface(interfaceName, 450 InternalEndpoint.class.getName()); 451 } 452 453 456 public AbstractEndpoint[] getInternalEndpointsForService(QName serviceName) { 457 log.call(); 458 return retrieveEndpointsForService(serviceName, InternalEndpoint.class 459 .getName()); 460 } 461 462 465 public Context getUsersContext() { 466 return usersContext; 467 } 468 469 472 public void registerConnection(LinkedEndpoint linkedEndpoint) 473 throws RegistryException { 474 log.start(); 475 if (linkedEndpoint == null) { 476 throw new IllegalArgumentException ( 477 "The connection must be non null"); 478 } 479 if (linkedEndpoint.getInterfaces() != null) { 487 try { 488 LinkRef linkRef = new LinkRef ("/" + ENDPOINTS_REF + "/" 489 + linkedEndpoint.getToEndpointName()); 490 if (!JNDIUtil.isBound(rootContext, INTERFACES_REF, NamingHelper 491 .qNameToName(linkedEndpoint.getInterfaces()[0]))) { 492 retrieveInterfaceContext( 493 NamingHelper.qNameToName(linkedEndpoint 494 .getInterfaces()[0])).bind( 495 linkedEndpoint.getToEndpointName(), linkRef); 496 } else { 497 retrieveInterfaceContext( 498 NamingHelper.qNameToName(linkedEndpoint 499 .getInterfaces()[0])).rebind( 500 linkedEndpoint.getToEndpointName(), linkRef); 501 } 502 } catch (NamingException e) { 503 log.error(e.getMessage(), e); 504 throw new RegistryException( 505 "problem while registering connection with interfacename " 506 + linkedEndpoint.getInterfaces()[0] + " to " 507 + linkedEndpoint.getToEndpointName() + " "); 508 } 509 } else { 510 try { 511 LinkRef linkRef = new LinkRef ("/" + ENDPOINTS_REF + "/" 512 + linkedEndpoint.getToEndpointName()); 513 if (!JNDIUtil.isBound(rootContext, SERVICES_REF, NamingHelper 514 .qNameToName(linkedEndpoint.getServiceName()))) { 515 retrieveServiceContext( 516 NamingHelper.qNameToName(linkedEndpoint 517 .getServiceName())).bind( 518 linkedEndpoint.getEndpointName(), linkRef); 519 } else { 520 retrieveServiceContext( 521 NamingHelper.qNameToName(linkedEndpoint 522 .getServiceName())).rebind( 523 linkedEndpoint.getEndpointName(), linkRef); 524 } 525 if (!JNDIUtil.isBound(rootContext, ENDPOINTS_REF, 526 linkedEndpoint.getEndpointName())) { 527 endpointsContext.bind(linkedEndpoint.getEndpointName(), 528 linkRef); 529 } else { 530 endpointsContext.rebind(linkedEndpoint.getEndpointName(), 531 linkRef); 532 } 533 534 } catch (NamingException e) { 535 log.error(e.getMessage(), e); 536 throw new RegistryException( 537 "problem while registering connection with service name " 538 + linkedEndpoint.getServiceName() 539 + " and endpoint name " 540 + linkedEndpoint.getEndpointName() + " to " 541 + linkedEndpoint.getToEndpointName() + " "); 542 } 543 } 544 log.end(); 546 } 547 548 551 public void registerExternalEndpoint(ServiceEndpoint externalEndpoint) 552 throws RegistryException { 553 log.start(); 554 registerEndpoint(externalEndpoint); 555 log.end(); 556 } 557 558 561 public void registerInternalEndpoint(AbstractEndpoint endpoint) 562 throws RegistryException { 563 log.start(); 564 registerEndpoint(endpoint); 565 log.end(); 566 } 567 568 571 public List <AbstractEndpoint> retrieveNewEndpoints() 572 throws RegistryException { 573 log.start(); 574 List <AbstractEndpoint> endpoints = new ArrayList <AbstractEndpoint>(); 575 try { 576 NamingEnumeration <Binding > bindings = rootContext 577 .listBindings(NEW_ENDPOINTS_REF); 578 579 while (bindings.hasMoreElements()) { 580 Binding binding = bindings.next(); 581 Object object = binding.getObject(); 582 if (object instanceof LinkRef ) { 583 AbstractEndpoint abstractEndpoint = (AbstractEndpoint) rootContext 584 .lookup(((LinkRef ) object).getLinkName()); 585 if (abstractEndpoint.getDescription() == null) { 586 endpoints.add(abstractEndpoint); 587 } 588 } 589 } 590 } catch (Exception e) { 591 String msg = "Problem while retrieving all the new endpoints"; 592 log.error(msg, e); 593 throw new RegistryException(msg, e); 594 } 595 log.end(); 596 return endpoints; 597 } 598 599 602 @LifeCycle(on=LifeCycleType.START) 603 public void start() throws IllegalLifeCycleException { 604 log = new LoggingUtil(logger); 605 try { 606 initContexts(); 607 } catch (JBIException e) { 608 throw new IllegalLifeCycleException(e.getMessage()); 609 } 610 } 611 612 615 public void validateEndpoint(AbstractEndpoint endpoint) 616 throws RegistryException { 617 log.start(); 618 if (endpoint == null) { 619 throw new IllegalArgumentException ("The endpoint must be non null"); 620 } 621 try { 622 for (QName name : endpoint.getInterfaces()) { 624 Name nameInterface = NamingHelper.qNameToName(name); 625 626 Context interfaceCtx = retrieveInterfaceContext(nameInterface); 627 if (JNDIUtil.isBound(interfacesContext, nameInterface, endpoint 629 .getEndpointName())) { 630 LinkRef linkRef = new LinkRef ("/" + ENDPOINTS_REF + "/" 632 + endpoint.getEndpointName()); 633 interfaceCtx.rebind(endpoint.getEndpointName(), linkRef); 634 } else { 635 LinkRef linkRef = new LinkRef ("/" + ENDPOINTS_REF + "/" 637 + endpoint.getEndpointName()); 638 interfaceCtx.bind(endpoint.getEndpointName(), linkRef); 639 } 640 } 641 endpointsContext.rebind(endpoint.getEndpointName(), endpoint); 643 644 } catch (Exception e) { 647 log.error("Error while validating endpoint " 648 + endpoint.getEndpointName(), e); 649 throw new RegistryException(e); 650 } 651 log.end(); 652 } 653 654 661 @SuppressWarnings ("unchecked") 662 protected void bindInEndpointContext(AbstractEndpoint endpoint) 663 throws NamingException { 664 log.call(); 665 if (JNDIUtil.isBound(rootContext, ENDPOINTS_REF, endpoint 666 .getEndpointName())) { 667 throw new NamingException ("Endpoint " + endpoint.getEndpointName() 668 + " is already bound"); 669 } else { 670 endpointsContext.bind(endpoint.getEndpointName(), endpoint); 671 } 672 } 673 674 681 protected void bindInNewEndpointContext(AbstractEndpoint endpoint) 682 throws NamingException { 683 log.call(); 684 LinkRef linkRef = new LinkRef ("/" + ENDPOINTS_REF + "/" 685 + endpoint.getEndpointName()); 686 if (!JNDIUtil.isBound(rootContext, NEW_ENDPOINTS_REF, endpoint 687 .getEndpointName())) { 688 newEndpointContext.bind(endpoint.getEndpointName(), linkRef); 689 } 690 } 691 692 700 protected void bindInServiceContext(AbstractEndpoint endpoint) 701 throws NamingException { 702 log.call(); 703 Name serviceName = NamingHelper.qNameToName(endpoint.getServiceName()); 704 if (!StringHelper.isEmpty(NamingHelper.qNameToString(endpoint 705 .getServiceName()))) { 706 LinkRef linkRef = new LinkRef ("/" + ENDPOINTS_REF + "/" 707 + endpoint.getEndpointName()); 708 Context servContext = retrieveServiceContext(serviceName); 709 if (!JNDIUtil.isBound(servicesContext, serviceName, endpoint 710 .getEndpointName())) { 711 servContext.bind(endpoint.getEndpointName(), linkRef); 712 } 713 } 714 } 715 716 723 protected void initContexts() throws RegistryException { 724 log.start(); 725 try { 726 rootContext = new InitialContext (PropertyUtil 727 .retrieveJNDIProperties()); 728 if (JNDIUtil.isBound(rootContext, "/", ENDPOINTS_REF)) { 729 endpointsContext = (Context ) rootContext.lookup(ENDPOINTS_REF); 730 } else { 731 endpointsContext = rootContext.createSubcontext(ENDPOINTS_REF); 732 } 733 if (JNDIUtil.isBound(rootContext, "/", SERVICES_REF)) { 734 servicesContext = (Context ) rootContext.lookup(SERVICES_REF); 735 } else { 736 servicesContext = rootContext.createSubcontext(SERVICES_REF); 737 } 738 if (JNDIUtil.isBound(rootContext, "/", NEW_ENDPOINTS_REF)) { 739 newEndpointContext = (Context ) rootContext 740 .lookup(NEW_ENDPOINTS_REF); 741 } else { 742 newEndpointContext = rootContext 743 .createSubcontext(NEW_ENDPOINTS_REF); 744 } 745 if (JNDIUtil.isBound(rootContext, "/", INTERFACES_REF)) { 746 interfacesContext = (Context ) rootContext 747 .lookup(INTERFACES_REF); 748 } else { 749 interfacesContext = rootContext 750 .createSubcontext(INTERFACES_REF); 751 } 752 if (JNDIUtil.isBound(rootContext, "/", USERS_REF)) { 753 usersContext = (Context ) rootContext.lookup(USERS_REF); 754 } else { 755 usersContext = rootContext.createSubcontext(USERS_REF); 756 } 757 if (endpointsContext == null || servicesContext == null 758 || interfacesContext == null || usersContext == null) { 759 throw new NotContextException (); 760 } 761 } catch (Exception e) { 762 log.error("Problem initating the contexts", e); 763 throw new RegistryException(e); 764 } 765 log.end(); 766 } 767 768 771 protected void registerEndpoint(ServiceEndpoint endpoint) 772 throws RegistryException { 773 log.start(); 774 if (endpoint == null) { 775 throw new IllegalArgumentException ("Endpoint must not be null"); 776 } 777 if (JNDIUtil.isBound(rootContext, ENDPOINTS_REF, endpoint 778 .getEndpointName())) { 779 AbstractEndpoint registeredEndpoint = retrieveEndpoint(endpoint 781 .getEndpointName()); 782 783 if (registeredEndpoint == null) { 786 String msg = "You are trying to register an endpoint with a name that " 787 + "is already bound to an other object " 788 + "(link or anything else) in the JNDI Registry."; 789 log.error(msg); 790 throw new RegistryException(msg); 791 } 792 793 if (!(((AbstractEndpoint) endpoint).getContainerName().equals( 797 registeredEndpoint.getContainerName()) && ((AbstractEndpoint) endpoint) 798 .getComponentName().equals( 799 registeredEndpoint.getComponentName()))) { 800 String msg = "The endpoint " 801 + endpoint.getEndpointName() 802 + " is already registered for an other component/container"; 803 log.error(msg); 804 throw new RegistryException(msg); 805 } 806 807 } else { 808 try { 809 bindInEndpointContext((AbstractEndpoint) endpoint); 810 811 bindInNewEndpointContext((AbstractEndpoint) endpoint); 812 813 bindInServiceContext((AbstractEndpoint) endpoint); 814 } catch (Exception e) { 815 log.error("Problem while registering endpoint " 816 + endpoint.getEndpointName(), e); 817 throw new RegistryException( 818 "Problem while registering endpoint " 819 + endpoint.getEndpointName()); 820 } 821 } 822 log.end(); 823 } 824 825 839 @SuppressWarnings ("unchecked") 840 protected AbstractEndpoint retrieveEndpoint(QName service, String name, 841 String endpointClassName) throws RegistryException { 842 log.call(); 843 AbstractEndpoint endpoint = retrieveEndpoint(service, name, 844 endpointClassName, true); 845 return endpoint; 846 } 847 848 864 @SuppressWarnings ("unchecked") 865 protected AbstractEndpoint retrieveEndpoint(QName service, String name, 866 String endpointClassName, boolean resolveLink) 867 throws RegistryException { 868 log.start(); 869 if (service == null) { 870 throw new IllegalArgumentException ( 871 "The service name must be non null"); 872 } 873 if (name == null) { 874 throw new IllegalArgumentException ( 875 "The endpoint name must be non null"); 876 } 877 AbstractEndpoint result = null; 878 try { 879 Object outObj = endpointsContext.lookup(name); 880 881 if (outObj instanceof AbstractEndpoint) { 883 AbstractEndpoint endpoint = (AbstractEndpoint) outObj; 884 if (endpoint.getClass().getName().equals(endpointClassName)) { 885 result = endpoint; 886 } 887 } 888 else if (outObj instanceof LinkRef ) { 890 Object obj = rootContext.lookup(((LinkRef ) outObj) 891 .getLinkName()); 892 893 if (obj instanceof AbstractEndpoint) { 894 AbstractEndpoint endpoint = (AbstractEndpoint) obj; 895 if (endpoint.getClass().getName().equals(endpointClassName)) { 896 if (resolveLink) { 898 result = endpoint; 899 } 900 else { 902 result = new LinkedEndpoint(service, name, endpoint 903 .getServiceName(), endpoint 904 .getEndpointName(), null); 905 } 906 } 907 } 908 } 909 } catch (NamingException e1) { 910 } 912 log.end(); 913 return result; 914 } 915 916 927 @SuppressWarnings ("unchecked") 928 protected AbstractEndpoint retrieveEndpoint(String name) 929 throws RegistryException { 930 log.start(); 931 if (name == null) { 932 throw new IllegalArgumentException ( 933 "The endpoint name must be non null"); 934 } 935 AbstractEndpoint result = null; 936 try { 937 Object outObj = endpointsContext.lookup(name); 938 939 if (outObj instanceof AbstractEndpoint) { 941 result = (AbstractEndpoint) outObj; 942 } 943 } catch (NamingException e1) { 944 String msg = "Error while looking up an Endpoint in the JNDI Registry"; 945 log.error(msg, e1); 946 throw new RegistryException(msg, e1); 947 } 948 log.end(); 949 return result; 950 } 951 952 963 @SuppressWarnings ("unchecked") 964 protected AbstractEndpoint[] retrieveEndpointsForInterface( 965 QName interfaceName, String endpointType) throws RegistryException { 966 log.start(); 967 List <AbstractEndpoint> result = new ArrayList <AbstractEndpoint>(); 968 try { 969 if (interfaceName == null) { 970 NamingEnumeration <Binding > bindings = rootContext 972 .listBindings(ENDPOINTS_REF); 973 974 while (bindings.hasMoreElements()) { 975 Binding binding = (Binding ) bindings.next(); 976 if (binding.getObject() instanceof AbstractEndpoint) { 977 AbstractEndpoint endpoint = (AbstractEndpoint) binding 978 .getObject(); 979 if (endpoint.getClass().getName().equals(endpointType)) { 980 result.add(endpoint); 981 } 982 } 983 } 984 } else { 985 Name name = NamingHelper.qNameToName(interfaceName); 988 if (JNDIUtil.isBound(rootContext, INTERFACES_REF, name)) { 989 NamingEnumeration <Binding > bindings = interfacesContext 990 .listBindings(name); 991 992 while (bindings.hasMoreElements()) { 993 Binding binding = bindings.next(); 994 Object object = binding.getObject(); 995 if (object instanceof LinkRef ) { 996 LinkRef linkRef = (LinkRef ) object; 997 Object obj = rootContext.lookup(linkRef 998 .getLinkName()); 999 if (obj instanceof AbstractEndpoint) { 1000 AbstractEndpoint endpoint = (AbstractEndpoint) obj; 1001 if (endpoint.getClass().getName().equals( 1002 endpointType)) { 1003 result.add(endpoint); 1004 } 1005 } 1006 } 1007 } 1008 } 1009 } 1010 } catch (Exception e) { 1011 log.error(e.getMessage(), e); 1012 throw new RegistryException( 1013 "Problem while getting endpoints for the specified interface " 1014 + interfaceName); 1015 } 1016 log.end(); 1017 return result.toArray(new AbstractEndpoint[0]); 1018 } 1019 1020 1023 @SuppressWarnings ("unchecked") 1024 protected AbstractEndpoint[] retrieveEndpointsForService(QName serviceName, 1025 String endpointType) { 1026 log.start(); 1027 if (serviceName == null) { 1028 throw new IllegalArgumentException ( 1029 "The service name must be non null"); 1030 } 1031 AbstractEndpoint[] result = new AbstractEndpoint[0]; 1032 Name name = NamingHelper.qNameToName(serviceName); 1033 if (JNDIUtil.isBound(rootContext, SERVICES_REF, name)) { 1034 try { 1035 NamingEnumeration <Binding > bindings = servicesContext 1036 .listBindings(NamingHelper.qNameToName(serviceName)); 1037 List <AbstractEndpoint> endpoints = new ArrayList <AbstractEndpoint>(); 1038 while (bindings.hasMoreElements()) { 1039 Binding binding = bindings.next(); 1040 Object object = binding.getObject(); 1041 if (object instanceof LinkRef ) { 1042 LinkRef linkRef = (LinkRef ) object; 1043 Object obj = rootContext.lookup(linkRef.getLinkName()); 1044 if (obj instanceof AbstractEndpoint) { 1045 AbstractEndpoint endpoint = (AbstractEndpoint) obj; 1046 if (endpoint.getClass().getName().equals( 1047 endpointType)) { 1048 endpoints.add(endpoint); 1049 } 1050 } 1051 } 1052 } 1053 result = endpoints.toArray(new AbstractEndpoint[0]); 1054 } catch (NamingException e) { 1055 log.error(e.getMessage(), e); 1056 } 1057 } 1058 log.end(); 1059 return result; 1060 } 1061 1062 1069 protected Context retrieveInterfaceContext(Name interfaceName) 1070 throws NamingException { 1071 log.call(); 1072 Context interfContext = null; 1073 if (JNDIUtil.isBound(rootContext, INTERFACES_REF, interfaceName)) { 1074 interfContext = (Context ) interfacesContext.lookup(interfaceName); 1075 } else { 1076 interfContext = interfacesContext.createSubcontext(interfaceName); 1077 } 1078 return interfContext; 1079 } 1080 1081 1088 protected Context retrieveServiceContext(Name serviceName) 1089 throws NamingException { 1090 log.call(); 1091 Context serviceContext = null; 1092 if (JNDIUtil.isBound(rootContext, SERVICES_REF, serviceName)) { 1093 serviceContext = (Context ) servicesContext.lookup(serviceName); 1094 } else { 1095 serviceContext = servicesContext.createSubcontext(serviceName); 1096 } 1097 return serviceContext; 1098 } 1099 1100} 1101 | Popular Tags |