KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.objectweb.modfact.jmi.impl;
2
3 import javax.jmi.model.Attribute;
4 import javax.jmi.model.ModelElement;
5 import javax.jmi.model.MofClass;
6 import javax.jmi.model.Operation;
7 import javax.jmi.model.Reference;
8 import javax.jmi.model.ScopeKindEnum;
9 import javax.jmi.model.VisibilityKindEnum;
10
11 import org.objectweb.modfact.jmi.helper.ImplHelper;
12 import org.objectweb.modfact.jmi.helper.JMIProvider;
13 import org.objectweb.modfact.jmi.helper.MofHelper;
14 import org.objectweb.modfact.jmi.logging.ModFactLogger;
15
16
17 /**
18  * @author Xavier
19  *
20  */

21 public class InstanceImplementationGenerator extends CommonImplementationGenerator {
22     MofClass[] input;
23
24     ModFactLogger logger;
25
26     /**
27      * Set Input
28      */

29     public void setInput(ModelElement[] elt) {
30         input = new MofClass[elt.length];
31         for (int i = 0; i < input.length; i++) {
32             input[i] = (MofClass) elt[i];
33         }
34     }
35
36     /**
37      * Set Trace
38      */

39     public void setLogger(ModFactLogger log) {
40         logger = log;
41     }
42
43     /**
44      * @see org.objectweb.modfact.generation.Generator#generate()
45      */

46     public void generate() {
47
48         MofClass c = input[0];
49
50         outputln("package " +ImplHelper.implPrefix + JMIProvider.shortQualifierOf(c) + ";" );
51         outputln("import " + JMIProvider.qualifierOf(c) + ".*;" );
52         
53         outputln("import org.objectweb.modfact.jmi.reflect.*;");
54
55         output("public class " + JMIProvider.jmiClassName(c) +"Impl"
56             +" extends RefObjectImpl "
57             +"implements "
58             +JMIProvider.jmiClassQualifiedName(c)
59             +" {" );
60
61
62         //for each instance level attribute of this class, generate the appropriate code
63
//MofAttribute[] attributes_d = MofHelper.attributesOfClass(c , ScopeKind.instance_level , true );
64
//for (int i = 0 ; i < attributes_d.length ; i++) {
65
// attributeTemplate(attributes_d[i]);
66
//}
67

68         Attribute[] attributes_nd =
69             MofHelper.attributesOfClass(
70                 c,
71                 ScopeKindEnum.forName("instance_level"), true);
72                 
73         for (int i = 0; i < attributes_nd.length; i++) {
74             attributeTemplate(attributes_nd[i]);
75         }
76
77         //for each instance level reference of this class, generate the appropriate code if public
78
Reference[] references = MofHelper.referencesOfClass( c, true );
79         for (int i = 0; i < references.length; i++) {
80             referenceTemplate(references[i]);
81         }
82
83         //for each operation, generate the appropriate code if public_vis
84
Operation[] operations = MofHelper.operationsOfClass(c, ScopeKindEnum.INSTANCE_LEVEL, true );
85         for (int i = 0; i < operations.length; i++) {
86             if (operations[i].getVisibility().equals(VisibilityKindEnum.PUBLIC_VIS))
87                 operationTemplate(operations[i]);
88         }
89
90         //end
91
outputln("}"); //end of interface
92
flushFile();
93     }
94 }
95
Popular Tags