KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > jmi > ps > PersistantService


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 JavaDoc;
7
8 /**
9  * @author gregory
10  *
11  * The persistant service provide common operation
12  * for loadind and unloading a model in the repository.
13  * All metamodels are uniquely identified by their name.
14  * When unloading a metamodel, it is written in the database
15  */

16 public class PersistantService {
17     
18     
19     private RefPackage repository;
20     
21     
22     public PersistantService(){
23         this.repository = RefPackageImpl.getM2Repository();
24     }
25
26
27     /**
28      * Method load.
29      * @param name
30      * @return boolean
31      * @throws ClassNotFoundException
32      * @throws SQLException
33      *
34      * load a metamodel in the M2 level repository
35      * */

36
37     public boolean load(String JavaDoc name) throws ClassNotFoundException JavaDoc, SQLException JavaDoc {
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     /**
53      * Method isLoaded.
54      * @param metamodel
55      * @return boolean
56      */

57     private boolean isLoaded(String JavaDoc 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     /**
70      * Method store.
71      * @param name
72      * @throws ClassNotFoundException
73      * @throws SQLException
74      *
75      * Very dirty : we delete the content of the metamodel before writing it
76      * again ...
77      */

78     public void store(String JavaDoc name)
79         throws ClassNotFoundException JavaDoc, SQLException JavaDoc {
80
81         boolean modelExist;
82         String JavaDoc modelId;
83         String JavaDoc 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         //null all reference of the repository where outermost package == metamodelname
104
psWriter = null;
105         mofIt = null;
106         System.gc();
107     }
108
109     public void deleteMetamodel(RefPackage metaModel) {
110     
111     }
112     
113     public RefObject getRepository(String JavaDoc metamodel){
114         
115         
116         return null;
117     }
118
119 }
120
Popular Tags