1 26 27 package org.objectweb.openccm.pss.generator.common.lib; 28 29 import org.objectweb.util.cmdline.api.OptionArgument; 31 import org.objectweb.util.cmdline.lib.DefaultCommandLine; 32 import org.objectweb.util.cmdline.lib.DefaultOptionArgument; 33 import org.objectweb.openccm.ast.api.FileScope; 34 35 42 43 public class PSDLtoJavaCommand 44 extends org.objectweb.openccm.command.lib.CompilerGeneratorBase 45 implements org.objectweb.openccm.pss.generator.common.api.PSDLtoJavaCommand 46 { 47 53 54 OptionArgument odir_; 56 57 OptionArgument user_props_; 59 60 OptionArgument backend_; 62 68 71 public 72 PSDLtoJavaCommand() 73 { 74 super(new DefaultCommandLine("psdl_java", 76 "file", 77 "Compile an OMG PSDL file and generate its associated Java mapping", 78 true)); 79 80 odir_ = new DefaultOptionArgument( 82 new String [] { "-d" }, 83 "outputdir", 84 new String [] { 85 "Generate Java mapping into directory <outputdir>,", 86 "default is generated/" 87 }, 88 "generated" ); 89 getCommandLine().addOption(odir_); 90 91 user_props_ = new DefaultOptionArgument( 93 new String [] { "-userprop" }, 94 "user_properties_file", 95 new String [] { 96 "Get user classes definition from the properties file <user_properties_file>", 97 "default is \"user.properties\"" 98 }, 99 "user.properties" ); 100 getCommandLine().addOption(user_props_); 101 102 backend_ = new DefaultOptionArgument( 104 new String [] { "-backend" }, 105 "jdo|hibernate", 106 new String [] { 107 "Choose the persistent framework to use : jdo or hibernate", 108 "default is \"jdo\"" 109 }, 110 "jdo" ); 111 getCommandLine().addOption(backend_); 112 } 113 114 120 126 132 139 public int 140 run(java.lang.String [] args) 141 { 142 String filename = args[0]; 143 144 if(!initAST()) 146 return -1; 147 148 FileScope fileScope = compile(filename); 150 if(fileScope == null) 151 return -1; 152 153 if (!generate_java_mapping(fileScope, 155 filename, getOutputDirectory(), getUserPropertiesFile(), getBackend() )) return -1; 160 161 return 0; 163 } 164 165 171 177 183 189 195 200 public String 201 getOutputDirectory() 202 { 203 return odir_.getArgument(); 204 } 205 206 211 public String 212 getUserPropertiesFile() 213 { 214 return user_props_.getArgument(); 215 } 216 217 222 public String 223 getBackend() 224 { 225 return backend_.getArgument(); 226 } 227 228 242 public boolean 243 generate_java_mapping(FileScope filescope, 244 String inputfile, 245 String base_dir, 246 String user_properties_file, 247 String backend) 248 { 249 org.objectweb.openccm.pss.generator.common.api.PSDL2JavaGenerator gen = 251 new org.objectweb.openccm.pss.generator.common.lib.PSDL2JavaGenerator(getAST()); 252 253 getConsole().message("Generating Java mapping from " + inputfile + " ..."); 255 try 256 { 257 gen.psdl_to_java( base_dir, 258 filescope, 259 user_properties_file, 260 backend); 261 } 262 catch(org.objectweb.openccm.generator.common.lib.GenerationException ex) 263 { 264 report_exception(ex); 265 return false; 266 } 267 getConsole().message("Java mapping generated."); 268 269 return true; 270 } 271 272 278 283 public static void 284 main(String [] args) 285 { 286 PSDLtoJavaCommand psdl2java = new PSDLtoJavaCommand(); 287 psdl2java.runMain(args); 288 } 289 } 290 | Popular Tags |