1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.config;
26
27 import java.io.IOException;
28 import java.io.StringReader;
29 import java.net.URL;
30 import java.util.ArrayList;
31 import java.util.List;
32 import java.util.Properties;
33
34 import org.xerial.core.XerialException;
35 import org.xerial.lens.SilkLens;
36
37
38
39
40
41
42
43 public class UTGBConfig {
44
45 public static class WebAction {
46 public String alias;
47 public String javaPackage;
48
49 }
50
51 public static class Database {
52 public String id;
53 public String dbms = "sqlite";
54 public String driver;
55 public String jdbcPrefix;
56 public String address;
57 public String user;
58 public String pass;
59
60 @Override
61 public String toString() {
62 return String.format("id:%s, dbms:%s, driver:%s, address:%s", id, dbms, driver, address);
63 }
64 }
65
66 public String version = "1.0";
67 public String group;
68 public String projectName;
69 public String javaPackage;
70 public List<WebAction> webAction = new ArrayList<WebAction>();
71 public List<Database> database = new ArrayList<Database>();
72 public Properties _ = new Properties();
73
74 public void put(String key, String value) {
75 _.put(key, value);
76 }
77
78 public String getProperty(String key) {
79 return _.getProperty(key);
80 }
81
82 public boolean hasPropertyOf(String key) {
83 return _.containsKey(key);
84 }
85
86 public String getProperty(String key, String defaultValue) {
87 return _.getProperty(key, defaultValue);
88 }
89
90 public Database getDatabase(String id) {
91 for (Database each : database) {
92 if (id.equals(each.id))
93 return each;
94 }
95 return null;
96 }
97
98
99
100
101
102
103
104
105
106
107
108 public static UTGBConfig parse(URL configResource) throws IOException, XerialException {
109 return SilkLens.loadSilk(UTGBConfig.class, configResource);
110 }
111
112 public static UTGBConfig parseSilk(String silk) throws XerialException, IOException {
113 return SilkLens.loadSilk(UTGBConfig.class, new StringReader(silk));
114 }
115
116 public String toSilk() {
117 return SilkLens.toSilk(this);
118 }
119
120 }