1 20 package org.objectweb.modfact.corba.idl2java; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.io.IOException ; 24 25 import org.objectweb.modfact.corba.generator.ZipGenerator; 26 import org.objectweb.modfact.corba.helper.JavaCommon; 27 import org.objectweb.modfact.corba.helper.MOFCommon; 28 import org.objectweb.modfact.corba.logging.Level; 29 import org.objectweb.modfact.corba.logging.ModFactLogger; 30 31 public class IDL2JavaMOF1_3Generator extends ZipGenerator { 32 33 private org.omg.mof.Model.Package[] input; 34 35 private MOFCommon mofHelper; 36 37 private JavaCommon javaHelper; 38 39 private ModFactLogger logger; 40 41 44 public void setInput(org.omg.mof.Model.ModelElement[] elt) { 45 input = new org.omg.mof.Model.Package[elt.length]; 46 for (int i = 0; i < input.length; i++) { 47 input[i] = (org.omg.mof.Model.Package) elt[i]; 48 } 49 } 50 51 54 public void setLogger(ModFactLogger log) { 55 logger = log; 56 } 57 58 61 public void generate() 62 throws 63 org.omg.mof.Reflective.MofError, 64 org.omg.CORBA.TypeCodePackage.BadKind , 65 org.omg.CORBA.TypeCodePackage.Bounds , 66 org.omg.mof.Reflective.NotSet, 67 java.io.FileNotFoundException , 68 IOException { 69 70 logger.log(Level.FINE, "IDL2Java Start Generation of "+input.length+" packages"); 72 for (int i = 0; i < input.length; i++) { 73 74 if (input[i] 75 .visibility() 76 .equals(org.omg.mof.Model.VisibilityKind.public_vis)) { 77 78 org.omg.mof.Model.Package[] apackage = 79 new org.omg.mof.Model.Package[1]; 80 apackage[0] = input[i]; 81 82 logger.log(Level.FINE , "package "+apackage[0].name()); 83 84 PackageImplementationGenerator packageImpl = 86 new PackageImplementationGenerator(); 87 packageImpl.setInput(apackage); 88 ByteArrayOutputStream entryOutput1 = 89 new ByteArrayOutputStream (); 90 packageImpl.setOutput(entryOutput1); 91 packageImpl.setMofHelper(mofHelper); 92 packageImpl.setJavaHelper(javaHelper); 93 packageImpl.generate(); 94 95 String entryName = 96 javaHelper.format1Idl2JavaConflict( 97 input[i].name() + "Package") 98 + "Impl.java"; 99 writeEntry(entryName, entryOutput1); 100 entryOutput1.close(); 101 102 PackageFactoryImplementationGenerator packageFactoryImpl = 103 new PackageFactoryImplementationGenerator(); 104 packageFactoryImpl.setInput(apackage); 105 ByteArrayOutputStream entryOutput2 = 107 new ByteArrayOutputStream (); 108 packageFactoryImpl.setOutput(entryOutput2); 109 packageFactoryImpl.setMofHelper(mofHelper); 110 packageFactoryImpl.setJavaHelper(javaHelper); 111 packageFactoryImpl.generate(); 112 entryName = 113 javaHelper.format1Idl2JavaConflict( 114 input[i].name() + "PackageFactory") 115 + "Impl.java"; 116 writeEntry(entryName, entryOutput2); 117 entryOutput2.close(); 118 119 121 org.omg.mof.Model.Class[] classes = 123 mofHelper.classesOfPackage(input[i]); 124 125 for (int j = 0; j < classes.length; j++) { 126 logger.log(Level.FINE, "Class "+classes[j].name()); 127 if (classes[0].visibility() 128 == org.omg.mof.Model.VisibilityKind.public_vis) { 129 130 org.omg.mof.Model.Class[] aclass = 131 new org.omg.mof.Model.Class[1]; 132 aclass[0] = classes[j]; 133 134 136 ClassProxyImplementationGenerator classProxyImpl = 137 new ClassProxyImplementationGenerator(); 138 classProxyImpl.setInput(aclass); 139 ByteArrayOutputStream entryOutputCP = 142 new ByteArrayOutputStream (); 143 classProxyImpl.setOutput(entryOutputCP); 144 classProxyImpl.setMofHelper(mofHelper); 145 classProxyImpl.setJavaHelper(javaHelper); 146 classProxyImpl.generate(); 147 String entryNameCP = 148 javaHelper.format1Idl2JavaConflict( 149 javaHelper.javaClassName(classes[j]) + "Class") 150 + "Impl.java"; 151 writeEntry(entryNameCP, entryOutputCP); 152 entryOutputCP.close(); 153 logger.log(Level.FINER , "Entry "+entryNameCP+" has been added"); 154 155 if (!(classes[j].is_abstract())) { 157 ClassImplementationGenerator classImpl = 158 new ClassImplementationGenerator(); 159 classImpl.setInput(aclass); 160 ByteArrayOutputStream entryOutputC = 162 new ByteArrayOutputStream (); 163 classImpl.setOutput(entryOutputC); 164 classImpl.setMofHelper(mofHelper); 165 classImpl.setJavaHelper(javaHelper); 166 classImpl.generate(); 167 168 String entryNameC = 169 javaHelper.format1Idl2JavaConflict( 170 javaHelper.javaClassName(classes[j])) 171 + "Impl.java"; 172 writeEntry(entryNameC, entryOutputC); 173 entryOutputC.close(); 174 logger.log(Level.FINER , "Entry "+entryNameC+" has been added"); 175 } 176 } 177 } 178 179 org.omg.mof.Model.Association[] associations = 181 mofHelper.associationsOfPackage(input[i]); 182 for (int j = 0; j < associations.length; j++) { 183 if (associations[j].visibility() 184 == org.omg.mof.Model.VisibilityKind.public_vis) { 185 org.omg.mof.Model.Association[] anasso = 186 new org.omg.mof.Model.Association[1]; 187 anasso[0] = associations[j]; 188 189 AssociationImplementationGenerator associationImpl = 190 new AssociationImplementationGenerator(); 191 associationImpl.setInput(anasso); 192 ByteArrayOutputStream entryOutputA = 194 new ByteArrayOutputStream (); 195 associationImpl.setOutput(entryOutputA); 196 associationImpl.setMofHelper(mofHelper); 197 associationImpl.setJavaHelper(javaHelper); 198 associationImpl.generate(); 199 200 String entryNameA = 201 javaHelper.format1Idl2JavaConflict( 202 associations[j].name()) 203 + "Impl.java"; 204 writeEntry(entryNameA, entryOutputA); 205 entryOutputA.close(); 206 } 207 } 208 209 org.omg.mof.Model.Package[] packages = 211 mofHelper.packagesOfPackage(input[i]); 212 if (packages.length != 0) { 213 IDL2JavaMOF1_3Generator javaGenerator = 214 new IDL2JavaMOF1_3Generator(); 215 javaGenerator.setLogger(logger); 216 javaGenerator.setInput(packages); 217 javaGenerator.setMofHelper(mofHelper); 218 javaGenerator.setJavaHelper(javaHelper); 219 ByteArrayOutputStream entryOutputPackage = 220 new ByteArrayOutputStream (); 221 javaGenerator.setOutput(entryOutputPackage); 222 javaGenerator.generate(); 223 224 String entryNameP = 225 javaHelper.format1Idl2JavaConflict(input[i].name()) 226 + "NestedPackages.zip"; 227 writeEntry(entryNameP, entryOutputPackage); 228 entryOutputPackage.close(); 229 } 230 231 } 232 } 233 logger.log(Level.FINE, "IDL2Java Generation of "+input.length+" packages ended !!!"); 234 out.finish(); 235 } 236 237 241 public JavaCommon getJavaHelper() { 242 return javaHelper; 243 } 244 245 249 public MOFCommon getMofHelper() { 250 return mofHelper; 251 } 252 253 257 public void setJavaHelper(JavaCommon javaHelper) { 258 this.javaHelper = javaHelper; 259 } 260 261 265 public void setMofHelper(MOFCommon mofHelper) { 266 this.mofHelper = mofHelper; 267 } 268 269 } | Popular Tags |