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.util.ArrayList;
28 import java.util.List;
29 import java.util.Properties;
30
31 import org.utgenome.config.UTGBConfig.Database;
32 import org.utgenome.config.UTGBConfig.WebAction;
33 import org.xerial.util.log.Logger;
34
35
36
37
38
39
40
41 public class TrackConfiguration {
42 private static Logger _logger = Logger.getLogger(TrackConfiguration.class);
43
44 private String version;
45 private String packageName;
46 private String projectName;
47 private String group;
48 private ArrayList<ActionInfo> actionList = new ArrayList<ActionInfo>();
49 private ArrayList<DatabaseInfo> dbInfoList = new ArrayList<DatabaseInfo>();
50 private ArrayList<ImportStmt> importList = new ArrayList<ImportStmt>();
51 private Properties properties = new Properties();
52
53 public TrackConfiguration() {
54 }
55
56 public DatabaseInfo getDatabase(String databaseID) {
57 for (DatabaseInfo dbInfo : dbInfoList) {
58 if (dbInfo.getId().equals(databaseID))
59 return dbInfo;
60 }
61 return null;
62 }
63
64 public String getVersion() {
65 return version;
66 }
67
68 public void setVersion(String version) {
69 this.version = version;
70 }
71
72 public String getPackage() {
73 return packageName;
74 }
75
76 public void setPackage(String packageName) {
77 this.packageName = packageName;
78 }
79
80 public List<ActionInfo> getActionList() {
81 return actionList;
82 }
83
84 public void addAction(ActionInfo action) {
85 actionList.add(action);
86 }
87
88 public List<DatabaseInfo> getDatabaseList() {
89 return dbInfoList;
90 }
91
92 public void addDatabase(DatabaseInfo db) {
93 dbInfoList.add(db);
94 }
95
96 public String getProjectName() {
97 return projectName;
98 }
99
100 public void setProjectName(String projectName) {
101 this.projectName = projectName;
102 }
103
104 public void addImport(ImportStmt importStatement) {
105 this.importList.add(importStatement);
106 }
107
108 public List<ImportStmt> getImportList() {
109 return this.importList;
110 }
111
112 public String getGroup() {
113 return group;
114 }
115
116 public void setGroup(String group) {
117 this.group = group;
118 }
119
120 public String getProperty(String key, String defaultValue) {
121 return properties.getProperty(key, defaultValue);
122 }
123
124 public void putProperty(String key, String value) {
125 properties.setProperty(key, value);
126 }
127
128 public void put(String key, String value) {
129 properties.setProperty(key, value);
130 }
131
132 public UTGBConfig convert() {
133 UTGBConfig config = new UTGBConfig();
134 config.version = version;
135 config.group = group;
136 config.javaPackage = packageName;
137 config.projectName = projectName;
138
139 for (ImportStmt each : importList) {
140 WebAction ac = new WebAction();
141 ac.alias = each.getAlias();
142 ac.javaPackage = each.getActionPackage();
143 config.webAction.add(ac);
144 }
145
146 for (DatabaseInfo each : dbInfoList) {
147 Database db = new Database();
148 db.id = each.getId();
149 if (each.getConnectionList().isEmpty())
150 continue;
151 else if (each.getConnectionList().size() > 1) {
152 _logger.warn(String.format("db connection settings (id=%s) except the first entry will be ignored: ", each.getId()));
153 }
154
155 ConnectionInfo ci = each.getConnectionList().get(0);
156 db.dbms = ci.getDbms();
157 db.address = ci.getAddress();
158 db.user = ci.getUser();
159 db.pass = ci.getPass();
160
161 config.database.add(db);
162 }
163
164
165 for (Object key : properties.keySet()) {
166 config.put(key.toString(), properties.getProperty(key.toString()));
167 }
168
169 return config;
170
171 }
172
173 }