1 20 package org.objectweb.modfact.corba.server; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.io.IOException ; 24 import org.objectweb.modfact.corba.logging.Level; 25 import org.objectweb.modfact.corba.logging.ModFactLogger; 26 27 import org.omg.mof.Model.ModelElement; 28 import org.omg.mof.Model.Package; 29 30 import org.objectweb.modfact.corba.generator.ZipGenerator; 31 import org.objectweb.modfact.corba.helper.IDLCommon; 32 import org.objectweb.modfact.corba.helper.JavaCommon; 33 import org.objectweb.modfact.corba.helper.MOFCommon; 34 import org.objectweb.modfact.corba.helper.XMIImportCommon; 35 36 40 public class ServerGenerator extends ZipGenerator { 41 42 private Package [] input; 43 44 private ModFactLogger logger; 45 46 private MOFCommon mofHelper; 47 private JavaCommon javaHelper; 48 private IDLCommon idlHelper; 49 private XMIImportCommon xmiImportHelper; 50 private boolean mappingValid; 51 52 55 public void setInput(ModelElement[] elt) { 56 input = new Package [elt.length]; 57 for (int i = 0; i < input.length; i++) { 58 input[i] = (Package ) elt[i]; 59 } 60 } 61 62 65 public void setLogger(ModFactLogger log) { 66 logger = log; 67 } 68 69 72 public ServerGenerator() { 73 } 74 75 78 public void generate() throws IOException { 79 logger.log(Level.FINE, "Begin generation of JMI Importer"); 80 81 java.util.List redundant_packages = new java.util.ArrayList (); 82 try { 83 for (int i = 0; i < input.length; i++) { 84 org.omg.mof.Model.ModelElement contents[] = input[i].contents(); 85 for (int j = 0; j < contents.length; j++) { 86 if (contents[j]._is_a(org.omg.mof.Model.PackageHelper.id())) { 87 redundant_packages.add(contents[j].ref_mof_id()); 88 } else if (contents[j]._is_a(org.omg.mof.Model.ImportHelper.id())) { 89 org.omg.mof.Model.Import imp = org.omg.mof.Model.ImportHelper.narrow(contents[j]); 90 redundant_packages.add(imp.imported_namespace().ref_mof_id()); 91 } 92 } 93 } 94 } catch (org.omg.mof.Reflective.MofError mofError) { 95 } 97 98 for (int p = 0; p < input.length; p++) { 99 if (redundant_packages.contains(input[p].ref_mof_id())) 101 continue; 102 Package [] param = new Package [1]; 103 param[0] = input[p]; 104 105 try { 106 String path = javaHelper.javaPackage(input[p]); 107 path = path.replace('.', '/') + "/"; 108 String className = idlHelper.format1(input[p].name()) + "Server"; 109 String baseFileName = path + className; 110 111 GenerationServer serverGenerator = new GenerationServer(); 112 ByteArrayOutputStream entryOutput1 = new ByteArrayOutputStream (); 113 serverGenerator.setOutput(entryOutput1); 114 serverGenerator.setIdlHelper(idlHelper); 115 serverGenerator.setJavaHelper(javaHelper); 116 serverGenerator.generateServer(param[0], className); 117 writeEntry(baseFileName + ".java", entryOutput1); 118 entryOutput1.close(); 119 120 GenerationServerApplication serverApplication = new GenerationServerApplication(); 122 entryOutput1 = new ByteArrayOutputStream (); 123 serverApplication.setOutput(entryOutput1); 124 serverApplication.setJavaHelper(javaHelper); 125 serverApplication.generateServerApplication(param[0], className, className + "Application"); 126 writeEntry(baseFileName + "Application.java", entryOutput1); 127 entryOutput1.close(); 128 129 logger.log(Level.FINE, "Server is generated"); 130 } catch (org.omg.CORBA.UserException userException) { 131 logger.log(Level.FATAL, "An error occurs during the generation (" + userException.getMessage() + ")"); 132 } 133 } 134 out.finish(); 135 logger.log(Level.FINE, " Generation is completed without error"); 136 } 137 138 141 public void setIdlHelper(IDLCommon common) { 142 idlHelper = common; 143 } 144 145 148 public void setJavaHelper(JavaCommon common) { 149 javaHelper = common; 150 } 151 152 155 public void setMofHelper(MOFCommon common) { 156 mofHelper = common; 157 } 158 159 162 public void setXmiImportHelper(XMIImportCommon common) { 163 xmiImportHelper = common; 164 } 165 166 169 public void setMappingValid(boolean b) { 170 mappingValid = b; 171 } 172 173 } 174 | Popular Tags |