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.StorageTypeDecl; 33 import org.objectweb.openccm.ast.api.StorageHomeDecl; 34 import org.objectweb.openccm.ast.api.AbstractStorageTypeDecl; 35 import org.objectweb.openccm.ast.api.AbstractStorageHomeDecl; 36 37 38 import org.objectweb.openccm.ast.api.Declaration; 39 40 41 import org.objectweb.openccm.ast.api.ASTError; 42 43 73 74 public class StorageHomeDeclImpl 75 extends StorageHomeBaseImpl 76 implements org.objectweb.openccm.ast.api.StorageHomeDecl 77 { 78 84 85 protected StorageTypeDeclImpl managedStorageType_; 86 87 88 protected StorageHomeDeclImpl baseStorageHome_; 89 90 91 protected String primaryKeyName_; 92 93 94 protected boolean isPrimaryKeyRef_; 95 96 102 107 protected 108 StorageHomeDeclImpl(Repository rep, 109 ScopeImpl parent) 110 { 111 super(rep, parent); 113 114 managedStorageType_ = null; 116 baseStorageHome_ = null; 117 primaryKeyName_ = null; 118 isPrimaryKeyRef_ = false; 119 } 120 121 127 133 140 public long 141 getDeclKind() 142 { 143 return DeclarationKind.dk_storage_home; 144 } 145 146 147 150 public void 151 create() 152 { 153 super.create(); 155 156 if(primaryKeyName_ != null) 158 { 159 java.util.List keys = new java.util.ArrayList (); 160 161 int size = 0; 162 size = abstract_storagehomes_.getSize(); 163 for (int i=0; i<size; i++) 164 { 165 AbstractStorageHomeDeclImpl ash = (AbstractStorageHomeDeclImpl)abstract_storagehomes_.get(i); 166 Declaration decls[] = ash.getKeys(); 167 if(decls != null) 168 { 169 for(int j=0; j<decls.length; j++) 170 keys.add( decls[j] ); 171 } 172 } 173 174 int i = 0; 175 boolean found = false; 176 177 size = keys.size(); 178 while( (i<size) && !found) 179 { 180 if( primaryKeyName_.compareTo(((Declaration)keys.get(i)).getName()) == 0 ) 181 found = true; 182 i++; 183 } 184 if(!found) 185 { 186 throw new ASTError(getName() +" : " + primaryKeyName_ + " is not a valid primary key."); 187 } 188 } 189 190 java.util.List ast_required = new java.util.ArrayList (); 192 AbstractStorageHomeListImpl ash_list = null; 193 int size = 0; 194 195 ash_list = (AbstractStorageHomeListImpl)getAbstractStorageHomeList(); 197 size = ash_list.getSize(); 198 for(int i=0; i<size; i++) 199 { 200 AbstractStorageHomeDeclImpl ash = (AbstractStorageHomeDeclImpl)ash_list.get(i); 201 AbstractStorageTypeDeclImpl ast = (AbstractStorageTypeDeclImpl)ash.getAbstractStorageType(); 202 ast_required.add(ast); 203 } 204 205 AbstractStorageTypeDecl[] ast_list = null; 207 java.util.ArrayList implemented_ast_found = new java.util.ArrayList (); 208 209 ast_list = managedStorageType_.getAllImplementedAbstractStorageTypes().getAbstractStorageTypes(); 210 for(int i=0; i<ast_list.length; i++) 211 { 212 implemented_ast_found.add(ast_list[i]); 213 } 214 215 216 if(!implemented_ast_found.containsAll(ast_required)) 217 throw new ASTError(getName() + " has not a valid storage type."); 218 219 } 220 221 227 233 239 245 251 257 263 266 public void 267 check() 268 { 269 super.check(managedStorageType_); 271 } 272 273 279 285 291 297 302 public void 303 setStorageType(StorageTypeDecl st) 304 { 305 if(st != null) 306 { 307 managedStorageType_ = (StorageTypeDeclImpl)st; 308 } 309 } 310 311 316 public StorageTypeDecl 317 getStorageType() 318 { 319 return managedStorageType_; 320 } 321 322 327 public void 328 setBaseStorageHome(StorageHomeDecl sh) 329 { 330 if(sh != null) 331 { 332 baseStorageHome_ = (StorageHomeDeclImpl)sh; 333 } 334 } 335 336 341 public StorageHomeDecl 342 getBaseStorageHome() 343 { 344 return baseStorageHome_; 345 } 346 347 352 public void 353 setPrimaryKeyName(String name) 354 { 355 primaryKeyName_ = name; 356 } 357 358 363 public String 364 getPrimaryKeyName() 365 { 366 return primaryKeyName_; 367 } 368 369 374 public void 375 setPrimaryKeyRef(boolean b) 376 { 377 isPrimaryKeyRef_ = b; 378 } 379 380 385 public boolean 386 isPrimaryKeyRef() 387 { 388 return isPrimaryKeyRef_; 389 } 390 391 396 public AbstractStorageHomeDecl[] 397 getDirectlyImplementedAbstractStorageHomes() 398 { 399 AbstractStorageHomeDecl[] sh_base_implemented = null, 400 ash_implemented = null, 401 result = null; 402 403 ash_implemented = 404 getAllImplementedAbstractStorageHomes().getAbstractStorageHomes(); 405 406 if (getBaseStorageHome() == null) 407 { 408 return ash_implemented; 409 } 410 411 sh_base_implemented = 412 getBaseStorageHome().getAllImplementedAbstractStorageHomes().getAbstractStorageHomes(); 413 414 java.util.Set base_list = new java.util.HashSet (); 417 for (int i=0; i<sh_base_implemented.length; i++) 418 { 419 base_list.add(sh_base_implemented[i]); 420 } 421 422 java.util.Set own_list = new java.util.HashSet (); 424 for (int i=0; i<ash_implemented.length; i++) 425 { 426 own_list.add(ash_implemented[i]); 427 } 428 429 own_list.removeAll(base_list); 431 result = (AbstractStorageHomeDecl[])own_list.toArray(new AbstractStorageHomeDecl[0]); 432 return result; 433 } 434 } 435 | Popular Tags |