KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > xml > dom4j > o3impl > FlyweightProcessingInstruction


1 /*
2  * Copyright 2001 (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: FlyweightProcessingInstruction.java,v 1.2 2003/06/10 16:18:36 per_nyfelt Exp $
8  */

9
10 package org.ozoneDB.xml.dom4j.o3impl;
11
12 import org.dom4j.Element;
13 import org.dom4j.Node;
14
15 import java.util.Collections JavaDoc;
16 import java.util.Map JavaDoc;
17
18 /** <p><code>FlyweightProcessingInstruction</code> is a Flyweight pattern implementation
19  * of a singly linked, read-only XML Processing Instruction.</p>
20  *
21  * <p>This node could be shared across documents and elements though
22  * it does not support the parent relationship.</p>
23  *
24  * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
25  * @version $Revision: 1.2 $
26  */

27 public class FlyweightProcessingInstruction extends AbstractProcessingInstruction {
28
29     /** The target of the PI */
30     protected String JavaDoc target;
31
32     /** The values for the PI as a String */
33     protected String JavaDoc text;
34
35     /** The values for the PI in name/value pairs */
36     protected Map JavaDoc values;
37
38     /** A default constructor for implementors to use.
39      */

40     public FlyweightProcessingInstruction() {
41     }
42
43     /** <p>This will create a new PI with the given target and values</p>
44      *
45      * @param target is the name of the PI
46      * @param values is the <code>Map</code> of the values for the PI
47      */

48     public FlyweightProcessingInstruction(String JavaDoc target, Map JavaDoc values) {
49         this.target = target;
50         this.values = values;
51         this.text = toString(values);
52     }
53
54     /** <p>This will create a new PI with the given target and values</p>
55      *
56      * @param target is the name of the PI
57      * @param text is the values for the PI as text
58      */

59     public FlyweightProcessingInstruction(String JavaDoc target, String JavaDoc text) {
60         this.target = target;
61         this.text = text;
62         this.values = parseValues(text);
63     }
64
65     public String JavaDoc getTarget() {
66         return target;
67     }
68
69     public void setTarget(String JavaDoc target) {
70         throw new UnsupportedOperationException JavaDoc("This PI is read-only and cannot be modified");
71     }
72
73     public String JavaDoc getText() {
74         return text;
75     }
76
77     public String JavaDoc getValue(String JavaDoc name) {
78         String JavaDoc answer = (String JavaDoc) values.get(name);
79         if (answer == null) {
80             return "";
81         }
82         return answer;
83     }
84
85     public Map JavaDoc getValues() {
86         return Collections.unmodifiableMap(values);
87     }
88
89     protected Node createXPathResult(Element parent) {
90         return new DefaultProcessingInstruction(parent, getTarget(), getText());
91     }
92 }
93
94
95 /*
96  * Redistribution and use of this software and associated documentation
97  * ("Software"), with or without modification, are permitted provided
98  * that the following conditions are met:
99  *
100  * 1. Redistributions of source code must retain copyright
101  * statements and notices. Redistributions must also contain a
102  * copy of this document.
103  *
104  * 2. Redistributions in binary form must reproduce the
105  * above copyright notice, this list of conditions and the
106  * following disclaimer in the documentation and/or other
107  * materials provided with the distribution.
108  *
109  * 3. The name "DOM4J" must not be used to endorse or promote
110  * products derived from this Software without prior written
111  * permission of MetaStuff, Ltd. For written permission,
112  * please contact dom4j-info@metastuff.com.
113  *
114  * 4. Products derived from this Software may not be called "DOM4J"
115  * nor may "DOM4J" appear in their names without prior written
116  * permission of MetaStuff, Ltd. DOM4J is a registered
117  * trademark of MetaStuff, Ltd.
118  *
119  * 5. Due credit should be given to the DOM4J Project
120  * (http://dom4j.org/).
121  *
122  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
123  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
124  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
125  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
126  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
127  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
128  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
129  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
130  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
131  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
132  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
133  * OF THE POSSIBILITY OF SUCH DAMAGE.
134  *
135  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
136  *
137  * $Id: FlyweightProcessingInstruction.java,v 1.2 2003/06/10 16:18:36 per_nyfelt Exp $
138  */

139
Popular Tags