KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > jmi > service > Generation


1 /**
2  * copyright 2002 2004 Laboratoire d'Informatique Paris 6 (LIP6)
3  *
4  * This file is part of ModFact.
5  *
6  * ModFact is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * at your option) any later version.
10  *
11  * ModFact is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with ModFact; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20 package org.objectweb.modfact.jmi.service;
21
22 import java.io.FileInputStream JavaDoc;
23 import java.io.FileOutputStream JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.OutputStream JavaDoc;
26
27 import javax.jmi.model.ModelPackage;
28 import javax.jmi.model.MofPackage;
29 import javax.jmi.xmi.XmiReader;
30
31 // Imports for the logging
32
import org.objectweb.modfact.jmi.logging.ModFactLogger;
33
34 // Imports for the generators
35
import org.objectweb.modfact.jmi.impl.JMI1_0ImplementationGenerator;
36 import org.objectweb.modfact.jmi.api.JMI1_0Generator;
37 import org.objectweb.modfact.jmi.xmiio.exporter.JMI1_0ExportGenerator;
38 import org.objectweb.modfact.jmi.xmiio.importer.JMI1_0ImportGenerator;
39
40 // Imports for the MOF Repository
41
import org.objectweb.modfact.jmi.xmi.XmiReaderImpl;
42 import org.objectweb.modfact.jmi.reflect.RefPackageImpl;
43
44
45
46 public class Generation {;
47
48     /** The all MOF Packages. */
49     protected MofPackage[] allPackages;
50         
51     /**
52      * Generates all the selected items.
53      * @param metaModelFile The metamodel file.
54      * @param apiFile The API Zip file.
55      * @param implFile The Implementation Zip file.
56      * @param importFile The XMI Importer Zip file.
57      * @param exportFile The XMI Exporter Zip file.
58      */

59     public void execute(InputStream JavaDoc metaModelFile, OutputStream JavaDoc apiFile, OutputStream JavaDoc implFile, OutputStream JavaDoc importFile, OutputStream JavaDoc exportFile)
60         throws java.io.IOException JavaDoc, javax.jmi.xmi.MalformedXMIException {
61         
62         ModelPackage modelPackage;
63         modelPackage = (ModelPackage) RefPackageImpl.getM2Repository();
64         // input XML model
65
XmiReader reader = new XmiReaderImpl();
66         reader.read(metaModelFile, "", modelPackage);
67         setMetaModel(modelPackage);
68         
69         if(apiFile!=null) {
70             generateAPIs(apiFile);
71         }
72         if(implFile!=null) {
73             generateImpl(implFile);
74         }
75         if(importFile!=null) {
76             generateImport(importFile);
77         }
78         if(exportFile!=null) {
79             generateExport(exportFile);
80         }
81     }
82     
83     /**
84      * Generates all the selected items.
85      * @param metaModelFile The metamodel file.
86      * @param apiFile The API Zip file.
87      * @param implFile The Implementation Zip file.
88      * @param importFile The XMI Importer Zip file.
89      * @param exportFile The XMI Exporter Zip file.
90      */

91     public void execute(String JavaDoc metaModelFile, String JavaDoc apiFile, String JavaDoc implFile, String JavaDoc importFile, String JavaDoc exportFile)
92         throws java.io.IOException JavaDoc, javax.jmi.xmi.MalformedXMIException {
93         
94        ModelPackage modelPackage;
95        modelPackage = (ModelPackage) RefPackageImpl.getM2Repository();
96        // input XML model
97
XmiReader reader = new XmiReaderImpl();
98        reader.read(new FileInputStream JavaDoc(metaModelFile), "", modelPackage);
99        setMetaModel(modelPackage);
100         
101        if(apiFile!=null) {
102            generateAPIs(new FileOutputStream JavaDoc(apiFile));
103        }
104        if(implFile!=null) {
105            generateImpl(new FileOutputStream JavaDoc(implFile));
106        }
107        if(importFile!=null) {
108            generateImport(new FileOutputStream JavaDoc(importFile));
109        }
110        if(exportFile!=null) {
111            generateExport(new FileOutputStream JavaDoc(exportFile));
112        }
113     }
114     
115     public void setMetaModel(ModelPackage modelPackage) {
116         allPackages = (MofPackage[]) modelPackage.getMofPackage().refAllOfType().toArray(new MofPackage[0]);
117     }
118     
119     public void generateAPIs(OutputStream JavaDoc out)
120         throws java.io.IOException JavaDoc {
121         ModFactLogger logger =
122             ModFactLogger.getLogger("fr.lip6.modfact.generator.jmi.JMI1_0Generator");
123
124         JMI1_0Generator jmiGenerator = new JMI1_0Generator();
125         jmiGenerator.setLogger(logger);
126         jmiGenerator.setInput(allPackages);
127         jmiGenerator.setOutput(out);
128         jmiGenerator.generate();
129         //System.out.println("JMI APIs generated");
130
}
131
132     public void generateImpl(OutputStream JavaDoc out)
133         throws java.io.IOException JavaDoc {
134         ModFactLogger logger =
135             ModFactLogger.getLogger(
136                 "fr.lip6.modfact.generator.jmi_impl.JMI1_0Generator_impl");
137         JMI1_0ImplementationGenerator jmiGenerator = new JMI1_0ImplementationGenerator();
138         jmiGenerator.setLogger(logger);
139         jmiGenerator.setInput(allPackages);
140         jmiGenerator.setOutput(out);
141         jmiGenerator.generate();
142         //System.out.println("JMI APIs implemented");
143
}
144
145     public void generateImport(OutputStream JavaDoc out)
146         throws java.io.IOException JavaDoc {
147
148         ModFactLogger logger =
149             ModFactLogger.getLogger(
150                 "fr.lip6.modfact.generator.jmi_impl.JMI1_0ImportGenerator_impl");
151
152         JMI1_0ImportGenerator jmiImportGenerator = new JMI1_0ImportGenerator();
153         jmiImportGenerator.setLogger(logger);
154         jmiImportGenerator.setInput(allPackages);
155         jmiImportGenerator.setOutput(out);
156         jmiImportGenerator.generate();
157         //System.out.println("JMI Importers generated");
158
}
159
160     public void generateExport(OutputStream JavaDoc out)
161         throws java.io.IOException JavaDoc {
162
163         ModFactLogger logger =
164             ModFactLogger.getLogger(
165                 "fr.lip6.modfact.generator.jmi_impl.JMI1_0ExportGenerator_impl");
166
167         JMI1_0ExportGenerator jmiExportGenerator = new JMI1_0ExportGenerator();
168         jmiExportGenerator.setLogger(logger);
169         jmiExportGenerator.setInput(allPackages);
170         jmiExportGenerator.setOutput(out);
171         jmiExportGenerator.generate();
172         //System.out.println("JMI Exporters generated");
173
}
174     
175 }
176
Popular Tags