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

📄 tableenginefactory.java

📁 本系统有十分强大的功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        
        NodeList nodes = node.getChildNodes();
        for(int i=0; i<nodes.getLength(); i++) {
            if(nodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
                if("format".equals(nodes.item(i).getNodeName())) {
                    Formatter format = parseFormat(nodes.item(i));
                    if(format == null) {
                        format = new DefaultFormatter();
                    }
                    property.setFormatter(format);
                } else if("search".equals(nodes.item(i).getNodeName())) {
                    property.setSearch(parseSearch(nodes.item(i)));
                }

            }
        }
        
        return property;
    }
    
    private Formatter parseFormat(Node node) throws TableEngineException {
        Formatter format = null;

        NamedNodeMap attributes = node.getAttributes();
        for(int i=0; i<attributes.getLength(); i++) {
            Node attributeNode = attributes.item(i);
            if(attributeNode.getNodeType() == Node.ATTRIBUTE_NODE) {
                String name = attributeNode.getNodeName();
                if("type".equals(name)) {
                    if("date".equals(attributeNode.getNodeValue())) {
                        format = new DateFormatter(attributes.getNamedItem("formatKey").getNodeValue());
                    } else if("enum".equals(attributeNode.getNodeValue())) {
                        try {
                            EnumFormatter enumFormat = new EnumFormatter((Class<? extends Enum>)Class.forName(attributes.getNamedItem("class").getNodeValue()));
                            NodeList nodes = node.getChildNodes();
                            for(int j=0; j<nodes.getLength(); j++) {
                                if(nodes.item(j).getNodeType() == Node.ELEMENT_NODE) {
                                    if("value".equals(nodes.item(j).getNodeName())) {
                                        parseValue(enumFormat, nodes.item(j));
                                    }
                                }
                           }
                            
                           format = enumFormat;
                        } catch(ClassNotFoundException e) {
                            throw new TableEngineException("could get attribute 'class'", e);
                        }
                    } else if("string".equals(attributeNode.getNodeValue())) {
                        StringFormatter stringFormat = new StringFormatter();
                        NodeList nodes = node.getChildNodes();
                        for(int j=0; j<nodes.getLength(); j++) {
                            if(nodes.item(j).getNodeType() == Node.ELEMENT_NODE) {
                                if("value".equals(nodes.item(j).getNodeName())) {
                                    parseValue(stringFormat, nodes.item(j));
                                }
                            }
                       }
                        
                       format = stringFormat;
                    }
                }
            }
        }
        
        return format;
    }
    
    private void parseValue(EnumFormatter format, Node node) {
        Enum[] enums = format.getClazz().getEnumConstants();
        
        Enum type         = null;
        String messageKey = null;
        
        NamedNodeMap attributes = node.getAttributes();
        for(int i=0; i<attributes.getLength(); i++) {
            Node attributeNode = attributes.item(i);
            if(attributeNode.getNodeType() == Node.ATTRIBUTE_NODE) {
                String name = attributeNode.getNodeName();
                if("type".equals(name)) {
                    for(Enum e : enums) {
                        if(attributeNode.getNodeValue().equals(e.name())) {
                            type = e;
                        }
                    }
                } else if("messageKey".equals(name)) {
                    messageKey = attributeNode.getNodeValue();
                }
            }
        }
        
        format.getMessageKeys().put(type, messageKey);
    }

    private void parseValue(StringFormatter format, Node node) {
        String type       = null;
        String messageKey = null;
        
        NamedNodeMap attributes = node.getAttributes();
        for(int i=0; i<attributes.getLength(); i++) {
            Node attributeNode = attributes.item(i);
            if(attributeNode.getNodeType() == Node.ATTRIBUTE_NODE) {
                String name = attributeNode.getNodeName();
                if("type".equals(name)) {
                    type = attributeNode.getNodeValue();
                } else if("messageKey".equals(name)) {
                    messageKey = attributeNode.getNodeValue();
                }
            }
        }
        
        format.getMessageKeys().put(type, messageKey);
    }
    
    private Search parseSearch(Node node) throws TableEngineException {
        Search search = null;

        NamedNodeMap attributes = node.getAttributes();
        for(int i=0; i<attributes.getLength(); i++) {
            Node attributeNode = attributes.item(i);
            if(attributeNode.getNodeType() == Node.ATTRIBUTE_NODE) {
                String name = attributeNode.getNodeName();
                if("type".equals(name)) {
                    if("enum".equals(attributeNode.getNodeValue())) {
                        try {
                            EnumSearch enumSearch = new EnumSearch((Class<? extends Enum>)Class.forName(attributes.getNamedItem("class").getNodeValue()));
                            NodeList nodes = node.getChildNodes();
                            for(int j=0; j<nodes.getLength(); j++) {
                                if(nodes.item(j).getNodeType() == Node.ELEMENT_NODE) {
                                    if("value".equals(nodes.item(i).getNodeName())) {
                                        parseValue(enumSearch, nodes.item(j));
                                    }
                                }
                            }
                            
                            search = enumSearch;
                        } catch(ClassNotFoundException e) {
                            throw new TableEngineException("could get attribute 'class'", e);
                        }
                    } else if("text".equals(attributeNode.getNodeValue())) {
                        search = new TextSearch(attributes.getNamedItem("pattern").getNodeValue());
                    } else if("date".equals(attributeNode.getNodeValue())) {
                        search = new DateSearch(attributes.getNamedItem("formatKey").getNodeValue());
                    } else if("text.select".equals(attributeNode.getNodeValue())) {
                        TextSelectSearch textSelectSearch = new TextSelectSearch();
                        if(attributes.getNamedItem("hql") != null)
                            textSelectSearch.setHql(attributes.getNamedItem("hql").getNodeValue().equalsIgnoreCase("true") ? true : false);
                        
                        NodeList nodes = node.getChildNodes();
                        for(int j=0; j<nodes.getLength(); j++) {
                            if(nodes.item(j).getNodeType() == Node.ELEMENT_NODE) {
                                if("value".equals(nodes.item(i).getNodeName())) {
                                    parseValue(textSelectSearch, nodes.item(j));
                                }
                            }
                        }
                        
                        search = textSelectSearch;
                    } else if("list.select".equals(attributeNode.getNodeValue())) {
                        String clazz = attributes.getNamedItem("class").getNodeValue();
                        try {
                            ListSelectSearch listSelectSearch = new ListSelectSearch();
                            listSelectSearch.setClazz(Class.forName(clazz));
                            if("true".equalsIgnoreCase(attributes.getNamedItem("all").getNodeValue()))
                                listSelectSearch.setAllAvailable(true);
                            else
                                listSelectSearch.setAllAvailable(false);
                            listSelectSearch.setSearchProperty(attributes.getNamedItem("searchProperty").getNodeValue());
                            
                            search = listSelectSearch;
                        } catch(ClassNotFoundException e) {
                            throw new TableEngineException("could not create/use dao: "+clazz, e);
                        }
                    }
                }
            }
        }
        
        return search;
    }

    private void parseValue(EnumSearch search, Node node) {
        Enum[] enums = search.getClazz().getEnumConstants();
        
        Enum type         = null;
        String messageKey = null;
        boolean isDefault = false;
        
        NamedNodeMap attributes = node.getAttributes();
        for(int i=0; i<attributes.getLength(); i++) {
            Node attributeNode = attributes.item(i);
            if(attributeNode.getNodeType() == Node.ATTRIBUTE_NODE) {
                String name = attributeNode.getNodeName();
                if("type".equals(name)) {
                    for(Enum e : enums) {
                        if(attributeNode.getNodeValue().equals(e.name())) {
                            type = e;
                        }
                    }
                } else if("messageKey".equals(name)) {
                    messageKey = attributeNode.getNodeValue();
                } else if("default".equals(name)) {
                    if("true".equalsIgnoreCase(attributeNode.getNodeValue())) {
                        isDefault = true;
                    }
                }
            }
        }
        
        search.getMessageKeys().put(type, messageKey);
        if(isDefault) {
            search.setDefaultValue(type);
        }
    }

    private void parseValue(TextSelectSearch search, Node node) {
        String type       = null;
        String messageKey = null;
        String hql        = null;
        boolean isDefault = false;
        
        NamedNodeMap attributes = node.getAttributes();
        for(int i=0; i<attributes.getLength(); i++) {
            Node attributeNode = attributes.item(i);
            if(attributeNode.getNodeType() == Node.ATTRIBUTE_NODE) {
                String name = attributeNode.getNodeName();
                if("type".equals(name)) {
                    type = attributeNode.getNodeValue();
                } else if("messageKey".equals(name)) {
                    messageKey = attributeNode.getNodeValue();
                } else if("hql".equals(name) && search.isHql()) {
                    hql = attributeNode.getNodeValue();
                } else if("default".equals(name)) {
                    if("true".equalsIgnoreCase(attributeNode.getNodeValue())) {
                        isDefault = true;
                    }
                }
            }
        }
        
        search.getBeans().put(type, new TextSelectSearch.Bean(messageKey, hql));
        if(isDefault) {
            search.setDefaultValue(type);
        }
    }
}

⌨️ 快捷键说明

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