KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 import javax.jmi.model.*;
24
25 import org.objectweb.modfact.jmi.generator.BracketGenerator;
26 import org.objectweb.modfact.jmi.helper.*;
27
28
29 /**
30  * @author Xavier
31  *
32  */

33 public abstract class CommonGenerator extends BracketGenerator {
34     
35     
36     public void attributeTemplate(Attribute attribute) {
37         if (attribute.getVisibility().equals(VisibilityKindEnum.forName("public_vis"))) {
38             //<<ANNOTATION TEMPLATE>>
39

40             //----------------------- Accessor Operations
41
structuralFeatureAccessor(attribute);
42         
43             //------------------------- Mutator Operations
44
structuralFeatureMutator(attribute);
45
46         }
47     }
48
49     public void referenceTemplate(Reference reference) {
50         if (reference.getVisibility().equals(VisibilityKindEnum.forName("public_vis"))) {
51             //<<ANNOTATION TEMPLATE>>
52

53             //----------------------- Accessor Operations
54
structuralFeatureAccessor(reference);
55         
56             //------------------------- Mutator Operations
57
structuralFeatureMutator(reference);
58             
59         }
60     }
61     
62     public void structuralFeatureAccessor(StructuralFeature f) {
63         
64         String JavaDoc fType = JMIProvider.typeTemplate(f);
65         String JavaDoc accessorName = JMIProvider.jmiAccessorName(f);
66         
67         outputln(
68                 "public "
69                     + fType
70                     + " "
71                     + accessorName
72                     + "() throws javax.jmi.reflect.JmiException;");
73
74     }
75     
76     
77     public void structuralFeatureMutator(StructuralFeature f) {
78         
79         String JavaDoc mutatorName = JMIProvider.jmiMutatorName(f);
80         String JavaDoc fType = JMIProvider.typeTemplate(f);
81                 
82         if ( f.getMultiplicity().getUpper() == 1 && f.isChangeable() ) {
83             outputln(
84                 "public void "
85                     + mutatorName
86                     + "("
87                     + fType
88                     + " newValue) throws javax.jmi.reflect.JmiException;");
89         }
90     }
91     
92
93     ///////////////// Operation //////////////////////////////////
94
public void operationTemplate(Operation operation) {
95         if (operation.getVisibility().equals(VisibilityKindEnum.forName("public_vis"))) {
96             //<<JAVADOCS TEMPLATE>>
97
//Get Parameters and exceptions
98
Parameter[] parameters = MofHelper.parametersOf(operation);
99             MofException[] exceptions = MofHelper.exceptionsOf(operation);
100             Parameter returnParameter = null;
101             
102             for(int i=0; i<parameters.length; i++) {
103                 if(parameters[i].getDirection().equals(DirectionKindEnum.RETURN_DIR)) {
104                     returnParameter = parameters[i];
105                 }
106             }
107
108             if (returnParameter==null) output("\tpublic void ");
109             else output("public "
110                 +JMIProvider.typeTemplate(returnParameter)
111                 +" " );
112             
113             output(operation.getName()+"(");
114             
115             boolean comma = false;
116             for (int i=0 ; i <parameters.length ; i++) {
117                 DirectionKind dir = parameters[i].getDirection();
118                 if ( !dir.equals(DirectionKindEnum.RETURN_DIR)) {
119                   if (comma) output(",");
120                   output( JMIProvider.typeTemplate(parameters[i]) +" " +parameters[i].getName());
121                   comma = true;
122                 }
123             }
124             output(") throws ");
125             
126             //for each exception
127
for (int i=0 ; i < exceptions.length ; i++) {
128                 output(exceptions[i].getName()+",");
129             }
130             outputln("javax.jmi.reflect.JmiException;");
131         }
132     }
133
134
135     
136     
137     
138     /////////////////// DATA TYPE //////////////////
139
public void dataTypeTemplates(Namespace ns) {
140         //for each StructType directly contained by the package/class
141
DataType[] containedDataTypes =
142             MofHelper.datatypesOf(ns, false);
143         for (int i = 0; i < containedDataTypes.length; i++) {
144             if ( containedDataTypes[i] instanceof StructureType) {
145                 structTemplate((StructureType)containedDataTypes[i]);
146             }
147         }
148     }
149     
150     public void structTemplate(StructureType t) {
151
152             output(
153                 "public "
154                     + JMIProvider.jmiDataTypeQualifiedName(t)
155                     + " create"
156                     + t.getName()
157                     + " (");
158                                     
159             StructureField[] fields = MofHelper.structureFieldsOf(t);
160             for (int j = 0; j < fields.length; j++) {
161                 output( JMIProvider.typeTemplate(fields[j]) );
162                 //attribute type
163
output(" ");
164                 output(fields[j].getName()); //attribute name
165
if (j != fields.length - 1)
166                     output(" , ");
167             }
168             outputln(") throws javax.jmi.reflect.JmiException;");
169     
170     }
171     
172     public void constantTemplate(Constant constant) {
173         //<<ANNOTATION TEMPLATE>>
174
// TODO
175
outputln(
176             "public final "
177                 + "String"
178                 + " "
179                 + constant.getName()
180                 + "= \""
181                 + constant.getValue()
182                 + "\";");
183     }
184     
185     
186 }
187
Popular Tags