1 19 20 26 package org.enhydra.dods.generator; 27 28 import java.io.BufferedReader ; 29 import java.io.File ; 30 import java.io.IOException ; 31 import java.io.InputStreamReader ; 32 import java.lang.reflect.InvocationTargetException ; 33 import java.util.ArrayList ; 34 import java.util.HashMap ; 35 import java.util.HashSet ; 36 import org.enhydra.dods.Common; 37 import org.enhydra.dods.wizard.DefaultDODSWizard; 38 39 42 public class DODSGenerator { 43 protected static final int HELP_PARAMETER = 0; 45 protected static final int ACTION_PARAMETER = 10; 46 protected static final int TEMPLATE_SET_PARAMETER = 20; 47 protected static final int FORCE_PARAMETER = 30; 48 protected static final int DATABASE_PARAMETER = 40; 49 protected static final int CONFIGURATION_DIR_PARAMETER = 50; 50 protected static final int HTML_PARAMETER = 100; 51 protected static final int PDF_PARAMETER = 110; 52 protected static final int XMI_PARAMETER = 120; 53 protected static final int PTL_PARAMETER = 130; 54 protected static final String HELP_MESSAGE = "\n"; 56 protected static final String INVALID_NUMBER_OF_PARAMETER_MESSAGE = "\nWrong number of input parameters.\n"; 57 protected static final String INVALID_PARAMETER_MESSAGE = "\nWrong input parameter "; 58 protected static final String INVALID_ACTION_PARAMETER_MESSAGE = "\nWrong action parameter "; 59 protected static final String INVALID_TEMPLATE_SET_PARAMETER_MESSAGE = "\n Wrong template set "; 60 protected static final String INVALID_DOML_FILE = "\n Wrong .doml file "; 61 protected static final String NONEXISTING_DOML_FILE = "\n Doml file doesn't exist "; 62 protected static final String INVALID_CONF_DIR_MESSAGE = "\nWrong input parameter "; 63 64 public static final String DATABASE_NOT_SET = "database_not_set"; 65 66 69 protected DODSWizard wizard = null; 70 71 74 protected String doml = null; 75 76 79 protected String outputDir = null; 80 81 84 protected String action = null; 85 86 89 protected String templateSet = null; 90 91 94 protected String configDir = null; 95 96 99 protected String force = "false"; 100 101 104 protected String database = null; 105 106 109 protected boolean html = false; 110 111 114 protected boolean pdf = false; 115 116 119 protected boolean xmi = false; 120 121 124 protected boolean ptl = false; 125 126 129 protected boolean invoke = false; 130 131 134 protected boolean kelp = false; 135 protected static boolean help = false; 136 protected static HashMap parameters; 137 protected static HashSet actions; 138 protected static HashSet templateSets; 139 static { 140 parameters = new HashMap (); 142 parameters.put("-?", new Integer (HELP_PARAMETER)); 143 parameters.put("-help", new Integer (HELP_PARAMETER)); 144 parameters.put("-a", new Integer (ACTION_PARAMETER)); 145 parameters.put("-t", new Integer (TEMPLATE_SET_PARAMETER)); 146 parameters.put("-f", new Integer (FORCE_PARAMETER)); 147 parameters.put("-force", new Integer (FORCE_PARAMETER)); 148 parameters.put("-b", new Integer (DATABASE_PARAMETER)); 149 parameters.put("-databse", new Integer (DATABASE_PARAMETER)); 150 parameters.put("-c", new Integer (CONFIGURATION_DIR_PARAMETER)); 151 parameters.put("-h", new Integer (HTML_PARAMETER)); 152 parameters.put("-html", new Integer (HTML_PARAMETER)); 153 parameters.put("-p", new Integer (PDF_PARAMETER)); 154 parameters.put("-pdf", new Integer (PDF_PARAMETER)); 155 parameters.put("-x", new Integer (XMI_PARAMETER)); 156 parameters.put("-xmi", new Integer (XMI_PARAMETER)); 157 parameters.put("-r", new Integer (PTL_PARAMETER)); 158 parameters.put("-ptl", new Integer (PTL_PARAMETER)); 159 actions = new HashSet (); 161 actions.add("dods:sql"); 162 actions.add("dods:java"); 163 actions.add("dods:javaNoCompile"); 164 actions.add("dods:noCompile"); 165 actions.add("dods:build_all_split"); 166 actions.add("dods:sqlsplit"); 167 actions.add("dods:noCompileSplit"); 168 actions.add("dods:build_all"); 169 } 170 171 174 public DODSGenerator() { 175 wizard = new DefaultDODSWizard(this); 176 action = "dods:build_all"; 177 templateSet = "standard"; 178 database = DATABASE_NOT_SET; 179 } 180 181 186 public DODSWizard getWizard() { 187 return wizard; 188 } 189 190 195 public void setWizard(DODSWizard wizard) { 196 this.wizard = wizard; 197 } 198 199 204 public String getDoml() { 205 return doml; 206 } 207 208 213 public void setDoml(String doml) { 214 this.doml = doml; 215 } 216 217 222 public String getOutputDir() { 223 return outputDir; 224 } 225 226 231 public void setOutputDir(String outputDir) { 232 this.outputDir = outputDir; 233 } 234 235 240 public String getAction() { 241 return action; 242 } 243 244 249 public void setAction(String action) { 250 this.action = action; 251 } 252 253 258 public String getTemplateSet() { 259 return templateSet; 260 } 261 262 267 public void setTemplateSet(String templateSet) { 268 this.templateSet = templateSet; 269 } 270 271 276 public String getForce() { 277 return force; 278 } 279 280 285 public void setForce(String force) { 286 this.force = force; 287 } 288 289 294 public String getDatabase() { 295 return database; 296 } 297 298 303 public void setDatabase(String database) { 304 this.database = database; 305 } 306 307 312 public boolean getHtml() { 313 return html; 314 } 315 316 321 public void setHtml(boolean html) { 322 this.html = html; 323 } 324 325 330 public boolean getPdf() { 331 return pdf; 332 } 333 334 339 public void setPdf(boolean pdf) { 340 this.pdf = pdf; 341 } 342 343 348 public boolean getXmi() { 349 return xmi; 350 } 351 352 357 public void setXmi(boolean xmi) { 358 this.xmi = xmi; 359 } 360 361 366 public boolean getPtl() { 367 return ptl; 368 } 369 370 375 public void setPtl(boolean ptl) { 376 this.ptl = ptl; 377 } 378 379 384 public boolean getInvoke() { 385 return invoke; 386 } 387 388 393 public void setInvoke(boolean invoke) { 394 this.invoke = invoke; 395 } 396 397 402 public boolean getKelp() { 403 return kelp; 404 } 405 406 411 public void setKelp(boolean kelp) { 412 this.kelp = kelp; 413 } 414 415 418 public void runWizard() { 419 wizard.startup(); 420 } 421 422 426 public void preGenerate() {} 427 428 432 public void postGenerate() {} 433 434 438 public void preClose() {} 439 440 444 public void preCancel() {} 445 446 474 475 476 477 public static Process generateCode(String outputDir, String domlFile, String action, String templateSet, 478 String forceBuild, String database, boolean ownErrorReader) 479 throws DODSGenerateException { 480 java.lang.Process process = null; 481 482 try { 483 if (action == null) { 484 action = "dods:build_all"; 485 } if (templateSet == null) { 487 templateSet = "standard"; 488 } if (forceBuild == null) { 490 forceBuild = "false"; 491 } if (database == null) { 493 database = DATABASE_NOT_SET; 494 } java.util.ArrayList argsList = new ArrayList (); 497 498 argsList.add(domlFile); 499 argsList.add(outputDir); 500 argsList.add(templateSet); 501 argsList.add(database); 502 argsList.add(forceBuild); 503 String className = "org.enhydra.dods.generator.DODSEjenProperties"; 504 java.lang.reflect.Method m = null; 505 java.lang.Class c = null; 506 507 c = java.lang.Class.forName(className); 508 m = c.getMethod("main", new java.lang.Class [] { 509 String [].class 510 }); 511 String args[] = (String []) argsList.toArray(((java.lang.Object []) ( 512 new String [argsList.size()]))); 513 514 if (m != null) { 515 m.invoke(((java.lang.Object ) (null)), new java.lang.Object [] { 516 args 517 }); 518 } 519 520 String as[] = null; 521 String endorsing = System.getProperty("DODS_ENDORSED", null); 522 as = new String [12]; 524 as[0] = System.getProperty("JAVA_HOME") + File.separator + "bin" 525 + File.separator + "java"; 526 as[1] = "-DDODS_HOME=" + System.getProperty("DODS_HOME"); 527 as[2] = "-DPROJECT_ROOT=" + outputDir; 528 as[3] = "-DDOML_FILE=" + domlFile; 529 as[4] = "-DTEMPLATESET=" + templateSet; 530 as[5] = "-DDATABASE_VENDOR=" + database; 531 as[6] = "-DFORCE=" + forceBuild; 532 as[7] = (null != endorsing) 533 ?("-Djava.endorsed.dirs=" + endorsing) 534 :("-DDODS_HOME=" + System.getProperty("DODS_HOME")); 535 as[8] = "org.apache.tools.ant.Main"; 536 as[9] = "-f"; 537 as[10] = new String (System.getProperty("DODS_HOME") + File.separator 538 + "build" + File.separator + "generate.xml"); 539 as[11] = action; 540 process = Runtime.getRuntime().exec(as); 541 if (!ownErrorReader) { 542 BufferedReader errorBufferedReader = new BufferedReader (new InputStreamReader (process.getErrorStream())); 543 544 (new ErrorReader(errorBufferedReader, true)).start(); 545 } 546 } catch (ClassNotFoundException e) { 547 throw new DODSGenerateException(e); 548 } catch (NoSuchMethodException e) { 549 throw new DODSGenerateException(e); 550 } catch (IllegalAccessException e) { 551 throw new DODSGenerateException(e); 552 } catch (IOException e) { 553 throw new DODSGenerateException(e); 554 } catch (InvocationTargetException e) { 555 throw new DODSGenerateException(e); 556 } 557 return process; 558 } 559 560 581 public Process generateCode(boolean ownErrorReader) 582 throws DODSGenerateException { 583 return generateCode(outputDir, doml, action, templateSet, force, 584 database, ownErrorReader); 585 } 586 587 605 public static Process generateHTML(String outputDir, String domlFile, String htmlFile, 606 String forceBuild, boolean ownErrorReader) 607 throws DODSGenerateException { 608 return generateDocumentation(outputDir, domlFile, htmlFile, forceBuild, 609 ownErrorReader, "html", "html"); 610 } 611 612 625 626 public Process generateHTML(boolean ownErrorReader) 627 throws DODSGenerateException { 628 return generateDocumentation(outputDir,doml,null,force,ownErrorReader,"html","html"); 629 } 630 648 public static Process generatePDF(String outputDir, String domlFile, String pdfFile, 649 String forceBuild, boolean ownErrorReader) 650 throws DODSGenerateException { 651 return generateDocumentation(outputDir, domlFile, pdfFile, forceBuild, 652 ownErrorReader, "pdf", "pdf"); 653 } 654 655 668 public Process generatePDF(boolean ownErrorReader) 669 throws DODSGenerateException { 670 return generateDocumentation(outputDir, doml, null, force, 671 ownErrorReader, "pdf", "pdf"); 672 } 673 674 692 public static Process generateXMI(String outputDir, String domlFile, String xmiFile, 693 String forceBuild, boolean ownErrorReader) 694 throws DODSGenerateException { 695 return generateDocumentation(outputDir, domlFile, xmiFile, forceBuild, 696 ownErrorReader, "xmi", "xmi"); 697 } 698 699 712 public Process generateXMI(boolean ownErrorReader) 713 throws DODSGenerateException { 714 return generateDocumentation(outputDir, doml, null, force, 715 ownErrorReader, "xmi", "xmi"); 716 } 717 718 736 public static Process generatePTL(String outputDir, String domlFile, String ptlFile, 737 String forceBuild, boolean ownErrorReader) 738 throws DODSGenerateException { 739 return generateDocumentation(outputDir, domlFile, ptlFile, forceBuild, 740 ownErrorReader, "ptl", "ptl"); 741 } 742 743 756 public Process generatePTL(boolean ownErrorReader) 757 throws DODSGenerateException { 758 return generateDocumentation(outputDir, doml, null, force, 759 ownErrorReader, "ptl", "ptl"); 760 } 761 762 766 private static Process generateDocumentation(String outputDir, String doml, String outputName, String forceBuild, 767 boolean ownErrorReader, String type, String extension) 768 throws DODSGenerateException { 769 java.lang.Process process = null; 770 String as[] = new String [3]; 771 772 try { 773 if (System.getProperty("os.name").toLowerCase().startsWith("win")) { 774 as[0] = System.getProperty("DODS_HOME") + File.separator + "bin" 775 + File.separator + "doml2" + type + ".bat"; 776 } else { 777 as[0] = System.getProperty("DODS_HOME") + File.separator + "bin" 778 + File.separator + "doml2" + type; 779 } 780 as[1] = doml; 781 if (outputName == null) { 782 int index = doml.lastIndexOf(File.separator); 783 784 if (index != -1) { 785 outputName = doml.substring(index + 1); 786 } else { 787 outputName = doml; 788 } 789 outputName = outputName.substring(0, 790 outputName.lastIndexOf(".doml")); 791 } 792 as[2] = outputDir + File.separator + outputName + "." + extension; 793 process = Runtime.getRuntime().exec(as); 794 if (!ownErrorReader) { 795 BufferedReader errorBufferedReader = new BufferedReader (new InputStreamReader (process.getErrorStream())); 796 797 (new ErrorReader(errorBufferedReader, true)).start(); 798 } 799 } catch (IOException e) { 800 throw new DODSGenerateException(e); 801 } catch (StringIndexOutOfBoundsException e) { 802 throw new DODSGenerateException(e); 803 } 804 return process; 805 } 806 807 825 public static int generateAll(String outputDir, String domlFile, String genAction, String templateSet, 826 String forceBuild, String database, boolean genHtml, boolean genPdf, 827 boolean genXmi, boolean genPtl) 828 throws DODSGenerateException { 829 int exit = 0; 830 831 try { 832 ErrorReader errorReader; 833 Process process; 834 BufferedReader buffer; 835 BufferedReader error; 836 String s; 837 File f = new File (domlFile); 838 839 outputDir = (new File (outputDir)).getAbsolutePath(); 840 File dir = new File (outputDir); 841 842 dir.mkdirs(); 843 domlFile = f.getAbsolutePath(); 844 f = new File (domlFile); 845 if (!f.exists()) { 846 throw new DODSGenerateException(NONEXISTING_DOML_FILE + " " 847 + domlFile + "\n"); 848 } 849 if (genHtml) { 850 process = DODSGenerator.generateHTML(outputDir, domlFile, null, 851 "true", true); 852 buffer = new BufferedReader (new InputStreamReader (process.getInputStream())); 853 error = new BufferedReader (new InputStreamReader (process.getErrorStream())); 854 (new ErrorReader(error, true)).start(); 855 while ((s = buffer.readLine()) != null) { 856 System.out.println(s); 857 } 858 if (exit != 0) { 859 return exit; 860 } 861 } 862 if (genPdf) { 863 process = DODSGenerator.generatePDF(outputDir, domlFile, null, 864 "true", true); 865 buffer = new BufferedReader (new InputStreamReader (process.getInputStream())); 866 error = new BufferedReader (new InputStreamReader (process.getErrorStream())); 867 (new ErrorReader(error, true)).start(); 868 while ((s = buffer.readLine()) != null) { 869 System.out.println(s); 870 } 871 if (exit != 0) { 872 return exit; 873 } 874 } 875 if (genXmi) { 876 process = DODSGenerator.generateXMI(outputDir, domlFile, null, 877 "true", true); 878 buffer = new BufferedReader (new InputStreamReader (process.getInputStream())); 879 error = new BufferedReader (new InputStreamReader (process.getErrorStream())); 880 (new ErrorReader(error, true)).start(); 881 while ((s = buffer.readLine()) != null) { 882 System.out.println(s); 883 } 884 if (exit != 0) { 885 return exit; 886 } 887 } 888 if (genPtl) { 889 process = DODSGenerator.generatePTL(outputDir, domlFile, null, 890 "true", true); 891 buffer = new BufferedReader (new InputStreamReader (process.getInputStream())); 892 error = new BufferedReader (new InputStreamReader (process.getErrorStream())); 893 (new ErrorReader(error, true)).start(); 894 while ((s = buffer.readLine()) != null) { 895 System.out.println(s); 896 } 897 if (exit != 0) { 898 return exit; 899 } 900 } 901 if(!genAction.equalsIgnoreCase("dods:generatorOff")){ 902 process = DODSGenerator.generateCode(outputDir, domlFile, genAction, 903 templateSet, forceBuild, database, true); 904 buffer = new BufferedReader (new InputStreamReader (process.getInputStream())); 905 error = new BufferedReader (new InputStreamReader (process.getErrorStream())); 906 (new ErrorReader(error, true)).start(); 907 while ((s = buffer.readLine()) != null) { 908 System.out.println(s); 909 } 910 exit = process.waitFor(); 911 } 912 } catch (IOException e) { 913 throw new DODSGenerateException(e); 914 } catch (InterruptedException e) { 915 throw new DODSGenerateException(e); 916 } catch (DODSGenerateException e) { 917 Throwable pe = e.getCause(); 918 if (pe instanceof java.lang.StringIndexOutOfBoundsException ) { 919 System.out.println(INVALID_DOML_FILE + domlFile + "\n"); 920 } else { 921 throw new DODSGenerateException(e); 922 } 923 } 924 return exit; 925 } 926 927 946 947 public static int generateAll(String outputDir, String domlFile, String genAction, String configDir, String templateDir, 948 String templateSet, String forceBuild, String database, boolean genHtml, boolean genPdf, 949 boolean genXmi, boolean genPtl) 950 throws DODSGenerateException { 951 Common.setCustomTemplateDir(templateDir); 952 Common.setConfigDir(configDir); 953 954 return generateAll(outputDir, domlFile, genAction, templateSet, 955 forceBuild, database, genHtml, genPdf, genXmi, genPtl); 956 } 957 958 966 public int generateAll() 967 throws DODSGenerateException { 968 return generateAll(outputDir, doml, action, templateSet, force, database, 969 html, pdf, xmi, ptl); 970 } 971 972 996 public static Process generateAll(String outputDir, String domlFile, String genAction, String configDir, 997 String templateSet, String forceBuild, String database, 998 boolean genHtml, boolean genPdf, boolean genXmi, 999 boolean genPtl, boolean ownErrorReader) 1000 throws DODSGenerateException { 1001 int exit = 0; 1002 Process process = null; 1003 1004 try { 1005 ErrorReader errorReader; 1006 BufferedReader buffer; 1007 BufferedReader error; 1008 String s; 1009 File f = new File (domlFile); 1010 1011 outputDir = (new File (outputDir)).getAbsolutePath(); 1012 domlFile = f.getAbsolutePath(); 1013 f = new File (domlFile); 1014 if (!f.exists()) { 1015 throw new DODSGenerateException(NONEXISTING_DOML_FILE + " " 1016 + domlFile + "\n"); 1017 } 1018 String tmp[] = new String [16]; 1019 int param = 1; 1020 1021 if (System.getProperty("os.name").toLowerCase().startsWith("win")) { 1022 tmp[0] = System.getProperty("DODS_HOME") + File.separator 1023 + "bin" + File.separator + "dods.bat"; 1024 } else { 1025 tmp[0] = System.getProperty("DODS_HOME") + File.separator 1026 + "bin" + File.separator + "dods"; 1027 } 1028 if (genAction != null) { 1029 tmp[param] = "-a"; 1030 param++; 1031 tmp[param] = genAction; 1032 param++; 1033 } 1034 if (configDir != null) { 1035 tmp[param] = "-c"; 1036 param++; 1037 tmp[param] = configDir; 1038 param++; 1039 } 1040 if (templateSet != null) { 1041 tmp[param] = "-t"; 1042 param++; 1043 tmp[param] = templateSet; 1044 param++; 1045 } 1046 if (forceBuild != null) { 1047 if (forceBuild.equals("true")) { 1048 tmp[param] = "-f"; 1049 param++; 1050 } 1051 } 1052 if (database != null) { 1053 tmp[param] = "-b"; 1054 param++; 1055 tmp[param] = database; 1056 param++; 1057 } 1058 if (genHtml) { 1059 tmp[param] = "-h"; 1060 param++; 1061 } 1062 if (genPdf) { 1063 tmp[param] = "-p"; 1064 param++; 1065 } 1066 if (genXmi) { 1067 tmp[param] = "-x"; 1068 param++; 1069 } 1070 if (genPtl) { 1071 tmp[param] = "-r"; 1072 param++; 1073 } 1074 tmp[param] = domlFile; 1075 param++; 1076 tmp[param] = outputDir; 1077 param++; 1078 String as[] = new String [param]; 1079 1080 for (int i = 0; i < param; i++) { 1081 as[i] = tmp[i]; 1082 } 1083 process = Runtime.getRuntime().exec(as); 1084 if (!ownErrorReader) { 1085 BufferedReader errorBufferedReader = new BufferedReader (new InputStreamReader (process.getErrorStream())); 1086 1087 (new ErrorReader(errorBufferedReader, true)).start(); 1088 } 1089 } catch (IOException e) { 1090 e.printStackTrace(); 1091 throw new DODSGenerateException(e); 1092 } 1093 return process; 1094 } 1095 1096 1119 public static Process generateAll(String outputDir, String domlFile, String genAction, 1120 String templateSet, String forceBuild, String database, 1121 boolean genHtml, boolean genPdf, boolean genXmi, 1122 boolean genPtl, boolean ownErrorReader) 1123 throws DODSGenerateException { 1124 return generateAll(outputDir, domlFile, genAction, null, templateSet, 1125 forceBuild, database, genHtml, genPdf, genXmi, genPtl, 1126 ownErrorReader); 1127 } 1128 1129 1141 public Process generateAll(boolean ownErrorReader) 1142 throws DODSGenerateException { 1143 return generateAll(outputDir, doml, action, configDir, templateSet, 1144 force, database, html, pdf, xmi, ptl, ownErrorReader); 1145 } 1146 1147 1150 public static void help() { 1151 String dods = "dods"; 1152 String space = " "; 1153 String example = "/home/tanja/test/discRack.doml /home/tanja/test/discRack"; 1154 1155 if (System.getProperty("os.name").toLowerCase().startsWith("win")) { 1156 dods = "dods.bat"; 1157 space = " "; 1158 example = "c:\\test\\discRack.doml c:\\test\\discRack"; 1159 } 1160 System.out.println("\nCommand line help:\n"); 1161 System.out.println(dods 1162 + " [-?/help] [-a action] [-t templateset] [-b/-database] [-c confPath] "); 1163 System.out.println(space 1164 + "[-f/force] [-h/html] [-p/pdf] [-x/xmi] [-r/ptl] domlfile outputdir\n"); 1165 System.out.println(" where:\n"); 1166 System.out.println(" outputdir full path to output directory that will be used.\n"); 1167 System.out.println(" domlfile full path to .doml file for generating code.\n"); 1168 System.out.println(" options:\n"); 1169 System.out.println(" [-? -help] shows help.\n"); 1170 System.out.println(" [-a action] ant task parameter for code generation:"); 1171 System.out.println(" dods:build_all - to create all sql files and java classes (default)."); 1172 System.out.println(" dods:sql - to create only sql files."); 1173 System.out.println(" dods:java - to create only java files and to compile them."); 1174 System.out.println(" dods:javaNoCompile - to create only java files and not to compile them."); 1175 System.out.println(" dods:noCompile - to create SQL files and java files and not to"); 1176 System.out.println(" compile them."); 1177 System.out.println(" dods:build_all_split - to create all sql files and java classes and to"); 1178 System.out.println(" compile it. SQL files will be divided into separate"); 1179 System.out.println(" files using SQLSplitter ."); 1180 System.out.println(" dods:sqlsplit - to create only sql files and separate in different"); 1181 System.out.println(" files using SQLSplitter."); 1182 System.out.println(" dods:noCompileSplit - to create SQL files and separate sql commands using"); 1183 System.out.println(" SQLSplitter and java files and not to compile them.\n"); 1184 System.out.println(" [-t templateset] template set for generating java and sql code:"); 1185 System.out.println(" standard - generate standard java code (default)."); 1186 System.out.println(" <user_defined> - any user defined template set.\n"); 1187 System.out.println(" [-b/-database] sets database vendor for generating sql.\n"); 1188 System.out.println(" [-c confPath] sets folder with dodsConf.xml file \n"); 1189 System.out.println(" [-f/-force] with this switch, code will be always generated, without it, only changes"); 1190 System.out.println(" will be regenerated.\n"); 1191 System.out.println(" [-h/-html] generates DODS html documentation from .doml file.\n"); 1192 System.out.println(" [-p/-pdf] generates DODS pdf documentation from .doml file.\n"); 1193 System.out.println(" [-x/-xmi] generates DODS xmi documentation from .doml file.\n"); 1194 System.out.println(" [-r/-ptl] generates DODS ptl (Rational Rose) documentation from .doml file.\n"); 1195 System.out.println("Example:\n"); 1196 System.out.println(" " + dods + " -a dods:java -t standard -f -pdf -x " 1197 + example + "\n"); 1198 } 1199 1200 1206 public String parse(String [] args) { 1207 try { 1208 int curr = 0; 1209 int param = -1; 1210 1211 while (curr < args.length) { 1212 Integer integer = (Integer ) parameters.get(args[curr]); 1213 1214 if (integer == null) { 1215 break; 1216 } 1217 param = integer.intValue(); 1218 curr++; 1219 switch (param) { 1220 case HELP_PARAMETER: { 1221 help = true; 1222 return HELP_MESSAGE; 1223 } 1224 1225 case ACTION_PARAMETER: { 1226 if (actions.contains(args[curr])) { 1227 action = args[curr]; 1228 } else { 1229 return INVALID_ACTION_PARAMETER_MESSAGE + args[curr]; 1230 } 1231 curr++; 1232 break; 1233 } 1234 1235 case CONFIGURATION_DIR_PARAMETER: { 1236 configDir = args[curr]; 1237 curr++; 1238 break; 1239 } 1240 1241 case TEMPLATE_SET_PARAMETER: { 1242 templateSet = args[curr]; 1243 curr++; 1244 break; 1245 } 1246 1247 case DATABASE_PARAMETER: { 1248 database = args[curr]; 1249 curr++; 1250 break; 1251 } 1252 1253 case FORCE_PARAMETER: { 1254 force = "true"; 1255 break; 1256 } 1257 1258 case HTML_PARAMETER: { 1259 html = true; 1260 break; 1261 } 1262 1263 case PDF_PARAMETER: { 1264 pdf = true; 1265 break; 1266 } 1267 1268 case XMI_PARAMETER: { 1269 xmi = true; 1270 break; 1271 } 1272 1273 case PTL_PARAMETER: { 1274 ptl = true; 1275 break; 1276 } 1277 } } 1280 try { 1281 Common.setConfigDir(configDir); 1282 } catch (Error e) { 1283 return INVALID_CONF_DIR_MESSAGE + configDir; 1284 } 1285 templateSets = Common.getAllTemplateSets(); 1286 1287 if (!templateSets.contains(templateSet)) { 1288 return INVALID_TEMPLATE_SET_PARAMETER_MESSAGE + templateSet; 1289 } 1290 if (args.length - curr < 2) { 1291 return INVALID_NUMBER_OF_PARAMETER_MESSAGE; 1292 } 1293 if (args[curr].startsWith("-") || args[curr + 1].startsWith("-")) { 1294 return INVALID_PARAMETER_MESSAGE + args[curr]; 1295 } 1296 doml = args[curr]; 1297 outputDir = args[curr + 1]; 1298 } catch (NullPointerException e) { 1299 return INVALID_PARAMETER_MESSAGE; 1300 } catch (ArrayIndexOutOfBoundsException e) { 1301 return INVALID_NUMBER_OF_PARAMETER_MESSAGE; 1302 } 1303 return null; 1304 } 1305 1306 1365 public static void main(String [] args) { 1366 DODSGenerator generator = new DODSGenerator(); 1367 1368 if (args.length == 0) { 1369 generator.runWizard(); 1370 return; 1371 } 1372 try { 1373 String message = generator.parse(args); 1374 1375 if (message != null) { 1376 System.out.println(message); 1377 help(); 1378 return; 1379 } 1380 int exit = generator.generateAll(); 1381 1382 System.exit(exit); 1383 } catch (DODSGenerateException e) { 1384 String message = e.getLocalizedMessage(); 1385 1386 if (message != null) { 1387 System.out.println(message); 1388 } else { 1389 e.printStackTrace(); 1390 } 1391 } catch (Exception e) { 1392 e.printStackTrace(); 1393 } 1394 } 1395 1396 1399 public void setConfigDir(String conDir) { 1400 configDir = conDir; 1401 } 1402 1403 1406 public String getConfigDir() { 1407 return configDir; 1408 } 1409} 1410 | Popular Tags |