KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > jmi > xmiio > importer > JMI1_0ImportGenerator


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.importer;
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_0ImportGenerator 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_0ImportGenerator() {
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 Importer");
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]) + "XMIImport";
84                 String JavaDoc baseFileName = path + className;
85
86                 GenerationXMIImport importGenerator = new GenerationXMIImport();
87                 ByteArrayOutputStream JavaDoc entryOutput1 = new ByteArrayOutputStream JavaDoc();
88                 importGenerator.setOutput(entryOutput1);
89                 importGenerator.generateXMIImport(param[0]);
90                 writeEntry(baseFileName + ".java", entryOutput1);
91                 entryOutput1.close();
92                 
93
94                 // XMIImportAttributes
95
GenerationXMIImportAttributes xmiImportAttributes = new GenerationXMIImportAttributes();
96                 entryOutput1 = new ByteArrayOutputStream JavaDoc();
97                 xmiImportAttributes.setOutput(entryOutput1);
98                 xmiImportAttributes.generateXMIImportAttributes(param[0], className + "Attributes");
99                 writeEntry(baseFileName + "Attributes.java", entryOutput1);
100                 entryOutput1.close();
101                 
102                 // XMIImportClasses
103
GenerationXMIImportClasses xmiImportClasses = new GenerationXMIImportClasses();
104                 entryOutput1 = new ByteArrayOutputStream JavaDoc();
105                 xmiImportClasses.setOutput(entryOutput1);
106                 xmiImportClasses.generateXMIImportClasses(param[0], className + "Classes");
107                 writeEntry(baseFileName + "Classes.java", entryOutput1);
108                 entryOutput1.close();
109                 
110                 // XMIImportAssociations
111
GenerationXMIImportAssociations xmiImportAssociations = new GenerationXMIImportAssociations();
112                 entryOutput1 = new ByteArrayOutputStream JavaDoc();
113                 xmiImportAssociations.setOutput(entryOutput1);
114                 xmiImportAssociations.generateXMIImportAssociations(param[0], className + "Associations");
115                 writeEntry(baseFileName + "Associations.java", entryOutput1);
116                 entryOutput1.close();
117                 
118                 // XMIImportApplication
119
GenerationXMIImportApplication xmiImportApplication = new GenerationXMIImportApplication();
120                 entryOutput1 = new ByteArrayOutputStream JavaDoc();
121                 xmiImportApplication.setOutput(entryOutput1);
122                 xmiImportApplication.generateXMIImportApplication(param[0], className, className + "Application");
123                 writeEntry(baseFileName + "Application.java", entryOutput1);
124                 entryOutput1.close();
125                 
126                 logger.log(Level.FINE, "Importer is generated");
127             }
128         }
129         out.finish();
130         logger.log(Level.FINE, " Generation is completed without error");
131     }
132
133 }
134
Popular Tags