1 26 27 package org.objectweb.openccm.command.lib; 28 29 import org.objectweb.util.cmdline.lib.DefaultCommandLine; 32 import java.util.ArrayList ; 33 34 42 43 public class IR3toIDL2 44 extends GeneratorBase 45 implements org.objectweb.openccm.command.api.IR3toIDL2 46 { 47 53 54 private OptionMultipleArguments include_; 55 private OptionMultipleArguments userInclude_; 56 57 63 64 public 65 IR3toIDL2() 66 { 67 super(new DefaultCommandLine("ir3_idl2", 69 "declaration", 70 "Generate OMG IDL2 for a declaration from the OpenCCM Interface Repository", 71 true), 72 "generated.idl"); 73 74 include_ = new OptionMultipleArguments( 77 "-i", 78 new String [] { "-i" }, 79 "file", 80 new String [] { "Add a #include <file> statement" }, 81 "", 82 true ); 83 getCommandLine().addOption(include_); 84 85 userInclude_ = new OptionMultipleArguments( 87 "-ipath", 88 new String [] { "-ipath" }, 89 "file", 90 new String [] { 91 "Add a #include \"file\" statement where", 92 "file must be the complete file path" 93 }, 94 "", 95 true); 96 getCommandLine().addOption(userInclude_); 97 } 98 99 105 111 117 124 public int 125 run(java.lang.String [] args) 126 { 127 if(!initAST()) 129 return -1; 130 131 String localfilename = getOutputFileName(); 133 int index = localfilename.lastIndexOf('.'); 134 if ((index == -1) || (index == localfilename.length())) 135 localfilename += "_local"; 136 else 137 localfilename = localfilename.substring(0, index) + "_local" 138 + localfilename.substring(index); 139 140 if (!generate_idl2(args[0], 142 getOutputFileName(), 143 localfilename, 144 include_.getOptionArguments(), 145 userInclude_.getOptionArguments())) 146 return -1; 147 148 return 0; 150 } 151 152 158 164 170 176 187 public boolean 188 generate_idl2(String decl_name, 189 String outputfile, 190 String outputfile_local, 191 String [] includes, 192 String [] userIncludes) 193 { 194 getComponentRepository().as_IDL2_repository(); 196 197 org.objectweb.openccm.ast.api.Scope scope = null; 199 try 200 { 201 scope = (org.objectweb.openccm.ast.api.Scope)getAST().lookup(decl_name); 202 } 203 catch(ClassCastException e) 204 { 205 getConsole().error(decl_name + "is not a scope!"); 206 return false; 207 } 208 209 if(scope == null) 210 { 211 getConsole().error("Declaration " + decl_name + " not found!"); 212 return false; 213 } 214 215 getConsole().message("Generating OMG IDL2 for " + decl_name + "..."); 216 217 ArrayList includes_list = new ArrayList ( java.util.Arrays.asList(includes) ); 219 includes_list.add("Components.idl"); 220 221 org.objectweb.openccm.generator.idl.api.IDL2Generator gen = 223 new org.objectweb.openccm.generator.idl.lib.IDL2Generator(getAST()); 224 gen.initialize( outputfile, 225 outputfile_local, 226 includes_list, 227 new ArrayList (java.util.Arrays.asList(userIncludes)), 228 scope, 229 "IR3toIDL2" ); 230 try 232 { 233 gen.generate(scope); 234 } 235 catch(org.objectweb.openccm.generator.common.lib.GenerationException ex) 236 { 237 report_exception(ex); 238 return false; 239 } 240 241 getComponentRepository().as_IDL3_repository(); 243 244 if (outputfile.equals(outputfile_local)) 245 getConsole().message("OMG IDL2 generated in " + outputfile + "."); 246 else 247 getConsole().message("OMG IDL2 generated in " + outputfile + " and " + outputfile_local + "."); 248 return true; 249 } 250 251 257 262 public static void 263 main(String [] args) 264 { 265 IR3toIDL2 ir3_idl2 = new IR3toIDL2(); 266 ir3_idl2.runMain(args); 267 } 268 } 269 | Popular Tags |