1 /* 2 * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. 3 * 4 * This software is open source. 5 * See the bottom of this file for the licence. 6 * 7 * $Id: NonLazyDocumentFactory.java,v 1.7 2004/06/25 08:03:41 maartenc Exp $ 8 */ 9 10 package org.dom4j.util; 11 12 import org.dom4j.DocumentFactory; 13 import org.dom4j.Element; 14 import org.dom4j.QName; 15 16 /*** <p><code>NonLazyDocumentFactory</code> is a factory of XML objects which 17 * avoid using the lazy creation pattern. This results in a slower 18 * creation of a Document and uses more memory but it means that the 19 * same Document instance can be shared across threads provided it is not 20 * modified.</p> 21 * 22 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> 23 * @version $Revision: 1.7 $ 24 */ 25 public class NonLazyDocumentFactory extends DocumentFactory { 26 27 /*** The Singleton instance */ 28 static transient NonLazyDocumentFactory singleton = new NonLazyDocumentFactory(); 29 30 31 /*** <p>Access to the singleton instance of this factory.</p> 32 * 33 * @return the default singleon instance 34 */ 35 public static DocumentFactory getInstance() { 36 return singleton; 37 } 38 39 40 // DocumentFactory methods 41 //------------------------------------------------------------------------- 42 43 public Element createElement(QName qname) { 44 return new NonLazyElement(qname); 45 } 46 } 47 48 49 50 51 /* 52 * Redistribution and use of this software and associated documentation 53 * ("Software"), with or without modification, are permitted provided 54 * that the following conditions are met: 55 * 56 * 1. Redistributions of source code must retain copyright 57 * statements and notices. Redistributions must also contain a 58 * copy of this document. 59 * 60 * 2. Redistributions in binary form must reproduce the 61 * above copyright notice, this list of conditions and the 62 * following disclaimer in the documentation and/or other 63 * materials provided with the distribution. 64 * 65 * 3. The name "DOM4J" must not be used to endorse or promote 66 * products derived from this Software without prior written 67 * permission of MetaStuff, Ltd. For written permission, 68 * please contact dom4j-info@metastuff.com. 69 * 70 * 4. Products derived from this Software may not be called "DOM4J" 71 * nor may "DOM4J" appear in their names without prior written 72 * permission of MetaStuff, Ltd. DOM4J is a registered 73 * trademark of MetaStuff, Ltd. 74 * 75 * 5. Due credit should be given to the DOM4J Project - 76 * http://www.dom4j.org 77 * 78 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 79 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 80 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 81 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 82 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 83 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 84 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 85 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 86 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 87 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 88 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 89 * OF THE POSSIBILITY OF SUCH DAMAGE. 90 * 91 * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. 92 * 93 * $Id: NonLazyDocumentFactory.java,v 1.7 2004/06/25 08:03:41 maartenc Exp $ 94 */