1 20 package org.objectweb.modfact.jmi.xmiio.importer; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.io.IOException ; 24 import org.objectweb.modfact.jmi.logging.Level; 25 import org.objectweb.modfact.jmi.logging.ModFactLogger; 26 27 import javax.jmi.model.ModelElement; 28 import javax.jmi.model.MofPackage; 29 import javax.jmi.model.VisibilityKindEnum; 30 31 import org.objectweb.modfact.jmi.generator.ZipGenerator; 32 import org.objectweb.modfact.jmi.helper.JMIProvider; 33 34 38 public class JMI1_0ImportGenerator extends ZipGenerator { 39 40 MofPackage[] input; 41 42 ModFactLogger logger; 43 44 47 public void setInput(ModelElement[] elt) { 48 input = new MofPackage[elt.length]; 49 for (int i = 0; i < input.length; i++) { 50 input[i] = (MofPackage) elt[i]; 51 } 52 } 53 54 57 public void setLogger(ModFactLogger log) { 58 logger = log; 59 } 60 61 public JMI1_0ImportGenerator() { 62 } 63 64 67 public void generate() 68 throws IOException { 69 logger.log(Level.FINE, "Begin generation of JMI Importer"); 70 71 for (int p = 0; p < input.length; p++) { 72 if (input[p] 73 .getVisibility() 74 .equals(VisibilityKindEnum.forName("public_vis")) 75 && input[p].refGetValue("container") == null) { 76 77 MofPackage[] param = new MofPackage[1]; 79 param[0] = input[p]; 80 81 String path = JMIProvider.qualifierOf(input[p]); 82 path = path.replace('.', '/') +"/"; 83 String className = JMIProvider.jmiPackageExtentName(input[p]) + "XMIImport"; 84 String baseFileName = path + className; 85 86 GenerationXMIImport importGenerator = new GenerationXMIImport(); 87 ByteArrayOutputStream entryOutput1 = new ByteArrayOutputStream (); 88 importGenerator.setOutput(entryOutput1); 89 importGenerator.generateXMIImport(param[0]); 90 writeEntry(baseFileName + ".java", entryOutput1); 91 entryOutput1.close(); 92 93 94 GenerationXMIImportAttributes xmiImportAttributes = new GenerationXMIImportAttributes(); 96 entryOutput1 = new ByteArrayOutputStream (); 97 xmiImportAttributes.setOutput(entryOutput1); 98 xmiImportAttributes.generateXMIImportAttributes(param[0], className + "Attributes"); 99 writeEntry(baseFileName + "Attributes.java", entryOutput1); 100 entryOutput1.close(); 101 102 GenerationXMIImportClasses xmiImportClasses = new GenerationXMIImportClasses(); 104 entryOutput1 = new ByteArrayOutputStream (); 105 xmiImportClasses.setOutput(entryOutput1); 106 xmiImportClasses.generateXMIImportClasses(param[0], className + "Classes"); 107 writeEntry(baseFileName + "Classes.java", entryOutput1); 108 entryOutput1.close(); 109 110 GenerationXMIImportAssociations xmiImportAssociations = new GenerationXMIImportAssociations(); 112 entryOutput1 = new ByteArrayOutputStream (); 113 xmiImportAssociations.setOutput(entryOutput1); 114 xmiImportAssociations.generateXMIImportAssociations(param[0], className + "Associations"); 115 writeEntry(baseFileName + "Associations.java", entryOutput1); 116 entryOutput1.close(); 117 118 GenerationXMIImportApplication xmiImportApplication = new GenerationXMIImportApplication(); 120 entryOutput1 = new ByteArrayOutputStream (); 121 xmiImportApplication.setOutput(entryOutput1); 122 xmiImportApplication.generateXMIImportApplication(param[0], className, className + "Application"); 123 writeEntry(baseFileName + "Application.java", entryOutput1); 124 entryOutput1.close(); 125 126 logger.log(Level.FINE, "Importer is generated"); 127 } 128 } 129 out.finish(); 130 logger.log(Level.FINE, " Generation is completed without error"); 131 } 132 133 } 134 | Popular Tags |