1 26 27 package org.objectweb.util.cmdline.lib; 28 29 import org.objectweb.util.misc.api.ExceptionWrapper; 31 import org.objectweb.util.cmdline.api.Application; 32 import org.objectweb.util.cmdline.api.CommandLine; 33 import org.objectweb.util.cmdline.api.Console; 34 35 52 53 abstract public class ApplicationBase 54 extends DefaultCommandLineHolder 55 implements Application 56 { 57 63 64 private Console console_; 65 66 72 73 public 74 ApplicationBase() 75 { 76 this(null, false, true); 77 } 78 79 84 public 85 ApplicationBase(CommandLine commandLine) 86 { 87 this(commandLine, false, true); 88 } 89 90 96 public 97 ApplicationBase(CommandLine commandLine, 98 boolean withDefaultOptions) 99 { 100 this(commandLine, false, withDefaultOptions); 101 } 102 103 110 public 111 ApplicationBase(CommandLine commandLine, 112 boolean silentMessage, 113 boolean withDefaultOptions) 114 { 115 super(commandLine); 117 118 setConsole(new DefaultConsole(getIdentity(), silentMessage)); 120 121 if(withDefaultOptions) 122 { 123 if(withDefaultOptions && commandLine != null) 125 commandLine.addOption(new DefaultOptionVersion(this)); 126 127 if(commandLine != null) 129 commandLine.addOption(new DefaultOptionSilentMessage(console_)); 130 } 131 } 132 133 139 144 protected void 145 report_property(String propertyName) 146 { 147 getConsole().getErrorStream(). 148 println("System property " + propertyName + " = " + 149 System.getProperty(propertyName)); 150 } 151 152 158 165 public String 166 getIdentity() 167 { 168 return this.getClass().getName(); 169 } 170 171 177 183 188 public Console 189 getConsole() 190 { 191 return console_; 192 } 193 194 199 public void 200 setConsole(Console console) 201 { 202 console_ = console; 203 getCommandLine().setConsole(console); 204 } 205 206 212 217 public String 218 getMailingList() 219 { 220 return "openccm@objectweb.org"; 221 } 222 223 228 public String [] 229 getVersionInformation() 230 { 231 return new String [] { 232 getIdentity(), 233 "", 234 "Copyright (C) 2000-2005 INRIA - USTL - LIFL - GOAL", 235 "This is free software; you can redistribute it and/or", 236 "modify it under the terms of the GNU Lesser General Public", 237 "License as published by the Free Software Foundation; either", 238 "version 2.1 of the License, or any later version.", 239 "", 240 "This is distributed in the hope that it will be useful,", 241 "but WITHOUT ANY WARRANTY; without even the implied warranty of", 242 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU", 243 "Lesser General Public License for more details.", 244 "", 245 "You should have received a copy of the GNU Lesser General Public", 246 "License along with this library; if not, write to the Free Software", 247 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA" 248 }; 249 } 250 251 256 public void 257 report_exception(Exception exception) 258 { 259 java.io.PrintStream err = getConsole().getErrorStream(); 260 err.print("Please report the following exception trace to "); 261 err.println(getMailingList()); 262 report_property("os.name"); 264 report_property("os.version"); 265 report_property("java.vendor"); 266 report_property("java.version"); 267 exception.printStackTrace(); 268 } 269 270 278 public void 279 runMain(String [] args) 280 { 281 try { 282 String [] arguments = getCommandLine().parse(args); 284 285 int status = start(arguments); 287 288 System.exit(status); 290 } catch(ExceptionWrapper exc) { 293 report_exception(exc.getException()); 294 } catch(Exception exc) { 295 report_exception(exc); 296 } 297 } 298 299 308 abstract public int 309 start(String [] args); 310 } 311 | Popular Tags |