1 22 package org.jboss.proxy.ejb; 23 24 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 import javax.ejb.EJBHome ; 31 import javax.ejb.EJBMetaData ; 32 import javax.ejb.EJBObject ; 33 import javax.management.ObjectName ; 34 import javax.naming.Context ; 35 import javax.naming.InitialContext ; 36 import javax.naming.NamingException ; 37 import javax.naming.Reference ; 38 import javax.naming.StringRefAddr ; 39 import javax.rmi.CORBA.Stub ; 40 import javax.rmi.PortableRemoteObject ; 41 42 import org.jacorb.ssl.SSLPolicyValue; 43 import org.jacorb.ssl.SSLPolicyValueHelper; 44 import org.jacorb.ssl.SSL_POLICY_TYPE; 45 import org.jboss.ejb.Container; 46 import org.jboss.ejb.EJBProxyFactory; 47 import org.jboss.ejb.EJBProxyFactoryContainer; 48 import org.jboss.ejb.EntityContainer; 49 import org.jboss.ejb.StatefulSessionContainer; 50 import org.jboss.ejb.StatelessSessionContainer; 51 import org.jboss.iiop.CorbaNamingService; 52 import org.jboss.iiop.CorbaORBService; 53 import org.jboss.iiop.codebase.CodebasePolicy; 54 import org.jboss.iiop.csiv2.CSIv2Policy; 55 import org.jboss.iiop.rmi.AttributeAnalysis; 56 import org.jboss.iiop.rmi.InterfaceAnalysis; 57 import org.jboss.iiop.rmi.OperationAnalysis; 58 import org.jboss.iiop.rmi.ir.InterfaceRepository; 59 import org.jboss.iiop.rmi.marshal.strategy.SkeletonStrategy; 60 import org.jboss.invocation.Invocation; 61 import org.jboss.invocation.iiop.ReferenceFactory; 62 import org.jboss.invocation.iiop.ServantRegistries; 63 import org.jboss.invocation.iiop.ServantRegistry; 64 import org.jboss.invocation.iiop.ServantRegistryKind; 65 import org.jboss.invocation.iiop.ServantWithMBeanServer; 66 import org.jboss.logging.Logger; 67 import org.jboss.metadata.EntityMetaData; 68 import org.jboss.metadata.InvokerProxyBindingMetaData; 69 import org.jboss.metadata.IorSecurityConfigMetaData; 70 import org.jboss.metadata.MetaData; 71 import org.jboss.metadata.SessionMetaData; 72 import org.jboss.naming.Util; 73 import org.jboss.system.Registry; 74 import org.jboss.web.WebClassLoader; 75 import org.omg.CORBA.Any ; 76 import org.omg.CORBA.InterfaceDef ; 77 import org.omg.CORBA.InterfaceDefHelper; 78 import org.omg.CORBA.ORB ; 79 import org.omg.CORBA.Policy ; 80 import org.omg.CORBA.Repository ; 81 import org.omg.CosNaming.NameComponent ; 82 import org.omg.CosNaming.NamingContext ; 83 import org.omg.CosNaming.NamingContextExt ; 84 import org.omg.CosNaming.NamingContextExtHelper ; 85 import org.omg.CosNaming.NamingContextHelper ; 86 import org.omg.CosNaming.NamingContextPackage.CannotProceed ; 87 import org.omg.CosNaming.NamingContextPackage.InvalidName ; 88 import org.omg.CosNaming.NamingContextPackage.NotFound ; 89 import org.omg.PortableServer.Current ; 90 import org.omg.PortableServer.CurrentHelper ; 91 import org.omg.PortableServer.POA ; 92 import org.w3c.dom.Element ; 93 94 107 public class IORFactory 108 implements EJBProxyFactory 109 { 110 111 113 private static final Logger staticLogger = 114 Logger.getLogger(IORFactory.class); 115 116 118 121 private ORB orb; 122 123 126 private Container container; 127 128 131 private String jndiName; 132 133 137 private boolean useJNPContext; 138 139 142 private String jnpName; 143 144 147 private EJBMetaDataImplIIOP ejbMetaData; 148 149 152 private Map beanMethodMap; 153 154 157 private Map homeMethodMap; 158 159 163 private String [] beanRepositoryIds; 164 165 169 private String [] homeRepositoryIds; 170 171 174 private ServantRegistry homeServantRegistry; 175 176 179 private ServantRegistry beanServantRegistry; 180 181 184 private ReferenceFactory homeReferenceFactory; 185 186 189 private ReferenceFactory beanReferenceFactory; 190 191 195 private Current poaCurrent; 196 197 200 private Policy codebasePolicy; 201 202 205 private Policy csiv2Policy; 206 207 210 private Policy sslPolicy; 211 212 215 private EJBHome ejbHome; 216 217 220 private InvokerProxyBindingMetaData invokerMetaData; 221 222 225 private ServantRegistries servantRegistries; 226 227 231 private InterfaceRepository iri; 232 233 236 private POA irPoa; 237 238 244 private Logger logger = staticLogger; 245 246 248 public void setContainer(Container container) 249 { 250 this.container = container; 251 if (container != null) { 252 String loggerName = IORFactory.class.getName() + '.' 253 + container.getBeanMetaData().getJndiName(); 254 logger = Logger.getLogger(loggerName); 255 } 256 } 257 258 public void create() throws Exception 259 { 260 try { 262 orb = (ORB )new InitialContext ().lookup("java:/" 263 + CorbaORBService.ORB_NAME); 264 } 265 catch (NamingException e) { 266 throw new Exception ("Cannot lookup java:/" 267 + CorbaORBService.ORB_NAME + ": " + e); 268 } 269 try { 270 irPoa = (POA )new InitialContext ().lookup("java:/" 271 + CorbaORBService.IR_POA_NAME); 272 } 273 catch (NamingException e) { 274 throw new Exception ("Cannot lookup java:/" 275 + CorbaORBService.IR_POA_NAME + ": " + e); 276 } 277 278 Element proxyFactoryConfig = invokerMetaData.getProxyFactoryConfig(); 280 boolean interfaceRepositorySupported = 281 MetaData.getOptionalChildBooleanContent( 282 proxyFactoryConfig, "interface-repository-supported"); 283 284 if (interfaceRepositorySupported) { 285 iri = new InterfaceRepository(orb, irPoa, jndiName); 287 288 iri.mapClass(((EJBProxyFactoryContainer)container).getRemoteClass()); 290 iri.mapClass(((EJBProxyFactoryContainer)container).getHomeClass()); 291 iri.finishBuild(); 292 293 logger.info("CORBA interface repository for " + jndiName + ": " 294 + orb.object_to_string(iri.getReference())); 295 } 296 297 logger.debug("Bean methods:"); 299 300 InterfaceAnalysis interfaceAnalysis = 301 InterfaceAnalysis.getInterfaceAnalysis( 302 ((EJBProxyFactoryContainer)container).getRemoteClass()); 303 304 beanMethodMap = new HashMap (); 305 306 AttributeAnalysis[] attrs = interfaceAnalysis.getAttributes(); 307 for (int i = 0; i < attrs.length; i++) { 308 OperationAnalysis op = attrs[i].getAccessorAnalysis(); 309 310 logger.debug(" " + op.getJavaName() 311 + "\n " + op.getIDLName()); 312 beanMethodMap.put(op.getIDLName(), 313 new SkeletonStrategy(op.getMethod())); 314 op = attrs[i].getMutatorAnalysis(); 315 if (op != null) { 316 logger.debug(" " + op.getJavaName() 317 + "\n " + op.getIDLName()); 318 beanMethodMap.put(op.getIDLName(), 319 new SkeletonStrategy(op.getMethod())); 320 } 321 } 322 323 OperationAnalysis[] ops = interfaceAnalysis.getOperations(); 324 for (int i = 0; i < ops.length; i++) { 325 logger.debug(" " + ops[i].getJavaName() 326 + "\n " + ops[i].getIDLName()); 327 beanMethodMap.put(ops[i].getIDLName(), 328 new SkeletonStrategy(ops[i].getMethod())); 329 } 330 331 beanRepositoryIds = interfaceAnalysis.getAllTypeIds(); 333 334 logger.debug("Home methods:"); 336 337 interfaceAnalysis = 338 InterfaceAnalysis.getInterfaceAnalysis( 339 ((EJBProxyFactoryContainer)container).getHomeClass()); 340 341 homeMethodMap = new HashMap (); 342 343 attrs = interfaceAnalysis.getAttributes(); 344 for (int i = 0; i < attrs.length; i++) { 345 OperationAnalysis op = attrs[i].getAccessorAnalysis(); 346 347 logger.debug(" " + op.getJavaName() 348 + "\n " + op.getIDLName()); 349 homeMethodMap.put(op.getIDLName(), 350 new SkeletonStrategy(op.getMethod())); 351 op = attrs[i].getMutatorAnalysis(); 352 if (op != null) { 353 logger.debug(" " + op.getJavaName() 354 + "\n " + op.getIDLName()); 355 homeMethodMap.put(op.getIDLName(), 356 new SkeletonStrategy(op.getMethod())); 357 } 358 } 359 360 ops = interfaceAnalysis.getOperations(); 361 for (int i = 0; i < ops.length; i++) { 362 logger.debug(" " + ops[i].getJavaName() 363 + "\n " + ops[i].getIDLName()); 364 homeMethodMap.put(ops[i].getIDLName(), 365 new SkeletonStrategy(ops[i].getMethod())); 366 } 367 368 homeRepositoryIds = interfaceAnalysis.getAllTypeIds(); 370 371 logger.debug("container classloader: " + container.getClassLoader() 373 + "\ncontainer parent classloader: " 374 + container.getClassLoader().getParent()); 375 WebClassLoader wcl = (WebClassLoader)container.getWebClassLoader(); 376 String codebaseString; 377 if (wcl != null && (codebaseString = wcl.getCodebaseString()) != null) 378 { 379 Any codebase = orb.create_any(); 380 codebase.insert_string(codebaseString); 381 codebasePolicy = orb.create_policy(CodebasePolicy.TYPE, codebase); 382 logger.debug("codebasePolicy: " + codebasePolicy); 383 } 384 else 385 { 386 logger.debug("Not setting codebase policy, codebase is null"); 387 } 388 389 Any secPolicy = orb.create_any(); 392 IorSecurityConfigMetaData iorSecurityConfigMetaData = 393 container.getBeanMetaData().getIorSecurityConfigMetaData(); 394 secPolicy.insert_Value(iorSecurityConfigMetaData); 395 csiv2Policy = orb.create_policy(CSIv2Policy.TYPE, secPolicy); 396 397 boolean sslRequired = false; 401 if (iorSecurityConfigMetaData != null) { 402 IorSecurityConfigMetaData.TransportConfig tc = 403 iorSecurityConfigMetaData.getTransportConfig(); 404 sslRequired = 405 tc.getIntegrity() == 406 IorSecurityConfigMetaData.TransportConfig.INTEGRITY_REQUIRED 407 || tc.getConfidentiality() == 408 IorSecurityConfigMetaData.TransportConfig.CONFIDENTIALITY_REQUIRED 409 || tc.getEstablishTrustInClient() == 410 IorSecurityConfigMetaData.TransportConfig.ESTABLISH_TRUST_IN_CLIENT_REQUIRED; 411 } 412 Any sslPolicyValue = orb.create_any(); 413 SSLPolicyValueHelper.insert( 414 sslPolicyValue, 415 (sslRequired) ? SSLPolicyValue.SSL_REQUIRED 416 : SSLPolicyValue.SSL_NOT_REQUIRED); 417 sslPolicy = orb.create_policy(SSL_POLICY_TYPE.value, sslPolicyValue); 418 logger.debug("container's SSL policy: " + sslPolicy); 419 420 poaCurrent = CurrentHelper.narrow( 422 orb.resolve_initial_references("POACurrent")); 423 } 424 425 public void start() throws Exception 426 { 427 ObjectName oname = new ObjectName (invokerMetaData.getInvokerMBean()); 431 servantRegistries = (ServantRegistries)Registry.lookup(oname); 432 if (servantRegistries == null) 433 throw new Exception ("invoker is null: " + oname); 434 435 Policy[] policies = null; 436 if (codebasePolicy == null) 437 policies = new Policy[] { sslPolicy, csiv2Policy }; 438 else 439 policies = new Policy[] { codebasePolicy, sslPolicy, csiv2Policy }; 440 441 442 ServantRegistryKind registryWithTransientPOA; 444 ServantRegistryKind registryWithPersistentPOA; 445 Element proxyFactoryConfig = invokerMetaData.getProxyFactoryConfig(); 446 String poaUsageModel = 447 MetaData.getOptionalChildContent(proxyFactoryConfig, "poa"); 448 if (poaUsageModel == null || poaUsageModel.equals("shared")) { 449 registryWithTransientPOA = ServantRegistryKind.SHARED_TRANSIENT_POA; 450 registryWithPersistentPOA = ServantRegistryKind.SHARED_PERSISTENT_POA; 451 } 452 else if (poaUsageModel.equals("per-servant")) { 453 registryWithTransientPOA = 454 ServantRegistryKind.TRANSIENT_POA_PER_SERVANT; 455 registryWithPersistentPOA = 456 ServantRegistryKind.PERSISTENT_POA_PER_SERVANT; 457 } 458 else { 459 throw new Exception ("invalid poa element in proxy factory config: " 460 + poaUsageModel); 461 } 462 463 InterfaceDef homeInterfaceDef = null; 466 if (iri != null) { 467 Repository ir = iri.getReference(); 468 homeInterfaceDef = 469 InterfaceDefHelper.narrow(ir.lookup_id(homeRepositoryIds[0])); 470 } 471 472 homeServantRegistry = 475 servantRegistries.getServantRegistry(registryWithPersistentPOA); 476 477 478 String homeServantLoggerName = 479 EjbHomeCorbaServant.class.getName() + '.'+ jndiName; 480 481 ServantWithMBeanServer homeServant = 482 new EjbHomeCorbaServant(container.getJmxName(), 483 container.getClassLoader(), 484 homeMethodMap, 485 homeRepositoryIds, 486 homeInterfaceDef, 487 Logger.getLogger(homeServantLoggerName)); 488 489 homeReferenceFactory = homeServantRegistry.bind(homeServantName(jndiName), homeServant, policies); 490 491 org.omg.CORBA.Object corbaRef = 492 homeReferenceFactory.createReference(homeRepositoryIds[0]); 493 ((EjbHomeCorbaServant)homeServant).setHomeHandle( 494 new HomeHandleImplIIOP(corbaRef)); 495 ejbHome = (EJBHome )PortableRemoteObject.narrow(corbaRef, EJBHome .class); 496 497 if (container.getBeanMetaData() instanceof EntityMetaData) { 499 500 beanServantRegistry = 502 servantRegistries.getServantRegistry(registryWithPersistentPOA); 503 504 Class pkClass; 505 EntityMetaData metaData = (EntityMetaData)container.getBeanMetaData(); 506 String pkClassName = metaData.getPrimaryKeyClass(); 507 try { 508 if (pkClassName != null) 509 pkClass = container.getClassLoader().loadClass(pkClassName); 510 else 511 pkClass = container.getClassLoader().loadClass( 512 metaData.getEjbClass()).getField( 513 metaData.getPrimKeyField()).getClass(); 514 } 515 catch (NoSuchFieldException e) { 516 logger.error("Unable to identify Bean's Primary Key class! " 517 + "Did you specify a primary key class and/or field? " 518 + "Does that field exist?"); 519 throw new Exception ("Primary Key Problem"); 520 } 521 catch (NullPointerException e) { 522 logger.error("Unable to identify Bean's Primary Key class! " 523 + "Did you specify a primary key class and/or field? " 524 + "Does that field exist?"); 525 throw new Exception ("Primary Key Problem"); 526 } 527 528 ejbMetaData = new EJBMetaDataImplIIOP( 529 ((EJBProxyFactoryContainer)container).getRemoteClass(), 530 ((EJBProxyFactoryContainer)container).getHomeClass(), 531 pkClass, 532 false, false, ejbHome); 535 } 536 else { 537 538 beanServantRegistry = 540 servantRegistries.getServantRegistry(registryWithTransientPOA); 541 542 if (((SessionMetaData)container.getBeanMetaData()).isStateless()) { 543 544 ejbMetaData = new EJBMetaDataImplIIOP( 546 ((EJBProxyFactoryContainer)container).getRemoteClass(), 547 ((EJBProxyFactoryContainer)container).getHomeClass(), 548 null, true, true, ejbHome); 552 553 } 554 else { 555 556 ejbMetaData = new EJBMetaDataImplIIOP( 558 ((EJBProxyFactoryContainer)container).getRemoteClass(), 559 ((EJBProxyFactoryContainer)container).getHomeClass(), 560 null, true, false, ejbHome); 564 } 565 } 566 567 InterfaceDef beanInterfaceDef = null; 570 if (iri != null) { 571 Repository ir = iri.getReference(); 572 beanInterfaceDef = 573 InterfaceDefHelper.narrow(ir.lookup_id(beanRepositoryIds[0])); 574 } 575 576 String beanServantLoggerName = 577 EjbObjectCorbaServant.class.getName() + '.'+ jndiName; 578 579 ServantWithMBeanServer beanServant = 580 new EjbObjectCorbaServant(container.getJmxName(), 581 container.getClassLoader(), 582 poaCurrent, 583 beanMethodMap, 584 beanRepositoryIds, 585 beanInterfaceDef, 586 Logger.getLogger(beanServantLoggerName)); 587 588 beanReferenceFactory = beanServantRegistry.bind(beanServantName(jndiName), beanServant, policies); 589 590 logger.info("EJBHome reference for " + jndiName + ":\n" 592 + orb.object_to_string((org.omg.CORBA.Object )ejbHome)); 593 594 useJNPContext = MetaData.getOptionalChildBooleanContent( 596 proxyFactoryConfig, "register-ejbs-in-jnp-context"); 597 598 Context initialContext = new InitialContext (); 599 600 if (useJNPContext) { 601 String jnpContext = 602 MetaData.getOptionalChildContent(proxyFactoryConfig, 603 "jnp-context"); 604 if (jnpContext != null && !jnpContext.equals("")) { 605 jnpName = jnpContext + "/" + jndiName; 606 } 607 else { 608 jnpName = jndiName; 609 } 610 611 try { 612 Util.rebind(initialContext, 614 jnpName, 615 new Reference ( 616 "javax.ejb.EJBHome", 617 new StringRefAddr ("IOR", 618 orb.object_to_string( 619 (org.omg.CORBA.Object )ejbHome)), 620 IIOPHomeFactory.class.getName(), 621 null)); 622 logger.info("Home IOR for " + container.getBeanMetaData().getEjbName() 623 + " bound to " + jnpName + " in JNP naming service"); 624 } 625 catch (NamingException e) { 626 throw new Exception ("Cannot bind EJBHome in JNDI:\n" + e); 627 } 628 } 629 630 NamingContextExt corbaContext = null; 631 try { 632 corbaContext = NamingContextExtHelper.narrow((org.omg.CORBA.Object ) 634 initialContext.lookup("java:/" + 635 CorbaNamingService.NAMING_NAME)); 636 } 637 catch (NamingException e) { 638 throw new Exception ("Cannot lookup java:/" + 639 CorbaNamingService.NAMING_NAME + ":\n" + e); 640 } 641 642 try { 643 rebind(corbaContext, jndiName, (org.omg.CORBA.Object )ejbHome); 645 logger.info("Home IOR for " + container.getBeanMetaData().getEjbName() 646 + " bound to " + jndiName + " in CORBA naming service"); 647 } 648 catch (Exception e) { 649 logger.error("Cannot bind EJBHome in CORBA naming service:", e); 650 throw new Exception ("Cannot bind EJBHome in CORBA naming service:\n" 651 + e); 652 } 653 654 } 655 656 public void stop() 657 { 658 try { 659 Context initialContext = new InitialContext (); 661 662 if (useJNPContext) { 663 try { 665 initialContext.unbind(jnpName); 666 } 667 catch (NamingException namingException) { 668 logger.error("Cannot unbind EJBHome from JNDI", namingException); 669 } 670 } 671 672 NamingContextExt corbaContext = 674 NamingContextExtHelper.narrow((org.omg.CORBA.Object ) 675 initialContext.lookup("java:/" 676 + CorbaNamingService.NAMING_NAME)); 677 678 try { 680 NameComponent [] name = corbaContext.to_name(jndiName); 681 corbaContext.unbind(name); 682 } 683 catch (InvalidName invalidName) { 684 logger.error("Cannot unregister EJBHome from CORBA naming service", 685 invalidName); 686 } 687 catch (NotFound notFound) { 688 logger.error("Cannot unregister EJBHome from CORBA naming service", 689 notFound); 690 } 691 catch (CannotProceed cannotProceed) { 692 logger.error("Cannot unregister EJBHome from CORBA naming service", 693 cannotProceed); 694 } 695 } 696 catch (NamingException namingException) { 697 logger.error("Unexpected error in JNDI lookup", namingException); 698 } 699 700 try { 702 homeServantRegistry.unbind(homeServantName(jndiName)); 703 } 704 catch (Exception e) { 705 logger.error("Cannot deactivate home servant", e); 706 } 707 try { 708 beanServantRegistry.unbind(beanServantName(jndiName)); 709 } 710 catch (Exception e) { 711 logger.error("Cannot deactivate bean servant", e); 712 } 713 714 if (iri != null) { 715 iri.shutdown(); 717 } 718 } 719 720 public void destroy() 721 { 722 } 723 724 726 public void setInvokerMetaData(InvokerProxyBindingMetaData imd) 727 { 728 invokerMetaData = imd; 729 } 730 731 public void setInvokerBinding(String binding) 732 { 733 jndiName = binding; 734 } 735 736 public boolean isIdentical(Container container, Invocation mi) 737 { 738 EJBObject other = (EJBObject ) mi.getArguments()[0]; 739 if (other == null) 740 return false; 741 EJBObject me; 742 if (container instanceof StatelessSessionContainer) 743 me = (EJBObject ) getStatelessSessionEJBObject(); 744 else if (container instanceof StatefulSessionContainer) 745 me = (EJBObject ) getStatefulSessionEJBObject(mi.getId()); 746 else if (container instanceof EntityContainer) 747 me = (EJBObject ) getEntityEJBObject(mi.getId()); 748 else 749 return false; 750 751 Stub meStub = (Stub ) me; 752 Stub otherStub = (Stub ) other; 753 return meStub._is_equivalent(otherStub); 754 } 755 756 public EJBMetaData getEJBMetaData() 757 { 758 return ejbMetaData; 759 } 760 761 public Object getEJBHome() 762 { 763 return ejbHome; 764 } 765 766 public Object getStatelessSessionEJBObject() 767 { 768 try { 769 return (EJBObject )PortableRemoteObject.narrow( 770 beanReferenceFactory.createReference(beanRepositoryIds[0]), 771 EJBObject .class); 772 } 773 catch (Exception e) { 774 throw new RuntimeException ("Unable to create reference to EJBObject\n" 775 + e); 776 } 777 } 778 779 public Object getStatefulSessionEJBObject(Object id) 780 { 781 try { 782 return (EJBObject )PortableRemoteObject.narrow( 783 beanReferenceFactory.createReferenceWithId( 784 id, 785 beanRepositoryIds[0]), 786 EJBObject .class); 787 } 788 catch (Exception e) { 789 throw new RuntimeException ("Unable to create reference to EJBObject\n" 790 + e); 791 } 792 } 793 794 public Object getEntityEJBObject(Object id) 795 { 796 if (logger.isTraceEnabled()) { 797 logger.trace("getEntityEJBObject(), id class is " 798 + id.getClass().getName()); 799 } 800 try { 801 Object ejbObject = (id == null ? null : 802 (EJBObject )PortableRemoteObject.narrow( 803 beanReferenceFactory.createReferenceWithId(id, beanRepositoryIds[0]), 804 EJBObject .class)); 805 return ejbObject; 806 } 807 catch (Exception e) { 808 throw new RuntimeException ("Unable to create reference to EJBObject\n" 809 + e); 810 } 811 } 812 813 public Collection getEntityCollection(Collection ids) 814 { 815 if (logger.isTraceEnabled()) { 816 logger.trace("entering getEntityCollection()"); 817 } 818 Collection collection = new ArrayList (ids.size()); 819 Iterator idEnum = ids.iterator(); 820 while(idEnum.hasNext()) { 821 collection.add(getEntityEJBObject(idEnum.next())); 822 } 823 if (logger.isTraceEnabled()) { 824 logger.trace("leaving getEntityCollection()"); 825 } 826 return collection; 827 } 828 829 831 834 public static String rmiRepositoryId(Class clz) 835 { 836 return "RMI:" + clz.getName() + ":0000000000000000"; 837 } 838 839 843 public static void rebind(NamingContextExt ctx, 844 String strName, org.omg.CORBA.Object obj) 845 throws Exception 846 { 847 NameComponent [] name = ctx.to_name(strName); 848 NamingContext intermediateCtx = ctx; 849 850 for (int i = 0; i < name.length - 1; i++ ) { 851 NameComponent [] relativeName = new NameComponent [] { name[i] }; 852 try { 853 intermediateCtx = NamingContextHelper.narrow( 854 intermediateCtx.resolve(relativeName)); 855 } 856 catch (NotFound e) { 857 intermediateCtx = intermediateCtx.bind_new_context(relativeName); 858 } 859 } 860 intermediateCtx.rebind(new NameComponent [] { name[name.length - 1] }, 861 obj); 862 } 863 864 868 private static String homeServantName(String jndiName) 869 { 870 return "EJBHome/" + jndiName; 871 } 872 873 877 private static String beanServantName(String jndiName) 878 { 879 return "EJBObject/" + jndiName; 880 } 881 882 } 883 | Popular Tags |