1 26 27 package org.objectweb.openccm.ast.lib; 28 29 import org.objectweb.openccm.ast.api.DeclarationCategory; 31 import org.objectweb.openccm.ast.api.Declaration; 32 import org.objectweb.openccm.ast.api.AST; 33 import org.objectweb.openccm.ast.api.Scope; 34 35 36 47 48 abstract public class DeclarationImpl 49 extends WithNameImpl 50 implements Declaration 51 { 52 58 59 protected java.lang.String prefix_; 60 61 62 protected java.lang.String version_; 63 64 65 protected java.lang.String id_; 66 67 68 protected boolean is_imported_; 69 70 71 protected Repository the_repository_; 72 73 74 protected ScopeImpl the_parent_; 75 76 77 protected boolean is_mapping_; 78 79 80 protected Declaration[] dependencies_; 81 82 88 94 protected 95 DeclarationImpl(Repository rep, 96 ScopeImpl parent) 97 { 98 super(); 100 101 the_repository_ = rep; 103 the_parent_ = parent; 104 prefix_ = null; 105 version_ = "1.0"; 106 id_ = null; 107 is_imported_ = false; 108 is_mapping_ = false; 109 dependencies_ = null; 110 } 111 112 118 123 protected java.lang.String 124 computePrefix() 125 { 126 int idx1 = id_.indexOf(':'); 127 int idx2 = id_.indexOf('/'); 128 129 java.lang.String pname = the_parent_.getName(); 130 if ( (pname==null) || 131 (pname.equals("")) || 132 (the_parent_ instanceof org.objectweb.openccm.ast.api.FileScope) ) 133 { 135 if (id_.indexOf(name_)==-1) 137 return null; 139 else if (idx2!=-1) 140 return id_.substring(idx1+1,idx2); 142 else 143 return null; 145 } 146 else 147 { 148 if (id_.indexOf(name_)==-1) 150 return null; 152 else if (id_.indexOf(the_parent_.computeBaseRID())==-1) 153 return id_.substring(idx1+1, idx2); 163 else 164 return null; 166 } 167 } 168 169 175 protected java.lang.String 176 computeBaseRID() 177 { 178 java.lang.String result = ""; 179 180 if (prefix_ != null) 181 result = prefix_; 182 if( (the_parent_ != null) && 183 (the_parent_.getName()!=null) && 184 (!the_parent_.getName().equals("")) && 185 (!(the_parent_ instanceof org.objectweb.openccm.ast.api.FileScope)) ) 186 { 187 result = the_parent_.computeBaseRID(); 189 } 190 191 if (name_ != null) 192 { 193 if (result.length() != 0) 194 result = result + '/' + name_; 195 else 196 result = name_; 197 } 198 199 return result; 200 } 201 202 206 protected void 207 setImported() 208 { 209 is_imported_ = true; 210 } 211 212 215 protected Repository 216 getRepository() 217 { 218 return the_repository_; 219 } 220 221 226 protected void 227 load(org.omg.CORBA.Contained contained) 228 { 229 version_ = contained.version(); 230 id_ = contained.id(); 231 prefix_ = computePrefix(); 232 the_repository_.addDeclInRep(getId(), this); 233 if (the_parent_!=null) 234 the_parent_.addDecl(this); 235 } 236 237 242 protected void 243 loadAsMapping(org.omg.CORBA.Contained contained) 244 { 245 247 version_ = contained.version(); 248 id_ = contained.id(); 249 prefix_ = computePrefix(); 250 the_repository_.addMappedDeclInRep(getId(), this); 251 is_mapping_ = true; 252 if ((the_parent_!=null) && 254 (the_parent_.is_mapping_)) 255 the_parent_.addDecl(this); 256 } 257 258 263 abstract protected org.omg.CORBA.Contained 264 getContained(); 265 266 272 277 public String 278 getIdPrefix() 279 { 280 if (getCategory() == DeclarationCategory.dc_cidl) 281 return "CIDL"; 282 if (getCategory() == DeclarationCategory.dc_psdl) 283 return "PSDL"; 284 return "IDL"; 285 } 286 287 290 public boolean 291 isDeclaration() 292 { 293 return true; 294 } 295 296 302 309 public Declaration[] 310 getDependencies() 311 { 312 return new Declaration[0]; 313 } 314 315 321 328 abstract public long 329 getDeclKind(); 330 331 336 public java.lang.String 337 getAbsoluteName() 338 { 339 java.lang.String result = ""; 340 if(the_parent_ != null) 341 result = the_parent_.getAbsoluteName(); 342 343 if(name_ != null) 344 result = result + "::" + name_; 345 346 return result; 347 } 348 349 354 public void 355 setId(java.lang.String id) 356 { 357 id_ = id; 358 the_repository_.addDeclInRep(id, this); 359 org.omg.CORBA.Contained contained = getContained(); 360 if (contained != null) 361 contained.id(id_); 362 } 363 364 369 public java.lang.String 370 getId() 371 { 372 if (id_ != null) 373 return id_; 374 375 return getIdPrefix() + ':' + computeBaseRID() + ':' + version_; 376 } 377 378 386 public void 387 setPrefix(java.lang.String prefix) 388 { 389 prefix_ = prefix; 390 391 org.omg.CORBA.Contained contained = getContained(); 392 if (contained != null) 393 contained.id(getId()); 394 } 395 396 402 public java.lang.String 403 getPrefix() 404 { 405 if (prefix_!=null) 406 return prefix_; 407 if ( (the_parent_!=null) && 408 (the_parent_.getName()!=null) && 409 (!the_parent_.getName().equals("")) ) 410 return the_parent_.getPrefix(); 411 412 return ""; 413 } 414 415 420 public void 421 setVersion(java.lang.String version) 422 { 423 version_ = version; 424 org.omg.CORBA.Contained contained = getContained(); 425 if (contained != null) 426 contained.version(version); 427 } 428 429 435 public java.lang.String 436 getVersion() 437 { 438 return version_; 439 } 440 441 447 public Scope 448 getParent() 449 { 450 return the_parent_; 451 } 452 453 456 public void 457 create() 458 { 459 if (the_parent_!=null) 460 the_parent_.addDecl(this); 461 } 462 463 466 public void 467 destroy() 468 { 469 org.omg.CORBA.IRObject obj = (org.omg.CORBA.IRObject )getContained(); 470 if (obj != null) 471 { 472 if (!is_imported_) 474 obj.destroy(); 475 476 the_repository_.removeDeclFromRep(getId()); 477 if (the_parent_!=null) 478 the_parent_.removeDecl(name_); 479 } 480 } 481 482 485 public AST 486 getAST() 487 { 488 return the_repository_; 489 } 490 491 496 public DeclarationCategory 497 getCategory() 498 { 499 return DeclarationCategory.dc_idl; 500 } 501 502 505 public void 506 check() 507 { 508 } 510 511 514 public void 515 print() 516 { 517 System.out.println(getAbsoluteName()); 518 } 519 } 520 | Popular Tags |