1 20 package org.objectweb.modfact.jmi.api; 21 22 23 import javax.jmi.model.*; 24 25 import org.objectweb.modfact.jmi.generator.BracketGenerator; 26 import org.objectweb.modfact.jmi.helper.*; 27 28 29 33 public abstract class CommonGenerator extends BracketGenerator { 34 35 36 public void attributeTemplate(Attribute attribute) { 37 if (attribute.getVisibility().equals(VisibilityKindEnum.forName("public_vis"))) { 38 40 structuralFeatureAccessor(attribute); 42 43 structuralFeatureMutator(attribute); 45 46 } 47 } 48 49 public void referenceTemplate(Reference reference) { 50 if (reference.getVisibility().equals(VisibilityKindEnum.forName("public_vis"))) { 51 53 structuralFeatureAccessor(reference); 55 56 structuralFeatureMutator(reference); 58 59 } 60 } 61 62 public void structuralFeatureAccessor(StructuralFeature f) { 63 64 String fType = JMIProvider.typeTemplate(f); 65 String accessorName = JMIProvider.jmiAccessorName(f); 66 67 outputln( 68 "public " 69 + fType 70 + " " 71 + accessorName 72 + "() throws javax.jmi.reflect.JmiException;"); 73 74 } 75 76 77 public void structuralFeatureMutator(StructuralFeature f) { 78 79 String mutatorName = JMIProvider.jmiMutatorName(f); 80 String fType = JMIProvider.typeTemplate(f); 81 82 if ( f.getMultiplicity().getUpper() == 1 && f.isChangeable() ) { 83 outputln( 84 "public void " 85 + mutatorName 86 + "(" 87 + fType 88 + " newValue) throws javax.jmi.reflect.JmiException;"); 89 } 90 } 91 92 93 public void operationTemplate(Operation operation) { 95 if (operation.getVisibility().equals(VisibilityKindEnum.forName("public_vis"))) { 96 Parameter[] parameters = MofHelper.parametersOf(operation); 99 MofException[] exceptions = MofHelper.exceptionsOf(operation); 100 Parameter returnParameter = null; 101 102 for(int i=0; i<parameters.length; i++) { 103 if(parameters[i].getDirection().equals(DirectionKindEnum.RETURN_DIR)) { 104 returnParameter = parameters[i]; 105 } 106 } 107 108 if (returnParameter==null) output("\tpublic void "); 109 else output("public " 110 +JMIProvider.typeTemplate(returnParameter) 111 +" " ); 112 113 output(operation.getName()+"("); 114 115 boolean comma = false; 116 for (int i=0 ; i <parameters.length ; i++) { 117 DirectionKind dir = parameters[i].getDirection(); 118 if ( !dir.equals(DirectionKindEnum.RETURN_DIR)) { 119 if (comma) output(","); 120 output( JMIProvider.typeTemplate(parameters[i]) +" " +parameters[i].getName()); 121 comma = true; 122 } 123 } 124 output(") throws "); 125 126 for (int i=0 ; i < exceptions.length ; i++) { 128 output(exceptions[i].getName()+","); 129 } 130 outputln("javax.jmi.reflect.JmiException;"); 131 } 132 } 133 134 135 136 137 138 public void dataTypeTemplates(Namespace ns) { 140 DataType[] containedDataTypes = 142 MofHelper.datatypesOf(ns, false); 143 for (int i = 0; i < containedDataTypes.length; i++) { 144 if ( containedDataTypes[i] instanceof StructureType) { 145 structTemplate((StructureType)containedDataTypes[i]); 146 } 147 } 148 } 149 150 public void structTemplate(StructureType t) { 151 152 output( 153 "public " 154 + JMIProvider.jmiDataTypeQualifiedName(t) 155 + " create" 156 + t.getName() 157 + " ("); 158 159 StructureField[] fields = MofHelper.structureFieldsOf(t); 160 for (int j = 0; j < fields.length; j++) { 161 output( JMIProvider.typeTemplate(fields[j]) ); 162 output(" "); 164 output(fields[j].getName()); if (j != fields.length - 1) 166 output(" , "); 167 } 168 outputln(") throws javax.jmi.reflect.JmiException;"); 169 170 } 171 172 public void constantTemplate(Constant constant) { 173 outputln( 176 "public final " 177 + "String" 178 + " " 179 + constant.getName() 180 + "= \"" 181 + constant.getValue() 182 + "\";"); 183 } 184 185 186 } 187 | Popular Tags |