1 26 27 package org.objectweb.openccm.ast.lib; 28 29 30 import org.objectweb.openccm.ast.api.DeclarationKind; 31 32 33 import org.objectweb.openccm.ast.api.Declaration; 34 35 36 import org.objectweb.openccm.ast.api.ExceptionDecl; 37 38 39 import org.objectweb.openccm.ast.api.ExceptionList; 40 41 42 import org.omg.CORBA.ExtAttributeDef; 43 import org.omg.CORBA.ExtAttributeDefHelper; 44 45 46 import org.omg.CORBA.AttributeMode ; 47 48 49 import org.omg.CORBA.ExceptionDef ; 50 51 63 64 public class AttributeDeclImpl 65 extends DeclarationWithTypeRefImpl 66 implements org.objectweb.openccm.ast.api.AttributeDecl 67 { 68 74 75 private ExtAttributeDef ext_attribute_def_; 76 77 78 private AttributeMode mode_; 79 80 81 private ExceptionListImpl get_exceptions_; 82 83 84 private ExceptionListImpl set_exceptions_; 85 86 92 98 protected 99 AttributeDeclImpl(Repository rep, 100 ScopeImpl parent) 101 { 102 super(rep, parent); 104 105 ext_attribute_def_ = null; 107 mode_ = AttributeMode.ATTR_NORMAL; 108 get_exceptions_ = new ExceptionListImpl(); 109 set_exceptions_ = new ExceptionListImpl(); 110 } 111 112 118 124 protected void 125 addDependencies(java.util.List attr_depend, 126 ExceptionDecl[] excs) 127 { 128 Declaration[] depend = null; 129 for (int i=0;i<excs.length;i++) 130 { 131 attr_depend.add(excs[i]); 132 depend = excs[i].getDependencies(); 133 for (int j=0;j<depend.length;j++) 134 { 135 if (attr_depend.indexOf(depend[j])==-1) 136 attr_depend.add(depend[j]); 137 } 138 } 139 } 140 141 147 152 protected void 153 load(org.omg.CORBA.Contained contained) 154 { 155 ext_attribute_def_ = ExtAttributeDefHelper.narrow(contained); 156 mode_ = ext_attribute_def_.mode(); 157 setType(getRepository().getAsTypeRef(ext_attribute_def_.type_def())); 158 159 ExceptionDef [] exc = ext_attribute_def_.get_exceptions(); 160 for (int i=0; i<exc.length; i++) 161 get_exceptions_.add((ExceptionDecl)getRepository(). 162 lookupId(exc[i].id())); 163 164 exc = ext_attribute_def_.set_exceptions(); 165 for (int i=0; i<exc.length; i++) 166 set_exceptions_.add((ExceptionDecl)getRepository(). 167 lookupId(exc[i].id())); 168 169 super.load(contained); 170 } 171 172 177 protected void 178 loadAsMapping(org.omg.CORBA.Contained contained) 179 { 180 ext_attribute_def_ = ExtAttributeDefHelper.narrow(contained); 181 mode_ = ext_attribute_def_.mode(); 182 setType(getRepository(). 183 getAsMappedTypeRef(ext_attribute_def_.type_def())); 184 185 ExceptionDef [] exc = ext_attribute_def_.get_exceptions(); 186 for (int i=0; i<exc.length; i++) 187 get_exceptions_.add((ExceptionDecl)getRepository(). 188 lookupMappedId(exc[i].id())); 189 190 exc = ext_attribute_def_.set_exceptions(); 191 for (int i=0; i<exc.length; i++) 192 set_exceptions_.add((ExceptionDecl)getRepository(). 193 lookupMappedId(exc[i].id())); 194 195 super.loadAsMapping(contained); 196 } 197 198 204 protected org.omg.CORBA.Contained 205 getContained() 206 { 207 return ext_attribute_def_; 208 } 209 210 216 222 230 public Declaration[] 231 getDependencies() 232 { 233 if (dependencies_!=null) 234 return dependencies_; 235 236 java.util.List attr_depend = new java.util.ArrayList (); 237 Declaration[] depend = null; 238 239 if (getType().isDeclaration()) 241 attr_depend.add(getType()); 242 243 depend = getType().getDependencies(); 244 for (int i=0; i<depend.length; i++) 245 attr_depend.add(depend[i]); 246 247 if (isReadonly()) 249 addDependencies(attr_depend, getExceptions()); 250 else 251 { 252 addDependencies(attr_depend, getGetExceptions()); 253 addDependencies(attr_depend, getSetExceptions()); 254 } 255 256 dependencies_ = (Declaration[])attr_depend.toArray(new Declaration[0]); 257 return dependencies_; 258 } 259 260 266 271 public long 272 getDeclKind() 273 { 274 return DeclarationKind.dk_attribute; 275 } 276 277 280 public void 281 create() 282 { 283 ext_attribute_def_ = the_parent_.createExtAttribute(this, 284 getIDLType(), mode_, 285 get_exceptions_.getExceptionDefSeq(), 286 set_exceptions_.getExceptionDefSeq()); 287 super.create(); 288 } 289 290 296 299 public void 300 setNormal() 301 { 302 mode_ = AttributeMode.ATTR_NORMAL; 303 } 304 305 310 public boolean 311 isNormal() 312 { 313 return mode_ == AttributeMode.ATTR_NORMAL; 314 } 315 316 319 public void 320 setReadonly() 321 { 322 mode_ = AttributeMode.ATTR_READONLY; 323 } 324 325 330 public boolean 331 isReadonly() 332 { 333 return mode_ == AttributeMode.ATTR_READONLY; 334 } 335 336 342 public ExceptionList 343 getGetExceptionList() 344 { 345 return get_exceptions_; 346 } 347 348 354 public ExceptionDecl[] 355 getGetExceptions() 356 { 357 if (isNormal()) 358 return get_exceptions_.getExceptions(); 359 return new ExceptionDecl[0]; 360 } 361 362 369 public ExceptionList 370 getSetExceptionList() 371 { 372 return set_exceptions_; 373 } 374 375 382 public ExceptionDecl[] 383 getSetExceptions() 384 { 385 if (isNormal()) 386 return set_exceptions_.getExceptions(); 387 return new ExceptionDecl[0]; 388 } 389 390 397 public ExceptionList 398 getExceptionList() 399 { 400 if (isReadonly()) 401 return get_exceptions_; 402 else 403 return new ExceptionListImpl(); 404 } 405 406 413 public ExceptionDecl[] 414 getExceptions() 415 { 416 if (isReadonly()) 417 return get_exceptions_.getExceptions(); 418 else 419 return new ExceptionDecl[0]; 420 } 421 } 422 | Popular Tags |