1 20 package org.objectweb.modfact.jmi.impl; 21 22 import javax.jmi.model.Attribute; 23 import javax.jmi.model.ModelElement; 24 import javax.jmi.model.MofClass; 25 import javax.jmi.model.Operation; 26 import javax.jmi.model.ScopeKindEnum; 27 28 import org.objectweb.modfact.jmi.helper.ImplHelper; 29 import org.objectweb.modfact.jmi.helper.JMIProvider; 30 import org.objectweb.modfact.jmi.helper.MofHelper; 31 import org.objectweb.modfact.jmi.logging.ModFactLogger; 32 33 37 public class ClassProxyImplementationGenerator 38 extends CommonImplementationGenerator { 39 40 MofClass[] input; 41 42 ModFactLogger logger; 43 44 47 public void setInput(ModelElement[] elt) { 48 input = new MofClass[elt.length]; 49 for (int i = 0; i < input.length; i++) { 50 input[i] = (MofClass) elt[i]; 51 } 52 } 53 54 57 public void setLogger(ModFactLogger log) { 58 logger = log; 59 } 60 61 64 public void generate() { 65 int c = 0; 67 68 outputln("package " +ImplHelper.implPrefix + JMIProvider.shortQualifierOf(input[c]) + ";" ); 69 outputln("import " + JMIProvider.qualifierOf(input[c]) + ".*;" ); 70 outputln("import org.objectweb.modfact.jmi.reflect.*;"); 71 outputln( 72 "public class " 73 + JMIProvider.jmiClassName(input[c]) 74 + "ClassImpl extends org.objectweb.modfact.jmi.reflect.RefClassImpl" 75 + " implements " 76 + JMIProvider.jmiClassQualifiedName(input[c]) +"Class" 77 + " {"); 78 79 creatorTemplate(input[c]); 80 newObjectTemplate(input[c]); 81 82 dataTypeTemplates(input[c]); 84 85 newEnumTemplate(input[c]); 86 newStructTemplate(input[c]); 87 88 Attribute[] attributes = MofHelper.attributesOfClass( 91 input[c], 92 ScopeKindEnum.forName("classifier_level"), true ); 93 for (int i = 0; i < attributes.length; i++) { 94 attributeTemplate(attributes[i]); 95 } 96 97 Operation[] operations = 98 MofHelper.operationsOfClass( 99 input[c], 100 ScopeKindEnum.forName("classifier_level"), true ); 101 for (int i = 0; i < operations.length; i++) { 102 operationTemplate(operations[i]); 103 } 104 105 outputln("}//end of interface"); 106 flushFile(); 107 } 108 109 void creatorTemplate(MofClass cl) { 110 if (!cl.isAbstract()) { 112 String javaType = JMIProvider.jmiClassQualifiedName(cl); 113 outputln( 114 "public " 115 + javaType 116 + " create" 117 + JMIProvider.jmiClassName(cl) 118 + "() throws javax.jmi.reflect.JmiException { "); 119 120 outputln("return (" 121 +javaType 122 +") refCreateInstance(null);"); 123 outputln("} \n"); 124 125 ArgList argList = new ArgList(); 126 Attribute[] attributes = MofHelper.attributesOfClass(cl, 127 ScopeKindEnum.forName("instance_level"), true ); 128 129 java.util.List v = new java.util.Vector (); 130 for(int i =0; i<attributes.length; i++) { 131 if(!attributes[i].isDerived()) v.add(attributes[i]); 132 } 133 attributes = (Attribute[]) v.toArray(new Attribute[0]); 134 135 if (attributes.length != 0) { 136 output( 137 "public " 138 + JMIProvider.jmiClassQualifiedName(cl) 139 + " create" 140 + JMIProvider.jmiClassName(cl) 141 + "("); 142 for (int i = 0; i < attributes.length; i++) { 144 145 output( 146 JMIProvider.typeTemplate(attributes[i]) +" " +attributes[i].getName() 147 ); 148 argList.add(attributes[i]); 149 if (i != attributes.length - 1) 150 output(" , "); 151 } 152 outputln(") throws javax.jmi.reflect.JmiException { \n"); 153 output(argList.code); 154 outputln("return (" 155 +javaType 156 +") refCreateInstance(list);"); 157 outputln("} \n"); 158 } 159 } 160 } 161 162 void newObjectTemplate(MofClass cl) { 163 outputln("public RefObjectImpl newObject() { "); 164 outputln("return new " +ImplHelper.implPrefix 165 +JMIProvider.shortQualifierOf(cl) 166 +"." 167 +JMIProvider.jmiClassName(cl)+"Impl();"); 168 outputln("}"); 169 } 170 171 } 172 | Popular Tags |