1 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 31 public class ClassProxyImplementationGenerator 32 extends CommonImplementationGenerator { 33 34 MofClass[] input; 35 36 ModFactLogger logger; 37 38 41 public void setInput(ModelElement[] elt) { 42 input = new MofClass[elt.length]; 43 for (int i = 0; i < input.length; i++) { 44 input[i] = (MofClass) elt[i]; 45 } 46 } 47 48 51 public void setLogger(ModFactLogger log) { 52 logger = log; 53 } 54 55 58 public void generate() { 59 int c = 0; 61 62 out.println("package " +ImplHelper.implPrefix + JMIProvider.shortQualifierOf(input[c]) + ";" ); 63 out.println("import " + JMIProvider.qualifierOf(input[c]) + ".*;" ); 64 out.println("import org.objectweb.modfact.jmi.reflect.*;"); 65 out.println( 66 "public class " 67 + JMIProvider.jmiClassName(input[c]) 68 + "ClassImpl extends org.objectweb.modfact.jmi.reflect.RefClassImpl" 69 + " implements " 70 + JMIProvider.jmiClassQualifiedName(input[c]) +"Class" 71 + " {"); 72 73 creatorTemplate(input[c]); 74 newObjectTemplate(input[c]); 75 76 dataTypeTemplates(input[c]); 78 79 newEnumTemplate(input[c]); 80 newStructTemplate(input[c]); 81 82 Attribute[] attributes = MofHelper.attributesOfClass( 85 input[c], 86 ScopeKindEnum.forName("classifier_level"), true ); 87 for (int i = 0; i < attributes.length; i++) { 88 attributeTemplate(attributes[i]); 89 } 90 91 Operation[] operations = 92 MofHelper.operationsOfClass( 93 input[c], 94 ScopeKindEnum.forName("classifier_level"), true ); 95 for (int i = 0; i < operations.length; i++) { 96 operationTemplate(operations[i]); 97 } 98 99 out.println("}//end of interface"); 100 out.flush(); 101 } 102 103 void creatorTemplate(MofClass cl) { 104 if (!cl.isAbstract()) { 106 String javaType = JMIProvider.jmiClassQualifiedName(cl); 107 out.println( 108 "\tpublic " 109 + javaType 110 + " create" 111 + JMIProvider.jmiClassName(cl) 112 + "() throws javax.jmi.reflect.JmiException { "); 113 114 out.println("\t\t return (" 115 +javaType 116 +") refCreateInstance(null);"); 117 out.println("\t} \n"); 118 119 ArgList argList = new ArgList(); 120 Attribute[] attributes = MofHelper.attributesOfClass(cl, 121 ScopeKindEnum.forName("instance_level"), true ); 122 123 java.util.List v = new java.util.Vector (); 124 for(int i =0; i<attributes.length; i++) { 125 if(!attributes[i].isDerived()) v.add(attributes[i]); 126 } 127 attributes = (Attribute[]) v.toArray(new Attribute[0]); 128 129 if (attributes.length != 0) { 130 out.print( 131 "\tpublic " 132 + JMIProvider.jmiClassQualifiedName(cl) 133 + " create" 134 + JMIProvider.jmiClassName(cl) 135 + "("); 136 for (int i = 0; i < attributes.length; i++) { 138 139 out.print( 140 JMIProvider.typeTemplate(attributes[i]) +" " +attributes[i].getName() 141 ); 142 argList.add(attributes[i]); 143 if (i != attributes.length - 1) 144 out.print(" , "); 145 } 146 out.println(") throws javax.jmi.reflect.JmiException { \n"); 147 out.print(argList.code); 148 out.println("\t\t return (" 149 +javaType 150 +") refCreateInstance(list);"); 151 out.println("\t} \n"); 152 } 153 } 154 } 155 156 void newObjectTemplate(MofClass cl) { 157 out.println("\tpublic RefObjectImpl newObject() { "); 158 out.println("\t\treturn new " +ImplHelper.implPrefix 159 +JMIProvider.shortQualifierOf(cl) 160 +"." 161 +JMIProvider.jmiClassName(cl)+"Impl();"); 162 out.println("\t}"); 163 } 164 165 } 166 | Popular Tags |