1 20 package org.objectweb.modfact.jmi.impl.tayloredBased; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.io.IOException ; 24 import org.objectweb.modfact.jmi.helper.*; 25 import org.objectweb.modfact.jmi.logging.Level; 26 import org.objectweb.modfact.jmi.logging.ModFactLogger; 27 28 import javax.jmi.model.*; 29 30 import org.objectweb.modfact.jmi.generator.ZipGenerator; 31 32 33 37 public class JMI1_0ImplementationGenerator extends ZipGenerator { 38 39 MofPackage[] input; 40 41 ModFactLogger logger; 42 43 46 public void setInput(ModelElement[] elt) { 47 input = new MofPackage[elt.length]; 48 for (int i = 0; i < input.length; i++) { 49 input[i] = (MofPackage) elt[i]; 50 } 51 } 52 53 56 public void setLogger(ModFactLogger log) { 57 logger = log; 58 } 59 60 63 public void generate() 64 throws IOException { 65 66 67 logger.log(Level.FINE, "Begin generation of JMI Interfaces"); 68 69 for (int p = 0; p < input.length; p++) { 70 if (input[p] 71 .getVisibility() 72 .equals(VisibilityKindEnum.forName("public_vis"))) { 73 74 PackageImplementationGenerator packageGenerator = new PackageImplementationGenerator(); 76 MofPackage[] param = new MofPackage[1]; 77 param[0] = input[p]; 78 packageGenerator.setInput(param); 79 ByteArrayOutputStream entryOutput1 = 80 new ByteArrayOutputStream (); 81 packageGenerator.setOutput(entryOutput1); 82 packageGenerator.generate(); 83 84 String path = ImplHelper.implPrefix + JMIProvider.shortQualifierOf(input[p]); 85 path = path.replace('.', '/') +"/"; 86 87 String entryName = path 88 +JMIProvider.jmiPackageExtentName(input[p]) + "PackageImpl" + ".java"; 89 90 writeEntry(entryName, entryOutput1); 91 entryOutput1.close(); 92 93 logger.log(Level.FINE, entryName+" is generated"); 94 95 MofClass[] classes = MofHelper.classesOfPackage(input[p]); 97 98 for (int i = 0; i < classes.length; i++) { 99 if (classes[i].getVisibility() 100 == VisibilityKindEnum.forName("public_vis")) { 101 102 ClassProxyImplementationGenerator classProxyGenerator = new ClassProxyImplementationGenerator(); 104 MofClass[] paramCP = new MofClass[1]; 105 paramCP[0] = classes[i]; 106 classProxyGenerator.setInput(paramCP); 107 ByteArrayOutputStream entryOutputClassProxy = 108 new ByteArrayOutputStream (); 109 classProxyGenerator.setOutput(entryOutputClassProxy); 110 classProxyGenerator.generate(); 111 112 String entryNameClassProxy = path 113 +JMIProvider.jmiClassName(classes[i]) 114 + "ClassImpl" 115 + ".java"; 116 writeEntry(entryNameClassProxy, entryOutputClassProxy); 117 entryOutputClassProxy.close(); 118 119 logger.log(Level.FINE, entryNameClassProxy+" is generated"); 120 121 InstanceImplementationGenerator classImpl = new InstanceImplementationGenerator(); 123 MofClass[] paramCI = new MofClass[1]; 124 paramCI[0] = classes[i]; 125 classImpl.setInput(paramCI); 126 ByteArrayOutputStream entryOutputInstance = new ByteArrayOutputStream (); 127 classImpl.setOutput(entryOutputInstance); 128 classImpl.generate(); 129 130 String entryNameInstance = path 131 +JMIProvider.jmiClassName(classes[i]) + "Impl.java"; 132 writeEntry(entryNameInstance, entryOutputInstance); 133 entryOutputInstance.close(); 134 135 logger.log(Level.FINE, entryNameInstance+" is generated"); 136 137 DataType[] datatypes = 139 MofHelper.datatypesOf(classes[i], false); 140 for (int j = 0; j < datatypes.length; j++) { 141 142 if (datatypes[j] instanceof StructureType) { 143 StructureTypeImplementationGenerator structGenerator = 144 new StructureTypeImplementationGenerator(); 145 DataType[] inImpl = new DataType[1]; 146 inImpl[0] = datatypes[j]; 147 structGenerator.setInput(inImpl); 148 structGenerator.setLogger(logger); 149 150 ByteArrayOutputStream structEntryOutputImpl = 151 new ByteArrayOutputStream (); 152 structGenerator.setOutput( 153 structEntryOutputImpl); 154 structGenerator.generate(); 155 156 String entryNameStruct = path 157 +datatypes[j].getName() + "Impl.java"; 158 writeEntry( 159 entryNameStruct, 160 structEntryOutputImpl); 161 structEntryOutputImpl.close(); 162 163 logger.log(Level.FINE, entryNameStruct+" is generated"); 164 } 165 } 166 167 } 168 } 169 170 Association[] associations = 172 MofHelper.associationsOfPackage(input[p]); 173 for (int i = 0; i < associations.length; i++) { 174 if (associations[i] 175 .getVisibility() 176 .equals(VisibilityKindEnum.forName("public_vis"))) { 177 AssociationImplementationGenerator associationGenerator = 178 new AssociationImplementationGenerator(); 179 Association[] paramA = new Association[1]; 180 paramA[0] = associations[i]; 181 associationGenerator.setInput(paramA); 182 ByteArrayOutputStream entryOutputAssociation = 183 new ByteArrayOutputStream (); 184 associationGenerator.setOutput(entryOutputAssociation); 185 186 associationGenerator.generate(); 187 188 String entryNameAssociation = path+ 189 JMIProvider.jmiAssociationName(associations[i]) 190 + "Impl.java"; 191 writeEntry( 192 entryNameAssociation, 193 entryOutputAssociation); 194 entryOutputAssociation.close(); 195 196 logger.log(Level.FINE, entryNameAssociation+" is generated"); 197 } 198 } 199 200 DataType[] datatypes = MofHelper.datatypesOf(input[p], false); 202 for (int i = 0; i < datatypes.length; i++) { 203 if (datatypes[i] instanceof StructureType) { 204 StructureTypeImplementationGenerator structureTypeInterfaceGenerator = 205 new StructureTypeImplementationGenerator(); 206 DataType[] paramT = new DataType[1]; 207 paramT[0] = datatypes[i]; 208 structureTypeInterfaceGenerator.setInput(paramT); 209 ByteArrayOutputStream entryOutputDataType = 210 new ByteArrayOutputStream (); 211 structureTypeInterfaceGenerator.setOutput( 212 entryOutputDataType); 213 214 structureTypeInterfaceGenerator.generate(); 215 216 String entryNameStructure = path+ 217 datatypes[i].getName() + "Impl.java"; 218 writeEntry(entryNameStructure, entryOutputDataType); 219 entryOutputDataType.close(); 220 221 logger.log(Level.FINE, entryNameStructure+" is generated"); 222 } 223 } 224 225 } 226 } 227 out.finish(); 228 logger.log(Level.FINE, " Generation is completed without error"); 229 } 230 231 } 232 | Popular Tags |