KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > jmi > impl > tayloredBased > JMI1_0ImplementationGenerator


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.jmi.impl.tayloredBased;
21
22 import java.io.ByteArrayOutputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24 import org.objectweb.modfact.jmi.helper.*;
25 import org.objectweb.modfact.jmi.logging.Level;
26 import org.objectweb.modfact.jmi.logging.ModFactLogger;
27
28 import javax.jmi.model.*;
29
30 import org.objectweb.modfact.jmi.generator.ZipGenerator;
31
32
33 /**
34  * @author Xavier
35  *
36  */

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

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

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

63     public void generate()
64             throws IOException JavaDoc {
65
66
67         logger.log(Level.FINE, "Begin generation of JMI Interfaces");
68
69         for (int p = 0; p < input.length; p++) {
70             if (input[p]
71                 .getVisibility()
72                 .equals(VisibilityKindEnum.forName("public_vis"))) {
73
74                 //Traitemement du Package
75
PackageImplementationGenerator packageGenerator = new PackageImplementationGenerator();
76                 MofPackage[] param = new MofPackage[1];
77                 param[0] = input[p];
78                 packageGenerator.setInput(param);
79                 ByteArrayOutputStream JavaDoc entryOutput1 =
80                     new ByteArrayOutputStream JavaDoc();
81                 packageGenerator.setOutput(entryOutput1);
82                 packageGenerator.generate();
83                 
84                 String JavaDoc path = ImplHelper.implPrefix + JMIProvider.shortQualifierOf(input[p]);
85                 path = path.replace('.', '/') +"/";
86                 
87                 String JavaDoc entryName = path
88                     +JMIProvider.jmiPackageExtentName(input[p]) + "PackageImpl" + ".java";
89                     
90                 writeEntry(entryName, entryOutput1);
91                 entryOutput1.close();
92                 
93                 logger.log(Level.FINE, entryName+" is generated");
94
95                 //Traitement des Classes
96
MofClass[] classes = MofHelper.classesOfPackage(input[p]);
97                 
98                 for (int i = 0; i < classes.length; i++) {
99                     if (classes[i].getVisibility()
100                         == VisibilityKindEnum.forName("public_vis")) {
101
102                         // Cette Partie génère toutes les ClasseProxy
103
ClassProxyImplementationGenerator classProxyGenerator = new ClassProxyImplementationGenerator();
104                         MofClass[] paramCP = new MofClass[1];
105                         paramCP[0] = classes[i];
106                         classProxyGenerator.setInput(paramCP);
107                         ByteArrayOutputStream JavaDoc entryOutputClassProxy =
108                             new ByteArrayOutputStream JavaDoc();
109                         classProxyGenerator.setOutput(entryOutputClassProxy);
110                         classProxyGenerator.generate();
111
112                         String JavaDoc entryNameClassProxy = path
113                             +JMIProvider.jmiClassName(classes[i])
114                                 + "ClassImpl"
115                                 + ".java";
116                         writeEntry(entryNameClassProxy, entryOutputClassProxy);
117                         entryOutputClassProxy.close();
118                         
119                         logger.log(Level.FINE, entryNameClassProxy+" is generated");
120
121                         // Cette partie génère toutes les Classes
122
InstanceImplementationGenerator classImpl = new InstanceImplementationGenerator();
123                         MofClass[] paramCI = new MofClass[1];
124                         paramCI[0] = classes[i];
125                         classImpl.setInput(paramCI);
126                         ByteArrayOutputStream JavaDoc entryOutputInstance = new ByteArrayOutputStream JavaDoc();
127                         classImpl.setOutput(entryOutputInstance);
128                         classImpl.generate();
129
130                         String JavaDoc entryNameInstance = path
131                             +JMIProvider.jmiClassName(classes[i]) + "Impl.java";
132                         writeEntry(entryNameInstance, entryOutputInstance);
133                         entryOutputInstance.close();
134                         
135                         logger.log(Level.FINE, entryNameInstance+" is generated");
136
137                         //Cette partie traite les DataType (Enum et Struct) des classes
138
DataType[] datatypes =
139                             MofHelper.datatypesOf(classes[i], false);
140                         for (int j = 0; j < datatypes.length; j++) {
141                             
142                             if (datatypes[j] instanceof StructureType) {
143                                 StructureTypeImplementationGenerator structGenerator =
144                                     new StructureTypeImplementationGenerator();
145                                 DataType[] inImpl = new DataType[1];
146                                 inImpl[0] = datatypes[j];
147                                 structGenerator.setInput(inImpl);
148                                 structGenerator.setLogger(logger);
149
150                                 ByteArrayOutputStream JavaDoc structEntryOutputImpl =
151                                     new ByteArrayOutputStream JavaDoc();
152                                 structGenerator.setOutput(
153                                     structEntryOutputImpl);
154                                 structGenerator.generate();
155
156                                 String JavaDoc entryNameStruct = path
157                                     +datatypes[j].getName() + "Impl.java";
158                                 writeEntry(
159                                     entryNameStruct,
160                                     structEntryOutputImpl);
161                                 structEntryOutputImpl.close();
162                                 
163                                 logger.log(Level.FINE, entryNameStruct+" is generated");
164                             }
165                         }
166
167                     }
168                 }
169
170                 //Traitement des Associations
171
Association[] associations =
172                     MofHelper.associationsOfPackage(input[p]);
173                 for (int i = 0; i < associations.length; i++) {
174                     if (associations[i]
175                         .getVisibility()
176                         .equals(VisibilityKindEnum.forName("public_vis"))) {
177                         AssociationImplementationGenerator associationGenerator =
178                             new AssociationImplementationGenerator();
179                         Association[] paramA = new Association[1];
180                         paramA[0] = associations[i];
181                         associationGenerator.setInput(paramA);
182                         ByteArrayOutputStream JavaDoc entryOutputAssociation =
183                             new ByteArrayOutputStream JavaDoc();
184                         associationGenerator.setOutput(entryOutputAssociation);
185
186                         associationGenerator.generate();
187
188                         String JavaDoc entryNameAssociation = path+
189                             JMIProvider.jmiAssociationName(associations[i])
190                                 + "Impl.java";
191                         writeEntry(
192                             entryNameAssociation,
193                             entryOutputAssociation);
194                         entryOutputAssociation.close();
195                         
196                         logger.log(Level.FINE, entryNameAssociation+" is generated");
197                     }
198                 }
199
200                 //Traitement des DataTypes Enum et Struct
201
DataType[] datatypes = MofHelper.datatypesOf(input[p], false);
202                 for (int i = 0; i < datatypes.length; i++) {
203                     if (datatypes[i] instanceof StructureType) {
204                         StructureTypeImplementationGenerator structureTypeInterfaceGenerator =
205                             new StructureTypeImplementationGenerator();
206                         DataType[] paramT = new DataType[1];
207                         paramT[0] = datatypes[i];
208                         structureTypeInterfaceGenerator.setInput(paramT);
209                         ByteArrayOutputStream JavaDoc entryOutputDataType =
210                             new ByteArrayOutputStream JavaDoc();
211                         structureTypeInterfaceGenerator.setOutput(
212                             entryOutputDataType);
213
214                         structureTypeInterfaceGenerator.generate();
215
216                         String JavaDoc entryNameStructure = path+
217                             datatypes[i].getName() + "Impl.java";
218                         writeEntry(entryNameStructure, entryOutputDataType);
219                         entryOutputDataType.close();
220                         
221                         logger.log(Level.FINE, entryNameStructure+" is generated");
222                     }
223                 }
224
225             }
226         }
227         out.finish();
228         logger.log(Level.FINE, " Generation is completed without error");
229     }
230
231 }
232
Popular Tags