Return JSON representing the entire tree of MBeans in DynaTree format.

@param key
@param mode
512593
@GET
    public Response getMBeans(
            @QueryParam("key") @DefaultValue("root") String key,
            @QueryParam("mode") @DefaultValue("") String mode,
            @QueryParam("jsonp") @DefaultValue("") String jsonp)
            throws Exception {

        LOG.info("key" + key);
        DynaTreeNode root = new DynaTreeNode();
        for (String domain : jmx.getDomainList()) {
            root.putChild(jmx.getDomainTree(domain).setTitle(domain)
                    .setMode("domain"));
        }

        StringWriter out = new StringWriter();
        if (jsonp.isEmpty()) {
            root.getChildrenJSONArray().write(out);
        } else {
            out.append(jsonp).append("(");
            root.getChildrenJSONArray().write(out);
            out.append(");");
        }

        return Response.ok(out.toString()).header("Pragma", "no-cache")
                .header("Cache-Control", "no-cache").header("Expires", "0")
                .build();
    }
260458
@SuppressWarnings("unchecked")
    private Map<String,Object> jsonifyMBeanInfo(MBeanInfo mBeanInfo) {
        Map<String, Object> result = new LinkedHashMap<>();

        // desc
        result.put("desc", mBeanInfo.getDescription());

        // attr
        Map<String, Object> attrMap = new LinkedHashMap<>();
        result.put("attr", attrMap);
        for (MBeanAttributeInfo attrInfo : mBeanInfo.getAttributes()) {
            if (attrInfo == null) {
                continue;
            }
            Map<String, Object> attr = new HashMap<>();
            attr.put("type", attrInfo.getType());
            attr.put("desc", attrInfo.getDescription());
            attr.put("rw", attrInfo.isWritable() && attrInfo.isReadable());
            attrMap.put(attrInfo.getName(), attr);
        }

        // op
        Map<String, Object> opMap = new LinkedHashMap<>();
        result.put("op", opMap);
        for (MBeanOperationInfo opInfo : mBeanInfo.getOperations()) {
            Map<String, Object> map = new HashMap<>();
            List<Map<String, String>> argList = new ArrayList<>(opInfo.getSignature().length);
            for (MBeanParameterInfo paramInfo : opInfo.getSignature()) {
                Map<String, String> args = new HashMap<>();
                args.put("desc", paramInfo.getDescription());
                args.put("name", paramInfo.getName());
                args.put("type", paramInfo.getType());
                argList.add(args);
            }
            map.put("args", argList);
            map.put("ret", opInfo.getReturnType());
            map.put("desc", opInfo.getDescription());
            Object ops = opMap.get(opInfo.getName());
            if (ops != null) {
                if (ops instanceof List) {
                    // If it is already a list, simply add it to the end
                    ((List) ops).add(map);
                } else if (ops instanceof Map) {
                    // If it is a map, add a list with two elements
                    // (the old one and the new one)
                    List<Object> opList = new LinkedList<>();
                    opList.add(ops);
                    opList.add(map);
                    opMap.put(opInfo.getName(), opList);
                }
            } else {
                // No value set yet, simply add the map as plain value
                opMap.put(opInfo.getName(), map);
            }
        }

        // not
        Map<String, Object> notMap = new LinkedHashMap<>();
        result.put("not", notMap);
        for (MBeanNotificationInfo notInfo : mBeanInfo.getNotifications()) {
            Map<String, Object> map = new HashMap<>();
            map.put("name", notInfo.getName());
            map.put("desc", notInfo.getDescription());
            String[] types = notInfo.getNotifTypes();
            List<String> tList = new ArrayList<>(types.length);
            Collections.addAll(tList, types);
            map.put("types", tList);
            notMap.put(notInfo.getName(), map);
        }

        // this is default - in case we won't find RBACDecorator (possible in hawtio-wildfly for example)
        result.put("canInvoke", true);

        return result;
    }
128328
private void doMultiMapKeys(final Message<JsonObject> message) {
    final String name = message.body().getString("name");
    if (name == null) {
      message.reply(new JsonObject().putString("status", "error").putString("message", "No name specified."));
      return;
    }

    context.execute(new Action<Set<Object>>() {
      @Override
      public Set<Object> perform() {
        return data.getMultiMap(formatKey(name)).keySet();
      }
    }, new Handler<AsyncResult<Set<Object>>>() {
      @Override
      public void handle(AsyncResult<Set<Object>> result) {
        if (result.failed()) {
          message.reply(new JsonObject().putString("status", "error").putString("message", result.cause().getMessage()));
        } else {
          message.reply(new JsonObject().putString("status", "ok").putArray("result", new JsonArray(result.result().toArray(new Object[result.result().size()]))));
        }
      }
    });
  }
134919
Map<String, Object> serialize() {

		final Map<String, Object> map = new TreeMap<>();

		map.put(JsonSchema.KEY_DEFINITIONS, typeDefinitions.serialize());
		map.put(JsonSchema.KEY_METHODS, globalMethods.serialize());
		map.put(JsonSchema.KEY_ID, getId());

		return map;
	}
