View Javadoc

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: ProxyDocumentFactory.java,v 1.11 2004/06/25 08:03:41 maartenc Exp $
8    */
9   
10  package org.dom4j.util;
11  
12  import java.util.Map;
13  
14  import org.dom4j.Attribute;
15  import org.dom4j.CDATA;
16  import org.dom4j.Comment;
17  import org.dom4j.Document;
18  import org.dom4j.DocumentFactory;
19  import org.dom4j.DocumentType;
20  import org.dom4j.Element;
21  import org.dom4j.Entity;
22  import org.dom4j.Namespace;
23  import org.dom4j.NodeFilter;
24  import org.dom4j.ProcessingInstruction;
25  import org.dom4j.QName;
26  import org.dom4j.Text;
27  import org.dom4j.XPath;
28  import org.dom4j.rule.Pattern;
29  import org.jaxen.VariableContext;
30  
31  /*** <p><code>ProxyDocumentFactory</code> implements a proxy to a DocumentFactory
32    * which is useful for implementation inheritence, allowing the pipelining
33    * of various factory implementations. For example an EncodingDocumentFactory 
34    * which takes care of encoding strings outside of allowable XML ranges
35    * could be used with a DatatypeDocumentFactory which is XML Schema Data Type 
36    * aware.</p>
37    *
38    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
39    * @version $Revision: 1.11 $
40    */
41  public abstract class ProxyDocumentFactory {
42  
43      private DocumentFactory proxy;
44      
45      public ProxyDocumentFactory() {
46          // use default factory
47          this.proxy = DocumentFactory.getInstance();
48      }
49      
50      public ProxyDocumentFactory(DocumentFactory proxy) {
51          this.proxy = proxy;
52      }
53      
54      // Factory methods
55      //-------------------------------------------------------------------------
56      
57      public Document createDocument() {
58          return proxy.createDocument();
59      }
60      
61      public Document createDocument(Element rootElement) {
62          return proxy.createDocument(rootElement);
63      }
64      
65      public DocumentType createDocType(String name, String publicId, String systemId) {
66          return proxy.createDocType(name, publicId, systemId);
67      }
68      
69      public Element createElement(QName qname) {
70          return proxy.createElement(qname);
71      }
72  
73      public Element createElement(String name) {
74          return proxy.createElement(name);
75      }
76  
77      
78      public Attribute createAttribute(Element owner, QName qname, String value) {
79          return proxy.createAttribute(owner, qname, value);
80      }
81      
82      public Attribute createAttribute(Element owner, String name, String value) {
83          return proxy.createAttribute(owner, name, value);
84      }
85      
86      public CDATA createCDATA(String text) {
87          return proxy.createCDATA(text);
88      }
89      
90      public Comment createComment(String text) {
91          return proxy.createComment(text);
92      }
93      
94      public Text createText(String text) {
95          return proxy.createText(text);
96      }
97      
98      
99      public Entity createEntity(String name, String text) {
100         return proxy.createEntity(name, text);
101     }
102     
103     public Namespace createNamespace(String prefix, String uri) {
104         return proxy.createNamespace(prefix, uri);
105     }
106     
107     public ProcessingInstruction createProcessingInstruction(String target, String data) {
108         return proxy.createProcessingInstruction(target, data);
109     }
110     
111     public ProcessingInstruction createProcessingInstruction(String target, Map data) {
112         return proxy.createProcessingInstruction(target, data);
113     }
114     
115     public QName createQName(String localName, Namespace namespace) {
116         return proxy.createQName(localName, namespace);
117     }
118     
119     public QName createQName(String localName) {
120         return proxy.createQName(localName);
121     }
122     
123     public QName createQName(String name, String prefix, String uri) {
124         return proxy.createQName(name, prefix, uri);
125     }
126 
127     public QName createQName(String qualifiedName, String uri) {
128         return proxy.createQName(qualifiedName, uri);
129     }
130     
131     public XPath createXPath(String xpathExpression) {
132         return proxy.createXPath(xpathExpression);
133     }
134 
135     public XPath createXPath(String xpathExpression, VariableContext variableContext) {
136         return proxy.createXPath(xpathExpression, variableContext);
137     }
138 
139     public NodeFilter createXPathFilter(String xpathFilterExpression, VariableContext variableContext) {
140         return proxy.createXPathFilter(xpathFilterExpression, variableContext);
141     }
142     
143     public NodeFilter createXPathFilter(String xpathFilterExpression) {
144         return proxy.createXPathFilter(xpathFilterExpression);
145     }
146     
147     public Pattern createPattern(String xpathPattern) {
148         return proxy.createPattern(xpathPattern);
149     }
150     
151     
152     // Implementation methods
153     //-------------------------------------------------------------------------
154     protected DocumentFactory getProxy() {
155         return proxy;
156     }
157     
158     protected void setProxy(DocumentFactory proxy) {
159         if ( proxy == null ) {
160             // use default factory
161             proxy = DocumentFactory.getInstance();
162         }
163         this.proxy = proxy;
164     }
165 }
166 
167 
168 
169 
170 /*
171  * Redistribution and use of this software and associated documentation
172  * ("Software"), with or without modification, are permitted provided
173  * that the following conditions are met:
174  *
175  * 1. Redistributions of source code must retain copyright
176  *    statements and notices.  Redistributions must also contain a
177  *    copy of this document.
178  *
179  * 2. Redistributions in binary form must reproduce the
180  *    above copyright notice, this list of conditions and the
181  *    following disclaimer in the documentation and/or other
182  *    materials provided with the distribution.
183  *
184  * 3. The name "DOM4J" must not be used to endorse or promote
185  *    products derived from this Software without prior written
186  *    permission of MetaStuff, Ltd.  For written permission,
187  *    please contact dom4j-info@metastuff.com.
188  *
189  * 4. Products derived from this Software may not be called "DOM4J"
190  *    nor may "DOM4J" appear in their names without prior written
191  *    permission of MetaStuff, Ltd. DOM4J is a registered
192  *    trademark of MetaStuff, Ltd.
193  *
194  * 5. Due credit should be given to the DOM4J Project - 
195  *    http://www.dom4j.org
196  *
197  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
198  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
199  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
200  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
201  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
202  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
203  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
204  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
205  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
206  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
207  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
208  * OF THE POSSIBILITY OF SUCH DAMAGE.
209  *
210  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
211  *
212  * $Id: ProxyDocumentFactory.java,v 1.11 2004/06/25 08:03:41 maartenc Exp $
213  */