1 package org.jacorb.orb; 2 3 22 23 import java.util.*; 24 import java.io.*; 25 import java.lang.reflect.*; 26 27 import org.jacorb.imr.ImRAccessImpl; 28 import org.jacorb.util.*; 29 import org.jacorb.orb.iiop.*; 30 import org.jacorb.orb.policies.*; 31 import org.jacorb.orb.dii.Request; 32 import org.jacorb.orb.giop.*; 33 import org.jacorb.orb.portableInterceptor.*; 34 import org.jacorb.poa.util.POAUtil; 35 36 import org.apache.avalon.framework.logger.*; 37 import org.apache.avalon.framework.configuration.*; 38 39 import org.omg.CORBA.BAD_PARAM ; 40 import org.omg.CORBA.BAD_INV_ORDER ; 41 import org.omg.CORBA.INITIALIZE ; 42 import org.omg.CORBA.INTERNAL ; 43 import org.omg.CORBA.BAD_QOS ; 44 import org.omg.CORBA.TypeCode ; 45 import org.omg.CORBA.BooleanHolder ; 46 import org.omg.CORBA.ORBPackage.InvalidName ; 47 import org.omg.CORBA.portable.ValueFactory ; 48 import org.omg.CORBA.portable.BoxedValueHelper ; 49 import org.omg.CORBA.portable.StreamableValue ; 50 import org.omg.Messaging.*; 51 import org.omg.PortableInterceptor.*; 52 import org.omg.PortableServer.POAManagerPackage.AdapterInactive ; 53 import org.omg.PortableServer.POAManagerPackage.State ; 54 import org.omg.IOP.*; 55 import org.omg.IIOP.*; 56 import org.omg.ETF.*; 57 58 62 63 public final class ORB 64 extends ORBSingleton 65 implements org.jacorb.poa.POAListener, Configurable 66 { 67 private static final String versionString = org.jacorb.util.Version.version; 68 private static final String dateString = org.jacorb.util.Version.date; 69 private static final String nullIORString = 70 "IOR:00000000000000010000000000000000"; 71 72 73 private org.jacorb.config.Configuration configuration = null; 74 75 76 private boolean cacheReferences; 77 private String implName; 78 private int giopMinorVersion; 79 private boolean giopAdd_1_0_Profiles; 80 private String hashTableClassName; 81 private boolean useIMR; 82 private boolean useIMREndpoint; 83 private String imrProxyHost = null; 84 private int imrProxyPort = -1; 85 private String iorProxyHost; 86 private int iorProxyPort = -1; 87 private boolean printVersion = true; 88 89 90 private Map initial_references = new HashMap(); 91 92 private org.jacorb.poa.POA rootpoa; 93 private org.jacorb.poa.Current poaCurrent; 94 private BasicAdapter basicAdapter; 95 private org.omg.SecurityLevel2.Current securityCurrent = null; 96 97 98 private InterceptorManager interceptor_manager = null; 99 private boolean hasClientInterceptors = false; 100 private boolean hasServerInterceptors = false; 101 private org.omg.PortableInterceptor.Current piCurrent = new PICurrent(); 102 103 104 private Map knownReferences = null; 105 106 107 private ClientConnectionManager clientConnectionManager; 108 109 110 private TransportManager transport_manager = null; 111 112 private GIOPConnectionManager giop_connection_manager = null; 113 114 115 private BufferManager bufferManager; 116 117 122 protected Map valueFactories = new HashMap(); 123 124 128 protected Map boxedValueHelpers = new HashMap(); 129 130 private Map objectKeyMap = new HashMap(); 131 132 133 private java.util.Properties _props; 134 135 136 private Logger logger; 137 138 139 public String [] _args; 140 141 142 private Object orb_synch = new java.lang.Object (); 143 private boolean run = true; 144 private boolean wait = true; 145 private boolean shutdown_in_progress = false; 146 private boolean destroyed = false; 147 private Object shutdown_synch = new Object (); 148 149 150 private ImRAccess imr = null; 151 private int persistentPOACount; 152 153 public static final String orb_id = "jacorb:" + org.jacorb.util.Version.version; 154 155 156 private Set requests = Collections.synchronizedSet( new HashSet() ); 157 158 private Request request = null; 159 160 161 private org.jacorb.orb.policies.PolicyManager policyManager = null; 162 163 164 private Map policy_factories = null; 165 166 private static org.omg.CORBA.TCKind kind; 167 168 private static final String [] services = 169 {"RootPOA","POACurrent", "DynAnyFactory", "PICurrent", "CodecFactory"}; 170 171 private boolean bidir_giop = false; 172 173 174 public ORB() 175 { 176 } 177 178 181 182 public void configure(Configuration myConfiguration) 183 throws ConfigurationException 184 { 185 super.configure(myConfiguration); 186 this.configuration = 187 (org.jacorb.config.Configuration)myConfiguration; 188 logger = 189 configuration.getNamedLogger("jacorb.orb"); 190 191 cacheReferences = 192 configuration.getAttribute("jacorb.reference_caching", "off").equals("on"); 193 194 implName = 195 configuration.getAttribute("jacorb.implname", "" ); 196 197 giopMinorVersion = 198 configuration.getAttributeAsInteger("jacorb.giop_minor_version", 2); 199 200 giopAdd_1_0_Profiles = 201 configuration.getAttribute("jacorb.giop.add_1_0_profiles", "off").equals("on"); 202 203 hashTableClassName = 204 configuration.getAttribute( "jacorb.hashtable_class", "" ); 205 206 useIMR = 207 configuration.getAttribute("jacorb.use_imr","off").equals("on"); 208 209 imrProxyHost = 210 configuration.getAttribute("jacorb.imr.ior_proxy_host",null); 211 212 imrProxyPort = 213 configuration.getAttributeAsInteger("jacorb.imr.ior_proxy_port",-1); 214 215 useIMREndpoint = 216 configuration.getAttribute("jacorb.use_imr", "on").equals("on"); 217 218 iorProxyHost = 219 configuration.getAttribute("jacorb.ior_proxy_host", null); 220 221 iorProxyPort = 222 configuration.getAttributeAsInteger("jacorb.ior_proxy_port",-1); 223 224 printVersion = 225 configuration.getAttribute("jacorb.orb.print_version", "on").equals("on"); 226 227 if( printVersion && logger.isInfoEnabled()) 228 { 229 logger.info("\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + 230 "\tJacORB V " + versionString + ", www.jacorb.org\n" + 231 "\t(C) The JacORB project " + 232 dateString + "\n" + 233 "\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); 234 } 235 236 BufferManager.configure( configuration); 237 try 238 { 239 bufferManager = BufferManager.getInstance(); 240 } 241 catch( BAD_INV_ORDER b) 242 { 243 b.printStackTrace(); } 245 246 configureObjectKeyMap(configuration); 247 } 248 249 254 255 public org.jacorb.config.Configuration getConfiguration() 256 { 257 return configuration; 258 } 259 260 263 264 public String id() 265 { 266 return orb_id; 267 } 268 269 public boolean useBiDirGIOP() 270 { 271 return bidir_giop; 272 } 273 274 public void turnOnBiDirGIOP() 275 { 276 if( ! bidir_giop ) 277 { 278 bidir_giop = true; 279 280 clientConnectionManager.setRequestListener( basicAdapter.getRequestListener() ); 281 } 282 } 283 284 289 290 public synchronized org.omg.CORBA.Object _getObject( ParsedIOR pior ) 291 { 292 String key = pior.getIORString(); 293 org.omg.CORBA.portable.ObjectImpl o = 294 (org.omg.CORBA.portable.ObjectImpl )knownReferences.get( key ); 295 296 if( o != null ) 297 { 298 org.jacorb.orb.Delegate del = (org.jacorb.orb.Delegate)o._get_delegate(); 299 if (del != null) 300 { 301 ParsedIOR delpior= del.getParsedIOR(); 302 if (delpior == null) 303 { 304 knownReferences.remove(key); 305 if (logger.isDebugEnabled()) 306 { 307 logger.debug("Removing an invalid reference from cache."); 308 } 309 } 310 else if( pior.getEffectiveProfile() 311 .is_match(delpior.getEffectiveProfile())) 312 { 313 return o._duplicate(); 314 } 315 } 316 else 317 { 318 if (logger.isDebugEnabled()) 319 { 320 logger.debug("Remove stale reference from cache "); 321 } 322 knownReferences.remove( key ); 323 } 324 } 325 326 if (pior == null) 327 { 328 if (logger.isErrorEnabled()) 329 logger.error("Internal error, pior is null"); 330 } 331 332 org.jacorb.orb.Delegate d = new Delegate(this, pior ); 333 try 334 { 335 d.configure(configuration); 336 } 337 catch(ConfigurationException ce) 338 { 339 if (logger.isErrorEnabled()) 340 logger.error("ConfigurationException", ce); 341 } 342 343 o = d.getReference( null ); 344 345 if( cacheReferences ) 346 { 347 knownReferences.put( key, o ); 348 } 349 return o; 350 } 351 352 358 359 org.jacorb.poa.POA findPOA( org.jacorb.orb.Delegate d, 360 org.omg.CORBA.Object ref ) 361 { 362 List scopes; 363 String res; 364 String refImplName = null; 365 366 if( rootpoa == null || basicAdapter == null ) 368 { 369 return null; 370 } 371 372 374 try 375 { 376 refImplName = 377 org.jacorb.poa.util.POAUtil.extractImplName( d.getObjectKey() ); 378 } 379 catch( org.jacorb.poa.except.POAInternalError pie ) 380 { 381 if( logger.isDebugEnabled() ) 382 { 383 logger.debug("findPOA: reference generated by foreign POA"); 384 } 385 return null; 386 } 387 388 if( refImplName == null ) 389 { 390 if( implName.length() > 0 ) 391 { 392 if( logger.isDebugEnabled() ) 393 { 394 logger.debug("findPOA: impl_name mismatch"); 395 } 396 return null; 397 } 398 } 399 else 400 { 401 if( !(implName.equals( refImplName ) )) 402 { 403 if( logger.isDebugEnabled() ) 404 { 405 logger.debug("findPOA: impl_name mismatch"); 406 } 407 return null; 408 } 409 } 410 411 412 try 413 { 414 org.jacorb.poa.POA tmp_poa = (org.jacorb.poa.POA)rootpoa; 415 String poa_name = 416 org.jacorb.poa.util.POAUtil.extractPOAName( d.getObjectKey() ); 417 418 421 scopes = POAUtil.extractScopedPOANames (poa_name); 422 423 for( int i = 0; i < scopes.size(); i++) 424 { 425 res = ((String )scopes.get( i )); 426 427 if( res.equals ("")) 428 break; 429 430 443 444 try 445 { 446 tmp_poa = tmp_poa._getChildPOA( res ); 447 } 448 catch ( org.jacorb.poa.except.ParentIsHolding p ) 449 { 450 if( logger.isDebugEnabled() ) 451 { 452 logger.debug("findPOA: holding adapter"); 453 } 454 return null; 455 } 456 } 457 byte[] objectId = 458 org.jacorb.poa.util.POAUtil.extractOID( ref ); 459 460 if( tmp_poa.isSystemId() 461 && ! tmp_poa.previouslyGeneratedObjectId(objectId)) 462 { 463 if( logger.isDebugEnabled() ) 464 { 465 logger.debug("findPOA: not a previously generated object key."); 466 } 467 return null; 468 } 469 470 return tmp_poa; 471 } 472 catch( Exception e ) 473 { 474 if( logger.isErrorEnabled() ) 475 { 476 logger.error(e.getMessage()); 477 } 478 } 479 480 if( logger.isDebugEnabled() ) 481 { 482 logger.debug("findPOA: nothing found"); 483 } 484 return null; 485 } 486 487 488 public ClientConnectionManager getClientConnectionManager() 489 { 490 return clientConnectionManager; 491 } 492 493 public GIOPConnectionManager getGIOPConnectionManager() 494 { 495 if (giop_connection_manager == null) 496 { 497 giop_connection_manager = 498 new GIOPConnectionManager(); 499 try 500 { 501 giop_connection_manager.configure(configuration); 502 } 503 catch( ConfigurationException ce ) 504 { 505 throw new INTERNAL (ce.getMessage()); 506 } 507 } 508 return giop_connection_manager; 509 } 510 511 512 516 synchronized void _release( String iorString ) 517 { 518 knownReferences.remove( iorString ); 519 } 520 521 522 532 533 public org.omg.CORBA.Policy create_policy( int type, org.omg.CORBA.Any value ) 534 throws org.omg.CORBA.PolicyError 535 { 536 switch (type) 537 { 538 case MAX_HOPS_POLICY_TYPE.value: 539 return new 540 org.jacorb.orb.policies.MaxHopsPolicy (value); 541 case QUEUE_ORDER_POLICY_TYPE.value: 542 return new 543 org.jacorb.orb.policies.QueueOrderPolicy (value); 544 case REBIND_POLICY_TYPE.value: 545 return new 546 org.jacorb.orb.policies.RebindPolicy (value); 547 case RELATIVE_REQ_TIMEOUT_POLICY_TYPE.value: 548 return new 549 org.jacorb.orb.policies.RelativeRequestTimeoutPolicy (value); 550 case RELATIVE_RT_TIMEOUT_POLICY_TYPE.value: 551 return new 552 org.jacorb.orb.policies.RelativeRoundtripTimeoutPolicy (value); 553 case REPLY_END_TIME_POLICY_TYPE.value: 554 return new 555 org.jacorb.orb.policies.ReplyEndTimePolicy (value); 556 case REPLY_PRIORITY_POLICY_TYPE.value: 557 return new 558 org.jacorb.orb.policies.ReplyPriorityPolicy (value); 559 case REPLY_START_TIME_POLICY_TYPE.value: 560 return new 561 org.jacorb.orb.policies.ReplyStartTimePolicy (value); 562 case REQUEST_END_TIME_POLICY_TYPE.value: 563 return new 564 org.jacorb.orb.policies.RequestEndTimePolicy (value); 565 case REQUEST_PRIORITY_POLICY_TYPE.value: 566 return new 567 org.jacorb.orb.policies.RequestPriorityPolicy (value); 568 case REQUEST_START_TIME_POLICY_TYPE.value: 569 return new 570 org.jacorb.orb.policies.RequestStartTimePolicy (value); 571 case ROUTING_POLICY_TYPE.value: 572 return new 573 org.jacorb.orb.policies.RoutingPolicy (value); 574 case SYNC_SCOPE_POLICY_TYPE.value: 575 return new 576 org.jacorb.orb.policies.SyncScopePolicy (value); 577 default: 578 Integer key = new Integer (type); 579 if ( policy_factories == null || 580 (! policy_factories.containsKey(key)) ) 581 throw new org.omg.CORBA.PolicyError (); 582 PolicyFactory factory = 583 (PolicyFactory)policy_factories.get(key); 584 return factory.create_policy(type, value); 585 } 586 } 587 588 589 592 public boolean hasPolicyFactoryForType(int type) 593 { 594 return (policy_factories != null && 595 policy_factories.containsKey( new Integer (type)) ); 596 } 597 598 public org.omg.CORBA.ContextList create_context_list() 599 { 600 throw new org.omg.CORBA.NO_IMPLEMENT (); 601 } 602 603 public org.omg.CORBA.Environment create_environment() 604 { 605 throw new org.omg.CORBA.NO_IMPLEMENT (); 606 } 607 608 public org.omg.CORBA.portable.OutputStream create_output_stream() 609 { 610 return new CDROutputStream(this); 611 } 612 613 org.omg.IOP.IOR createIOR(String repId, 614 byte[] objectKey, 615 boolean _transient, 616 org.jacorb.poa.POA poa, 617 Map policy_overrides) 618 { 619 List profiles = new ArrayList(); 620 Map componentMap = new HashMap(); 621 int[] profileTags = new int[basicAdapter.getEndpointProfiles().size()]; 622 int n = 0; 623 for (Iterator i = basicAdapter.getEndpointProfiles().iterator(); 624 i.hasNext();) 625 { 626 Profile profile = (Profile)i.next(); 627 profile.set_object_key (objectKey); 628 profiles.add (profile); 629 profileTags[n++] = profile.tag(); 630 631 TaggedComponentList profileComponents = new TaggedComponentList(); 632 profileComponents.addComponent(create_ORB_TYPE_ID()); 633 componentMap.put(new Integer (profile.tag()), profileComponents); 634 635 if (profile instanceof IIOPProfile) 636 { 637 patchAddress((IIOPProfile)profile, repId, _transient); 639 640 if (poa.isSSLRequired()) 642 { 643 ((IIOPProfile)profile).patchPrimaryAddress(null, 0); 644 } 645 } 646 647 } 648 649 TaggedComponentList multipleComponents = new TaggedComponentList(); 650 componentMap.put (new Integer (TAG_MULTIPLE_COMPONENTS.value), 651 multipleComponents); 652 653 if ((interceptor_manager != null) && 655 interceptor_manager.hasIORInterceptors()) 656 { 657 IORInfoImpl info = new IORInfoImpl(this, poa, 658 componentMap, 659 policy_overrides, 660 profiles); 661 interceptor_manager.setProfileTags(profileTags); 662 try 663 { 664 interceptor_manager.getIORIterator().iterate( info ); 665 } 666 catch (Exception e) 667 { 668 if (logger.isErrorEnabled()) 669 logger.error(e.getMessage()); 670 } 671 } 672 673 IIOPProfile iiopProfile = findIIOPProfile(profiles); 675 if ( (iiopProfile != null) 676 && ( this.giopMinorVersion == 0 || this.giopAdd_1_0_Profiles )) 677 { 680 Profile profile_1_0 = iiopProfile.to_GIOP_1_0(); 681 profiles.add(profile_1_0); 682 683 TaggedComponentList iiopComponents = 685 (TaggedComponentList)componentMap.get(new Integer (TAG_INTERNET_IOP.value)); 686 687 multipleComponents.addAll(iiopProfile.getComponents()); 688 multipleComponents.addAll(iiopComponents); 689 690 if (giopMinorVersion == 0) 692 { 693 profiles.remove(iiopProfile); 694 } 695 } 696 697 TaggedProfile[] tps = null; 699 if (multipleComponents.isEmpty()) 700 { 701 tps = new TaggedProfile [profiles.size()]; 702 } 703 else 704 { 705 tps = new TaggedProfile [profiles.size() + 1]; 706 tps[tps.length-1] = 707 createMultipleComponentsProfile(multipleComponents); 708 } 709 710 TaggedProfileHolder tp = new TaggedProfileHolder(); 711 TaggedComponentSeqHolder tc = new TaggedComponentSeqHolder(); 712 for (int i=0; i<profiles.size(); i++) 713 { 714 Profile p = (Profile)profiles.get(i); 715 TaggedComponentList c = 716 (TaggedComponentList)componentMap.get (new Integer (p.tag())); 717 tc.value = c.asArray(); 718 p.marshal (tp, tc); 719 tps[i] = tp.value; 720 } 721 722 return new IOR(repId, tps); 723 } 724 725 private TaggedProfile createMultipleComponentsProfile 726 (TaggedComponentList components) 727 { 728 CDROutputStream out = new CDROutputStream(this); 729 out.beginEncapsulatedArray(); 730 MultipleComponentProfileHelper.write(out, components.asArray()); 731 return new TaggedProfile 732 ( 733 TAG_MULTIPLE_COMPONENTS.value, 734 out.getBufferCopy() 735 ); 736 } 737 738 743 private IIOPProfile findIIOPProfile (List profiles) 744 { 745 for (Iterator i = profiles.iterator(); i.hasNext();) 746 { 747 Profile p = (Profile)i.next(); 748 if (p instanceof IIOPProfile) 749 return (IIOPProfile)p; 750 } 751 return null; 752 } 753 754 public org.omg.CORBA.Context get_default_context () 755 { 756 throw new org.omg.CORBA.NO_IMPLEMENT (); 757 } 758 759 760 764 public org.jacorb.orb.BasicAdapter getBasicAdapter() 765 { 766 if( basicAdapter == null ) 767 throw new INITIALIZE ("Adapters not initialized; resolve RootPOA."); 768 return basicAdapter; 769 } 770 771 772 775 776 public org.jacorb.poa.Current getPOACurrent() 777 { 778 if (poaCurrent == null) 779 { 780 poaCurrent = org.jacorb.poa.Current._Current_init(); 781 } 782 return poaCurrent; 783 } 784 785 794 public org.omg.CORBA.Object getReference( org.jacorb.poa.POA poa, 795 byte[] object_key, 796 String rep_id, 797 boolean _transient ) 798 { 799 if( rep_id == null ) 800 rep_id = "IDL:omg.org/CORBA/Object:1.0"; 801 802 org.omg.IOP.IOR ior = 803 createIOR( rep_id, object_key, _transient, poa, null ); 804 805 if (ior == null) 806 { 807 if (logger.isErrorEnabled()) 808 logger.error("Interal error: createIOR returns null"); 809 } 810 811 Delegate d = new Delegate( this, ior ); 812 try 813 { 814 d.configure(configuration); 815 } 816 catch(ConfigurationException ce) 817 { 818 if (logger.isErrorEnabled()) 819 logger.error(ce.getMessage(), ce); 820 } 821 return d.getReference( poa ); 822 } 823 824 public org.jacorb.poa.POA getRootPOA() 825 throws org.omg.CORBA.INITIALIZE 826 { 827 if( rootpoa == null ) 828 { 829 rootpoa = org.jacorb.poa.POA._POA_init(this); 830 831 basicAdapter = new BasicAdapter( this, 832 rootpoa, 833 getTransportManager(), 834 getGIOPConnectionManager() ); 835 836 try 837 { 838 basicAdapter.configure(configuration); 839 rootpoa.configure(configuration); 840 } 841 catch( ConfigurationException ce ) 842 { 843 throw new org.omg.CORBA.INITIALIZE ("ConfigurationException: " + 844 ce.getMessage() ); 845 } 846 rootpoa._addPOAEventListener( this ); 847 848 } 849 return rootpoa; 850 } 851 852 public String [] list_initial_services() 853 { 854 List l = new ArrayList(); 855 856 for( Iterator e = initial_references.keySet().iterator(); 857 e.hasNext(); l.add( e.next() ) ); 858 859 String [] initial_services = 860 new String [ services.length + l.size()]; 861 862 l.toArray( initial_services ); 863 864 System.arraycopy( services, 0, initial_services, l.size(), services.length ); 865 return initial_services; 866 } 867 868 872 873 public void poaCreated( org.jacorb.poa.POA poa ) 874 { 875 879 poa._addPOAEventListener( this ); 880 881 885 886 if( poa.isPersistent() ) 887 { 888 persistentPOACount++; 889 890 getImR (); 891 892 if( imr != null ) 893 { 894 895 String server_name = implName; 896 897 imr.registerPOA( server_name + "/" + poa._getQualifiedName(), 898 server_name, getServerAddress(), 900 getServerPort() ); 901 } 902 } 903 } 904 905 906 private void getImR () 907 { 908 909 if( imr == null && useIMR ) 910 { 911 try 912 { 913 imr = ImRAccessImpl.connect (this); 914 } 915 catch( Exception e ) 916 { 917 if (logger.isWarnEnabled()) 919 { 920 logger.warn("Error: No connection to ImplementationRepository"); 921 } 922 if (logger.isDebugEnabled()) 923 { 924 logger.debug(e.getMessage()); 925 } 926 927 if( e instanceof org.omg.CORBA.INTERNAL ) 928 { 929 throw new org.omg.CORBA.OBJ_ADAPTER ("Unable to resolve ImR"); 930 } 931 else if (e instanceof org.omg.CORBA.TRANSIENT ) 932 { 933 throw (org.omg.CORBA.TRANSIENT )e; 934 } 935 else 936 { 937 throw new org.omg.CORBA.OBJ_ADAPTER ( e.toString() ); 938 } 939 } 940 } 941 } 942 943 946 private void patchAddress(IIOPProfile profile, 947 String repId, 948 boolean _transient) 949 { 950 if (repId.equals ("IDL:org/jacorb/imr/ImplementationRepository:1.0")) 951 { 952 profile.patchPrimaryAddress(imrProxyHost,imrProxyPort); 953 } 954 else if (!_transient 955 && useIMR 956 && useIMREndpoint ) 957 { 958 getImR(); 959 960 profile.patchPrimaryAddress(imr.getImRHost(), imr.getImRPort()); 964 profile.patchPrimaryAddress(imrProxyHost, imrProxyPort); 965 } 966 else 967 { 968 profile.patchPrimaryAddress(iorProxyHost, iorProxyPort); 969 } 970 } 971 972 975 private TaggedComponent create_ORB_TYPE_ID() 976 { 977 CDROutputStream orbIDComponentDataStream = new CDROutputStream( this ); 978 orbIDComponentDataStream.beginEncapsulatedArray(); 979 orbIDComponentDataStream.write_long( ORBConstants.JACORB_ORB_ID ); 980 981 return new TaggedComponent 982 ( 983 TAG_ORB_TYPE.value, 984 orbIDComponentDataStream.getBufferCopy() 985 ); 986 } 987 988 989 997 private String getServerAddress() 998 { 999 String address = iorProxyHost; 1000 1001 if( address == null ) 1002 { 1003 address = getBasicAdapter().getAddress(); 1005 } 1006 else 1007 { 1008 if (logger.isInfoEnabled()) 1009 { 1010 logger.info("Using proxy host " + address + " in IOR" ); 1011 } 1012 } 1013 1014 return address; 1015 } 1016 1017 1018 1026 private int getServerPort() 1027 { 1028 int port = -1; 1029 1030 if( iorProxyPort != -1 ) 1031 { 1032 port = iorProxyPort; 1033 1034 if( port < 0 ) 1035 { 1036 throw new BAD_QOS ( "Negative port numbers are not allowed! " + 1037 "(check property \"jacorb.ior_proxy_port\")" ); 1038 } 1039 1040 if (logger.isInfoEnabled()) 1041 { 1042 logger.info("Using proxy port " + port + " in IOR" ); 1043 } 1044 } 1045 else 1046 { 1047 port = getBasicAdapter().getPort(); 1049 } 1050 1051 return port; 1052 } 1053 1054 1060 private String getIMRAddressForIOR(String imrAddress) 1061 { 1062 return (imrProxyHost == null ? imrAddress : imrProxyHost); 1063 } 1064 1065 1071 private int getIMRPortForIOR(int imrPort) 1072 { 1073 return imrProxyPort; 1074 } 1075 1076 public void poaStateChanged(org.jacorb.poa.POA poa, int new_state) 1077 { 1078 if( ( new_state == org.jacorb.poa.POAConstants.DESTROYED || 1079 new_state == org.jacorb.poa.POAConstants.INACTIVE ) && 1080 poa.isPersistent() && imr != null 1081 ) 1082 { 1083 1085 if( --persistentPOACount == 0 ) 1086 { 1087 imr.setServerDown(implName); 1088 } 1089 } 1090 } 1091 1092 1093 public void referenceCreated(org.omg.CORBA.Object o) {} 1094 1095 public boolean get_service_information( short service_type, 1096 org.omg.CORBA.ServiceInformationHolder service_information) 1097 { 1098 throw new org.omg.CORBA.NO_IMPLEMENT (); 1115 } 1116 1117 1120 1121 public org.omg.CORBA.Object resolve_initial_references(String identifier) 1122 throws org.omg.CORBA.ORBPackage.InvalidName 1123 { 1124 if ( initial_references.containsKey(identifier) ) 1125 { 1126 return (org.omg.CORBA.Object )initial_references.get(identifier); 1127 } 1128 else 1129 { 1130 org.omg.CORBA.Object obj = null; 1131 String url = null; 1132 1133 try 1134 { 1135 url = 1136 configuration.getAttribute("ORBInitRef." + identifier); 1137 } 1138 catch( Exception e ) 1139 { 1140 } 1142 1143 if( url != null ) 1144 { 1145 try 1146 { 1147 obj = this.string_to_object( url ); 1148 } 1149 catch( Exception e ) 1150 { 1151 if (logger.isErrorEnabled()) 1152 { 1153 logger.error( "Could not create initial reference for \"" + 1154 identifier + "\"\n" + 1155 "Please check property \"ORBInitRef." + 1156 identifier + '\"' ); 1157 } 1158 if (logger.isDebugEnabled()) 1159 { 1160 logger.debug( e.getMessage() ); 1161 } 1162 1163 throw new org.omg.CORBA.ORBPackage.InvalidName (); 1164 } 1165 } 1166 else if( identifier.equals("RootPOA") ) 1167 { 1168 return (org.omg.CORBA.Object )getRootPOA(); 1169 } 1170 else if( identifier.equals("POACurrent") ) 1171 { 1172 return (org.omg.CORBA.Object )getPOACurrent(); 1173 } 1174 else if( identifier.equals("SecurityCurrent") ) 1175 { 1176 if( securityCurrent == null ) 1177 { 1178 try 1179 { 1180 Class currentClass = 1181 ObjectUtil.classForName( "org.jacorb.security.level2.CurrentImpl" ); 1182 1183 Constructor constr = 1184 currentClass.getConstructor( new Class []{ org.omg.CORBA.ORB .class }); 1185 1186 securityCurrent = 1187 (org.omg.SecurityLevel2.Current)constr.newInstance( new Object []{ this }); 1188 1189 Method configureMethod = 1190 currentClass.getDeclaredMethod( "configure", 1191 new Class []{ Configuration.class } ); 1192 1193 configureMethod.invoke( securityCurrent, new Object []{ configuration }); 1194 1195 Method init = 1196 currentClass.getDeclaredMethod( "init", new Class [0] ); 1197 1198 init.invoke( securityCurrent, new Object [0] ); 1199 } 1200 catch (Exception e) 1201 { 1202 if (logger.isWarnEnabled()) 1203 { 1204 logger.warn("Exception",e); 1205 } 1206 } 1207 } 1208 1209 obj = securityCurrent; 1210 } 1211 else if( identifier.equals("DynAnyFactory") ) 1212 { 1213 obj = new org.jacorb.orb.dynany.DynAnyFactoryImpl( this ); 1214 } 1215 else if( identifier.equals("PICurrent") ) 1216 { 1217 return piCurrent; 1218 } 1219 else if( identifier.equals("ORBPolicyManager") ) 1220 { 1221 return getPolicyManager(); 1222 } 1223 else if( identifier.equals("CodecFactory") ) 1224 { 1225 obj = new CodecFactoryImpl(this); 1226 } 1227 else 1228 { 1229 throw new org.omg.CORBA.ORBPackage.InvalidName (); 1230 } 1231 1232 if (obj != null) 1233 { 1234 initial_references.put (identifier, obj); 1235 } 1236 1237 return obj; 1238 } 1239 } 1240 1241 PolicyManager getPolicyManager() 1242 { 1243 return policyManager; 1244 } 1245 1246 1258 1259 public void register_initial_reference( String id, org.omg.CORBA.Object obj ) 1260 throws InvalidName 1261 { 1262 if (id == null || id.length() == 0 || 1263 initial_references.containsKey(id) ) 1264 { 1265 throw new InvalidName (); 1266 } 1267 else 1268 { 1269 if (logger.isDebugEnabled()) 1270 { 1271 logger.debug( "Registering initial ref " + id ); 1272 } 1273 initial_references.put(id, obj); 1274 } 1275 } 1276 1277 public void run() 1278 { 1279 if (logger.isInfoEnabled()) 1280 { 1281 logger.info("ORB run"); 1282 } 1283 1284 try 1285 { 1286 synchronized( orb_synch ) 1287 { 1288 while( run ) 1289 { 1290 orb_synch.wait(); 1291 } 1292 } 1293 } 1294 catch (InterruptedException ex) 1295 { 1296 } 1297 if (logger.isInfoEnabled()) 1298 { 1299 logger.info("ORB run, exit"); 1300 } 1301 } 1302 1303 1304 public void send_multiple_requests_oneway( org.omg.CORBA.Request [] req ) 1305 { 1306 for( int i = 0; i < req.length; i++ ) 1307 { 1308 req[i].send_oneway(); 1309 } 1310 } 1311 1312 public void send_multiple_requests_deferred( org.omg.CORBA.Request [] req ) 1313 { 1314 for( int i = 0; i < req.length; i++ ) 1315 { 1316 req[i].send_deferred(); 1317 } 1318 } 1319 1320 public boolean poll_next_response() 1321 { 1322 if( requests.size () == 0 ) 1323 { 1324 throw new org.omg.CORBA.BAD_INV_ORDER 1325 ( 11, org.omg.CORBA.CompletionStatus.COMPLETED_NO ); 1326 } 1327 1328 synchronized( requests ) 1329 { 1330 Request req; 1331 Iterator iter = requests.iterator(); 1332 while( iter.hasNext() ) 1333 { 1334 req = (Request)iter.next(); 1335 if( req.poll_response() ) 1336 { 1337 request = req; 1338 return true; 1339 } 1340 } 1341 } 1342 return false; 1343 } 1344 1345 public org.omg.CORBA.Request get_next_response () 1346 { 1347 if( requests.size () == 0 ) 1348 { 1349 throw new org.omg.CORBA.BAD_INV_ORDER 1350 ( 11, org.omg.CORBA.CompletionStatus.COMPLETED_NO ); 1351 } 1352 1353 synchronized( requests ) 1354 { 1355 Request req = null; 1356 if( request != null ) 1357 { 1358 request.get_response(); 1359 req = request; 1360 request = null; 1361 return req; 1362 } 1363 1364 Iterator iter; 1365 while( true ) 1366 { 1367 iter = requests.iterator(); 1368 while( iter.hasNext() ) 1369 { 1370 req = (Request)iter.next(); 1371 if( req.poll_response() ) 1372 { 1373 req.get_response(); 1374 return req; 1375 } 1376 } 1377 } 1378 } 1379 } 1380 1381 public void addRequest( org.omg.CORBA.Request req ) 1382 { 1383 requests.add( req ); 1384 } 1385 1386 public void removeRequest( org.omg.CORBA.Request req ) 1387 { 1388 requests.remove( req ); 1389 } 1390 1391 1392 1395 1396 protected void set_parameters(String [] args, java.util.Properties props) 1397 { 1398 _props = props; 1399 1400 try 1401 { 1402 configure( org.jacorb.config.Configuration.getConfiguration(props, 1403 this, 1404 false)); } 1406 catch( ConfigurationException ce ) 1407 { 1408 if ( logger != null && logger.isErrorEnabled()) 1409 { 1410 logger.error( ce.getMessage()); 1411 } 1412 else 1413 ce.printStackTrace(); 1414 1415 throw new org.omg.CORBA.INITIALIZE ( ce.getMessage() ); 1416 } 1417 1418 1422 1423 if( args != null ) 1424 { 1425 _args = args; 1426 for( int i = 0; i < args.length; i++ ) 1427 { 1428 String arg = args[ i ].trim(); 1429 1430 if( arg.startsWith( "-ORBInitRef." )) 1431 { 1432 1434 String prop = arg.substring( 1 ); 1436 1437 int equals_pos = prop.indexOf( '=' ); 1440 if ( equals_pos == -1 ) 1441 { 1442 throw new org.omg.CORBA.BAD_PARAM ( "InitRef format invalid for " + prop ); 1443 } 1444 1445 ((DefaultConfiguration)configuration).setAttribute( prop.substring( 0, equals_pos ), 1447 prop.substring( equals_pos + 1) ); 1448 } 1449 else if( arg.equals( "-ORBInitRef" )) 1450 { 1451 1453 if( (args.length - 1) < (i + 1) ) 1455 { 1456 if (logger.isWarnEnabled()) 1457 { 1458 logger.warn( "WARNING: -ORBInitRef argument without value" ); 1459 } 1460 continue; 1461 } 1462 1463 String prop = args[ ++i ].trim(); 1464 1465 int equals_pos = prop.indexOf( '=' ); 1468 if ( equals_pos == -1 ) 1469 { 1470 throw new org.omg.CORBA.BAD_PARAM ( "InitRef format invalid for " + prop ); 1471 } 1472 1473 ((DefaultConfiguration)configuration).setAttribute( "ORBInitRef." + 1475 prop.substring( 0, equals_pos ), 1476 prop.substring( equals_pos + 1) ); 1477 } 1478 } 1479 } 1480 1481 internalInit(); 1482 } 1483 1484 1488 1489 protected void set_parameters(java.applet.Applet app, 1490 java.util.Properties props) 1491 { 1492 _props = props; 1493 1494 try 1495 { 1496 configure( org.jacorb.config.Configuration.getConfiguration(props, 1497 this, 1498 true)); } 1500 catch( ConfigurationException ce ) 1501 { 1502 if (logger.isErrorEnabled()) 1503 { 1504 logger.error( ce.getMessage()); 1505 } 1506 throw new org.omg.CORBA.INITIALIZE ( ce.getMessage() ); 1507 } 1508 1509 internalInit(); 1510 } 1511 1512 private void internalInit() 1513 { 1514 policyManager = new PolicyManager( this ); 1515 1516 try 1517 { 1518 clientConnectionManager = 1519 new ClientConnectionManager( this, 1520 getTransportManager(), 1521 getGIOPConnectionManager()); 1522 clientConnectionManager.configure(configuration); 1523 } 1524 catch( ConfigurationException ce ) 1525 { 1526 if (logger.isErrorEnabled()) 1527 logger.error(ce.getMessage()); 1528 } 1529 1530 1531 if( hashTableClassName == null || hashTableClassName.length() == 0 ) 1533 { 1534 if (logger.isInfoEnabled()) 1535 { 1536 logger.info("Property \"jacorb.hashtable_class\" not present. Will use default hashtable implementation" ); 1537 } 1538 knownReferences = new HashMap(); 1539 } 1540 else 1541 { 1542 try 1543 { 1544 knownReferences = 1545 (Map)ObjectUtil.classForName( hashTableClassName ).newInstance(); 1546 } 1547 catch( Exception e ) 1548 { 1549 if (logger.isInfoEnabled()) 1550 { 1551 logger.info(e.getMessage()); 1552 } 1553 knownReferences = new HashMap(); 1554 } 1555 } 1556 1557 interceptorInit(); 1558 } 1559 1563 1564 private void interceptorInit() 1565 { 1566 Vector orb_initializers = getORBInitializers(); 1567 1568 if (orb_initializers.size () > 0) 1569 { 1570 ORBInitInfoImpl info = new ORBInitInfoImpl (this); 1571 ORBInitializer init; 1572 1573 for (int i = 0; i < orb_initializers.size(); i++) 1575 { 1576 try 1577 { 1578 init = (ORBInitializer) orb_initializers.elementAt (i); 1579 init.pre_init (info); 1580 } 1581 catch (Exception e) 1582 { 1583 if (logger.isWarnEnabled()) 1584 { 1585 logger.warn( e.getMessage()); 1586 } 1587 } 1588 } 1589 1590 for (int i = 0; i < orb_initializers.size (); i++) 1592 { 1593 try 1594 { 1595 init = (ORBInitializer) orb_initializers.elementAt (i); 1596 init.post_init (info); 1597 } 1598 catch (Exception e) 1599 { 1600 if (logger.isWarnEnabled()) 1601 { 1602 logger.warn( e.getMessage()); 1603 } 1604 } 1605 } 1606 1607 info.setInvalid (); 1609 1610 Vector client_interceptors = info.getClientInterceptors (); 1611 Vector server_interceptors = info.getServerInterceptors (); 1612 Vector ior_intercept = info.getIORInterceptors (); 1613 1614 hasClientInterceptors = (client_interceptors.size () > 0); 1615 hasServerInterceptors = (server_interceptors.size () > 0); 1616 1617 if (hasClientInterceptors || hasServerInterceptors || (ior_intercept.size () > 0)) 1618 { 1619 interceptor_manager = new InterceptorManager 1620 ( 1621 client_interceptors, 1622 server_interceptors, 1623 ior_intercept, 1624 info.getSlotCount (), 1625 this 1626 ); 1627 } 1628 1629 policy_factories = info.getPolicyFactories(); 1631 } 1632 } 1633 1634 1635 1641 1642 private Vector getORBInitializers() 1643 { 1644 String [] prop_names = configuration.getAttributeNames(); 1645 Vector orb_initializers = new Vector(); 1646 1647 String initializer_prefix = 1648 "org.omg.PortableInterceptor.ORBInitializerClass."; 1649 1650 for(int i = 0; i < prop_names.length; i++) 1652 { 1653 if ( prop_names[i].startsWith( initializer_prefix )) 1654 { 1655 String name = null; 1656 name = configuration.getAttribute( prop_names[i], "" ); 1659 1665 if( name.length() == 0 ) 1666 { 1667 if( prop_names[i].length() > initializer_prefix.length() ) 1668 { 1669 name = 1670 prop_names[i].substring( initializer_prefix.length() ); 1671 } 1672 } 1673 1674 if( name == null ) 1675 { 1676 continue; 1677 } 1678 1679 try 1680 { 1681 orb_initializers.addElement(ObjectUtil.classForName(name).newInstance()); 1682 if( logger.isDebugEnabled()) 1683 logger.debug("Build: " + name); 1684 } 1685 catch (Exception e) 1686 { 1687 if( logger.isDebugEnabled()) 1688 logger.debug( "Unable to build ORBInitializer from >>" + 1689 name + "<<" ); 1690 } 1691 } 1692 } 1693 1694 return orb_initializers; 1695 } 1696 1697 1698 1699 1700 public void shutdown( boolean wait_for_completion ) 1701 { 1702 if (logger.isInfoEnabled()) 1703 { 1704 logger.info("prepare ORB for shutdown..."); 1705 } 1706 1707 if( ! run ) 1708 { 1709 return; } 1711 1712 synchronized( shutdown_synch ) 1713 { 1714 if (logger.isInfoEnabled()) 1715 { 1716 logger.info("ORB going down..."); 1717 } 1718 1719 if( shutdown_in_progress && wait_for_completion ) 1720 { 1721 synchronized( shutdown_synch ) 1722 { 1723 try 1724 { 1725 shutdown_synch.wait(); 1726 } 1727 catch( InterruptedException ie ) 1728 {} 1729 1730 if (logger.isDebugEnabled()) 1731 { 1732 logger.debug("ORB going shutdown complete (1)"); 1733 } 1734 1735 return; 1736 } 1737 } 1738 else if( shutdown_in_progress && !wait_for_completion ) 1739 { 1740 if (logger.isDebugEnabled()) 1741 { 1742 logger.debug("ORB going shutdown complete (2)"); 1743 } 1744 return; 1745 } 1746 1747 shutdown_in_progress = true; 1748 } 1749 1750 if( rootpoa != null ) 1751 rootpoa.destroy(true, wait_for_completion); 1752 1753 if( basicAdapter != null ) 1754 { 1755 basicAdapter.stopListeners(); 1756 } 1757 1758 if (logger.isDebugEnabled()) 1759 { 1760 logger.debug("ORB going shutdown (cleaning up ORB...)"); 1761 } 1762 1763 clientConnectionManager.shutdown(); 1764 knownReferences.clear(); 1765 bufferManager.release(); 1766 1767 1768 1769 synchronized( shutdown_synch ) 1770 { 1771 shutdown_synch.notifyAll(); 1772 } 1773 1774 1775 synchronized( orb_synch ) 1776 { 1777 run = false; 1778 orb_synch.notifyAll(); 1779 } 1780 if (logger.isInfoEnabled()) 1781 { 1782 logger.info("ORB shutdown complete"); 1783 } 1784 } 1785 1786 public void destroy() 1787 { 1788 if( destroyed ) 1789 throw new org.omg.CORBA.OBJECT_NOT_EXIST (); 1790 1791 if( run ) 1792 { 1793 shutdown( true ); 1794 } 1795 1796 if( interceptor_manager != null ) 1797 { 1798 interceptor_manager.destroy(); 1799 } 1800 1801 destroyed = true; 1803 } 1804 1805 public org.omg.CORBA.Object string_to_object (String str) 1806 { 1807 if (str == null) 1808 { 1809 return null; 1810 } 1811 1812 try 1813 { 1814 ParsedIOR pior = new ParsedIOR( str, this, logger ); 1815 if( pior.isNull() ) 1816 { 1817 return null; 1818 } 1819 else 1820 { 1821 return _getObject(pior); 1822 } 1823 } 1824 catch (IllegalArgumentException iae) 1825 { 1826 if (logger.isDebugEnabled()) 1827 { 1828 logger.debug(iae.getMessage()); 1829 } 1830 return null; 1831 } 1832 } 1833 1834 1837 1838 public org.omg.CORBA.Object get_value_def(String repid) 1839 throws org.omg.CORBA.BAD_PARAM 1840 { 1841 throw new org.omg.CORBA.NO_IMPLEMENT (); 1842 } 1843 1844 1847 1848 public void set_delegate( java.lang.Object wrapper ) 1849 { 1850 if( ! (wrapper instanceof org.omg.PortableServer.Servant ) ) 1851 throw new org.omg.CORBA.BAD_PARAM ("Argument must be of type org.omg.PortableServer.Servant"); 1852 else 1853 { 1854 try 1855 { 1856 ((org.omg.PortableServer.Servant )wrapper)._get_delegate(); 1857 } 1858 catch( org.omg.CORBA.BAD_INV_ORDER bio ) 1859 { 1860 org.jacorb.orb.ServantDelegate delegate = 1862 new org.jacorb.orb.ServantDelegate( this ); 1863 ((org.omg.PortableServer.Servant )wrapper)._set_delegate(delegate); 1864 } 1865 } 1866 } 1867 1868 1869 public String object_to_string( org.omg.CORBA.Object obj) 1870 { 1871 if (obj == null) 1872 { 1873 return nullIORString; 1874 } 1875 1876 if (obj instanceof org.omg.CORBA.LocalObject ) 1877 { 1878 throw new org.omg.CORBA.MARSHAL ("Attempt to stringify a local object"); 1879 } 1880 1881 Object delegate = 1882 ((org.omg.CORBA.portable.ObjectImpl )obj)._get_delegate(); 1883 if (delegate instanceof org.jacorb.orb.Delegate) 1884 return delegate.toString(); 1885 else 1886 throw new BAD_PARAM ("Argument has a delegate whose class is " 1887 + delegate.getClass().getName() 1888 + ", a org.jacorb.orb.Delegate was expected"); 1889 } 1890 1891 public void perform_work () 1892 { 1893 if (! run) 1894 { 1895 throw new org.omg.CORBA.BAD_INV_ORDER 1896 (4, org.omg.CORBA.CompletionStatus.COMPLETED_NO); 1897 } 1898 } 1899 1900 public boolean work_pending () 1901 { 1902 if (! run) 1903 { 1904 throw new org.omg.CORBA.BAD_INV_ORDER 1905 (4, org.omg.CORBA.CompletionStatus.COMPLETED_NO); 1906 } 1907 1908 return false; 1909 } 1910 1911 public ValueFactory register_value_factory(String id, 1912 ValueFactory factory) 1913 { 1914 return (ValueFactory )valueFactories.put (id, factory); 1915 } 1916 1917 public void unregister_value_factory(String id) 1918 { 1919 valueFactories.remove (id); 1920 } 1921 1922 public ValueFactory lookup_value_factory(String id) 1923 { 1924 ValueFactory result = (ValueFactory )valueFactories.get (id); 1925 1926 if (result == null) 1927 { 1928 if (id.startsWith("IDL")) 1929 { 1930 String valueName = org.jacorb.ir.RepositoryID.className(id, null); 1931 result = findValueFactory(valueName); 1932 valueFactories.put(id, result); 1933 } 1934 } 1935 return result; 1936 } 1937 1938 1941 1942 private ValueFactory findValueFactory(String valueName) 1943 { 1944 Class result = null; 1945 result = findClass (valueName + "DefaultFactory", true); 1946 if (result != null) 1947 { 1948 return (ValueFactory )instantiate (result); 1949 } 1950 else 1951 { 1952 Class c = findClass (valueName, false); 1955 result = findClass (valueName + "Impl", false); 1956 1957 if (result != null && c.isAssignableFrom (result)) 1958 { 1959 if (ValueFactory .class.isAssignableFrom (result)) 1960 { 1961 return (ValueFactory )instantiate (result); 1962 } 1963 else 1964 { 1965 return new JacORBValueFactory (result); 1967 } 1968 } 1969 else 1970 return null; 1971 } 1972 } 1973 1974 1978 private class JacORBValueFactory 1979 implements org.omg.CORBA.portable.ValueFactory 1980 { 1981 private Class implementationClass; 1982 1983 public JacORBValueFactory (Class c) 1984 { 1985 implementationClass = c; 1986 } 1987 1988 public java.io.Serializable read_value 1989 (org.omg.CORBA_2_3.portable.InputStream is) 1990 { 1991 StreamableValue value = 1992 (StreamableValue )instantiate (implementationClass); 1993 return is.read_value(value); 1994 } 1995 1996 } 1997 1998 2003 private Class findClass (String name, boolean orgomg) 2004 { 2005 Class result = null; 2006 try 2007 { 2008 result = ObjectUtil.classForName(name); 2009 } 2010 catch (ClassNotFoundException e) 2011 { 2012 if (orgomg && name.startsWith ("org.omg")) 2013 try 2014 { 2015 result = ObjectUtil.classForName("omg.org" + name.substring(7)); 2016 } 2017 catch (ClassNotFoundException x) 2018 { 2019 } 2021 } 2022 return result; 2023 } 2024 2025 2029 private Object instantiate (Class c) 2030 { 2031 try 2032 { 2033 return c.newInstance(); 2034 } 2035 catch (IllegalAccessException e1) 2036 { 2037 throw new RuntimeException ("cannot instantiate class " 2038 + c.getName() 2039 + " (IllegalAccessException)"); 2040 } 2041 catch (InstantiationException e2) 2042 { 2043 throw new RuntimeException ("cannot instantiate class " 2044 + c.getName() 2045 + " (InstantiationException)"); 2046 } 2047 } 2048 2049 2061 2062 public BoxedValueHelper getBoxedValueHelper(String repId) 2063 { 2064 BoxedValueHelper result = (BoxedValueHelper )boxedValueHelpers.get(repId); 2065 if (result == null) 2066 { 2067 if (boxedValueHelpers.containsKey(repId)) 2068 return null; 2069 else 2070 { 2071 result = org.jacorb.ir.RepositoryID.createBoxedValueHelper(repId, null); 2072 boxedValueHelpers.put(repId, result); 2073 } 2074 } 2075 return result; 2076 } 2077 2078 2082 2083 public boolean hasClientRequestInterceptors () 2084 { 2085 return hasClientInterceptors; 2086 } 2087 2088 2092 2093 public boolean hasServerRequestInterceptors () 2094 { 2095 return hasServerInterceptors; 2096 } 2097 2098 2101 2102 public boolean hasRequestInterceptors () 2103 { 2104 return (hasServerInterceptors || hasClientInterceptors); 2105 } 2106 2107 2112 2113 public org.jacorb.orb.portableInterceptor.InterceptorManager getInterceptorManager() 2114 { 2115 return interceptor_manager; 2116 } 2117 2118 public TransportManager getTransportManager() 2119 { 2120 if (transport_manager == null) 2121 { 2122 transport_manager = new TransportManager(this); 2123 try 2124 { 2125 transport_manager.configure(configuration); 2126 } 2127 catch( ConfigurationException ce ) 2128 { 2129 throw new INTERNAL (ce.getMessage()); 2130 } 2131 } 2132 return transport_manager; 2133 } 2134 2135 2136 2137 public org.omg.CORBA.ExceptionList create_exception_list () 2138 { 2139 return new org.jacorb.orb.dii.ExceptionList (); 2140 } 2141 2142 public org.omg.CORBA.NVList create_list (int count) 2143 { 2144 return new org.jacorb.orb.NVList (this, count); 2145 } 2146 2147 public org.omg.CORBA.NamedValue create_named_value 2148 (String name, org.omg.CORBA.Any value, int flags) 2149 { 2150 return new org.jacorb.orb.NamedValue (name, value, flags); 2151 } 2152 2153 public org.omg.CORBA.NVList create_operation_list (org.omg.CORBA.Object obj) 2154 { 2155 org.omg.CORBA.OperationDef oper; 2156 2157 if (obj instanceof org.omg.CORBA.OperationDef ) 2158 { 2159 oper = (org.omg.CORBA.OperationDef ) obj; 2160 } 2161 else 2162 { 2163 throw new org.omg.CORBA.BAD_PARAM ("Argument must be of type org.omg.CORBA.OperationDef"); 2164 } 2165 return (create_operation_list (oper)); 2166 } 2167 2168 2170 public org.omg.CORBA.NVList create_operation_list 2171 (org.omg.CORBA.OperationDef oper) 2172 { 2173 int no = 0; 2174 org.omg.CORBA.Any any; 2175 org.omg.CORBA.ParameterDescription [] params = null; 2176 org.omg.CORBA.ParameterDescription param; 2177 org.omg.CORBA.NVList list; 2178 2179 params = oper.params (); 2180 if (params != null) 2181 { 2182 no = params.length; 2183 } 2184 list = new org.jacorb.orb.NVList (this, no); 2185 2186 for (int i = 0; i < no; i++) 2187 { 2188 param = params[i]; 2189 any = create_any (); 2190 any.type (param.type); 2191 list.add_value (param.name, any, param.mode.value ()); 2192 } 2193 2194 return list; 2195 } 2196 2197 2202 2203 private void configureObjectKeyMap (Configuration config) 2204 { 2205 String [] names = config.getAttributeNames(); 2206 String prefix = "jacorb.orb.objectKeyMap."; 2207 for (int i = 0; i < names.length; i++) 2208 if (names[i].startsWith (prefix)) 2209 objectKeyMap.put(names[i].substring (prefix.length()), 2210 config.getAttribute (names[i],"")); 2211 } 2212 2213 2222 public void addObjectKey(String key_name, String full_path) 2223 { 2224 objectKeyMap.put(key_name, full_path); 2225 } 2226 2227 2228 2238 public byte[] mapObjectKey( byte[] originalKey ) 2239 { 2240 BufferedReader br = null; 2241 File iorFile = null; 2242 ParsedIOR pIOR = null; 2243 String found = null; 2244 String original = null; 2245 2246 if( objectKeyMap.size() != 0 ) 2247 { 2248 original = new String ( originalKey ); 2249 found = (String )objectKeyMap.get( original ); 2250 2251 if( found != null ) 2252 { 2253 if ( ParsedIOR.isParsableProtocol ( found ) ) 2254 { 2255 try 2258 { 2259 pIOR = new ParsedIOR( found, this, logger ); 2260 return pIOR.get_object_key(); 2261 } 2262 catch ( IllegalArgumentException e ) 2263 { 2264 if (logger.isDebugEnabled()) 2265 { 2266 logger.debug("Error - could not read protocol " + found ); 2267 } 2268 return originalKey; 2269 } 2270 } 2271 else 2272 { 2273 return org.jacorb.orb.util.CorbaLoc.parseKey(found); 2274 } 2275 } 2276 } 2277 return originalKey; 2279 } 2280 2281 2285 private class PICurrent 2286 extends org.omg.CORBA.LocalObject 2287 implements org.omg.PortableInterceptor.Current 2288 { 2289 private Current getTarget() 2292 { 2293 if (interceptor_manager == null) 2294 return InterceptorManager.EMPTY_CURRENT; 2295 else 2296 return interceptor_manager.getCurrent(); 2297 } 2298 2299 2301 public org.omg.CORBA.Any get_slot(int id) 2302 throws InvalidSlot 2303 { 2304 return getTarget().get_slot(id); 2305 } 2306 2307 public void set_slot(int id, org.omg.CORBA.Any data) 2308 throws InvalidSlot 2309 { 2310 getTarget().set_slot(id, data); 2311 } 2312 2313 } 2314 2315 2320 2323 private boolean firstConnection = true; 2324 2325 2330 private Map connectedObjects = new HashMap(); 2331 2332 2335 static class HandlerWrapper extends org.omg.PortableServer.Servant 2336 implements org.omg.CORBA.portable.InvokeHandler 2337 { 2338 private org.omg.CORBA.portable.InvokeHandler wrappedHandler; 2339 2340 public HandlerWrapper(org.omg.CORBA.portable.ObjectImpl objectImpl) 2341 { 2342 wrappedHandler = (org.omg.CORBA.portable.InvokeHandler )objectImpl; 2343 } 2344 2345 public String [] _all_interfaces(org.omg.PortableServer.POA poa, 2346 byte[] objectID) 2347 { 2348 return ((org.omg.CORBA.portable.ObjectImpl )wrappedHandler)._ids(); 2349 } 2350 2351 public org.omg.CORBA.portable.OutputStream _invoke( 2352 String method, 2353 org.omg.CORBA.portable.InputStream input, 2354 org.omg.CORBA.portable.ResponseHandler handler) 2355 throws org.omg.CORBA.SystemException 2356 { 2357 return wrappedHandler._invoke(method, input, handler); 2358 } 2359 2360 } 2361 2362 public void connect(org.omg.CORBA.Object obj) 2363 { 2364 if (!(obj instanceof org.omg.CORBA.portable.ObjectImpl )) 2365 throw new BAD_PARAM ("connect parameter must extend " + 2366 "org.omg.CORBA.portable.ObjectImpl"); 2367 2368 if (!(obj instanceof org.omg.CORBA.portable.InvokeHandler )) 2369 throw new BAD_PARAM ("connect parameter must implement " + 2370 "org.omg.CORBA.portable.InvokeHandler"); 2371 2372 synchronized (connectedObjects) 2373 { 2374 if (connectedObjects.containsKey(obj) == false) 2375 { 2376 org.omg.CORBA.portable.ObjectImpl objectImpl = 2377 (org.omg.CORBA.portable.ObjectImpl )obj; 2378 org.omg.PortableServer.Servant servant = 2379 new HandlerWrapper(objectImpl); 2380 org.omg.CORBA.Object ref = servant._this_object(this); 2381 objectImpl._set_delegate( 2382 ((org.omg.CORBA.portable.ObjectImpl )ref)._get_delegate()); 2383 connectedObjects.put(obj, servant); 2384 if (firstConnection) 2385 { 2386 firstConnection = false; 2387 org.omg.PortableServer.POAManager rootPOAManager = 2388 getRootPOA().the_POAManager(); 2389 if (rootPOAManager.get_state() == State.HOLDING) 2390 { 2391 try 2392 { 2393 rootPOAManager.activate(); 2394 } 2395 catch (AdapterInactive adapterInactive) 2396 { 2397 if( logger.isErrorEnabled() ) 2399 { 2400 logger.error(adapterInactive.getMessage()); 2401 } 2402 } 2403 } 2404 } 2405 } 2406 } 2407 } 2408 2409 public void disconnect(org.omg.CORBA.Object obj) 2410 { 2411 if (!(obj instanceof org.omg.CORBA.portable.ObjectImpl )) 2412 throw new BAD_PARAM ("disconnect parameter must extend " + 2413 "org.omg.CORBA.portable.ObjectImpl"); 2414 2415 if (!(obj instanceof org.omg.CORBA.portable.InvokeHandler )) 2416 throw new BAD_PARAM ("disconnect parameter must implement " + 2417 "org.omg.CORBA.portable.InvokeHandler"); 2418 2419 synchronized (connectedObjects) 2420 { 2421 org.omg.PortableServer.Servant servant = 2422 (org.omg.PortableServer.Servant )connectedObjects.get(obj); 2423 2424 if (servant != null) 2425 { 2426 connectedObjects.remove(obj); 2427 try 2428 { 2429 getRootPOA().deactivate_object( 2430 getRootPOA().servant_to_id(servant)); 2431 } 2432 catch (Exception e) 2433 { 2434 if( logger.isErrorEnabled()) 2436 { 2437 logger.error(e.getMessage()); 2438 } 2439 } 2440 } 2441 } 2442 } 2443 2444} 2445 | Popular Tags |