dom4j - 1.6.1

Clover coverage report - dom4j - 1.6.1
Coverage timestamp: ma mei 16 2005 14:23:01 GMT+01:00
FRAMES NO FRAMES

file stats: | LOC: | 216 |  | Methods: | 18
| NCLOC: | 122 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

DOMDocumentFactory.java

0%

46,5%

44,4%

41,8%

1 |  | /*
2 |  | * Copyright 2001-2005 (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 |  |
8 |  | package org.dom4j.dom;
9 |  |
10 |  | import java.util.Map;
11 |  |
12 |  | import org.dom4j.Attribute;
13 |  | import org.dom4j.CDATA;
14 |  | import org.dom4j.Comment;
15 |  | import org.dom4j.Document;
16 |  | import org.dom4j.DocumentFactory;
17 |  | import org.dom4j.DocumentType;
18 |  | import org.dom4j.Element;
19 |  | import org.dom4j.Entity;
20 |  | import org.dom4j.Namespace;
21 |  | import org.dom4j.ProcessingInstruction;
22 |  | import org.dom4j.QName;
23 |  | import org.dom4j.Text;
24 |  | import org.dom4j.util.SingletonStrategy;
25 |  | import org.w3c.dom.DOMException;
26 |  |
27 |  | /**
28 |  | * <p>
29 |  | * <code>DOMDocumentFactory</code> is a factory of DOM4J objects which
30 |  | * implement the W3C DOM API.
31 |  | * </p>
32 |  | *
33 |  | * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
34 |  | * @version $Revision: 1.21 $
35 |  | */
36 |  | public class DOMDocumentFactory extends DocumentFactory implements
37 |  | org.w3c.dom.DOMImplementation {
38 |  |
39 |  | /** The Singleton instance */
40 |  | private static SingletonStrategy singleton = null;
41 |  |
42 |  | static {
43 | 3 | try {
44 | 3 | String defaultSingletonClass = "org.dom4j.util.SimpleSingleton";
45 | 3 | Class clazz = null;
46 | 3 | try {
47 | 3 | String singletonClass = defaultSingletonClass;
48 | 3 | singletonClass = System.getProperty(
49 |  | "org.dom4j.dom.DOMDocumentFactory.singleton.strategy",
50 |  | singletonClass);
51 | 3 | clazz = Class.forName(singletonClass);
52 |  | } catch (Exception exc1) {
53 | 0 | try {
54 | 0 | String singletonClass = defaultSingletonClass;
55 | 0 | clazz = Class.forName(singletonClass);
56 |  | } catch (Exception exc2) {
57 |  | }
58 |  | }
59 | 3 | singleton = (SingletonStrategy) clazz.newInstance();
60 | 3 | singleton.setSingletonClassName(DOMDocumentFactory.class.getName());
61 |  | } catch (Exception exc3) {
62 |  | }
63 |  | }
64 |  |
65 |  | /**
66 |  | * <p>
67 |  | * Access to the singleton instance of this factory.
68 |  | * </p>
69 |  | *
70 |  | * @return the default singleon instance
71 |  | */
72 | 12 | public static DocumentFactory getInstance() {
73 | 12 | DOMDocumentFactory fact = (DOMDocumentFactory) singleton.instance();
74 | 12 | return fact;
75 |  | }
76 |  |
77 |  | // Factory methods
78 | 6 | public Document createDocument() {
79 | 6 | DOMDocument answer = new DOMDocument();
80 | 6 | answer.setDocumentFactory(this);
81 |  |
82 | 6 | return answer;
83 |  | }
84 |  |
85 | 0 | public DocumentType createDocType(String name, String publicId,
86 |  | String systemId) {
87 | 0 | return new DOMDocumentType(name, publicId, systemId);
88 |  | }
89 |  |
90 | 151 | public Element createElement(QName qname) {
91 | 151 | return new DOMElement(qname);
92 |  | }
93 |  |
94 | 0 | public Element createElement(QName qname, int attributeCount) {
95 | 0 | return new DOMElement(qname, attributeCount);
96 |  | }
97 |  |
98 | 114 | public Attribute createAttribute(Element owner, QName qname, String value) {
99 | 114 | return new DOMAttribute(qname, value);
100 |  | }
101 |  |
102 | 0 | public CDATA createCDATA(String text) {
103 | 0 | return new DOMCDATA(text);
104 |  | }
105 |  |
106 | 12 | public Comment createComment(String text) {
107 | 12 | return new DOMComment(text);
108 |  | }
109 |  |
110 | 307 | public Text createText(String text) {
111 | 307 | return new DOMText(text);
112 |  | }
113 |  |
114 | 0 | public Entity createEntity(String name) {
115 | 0 | return new DOMEntityReference(name);
116 |  | }
117 |  |
118 | 0 | public Entity createEntity(String name, String text) {
119 | 0 | return new DOMEntityReference(name, text);
120 |  | }
121 |  |
122 | 159 | public Namespace createNamespace(String prefix, String uri) {
123 | 159 | return new DOMNamespace(prefix, uri);
124 |  | }
125 |  |
126 | 12 | public ProcessingInstruction createProcessingInstruction(String target,
127 |  | String data) {
128 | 12 | return new DOMProcessingInstruction(target, data);
129 |  | }
130 |  |
131 | 0 | public ProcessingInstruction createProcessingInstruction(String target,
132 |  | Map data) {
133 | 0 | return new DOMProcessingInstruction(target, data);
134 |  | }
135 |  |
136 |  | // org.w3c.dom.DOMImplementation interface
137 | 0 | public boolean hasFeature(String feat, String version) {
138 | 0 | if ("XML".equalsIgnoreCase(feat) || "Core".equalsIgnoreCase(feat)) {
139 | 0 | return ((version == null) || (version.length() == 0)
140 |  | || "1.0".equals(version) || "2.0".equals(version));
141 |  | }
142 |  |
143 | 0 | return false;
144 |  | }
145 |  |
146 | 0 | public org.w3c.dom.DocumentType createDocumentType(String qualifiedName,
147 |  | String publicId, String systemId) throws DOMException {
148 | 0 | return new DOMDocumentType(qualifiedName, publicId, systemId);
149 |  | }
150 |  |
151 | 0 | public org.w3c.dom.Document createDocument(String namespaceURI,
152 |  | String qualifiedName, org.w3c.dom.DocumentType docType)
153 |  | throws org.w3c.dom.DOMException {
154 | 0 | DOMDocument document;
155 |  |
156 | 0 | if (docType != null) {
157 | 0 | DOMDocumentType documentType = asDocumentType(docType);
158 | 0 | document = new DOMDocument(documentType);
159 |  | } else {
160 | 0 | document = new DOMDocument();
161 |  | }
162 |  |
163 | 0 | document.addElement(createQName(qualifiedName, namespaceURI));
164 |  |
165 | 0 | return document;
166 |  | }
167 |  |
168 |  | // Implementation methods
169 | 0 | protected DOMDocumentType asDocumentType(org.w3c.dom.DocumentType docType) {
170 | 0 | if (docType instanceof DOMDocumentType) {
171 | 0 | return (DOMDocumentType) docType;
172 |  | } else {
173 | 0 | return new DOMDocumentType(docType.getName(),
174 |  | docType.getPublicId(), docType.getSystemId());
175 |  | }
176 |  | }
177 |  | }
178 |  |
179 |  |
180 |  |
181 |  | /*
182 |  | * Redistribution and use of this software and associated documentation
183 |  | * ("Software"), with or without modification, are permitted provided that the
184 |  | * following conditions are met:
185 |  | *
186 |  | * 1. Redistributions of source code must retain copyright statements and
187 |  | * notices. Redistributions must also contain a copy of this document.
188 |  | *
189 |  | * 2. Redistributions in binary form must reproduce the above copyright notice,
190 |  | * this list of conditions and the following disclaimer in the documentation
191 |  | * and/or other materials provided with the distribution.
192 |  | *
193 |  | * 3. The name "DOM4J" must not be used to endorse or promote products derived
194 |  | * from this Software without prior written permission of MetaStuff, Ltd. For
195 |  | * written permission, please contact dom4j-info@metastuff.com.
196 |  | *
197 |  | * 4. Products derived from this Software may not be called "DOM4J" nor may
198 |  | * "DOM4J" appear in their names without prior written permission of MetaStuff,
199 |  | * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
200 |  | *
201 |  | * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
202 |  | *
203 |  | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
204 |  | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
205 |  | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
206 |  | * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
207 |  | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
208 |  | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
209 |  | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
210 |  | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
211 |  | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
212 |  | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
213 |  | * POSSIBILITY OF SUCH DAMAGE.
214 |  | *
215 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
216 |  | */