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

📄 objectmbean.java

📁 mina是以Java实现的一个开源的网络程序框架
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            return getAttributes(names);    }    public final void setManagedResource(Object resource, String type)            throws InstanceNotFoundException, InvalidTargetObjectTypeException,            MBeanException {        throw new RuntimeOperationsException(new UnsupportedOperationException());    }    public final void setModelMBeanInfo(ModelMBeanInfo info) throws MBeanException {        throw new RuntimeOperationsException(new UnsupportedOperationException());    }    @Override    public final String toString() {        return source.toString();    }    public void addAttributeChangeNotificationListener(            NotificationListener listener, String name, Object handback) {    }    public void removeAttributeChangeNotificationListener(            NotificationListener listener, String name)            throws ListenerNotFoundException {    }    public void sendAttributeChangeNotification(            AttributeChangeNotification notification) throws MBeanException {        throw new RuntimeOperationsException(new UnsupportedOperationException());    }    public void sendAttributeChangeNotification(Attribute oldValue,            Attribute newValue) throws MBeanException {        throw new RuntimeOperationsException(new UnsupportedOperationException());    }    public void sendNotification(Notification notification)            throws MBeanException {        throw new RuntimeOperationsException(new UnsupportedOperationException());    }    public void sendNotification(String message) throws MBeanException {        throw new RuntimeOperationsException(new UnsupportedOperationException());    }    public void addNotificationListener(NotificationListener listener,            NotificationFilter filter, Object handback)            throws IllegalArgumentException {    }    public MBeanNotificationInfo[] getNotificationInfo() {        return new MBeanNotificationInfo[0];    }    public void removeNotificationListener(NotificationListener listener)            throws ListenerNotFoundException {    }    public void load() throws InstanceNotFoundException, MBeanException,            RuntimeOperationsException {        throw new RuntimeOperationsException(new UnsupportedOperationException());    }    public void store() throws InstanceNotFoundException, MBeanException,            RuntimeOperationsException {        throw new RuntimeOperationsException(new UnsupportedOperationException());    }    public final ObjectName preRegister(MBeanServer server, ObjectName name)            throws Exception {        this.server = server;        this.name = name;        return name;    }    public final void postRegister(Boolean registrationDone) {        if (registrationDone) {            sources.put(name, source);        }    }    public final void preDeregister() throws Exception {    }    public final void postDeregister() {        sources.remove(name);        this.server = null;        this.name = null;    }    private MBeanInfo createModelMBeanInfo(T source) {        String className = source.getClass().getName();        String description = "";                ModelMBeanConstructorInfo[] constructors = new ModelMBeanConstructorInfo[0];        ModelMBeanNotificationInfo[] notifications = new ModelMBeanNotificationInfo[0];                List<ModelMBeanAttributeInfo> attributes = new ArrayList<ModelMBeanAttributeInfo>();        List<ModelMBeanOperationInfo> operations = new ArrayList<ModelMBeanOperationInfo>();                addAttributes(attributes, source);        addExtraAttributes(attributes);                addOperations(operations, source);        addExtraOperations(operations);        operations.add(new ModelMBeanOperationInfo(                "unregisterMBean", "unregisterMBean",                new MBeanParameterInfo[0], void.class.getName(),                 ModelMBeanOperationInfo.ACTION));        return new ModelMBeanInfoSupport(                className, description,                attributes.toArray(new ModelMBeanAttributeInfo[attributes.size()]),                constructors,                operations.toArray(new ModelMBeanOperationInfo[operations.size()]),                notifications);    }        private void addAttributes(            List<ModelMBeanAttributeInfo> attributes, Object object) {        addAttributes(attributes, object, object.getClass(), "");    }    private void addAttributes(            List<ModelMBeanAttributeInfo> attributes,            Object object, Class<?> type, String prefix) {                PropertyDescriptor[] pdescs;        try {            pdescs = Introspector.getBeanInfo(type).getPropertyDescriptors();        } catch (IntrospectionException e) {            return;        }        for (PropertyDescriptor pdesc: pdescs) {            // Ignore a write-only property.            if (pdesc.getReadMethod() == null) {                continue;            }                        // Ignore unmanageable property.            String attrName = pdesc.getName();            Class<?> attrType = pdesc.getPropertyType();            if (attrName.equals("class")) {                continue;            }            if (!isReadable(type, attrName)) {                continue;            }                        // Expand if possible.            if (isExpandable(type, attrName)) {                expandAttribute(attributes, object, prefix, pdesc);                continue;            }                // Ordinary property.            String fqan = prefix + attrName;            boolean writable = isWritable(type, pdesc);            attributes.add(new ModelMBeanAttributeInfo(                    fqan, convertType(                            object.getClass(), attrName, attrType, writable).getName(),                    pdesc.getShortDescription(), true, writable, false));                        propertyDescriptors.put(fqan, pdesc);        }    }    private boolean isWritable(Class<?> type, PropertyDescriptor pdesc) {        if (type == null) {            throw new NullPointerException("type");        }        if (pdesc == null) {            return false;        }        String attrName = pdesc.getName();        Class<?> attrType = pdesc.getPropertyType();        boolean writable = pdesc.getWriteMethod() != null || isWritable(type, attrName);        if (getPropertyEditor(type, attrName, attrType) == null) {            writable = false;        }        return writable;    }    private void expandAttribute(            List<ModelMBeanAttributeInfo> attributes,            Object object, String prefix, PropertyDescriptor pdesc) {        Object property;        String attrName = pdesc.getName();        try {            property = getAttribute(object, attrName, pdesc.getPropertyType());        } catch (Exception e) {            logger.debug("Unexpected exception.", e);            return;        }        if (property == null) {            return;        }        addAttributes(                attributes,                property, property.getClass(),                prefix + attrName + '.');    }    private void addOperations(            List<ModelMBeanOperationInfo> operations, Object object) {            for (Method m: object.getClass().getMethods()) {            String mname = m.getName();                        // Ignore getters and setters.            if (mname.startsWith("is") || mname.startsWith("get") ||                mname.startsWith("set")) {                continue;            }                        // Ignore Object methods.            if (mname.matches(                    "(wait|notify|notifyAll|toString|equals|compareTo|hashCode|clone)")) {                continue;            }                        // Ignore other user-defined non-operations.            if (!isOperation(mname, m.getParameterTypes())) {                continue;            }                        List<MBeanParameterInfo> signature = new ArrayList<MBeanParameterInfo>();            int i = 1;            for (Class<?> paramType: m.getParameterTypes()) {                String paramName = "p" + (i ++);                if (getPropertyEditor(source.getClass(), paramName, paramType) == null) {                    continue;                }                signature.add(new MBeanParameterInfo(                        paramName, convertType(                                null, null, paramType, true).getName(),                        paramName));            }                Class<?> returnType = convertType(null, null, m.getReturnType(), false);            operations.add(new ModelMBeanOperationInfo(                    m.getName(), m.getName(),                    signature.toArray(new MBeanParameterInfo[signature.size()]),                    returnType.getName(), ModelMBeanOperationInfo.ACTION));        }    }    private Object getParent(String fqan) throws OgnlException {        Object parent;        int dotIndex = fqan.lastIndexOf('.');        if (dotIndex < 0) {            parent = source;        } else {            parent = getAttribute(source, fqan.substring(0, dotIndex), null);        }        return parent;    }    private String getLeafAttributeName(String fqan) {        int dotIndex = fqan.lastIndexOf('.');        if (dotIndex < 0) {            return fqan;        }        return fqan.substring(dotIndex + 1);    }    private Class<?> getAttributeClass(String signature)            throws ClassNotFoundException {        if (signature.equals(Boolean.TYPE.getName())) {            return Boolean.TYPE;        }        if (signature.equals(Byte.TYPE.getName())) {            return Byte.TYPE;        }        if (signature.equals(Character.TYPE.getName())) {            return Character.TYPE;        }        if (signature.equals(Double.TYPE.getName())) {            return Double.TYPE;        }        if (signature.equals(Float.TYPE.getName())) {            return Float.TYPE;        }        if (signature.equals(Integer.TYPE.getName())) {            return Integer.TYPE;        }        if (signature.equals(Long.TYPE.getName())) {            return Long.TYPE;        }        if (signature.equals(Short.TYPE.getName())) {            return Short.TYPE;        }            try {            ClassLoader cl = Thread.currentThread().getContextClassLoader();            if (cl != null) {                return cl.loadClass(signature);            }        } catch (ClassNotFoundException e) {        }                return Class.forName(signature);    }    private Object getAttribute(Object object, String fqan, Class<?> attrType) throws OgnlException {        Object property;        OgnlContext ctx = (OgnlContext) Ognl.createDefaultContext(object);        ctx.setTypeConverter(new OgnlTypeConverter());        if (attrType == null) {            property = Ognl.getValue(fqan, ctx, object);        } else {            property = Ognl.getValue(fqan, ctx, object, attrType);        }        return property;    }        @SuppressWarnings("unused")    private Class<?> convertType(Class<?> type, String attrName, Class<?> attrType, boolean writable) {        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 Date.class;            }        }        if (IoFilterChain.class.isAssignableFrom(attrType)) {            return Map.class;        }                if (IoFilterChainBuilder.class.isAssignableFrom(attrType)) {            return Map.class;        }

⌨️ 快捷键说明

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