KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * copyright 2002 2003 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.corba.service;
21
22 import java.io.InputStream JavaDoc;
23 import java.io.OutputStream JavaDoc;
24
25 import org.omg.CosNaming.*;
26
27 // Imports for the logging
28
import org.objectweb.modfact.corba.logging.Level;
29 import org.objectweb.modfact.corba.logging.ModFactLogger;
30
31 // Imports for the generators
32
import org.objectweb.modfact.corba.io.Import;
33 import org.objectweb.modfact.corba.idl.MOFIDL1_3Generator;
34 import org.objectweb.modfact.corba.idl2java.IDL2JavaMOF1_3Generator;
35 import org.objectweb.modfact.corba.xmi.XMI1_1DTDGenerator;
36 import org.objectweb.modfact.corba.xmiio.exporter.XMIExportGenerator;
37 import org.objectweb.modfact.corba.xmiio.importer.XMIImportGenerator;
38 import org.objectweb.modfact.corba.server.ServerGenerator;
39
40 // Imports for the Helper API
41
import org.objectweb.modfact.corba.helper.IDLCommon;
42 import org.objectweb.modfact.corba.helper.JavaCommon;
43 import org.objectweb.modfact.corba.helper.MOFCommon;
44 import org.objectweb.modfact.corba.helper.XMICommon;
45 import org.objectweb.modfact.corba.helper.XMIImportCommon;
46
47 // Imports for the Helper Implementation
48
import org.objectweb.modfact.corba.provider.IDLProvider;
49 import org.objectweb.modfact.corba.provider.JavaProvider;
50 import org.objectweb.modfact.corba.provider.MOFCachedProvider;
51 import org.objectweb.modfact.corba.provider.XMIImportProvider;
52 import org.objectweb.modfact.corba.provider.XMIProvider;
53
54
55 public class Generation {;
56
57     /**
58      * Generates all the selected items.
59      * @param idl TRUE to generate the IDL files.
60      * @param dtd TRUE to generate the DTD file.
61      * @param java TRUE to generate the Java files.
62      * @param xmiImport TRUE to generate the XMI Importer files.
63      * @param xmiExport TRUE to generate the XMI Exporter files.
64      * @param server TRUE to generate the Server files.
65      * @param mappingValid TRUE to indicate that the ORB is compliant with the IDL to Java mapping.
66      * @param input The input file (meta-model).
67      * @param output The output file (zip file).
68      * @param orb The ORB.
69      */

70     public void execute(boolean idl, boolean dtd, boolean java, boolean xmiImport, boolean xmiExport, boolean server, boolean mappingValid, InputStream JavaDoc input, OutputStream JavaDoc output, org.omg.CORBA.ORB JavaDoc orb) {
71         try {
72             // get the root naming context
73
org.omg.CORBA.Object JavaDoc objRef =
74                 orb.resolve_initial_references("NameService");
75
76             // Use NamingContextExt instead of NamingContext. This is
77
// part of the Interoperable naming Service.
78
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
79
80             // resolve the Object Reference in Naming
81
String JavaDoc name = "ModFactServer";
82             org.omg.mof.Model.ModelPackageFactory _reference =
83                 org.omg.mof.Model.ModelPackageFactoryHelper.narrow(
84                     ncRef.resolve_str(name));
85
86             // creation of Model
87
org.omg.mof.Model._ModelPackage modelPackage =
88                 _reference.create_model_package();
89
90             // initialisation
91
//ImportFromRose imp = new ImportFromRose();
92
//imp.initiate(modelPackage, orb);
93
ModFactLogger loggerImport = ModFactLogger.getLogger("org.objectweb.modfact.corba.io.Import");
94             Import imp = new Import();
95             imp.setIdlHelper(new IDLProvider());
96             imp.setLogger(loggerImport);
97             imp.initiate(modelPackage, orb);
98
99             // input XML model
100
org.omg.mof.Model.Package[] outermostPackages =
101                 imp.parse(input);
102
103             // Generation of IDL
104
if (idl) {
105                 ModFactLogger logger =
106                     ModFactLogger.getLogger(
107                         "org.objectweb.modfact.corba.idl.MOFIDL1_3Generator");
108                 MOFIDL1_3Generator idlGenerator = new MOFIDL1_3Generator();
109                 idlGenerator.setLogger(logger);
110                 idlGenerator.setInput(outermostPackages);
111                 idlGenerator.setOutput(output);
112                 MOFCommon mofHelper = new MOFCachedProvider(outermostPackages);
113                 idlGenerator.setMofHelper(mofHelper);
114                 IDLCommon idlHelper = new IDLProvider(mofHelper);
115                 idlGenerator.setIdlHelper(idlHelper);
116                 idlGenerator.generate();
117                 //ch.close();
118

119                 //output.close();
120
}
121
122             //Generation of DTD
123
if (dtd) {
124                 ModFactLogger logger =
125                     ModFactLogger.getLogger(
126                         "org.objectweb.modfact.corba.xmi.XMI1_1DTDGenerator");
127                 XMI1_1DTDGenerator dtdGenerator = new XMI1_1DTDGenerator();
128                 dtdGenerator.setLogger(logger);
129                 dtdGenerator.setInput(outermostPackages);
130                 dtdGenerator.setOutput(output);
131                 MOFCommon mofHelper = new MOFCachedProvider(outermostPackages);
132                 dtdGenerator.setMofHelper(mofHelper);
133                 XMICommon xmiHelper = new XMIProvider(mofHelper);
134                 dtdGenerator.setXmiHelper(xmiHelper);
135                 dtdGenerator.generate();
136                 //output.close();
137
}
138
139             //Generation of code
140
if (java) {
141                 ModFactLogger logger =
142                     ModFactLogger.getLogger(
143                         "org.objectweb.modfact.corba.idl2java.IDL2JavaMOF1_3Generator");
144                 IDL2JavaMOF1_3Generator javaGenerator =
145                     new IDL2JavaMOF1_3Generator();
146                 javaGenerator.setLogger(logger);
147                 javaGenerator.setInput(outermostPackages);
148                 javaGenerator.setOutput(output);
149                 MOFCommon mofHelper = new MOFCachedProvider(outermostPackages);
150                 javaGenerator.setMofHelper(mofHelper);
151                 JavaCommon javaHelper = new JavaProvider(mofHelper);
152                 javaGenerator.setJavaHelper(javaHelper);
153                 javaGenerator.generate();
154                 //output.close();
155
}
156
157             //Generation of code
158
if (xmiImport) {
159                 ModFactLogger logger =
160                     ModFactLogger.getLogger(
161                         "org.objectweb.modfact.corba.xmiio.importer.XMIImportGenerator");
162                 XMIImportGenerator xmiImpGenerator = new XMIImportGenerator();
163                 xmiImpGenerator.setLogger(logger);
164                 xmiImpGenerator.setInput(outermostPackages);
165                 xmiImpGenerator.setOutput(output);
166                 MOFCommon mofHelper = new MOFCachedProvider(outermostPackages);
167                 xmiImpGenerator.setMofHelper(mofHelper);
168                 JavaCommon javaHelper = new JavaProvider(mofHelper);
169                 xmiImpGenerator.setJavaHelper(javaHelper);
170                 IDLCommon idlHelper = new IDLProvider(mofHelper);
171                 xmiImpGenerator.setIdlHelper(idlHelper);
172                 XMIImportCommon xmiImpHelper = new XMIImportProvider(idlHelper, mofHelper, javaHelper);
173                 xmiImpGenerator.setXmiImportHelper(xmiImpHelper);
174                 xmiImpGenerator.setMappingValid(mappingValid);
175                 xmiImpGenerator.generate();
176                 //output.close();
177
}
178
179             //Generation of code
180
if (xmiExport) {
181                 ModFactLogger logger =
182                     ModFactLogger.getLogger(
183                         "org.objectweb.modfact.corba.xmiio.exporter.XMIExportGenerator");
184                 XMIExportGenerator xmiExpGenerator = new XMIExportGenerator();
185                 xmiExpGenerator.setLogger(logger);
186                 xmiExpGenerator.setInput(outermostPackages);
187                 xmiExpGenerator.setOutput(output);
188                 MOFCommon mofHelper = new MOFCachedProvider(outermostPackages);
189                 xmiExpGenerator.setMofHelper(mofHelper);
190                 JavaCommon javaHelper = new JavaProvider(mofHelper);
191                 xmiExpGenerator.setJavaHelper(javaHelper);
192                 IDLCommon idlHelper = new IDLProvider(mofHelper);
193                 xmiExpGenerator.setIdlHelper(idlHelper);
194                 xmiExpGenerator.setMappingValid(mappingValid);
195                 xmiExpGenerator.generate();
196                 //output.close();
197
}
198
199             //Generation of code
200
if (server) {
201                 ModFactLogger logger =
202                     ModFactLogger.getLogger(
203                         "org.objectweb.modfact.corba.server.ServerGenerator");
204                 ServerGenerator serverGenerator = new ServerGenerator();
205                 serverGenerator.setLogger(logger);
206                 serverGenerator.setInput(outermostPackages);
207                 serverGenerator.setOutput(output);
208                 MOFCommon mofHelper = new MOFCachedProvider(outermostPackages);
209                 IDLCommon idlHelper = new IDLProvider(mofHelper);
210                 serverGenerator.setIdlHelper(idlHelper);
211                 JavaCommon javaHelper = new JavaProvider(mofHelper);
212                 serverGenerator.setJavaHelper(javaHelper);
213                 serverGenerator.setMappingValid(mappingValid);
214                 serverGenerator.generate();
215                 //output.close();
216
}
217
218         } catch (Exception JavaDoc e) {
219             ModFactLogger logger = ModFactLogger.getLogger("org.objectweb.modfact.corba.service.Generation");
220             logger.log(Level.ERROR, e.toString());
221         }
222     }
223     
224 }
225
Popular Tags