1 7 8 package com.sun.corba.se.impl.naming.cosnaming; 9 10 import java.util.logging.Logger ; 12 import java.util.logging.Level ; 13 import com.sun.corba.se.impl.orbutil.LogKeywords; 14 15 import org.omg.CORBA.Object ; 17 import org.omg.CORBA.BAD_PARAM ; 18 import org.omg.CORBA.INTERNAL ; 19 import org.omg.CORBA.CompletionStatus ; 20 import org.omg.PortableServer.POA ; 21 import org.omg.PortableServer.Servant ; 22 23 import org.omg.CosNaming.BindingType ; 25 import org.omg.CosNaming.BindingTypeHolder ; 26 import org.omg.CosNaming.BindingListHolder ; 27 import org.omg.CosNaming.BindingIteratorHolder ; 28 import org.omg.CosNaming.NameComponent ; 29 import org.omg.CosNaming.NamingContextHelper ; 30 import org.omg.CosNaming.NamingContext ; 31 import org.omg.CosNaming.NamingContextPackage.*; 32 import org.omg.CosNaming._NamingContextImplBase ; 33 import org.omg.CosNaming.NamingContextExtHelper ; 34 import org.omg.CosNaming.NamingContextExt ; 35 import org.omg.CosNaming.NamingContextExtPOA ; 36 import org.omg.CosNaming.NamingContextExtPackage.*; 37 import org.omg.CosNaming.NamingContextPackage.NotFound ; 38 39 import com.sun.corba.se.impl.naming.cosnaming.NamingContextDataStore; 40 41 import com.sun.corba.se.impl.naming.namingutil.INSURLHandler; 42 import com.sun.corba.se.spi.logging.CORBALogDomains; 43 import com.sun.corba.se.impl.logging.NamingSystemException ; 44 45 import com.sun.corba.se.spi.orb.ORB; 46 47 72 public abstract class NamingContextImpl 73 extends NamingContextExtPOA 74 implements NamingContextDataStore 75 { 76 77 protected POA nsPOA; 78 private Logger readLogger, updateLogger, lifecycleLogger; 79 private NamingSystemException wrapper ; 80 private static NamingSystemException staticWrapper = 81 NamingSystemException.get( CORBALogDomains.NAMING_UPDATE ) ; 82 83 private InterOperableNamingImpl insImpl; 86 92 public NamingContextImpl(ORB orb, POA poa) throws java.lang.Exception { 93 super(); 94 this.orb = orb; 95 wrapper = NamingSystemException.get( orb, 96 CORBALogDomains.NAMING_UPDATE ) ; 97 98 insImpl = new InterOperableNamingImpl( ); 99 this.nsPOA = poa; 100 readLogger = orb.getLogger( CORBALogDomains.NAMING_READ); 101 updateLogger = orb.getLogger( CORBALogDomains.NAMING_UPDATE); 102 lifecycleLogger = orb.getLogger( 103 CORBALogDomains.NAMING_LIFECYCLE); 104 } 105 106 public POA getNSPOA( ) { 107 return nsPOA; 108 } 109 110 134 public void bind(NameComponent [] n, org.omg.CORBA.Object obj) 135 throws org.omg.CosNaming.NamingContextPackage.NotFound , 136 org.omg.CosNaming.NamingContextPackage.CannotProceed , 137 org.omg.CosNaming.NamingContextPackage.InvalidName , 138 org.omg.CosNaming.NamingContextPackage.AlreadyBound 139 { 140 if( obj == null ) 141 { 142 updateLogger.warning( LogKeywords.NAMING_BIND + 143 " unsuccessful because NULL Object cannot be Bound " ); 144 throw wrapper.objectIsNull() ; 145 } 146 NamingContextDataStore impl = (NamingContextDataStore)this; 148 doBind(impl,n,obj,false,BindingType.nobject); 149 if( updateLogger.isLoggable( Level.FINE ) ) { 150 updateLogger.fine( LogKeywords.NAMING_BIND_SUCCESS + " Name = " + 153 NamingUtils.getDirectoryStructuredName( n ) ); 154 } 155 } 156 157 158 180 public void bind_context(NameComponent [] n, NamingContext nc) 181 throws org.omg.CosNaming.NamingContextPackage.NotFound , 182 org.omg.CosNaming.NamingContextPackage.CannotProceed , 183 org.omg.CosNaming.NamingContextPackage.InvalidName , 184 org.omg.CosNaming.NamingContextPackage.AlreadyBound 185 { 186 if( nc == null ) { 187 updateLogger.warning( LogKeywords.NAMING_BIND_FAILURE + 188 " NULL Context cannot be Bound " ); 189 throw new BAD_PARAM ( "Naming Context should not be null " ); 190 } 191 NamingContextDataStore impl = (NamingContextDataStore)this; 193 doBind(impl,n,nc,false,BindingType.ncontext); 194 if( updateLogger.isLoggable( Level.FINE ) ) { 195 updateLogger.fine( LogKeywords.NAMING_BIND_SUCCESS + " Name = " + 198 NamingUtils.getDirectoryStructuredName( n ) ); 199 } 200 } 201 202 224 public void rebind(NameComponent [] n, org.omg.CORBA.Object obj) 225 throws org.omg.CosNaming.NamingContextPackage.NotFound , 226 org.omg.CosNaming.NamingContextPackage.CannotProceed , 227 org.omg.CosNaming.NamingContextPackage.InvalidName 228 { 229 if( obj == null ) 230 { 231 updateLogger.warning( LogKeywords.NAMING_REBIND_FAILURE + 232 " NULL Object cannot be Bound " ); 233 throw wrapper.objectIsNull() ; 234 } 235 try { 236 NamingContextDataStore impl = (NamingContextDataStore)this; 238 doBind(impl,n,obj,true,BindingType.nobject); 239 } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex) { 240 updateLogger.warning( LogKeywords.NAMING_REBIND_FAILURE + 241 NamingUtils.getDirectoryStructuredName( n ) + 242 " is already bound to a Naming Context" ); 243 throw wrapper.namingCtxRebindAlreadyBound( ex ) ; 245 } 246 if( updateLogger.isLoggable( Level.FINE ) ) { 247 updateLogger.fine( LogKeywords.NAMING_REBIND_SUCCESS + " Name = " + 250 NamingUtils.getDirectoryStructuredName( n ) ); 251 } 252 } 253 254 275 public void rebind_context(NameComponent [] n, NamingContext nc) 276 throws org.omg.CosNaming.NamingContextPackage.NotFound , 277 org.omg.CosNaming.NamingContextPackage.CannotProceed , 278 org.omg.CosNaming.NamingContextPackage.InvalidName 279 { 280 if( nc == null ) 281 { 282 updateLogger.warning( LogKeywords.NAMING_REBIND_FAILURE + 283 " NULL Context cannot be Bound " ); 284 throw wrapper.objectIsNull() ; 285 } 286 try { 287 NamingContextDataStore impl = (NamingContextDataStore)this; 289 doBind(impl,n,nc,true,BindingType.ncontext); 290 } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex) { 291 updateLogger.warning( LogKeywords.NAMING_REBIND_FAILURE + 293 NamingUtils.getDirectoryStructuredName( n ) + 294 " is already bound to a CORBA Object" ); 295 throw wrapper.namingCtxRebindctxAlreadyBound( ex ) ; 296 } 297 if( updateLogger.isLoggable( Level.FINE ) ) { 298 updateLogger.fine( LogKeywords.NAMING_REBIND_SUCCESS + " Name = " + 301 NamingUtils.getDirectoryStructuredName( n ) ); 302 } 303 } 304 305 325 public org.omg.CORBA.Object resolve(NameComponent [] n) 326 throws org.omg.CosNaming.NamingContextPackage.NotFound , 327 org.omg.CosNaming.NamingContextPackage.CannotProceed , 328 org.omg.CosNaming.NamingContextPackage.InvalidName 329 { 330 NamingContextDataStore impl = (NamingContextDataStore)this; 332 org.omg.CORBA.Object obj = doResolve(impl,n); 333 if( obj != null ) { 334 if( readLogger.isLoggable( Level.FINE ) ) { 335 readLogger.fine( LogKeywords.NAMING_RESOLVE_SUCCESS + 336 " Name: " + NamingUtils.getDirectoryStructuredName( n ) ); 337 } 338 } else { 339 readLogger.warning( LogKeywords.NAMING_RESOLVE_FAILURE + 340 " Name: " + NamingUtils.getDirectoryStructuredName( n ) ); 341 } 342 return obj; 343 } 344 345 346 363 public void unbind(NameComponent [] n) 364 throws org.omg.CosNaming.NamingContextPackage.NotFound , 365 org.omg.CosNaming.NamingContextPackage.CannotProceed , 366 org.omg.CosNaming.NamingContextPackage.InvalidName 367 { 368 NamingContextDataStore impl = (NamingContextDataStore)this; 370 doUnbind(impl,n); 371 if( updateLogger.isLoggable( Level.FINE ) ) { 372 updateLogger.fine( LogKeywords.NAMING_UNBIND_SUCCESS + 375 " Name: " + NamingUtils.getDirectoryStructuredName( n ) ); 376 } 377 } 378 379 392 public void list(int how_many, BindingListHolder bl, 393 BindingIteratorHolder bi) 394 { 395 NamingContextDataStore impl = (NamingContextDataStore)this; 397 synchronized (impl) { 398 impl.List(how_many,bl,bi); 399 } 400 if( readLogger.isLoggable( Level.FINE ) && (bl.value != null )) { 401 readLogger.fine ( LogKeywords.NAMING_LIST_SUCCESS + 404 "list(" + how_many + ") -> bindings[" + bl.value.length + 405 "] + iterator: " + bi.value); 406 } 407 } 408 409 416 public synchronized NamingContext new_context() 417 { 418 lifecycleLogger.fine( "Creating New Naming Context " ); 420 NamingContextDataStore impl = (NamingContextDataStore)this; 421 synchronized (impl) { 422 NamingContext nctx = impl.NewContext(); 423 if( nctx != null ) { 424 lifecycleLogger.fine( LogKeywords.LIFECYCLE_CREATE_SUCCESS ); 425 } else { 426 lifecycleLogger.severe ( LogKeywords.LIFECYCLE_CREATE_FAILURE ); 429 } 430 return nctx; 431 } 432 } 433 434 456 public NamingContext bind_new_context(NameComponent [] n) 457 throws org.omg.CosNaming.NamingContextPackage.NotFound , 458 org.omg.CosNaming.NamingContextPackage.AlreadyBound , 459 org.omg.CosNaming.NamingContextPackage.CannotProceed , 460 org.omg.CosNaming.NamingContextPackage.InvalidName 461 { 462 NamingContext nc = null; 463 NamingContext rnc = null; 464 try { 465 if (debug) 466 dprint("bind_new_context " + nameToString(n)); 467 nc = this.new_context(); 469 this.bind_context(n,nc); 470 rnc = nc; 471 nc = null; 472 } finally { 473 try { 474 if(nc != null) 475 nc.destroy(); 476 } catch (org.omg.CosNaming.NamingContextPackage.NotEmpty e) { 477 } 478 } 479 if( updateLogger.isLoggable( Level.FINE ) ) { 480 updateLogger.fine ( LogKeywords.NAMING_BIND + 483 "New Context Bound To " + 484 NamingUtils.getDirectoryStructuredName( n ) ); 485 } 486 return rnc; 487 } 488 489 497 public void destroy() 498 throws org.omg.CosNaming.NamingContextPackage.NotEmpty 499 { 500 lifecycleLogger.fine( "Destroying Naming Context " ); 501 NamingContextDataStore impl = (NamingContextDataStore)this; 502 synchronized (impl) { 503 if (impl.IsEmpty() == true) { 504 impl.Destroy(); 506 lifecycleLogger.fine ( LogKeywords.LIFECYCLE_DESTROY_SUCCESS ); 507 } 508 else { 509 lifecycleLogger.warning( LogKeywords.LIFECYCLE_DESTROY_FAILURE + 512 " NamingContext children are not destroyed still.." ); 513 throw new NotEmpty(); 514 } 515 } 516 } 517 518 552 public static void doBind(NamingContextDataStore impl, 553 NameComponent [] n, 554 org.omg.CORBA.Object obj, 555 boolean rebind, 556 org.omg.CosNaming.BindingType bt) 557 throws org.omg.CosNaming.NamingContextPackage.NotFound , 558 org.omg.CosNaming.NamingContextPackage.CannotProceed , 559 org.omg.CosNaming.NamingContextPackage.InvalidName , 560 org.omg.CosNaming.NamingContextPackage.AlreadyBound 561 { 562 if (n.length < 1) 564 throw new InvalidName(); 565 566 if (n.length == 1) { 568 if ( (n[0].id.length() == 0) && (n[0].kind.length() == 0 ) ) { 570 throw new InvalidName(); 571 } 572 573 synchronized (impl) { 575 BindingTypeHolder bth = new BindingTypeHolder (); 577 if (rebind) { 578 org.omg.CORBA.Object objRef = impl.Resolve( n[0], bth ); 579 if( objRef != null ) { 580 if ( bth.value.value() == BindingType.nobject.value() ){ 587 if ( bt.value() == BindingType.ncontext.value() ) { 588 throw new NotFound ( 589 NotFoundReason.not_context, n); 590 } 591 } else { 592 if ( bt.value() == BindingType.nobject.value() ) { 595 throw new NotFound ( 596 NotFoundReason.not_object, n); 597 } 598 } 599 impl.Unbind(n[0]); 600 } 601 602 } else { 603 if (impl.Resolve(n[0],bth) != null) 604 throw new AlreadyBound(); 606 } 607 608 impl.Bind(n[0],obj,bt); 610 } 611 } else { 612 NamingContext context = resolveFirstAsContext(impl,n); 614 615 NameComponent [] tail = new NameComponent [n.length - 1]; 617 System.arraycopy(n,1,tail,0,n.length-1); 618 619 switch (bt.value()) { 621 case BindingType._nobject: 622 { 623 if (rebind) 625 context.rebind(tail,obj); 626 else 627 context.bind(tail,obj); 628 } 629 break; 630 case BindingType._ncontext: 631 { 632 NamingContext objContext = (NamingContext )obj; 635 if (rebind) 637 context.rebind_context(tail,objContext); 638 else 639 context.bind_context(tail,objContext); 640 } 641 break; 642 default: 643 throw staticWrapper.namingCtxBadBindingtype() ; 645 } 646 } 647 } 648 649 674 public static org.omg.CORBA.Object doResolve(NamingContextDataStore impl, 675 NameComponent [] n) 676 throws org.omg.CosNaming.NamingContextPackage.NotFound , 677 org.omg.CosNaming.NamingContextPackage.CannotProceed , 678 org.omg.CosNaming.NamingContextPackage.InvalidName 679 { 680 org.omg.CORBA.Object obj = null; 681 BindingTypeHolder bth = new BindingTypeHolder (); 682 683 684 if (n.length < 1) 686 throw new InvalidName(); 687 688 if (n.length == 1) { 690 synchronized (impl) { 691 obj = impl.Resolve(n[0],bth); 693 } 694 if (obj == null) { 695 throw new NotFound (NotFoundReason.missing_node,n); 697 } 698 return obj; 699 } else { 700 if ( (n[1].id.length() == 0) && (n[1].kind.length() == 0) ) { 702 throw new InvalidName(); 703 } 704 705 NamingContext context = resolveFirstAsContext(impl,n); 706 707 NameComponent [] tail = new NameComponent [n.length -1]; 709 System.arraycopy(n,1,tail,0,n.length-1); 710 711 try { 713 Servant servant = impl.getNSPOA().reference_to_servant( 716 context ); 717 return doResolve(((NamingContextDataStore)servant), tail) ; 718 } catch( Exception e ) { 719 return context.resolve(tail); 720 } 721 } 722 } 723 724 744 public static void doUnbind(NamingContextDataStore impl, 745 NameComponent [] n) 746 throws org.omg.CosNaming.NamingContextPackage.NotFound , 747 org.omg.CosNaming.NamingContextPackage.CannotProceed , 748 org.omg.CosNaming.NamingContextPackage.InvalidName 749 { 750 if (n.length < 1) 752 throw new InvalidName(); 753 754 if (n.length == 1) { 756 if ( (n[0].id.length() == 0) && (n[0].kind.length() == 0 ) ) { 758 throw new InvalidName(); 759 } 760 761 org.omg.CORBA.Object objRef = null; 762 synchronized (impl) { 763 objRef = impl.Unbind(n[0]); 765 } 766 767 if (objRef == null) 768 throw new NotFound (NotFoundReason.missing_node,n); 770 return; 772 } else { 773 775 NamingContext context = resolveFirstAsContext(impl,n); 777 778 NameComponent [] tail = new NameComponent [n.length - 1]; 780 System.arraycopy(n,1,tail,0,n.length-1); 781 782 context.unbind(tail); 784 } 785 } 786 787 800 protected static NamingContext resolveFirstAsContext(NamingContextDataStore impl, 801 NameComponent [] n) 802 throws org.omg.CosNaming.NamingContextPackage.NotFound { 803 org.omg.CORBA.Object topRef = null; 804 BindingTypeHolder bth = new BindingTypeHolder (); 805 NamingContext context = null; 806 807 synchronized (impl) { 808 topRef = impl.Resolve(n[0],bth); 810 if (topRef == null) { 811 throw new NotFound (NotFoundReason.missing_node,n); 813 } 814 } 815 816 if (bth.value != BindingType.ncontext) { 818 throw new NotFound (NotFoundReason.not_context,n); 820 } 821 822 try { 824 context = NamingContextHelper.narrow(topRef); 825 } catch (org.omg.CORBA.BAD_PARAM ex) { 826 throw new NotFound (NotFoundReason.not_context,n); 828 } 829 830 return context; 832 } 833 834 835 843 public String to_string(org.omg.CosNaming.NameComponent [] n) 844 throws org.omg.CosNaming.NamingContextPackage.InvalidName 845 { 846 if ( (n == null ) || (n.length == 0) ) 848 { 849 throw new InvalidName(); 850 } 851 NamingContextDataStore impl = (NamingContextDataStore)this; 852 853 String theStringifiedName = insImpl.convertToString( n ); 854 855 if( theStringifiedName == null ) 856 { 857 throw new InvalidName(); 858 } 859 860 return theStringifiedName; 861 } 862 863 864 872 public org.omg.CosNaming.NameComponent [] to_name(String sn) 873 throws org.omg.CosNaming.NamingContextPackage.InvalidName 874 { 875 if ( (sn == null ) || (sn.length() == 0) ) 877 { 878 throw new InvalidName(); 879 } 880 NamingContextDataStore impl = (NamingContextDataStore)this; 881 org.omg.CosNaming.NameComponent [] theNameComponents = 882 insImpl.convertToNameComponent( sn ); 883 if( ( theNameComponents == null ) || (theNameComponents.length == 0 ) ) 884 { 885 throw new InvalidName(); 886 } 887 for( int i = 0; i < theNameComponents.length; i++ ) { 888 if ( ( ( theNameComponents[i].id == null ) 892 ||( theNameComponents[i].id.length() == 0 ) ) 893 &&( ( theNameComponents[i].kind == null ) 894 ||( theNameComponents[i].kind.length() == 0 ) ) ) { 895 throw new InvalidName(); 896 } 897 } 898 return theNameComponents; 899 } 900 901 914 915 public String to_url(String addr, String sn) 916 throws org.omg.CosNaming.NamingContextExtPackage.InvalidAddress , 917 org.omg.CosNaming.NamingContextPackage.InvalidName 918 { 919 if ( (sn == null ) || (sn.length() == 0) ) 921 { 922 throw new InvalidName(); 923 } 924 if( addr == null ) 925 { 926 throw new 927 org.omg.CosNaming.NamingContextExtPackage.InvalidAddress (); 928 } 929 NamingContextDataStore impl = (NamingContextDataStore)this; 930 String urlBasedAddress = null; 931 urlBasedAddress = insImpl.createURLBasedAddress( addr, sn ); 932 try { 935 INSURLHandler.getINSURLHandler( ).parseURL( urlBasedAddress ); 936 } catch( BAD_PARAM e ) { 937 throw new 938 org.omg.CosNaming.NamingContextExtPackage.InvalidAddress (); 939 } 940 return urlBasedAddress; 941 } 942 943 957 public org.omg.CORBA.Object resolve_str(String sn) 958 throws org.omg.CosNaming.NamingContextPackage.NotFound , 959 org.omg.CosNaming.NamingContextPackage.CannotProceed , 960 org.omg.CosNaming.NamingContextPackage.InvalidName 961 { 962 org.omg.CORBA.Object theObject = null; 963 if ( (sn == null ) || (sn.length() == 0) ) 965 { 966 throw new InvalidName(); 967 } 968 NamingContextDataStore impl = (NamingContextDataStore)this; 969 org.omg.CosNaming.NameComponent [] theNameComponents = 970 insImpl.convertToNameComponent( sn ); 971 972 if( ( theNameComponents == null ) || (theNameComponents.length == 0 ) ) 973 { 974 throw new InvalidName(); 975 } 976 theObject = resolve( theNameComponents ); 977 return theObject; 978 } 979 980 981 transient protected ORB orb; 982 983 public static String nameToString(NameComponent [] name) 984 { 985 StringBuffer s = new StringBuffer ("{"); 986 if (name != null || name.length > 0) { 987 for (int i=0;i<name.length;i++) { 988 if (i>0) 989 s.append(","); 990 s.append("["). 991 append(name[i].id). 992 append(","). 993 append(name[i].kind). 994 append("]"); 995 } 996 } 997 s.append("}"); 998 return s.toString(); 999 } 1000 1001 public static final boolean debug = false; 1003 1004 private static void dprint(String msg) { 1005 NamingUtils.dprint("NamingContextImpl(" + 1006 Thread.currentThread().getName() + " at " + 1007 System.currentTimeMillis() + 1008 " ems): " + msg); 1009 } 1010} 1011 | Popular Tags |