1 26 27 package org.objectweb.ccm.IDL3; 28 29 37 38 abstract public class DeclarationImpl 39 implements Declaration 40 { 41 47 50 private java.lang.String prefix_; 51 52 55 private java.lang.String name_; 56 57 60 private java.lang.String version_; 61 62 65 private java.lang.String id_; 66 67 70 private boolean is_imported_; 71 72 75 private int nb_refs_; 76 77 80 protected int the_declaration_kind_; 81 82 85 protected Repository the_repository_; 86 87 90 protected ScopeImpl the_parent_; 91 92 95 protected boolean is_mapping_; 96 97 100 protected Declaration[] dependencies_; 101 102 108 113 protected 114 DeclarationImpl(Repository rep, ScopeImpl parent) 115 { 116 the_repository_ = rep; 118 the_parent_ = parent; 119 prefix_ = null; 120 name_ = null; 121 version_ = "1.0"; 122 id_ = null; 123 is_imported_ = false; 124 is_mapping_ = false; 125 the_declaration_kind_ = DeclarationKind._dk_null; 126 nb_refs_ = 0; 127 dependencies_ = null; 128 } 129 130 136 141 protected java.lang.String 142 computePrefix() 143 { 144 int idx1 = id_.indexOf(':'); 145 int idx2 = id_.indexOf('/'); 146 147 java.lang.String pname = the_parent_.getName(); 148 if (pname==null) 149 { 151 if (id_.indexOf(name_)==-1) 152 return null; 154 else if (idx2!=-1) 155 return id_.substring(idx1+1,idx2); 157 else 158 return null; 160 } 161 else 162 { 163 if (id_.indexOf(name_)==-1) 164 return null; 166 else if (id_.indexOf(the_parent_.computeBaseRID())==-1) 167 return id_.substring(idx1+1, idx2); 177 else 178 return null; 180 } 181 } 182 183 188 protected java.lang.String 189 computeBaseRID() 190 { 191 java.lang.String result = ""; 192 193 if (prefix_ != null) 194 result = prefix_; 195 else if (the_parent_ != null) 196 result = the_parent_.computeBaseRID(); 197 198 if (name_ != null) 199 { 200 if (result.length() != 0) 201 result = result + '/' + name_; 202 else 203 result = name_; 204 } 205 206 return result; 207 } 208 209 213 protected void 214 setImported() 215 { 216 is_imported_ = true; 217 } 218 219 222 protected Repository 223 getRepository() 224 { 225 return the_repository_; 226 } 227 228 233 protected void 234 load(org.omg.CORBA.Contained contained) 235 { 236 version_ = contained.version(); 237 id_ = contained.id(); 238 prefix_ = computePrefix(); 239 the_repository_.addDeclInRep(getId(), this); 240 if (the_parent_!=null) 241 the_parent_.addDecl(this); 242 } 243 244 249 protected void 250 loadAsMapping(org.omg.CORBA.Contained contained) 251 { 252 version_ = contained.version(); 253 id_ = contained.id(); 254 prefix_ = computePrefix(); 255 the_repository_.addMappedDeclInRep(getId(), this); 256 is_mapping_ = true; 257 if ((the_parent_!=null) && 259 (the_parent_.is_mapping_)) 260 the_parent_.addDecl(this); 261 } 262 263 268 abstract protected org.omg.CORBA.Contained 269 getContained(); 270 271 277 280 public void 281 destroy() 282 { 283 if (nb_refs_!=0) 284 throw new Error ("Declaration can\'t be destroyed : it\'s still referenced"); 285 286 org.omg.CORBA.IRObject obj = (org.omg.CORBA.IRObject )getContained(); 287 if (obj != null) 288 { 289 if (!is_imported_) 291 obj.destroy(); 292 293 the_repository_.removeDeclFromRep(getId()); 294 if (the_parent_!=null) 295 the_parent_.removeDecl(name_); 296 } 297 } 298 299 307 public void 308 setPrefix(java.lang.String prefix) 309 { 310 prefix_ = prefix; 311 312 org.omg.CORBA.Contained contained = getContained(); 313 if (contained != null) 314 contained.id(getId()); 315 } 316 317 322 public void 323 setName(java.lang.String name) 324 { 325 name_ = name; 326 } 327 328 333 public void 334 setVersion(java.lang.String version) 335 { 336 version_ = version; 337 org.omg.CORBA.Contained contained = getContained(); 338 if (contained != null) 339 contained.version(version); 340 } 341 342 347 public void 348 setId(java.lang.String id) 349 { 350 id_ = id; 351 the_repository_.addDeclInRep(id, this); 352 org.omg.CORBA.Contained contained = getContained(); 353 if (contained != null) 354 contained.id(id_); 355 } 356 357 360 public void 361 create() 362 { 363 if (the_parent_!=null) 364 the_parent_.addDecl(this); 365 } 366 367 373 379 public java.lang.String 380 getPrefix() 381 { 382 if (prefix_!=null) 383 return prefix_; 384 if ((the_parent_!=null) && (the_parent_.getName()!=null)) 385 return the_parent_.getPrefix(); 386 387 return ""; 388 } 389 390 395 public java.lang.String 396 getName() 397 { 398 return name_; 399 } 400 401 406 public java.lang.String 407 getAbsoluteName() 408 { 409 java.lang.String result = ""; 410 if(the_parent_ != null) 411 result = the_parent_.getAbsoluteName(); 412 413 if(name_ != null) 414 result = result + "::" + name_; 415 416 return result; 417 } 418 419 425 public java.lang.String 426 getVersion() 427 { 428 return version_; 429 } 430 431 436 public java.lang.String 437 getId() 438 { 439 if (id_ != null) 440 return id_; 441 442 return "IDL:" + computeBaseRID() + ':' + version_; 443 } 444 445 450 public int 451 getDeclKind() 452 { 453 return the_declaration_kind_; 454 } 455 456 462 public Scope 463 getParent() 464 { 465 return the_parent_; 466 } 467 468 475 public Declaration[] 476 getDependencies() 477 { 478 return new Declaration[0]; 479 } 480 481 488 491 public boolean 492 isDeclaration() 493 { 494 return true; 495 } 496 497 503 506 public void 507 addRef() 508 { 509 nb_refs_++; 510 } 511 512 515 public void 516 removeRef() 517 { 518 nb_refs_--; 519 } 520 } 521 | Popular Tags |