1 20 package org.objectweb.modfact.jmi.service; 21 22 import java.io.FileInputStream ; 23 import java.io.FileOutputStream ; 24 import java.io.InputStream ; 25 import java.io.OutputStream ; 26 27 import javax.jmi.model.ModelPackage; 28 import javax.jmi.model.MofPackage; 29 import javax.jmi.xmi.XmiReader; 30 31 import org.objectweb.modfact.jmi.logging.ModFactLogger; 33 34 import org.objectweb.modfact.jmi.impl.JMI1_0ImplementationGenerator; 36 import org.objectweb.modfact.jmi.api.JMI1_0Generator; 37 import org.objectweb.modfact.jmi.xmiio.exporter.JMI1_0ExportGenerator; 38 import org.objectweb.modfact.jmi.xmiio.importer.JMI1_0ImportGenerator; 39 40 import org.objectweb.modfact.jmi.xmi.XmiReaderImpl; 42 import org.objectweb.modfact.jmi.reflect.RefPackageImpl; 43 44 45 46 public class Generation {; 47 48 49 protected MofPackage[] allPackages; 50 51 59 public void execute(InputStream metaModelFile, OutputStream apiFile, OutputStream implFile, OutputStream importFile, OutputStream exportFile) 60 throws java.io.IOException , javax.jmi.xmi.MalformedXMIException { 61 62 ModelPackage modelPackage; 63 modelPackage = (ModelPackage) RefPackageImpl.getM2Repository(); 64 XmiReader reader = new XmiReaderImpl(); 66 reader.read(metaModelFile, "", modelPackage); 67 setMetaModel(modelPackage); 68 69 if(apiFile!=null) { 70 generateAPIs(apiFile); 71 } 72 if(implFile!=null) { 73 generateImpl(implFile); 74 } 75 if(importFile!=null) { 76 generateImport(importFile); 77 } 78 if(exportFile!=null) { 79 generateExport(exportFile); 80 } 81 } 82 83 91 public void execute(String metaModelFile, String apiFile, String implFile, String importFile, String exportFile) 92 throws java.io.IOException , javax.jmi.xmi.MalformedXMIException { 93 94 ModelPackage modelPackage; 95 modelPackage = (ModelPackage) RefPackageImpl.getM2Repository(); 96 XmiReader reader = new XmiReaderImpl(); 98 reader.read(new FileInputStream (metaModelFile), "", modelPackage); 99 setMetaModel(modelPackage); 100 101 if(apiFile!=null) { 102 generateAPIs(new FileOutputStream (apiFile)); 103 } 104 if(implFile!=null) { 105 generateImpl(new FileOutputStream (implFile)); 106 } 107 if(importFile!=null) { 108 generateImport(new FileOutputStream (importFile)); 109 } 110 if(exportFile!=null) { 111 generateExport(new FileOutputStream (exportFile)); 112 } 113 } 114 115 public void setMetaModel(ModelPackage modelPackage) { 116 allPackages = (MofPackage[]) modelPackage.getMofPackage().refAllOfType().toArray(new MofPackage[0]); 117 } 118 119 public void generateAPIs(OutputStream out) 120 throws java.io.IOException { 121 ModFactLogger logger = 122 ModFactLogger.getLogger("fr.lip6.modfact.generator.jmi.JMI1_0Generator"); 123 124 JMI1_0Generator jmiGenerator = new JMI1_0Generator(); 125 jmiGenerator.setLogger(logger); 126 jmiGenerator.setInput(allPackages); 127 jmiGenerator.setOutput(out); 128 jmiGenerator.generate(); 129 } 131 132 public void generateImpl(OutputStream out) 133 throws java.io.IOException { 134 ModFactLogger logger = 135 ModFactLogger.getLogger( 136 "fr.lip6.modfact.generator.jmi_impl.JMI1_0Generator_impl"); 137 JMI1_0ImplementationGenerator jmiGenerator = new JMI1_0ImplementationGenerator(); 138 jmiGenerator.setLogger(logger); 139 jmiGenerator.setInput(allPackages); 140 jmiGenerator.setOutput(out); 141 jmiGenerator.generate(); 142 } 144 145 public void generateImport(OutputStream out) 146 throws java.io.IOException { 147 148 ModFactLogger logger = 149 ModFactLogger.getLogger( 150 "fr.lip6.modfact.generator.jmi_impl.JMI1_0ImportGenerator_impl"); 151 152 JMI1_0ImportGenerator jmiImportGenerator = new JMI1_0ImportGenerator(); 153 jmiImportGenerator.setLogger(logger); 154 jmiImportGenerator.setInput(allPackages); 155 jmiImportGenerator.setOutput(out); 156 jmiImportGenerator.generate(); 157 } 159 160 public void generateExport(OutputStream out) 161 throws java.io.IOException { 162 163 ModFactLogger logger = 164 ModFactLogger.getLogger( 165 "fr.lip6.modfact.generator.jmi_impl.JMI1_0ExportGenerator_impl"); 166 167 JMI1_0ExportGenerator jmiExportGenerator = new JMI1_0ExportGenerator(); 168 jmiExportGenerator.setLogger(logger); 169 jmiExportGenerator.setInput(allPackages); 170 jmiExportGenerator.setOutput(out); 171 jmiExportGenerator.generate(); 172 } 174 175 } 176 | Popular Tags |