001/* 002 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 003 * 004 * This software is open source. 005 * See the bottom of this file for the licence. 006 * 007 * $Id: ProxyDocumentFactory.java,v 1.7 2001/08/31 08:58:53 jstrachan Exp $ 008 */ 009 010package org.dom4j.util; 011 012import java.util.Map; 013 014import org.dom4j.Attribute; 015import org.dom4j.CDATA; 016import org.dom4j.Comment; 017import org.dom4j.Document; 018import org.dom4j.DocumentFactory; 019import org.dom4j.DocumentType; 020import org.dom4j.Element; 021import org.dom4j.Entity; 022import org.dom4j.Namespace; 023import org.dom4j.NodeFilter; 024import org.dom4j.ProcessingInstruction; 025import org.dom4j.QName; 026import org.dom4j.Text; 027import org.dom4j.XPath; 028import org.dom4j.rule.Pattern; 029 030import org.jaxen.VariableContext; 031 032import org.xml.sax.Attributes; 033 034/** <p><code>ProxyDocumentFactory</code> implements a proxy to a DocumentFactory 035 * which is useful for implementation inheritence, allowing the pipelining 036 * of various factory implementations. For example an EncodingDocumentFactory 037 * which takes care of encoding strings outside of allowable XML ranges 038 * could be used with a DatatypeDocumentFactory which is XML Schema Data Type 039 * aware.</p> 040 * 041 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> 042 * @version $Revision: 1.7 $ 043 */ 044public abstract class ProxyDocumentFactory { 045 046 private DocumentFactory proxy; 047 048 public ProxyDocumentFactory() { 049 // use default factory 050 this.proxy = DocumentFactory.getInstance(); 051 } 052 053 public ProxyDocumentFactory(DocumentFactory proxy) { 054 this.proxy = proxy; 055 } 056 057 // Factory methods 058 //------------------------------------------------------------------------- 059 060 public Document createDocument() { 061 return proxy.createDocument(); 062 } 063 064 public Document createDocument(Element rootElement) { 065 return proxy.createDocument(rootElement); 066 } 067 068 public DocumentType createDocType(String name, String publicId, String systemId) { 069 return proxy.createDocType(name, publicId, systemId); 070 } 071 072 public Element createElement(QName qname) { 073 return proxy.createElement(qname); 074 } 075 076 public Element createElement(String name) { 077 return proxy.createElement(name); 078 } 079 080 081 public Attribute createAttribute(Element owner, QName qname, String value) { 082 return proxy.createAttribute(owner, qname, value); 083 } 084 085 public Attribute createAttribute(Element owner, String name, String value) { 086 return proxy.createAttribute(owner, name, value); 087 } 088 089 public CDATA createCDATA(String text) { 090 return proxy.createCDATA(text); 091 } 092 093 public Comment createComment(String text) { 094 return proxy.createComment(text); 095 } 096 097 public Text createText(String text) { 098 return proxy.createText(text); 099 } 100 101 102 public Entity createEntity(String name, String text) { 103 return proxy.createEntity(name, text); 104 } 105 106 public Namespace createNamespace(String prefix, String uri) { 107 return proxy.createNamespace(prefix, uri); 108 } 109 110 public ProcessingInstruction createProcessingInstruction(String target, String data) { 111 return proxy.createProcessingInstruction(target, data); 112 } 113 114 public ProcessingInstruction createProcessingInstruction(String target, Map data) { 115 return proxy.createProcessingInstruction(target, data); 116 } 117 118 public QName createQName(String localName, Namespace namespace) { 119 return proxy.createQName(localName, namespace); 120 } 121 122 public QName createQName(String localName) { 123 return proxy.createQName(localName); 124 } 125 126 public QName createQName(String name, String prefix, String uri) { 127 return proxy.createQName(name, prefix, uri); 128 } 129 130 public QName createQName(String qualifiedName, String uri) { 131 return proxy.createQName(qualifiedName, uri); 132 } 133 134 public XPath createXPath(String xpathExpression) { 135 return proxy.createXPath(xpathExpression); 136 } 137 138 public XPath createXPath(String xpathExpression, VariableContext variableContext) { 139 return proxy.createXPath(xpathExpression, variableContext); 140 } 141 142 public NodeFilter createXPathFilter(String xpathFilterExpression, VariableContext variableContext) { 143 return proxy.createXPathFilter(xpathFilterExpression, variableContext); 144 } 145 146 public NodeFilter createXPathFilter(String xpathFilterExpression) { 147 return proxy.createXPathFilter(xpathFilterExpression); 148 } 149 150 public Pattern createPattern(String xpathPattern) { 151 return proxy.createPattern(xpathPattern); 152 } 153 154 155 // Implementation methods 156 //------------------------------------------------------------------------- 157 protected DocumentFactory getProxy() { 158 return proxy; 159 } 160 161 protected void setProxy(DocumentFactory proxy) { 162 if ( proxy == null ) { 163 // use default factory 164 proxy = DocumentFactory.getInstance(); 165 } 166 this.proxy = proxy; 167 } 168} 169 170 171 172 173/* 174 * Redistribution and use of this software and associated documentation 175 * ("Software"), with or without modification, are permitted provided 176 * that the following conditions are met: 177 * 178 * 1. Redistributions of source code must retain copyright 179 * statements and notices. Redistributions must also contain a 180 * copy of this document. 181 * 182 * 2. Redistributions in binary form must reproduce the 183 * above copyright notice, this list of conditions and the 184 * following disclaimer in the documentation and/or other 185 * materials provided with the distribution. 186 * 187 * 3. The name "DOM4J" must not be used to endorse or promote 188 * products derived from this Software without prior written 189 * permission of MetaStuff, Ltd. For written permission, 190 * please contact dom4j-info@metastuff.com. 191 * 192 * 4. Products derived from this Software may not be called "DOM4J" 193 * nor may "DOM4J" appear in their names without prior written 194 * permission of MetaStuff, Ltd. DOM4J is a registered 195 * trademark of MetaStuff, Ltd. 196 * 197 * 5. Due credit should be given to the DOM4J Project 198 * (http://dom4j.org/). 199 * 200 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 201 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 202 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 203 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 204 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 205 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 206 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 207 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 208 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 209 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 210 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 211 * OF THE POSSIBILITY OF SUCH DAMAGE. 212 * 213 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 214 * 215 * $Id: ProxyDocumentFactory.java,v 1.7 2001/08/31 08:58:53 jstrachan Exp $ 216 */