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

📄 xmlerrorsinkexporter.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
字号:
package com.esri.solutions.jitk.web.error;

import java.util.List;

import org.w3c.dom.Element;

/**
 * Exports the list of errors to an XML Document.  The XML Document
 * will have the following structure:
 * 
 * 
 * <jitk-errors count="#">
 * 	<jitk-error id="..." code="...">
 *  ... message ...
 *  </jitk-error>
 *  ...
 * </jitk-errors>
 */
public class XmlErrorSinkExporter implements IErrorSinkExporter {

	/**
	 * Errors that are to be exported.
	 */
	private List<IError> m_errors;
	
	/**
	 * Parent Element in which the errors will be exported to.
	 */
	private Element m_parent;
	
	/*
	 * (non-Javadoc)
	 * @see com.esri.solutions.jitk.web.error.IErrorSinkExporter#begin()
	 */
	public void begin() {
	}

	/*
	 * (non-Javadoc)
	 * @see com.esri.solutions.jitk.web.error.IErrorSinkExporter#end()
	 */
	public void end() {
	}

	/*
	 * (non-Javadoc)
	 * @see com.esri.solutions.jitk.web.error.IErrorSinkExporter#export()
	 */
	public void export() {
		if (m_errors != null) {
			Element root = m_parent.getOwnerDocument().createElement("jitk-errors");
			root.setAttribute("count", String.valueOf(m_errors.size()));
			for (IError error : m_errors) {
				createErrorElement(error, root);
			}
			m_parent.appendChild(root);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see com.esri.solutions.jitk.web.error.IErrorSinkExporter#setErrors(java.util.List)
	 */
	public void setErrors(List<IError> errors) {
		if (errors != null) {
			m_errors = errors;
		}
	}
	
	/**
	 * Sets the parent {@link Element} that will have the errors XML element added to it.
	 * After the export is complete, this parent element will have a child element named
	 * "errors" that will contain the error list in XML format.  See class documentation
	 * for complete XML schema.
	 * 
	 * @param parent  Errors XML will be added to this element, cannot be <code>null</code>.
	 */
	public void setParent (Element parent) {
		if (parent == null) {
			throw new NullPointerException ();
		}
		
		m_parent = parent;
	}
	
	/**
	 * Creates an error element for the specified error.  The
	 * error element will automatically be appended to the
	 * parent element.  If the Error's ID or Code properties
	 * are <code>null</code> then their corresponding attributes will not
	 * be included within the element.
	 * 
	 * @param error		Error information, cannot be <code>null</code>.
	 * @param parent	Parent Element.
	 */
	protected void createErrorElement (IError error, Element parent) {
		Element element = parent.getOwnerDocument().createElement("jitk-error");
		if (error.getId() != null) {
			element.setAttribute("id", error.getId().toString());
		}
		if (error.getCode() != null) {
			element.setAttribute("code", error.getCode());
		}
		
		if (error.getMessage() != null) {
			element.setTextContent(error.getMessage());
		}
		parent.appendChild(element);
	}
}

⌨️ 快捷键说明

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