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

📄 genericbeaninfo.java

📁 SWING的界面UI包 SWING的界面UI包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }
    }

    public PropertyDescriptor[] getPropertyDescriptors() {
        if (property_descriptor == null) {
            try {
                ArrayList<PropertyDescriptor> properties = getDeclaredProperties();

                if (properties == null) {
                    return null;
                }

                Class superClass = beanDescriptor.getBeanClass().getSuperclass();
                BeanInfo superBeanInfo = Introspector.getBeanInfo(superClass);
                PropertyDescriptor[] superPropertyDescriptors = superBeanInfo.getPropertyDescriptors();
                ArrayList<PropertyDescriptor> additional = new ArrayList<PropertyDescriptor>();
                if (superPropertyDescriptors != null) {
                    for (PropertyDescriptor propDesc : superPropertyDescriptors) {
                        if (!existsIn(propDesc, properties)) {
                            PropertyDescriptor clone = cloneProperty(propDesc);
                            additional.add(clone);
                        }
                    }
                }
                properties.addAll(additional);
                property_descriptor = properties.toArray(new PropertyDescriptor[0]);
                if (!isabstract) 
                    initDefaultValues();
            } catch (IntrospectionException ex) {
                ex.printStackTrace();
            }
        }
        return property_descriptor;
    }

    private void initDefaultValues() {
        for (PropertyDescriptor property : property_descriptor) {

            HashMap<String, DefaultValue> defaults = new HashMap<String, DefaultValue>();
            for (String name : lnf_names) {
                defaults.put(name, new DefaultValue());
            }
            property.setValue("default-value", defaults);

            ArrayList<Element> eDefaults = (ArrayList<Element>) property.getValue("default");
            if (eDefaults == null) {
                continue;
            }
            for (Element eDefault : eDefaults) {
                String lnf = eDefault.getAttribute("lnf");
                DefaultValue dValue = defaults.get(lnf);

                String sValue = eDefault.getAttribute("value");
                String itemString = (String) property.getValue("items");
                if (!Util.isStringNull(itemString)) {
                    try {
                        ItemProvider provider = (ItemProvider) Beans.instantiate(this.getClass().getClassLoader(),
                                itemString);
                        ItemWrapper wrapper = new ItemWrapper(provider);
                        Object value = wrapper.decode(sValue);
                        dValue.setValue(value);
                    } catch (Exception ex) {
                    }
                } else {
                    Class property_class = property.getPropertyType();
                    Decoder decoder = decoders.get(property_class);
                    if (decoder != null) {
                        Object value = decoder.decode(sValue);
                        dValue.setValue(value);
                    } else if (property_class == String.class) {
                        dValue.setValue(sValue);
                    } else if (sValue.equals("null")) {
                        dValue.setValue(null);
                    }
                }
            }
        }
    }

    private boolean existsIn(PropertyDescriptor prop, ArrayList<PropertyDescriptor> props) {
        for (PropertyDescriptor desc : props) {
            if (prop.getName().equals(desc.getName())) {
                return true;
            }

        }
        return false;
    }
    private PropertyDescriptor[] property_descriptor;

    protected ArrayList<PropertyDescriptor> getDeclaredProperties() {
        PropertyDesc[] propertyNames = getDeclaredPropertyNames();

        if (propertyNames == null) {
            return null;
        }

        ArrayList<PropertyDescriptor> properties = new ArrayList<PropertyDescriptor>();

        for (PropertyDesc prop_desc : propertyNames) {
            String propertyName = prop_desc.getPropertyName();
            String pEditorClassname = prop_desc.getPropertyEditor();
            Class beanClass = beanDescriptor.getBeanClass();

            try {
                PropertyDescriptor prop = new PropertyDescriptor(propertyName, beanClass);
                prop.setValue("bean-class", beanClass);
                if (pEditorClassname != null) {
                    setPropertyEditorClass(pEditorClassname, prop);
                }

                String description = prop_desc.getProperties().getProperty("description");
                if (!Util.isStringNull(description)) {
                    prop.setShortDescription(description);
                }

                ArrayList<Element> defaults = prop_desc.getDefaults();
                if (defaults != null) {
                    prop.setValue("default", defaults);
                }

                Properties props = prop_desc.getProperties();
                Enumeration names = props.propertyNames();

                while (names.hasMoreElements()) {
                    String key = (String) names.nextElement();
                    prop.setValue(key, props.get(key));
                }

                properties.add(prop);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

        return properties;
    }

    private void setPropertyEditorClass(String pEditorClassname, PropertyDescriptor prop) {
        try {
            Class editorClass = Class.forName(pEditorClassname);
            prop.setPropertyEditorClass(editorClass);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    protected abstract Class getBeanClass();

    private PropertyDesc[] getDeclaredPropertyNames() {
        BeanInfoDesc desc = getBeanInfoDesc(beanClass);

        if (desc == null) {
            return null;
        }

        return desc.getProperties();
    }

    private static Properties parseProperties(Element eProperty) {
        NamedNodeMap map = eProperty.getAttributes();
        Properties properties = new Properties();

        if ((map != null) && (map.getLength() > 0)) {
            for (int i = 0; i <
                    map.getLength(); i++) {
                Node node = map.item(i);
                properties.put(node.getNodeName(), node.getNodeValue());
            }

        }

        return properties;
    }

    private static class PropertyDesc {

        private String propertyName;
        private String propertyEditor;
        private Properties properties;
        private ArrayList<Element> defaults;

        public PropertyDesc() {
        }

        public String getPropertyName() {
            return propertyName;
        }

        public void setPropertyName(String propertyName) {
            this.propertyName = propertyName;
        }

        public String getPropertyEditor() {
            return propertyEditor;
        }

        public void setPropertyEditor(String propertyEditor) {
            this.propertyEditor = propertyEditor;
        }

        public Properties getProperties() {
            return properties;
        }

        public void setProperties(Properties properties) {
            this.properties = properties;
        }

        public ArrayList<Element> getDefaults() {
            return defaults;
        }

        public void setDefaults(ArrayList<Element> defaults) {
            this.defaults = defaults;
        }
    }

    private static class BeanInfoDesc {

        private String classname;
        private String resourceName;
        private PropertyDesc[] properties;
        private Properties beanProperties;

        public BeanInfoDesc() {
        }

        public String getClassname() {
            return classname;
        }

        public void setClassname(String classname) {
            this.classname = classname;
        }

        public PropertyDesc[] getProperties() {
            return properties;
        }

        public void setProperties(PropertyDesc[] propertyNames) {
            this.properties = propertyNames;
        }

        public String getResourceName() {
            return resourceName;
        }

        public void setResourceName(String resourceName) {
            this.resourceName = resourceName;
        }

        public Properties getBeanProperties() {
            return beanProperties;
        }

        public void setBeanProperties(Properties beanProperties) {
            this.beanProperties = beanProperties;
        }
    }
}

⌨️ 快捷键说明

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