* *
******************************************************************************/
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
*/
private static Map<String, Object> keyPool = new LinkedHashMap<String, Object>(keyPoolSize);
+ private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
+
/**
* JSONObject.NULL is equivalent to the value that JavaScript calls null,
* whilst Java's null is equivalent to the value that JavaScript calls
}
}
-
/**
* The map where the JSONObject's properties are kept.
*/
private final Map<String, Object> map;
-
/**
* It is sometimes more convenient and less ambiguous to have a
* <code>NULL</code> object than to use Java's <code>null</code> value.
*/
public static final Object NULL = new Null();
-
/**
* Construct an empty JSONObject.
*/
public LOGJSONObject() {
- this.map = new LinkedHashMap<String, Object>();
+ this.map = new LinkedHashMap<>();
}
-
/**
* Construct a JSONObject from a subset of another JSONObject.
* An array of strings is used to identify the keys that should be copied.
*
* @param jo A JSONObject.
* @param names An array of strings.
- * @throws JSONException
- * @throws JSONException If a value is a non-finite number or if a name is duplicated.
*/
public LOGJSONObject(LOGJSONObject jo, String[] names) {
this();
try {
this.putOnce(names[i], jo.opt(names[i]));
} catch (Exception ignore) {
+ intlogger.error("PROV0001 LOGJSONObject: " + ignore.getMessage(), ignore);
}
}
}
-
/**
* Construct a JSONObject from a JSONTokener.
*
* @throws JSONException If there is a syntax error in the source string
* or a duplicated key.
*/
- public LOGJSONObject(JSONTokener x) throws JSONException {
+ public LOGJSONObject(JSONTokener x) {
this();
char c;
String key;
}
}
-
/**
* Construct a JSONObject from a Map.
*
}
}
-
/**
* Construct a JSONObject from an Object using bean getters.
* It reflects on all of the public methods of the object.
this.populateMap(bean);
}
-
/**
* Construct a JSONObject from an Object, using reflection to find the
* public members. The resulting JSONObject's keys will be the strings
}
}
-
/**
* Construct a JSONObject from a source JSON text string.
* This is the most commonly used JSONObject constructor.
this(new JSONTokener(source));
}
-
/**
* Construct a JSONObject from a ResourceBundle.
*
}
}
-
/**
* Accumulate values under a key. It is similar to the put method except
* that if there is already an object stored under the key then a
return this;
}
-
/**
* Append values to the array under a key. If the key does not exist in the
* JSONObject, then the key is put in the JSONObject with its value being a
return this;
}
-
/**
* Produce a string from a double. The string "null" will be returned if
* the number is not finite.
return string;
}
-
/**
* Get the value object associated with a key.
*
return object;
}
-
/**
* Get the boolean value associated with a key.
*
"] is not a Boolean.");
}
-
/**
* Get the double value associated with a key.
*
* @throws JSONException if the key is not found or
* if the value is not a Number object and cannot be converted to a number.
*/
- public double getDouble(String key) throws JSONException {
+ public double getDouble(String key) {
Object object = this.get(key);
try {
return object instanceof Number
? ((Number) object).doubleValue()
: Double.parseDouble((String) object);
} catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a number.");
+ intlogger.error("JSONObject[" + quote(key) + "] is not a number.", e);
+ throw new JSONException("JSONObject[" + quote(key) + "] is not a number.");
}
}
-
/**
* Get the int value associated with a key.
*
* @throws JSONException if the key is not found or if the value cannot
* be converted to an integer.
*/
- public int getInt(String key) throws JSONException {
+ public int getInt(String key) {
Object object = this.get(key);
try {
return object instanceof Number
? ((Number) object).intValue()
: Integer.parseInt((String) object);
} catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not an int.");
+ intlogger.error("JSONObject[" + quote(key) + "] is not an int.", e);
+ throw new JSONException("JSONObject[" + quote(key) + "] is not an int.");
}
}
-
/**
* Get the JSONArray value associated with a key.
*
"] is not a JSONArray.");
}
-
/**
* Get the JSONObject value associated with a key.
*
"] is not a JSONObject.");
}
-
/**
* Get the long value associated with a key.
*
? ((Number) object).longValue()
: Long.parseLong((String) object);
} catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a long.");
+ intlogger.error("JSONObject[" + quote(key) + "] is not a long.", e);
+ throw new JSONException("JSONObject[" + quote(key) + "] is not a long.");
}
}
-
/**
* Get an array of field names from a JSONObject.
*
return names;
}
-
- /**
- * Get an array of field names from an Object.
- *
- * @return An array of field names, or null if there are no names.
- */
- public static String[] getNames(Object object) {
- if (object == null) {
- return null;
- }
- Class<? extends Object> klass = object.getClass();
- Field[] fields = klass.getFields();
- int length = fields.length;
- if (length == 0) {
- return null;
- }
- String[] names = new String[length];
- for (int i = 0; i < length; i += 1) {
- names[i] = fields[i].getName();
- }
- return names;
- }
-
-
/**
* Get the string associated with a key.
*
* @return A string which is the value.
* @throws JSONException if there is no string value for the key.
*/
- public String getString(String key) throws JSONException {
+ public String getString(String key) {
Object object = this.get(key);
if (object instanceof String) {
return (String) object;
"] not a string.");
}
-
/**
* Determine if the JSONObject contains a specific key.
*
return this.map.containsKey(key);
}
-
/**
* Increment a property of a JSONObject. If there is no such property,
* create one with a value of 1. If there is such a property, and if
* @throws JSONException If there is already a property with this name
* that is not an Integer, Long, Double, or Float.
*/
- public LOGJSONObject increment(String key) throws JSONException {
+ public LOGJSONObject increment(String key) {
Object value = this.opt(key);
if (value == null) {
this.put(key, 1);
return this;
}
-
- /**
- * Determine if the value associated with the key is null or if there is
- * no value.
- *
- * @param key A key string.
- * @return true if there is no value associated with the key or if
- * the value is the JSONObject.NULL object.
- */
- public boolean isNull(String key) {
- return LOGJSONObject.NULL.equals(this.opt(key));
- }
-
-
/**
* Get an enumeration of the keys of the JSONObject.
*
return this.keySet().iterator();
}
-
/**
* Get a set of keys of the JSONObject.
*
return this.map.keySet();
}
-
/**
* Get the number of keys stored in the JSONObject.
*
return this.map.size();
}
-
/**
* Produce a JSONArray containing the names of the elements of this
* JSONObject.
return string;
}
-
/**
* Get an optional value associated with a key.
*
return key == null ? null : this.map.get(key);
}
-
- /**
- * Get an optional boolean associated with a key.
- * It returns false if there is no such key, or if the value is not
- * Boolean.TRUE or the String "true".
- *
- * @param key A key string.
- * @return The truth.
- */
- public boolean optBoolean(String key) {
- return this.optBoolean(key, false);
- }
-
-
/**
* Get an optional boolean associated with a key.
* It returns the defaultValue if there is no such key, or if it is not
try {
return this.getBoolean(key);
} catch (Exception e) {
+ intlogger.trace("Using defaultValue: " + defaultValue, e);
return defaultValue;
}
}
-
- /**
- * Get an optional double associated with a key,
- * or NaN if there is no such key or if its value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A string which is the key.
- * @return An object which is the value.
- */
- public double optDouble(String key) {
- return this.optDouble(key, Double.NaN);
- }
-
-
/**
* Get an optional double associated with a key, or the
* defaultValue if there is no such key or if its value is not a number.
try {
return this.getDouble(key);
} catch (Exception e) {
+ intlogger.trace("Using defaultValue: " + defaultValue, e);
return defaultValue;
}
}
-
- /**
- * Get an optional int value associated with a key,
- * or zero if there is no such key or if the value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @return An object which is the value.
- */
- public int optInt(String key) {
- return this.optInt(key, 0);
- }
-
-
/**
* Get an optional int value associated with a key,
* or the default if there is no such key or if the value is not a number.
try {
return this.getInt(key);
} catch (Exception e) {
+ intlogger.trace("Using defaultValue: " + defaultValue, e);
return defaultValue;
}
}
-
- /**
- * Get an optional JSONArray associated with a key.
- * It returns null if there is no such key, or if its value is not a
- * JSONArray.
- *
- * @param key A key string.
- * @return A JSONArray which is the value.
- */
- public JSONArray optJSONArray(String key) {
- Object o = this.opt(key);
- return o instanceof JSONArray ? (JSONArray) o : null;
- }
-
-
/**
* Get an optional JSONObject associated with a key.
* It returns null if there is no such key, or if its value is not a
return object instanceof LOGJSONObject ? (LOGJSONObject) object : null;
}
-
- /**
- * Get an optional long value associated with a key,
- * or zero if there is no such key or if the value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @return An object which is the value.
- */
- public long optLong(String key) {
- return this.optLong(key, 0);
- }
-
-
/**
* Get an optional long value associated with a key,
* or the default if there is no such key or if the value is not a number.
}
}
-
- /**
- * Get an optional string associated with a key.
- * It returns an empty string if there is no such key. If the value is not
- * a string and is not null, then it is converted to a string.
- *
- * @param key A key string.
- * @return A string which is the value.
- */
- public String optString(String key) {
- return this.optString(key, "");
- }
-
-
/**
* Get an optional string associated with a key.
* It returns the defaultValue if there is no such key.
return NULL.equals(object) ? defaultValue : object.toString();
}
-
private void populateMap(Object bean) {
Class<? extends Object> klass = bean.getClass();
}
}
} catch (Exception ignore) {
+ intlogger.trace("populateMap: " + ignore.getMessage(), ignore);
}
}
}
-
/**
* Put a key/boolean pair in the JSONObject.
*
return this;
}
-
/**
* Put a key/value pair in the JSONObject, where the value will be a
* JSONArray which is produced from a Collection.
return this;
}
-
/**
* Put a key/double pair in the JSONObject.
*
return this;
}
-
/**
* Put a key/int pair in the JSONObject.
*
return this;
}
-
/**
* Put a key/long pair in the JSONObject.
*
return this;
}
-
/**
* Put a key/value pair in the JSONObject, where the value will be a
* JSONObject which is produced from a Map.
return this;
}
-
/**
* Put a key/value pair in the JSONObject. If the value is null,
* then the key will be removed from the JSONObject if it is present.
return this;
}
-
/**
* Put a key/value pair in the JSONObject, but only if the key and the
* value are both non-null, and only if there is not already a member
return this;
}
-
/**
* Put a key/value pair in the JSONObject, but only if the
* key and the value are both non-null.
return this;
}
-
/**
* Produce a string in double quotes with backslash sequences in all the
* right places. A backslash will be inserted within </, producing <\/,
synchronized (sw.getBuffer()) {
try {
return quote(string, sw).toString();
- } catch (IOException ignored) {
- // will never happen - we are writing to a string writer
+ } catch (IOException e) {
+ intlogger.trace("Ignore Exception message: ", e);
return "";
}
}
return myLong;
}
}
- } catch (Exception ignore) {
+ } catch (Exception e) {
+ intlogger.trace("Ignore Exception message: ", e);
}
}
return string;
}
-
/**
* Throw an exception if the object is a NaN or infinite number.
*
* @param o The object to test.
* @throws JSONException If o is a non-finite number.
*/
- public static void testValidity(Object o) throws JSONException {
+ public static void testValidity(Object o) {
if (o != null) {
if (o instanceof Double) {
if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
}
}
-
/**
* Produce a JSONArray containing the values of the members of this
* JSONObject.
try {
return this.toString(0);
} catch (Exception e) {
- return null;
+ intlogger.trace("Exception: ", e);
+ return "";
}
}
-
/**
* Make a prettyprinted JSON text of this JSONObject.
* <p>
*/
@SuppressWarnings("unchecked")
public static String valueToString(Object value) throws JSONException {
- if (value == null || value.equals(null)) {
+ if (value == null) {
return "null";
}
if (value instanceof JSONString) {
}
return new LOGJSONObject(object);
} catch (Exception exception) {
+ intlogger.trace("Exception: ", exception);
return null;
}
}
-
- /**
- * Write the contents of the JSONObject as JSON text to a writer.
- * For compactness, no whitespace is added.
- * <p>
- * Warning: This method assumes that the data structure is acyclical.
- *
- * @return The writer.
- * @throws JSONException
- */
- public Writer write(Writer writer) throws JSONException {
- return this.write(writer, 0, 0);
- }
-
-
@SuppressWarnings("unchecked")
static final Writer writeValue(Writer writer, Object value,
int indentFactor, int indent) throws JSONException, IOException {
- if (value == null || value.equals(null)) {
+ if (value == null) {
writer.write("null");
} else if (value instanceof LOGJSONObject) {
((LOGJSONObject) value).write(writer, indentFactor, indent);