From f5d7b444ffccf2872d60da04612263a1ffd61d13 Mon Sep 17 00:00:00 2001 From: Kris De Volder Date: Thu, 18 Jan 2018 10:10:52 -0800 Subject: [PATCH] Deal better with multiple contexts in live beans model parse for boot 2.0 --- .../boot/app/cli/livebean/LiveBeansModel.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/livebean/LiveBeansModel.java b/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/livebean/LiveBeansModel.java index 3f6d397d9..0f70a916d 100644 --- a/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/livebean/LiveBeansModel.java +++ b/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/livebean/LiveBeansModel.java @@ -117,26 +117,22 @@ public class LiveBeansModel { public LiveBeansModel parse(String json) throws Exception { Builder model = LiveBeansModel.builder(); JSONObject mainObject = new JSONObject(json); - JSONObject beansObject = getBeans(mainObject); - for (String id : beansObject.keySet()) { - JSONObject beanObject = beansObject.getJSONObject(id); - LiveBean bean = parseBean(id, beanObject); - if (bean!=null) { - model.add(bean); + mainObject = mainObject.getJSONObject("contexts"); + for (String contextId : mainObject.keySet()) { + JSONObject contextObject = mainObject.getJSONObject(contextId); + JSONObject beansObject = contextObject.getJSONObject("beans"); + for (String id : beansObject.keySet()) { + JSONObject beanObject = beansObject.getJSONObject(id); + LiveBean bean = parseBean(id, contextId, beanObject); + if (bean!=null) { + model.add(bean); + } } } return model.build(); } - private JSONObject getBeans(JSONObject mainObject) { - JSONObject beans = mainObject.optJSONObject("beans"); - if (beans==null) { - beans = mainObject.getJSONObject("contexts").getJSONObject("application").getJSONObject("beans"); - } - return beans; - } - - private LiveBean parseBean(String id, JSONObject beansJSON) { + private LiveBean parseBean(String id, String contextId, JSONObject beansJSON) { String type = beansJSON.optString("type"); String scope = beansJSON.optString("scope"); String resource = beansJSON.optString("resource");