KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
28  * @author Xavier
29  *
30  */

31 public class InstanceImplementationGenerator extends CommonImplementationGenerator {
32     MofClass[] input;
33
34     ModFactLogger logger;
35
36     /**
37      * Set Input
38      */

39     public void setInput(ModelElement[] elt) {
40         input = new MofClass[elt.length];
41         for (int i = 0; i < input.length; i++) {
42             input[i] = (MofClass) elt[i];
43         }
44     }
45
46     /**
47      * Set Trace
48      */

49     public void setLogger(ModFactLogger log) {
50         logger = log;
51     }
52
53     /**
54      * @see org.objectweb.modfact.generation.Generator#generate()
55      */

56     public void generate() {
57
58         MofClass c = input[0];
59
60         out.println("package " +ImplHelper.implPrefix + JMIProvider.shortQualifierOf(c) + ";" );
61         out.println("import " + JMIProvider.qualifierOf(c) + ".*;" );
62         
63         out.println("import org.objectweb.modfact.jmi.reflect.*;");
64
65         out.print("public class " + JMIProvider.jmiClassName(c) +"Impl"
66             +" extends RefObjectImpl "
67             +"implements "
68             +JMIProvider.jmiClassQualifiedName(c)
69             +" {" );
70
71
72         //for each instance level attribute of this class, generate the appropriate code
73
//MofAttribute[] attributes_d = MofHelper.attributesOfClass(c , ScopeKind.instance_level , true );
74
//for (int i = 0 ; i < attributes_d.length ; i++) {
75
// attributeTemplate(attributes_d[i]);
76
//}
77

78         Attribute[] attributes_nd =
79             MofHelper.attributesOfClass(
80                 c,
81                 ScopeKindEnum.forName("instance_level"), true);
82                 
83         for (int i = 0; i < attributes_nd.length; i++) {
84             attributeTemplate(attributes_nd[i]);
85         }
86
87         //for each instance level reference of this class, generate the appropriate code if public
88
Reference[] references = MofHelper.referencesOfClass( c, true );
89         for (int i = 0; i < references.length; i++) {
90             referenceTemplate(references[i]);
91         }
92
93         //for each operation, generate the appropriate code if public_vis
94
Operation[] operations = MofHelper.operationsOfClass(c, ScopeKindEnum.INSTANCE_LEVEL, true );
95         for (int i = 0; i < operations.length; i++) {
96             if (operations[i].getVisibility().equals(VisibilityKindEnum.PUBLIC_VIS))
97                 operationTemplate(operations[i]);
98         }
99
100         //end
101
out.println("}"); //end of interface
102
out.flush();
103     }
104 }
105
Popular Tags