Skip to main content
summaryrefslogtreecommitdiffstats
blob: ed666972d781a80e6da826eafccb950913cc931e (plain) (blame)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.jdk.core.util;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import org.eclipse.osee.framework.jdk.core.type.Pair;

/**
 * @author Roberto E. Escobar
 */
public class OseeProperties {
   private static final String OSEE_LOG_DEFAULT = "osee.log.default";
   private static final String OSEE_JINI_SERVICE_GROUPS = "osee.jini.lookup.groups";
   private static final String OSEE_JINI_FORCED_REGGIE_SEARCH = "osee.jini.forced.reggie.search";
   private static final String OSEE_PORT_SCAN_START_PORT = "osee.port.scanner.start.port";

   public static final String OSEE_DB_CONNECTION_ID = "osee.db.connection.id";
   private static final String OSEE_CONNECTION_INFO_URI = "osee.connection.info.uri";
   private static final String OSEE_EMBEDDED_DB_SERVER = "osee.db.embedded.server";
   private static final String OSEE_EMBEDDED_DB_WEB_SERVER_PORT = "osee.db.embedded.web.server.port";
   private static final String OSEE_DEFAULT_BROKER_URI = "osee.default.broker.uri";
   private static final String OSEE_PROXY_BYPASS_ENABLED = "osee.proxy.bypass.enabled";
   private static final String OSEE_DB_CONNECTION_POOL_SIZE = "osee.db.connection.pool.size";
   private static final String OSEE_DB_CONNECTION_POOL_CONFIG_URI = "osee.db.connection.pool.config.uri";

   protected OseeProperties() {
      // Utility Class
   }

   public static String getOseeDefaultBrokerUri() {
      return System.getProperty(OSEE_DEFAULT_BROKER_URI);
   }

   public static int getOseeDbEmbeddedWebServerPort() {
      int port = -1;
      String portStr = System.getProperty(OSEE_EMBEDDED_DB_WEB_SERVER_PORT, "");
      if (Strings.isValid(portStr)) {
         port = Integer.parseInt(portStr);
      }
      return port;
   }

   public static Pair<String, Integer> getOseeDbEmbeddedServerAddress() {
      Pair<String, Integer> addressAndPort = null;
      String serverAddress = System.getProperty(OSEE_EMBEDDED_DB_SERVER, "");
      if (Strings.isValid(serverAddress)) {
         String[] hostPort = serverAddress.split(":");
         addressAndPort = new Pair<>(hostPort[0], Integer.parseInt(hostPort[1]));
      }
      return addressAndPort;
   }

   public static int getOseePortScannerStartPort() {
      int toReturn = 18000;
      String startPort = System.getProperty(OSEE_PORT_SCAN_START_PORT, "18000");
      try {
         toReturn = Integer.parseInt(startPort);
      } catch (Exception ex) {
         toReturn = 18000;
      }
      return toReturn;
   }

   /**
    * Get the default OSEE logging level. The default level is WARNING.
    * 
    * @return default logging level
    */
   public static Level getOseeLogDefault() {
      Level toReturn = Level.WARNING;
      String level = System.getProperty(OSEE_LOG_DEFAULT, "WARNING");
      try {
         toReturn = Level.parse(level);
      } catch (Exception ex) {
         toReturn = Level.WARNING;
      }
      return toReturn;
   }

   /**
    * OSEE database information id to use for default database connections.
    * 
    * @return the default database information id to use for database connections.
    */
   public static String getOseeDbConnectionId() {
      return System.getProperty(OSEE_DB_CONNECTION_ID);
   }

   /**
    * Retrieve the connection info file location
    * 
    * @return connection info file URI
    */
   public static String getOseeConnectionInfoUri() {
      return System.getProperty(OSEE_CONNECTION_INFO_URI, "");
   }

   /**
    * Retrieve the number of max active connections
    * 
    * @return number of max active connections
    */
   public static int getOseeDbConnectionCount() {
      int toReturn;
      String connections = System.getProperty(OSEE_DB_CONNECTION_POOL_SIZE, "10");
      try {
         toReturn = Integer.parseInt(connections);
      } catch (Exception ex) {
         toReturn = 10;
      }
      return toReturn;
   }

   /**
    * Retrieve the connection pool configuration file location
    * 
    * @return connection pool configuration file URI
    */
   public static String getOseeDbConnectionPoolConfigUri() {
      return System.getProperty(OSEE_DB_CONNECTION_POOL_CONFIG_URI, "");
   }

   /**
    * Retrieves the JINI Groups this system is a part of.
    * 
    * @return JINI service groups
    */
   public static String getOseeJiniServiceGroups() {
      return System.getProperty(OSEE_JINI_SERVICE_GROUPS);
   }

   /**
    * Sets the JINI Groups this system is a part of.
    * 
    * @param JINI service groups
    */
   public static void setOseeJiniServiceGroups(String toStore) {
      System.setProperty(OSEE_JINI_SERVICE_GROUPS, toStore);
   }

   /**
    * @return whether forced reggie search is enabled
    */
   public static boolean isOseeJiniForcedReggieSearchEnabled() {
      return Boolean.valueOf(System.getProperty(OSEE_JINI_FORCED_REGGIE_SEARCH));
   }

   /**
    * Need to match methods in TestUtil
    */
   public static boolean isInTest() {
      return Boolean.valueOf(System.getProperty("osee.isInTest"));
   }

   /**
    * Need to match methods in TestUtil
    */
   public static void setIsInTest(boolean isInTest) {
      System.setProperty("osee.isInTest", String.valueOf(isInTest));
   }

   private void toStringHelper(List<String> list, Class<?> clazz) {
      Field[] fields = clazz.getDeclaredFields();
      for (Field field : fields) {
         int mod = field.getModifiers();
         if (Modifier.isStatic(mod) && Modifier.isFinal(mod)) {
            boolean wasModified = false;
            try {
               if (!field.isAccessible()) {
                  field.setAccessible(true);
                  wasModified = true;
               }
               Object object = field.get(this);
               if (object instanceof String) {
                  String value = (String) object;
                  list.add(String.format("%s: %s", value, System.getProperty(value)));
               }
            } catch (IllegalAccessException ex) {
               // DO NOTHING
            } finally {
               if (wasModified) {
                  field.setAccessible(false);
               }
            }
         }
      }
      Class<?> superClazz = clazz.getSuperclass();
      if (superClazz != null) {
         toStringHelper(list, superClazz);
      }
   }

   /**
    * @return whether proxy settings should be ignored for HttpRequests
    */
   public static boolean getOseeProxyBypassEnabled() {
      return Boolean.valueOf(System.getProperty(OSEE_PROXY_BYPASS_ENABLED, "false"));
   }

   @Override
   public String toString() {
      List<String> list = new ArrayList<>();
      toStringHelper(list, getClass());
      Collections.sort(list);
      return org.eclipse.osee.framework.jdk.core.util.Collections.toString("\n", list);
   }
}

Back to the top