package com.nis.util; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.commons.collections.map.CaseInsensitiveMap; import org.apache.log4j.Logger; import org.dom4j.Attribute; import org.dom4j.Element; import org.dom4j.Node; import org.dom4j.io.SAXReader; public class ServiceConfigTemplateUtil { private Logger logger = Logger.getLogger(getClass()); private Node root; /** * 配置文件内容 * @return */ public ServiceConfigTemplateUtil(){ SAXReader reader = new SAXReader(); org.dom4j.Document document = null; String configPath = "/service/service_config.xml"; try { document = reader.read(ServiceConfigTemplateUtil.class.getResourceAsStream(configPath)); root = document.getRootElement(); } catch (Exception e) { logger.error(e.getMessage()); e.printStackTrace(); } } /** * 获取业务节点列表 * @return */ public List getServiceNodeList(){ List nodes = root.selectNodes("service"); return nodes; } /** * 获取业务列表 * @return */ public List> getServiceList(){ List> list =new ArrayList(); List elements = root.selectNodes("service"); for(Element element:elements){ Map map = new HashMap(); for(int i=0;i> getServiceList(String functionId,String serviceId){ List> list =new ArrayList(); List elements = root.selectNodes("service"); boolean flag=false; for(Element element:elements){ if(!StringUtil.isEmpty(functionId) || !StringUtil.isEmpty(serviceId) ) { flag=false; String serviceIdC=element.attributeValue("id"); String functionIdC=element.attributeValue("functionId"); if(!StringUtil.isEmpty(functionId) && !StringUtil.isEmpty(serviceId)) { if(serviceIdC.equals(serviceId) && functionIdC.equals(functionId)) { flag=true; } }else { if(!StringUtil.isEmpty(serviceId) && serviceIdC.equals(serviceId) ) { flag=true; } if(!StringUtil.isEmpty(functionId) && functionIdC.equals(functionId) ) { flag=true; } } if(flag) { Map map = new HashMap(); for(int i=0;i map = new HashMap(); for(int i=0;i> getServiceCfgList(Element serviceNode){ List> list = new ArrayList(); List elements = serviceNode.selectNodes("serviceCfg"); for(Element element:elements){ Map map = new HashMap(); for(int i=0;i> getUserRegionList(Element serviceNode){ List> list = new ArrayList(); List elements = serviceNode.selectNodes("userRegion"); for(Element element:elements){ Map map = new HashMap(); for(int i=0;i elements = root.selectNodes(tag); for(Element element:elements){ list.add(element.attributeValue(attribute)); } return list; } public static void main(String[] args) { try { ServiceConfigTemplateUtil serviceTemplate = new ServiceConfigTemplateUtil(); List> list = serviceTemplate.getServiceList("","128"); for(Map map :list){ System.out.println("业务配置:"+map.get("id")+","+map.get("functionId")+","+map.get("serviceType")+","+map.get("tableName")); List> cfgList = (List>) map.get("cfgList"); List> userRegionList = (List>) map.get("userRegionList"); if(cfgList!=null){ for(Map m:cfgList){ System.out.println("cfgList:"+m.get("cfgType")+","+m.get("tableName")+","+m.get("groupReuse")+","+m.get("groupId")); } } if(userRegionList!=null){ for(Map n:userRegionList){ System.out.println("userRegionList:"+n.get("regionKey")+","+n.get("regionColumn")+","+n.get("handleType")); } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }