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: | 146 |  | Methods: | 9
| NCLOC: | 46 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

FlyweightProcessingInstruction.java

50%

60%

55,6%

57,7%

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.tree;
9 |  |
10 |  | import java.util.Collections;
11 |  | import java.util.Map;
12 |  |
13 |  | import org.dom4j.Element;
14 |  | import org.dom4j.Node;
15 |  |
16 |  | /**
17 |  | * <p>
18 |  | * <code>FlyweightProcessingInstruction</code> is a Flyweight pattern
19 |  | * implementation of a singly linked, read-only XML Processing Instruction.
20 |  | * </p>
21 |  | *
22 |  | * <p>
23 |  | * This node could be shared across documents and elements though it does not
24 |  | * support the parent relationship.
25 |  | * </p>
26 |  | *
27 |  | * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
28 |  | * @version $Revision: 1.7 $
29 |  | */
30 |  | public class FlyweightProcessingInstruction extends
31 |  | AbstractProcessingInstruction {
32 |  | /** The target of the PI */
33 |  | protected String target;
34 |  |
35 |  | /** The values for the PI as a String */
36 |  | protected String text;
37 |  |
38 |  | /** The values for the PI in name/value pairs */
39 |  | protected Map values;
40 |  |
41 |  | /**
42 |  | * A default constructor for implementors to use.
43 |  | */
44 | 0 | public FlyweightProcessingInstruction() {
45 |  | }
46 |  |
47 |  | /**
48 |  | * <p>
49 |  | * This will create a new PI with the given target and values
50 |  | * </p>
51 |  | *
52 |  | * @param target
53 |  | * is the name of the PI
54 |  | * @param values
55 |  | * is the <code>Map</code> of the values for the PI
56 |  | */
57 | 0 | public FlyweightProcessingInstruction(String target, Map values) {
58 | 0 | this.target = target;
59 | 0 | this.values = values;
60 | 0 | this.text = toString(values);
61 |  | }
62 |  |
63 |  | /**
64 |  | * <p>
65 |  | * This will create a new PI with the given target and values
66 |  | * </p>
67 |  | *
68 |  | * @param target
69 |  | * is the name of the PI
70 |  | * @param text
71 |  | * is the values for the PI as text
72 |  | */
73 | 28 | public FlyweightProcessingInstruction(String target, String text) {
74 | 28 | this.target = target;
75 | 28 | this.text = text;
76 | 28 | this.values = parseValues(text);
77 |  | }
78 |  |
79 | 29 | public String getTarget() {
80 | 29 | return target;
81 |  | }
82 |  |
83 | 0 | public void setTarget(String target) {
84 | 0 | throw new UnsupportedOperationException("This PI is read-only and "
85 |  | + "cannot be modified");
86 |  | }
87 |  |
88 | 29 | public String getText() {
89 | 29 | return text;
90 |  | }
91 |  |
92 | 4 | public String getValue(String name) {
93 | 4 | String answer = (String) values.get(name);
94 |  |
95 | 4 | if (answer == null) {
96 | 0 | return "";
97 |  | }
98 |  |
99 | 4 | return answer;
100 |  | }
101 |  |
102 | 1 | public Map getValues() {
103 | 1 | return Collections.unmodifiableMap(values);
104 |  | }
105 |  |
106 | 0 | protected Node createXPathResult(Element parent) {
107 | 0 | return new DefaultProcessingInstruction(parent, getTarget(), getText());
108 |  | }
109 |  | }
110 |  |
111 |  | /*
112 |  | * Redistribution and use of this software and associated documentation
113 |  | * ("Software"), with or without modification, are permitted provided that the
114 |  | * following conditions are met:
115 |  | *
116 |  | * 1. Redistributions of source code must retain copyright statements and
117 |  | * notices. Redistributions must also contain a copy of this document.
118 |  | *
119 |  | * 2. Redistributions in binary form must reproduce the above copyright notice,
120 |  | * this list of conditions and the following disclaimer in the documentation
121 |  | * and/or other materials provided with the distribution.
122 |  | *
123 |  | * 3. The name "DOM4J" must not be used to endorse or promote products derived
124 |  | * from this Software without prior written permission of MetaStuff, Ltd. For
125 |  | * written permission, please contact dom4j-info@metastuff.com.
126 |  | *
127 |  | * 4. Products derived from this Software may not be called "DOM4J" nor may
128 |  | * "DOM4J" appear in their names without prior written permission of MetaStuff,
129 |  | * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
130 |  | *
131 |  | * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
132 |  | *
133 |  | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
134 |  | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
135 |  | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
136 |  | * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
137 |  | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
138 |  | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
139 |  | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
140 |  | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
141 |  | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
142 |  | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
143 |  | * POSSIBILITY OF SUCH DAMAGE.
144 |  | *
145 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
146 |  | */