KickJava   Java API By Example, From Geeks To Geeks.

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


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: AbstractEntity.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.Entity;
14 import org.dom4j.Visitor;
15
16 import java.io.IOException JavaDoc;
17 import java.io.Writer JavaDoc;
18
19 /** <p><code>AbstractEntity</code> is an abstract base class for
20  * tree implementors to use for implementation inheritence.</p>
21  *
22  * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
23  * @version $Revision: 1.2 $
24  */

25 public abstract class AbstractEntity extends AbstractNode implements Entity {
26
27     public AbstractEntity() {
28     }
29
30     public short getNodeType() {
31         return ENTITY_REFERENCE_NODE;
32     }
33
34     public String JavaDoc getPath(Element context) {
35         // From XPaths perspective, entities are included in text
36
Element parent = getParent();
37         return (parent != null && parent != context)
38                 ? parent.getPath(context) + "/text()"
39                 : "text()";
40     }
41
42     public String JavaDoc getUniquePath(Element context) {
43         // From XPaths perspective, entities are included in text
44
Element parent = getParent();
45         return (parent != null && parent != context)
46                 ? parent.getUniquePath(context) + "/text()"
47                 : "text()";
48     }
49
50     public String JavaDoc toString() {
51         return super.toString() + " [Entity: &" + getName() + ";]";
52     }
53
54     public String JavaDoc getStringValue() {
55         return "&" + getName() + ";";
56     }
57
58     public String JavaDoc asXML() {
59         return "&" + getName() + ";";
60     }
61
62     public void write(Writer JavaDoc writer) throws IOException JavaDoc {
63         writer.write("&");
64         writer.write(getName());
65         writer.write(";");
66     }
67
68     public void accept(Visitor visitor) {
69         visitor.visit(this);
70     }
71
72 }
73
74
75 /*
76  * Redistribution and use of this software and associated documentation
77  * ("Software"), with or without modification, are permitted provided
78  * that the following conditions are met:
79  *
80  * 1. Redistributions of source code must retain copyright
81  * statements and notices. Redistributions must also contain a
82  * copy of this document.
83  *
84  * 2. Redistributions in binary form must reproduce the
85  * above copyright notice, this list of conditions and the
86  * following disclaimer in the documentation and/or other
87  * materials provided with the distribution.
88  *
89  * 3. The name "DOM4J" must not be used to endorse or promote
90  * products derived from this Software without prior written
91  * permission of MetaStuff, Ltd. For written permission,
92  * please contact dom4j-info@metastuff.com.
93  *
94  * 4. Products derived from this Software may not be called "DOM4J"
95  * nor may "DOM4J" appear in their names without prior written
96  * permission of MetaStuff, Ltd. DOM4J is a registered
97  * trademark of MetaStuff, Ltd.
98  *
99  * 5. Due credit should be given to the DOM4J Project
100  * (http://dom4j.org/).
101  *
102  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
103  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
104  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
105  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
106  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
107  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
108  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
109  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
110  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
111  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
112  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
113  * OF THE POSSIBILITY OF SUCH DAMAGE.
114  *
115  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
116  *
117  * $Id: AbstractEntity.java,v 1.2 2003/06/10 16:18:36 per_nyfelt Exp $
118  */

119
Popular Tags