1 26 27 package org.objectweb.openccm.ast.lib; 28 29 30 import org.objectweb.openccm.ast.api.DeclarationKind; 31 32 import org.objectweb.openccm.ast.api.StringList; 33 34 import org.objectweb.openccm.ast.api.StorageTypeDecl; 35 import org.objectweb.openccm.ast.api.AbstractStorageTypeDecl; 36 37 38 import org.objectweb.openccm.ast.api.ASTError; 39 40 64 65 public class StorageTypeDeclImpl 66 extends StorageTypeBaseImpl 67 implements org.objectweb.openccm.ast.api.StorageTypeDecl 68 { 69 75 76 protected StorageTypeDeclImpl baseStorageType_; 77 78 79 protected StringListImpl refRepDirectiveList_; 80 81 87 92 protected 93 StorageTypeDeclImpl(Repository rep, 94 ScopeImpl parent) 95 { 96 super(rep, parent); 98 99 baseStorageType_ = null; 101 refRepDirectiveList_ = new StringListImpl(); 102 } 103 104 110 117 protected boolean 118 isValidState(String state) 119 { 120 boolean found = super.isValidState(state); 122 123 if(baseStorageType_ == null) 124 return found; 125 if(!found) 126 return baseStorageType_.isValidState(state); 128 else 129 return true; 130 } 131 132 138 145 public long 146 getDeclKind() 147 { 148 return DeclarationKind.dk_storage_type; 149 } 150 151 157 163 169 175 181 187 190 public void 191 create() 192 { 193 super.create(); 195 196 int index = refRepDirectiveList_.checkSameItem(); 198 if( index != -1 ) 199 { 200 throw new ASTError( (String )refRepDirectiveList_.get(index) + " must be specified once and once only."); 201 } 202 } 203 204 207 public void 208 check() 209 { 210 211 int size = refRepDirectiveList_.getSize(); 212 213 if( (size>0) && (baseStorageType_ != null) ) 215 { 216 throw new ASTError( getName() + 217 " has a based storage type. This is not consistent with a reference representation directive!" ); 218 } 219 220 for(int i=0; i<size; i++) 222 { 223 String state = (String )refRepDirectiveList_.get(i); 224 if( isValidState(state) == false) 225 { 226 throw new ASTError(getName() + " => " + state + " is not a valid state member." ); 227 } 228 } 229 230 235 org.objectweb.openccm.ast.api.AbstractStorageTypeDecl[] ast_decls = null; 236 237 ast_decls = getDirectlyImplementedAbstractStorageTypes(); 239 for(int i=0; i<ast_decls.length; i++) 241 { 242 org.objectweb.openccm.ast.api.Declaration[] decls = null; 245 decls = ast_decls[i].getContents(true, org.objectweb.openccm.ast.api.DeclarationKind.dk_storage_type_state_member); 246 for(int j=0; j<decls.length; j++) 247 { 248 org.objectweb.openccm.ast.api.StorageTypeStateMemberDecl 249 member = (org.objectweb.openccm.ast.api.StorageTypeStateMemberDecl)decls[j]; 250 org.objectweb.openccm.ast.api.StorageTypeBase type = member.getType().getStorageTypeBase(); 251 if ( (type != null) && (!member.getType().isRef()) ) 252 { 253 String name = getAbsoluteName()+"::"+decls[j].getName()+"_store_directive"; 255 org.objectweb.openccm.ast.api.Declaration store_directive = lookup(name); 256 if (store_directive == null) 257 throw new ASTError( 258 getAbsoluteName()+" : No store directive found for "+decls[j].getName()); 259 } 260 } 261 } 262 263 } 264 265 271 277 283 289 294 public void 295 setBaseStorageType(StorageTypeDecl st) 296 { 297 if(st != null) 298 { 299 baseStorageType_ = (StorageTypeDeclImpl)st; 300 } 301 } 302 303 308 public StorageTypeDecl 309 getBaseStorageType() 310 { 311 return baseStorageType_; 312 } 313 314 319 public StringList 320 getRefRepDirectiveList() 321 { 322 return refRepDirectiveList_; 323 } 324 325 330 public AbstractStorageTypeDecl[] 331 getDirectlyImplementedAbstractStorageTypes() 332 { 333 AbstractStorageTypeDecl[] st_base_implemented = null, 334 ast_implemented = null, 335 result = null; 336 337 ast_implemented = 338 getAllImplementedAbstractStorageTypes().getAbstractStorageTypes(); 339 340 if (getBaseStorageType() == null) 341 { 342 return ast_implemented; 343 } 344 345 st_base_implemented = 346 getBaseStorageType().getAllImplementedAbstractStorageTypes().getAbstractStorageTypes(); 347 348 java.util.Set base_list = new java.util.HashSet (); 351 for (int i=0; i<st_base_implemented.length; i++) 352 { 353 base_list.add(st_base_implemented[i]); 354 } 355 356 java.util.Set own_list = new java.util.HashSet (); 358 for (int i=0; i<ast_implemented.length; i++) 359 { 360 own_list.add(ast_implemented[i]); 361 } 362 363 own_list.removeAll(base_list); 365 result = (AbstractStorageTypeDecl[])own_list.toArray(new AbstractStorageTypeDecl[0]); 366 return result; 367 } 368 } 369 | Popular Tags |