1 26 27 package org.objectweb.corba.command.lib; 28 29 import org.objectweb.util.cmdline.lib.DefaultCommandLine; 31 import org.objectweb.util.cmdline.lib.DefaultOptionArgument; 32 import org.objectweb.util.cmdline.lib.DefaultOptionArguments; 33 import org.objectweb.openccm.ast.api.FileScope; 34 import org.objectweb.openccm.command.lib.CompilerGeneratorBase; 35 import org.objectweb.openccm.command.lib.OptionMultipleArguments; 36 37 import java.util.List ; 38 39 47 48 public class CIDLtoCIF 49 extends CompilerGeneratorBase 50 implements org.objectweb.corba.command.api.CIDLtoCIF 51 { 52 58 59 private OptionMultipleArguments userInclude_; 60 61 62 org.objectweb.util.cmdline.api.OptionArgument odir_; 64 65 org.objectweb.util.cmdline.api.OptionArgument depdir_; 67 68 org.objectweb.util.cmdline.api.OptionArguments noprefix_; 70 76 77 public 78 CIDLtoCIF() 79 { 80 super(new DefaultCommandLine("cidl_cif", 82 "file", 83 new String [] { 84 "Compile an OMG CIDL file and generate its associated:", 85 "- local CIF interfaces", 86 "- Java component and home executor skeletons", 87 "- class dependencies files" 88 }, 89 true), 90 "generated_cif.idl"); 91 92 userInclude_ = new OptionMultipleArguments( 94 "-ipath", 95 new String [] { "-ipath" }, 96 "file", 97 new String [] { 98 "Add a #include \"file\" statement where", 99 "file must be the complete file path" 100 }, 101 "", 102 true); 103 getCommandLine().addOption(userInclude_); 104 105 odir_ = new DefaultOptionArgument( 107 new String [] { "-d" }, 108 "outputdir", 109 new String [] { 110 "Generate Java implementations into directory <outputdir>,", 111 "default is generated/" 112 }, 113 "generated" ); 114 getCommandLine().addOption(odir_); 115 116 depdir_ = new DefaultOptionArgument( 118 new String [] { "-dep" }, 119 "dependencies_dir", 120 new String [] { 121 "Generate CIDL class dependencies into directory <dependencies_dir>,", 122 "default is dependencies/" 123 }, 124 "dependencies" ); 125 getCommandLine().addOption(depdir_); 126 127 noprefix_ = new DefaultOptionArguments( 129 new String [] { "--noprefix" }, 130 "aprefix", 131 new String [] { 132 "CIDL class dependencies starting with <aprefix>", 133 "will not be included." 134 } ); 135 getCommandLine().addOption(noprefix_); 136 } 137 138 144 150 156 163 public int 164 run(java.lang.String [] args) 165 { 166 String filename = args[0]; 167 168 if(!initAST()) 170 return -1; 171 172 FileScope fileScope = compile(filename); 174 if(fileScope == null) 175 return -1; 176 177 if (!generate_cif(fileScope, 179 filename, getOutputFileName(), getCIFOutputDirectory(), userInclude_.getOptionArguments())) 183 return -1; 184 185 if ( !generate_cif_dependencies(fileScope, 187 getDependenciesOutputDirectory(), 188 getNoPrefix()) ) 189 return -1; 190 191 return 0; 193 } 194 195 201 207 213 219 225 230 public String 231 getCIFOutputDirectory() 232 { 233 return odir_.getArgument(); 234 } 235 236 241 public String 242 getDependenciesOutputDirectory() 243 { 244 return depdir_.getArgument(); 245 } 246 247 252 public String [] 253 getNoPrefix() 254 { 255 return noprefix_.getOptionValues(); 256 } 257 258 273 public boolean 274 generate_cif(FileScope filescope, 275 String inputfile, 276 String outputfile, 277 String base_dir, 278 String [] userIncludes) 279 { 280 List list = null; 281 282 org.objectweb.corba.generator.cif_idl.api.CIF_IDLGenerator cif_gen = 284 new org.objectweb.corba.generator.cif_idl.lib.CIF_IDLGenerator( getAST(), 285 getComponentRepository() ); 286 try 287 { 288 list = cif_gen.declare_cif(filescope); 289 } 290 catch(org.objectweb.openccm.generator.common.lib.GenerationException ex) 291 { 292 report_exception(ex); 293 return false; 294 } 295 296 getComponentRepository().as_IDL2_repository(); 298 299 org.objectweb.openccm.generator.idl.api.IDL2Generator idl2_gen = 301 new org.objectweb.openccm.generator.idl.lib.IDL2Generator( getAST() ); 302 idl2_gen.initialize(outputfile, 303 outputfile, 304 new java.util.ArrayList (), new java.util.ArrayList (java.util.Arrays.asList(userIncludes)), null, 307 "CIDLtoCIF" ); 308 309 getConsole().message("Generating CIF mapping from " + inputfile + "..."); 311 try 312 { 313 idl2_gen.generate(list); 314 } 315 catch(org.objectweb.openccm.generator.common.lib.GenerationException ex) 316 { 317 report_exception(ex); 318 return false; 319 } 320 getConsole().message("OMG IDL mapping generated in " + outputfile + "."); 321 322 org.objectweb.corba.generator.cif.lib.CIF_JavaGenerator cif_impl_gen = 324 new org.objectweb.corba.generator.cif.lib.CIF_JavaGenerator( getAST() ); 325 getConsole().message("Generating CIF implementations..."); 326 try 327 { 328 cif_impl_gen.cif_to_java(base_dir, filescope); 329 } 330 catch(org.objectweb.openccm.generator.common.lib.GenerationException ex) 331 { 332 report_exception(ex); 333 return false; 334 } 335 getConsole().message("CIF implementations generated."); 336 337 cif_gen.remove_decls(); 339 340 getComponentRepository().as_IDL3_repository(); 342 343 return true; 344 } 345 346 358 public boolean 359 generate_cif_dependencies(FileScope filescope, 360 String base_dir, 361 String [] unwanted_prefixs) 362 { 363 org.objectweb.corba.generator.dependencies.api.CIDLFileDependenciesResolver dep_resolver = null; 364 365 dep_resolver = 366 new org.objectweb.corba.generator.dependencies.lib.CIDLFileDependenciesResolver( getAST() ); 367 getConsole().message("Generating CIDL dependencies..."); 368 try 369 { 370 dep_resolver.set_filters(unwanted_prefixs); 371 dep_resolver.generate_dependencies( filescope, base_dir ); 372 } 373 catch(org.objectweb.openccm.generator.common.lib.GenerationException ex) 374 { 375 report_exception(ex); 376 return false; 377 } 378 getConsole().message("CIDL dependencies generated."); 379 380 return true; 381 } 382 383 389 394 public static void 395 main(String [] args) 396 { 397 CIDLtoCIF cidl2cif = new CIDLtoCIF(); 398 cidl2cif.runMain(args); 399 } 400 } 401 | Popular Tags |