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-
1513public 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 );
0 commit comments