1 26 27 package org.objectweb.openccm.pss.generator.common.lib; 28 29 31 import org.objectweb.openccm.ast.api.StorageHomeDecl; 32 import org.objectweb.openccm.ast.api.AbstractStorageHomeDecl; 33 import org.objectweb.openccm.ast.api.AbstractStorageTypeDecl; 34 import org.objectweb.openccm.ast.api.StorageTypeDecl; 35 import org.objectweb.openccm.ast.api.StorageHomeKeyDecl; 36 import org.objectweb.openccm.ast.api.StorageHomeFactoryDecl; 37 import org.objectweb.openccm.ast.api.StorageTypeStateMemberDecl; 38 import org.objectweb.openccm.ast.api.DeclarationKind; 39 import org.objectweb.openccm.ast.api.Declaration; 40 41 import org.objectweb.openccm.generator.java.ast.api.*; 42 import org.objectweb.openccm.generator.java.ast.lib.*; 43 44 import org.objectweb.openccm.generator.common.lib.GenerationException; 45 import org.objectweb.openccm.pss.generator.common.api.PSDL2JavaGenerator; 46 47 import java.util.List ; 48 49 50 57 58 public abstract class StorageHomeMapping 59 implements org.objectweb.openccm.pss.generator.common.api.StorageHomeMapping 60 { 61 62 68 69 private StorageHomeDecl sh_; 70 71 77 80 81 public StorageHomeMapping() 82 { 83 sh_ = null; 85 } 86 87 93 101 private boolean 102 hasOperation(AbstractStorageHomeDecl ash) 103 { 104 Declaration[] decls = null; 105 decls = ash.getContents(true, DeclarationKind.dk_psdl_operation); 106 if (decls.length > 0) 107 { 108 return true; 109 } 110 else 111 { 112 AbstractStorageHomeDecl[] implemented = null; 114 115 implemented = ash.getAbstractStorageHomeList().getAbstractStorageHomes(); 116 for (int i=0; i<implemented.length; i++) 117 { 118 if ( hasOperation(implemented[i]) ) 119 return true; 120 } 121 return false; 122 } 123 } 124 125 131 private void 132 mapStorageHomeCreateOperations( PSDL2JavaGenerator generator, 133 ClassObject obj ) 134 throws GenerationException 135 { 136 MethodObject method = null; 137 ParameterObject param = null; 138 StorageTypeDecl managed = null, 139 managed_base = null; 140 AbstractStorageTypeDecl[] ast_impl_directly = null;; 141 StorageTypeStateMemberDecl[] all_states = null; 142 List vect = new java.util.ArrayList (); 143 java.util.List states = null; 144 145 146 managed = sh_.getStorageType(); 147 148 149 managed_base = managed.getBaseStorageType(); 151 if (managed_base != null) 152 { 153 vect.addAll( generator.getDeclarations(managed_base, DeclarationKind.dk_storage_type_state_member) ); 154 all_states = (StorageTypeStateMemberDecl[])vect.toArray(new StorageTypeStateMemberDecl[0]); 155 } 156 ast_impl_directly = managed.getAllImplementedAbstractStorageTypes().getAbstractStorageTypes(); 158 for (int j=0; j<ast_impl_directly.length; j++) 159 { 160 vect.addAll( 161 generator.getDeclarations(ast_impl_directly[j], DeclarationKind.dk_storage_type_state_member) ); 162 } 163 vect.addAll( generator.getDeclarations(managed, DeclarationKind.dk_storage_type_state_member) ); 165 all_states = (StorageTypeStateMemberDecl[])vect.toArray(new StorageTypeStateMemberDecl[0]); 166 167 168 method = new MethodObjectImpl(); 169 method.addComment("The generic create method."); 170 method.setName("create_st_incarnation"); 171 method.setReturnType( generator.getTranslator().getAbsoluteName(managed) ); 172 method.getImpl().setMacro("SH_CREATE_ST_INCARNATION"); 173 method.getImpl().addContextValue("st_type", generator.getTranslator().getAbsoluteName(managed)); 174 obj.addMethod(method); 175 176 178 method = new MethodObjectImpl(); 179 method.addComment("A create method."); 180 method.setName("_create"); 181 method.setReturnType( generator.getTranslator().getAbsoluteName(managed) ); 182 states = new java.util.ArrayList (); 183 for (int i=0; i<all_states.length; i++) 184 { 185 org.objectweb.openccm.pss.generator.common.api.StateMemberMapping state = null; 186 187 state = (org.objectweb.openccm.pss.generator.common.api.StateMemberMapping) 188 MappingObjectFactory.getClass("StateMemberMapping"); 189 state.setStateMember(all_states[i]); 190 state.toJavaParameter(generator.getTranslator(), method); 191 states.add(all_states[i]); 192 } 193 method.getImpl().setMacro("SH_CREATE1_METHOD"); 194 method.getImpl().addContextValue("states", states); 195 method.getImpl().addContextValue("st_type", generator.getTranslator().getAbsoluteName(managed)); 196 obj.addMethod(method); 197 198 200 method = new MethodObjectImpl(); 201 method.addComment("A create method."); 202 method.setName("_create"); 203 method.setReturnType( generator.getTranslator().getAbsoluteName(managed) ); 204 states = new java.util.ArrayList (); 205 for (int i=0; i<all_states.length; i++) 206 { 207 if (all_states[i].getType().isRef()) 208 { 209 org.objectweb.openccm.pss.generator.common.api.StateMemberMapping state = null; 210 211 state = (org.objectweb.openccm.pss.generator.common.api.StateMemberMapping) 212 MappingObjectFactory.getClass("StateMemberMapping"); 213 state.setStateMember(all_states[i]); 214 state.toJavaParameter(generator.getTranslator(), method); 215 states.add(all_states[i]); 216 } 217 } 218 method.getImpl().setMacro("SH_CREATE1_METHOD"); 219 method.getImpl().addContextValue("states", states); 220 method.getImpl().addContextValue("st_type", generator.getTranslator().getAbsoluteName(managed)); 221 obj.addMethod(method); 222 223 226 method = new MethodObjectImpl(); 227 method.addComment("A create method."); 228 method.addComment(" "); 229 method.setName("_create"); 230 method.setReturnType("byte[]"); 231 states = new java.util.ArrayList (); 232 for (int i=0; i<all_states.length; i++) 233 { 234 org.objectweb.openccm.pss.generator.common.api.StateMemberMapping state = null; 235 236 state = (org.objectweb.openccm.pss.generator.common.api.StateMemberMapping) 237 MappingObjectFactory.getClass("StateMemberMapping"); 238 state.setStateMember(all_states[i]); 239 state.toJavaParameter(generator.getTranslator(), method); 240 states.add(all_states[i]); 241 } 242 param = new ParameterObjectImpl(); 243 param.setName("yr"); 244 param.setType("org.omg.CosPersistentState.YieldRef"); 245 method.addParameter(param); 246 method.getImpl().setMacro("SH_CREATE2_METHOD"); 247 method.getImpl().addContextValue("states", states); 248 method.getImpl().addContextValue("st_type", generator.getTranslator().getAbsoluteName(managed)); 249 obj.addMethod(method); 250 251 254 method = new MethodObjectImpl(); 255 method.addComment("A create method."); 256 method.setName("_create"); 257 method.setReturnType("byte[]"); 258 states = new java.util.ArrayList (); 259 for (int i=0; i<all_states.length; i++) 260 { 261 if (all_states[i].getType().isRef()) 262 { 263 org.objectweb.openccm.pss.generator.common.api.StateMemberMapping state = null; 264 265 state = (org.objectweb.openccm.pss.generator.common.api.StateMemberMapping) 266 MappingObjectFactory.getClass("StateMemberMapping"); 267 state.setStateMember(all_states[i]); 268 269 state.toJavaParameter(generator.getTranslator(), method); 270 states.add(all_states[i]); 271 } 272 } 273 param = new ParameterObjectImpl(); 274 param.setName("yr"); 275 param.setType("org.omg.CosPersistentState.YieldRef"); 276 method.addParameter(param); 277 method.getImpl().setMacro("SH_CREATE2_METHOD"); 278 method.getImpl().addContextValue("states", states); 279 method.getImpl().addContextValue("st_type", generator.getTranslator().getAbsoluteName(managed)); 280 obj.addMethod(method); 281 } 282 283 288 abstract protected String 289 getStorageHomeBaseClass(); 290 291 297 302 public void 303 setStorageHome(StorageHomeDecl sh) 304 { 305 sh_ = sh; 306 } 307 308 313 public void 314 toJava(PSDL2JavaGenerator generator) 315 throws GenerationException 316 { 317 ClassObject clazz = null; 318 ConstructorObject ct = null; 319 MethodObject method = null; 320 AttributeObject att = null; 321 ParameterObject param = null; 322 AbstractStorageHomeDecl[] implemented = null, 323 impl_directly = null;; 324 StorageHomeDecl base = null; 325 StorageHomeKeyDecl[] keys = null; 326 StorageHomeFactoryDecl[] factories = null; 327 List vect = null; 328 329 clazz = new ClassObjectImpl(sh_.getName()); 330 clazz.addComment(" Storage Home "+sh_.getName()); 331 clazz.addComment(""); 332 clazz.addComment(" @author OpenCCM PSDL Compiler"); 333 clazz.setModifier(ModifierKindImpl.mk_public); 334 clazz.setPackage(generator.getTranslator().getPackage(sh_)); 335 336 implemented = sh_.getAbstractStorageHomeList().getAbstractStorageHomes(); 338 for (int i=0; i<implemented.length; i++) 339 { 340 clazz.addImplementedObject(generator.getTranslator().getAbsoluteName(implemented[i])); 341 } 342 343 clazz.addImplementedObject("org.objectweb.openccm.pss.runtime.common.api.StorageHomeBase"); 345 346 int i = 0; 348 boolean found = false; 349 clazz.setAbstract(false); 350 while ((i<implemented.length) && !found) 351 { 352 if (hasOperation(implemented[i])) 353 { 354 clazz.setAbstract(true); 355 found = true; 356 } 357 i++; 358 } 359 360 base = sh_.getBaseStorageHome(); 362 if (base != null) 363 clazz.addInheritedObject( generator.getTranslator().getAbsoluteName(base) ); 364 else 365 clazz.addInheritedObject( getStorageHomeBaseClass() ); 366 367 ct = new ConstructorObjectImpl(); 369 clazz.addConstructor(ct); 370 371 impl_directly = sh_.getDirectlyImplementedAbstractStorageHomes(); 374 for (int j=0; j<impl_directly.length; j++) 375 { 376 vect = generator.getDeclarations(impl_directly[j], DeclarationKind.dk_storage_home_factory); 378 factories = (StorageHomeFactoryDecl[])vect.toArray(new StorageHomeFactoryDecl[0]); 379 for (int k=0; k<factories.length; k++) 380 { 381 org.objectweb.openccm.pss.generator.common.api.PSDLFactoryMapping factory = null; 382 383 factory = (org.objectweb.openccm.pss.generator.common.api.PSDLFactoryMapping) 384 MappingObjectFactory.getClass("PSDLFactoryMapping"); 385 factory.setFactory(factories[k]); 386 factory.toJava(generator, clazz, impl_directly[j].getAbstractStorageType(), sh_.getStorageType()); 387 } 388 vect = generator.getDeclarations(impl_directly[j], DeclarationKind.dk_storage_home_key); 390 keys = (StorageHomeKeyDecl[])vect.toArray(new StorageHomeKeyDecl[0]); 391 for (int k=0; k<keys.length; k++) 392 { 393 org.objectweb.openccm.pss.generator.common.api.PSDLKeyMapping key = null; 394 395 key = (org.objectweb.openccm.pss.generator.common.api.PSDLKeyMapping) 396 MappingObjectFactory.getClass("PSDLKeyMapping"); 397 key.setKey(keys[k]); 398 key.toJava(generator, clazz, impl_directly[j].getAbstractStorageType()); 399 } 400 } 401 402 mapStorageHomeCreateOperations(generator, clazz); 404 405 method = new MethodObjectImpl(); 407 method.addComment("Get the Repository ID of a storage home."); 408 method.setName("get_rid"); 409 method.setReturnType("java.lang.String"); 410 method.getImpl().setMacro("SH_GET_RID_METHOD"); 411 method.getImpl().addContextValue("sh_rid", sh_.getId()); 412 clazz.addMethod(method); 413 414 method = new MethodObjectImpl(); 416 method.addComment("Get the Repository ID of the managed storage type."); 417 method.setName("get_st_rid"); 418 method.setReturnType("java.lang.String"); 419 method.getImpl().setMacro("SH_GET_ST_RID_METHOD"); 420 method.getImpl().addContextValue("st_rid", sh_.getStorageType().getId()); 421 clazz.addMethod(method); 422 423 generator.getJavaRepository().addObject(clazz); 424 } 425 426 } 427 | Popular Tags |