KickJava   Java API By Example, From Geeks To Geeks.

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


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: FlyweightEntity.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 /** <p><code>FlyweightEntity</code> is a Flyweight pattern implementation
16  * of a singly linked, read-only XML entity.</p>
17  *
18  * <p>This node could be shared across documents and elements though
19  * it does not support the parent relationship.</p>
20  *
21  * <p>Often this node needs to be created and then the text content added
22  * later (for example in SAX) so this implementation allows a call to
23  * {@link #setText} providing the entity has no text already.
24  *
25  * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
26  * @version $Revision: 1.2 $
27  */

28 public class FlyweightEntity extends AbstractEntity {
29
30     /** The name of the <code>Entity</code> */
31     protected String JavaDoc name;
32
33     /** The text of the <code>Entity</code> */
34     protected String JavaDoc text;
35
36     /** A default constructor for implementors to use.
37      */

38     protected FlyweightEntity() {
39     }
40
41     /** Creates the <code>Entity</code> with the specified name
42      *
43      * @param name is the name of the entity
44      */

45     public FlyweightEntity(String JavaDoc name) {
46         this.name = name;
47     }
48
49     /** Creates the <code>Entity</code> with the specified name
50      * and text.
51      *
52      * @param name is the name of the entity
53      * @param text is the text of the entity
54      */

55     public FlyweightEntity(String JavaDoc name, String JavaDoc text) {
56         this.name = name;
57         this.text = text;
58     }
59
60     /** @return the name of the entity
61      */

62     public String JavaDoc getName() {
63         return name;
64     }
65
66     /** @return the text of the entity
67      */

68     public String JavaDoc getText() {
69         return text;
70     }
71
72     /** sets the value of the entity if it is not defined yet
73      * otherwise an <code>UnsupportedOperationException</code> is thrown
74      * as this class is read only.
75      */

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

136
Popular Tags