HIbernate的单例例子_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > HIbernate的单例例子

HIbernate的单例例子

 2013/11/10 0:55:55  alleni123  程序员俱乐部  我要评论(0)
  • 摘要:publicfinalclassXMLHelper{publicstaticfinalEntityResolverDEFAULT_DTD_RESOLVER=newDTDEntityResolver();privateDOMReaderdomReader;privateSAXReadersaxReader
  • 标签:例子 hibernate
class="java" name="code">
 

public final class XMLHelper {

	public static final EntityResolver DEFAULT_DTD_RESOLVER = new DTDEntityResolver();

	private DOMReader domReader;
	private SAXReader saxReader;

	/**
	 * @param errorHandler the sax error handler
	 * @param entityResolver an xml entity resolver
	 *
	 * @return Create and return a dom4j {@code SAXReader} which will append all validation errors
	 *         to the passed error list
	 */
	public SAXReader createSAXReader(ErrorHandler errorHandler, EntityResolver entityResolver) {
		SAXReader saxReader = resolveSAXReader();
		saxReader.setEntityResolver( entityResolver );
		saxReader.setErrorHandler( errorHandler );
		return saxReader;
	}

	private SAXReader resolveSAXReader() {
		if ( saxReader == null ) {
			saxReader = new SAXReader();
			saxReader.setMergeAdjacentText( true );
			saxReader.setValidation( true );
		}
		return saxReader;
	}

	
	
	
}



这里在createSAXReader方法的第一行就调用了resolveSAXReader(),
后者检查了saxReader是否为空, 如果为空, 则创建新的。
不为空则返回类的内部实例saxReader.
发表评论
用户名: 匿名