第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

獲取 mbean 屬性值樹

獲取 mbean 屬性值樹

慕碼人2483693 2023-02-23 10:22:47
我使用 JMX 從服務(wù)器獲取 mbeans 值(weblogic JMS 配置)不同的屬性有不同的返回類型:Ljavax.management.ObjectName; javax.management.ObjectName Ljava.lang.String;對于每個返回值列表的屬性,我在我的代碼中循環(huán) for/if/else。最后是非常嵌套的代碼。有更好的辦法嗎?
查看完整描述

1 回答

?
不負(fù)相思意

TA貢獻(xiàn)1777條經(jīng)驗 獲得超10個贊

我自己做。它對我有用


public static void parser(String javaxExcept, String LjavaxExcept, HashMap < String, Object > [] atrs, ObjectName ObjUrl, int ng, ObjectName[] origObjUrl) throws Exception {


    if (ng > 20) {

        System.out.println("Possibly loop detected");

        for (int t = 0; t < origObjUrl.length; t++) {

            System.out.println(origObjUrl[t]);

        }

        System.exit(1);

    }


    origObjUrl[ng] = ObjUrl;

    MBeanAttributeInfo[] attributes = (connection.getMBeanInfo(ObjUrl)).getAttributes();

    atrs[ng].put("ObjUrl", ObjUrl.toString());

    for (MBeanAttributeInfo attribute: attributes) {

        if (attribute.getType().equals("[Ljava.lang.String;")) {

            String[] Ljava = (String[]) connection.getAttribute(ObjUrl, attribute.getName());

            if (Ljava.length == 0) {

                atrs[ng].put(attribute.getName(), "null");

            } else {

                for (int p = 0; p < Ljava.length; p++) {

                    atrs[ng].put(attribute.getName(), Ljava[p]);

                }

            }

        } else if (attribute.getName().matches(".*(Password|KeyStorePass|PassPhrase|JNDIPropertiesCredential|ClearText|EncryptedValue).*")) {

            atrs[ng].put(attribute.getName(), "clear or encrypt text");

        } else if (attribute.getType().matches("java.util.Properties")) {

            Map < String, String > propmap = (Map < String, String > ) connection.getAttribute(ObjUrl, attribute.getName());

            if (attribute.getName().matches("BootProperties")) {

            propmap.put("password", "{AES} encrypt text");

            propmap.put("username", "{AES} encrypt text"); }

            atrs[ng].put(attribute.getName(), propmap);

        } else if (attribute.getType().equals("javax.management.ObjectName") && attribute.getName().matches(javaxExcept) && (connection.getAttribute(ObjUrl, attribute.getName())) != null) {

            atrs[ng].put(attribute.getName(), (connection.getAttribute(ObjUrl, attribute.getName()).toString()));

        } else if (attribute.getType().matches("java.lang.String|java.lang.Integer|java.lang.Boolean")) {

            atrs[ng].put(attribute.getName(), (connection.getAttribute(ObjUrl, attribute.getName())));

        } else if (attribute.getType().equals("javax.management.ObjectName") && (connection.getAttribute(ObjUrl, attribute.getName())) != null) {

            atrs[ng].put(attribute.getName(), attribute.getName());

            ng = ng + 1;

            atrs[ng] = new HashMap < String, Object > ();

            ObjUrl = (ObjectName) connection.getAttribute(ObjUrl, attribute.getName());

            parser(javaxExcept, LjavaxExcept, atrs, ObjUrl, ng, origObjUrl);

            atrs[ng - 1].put(attribute.getName(), atrs[ng]);

            ng = ng - 1;

            ObjUrl = origObjUrl[ng];

        } else if (attribute.getType().equals("[Ljavax.management.ObjectName;") && attribute.getName().matches(LjavaxExcept)) {

            ObjectName[] Ljavax = (ObjectName[]) connection.getAttribute(ObjUrl, attribute.getName());

            atrs[ng].put(attribute.getName(), attribute.getName());

            String[] Ljavaxarray = new String[Ljavax.length];

            for (int j = 0; j < Ljavax.length; j++) {

                Ljavaxarray[j] = Ljavax[j].toString();

              }

            atrs[ng].put(attribute.getName(), Ljavaxarray);

        } else if (attribute.getType().equals("javax.management.openmbean.ArrayType")) {

            CompositeData[] compdata = (CompositeData[]) connection.getAttribute(ObjUrl, attribute.getName());

            String[] kvcompdata = new String[compdata.length];

            int l = 0;

            for (CompositeData kv: compdata) {

                kvcompdata[l] = kv.get("DisplayName").toString();

                l = l + 1;

            }

            atrs[ng].put(attribute.getName(), kvcompdata);

        } else if (attribute.getType().equals("[Ljavax.management.ObjectName;")) {

            ObjectName[] Ljavax = (ObjectName[]) connection.getAttribute(ObjUrl, attribute.getName());

            atrs[ng].put(attribute.getName(), attribute.getName());

            HashMap < String, Object > Ljavaxmap = new HashMap < String, Object > ();

            for (int j = 0; j < Ljavax.length; j++) {

                ng = ng + 1;

                atrs[ng] = new HashMap < String, Object > ();

                ObjUrl = Ljavax[j];

                parser(javaxExcept, LjavaxExcept, atrs, ObjUrl, ng, origObjUrl);

                boolean success = false;

                String Ljavaxaname = new String();

                try {

                    Ljavaxaname = (connection.getAttribute(Ljavax[j], "Name")).toString();

                    success = true;

                } catch (AttributeNotFoundException e) {}

                if (success) {

                    Ljavaxaname = (connection.getAttribute(Ljavax[j], "Name")).toString();

                } else {

                    Ljavaxaname = (connection.getAttribute(Ljavax[j], "Key")).toString();

                }

                Ljavaxmap.put(Ljavaxaname, atrs[ng]);

                ng = ng - 1;

            }

            atrs[ng].put(attribute.getName(), Ljavaxmap);

            ObjUrl = origObjUrl[ng];

        } else {

            if (connection.getAttribute(ObjUrl, attribute.getName()) == null) {

                atrs[ng].put(attribute.getName(), "null");

            } else {

                atrs[ng].put(attribute.getName(), (connection.getAttribute(ObjUrl, attribute.getName()).toString()));

            }

        }

    }

}


查看完整回答
反對 回復(fù) 2023-02-23
  • 1 回答
  • 0 關(guān)注
  • 117 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號