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