1 package org.objectweb.modfact.jmi.ps; 2 3 import javax.jmi.reflect.*; 4 import java.util.*; 5 import org.objectweb.modfact.jmi.reflect.*; 6 import java.sql.SQLException ; 7 8 16 public class PersistantService { 17 18 19 private RefPackage repository; 20 21 22 public PersistantService(){ 23 this.repository = RefPackageImpl.getM2Repository(); 24 } 25 26 27 36 37 public boolean load(String name) throws ClassNotFoundException , SQLException { 38 39 if(isLoaded(name)) 40 return true; 41 else{ 42 43 Reader psReader = new Reader(name, repository); 44 psReader.read(); 45 return true; 46 } 47 48 49 } 50 51 52 57 private boolean isLoaded(String metamodel){ 58 RefObject o = null ; 59 Iterator it = repository.refAllPackages().iterator(); 60 while( it.hasNext()){ 61 if(((RefObject)it.next()).refGetValue("name").equals(metamodel)) 62 return true; 63 } 64 return false; 65 66 } 67 68 69 78 public void store(String name) 79 throws ClassNotFoundException , SQLException { 80 81 boolean modelExist; 82 String modelId; 83 String elementId; 84 modelExist = PersistantHelper.ifModelExist(name); 85 if (!modelExist) 86 PersistantHelper.createMetamodel(name); 87 else 88 PersistantHelper.deleteMetamodelContent(name); 89 90 modelId = PersistantHelper.getModelIdbyName(name); 91 92 MOFPolymorphicIterator mofIt = new MOFPolymorphicIterator(repository); 93 94 Writer psWriter = new Writer(repository); 95 while (mofIt.hasNext()) { 96 RefBaseObject ooo = (RefBaseObject) mofIt.next(); 97 if (ooo instanceof RefObject) { 98 99 elementId = psWriter.create((RefObject) ooo,modelId); 100 psWriter.rename((RefObject) ooo, elementId); 101 } 102 } 103 psWriter = null; 105 mofIt = null; 106 System.gc(); 107 } 108 109 public void deleteMetamodel(RefPackage metaModel) { 110 111 } 112 113 public RefObject getRepository(String metamodel){ 114 115 116 return null; 117 } 118 119 } 120 | Popular Tags |