1 27 package org.objectweb.corba.command.lib; 28 29 import org.objectweb.corba.generator.metainformation.lib.IDL_JavaMIGenerator; 30 import org.objectweb.openccm.command.lib.GeneratorBase; 31 import org.objectweb.openccm.command.lib.OptionMultipleArguments; 32 import org.objectweb.util.cmdline.lib.DefaultCommandLine; 33 import org.objectweb.util.cmdline.lib.DefaultOptionArgument; 34 35 41 43 public class IDLtoMI 44 extends GeneratorBase 45 { 46 47 48 54 55 public 56 IDLtoMI() 57 { 58 super(new DefaultCommandLine( 60 "idl_to_mi", 61 "declaration", 62 new String [] { 63 "Compile an OMG IDL3 file and generate its associated:", 64 "- local MI type implementations" 65 }, 66 true), 67 "none"); 68 69 71 odir_ = new DefaultOptionArgument( 72 new String [] { "-d" }, 73 "outputdir", 74 new String [] { 75 "Generate Java implementations into directory <outputdir>,", 76 "default is generated/" 77 }, 78 "generated" ); 79 getCommandLine().addOption(odir_); 80 } 81 87 88 private OptionMultipleArguments userInclude_; 89 90 org.objectweb.util.cmdline.api.OptionArgument odir_; 92 98 99 public int run(String [] args) 100 { 101 String filename = args[0]; 102 103 105 if(!initAST()) 106 return -1; 107 108 if (!generateMI(args[0],getOutputDirectory())) 109 return -1; 110 111 return 0; 113 } 114 115 public String getOutputDirectory() 116 { 117 return odir_.getArgument(); 118 } 119 125 136 137 public 138 boolean 139 generateMI(String decl, 140 String base_dir) 141 { 142 getComponentRepository().as_IDL3_repository(); 144 145 org.objectweb.openccm.ast.api.Scope scope = null; 147 try 148 { 149 scope = (org.objectweb.openccm.ast.api.Scope)getAST().lookup(decl); 150 } 151 catch(ClassCastException e) 152 { 153 getConsole().error(decl + "is not a scope!"); 154 return false; 155 } 156 157 if(scope == null) 158 { 159 getConsole().error("Declaration " + decl + " not found!"); 160 return false; 161 } 162 163 getConsole().message("Generating MetaInformation implementations for " + decl + "..."); 164 165 167 IDL_JavaMIGenerator MI_gen = new IDL_JavaMIGenerator(getAST()); 168 169 try 171 { 172 MI_gen.idl_to_java(base_dir,scope); 173 } 174 catch(org.objectweb.openccm.generator.common.lib.GenerationException ex) 175 { 176 report_exception(ex); 177 return false; 178 } 179 180 181 getConsole().message(" ..."); 182 184 return true; 185 } 186 187 193 198 public static void 199 main(String [] args) 200 { 201 IDLtoMI idl2mi = new IDLtoMI(); 202 idl2mi.runMain(args); 203 } 204 205 206 207 208 209 210 211 212 213 214 } | Popular Tags |