1 20 package org.objectweb.modfact.jmi.api; 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.JMIProvider; 29 import org.objectweb.modfact.jmi.helper.MofHelper; 30 import org.objectweb.modfact.jmi.logging.ModFactLogger; 31 32 33 37 public class ClassProxyInterfaceGenerator 38 extends CommonGenerator { 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( 74 "package " + JMIProvider.qualifierOf(input[c]) + ";" ); 75 76 outputln( 77 "public interface " 78 + JMIProvider.jmiClassName(input[c]) 79 + "Class extends javax.jmi.reflect.RefClass {"); 80 81 creatorTemplate(input[c]); 82 83 dataTypeTemplates(input[c]); 85 86 Attribute[] attributes = MofHelper.attributesOfClass( 89 input[c], 90 ScopeKindEnum.forName("classifier_level"), false ); 91 92 for (int i = 0; i < attributes.length; i++) { 93 attributeTemplate(attributes[i]); 94 } 95 96 Operation[] operations = 98 MofHelper.operationsOfClass( 99 input[c], 100 ScopeKindEnum.forName("classifier_level") 101 ,false ); 102 for (int i = 0; i < operations.length; i++) { 103 operationTemplate(operations[i]); 104 } 105 106 outputln("}//end of interface"); 107 flushFile(); 108 } 109 110 void creatorTemplate(MofClass cl) { 111 if (!cl.isAbstract()) { 113 outputln( 114 "public " 115 + JMIProvider.jmiClassQualifiedName(cl) 116 + " create" 117 + JMIProvider.jmiClassName(cl) 118 + "() throws javax.jmi.reflect.JmiException;\n"); 119 120 Attribute[] attributes = 121 MofHelper.attributesOfClass( 122 cl, 123 ScopeKindEnum.forName("instance_level"), true ); 124 125 java.util.List v = new java.util.Vector (); 126 for(int i =0; i<attributes.length; i++) { 127 if(!attributes[i].isDerived()) v.add(attributes[i]); 128 } 129 attributes = (Attribute[]) v.toArray(new Attribute[0]); 130 131 if (attributes.length != 0) { 132 output( 133 "public " 134 + JMIProvider.jmiClassQualifiedName(cl) 135 + " create" 136 + JMIProvider.jmiClassName(cl) 137 + "("); 138 for (int i = 0; i < attributes.length; i++) { 140 output( 141 JMIProvider.typeTemplate(attributes[i]) +" " +attributes[i].getName() 142 ); 143 if (i != attributes.length - 1) 144 output(" , "); 145 } 146 outputln(") throws javax.jmi.reflect.JmiException;\n"); 147 } 148 149 } 150 } 151 152 } 153 | Popular Tags |