⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objectmbean.java

📁 mina是以Java实现的一个开源的网络程序框架
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                if (!writable) {            if (Collection.class.isAssignableFrom(attrType) ||                    Map.class.isAssignableFrom(attrType)) {                if (List.class.isAssignableFrom(attrType)) {                    return List.class;                }                if (Set.class.isAssignableFrom(attrType)) {                    return Set.class;                }                if (Map.class.isAssignableFrom(attrType)) {                    return Map.class;                }                return Collection.class;            }                        if (attrType.isPrimitive() ||                    Date.class.isAssignableFrom(attrType) ||                    Boolean.class.isAssignableFrom(attrType) ||                    Character.class.isAssignableFrom(attrType) ||                    Number.class.isAssignableFrom(attrType)) {                if (attrName == null || !attrName.endsWith("InMillis") ||                        !propertyDescriptors.containsKey(                                attrName.substring(0, attrName.length() - 8))) {                    return attrType;                }            }        }                return String.class;    }    private Object convertValue(Class<?> type, String attrName, Object v, boolean writable) {        if (v == null) {            return null;        }                if (attrName != null && v instanceof Long) {            if (attrName.endsWith("Time") &&                    attrName.indexOf("Total") < 0 &&                    attrName.indexOf("Min") < 0 &&                    attrName.indexOf("Max") < 0 &&                    attrName.indexOf("Avg") < 0 &&                    attrName.indexOf("Average") < 0 &&                    !propertyDescriptors.containsKey(attrName + "InMillis")) {                long time = (Long) v;                if (time <= 0) {                    return null;                }                System.out.println("Converted to date");                return new Date((Long) v);            }        }        if (v instanceof IoSessionDataStructureFactory ||            v instanceof IoHandler) {            return v.getClass().getName();        }                if (v instanceof IoFilterChainBuilder) {            Map<String, String> filterMapping = new LinkedHashMap<String, String>();            if (v instanceof DefaultIoFilterChainBuilder) {                for (IoFilterChain.Entry e: ((DefaultIoFilterChainBuilder) v).getAll()) {                    filterMapping.put(e.getName(), e.getFilter().getClass().getName());                }            } else {                filterMapping.put("Unknown builder type", v.getClass().getName());            }            return filterMapping;        }            if (v instanceof IoFilterChain) {            Map<String, String> filterMapping = new LinkedHashMap<String, String>();            for (IoFilterChain.Entry e: ((IoFilterChain) v).getAll()) {                filterMapping.put(e.getName(), e.getFilter().getClass().getName());            }            return filterMapping;        }                if (!writable) {            if (v instanceof Collection || v instanceof Map) {                if (v instanceof List) {                    return convertCollection(v, new ArrayList<Object>());                }                if (v instanceof Set) {                    return convertCollection(v, new LinkedHashSet<Object>());                }                if (v instanceof Map) {                    return convertCollection(v, new LinkedHashMap<Object, Object>());                }                return convertCollection(v, new ArrayList<Object>());            }                        if (v instanceof Date ||                    v instanceof Boolean ||                    v instanceof Character ||                    v instanceof Number) {                if (attrName == null || !attrName.endsWith("InMillis") ||                        !propertyDescriptors.containsKey(                                attrName.substring(0, attrName.length() - 8))) {                    return v;                }            }        }                PropertyEditor editor = getPropertyEditor(type, attrName, v.getClass());        if (editor != null) {            editor.setValue(v);            return editor.getAsText();        }                return v.toString();    }        private Object convertCollection(Object src, Collection<Object> dst) {        Collection<?> srcCol = (Collection<?>) src;        for (Object e: srcCol) {            Object convertedValue = convertValue(dst.getClass(), "element", e, false);            if (e != null && convertedValue == null) {                convertedValue = e.toString();            }            dst.add(convertedValue);        }        return dst;    }    private Object convertCollection(Object src, Map<Object, Object> dst) {        Map<?, ?> srcCol = (Map<?, ?>) src;        for (Map.Entry<?, ?> e: srcCol.entrySet()) {            Object convertedKey = convertValue(dst.getClass(), "key", e.getKey(), false);            Object convertedValue = convertValue(dst.getClass(), "value", e.getValue(), false);            if (e.getKey() != null && convertedKey == null) {                convertedKey = e.getKey().toString();            }            if (e.getValue() != null && convertedValue == null) {                convertedKey = e.getValue().toString();            }            dst.put(convertedKey, convertedValue);        }        return dst;    }    private void throwMBeanException(Throwable e) throws MBeanException {        if (e instanceof OgnlException) {            OgnlException ognle = (OgnlException) e;            if (ognle.getReason() != null) {                throwMBeanException(ognle.getReason());            } else {                String message = ognle.getMessage();                if (e instanceof NoSuchPropertyException) {                    message = "No such property: " + message;                } else if (e instanceof ExpressionSyntaxException) {                    message = "Illegal expression syntax: " + message;                } else if (e instanceof InappropriateExpressionException) {                    message = "Inappropriate expression: " + message;                }                e = new IllegalArgumentException(ognle.getMessage());                e.setStackTrace(ognle.getStackTrace());            }        }        if (e instanceof InvocationTargetException) {            throwMBeanException(e.getCause());        }                logger.warn("Unexpected exception.", e);        if (e.getClass().getPackage().getName().matches("javax?\\..+")) {            if (e instanceof Exception) {                throw new MBeanException((Exception) e, e.getMessage());            } else {                throw new MBeanException(                        new RuntimeException(e), e.getMessage());            }        }                throw new MBeanException(new RuntimeException(                e.getClass().getName() + ": " + e.getMessage()),                e.getMessage());    }    protected Object getAttribute0(String fqan) throws Exception {        throw new AttributeNotFoundException(fqan);    }    @SuppressWarnings("unused")    protected void setAttribute0(String attrName, Object attrValue) throws Exception {        throw new AttributeNotFoundException(attrName);    }    @SuppressWarnings("unused")    protected Object invoke0(String name, Object params[], String signature[]) throws Exception {        throw new NoSuchMethodException();    }    protected boolean isReadable(Class<?> type, String attrName) {        if (IoService.class.isAssignableFrom(type) && attrName.equals("filterChain")) {            return false;        }        if (IoService.class.isAssignableFrom(type) && attrName.equals("localAddress")) {            return false;        }        if (IoService.class.isAssignableFrom(type) && attrName.equals("defaultLocalAddress")) {            return false;        }        if (IoSession.class.isAssignableFrom(type) && attrName.equals("attachment")) {            return false;        }        if (IoSession.class.isAssignableFrom(type) && attrName.equals("attributeKeys")) {            return false;        }        if (IoSession.class.isAssignableFrom(type) && attrName.equals("closeFuture")) {            return false;        }                if (ThreadPoolExecutor.class.isAssignableFrom(type) && attrName.equals("queue")) {            return false;        }        return true;    }        protected boolean isWritable(Class<?> type, String attrName) {        if (IoService.class.isAssignableFrom(type) && attrName.startsWith("defaultLocalAddress")) {            return true;        }        return false;    }        @SuppressWarnings("unused")    protected Class<?> getElementType(Class<?> type, String attrName) {        if (transportMetadata != null &&                IoAcceptor.class.isAssignableFrom(type) &&                "defaultLocalAddresses".equals(attrName)) {            return transportMetadata.getAddressType();        }        return String.class;    }    @SuppressWarnings("unused")    protected Class<?> getMapKeyType(Class<?> type, String attrName) {        return String.class;    }    @SuppressWarnings("unused")    protected Class<?> getMapValueType(Class<?> type, String attrName) {        return String.class;    }    protected boolean isExpandable(Class<?> type, String attrName) {        if (IoService.class.isAssignableFrom(type) && attrName.equals("sessionConfig")) {            return true;        }        if (IoService.class.isAssignableFrom(type) && attrName.equals("transportMetadata")) {            return true;        }        if (IoSession.class.isAssignableFrom(type) && attrName.equals("config")) {            return true;        }        if (IoSession.class.isAssignableFrom(type) && attrName.equals("transportMetadata")) {            return true;        }        if (ExecutorFilter.class.isAssignableFrom(type)) {            if (attrName.equals("executor")) {                return true;            }        }        if (ThreadPoolExecutor.class.isAssignableFrom(type)) {            if (attrName.equals("queueHandler")) {                return true;            }        }        return false;    }        @SuppressWarnings("unused")    protected boolean isOperation(String methodName, Class<?>[] paramTypes) {        return true;    }        @SuppressWarnings("unused")    protected void addExtraAttributes(List<ModelMBeanAttributeInfo> attributes) {}        @SuppressWarnings("unused")    protected void addExtraOperations(List<ModelMBeanOperationInfo> operations) {}    protected PropertyEditor getPropertyEditor(Class<?> type, String attrName, Class<?> attrType) {        if (type == null) {            throw new NullPointerException("type");        }        if (attrName == null) {            throw new NullPointerException("attrName");        }                if (transportMetadata != null && attrType == SocketAddress.class) {            attrType = transportMetadata.getAddressType();        }        if (attrName != null && (attrType == Long.class || attrType == long.class)) {            if (attrName.endsWith("Time") &&                    attrName.indexOf("Total") < 0 &&                    attrName.indexOf("Min") < 0 &&                    attrName.indexOf("Max") < 0 &&                    attrName.indexOf("Avg") < 0 &&                    attrName.indexOf("Average") < 0 &&                    !propertyDescriptors.containsKey(attrName + "InMillis")) {                return PropertyEditorFactory.getInstance(Date.class);            }                        if (attrName.equals("id")) {                return PropertyEditorFactory.getInstance(String.class);            }        }                if (type != null) {            if (List.class.isAssignableFrom(attrType)) {                return new ListEditor(getElementType(type, attrName));            }            if (Set.class.isAssignableFrom(attrType)) {                return new SetEditor(getElementType(type, attrName));            }            if (Collection.class.isAssignableFrom(attrType)) {                return new CollectionEditor(getElementType(type, attrName));            }            if (Map.class.isAssignableFrom(attrType)) {                return new MapEditor(                        getMapKeyType(type, attrName),                        getMapValueType(type, attrName));            }        }                return PropertyEditorFactory.getInstance(attrType);    }        private class OgnlTypeConverter extends PropertyTypeConverter {        @Override        protected PropertyEditor getPropertyEditor(                Class<?> type, String attrName, Class<?> attrType) {            return ObjectMBean.this.getPropertyEditor(type, attrName, attrType);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -