KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > jmi > api > PackageInterfaceGenerator


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.api;
21
22 import javax.jmi.model.Association;
23 import javax.jmi.model.GeneralizableElement;
24 import javax.jmi.model.Import;
25 import javax.jmi.model.ModelElement;
26 import javax.jmi.model.MofClass;
27 import javax.jmi.model.MofPackage;
28 import javax.jmi.model.VisibilityKindEnum;
29
30 import org.objectweb.modfact.jmi.helper.JMIProvider;
31 import org.objectweb.modfact.jmi.helper.MofHelper;
32 import org.objectweb.modfact.jmi.logging.ModFactLogger;
33
34
35 /**
36  * @author Xavier
37  *
38  */

39 public class PackageInterfaceGenerator extends CommonGenerator {
40
41     MofPackage[] input;
42
43     ModFactLogger logger;
44
45     /**
46      * Set Input
47      */

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

58     public void setLogger(ModFactLogger log) {
59         logger = log;
60     }
61
62     /**
63      * @see fr.lip6.modfact.generation.Generator#generate()
64      */

65     public void generate() {
66         //Tag Import todo
67
MofPackage _package = input[0];
68         //javadocsTemplate(_package);
69

70
71         outputln(
72             "package " + JMIProvider.qualifierOf(_package) + ";");
73
74         output(
75             "public interface "
76                 + JMIProvider.jmiPackageExtentName(_package)
77                 + "Package extends ");
78         GeneralizableElement[] generalizableElement = (GeneralizableElement[])_package.getSupertypes().toArray(new GeneralizableElement[0]);
79         if (generalizableElement.length == 0)
80             outputln("javax.jmi.reflect.RefPackage");
81         else {
82             for (int i = 0; i < generalizableElement.length; i++) {
83                 output(
84                     JMIProvider.jmiPackageQualifiedName(
85                         (MofPackage)generalizableElement[i] )
86                         + "Package ");
87                 if (i != generalizableElement.length)
88                     output(",");
89             }
90         }
91         outputln(" { ");
92         
93         //for each StructType
94
dataTypeTemplates(_package);
95
96         //////////////// Package Import /////////////////
97
Import[] imports = MofHelper.importsOfPackage(_package);
98         for (int i = 0; i < imports.length; i++) {
99             if ( VisibilityKindEnum.forName("public_vis").equals(imports[i].getVisibility())
100                 && imports[i].isClustered()
101                 && imports[i].getImportedNamespace() instanceof MofPackage
102             ) {
103                 MofPackage importedPackage = (MofPackage) imports[i].getImportedNamespace();
104                     outputln(
105                         "\tpublic "
106                             + JMIProvider.jmiPackageQualifiedName(importedPackage)
107                             + "Package get"
108                             + JMIProvider.jmiImportName(imports[i])
109                             + "();");
110             }
111         }
112
113         //for each contained package where visibility = public_vis
114
MofPackage[] containedPackages =
115             MofHelper.packagesOfPackage(_package);
116         for (int i = 0; i < containedPackages.length; i++) {
117             if (containedPackages[i]
118                 .getVisibility()
119                 .equals(VisibilityKindEnum.forName("public_vis"))
120                 ) {
121                     
122                 outputln(
123                     "\tpublic "
124                         + JMIProvider.jmiPackageQualifiedName(containedPackages[i])
125                         + "Package get"
126                         + JMIProvider.jmiPackageExtentName(containedPackages[i])
127                         + "();");
128             }
129         }
130
131         //for each contained class where visibility = public_vis
132
MofClass[] containedClasses =
133             MofHelper.classesOfPackage(_package);
134         for (int i = 0; i < containedClasses.length; i++) {
135             if (containedClasses[i]
136                 .getVisibility()
137                 .equals(VisibilityKindEnum.forName("public_vis"))) {
138                 outputln(
139                     "\tpublic "
140                         + JMIProvider.jmiClassQualifiedName(containedClasses[i])
141                         + "Class get"
142                         + JMIProvider.jmiClassName(containedClasses[i])
143                         + "();");
144             }
145         }
146
147         //for each contained association where visibility = public_vis
148
Association[] containedAssociations =
149             MofHelper.associationsOfPackage(_package);
150         for (int i = 0; i < containedAssociations.length; i++) {
151             if (containedAssociations[i]
152                 .getVisibility()
153                 .equals(VisibilityKindEnum.forName("public_vis")) ) {
154                 outputln(
155                     "\tpublic "
156                         + JMIProvider.jmiAssociationQualifiedName(containedAssociations[i])
157                         + " get"
158                         + JMIProvider.jmiAssociationName(containedAssociations[i])
159                         + "();");
160             }
161         }
162
163         outputln("}");
164         flushFile();
165     }
166
167
168 }
169
Popular Tags