1 26 27 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.registrar; 28 29 35 36 public class RegisterwithnamingDeployer 37 extends RegisterwithnamingDeployerContext 38 { 39 45 46 private org.omg.CosNaming.NameComponent [] ncomp; 47 48 private boolean failed; 49 50 private org.omg.CosNaming.NamingContextExt rootContext; 51 52 58 64 70 77 public void 78 rebind(org.omg.CORBA.Object objectToRebind) 79 throws NameserviceRegistrationFailureException 80 { 81 82 83 rootContext=getNamingcontextExt(); 84 try{ 85 ncomp=rebind(rootContext,getRegisterwithnaming().getName(),objectToRebind); 87 } 88 catch(Exception e) 89 { 90 failed=true; 91 throw new NameserviceRegistrationFailureException(this,e," TO complete"); 92 } 93 getLifeCycleManager().stepEndedSuccessFully(); 94 } 95 96 104 public static org.omg.CosNaming.NameComponent [] 105 rebind(org.omg.CosNaming.NamingContextExt rootContextExt, 106 String name, 107 org.omg.CORBA.Object objectToRebind) 108 throws Exception 109 { 110 String pathError="" ; 111 org.omg.CosNaming.NameComponent [] nameComp=null; 112 113 nameComp=rootContextExt.to_name(name); 114 String nameTmp=""; 115 try{ 117 rootContextExt.resolve(nameComp); 118 for(int i=0;true;i++) 119 { 120 nameTmp=name+"("+i+")"; 121 nameComp=rootContextExt.to_name(nameTmp); 122 rootContextExt.resolve(nameComp); 123 } 124 125 } 126 catch(org.omg.CosNaming.NamingContextPackage.NotFound nf ) 127 { 128 129 } 130 131 try{ 132 133 rootContextExt.rebind(nameComp,objectToRebind); 134 } 135 catch(org.omg.CosNaming.NamingContextPackage.NotFound nf ) 136 { 137 org.omg.CosNaming.NamingContext context=rootContextExt; 138 139 org.omg.CosNaming.NameComponent [] ncompTmp= 140 new org.omg.CosNaming.NameComponent [1]; 141 142 144 for(int i=0; i<nameComp.length-1; i++) 145 { 146 pathError+=nameComp[i].id+"/"; 147 ncompTmp[0]=nameComp[i]; 148 149 try{ 150 context=org.omg.CosNaming. 151 NamingContextHelper.narrow(context.resolve(ncompTmp)); 152 } 153 catch(org.omg.CORBA.BAD_PARAM bp) 154 { 155 System.err.println("Invalid registeration name,"+pathError+ 156 " is already used as full path to register a corba object "); 157 System.err.println 158 ("The corba object cannot be registered, take care some connection can fail"); 159 throw new org.omg.CosNaming.NamingContextPackage.CannotProceed (); 160 } 161 catch(Exception e) 162 { 163 try 164 { 165 context=context.bind_new_context(ncompTmp); 166 } 167 catch(org.omg.CosNaming.NamingContextPackage.AlreadyBound ab) 170 { 171 context=org.omg.CosNaming.NamingContextHelper.narrow(context.resolve(ncompTmp)); 174 } 175 } 176 } 177 ncompTmp[0]=nameComp[nameComp.length-1]; 178 context.rebind(ncompTmp,objectToRebind); 179 } 180 return nameComp; 181 } 182 183 187 public void 188 unbind() 189 throws NameserviceRegistrationFailureException 190 { 191 if(failed) 192 return; 193 try{ 194 org.objectweb.openccm.corba 195 .TheNameService.getNamingContext() 196 .getNamingContext().unbind(ncomp); 197 } 198 catch(Exception e){ 199 throw new NameserviceRegistrationFailureException(this,e,"Error occur during unbinding"); 200 } 201 getLifeCycleManager().stepEndedSuccessFully(); 202 } 203 } 204 205 | Popular Tags |