KickJava   Java API By Example, From Geeks To Geeks.

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


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.Attribute;
23 import javax.jmi.model.ModelElement;
24 import javax.jmi.model.MofClass;
25 import javax.jmi.model.Operation;
26 import javax.jmi.model.ScopeKindEnum;
27
28 import org.objectweb.modfact.jmi.helper.JMIProvider;
29 import org.objectweb.modfact.jmi.helper.MofHelper;
30 import org.objectweb.modfact.jmi.logging.ModFactLogger;
31
32
33 /**
34  * @author Xavier
35  *
36  */

37 public class ClassProxyInterfaceGenerator
38     extends CommonGenerator {
39
40     MofClass[] input;
41
42     ModFactLogger logger;
43
44     /**
45      * Set Input
46      */

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

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

64     public void generate() {
65         //Tag todo
66
int c = 0;
67
68         // Package _package = MofHelper.outermostPackageOfModelElement(input[c]);
69
// String packagePrefix = MofHelper.jmiPrefixForPackage(_package);
70
// if (packagePrefix.compareTo("") != 0) {
71
// outputln("package " + packagePrefix + ";");
72
// }
73
outputln(
74             "package " + JMIProvider.qualifierOf(input[c]) + ";" );
75
76         outputln(
77             "public interface "
78                 + JMIProvider.jmiClassName(input[c])
79                 + "Class extends javax.jmi.reflect.RefClass {");
80
81         creatorTemplate(input[c]);
82         
83         //for each StructType directly contained by the class (correction of the spec ?)
84
dataTypeTemplates(input[c]);
85
86         //for each attribute and operation contained in this class or one of its
87
//supertypes with "classifier-level" scope, generate the appropriate operations
88
Attribute[] attributes = MofHelper.attributesOfClass(
89                 input[c],
90                 ScopeKindEnum.forName("classifier_level"), false );
91                 
92         for (int i = 0; i < attributes.length; i++) {
93             attributeTemplate(attributes[i]);
94         }
95
96         // each operation
97
Operation[] operations =
98             MofHelper.operationsOfClass(
99                 input[c],
100                 ScopeKindEnum.forName("classifier_level")
101                 ,false );
102         for (int i = 0; i < operations.length; i++) {
103             operationTemplate(operations[i]);
104         }
105
106         outputln("}//end of interface");
107         flushFile();
108     }
109
110     void creatorTemplate(MofClass cl) {
111         //If isAbstract is not set to true, generate factory methods.
112
if (!cl.isAbstract()) {
113             outputln(
114                 "public "
115                     + JMIProvider.jmiClassQualifiedName(cl)
116                     + " create"
117                     + JMIProvider.jmiClassName(cl)
118                     + "() throws javax.jmi.reflect.JmiException;\n");
119
120             Attribute[] attributes =
121                 MofHelper.attributesOfClass(
122                     cl,
123                     ScopeKindEnum.forName("instance_level"), true );
124
125             java.util.List JavaDoc v = new java.util.Vector JavaDoc();
126             for(int i =0; i<attributes.length; i++) {
127               if(!attributes[i].isDerived()) v.add(attributes[i]);
128             }
129             attributes = (Attribute[]) v.toArray(new Attribute[0]);
130
131             if (attributes.length != 0) {
132                 output(
133                     "public "
134                         + JMIProvider.jmiClassQualifiedName(cl)
135                         + " create"
136                         + JMIProvider.jmiClassName(cl)
137                         + "(");
138                 //for each non-derived direct or inherited attribute
139
for (int i = 0; i < attributes.length; i++) {
140                     output(
141                         JMIProvider.typeTemplate(attributes[i]) +" " +attributes[i].getName()
142                     );
143                     if (i != attributes.length - 1)
144                         output(" , ");
145                 }
146                 outputln(") throws javax.jmi.reflect.JmiException;\n");
147             }
148             
149         }
150     }
151
152 }
153
Popular Tags