Skip to content

Commit 8cdfbc5

Browse files
committed
Code cleanup in the Main class
1 parent 76c3972 commit 8cdfbc5

File tree

1 file changed

+46
-64
lines changed

1 file changed

+46
-64
lines changed

src/javaxt/orm/Main.java

Lines changed: 46 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,59 @@
11
package javaxt.orm;
2+
import java.util.*;
3+
import javaxt.io.Jar;
4+
import static javaxt.utils.Console.console;
5+
6+
//******************************************************************************
7+
//** Main
8+
//******************************************************************************
9+
/**
10+
* Command line interface used to parse a model file and generate Java and SQL
11+
* output files.
12+
*
13+
******************************************************************************/
214

315
public class Main {
416

5-
public static void main(String[] args) throws Exception {
6-
7-
//Parse inputs
8-
javaxt.io.File inputFile = new javaxt.io.File(args[0]);
9-
javaxt.io.Directory outputDirectory = new javaxt.io.Directory(args[1]);
10-
11-
12-
//Validate inputs
13-
if (!inputFile.exists()) throw new IllegalArgumentException("Input file not found");
14-
15-
16-
//Get models
17-
Model[] models = new Parser(inputFile.getText()).getModels();
1817

19-
20-
//Run tests
21-
//testContact(models);
22-
//testUser(models);
23-
//testFile(models);
24-
new Writer(models).write(outputDirectory);
25-
}
26-
27-
28-
private static void testContact(Model[] models){
29-
for (Model model : models){
30-
31-
String modelName = model.getName();
32-
if (modelName.equals("Contact") || modelName.equals("Phone") || modelName.equals("Email")){}
33-
else continue;
34-
35-
36-
//Create class
37-
if (modelName.equals("Contact")) System.out.println(model.getJavaCode());
38-
39-
40-
//Create DDL
41-
System.out.println(model.getTableSQL());
42-
System.out.println(model.getForeignKeySQL());
18+
//**************************************************************************
19+
//** main
20+
//**************************************************************************
21+
/** Entry point for the application
22+
* @param arguments Command line arguments
23+
*/
24+
public static void main(String[] arguments) throws Exception {
25+
HashMap<String, String> args = console.parseArgs(arguments);
26+
27+
28+
//Print version as needed
29+
if (args.containsKey("-version")){
30+
Jar jar = new Jar(Main.class);
31+
javaxt.io.File jarFile = new javaxt.io.File(jar.getFile());
32+
String version = jar.getVersion();
33+
if (version==null) version = "Unknown";
34+
System.out.println(jarFile.getName(false) + " version \"" + version + "\"");
35+
return;
4336
}
44-
}
45-
46-
47-
private static void testUser(Model[] models){
48-
for (Model model : models){
4937

5038

51-
52-
String modelName = model.getName();
53-
if (!modelName.equals("UserAccount")) continue;
54-
55-
56-
System.out.println(model.getJavaCode());
57-
System.out.println(model.getTableSQL());
58-
System.out.println(model.getForeignKeySQL());
39+
//Parse inputs
40+
String input = args.get("-input");
41+
String output = args.get("-output");
42+
if (input==null){
43+
input = arguments[0];
44+
if (arguments.length>1) output = arguments[1];
5945
}
60-
}
61-
62-
63-
private static void testFile(Model[] models){
64-
for (Model model : models){
46+
javaxt.io.File inputFile = new javaxt.io.File(input);
47+
if (!inputFile.exists()) throw new IllegalArgumentException("Input file not found");
48+
javaxt.io.Directory outputDirectory = output==null ?
49+
inputFile.getDirectory() : new javaxt.io.Directory(output);
6550

6651

67-
68-
String modelName = model.getName();
69-
if (!modelName.equals("File")) continue;
70-
71-
72-
System.out.println(model.getJavaCode());
73-
System.out.println(model.getTableSQL());
74-
System.out.println(model.getForeignKeySQL());
75-
}
52+
//Create models
53+
Model[] models = new Parser(inputFile.getText()).getModels();
54+
55+
56+
//Create files
57+
Writer.write(models, outputDirectory);
7658
}
7759
}

0 commit comments

Comments
 (0)