KickJava   Java API By Example, From Geeks To Geeks.

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


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

39 public class InstanceInterfaceGenerator extends CommonGenerator {
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
66         MofClass c = input[0];
67
68         outputln(
69             "package " + JMIProvider.qualifierOf(c) + ";" );
70
71         output("public interface " + JMIProvider.jmiClassName(c));
72
73         MofClass[] supertypes = (MofClass[])c.getSupertypes().toArray(new MofClass[0]);
74         //if the class has no super-types
75
if (supertypes.length == 0) {
76             outputln(" extends javax.jmi.reflect.RefObject {");
77         //else, for each super-class
78
} else {
79             output(" extends ");
80             for (int i = 0; i < supertypes.length; i++) {
81                 if (i != 0) out.print(" ,");
82                 output(
83                     JMIProvider.jmiClassQualifiedName(supertypes[i]) );
84             }
85             outputln("{");
86         }
87
88         //for each constant, generate the appropriate code
89
Constant[] constants = MofHelper.constantsOfClass(c);
90         for (int i = 0; i < constants.length; i++) {
91             constantTemplate(constants[i]);
92         }
93
94         //for each instance level attribute of this class, generate the appropriate code
95
//MofAttribute[] attributes_d = MofHelper.attributesOfClass(c , ScopeKind.instance_level , true );
96
//for (int i = 0 ; i < attributes_d.length ; i++) {
97
// attributeTemplate(attributes_d[i]);
98
//}
99

100         Attribute[] attributes_nd =
101             MofHelper.attributesOfClass(
102                 c ,ScopeKindEnum.forName("instance_level"), false);
103                 
104         for (int i = 0; i < attributes_nd.length; i++) {
105             attributeTemplate(attributes_nd[i]);
106         }
107
108         //for each instance level reference of this class, generate the appropriate code if public
109
Reference[] references = MofHelper.referencesOfClass(c, false);
110         for (int i = 0; i < references.length; i++) {
111             referenceTemplate(references[i]);
112         }
113
114         //for each operation, generate the appropriate code if public_vis
115
Operation[] operations = MofHelper.operationsOfClass(c, ScopeKindEnum.INSTANCE_LEVEL, false );
116         for (int i = 0; i < operations.length; i++) {
117             if (operations[i].getVisibility().equals(VisibilityKindEnum.PUBLIC_VIS))
118                 operationTemplate(operations[i]);
119         }
120
121         //end
122
outputln("}"); //end of interface
123
flushFile();
124     }
125 }
126
Popular Tags