public static final AddressSettingsInfo from(final String jsonString) throws Exception { JSONObject object = new JSONObject(jsonString); return new AddressSettingsInfo(object.getString("addressFullMessagePolicy"), object.getLong("maxSizeBytes"), object.getInt("pageSizeBytes"), object.getInt("pageCacheMaxSize"), object.getInt("maxDeliveryAttempts"), object.getLong("redeliveryDelay"), object.getString("DLA"), object.getString("expiryAddress"), object.getBoolean("lastValueQueue"), object.getLong("redistributionDelay"), object.getBoolean("sendToDLAOnNoRoute")); }
/** * Get the JSONArray value associated with a key. * * @param key A key string. * @return A JSONArray which is the value. * @throws JSONException if the key is not found or * if the value is not a JSONArray. */ public JSONArray getJSONArray(final String key) throws JSONException { Object o = get(key); if (o instanceof JSONArray) { return (JSONArray)o; } throw new JSONException("JSONObject[" + JSONObject.quote(key) + "] is not a JSONArray."); }
/** * Get an array of field names from a JSONObject. * * @return An array of field names, or null if there are no names. */ public static String[] getNames(final JSONObject jo) { int length = jo.length(); if (length == 0) { return null; } Iterator i = jo.keys(); String[] names = new String[length]; int j = 0; while (i.hasNext()) { names[j] = (String)i.next(); j += 1; } return names; }
/** * Put a key/value pair in the JSONObject, where the value will be a * JSONObject which is produced from a Map. * @param key A key string. * @param value A Map value. * @return this. * @throws JSONException */ public JSONObject put(final String key, final Map value) throws JSONException { put(key, new JSONObject(value)); return this; }
/** * Get the long value associated with a key. If the number value is too * long for a long, it will be clipped. * * @param key A key string. * @return The long value. * @throws JSONException if the key is not found or if the value cannot * be converted to a long. */ public long getLong(final String key) throws JSONException { Object o = get(key); return o instanceof Number ? ((Number)o).longValue() : (long)getDouble(key); }
html.append("<td>" + txJson.get(TransactionDetail.KEY_CREATION_TIME) + "</td>"); html.append("<th>xid_as_base_64</th>"); html.append("<td colspan=\"3\">" + txJson.get(TransactionDetail.KEY_XID_AS_BASE64) + "</td></tr>"); html.append("<tr><th>xid_format_id</th>"); html.append("<td>" + txJson.get(TransactionDetail.KEY_XID_FORMAT_ID) + "</td>"); html.append("<th>xid_global_txid</th>"); html.append("<td>" + txJson.get(TransactionDetail.KEY_XID_GLOBAL_TXID) + "</td>"); html.append("<th>xid_branch_qual</th>"); html.append("<td>" + txJson.get(TransactionDetail.KEY_XID_BRANCH_QUAL) + "</td></tr>"); JSONArray msgs = txJson.getJSONArray(TransactionDetail.KEY_TX_RELATED_MESSAGES); for (int i = 0; i < msgs.length(); i++) JSONObject props = msgJson.getJSONObject(TransactionDetail.KEY_MSG_PROPERTIES); StringBuilder propstr = new StringBuilder(); @SuppressWarnings("unchecked") Iterator<String> propkeys = props.keys(); while (propkeys.hasNext()) propstr.append(key); propstr.append("="); propstr.append(props.get(key)); propstr.append(", "); html.append("<td>" + msgJson.get(TransactionDetail.KEY_MSG_OP_TYPE) + "</th>"); html.append("<th>message_type</th>"); html.append("<td>" + msgJson.get(TransactionDetail.KEY_MSG_TYPE) + "</td></tr>"); html.append("<tr><th>properties</th>"); html.append("<td colspan=\"3\">" + propstr.toString() + "</td></tr>");
public static String toJSon(final MessageCounter counter) throws Exception { DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM); JSONObject json = new JSONObject(counter); String lastAddTimestamp = dateFormat.format(new Date(counter.getLastAddedMessageTime())); json.put("lastAddTimestamp", lastAddTimestamp); String updateTimestamp = dateFormat.format(new Date(counter.getLastUpdate())); json.put("updateTimestamp", updateTimestamp); return json.toString(); }
/** * Returns an array of SubscriptionInfo corresponding to the JSON serialization returned * by {@link TopicControl#listAllSubscriptionsAsJSON()} and related methods. */ public static SubscriptionInfo[] from(final String jsonString) throws Exception { JSONArray array = new JSONArray(jsonString); SubscriptionInfo[] infos = new SubscriptionInfo[array.length()]; for (int i = 0; i < array.length(); i++) { JSONObject sub = array.getJSONObject(i); SubscriptionInfo info = new SubscriptionInfo(sub.getString("queueName"), sub.optString("clientID", null), sub.optString("name", null), sub.getBoolean("durable"), sub.optString("selector", null), sub.getInt("messageCount"), sub.getInt("deliveringCount")); infos[i] = info; } return infos; }
/** * Returns an array of SubscriptionInfo corresponding to the JSON serialization returned * by {@link TopicControl#listAllSubscriptionsAsJSON()} and related methods. */ public static JMSConsumerInfo[] from(final String jsonString) throws Exception { JSONArray array = new JSONArray(jsonString); JMSConsumerInfo[] infos = new JMSConsumerInfo[array.length()]; for (int i = 0; i < array.length(); i++) { JSONObject sub = array.getJSONObject(i); JMSConsumerInfo info = new JMSConsumerInfo(sub.getString("consumerID"), sub.getString("connectionID"), sub.getString("destinationName"), sub.getString("destinationType"), sub.getBoolean("browseOnly"), sub.getLong("creationTime"), sub.getBoolean("durable"), sub.optString("filter", null)); infos[i] = info; } return infos; }
/** * Returns an array of RoleInfo corresponding to the JSON serialization returned * by {@link QueueControl#listMessageCounterHistory()}. */ public static DayCounterInfo[] fromJSON(final String jsonString) throws JSONException { JSONObject json = new JSONObject(jsonString); JSONArray dayCounters = json.getJSONArray("dayCounters"); DayCounterInfo[] infos = new DayCounterInfo[dayCounters.length()]; for (int i = 0; i < dayCounters.length(); i++) { JSONObject counter = (JSONObject)dayCounters.get(i); JSONArray hour = (JSONArray)counter.getJSONArray("counters").get(0); int[] hourCounters = new int[24]; for (int j = 0; j < 24; j++) { hourCounters[j] = hour.getInt(j); } DayCounterInfo info = new DayCounterInfo(counter.getString("date"), hourCounters); infos[i] = info; } return infos; }
/** * 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 * JSONArray containing the value parameter. If the key was already * associated with a JSONArray, then the value parameter is appended to it. * @param key A key string. * @param value An object to be accumulated under the key. * @return this. * @throws JSONException If the key is null or if the current value * associated with the key is not a JSONArray. */ public JSONObject append(final String key, final Object value) throws JSONException { JSONObject.testValidity(value); Object o = opt(key); if (o == null) { put(key, new JSONArray().put(value)); } else if (o instanceof JSONArray) { put(key, ((JSONArray)o).put(value)); } else { throw new JSONException("JSONObject[" + key + "] is not a JSONArray."); } return this; }
/** * Put a value in the JSONArray, where the value will be a * JSONObject which is produced from a Map. * @param value A Map value. * @return this. */ public JSONArray put(final Map value) { put(new JSONObject(value)); return this; }
Iterator keys = keys(); writer.write('{'); writer.write(JSONObject.quote(k.toString())); writer.write(':'); Object v = map.get(k); if (v instanceof JSONObject) ((JSONObject)v).write(writer); writer.write(JSONObject.valueToString(v));
/** * Put a key/boolean pair in the JSONObject. * * @param key A key string. * @param value A boolean which is the value. * @return this. * @throws JSONException If the key is null. */ public JSONObject put(final String key, final boolean value) throws JSONException { put(key, value ? Boolean.TRUE : Boolean.FALSE); return this; }
public static JMSConnectionInfo[] from(final String jsonString) throws Exception { JSONArray array = new JSONArray(jsonString); JMSConnectionInfo[] infos = new JMSConnectionInfo[array.length()]; for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); String cid = obj.isNull("clientID") ? null : obj.getString("clientID"); String uname = obj.isNull("principal") ? null : obj.getString("principal"); JMSConnectionInfo info = new JMSConnectionInfo(obj.getString("connectionID"), obj.getString("clientAddress"), obj.getLong("creationTime"), cid, uname); infos[i] = info; } return infos; }
/** * Construct a JSONArray from a collection of beans. * The collection should have Java Beans. */ public JSONArray(final Collection collection, final boolean includeSuperClass) { myArrayList = collection == null ? new ArrayList<Object>() : new ArrayList<Object>(collection.size()); if (collection != null) { Iterator<Object> iter = collection.iterator(); while (iter.hasNext()) { Object o = iter.next(); if (o instanceof Map<?, ?>) { myArrayList.add(new JSONObject((Map<?, ?>)o, includeSuperClass)); } else if (!JSONObject.isStandardProperty(o.getClass())) { myArrayList.add(new JSONObject(o, includeSuperClass)); } else { myArrayList.add(o); } } } }
/** * Returns an array of RoleInfo corresponding to the JSON serialization returned * by {@link AddressControl#getRolesAsJSON()}. */ public static final RoleInfo[] from(final String jsonString) throws Exception { JSONArray array = new JSONArray(jsonString); RoleInfo[] roles = new RoleInfo[array.length()]; for (int i = 0; i < array.length(); i++) { JSONObject r = array.getJSONObject(i); RoleInfo role = new RoleInfo(r.getString("name"), r.getBoolean("send"), r.getBoolean("consume"), r.getBoolean("createDurableQueue"), r.getBoolean("deleteDurableQueue"), r.getBoolean("createNonDurableQueue"), r.getBoolean("deleteNonDurableQueue"), r.getBoolean("manage")); roles[i] = role; } return roles; }
Iterator keys = keys(); StringBuffer sb = new StringBuffer("{"); sb.append(JSONObject.quote(o.toString())); sb.append(':'); sb.append(JSONObject.valueToString(map.get(o)));
public static JMSSessionInfo[] from(final String jsonString) throws JSONException { JSONArray array = new JSONArray(jsonString); JMSSessionInfo[] infos = new JMSSessionInfo[array.length()]; for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); JMSSessionInfo info = new JMSSessionInfo(obj.getString("sessionID"), obj.getLong("creationTime")); infos[i] = info; } return infos; }