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

📄 nodeservice.java

📁 一个“对象--XML 映射”(Object-Xml Mapping) 的类库。 它的目的是帮助开发者方便、快速的从XML 文件构建出Java 对象
💻 JAVA
字号:
/**
 * @author 沈东良 Edward Shen<a href="mailto:shendl_s@hotmail.com">shendl_s@hotmail.com</a>
 * 2007-8-7 上午11:07:10
 */
package net.sf.oxmled.service;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;

import net.sf.oxmled.model.INode;
import net.sf.oxmled.model.Node;
import net.sf.oxmled.xml.util.dom4j.IXmlUtil;
import net.sf.oxmled.xml.util.dom4j.XmlUtil;

/**
 * @author 沈东良 Edward Shen<a href="mailto:shendl_s@hotmail.com">shendl_s@hotmail.com</a>
 * 2007-8-7 上午11:07:10
 *保存 Node操作的静态方法的助手类。
 *   类后加上s作为后缀,表示这个类保存静态方法。 其默认构造器为private,阻止生成该类的实例。
 *   这个层次的类只和xmlUtil有关,没有任何XML操作组件的相关代码。
 */
public class NodeService implements INodeService {

	private IXmlUtil xmlUtil=null;
	
	/**
	 * @return the xmlUtil
	 */
	public IXmlUtil getXmlUtil() {
		synchronized(this){
			if(this.xmlUtil==null){
				this.xmlUtil=new XmlUtil();
			}
			
			
		}
		
		return xmlUtil;
	}

	/**
	 * @param xmlUtil the xmlUtil to set
	 */
	public void setXmlUtil(IXmlUtil xmlUtil) {
		this.xmlUtil = xmlUtil;
	}

	/**
	 * 
	 */
	public NodeService() {
		/*
		 *
		 */
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		/*
		 *
		 */

	}
	/* (non-Javadoc)
	 * @see net.sf.oxmled.service.INodeService#loadXmlFile(java.net.URL)
	 */
	public INode loadXmlFile(URL url) throws Exception{
	
		
		return this.getXmlUtil().loadXmlFile(url);
	
	}
	
	/* (non-Javadoc)
	 * @see net.sf.oxmled.service.INodeService#loadXmlFileToString(java.net.URL)
	 */
	public String loadXmlFileToString(URL url) throws Exception{
		INode node=this.loadXmlFile(url);
		return node.toString();
		
	}

	/* (non-Javadoc)
	 * @see net.sf.oxmled.service.INodeService#getNodes(net.sf.oxmled.model.INode, java.lang.String, java.lang.String)
	 */
	public  List<Node> getNodes(INode rootNode, String attributeName,
			String attributeValue) {
		List<Node> results = new ArrayList<Node>();
		Iterator childIt = rootNode.getChildNodes().iterator();
		while (childIt.hasNext()) {
			/**
			 * 顶级的儿子
			 */
			this.getNodesRecursive(results, (Node) childIt.next(),
					attributeName, attributeValue);
	
		}
	
		return results;
	}

	/* (non-Javadoc)
	 * @see net.sf.oxmled.service.INodeService#getNodesRecursive(java.util.List, net.sf.oxmled.model.Node, java.lang.String, java.lang.String)
	 */
	public  void getNodesRecursive(List<Node> results, Node node,
			String attributeName, String attributeValue) {
		/**
		 * 儿孙级的
		 * 
		 * 
		 */
		if (((String) node.getAttributes().get(attributeName))
				.equalsIgnoreCase(attributeValue)) {
			results.add(node);
	
		}
		Iterator childIt = node.getChildNodes().iterator();
		while (childIt.hasNext()) {
			/**
			 * 顶级的儿子
			 */
			this.getNodesRecursive(results, (Node) childIt.next(),
					attributeName, attributeValue);
	
		}
	
	}

	/* (non-Javadoc)
	 * @see net.sf.oxmled.service.INodeService#getChild(net.sf.oxmled.model.INode, int)
	 */
	public  INode getChild(INode parent, int index) {
		/*
		 * 
		 */
		return parent.getChildNodes().get(index);
	
	}

	/* (non-Javadoc)
	 * @see net.sf.oxmled.service.INodeService#getChildCount(net.sf.oxmled.model.INode)
	 */
	public  int getChildCount(INode parent) {
		/*
		 * 
		 */
		return parent.getChildNodes().size();
	
	}

	/* (non-Javadoc)
	 * @see net.sf.oxmled.service.INodeService#getIndexOfChild(net.sf.oxmled.model.INode, net.sf.oxmled.model.INode)
	 */
	public  int getIndexOfChild(INode parent, INode child) {
		/*
		 * 
		 */
		return  parent.getChildNodes().indexOf(child);
	}

	@Override
	public void write(INode node, URL url) throws IOException, URISyntaxException {
		/*
		*
		*/
		this.getXmlUtil().write(node, url);
		
	}

	@Override
	public void write(INode node, String fileName) throws IOException, URISyntaxException {
		/*
		*
		*/
		this.getXmlUtil().write(node,fileName);
		
	}

	@Override
	public void writeToCompactFormat(INode node, String fileName) throws IOException {
		/*
		*
		*/
		this.getXmlUtil().writeToCompactFormat(node, fileName);
		
	}

	@Override
	public void writeToCompactFormat(INode node, URL url) throws IOException, URISyntaxException {
		/*
		*
		*/
		this.getXmlUtil().writeToCompactFormat(node, url);
	}

	@Override
	public void writeToPrettyPrint(INode node, URL url) throws IOException, URISyntaxException {
		/*
		*
		*/
		this.getXmlUtil().writeToPrettyPrint(node,url);
	}

	@Override
	public void writeToPrettyPrint(INode node, String fileName) throws IOException, URISyntaxException {
		/*
		*
		*/
		this.getXmlUtil().writeToPrettyPrint(node,fileName);
	}

}

⌨️ 快捷键说明

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