KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > jmi > xmiio > exporter > JMI1_0ExportGenerator


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.xmiio.exporter;
21
22 import java.io.ByteArrayOutputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24 import org.objectweb.modfact.jmi.logging.Level;
25 import org.objectweb.modfact.jmi.logging.ModFactLogger;
26
27 import javax.jmi.model.ModelElement;
28 import javax.jmi.model.MofPackage;
29 import javax.jmi.model.VisibilityKindEnum;
30
31 import org.objectweb.modfact.jmi.generator.ZipGenerator;
32 import org.objectweb.modfact.jmi.helper.JMIProvider;
33
34 /**
35  * An abstract implementation of an XMI Import application.
36  * This class provides methods for all XMI importers.
37  */

38 public class JMI1_0ExportGenerator extends ZipGenerator {
39     
40     MofPackage[] input;
41     
42     ModFactLogger logger;
43
44     /**
45      * Set Input
46      */

47     public void setInput(ModelElement[] elt) {
48         input = new MofPackage[elt.length];
49         for (int i = 0; i < input.length; i++) {
50             input[i] = (MofPackage) elt[i];
51         }
52     }
53
54     /**
55      * Set Trace
56      */

57     public void setLogger(ModFactLogger log) {
58         logger = log;
59     }
60
61     public JMI1_0ExportGenerator() {
62     }
63     
64     /**
65      * @see org.objectweb.modfact.generation.Generator#generate()
66      */

67     public void generate()
68             throws IOException JavaDoc {
69         logger.log(Level.FINE, "Begin generation of JMI Exporter");
70         
71         for (int p = 0; p < input.length; p++) {
72             if (input[p]
73                 .getVisibility()
74                 .equals(VisibilityKindEnum.forName("public_vis"))
75                 && input[p].refGetValue("container") == null) {
76
77                 //Traitemement du Package
78
MofPackage[] param = new MofPackage[1];
79                 param[0] = input[p];
80                 
81                 String JavaDoc path = JMIProvider.qualifierOf(input[p]);
82                 path = path.replace('.', '/') +"/";
83                 String JavaDoc className = JMIProvider.jmiPackageExtentName(input[p]) + "XMIExport";
84                 String JavaDoc baseFileName = path + className;
85
86                 GenerationXMIExport exportGenerator = new GenerationXMIExport();
87                 ByteArrayOutputStream JavaDoc entryOutput1 = new ByteArrayOutputStream JavaDoc();
88                 exportGenerator.setOutput(entryOutput1);
89                 exportGenerator.generateXMIExport(param[0], className);
90                 writeEntry(baseFileName + ".java", entryOutput1);
91                 entryOutput1.close();
92                 
93                 logger.log(Level.FINE, "Exporter is generated");
94             }
95         }
96         out.finish();
97         logger.log(Level.FINE, " Generation is completed without error");
98     }
99
100 }
101
Popular Tags