766141
public final PJsonObject optJSONObject(final String key) {
        final JSONObject val = this.obj.optJSONObject(key);
        return val != null ? new PJsonObject(this, val, key) : null;
    }
1226578
function toJSON(key) {
	    var O = _toObject(this);
	    var pv = _toPrimitive(O);
	    return typeof pv == 'number' && !isFinite(pv) ? null : O.toISOString();
	  }
773338
protected <T> JsonObjectBase buildSuccess(String key, T value) {
        return JsonObjectUtils.buildObjectSuccess(key, value);
    }
661797
private String string(JsonObject node, String key, String default_) {
    JsonElement value = node.get(key);
    if (value != null && value.isJsonPrimitive()) {
      return value.getAsString();
    }
    return default_;
  }
269145
function toJSON(key) {
    var O = toObject(this);
    var pv = toPrimitive(O);
    return typeof pv == 'number' && !isFinite(pv) ? null : O.toISOString();
  }
278247
@Override
	public Controller<M, V> getChild(final String key)
	{
		return children.get(key);
	}
510604
static <T> T registerJSONObject(T key, Object json) {
        registeredAtleastOnce = true;
        rawJsonMap.get().put(key, json);
        return key;
    }
227291
private void toJSON(JSONEmitter json) {
        switch (m_type) {
        case ARRAY:
            json.startArray(m_name);
            if (m_children != null) {
                for (UNode childNode : m_children) {
                    if (childNode.isMap()) {
                        json.startObject();
                        childNode.toJSON(json);
                        json.endObject();
                    } else {
                        childNode.toJSON(json);
                    }
                }
            }
            json.endArray();
            break;
            
        case MAP:
            // Return map child modes in name order.
            json.startGroup(m_name);
            if (m_childNodeMap != null) {
                assert m_childNodeMap.size() == m_children.size();
                for (UNode childNode : m_childNodeMap.values()) {
                    childNode.toJSON(json);
                }
            }
            json.endGroup();
            break;
            
        case VALUE:
            if (m_bAltFormat && m_tagName != null) {
                // Generate as "<tag>: {"<name>": "<value>"}
                json.startGroup(m_tagName);
                json.addValue(m_name, m_value);
                json.endGroup();
            } else if (m_parent != null && m_parent.isArray()) {
                if (m_name.equals("value")) {
                    // nameless node: "<value>"
                    json.addValue(m_value);
                } else {
                    // value as an object: {"name": "value"}
                    json.addObject(m_name, m_value);
                }
            } else {
                // Simple case: "<name>": "<value>"
                json.addValue(m_name, m_value);
            }
            break;
            
        default:
            assert false : "Unknown NodeType: " + m_type;
        }
    }
1134545
protected MessageResources getMessageResources( String key )
    {
        return ( MessageResources ) getServletContext().getAttribute( key + getModuleConfig().getPrefix() );
    }
1019554
private void pushLevel(final Mode mode) {
        JsonLevel newJsonLevel = null;

        if (mode == Mode.BOM) {
            newJsonLevel = new JsonLevel(mode, new JsonPointer()); //not a valid nesting level
        } else if (mode == Mode.JSON_OBJECT) {
            if (levelStack.size() > 0) {
                JsonLevel current = levelStack.peek();
                newJsonLevel = new JsonLevel(mode, new JsonPointer(current.jsonPointer().tokens()));
            } else {
                newJsonLevel = new JsonLevel(mode, new JsonPointer());
            }
        } else if (mode == Mode.JSON_ARRAY) {
            if (levelStack.size() > 0) {
                JsonLevel current = levelStack.peek();
                newJsonLevel = new JsonLevel(mode, new JsonPointer(current.jsonPointer().tokens()));
            } else {
                newJsonLevel = new JsonLevel(mode, new JsonPointer());
            }
            newJsonLevel.isArray(true);
            newJsonLevel.setArrayIndexOnJsonPointer();
        }

        levelStack.push(newJsonLevel);
    }
988772
View getViewWithKey(String key) {
        if (key == null) {
            throw new IllegalArgumentException("A key must be specified.");
        }

        Set<View> views = new HashSet<>();
        views.addAll(systemLandscapeViews);
        views.addAll(systemContextViews);
        views.addAll(containerViews);
        views.addAll(componentViews);
        views.addAll(dynamicViews);
        views.addAll(deploymentViews);

        return views.stream().filter(v -> key.equals(v.getKey())).findFirst().orElse(null);
    }
441322
private static JsonNode toJson(AggregatedHttpMessage res, @Nullable JsonNodeType expectedNodeType) {
        final String content = toString(res);
        final JsonNode node;
        try {
            node = Jackson.readTree(content);
        } catch (JsonParseException e) {
            throw new CentralDogmaException("failed to parse the response JSON", e);
        }

        if (expectedNodeType != null && node.getNodeType() != expectedNodeType) {
            throw new CentralDogmaException(
                    "invalid server response; expected: " + expectedNodeType +
                    ", actual: " + node.getNodeType() + ", content: " + content);
        }
        return node;
    }
463116
protected IModel<String> newIModel(final String key)
	{
		return ResourceModelFactory
			.newResourceModel(ResourceBundleKey.builder().key(key).defaultValue("").build(), this);
	}