KickJava   Java API By Example, From Geeks To Geeks.

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


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

34 public class StructureTypeImplementationGenerator extends PrintGenerator {
35
36     StructureType[] input;
37
38
39     ModFactLogger logger;
40
41     /**
42      * Set Input
43      */

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

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

61     public void generate() {
62         int t = 0;
63         DataType type = input[t];
64
65         // Package _package = MofHelper.outermostPackageOfModelElement(input[t]);
66
// String packagePrefix = MofHelper.jmiPrefixForPackage(_package);
67
// if (packagePrefix.compareTo("") != 0) {
68
// out.println("package " + packagePrefix + ";");
69
// }
70

71
72         out.println("package " +ImplHelper.implPrefix + JMIProvider.shortQualifierOf(type) + ";");
73         out.println("import " + JMIProvider.qualifierOf(type) + ".*;");
74         
75         out.println("import org.objectweb.modfact.jmi.reflect.*;");
76
77         //
78
//<<ANNOTATION TEMPLATE >>
79
out.println(
80             "public class "
81                 + type.getName()
82                 + "Impl extends RefStructImpl"
83                 + " implements "
84                 + JMIProvider.jmiDataTypeQualifiedName(type)
85                 +" {");
86                 
87         StructureField[] fields = MofHelper.structureFieldsOf((StructureType)type);
88         //for each attribute
89
for (int i = 0; i<fields.length ; i++) {
90             
91             String JavaDoc accessorName = JMIProvider.jmiAccessorName(fields[i]);
92             
93             out.println(
94                 "\tpublic "
95                     + JMIProvider.typeTemplate(fields[i])
96                     + " "
97                     + accessorName
98                     + "() throws javax.jmi.reflect.JmiException {");
99             out.println("\t\treturn "
100                 +"("+ JMIProvider.typeTemplate(fields[i]) +")"
101                 + ImplHelper.unwrap(
102                     fields[i]
103                     ,"refGetValue(\"" +fields[i].getName() +"\")"
104                   )
105                 +";"
106             );
107             out.println("\t}");
108         }
109         
110         
111         out.println("}");
112         out.flush();
113     }
114
115 }
116
Popular Tags