Skip to content

Commit 82bfebe

Browse files
committed
- Refactored config class - no more static methods
- Fixed bug in the setParameter() method in ServiceRequest - Fixed bug handling functions in parameters in WebService - Added UTF8_BOM static variable to the CSV class git-svn-id: svn://192.168.0.80/JavaXT/javaxt-express@1337 2c7b0aa6-e0b2-3c4e-bb4a-8b65b6c465ff
1 parent 38927f1 commit 82bfebe

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

src/javaxt/express/Config.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,18 @@
66
//** Config Class
77
//******************************************************************************
88
/**
9-
* Provides thread-safe, static methods used to get and set application
10-
* variables.
9+
* Provides thread-safe methods used to get and set application variables.
1110
*
1211
******************************************************************************/
1312

14-
1513
public class Config {
1614

17-
//private static javaxt.io.Jar jar;
18-
private static List<JSONObject> config;
19-
static {
20-
//jar = new javaxt.io.Jar(new Config());
21-
config = new LinkedList<JSONObject>();
15+
private List<JSONObject> config;
16+
17+
public Config(){
18+
config = new LinkedList<>();
2219
config.add(new JSONObject());
2320
}
24-
protected Config(){}
2521

2622

2723
//**************************************************************************
@@ -30,7 +26,7 @@ protected Config(){}
3026
/** Used to initialize the config with a given JSON document. This will
3127
* replace any previously assigned config values.
3228
*/
33-
public static void init(JSONObject json){
29+
public void init(JSONObject json){
3430
synchronized(config){
3531
config.set(0, json);
3632
config.notify();
@@ -43,7 +39,7 @@ public static void init(JSONObject json){
4339
//**************************************************************************
4440
/** Returns the value for a given key.
4541
*/
46-
public static JSONValue get(String key){
42+
public JSONValue get(String key){
4743
synchronized(config){
4844
return config.get(0).get(key);
4945
}
@@ -55,7 +51,7 @@ public static JSONValue get(String key){
5551
//**************************************************************************
5652
/** Used to set the value for a given key.
5753
*/
58-
public static void set(String key, Object value){
54+
public void set(String key, Object value){
5955
synchronized(config){
6056
config.get(0).set(key, value);
6157
config.notify();
@@ -68,7 +64,7 @@ public static void set(String key, Object value){
6864
//**************************************************************************
6965
/** Returns true if the config has a given key.
7066
*/
71-
public static boolean has(String key){
67+
public boolean has(String key){
7268
synchronized(config){
7369
return config.get(0).has(key);
7470
}
@@ -80,7 +76,7 @@ public static boolean has(String key){
8076
//**************************************************************************
8177
/** Returns a list of keys found in the config.
8278
*/
83-
public static ArrayList<String> getKeys(){
79+
public ArrayList<String> getKeys(){
8480
ArrayList<String> keys = new ArrayList<String>();
8581
synchronized(config){
8682
Iterator<String> it = config.get(0).keys();
@@ -97,15 +93,15 @@ public static ArrayList<String> getKeys(){
9793
//**************************************************************************
9894
/** Returns true if there are no entries in the config.
9995
*/
100-
public static boolean isEmpty(){
96+
public boolean isEmpty(){
10197
return getKeys().isEmpty();
10298
}
10399

104100

105101
//**************************************************************************
106102
//** getDatabase
107103
//**************************************************************************
108-
public static javaxt.sql.Database getDatabase(){
104+
public javaxt.sql.Database getDatabase(){
109105
JSONValue val = get("database");
110106
if (val==null) return null;
111107
if (val.toObject() instanceof javaxt.sql.Database){
@@ -118,11 +114,11 @@ public static javaxt.sql.Database getDatabase(){
118114
}
119115
}
120116

121-
public static javaxt.sql.Database getDatabase(JSONValue val){
117+
public javaxt.sql.Database getDatabase(JSONValue val){
122118
return getDatabase(val.toJSONObject());
123119
}
124120

125-
public static javaxt.sql.Database getDatabase(JSONObject json){
121+
public javaxt.sql.Database getDatabase(JSONObject json){
126122
if (json==null) return null;
127123
javaxt.sql.Database database = new javaxt.sql.Database();
128124
database.setDriver(json.get("driver").toString());
@@ -141,18 +137,17 @@ public static javaxt.sql.Database getDatabase(JSONObject json){
141137
//**************************************************************************
142138
//** setDatabase
143139
//**************************************************************************
144-
public static void setDatabase(javaxt.sql.Database database){
140+
public void setDatabase(javaxt.sql.Database database){
145141
set("database", database);
146142
}
147143

148144

149-
150145
//**************************************************************************
151146
//** toJson
152147
//**************************************************************************
153148
/** Returns the current config in JSON notation.
154149
*/
155-
public static JSONObject toJson(){
150+
public JSONObject toJson(){
156151
JSONObject json = new JSONObject();
157152
synchronized(config){
158153
JSONObject currConfig = config.get(0);

src/javaxt/express/ServiceRequest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,15 @@ public boolean hasParameter(String key){
245245
//**************************************************************************
246246
public void setParameter(String key, String val){
247247
if (key!=null){
248-
key = key.toLowerCase();
249-
List<String> parameters = getParameter(key, this.parameters);
250248

249+
if (val==null){
250+
removeParameter(key, this.parameters);
251+
return;
252+
}
253+
254+
255+
//Get parameters
256+
List<String> parameters = getParameter(key, this.parameters);
251257

252258

253259
//Special case for classes that override the hasParameter and
@@ -267,17 +273,15 @@ public void setParameter(String key, String val){
267273
parameters.add(val);
268274
setParameter(key, parameters, this.parameters);
269275
}
270-
else{
271-
removeParameter(key, this.parameters);
272-
}
273276
}
274277
else{
275278
if (val!=null) parameters.set(0, val);
276279
}
277280

278281

279282
//Update offset and limit as needed
280-
if (key.equals("offset") || key.equals("limit") || key.equals("page")){
283+
String k = key.toLowerCase();
284+
if (k.equals("offset") || k.equals("limit") || k.equals("page")){
281285
updateOffsetLimit();
282286
}
283287
}

src/javaxt/express/WebService.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,15 @@ private ServiceResponse list(Class c, ServiceRequest request, Database database)
281281
else{
282282
for (int i=0; i<fields.length; i++){
283283
if (i>0) str.append(",");
284-
String fieldName = fields[i].toString();
285-
fieldName = StringUtils.camelCaseToUnderScore(fieldName);
286-
str.append(fieldName);
284+
Field field = fields[i];
285+
String fieldName = field.toString();
286+
if (field.isFunction()){
287+
str.append(fieldName);
288+
}
289+
else{
290+
fieldName = StringUtils.camelCaseToUnderScore(fieldName);
291+
str.append(fieldName);
292+
}
287293
}
288294
}
289295

src/javaxt/express/utils/CSV.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
public class CSV {
1313

14+
public static final String UTF8_BOM = "\uFEFF";
1415

1516
//**************************************************************************
1617
//** Columns

0 commit comments

Comments
 (0)