001    /*
002     * Copyright (c) 2007 Henri Sivonen
003     * Copyright (c) 2007 Mozilla Foundation
004     *
005     * Permission is hereby granted, free of charge, to any person obtaining a 
006     * copy of this software and associated documentation files (the "Software"), 
007     * to deal in the Software without restriction, including without limitation 
008     * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
009     * and/or sell copies of the Software, and to permit persons to whom the 
010     * Software is furnished to do so, subject to the following conditions:
011     *
012     * The above copyright notice and this permission notice shall be included in 
013     * all copies or substantial portions of the Software.
014     *
015     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
016     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
017     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
018     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
019     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
020     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
021     * DEALINGS IN THE SOFTWARE.
022     */
023    
024    package nu.validator.saxtree;
025    
026    import java.util.List;
027    
028    import org.xml.sax.Attributes;
029    import org.xml.sax.Locator;
030    import org.xml.sax.SAXException;
031    
032    public abstract class Node implements Locator {
033    
034        private final String systemId;
035        private final String publicId;
036        private final int column;
037        private final int line;
038        
039        private Node nextSibling = null;
040        
041        private ParentNode parentNode = null;
042    
043        Node(Locator locator) {
044            if (locator == null) {
045                this.systemId = null;
046                this.publicId = null;
047                this.column = -1;
048                this.line = -1;
049            } else {
050                this.systemId = locator.getSystemId();
051                this.publicId = locator.getPublicId();
052                this.column = locator.getColumnNumber();
053                this.line = locator.getLineNumber();
054            }
055        }
056        
057        public int getColumnNumber() {
058            return column;
059        }
060    
061        public int getLineNumber() {
062            return line;
063        }
064    
065        public String getPublicId() {
066            return publicId;
067        }
068    
069        public String getSystemId() {
070            return systemId;
071        }
072    
073        abstract void visit(TreeParser treeParser) throws SAXException;
074        
075        void revisit(TreeParser treeParser) throws SAXException {
076            return;
077        }
078        
079        public Node getFirstChild() {
080            return null;
081        }
082    
083        /**
084         * Returns the nextSibling.
085         * 
086         * @return the nextSibling
087         */
088        public final Node getNextSibling() {
089            return nextSibling;
090        }
091    
092        /**
093         * Sets the nextSibling.
094         * 
095         * @param nextSibling the nextSibling to set
096         */
097        void setNextSibling(Node nextSibling) {
098            this.nextSibling = nextSibling;
099        }
100        
101        
102        /**
103         * Returns the parentNode.
104         * 
105         * @return the parentNode
106         */
107        public final ParentNode getParentNode() {
108            return parentNode;
109        }
110        
111        public abstract NodeType getNodeType();
112        
113        // Subclass-specific accessors that are hoisted here to 
114        // avoid casting.
115    
116        /**
117         * Sets the parentNode.
118         * 
119         * @param parentNode the parentNode to set
120         */
121        void setParentNode(ParentNode parentNode) {
122            this.parentNode = parentNode;
123        }
124        
125        public void detach() {
126            if (parentNode != null) {
127                parentNode.removeChild(this);
128                parentNode = null;
129            }
130        }
131        
132        /**
133         * Returns the name.
134         * 
135         * @return the name
136         */
137        public String getName() {
138            throw new UnsupportedOperationException();
139        }
140    
141        /**
142         * Returns the publicIdentifier.
143         * 
144         * @return the publicIdentifier
145         */
146        public String getPublicIdentifier() {
147            throw new UnsupportedOperationException();
148        }
149    
150        /**
151         * Returns the systemIdentifier.
152         * 
153         * @return the systemIdentifier
154         */
155        public String getSystemIdentifier() {
156            throw new UnsupportedOperationException();
157        }
158    
159        /**
160         * Returns the attributes.
161         * 
162         * @return the attributes
163         */
164        public Attributes getAttributes() {
165            throw new UnsupportedOperationException();
166        }
167    
168        /**
169         * Returns the localName.
170         * 
171         * @return the localName
172         */
173        public String getLocalName() {
174            throw new UnsupportedOperationException();
175        }
176    
177        /**
178         * Returns the prefixMappings.
179         * 
180         * @return the prefixMappings
181         */
182        public List<PrefixMapping> getPrefixMappings() {
183            throw new UnsupportedOperationException();
184        }
185    
186        /**
187         * Returns the qName.
188         * 
189         * @return the qName
190         */
191        public String getQName() {
192            throw new UnsupportedOperationException();
193        }
194    
195        /**
196         * Returns the uri.
197         * 
198         * @return the uri
199         */
200        public String getUri() {
201            throw new UnsupportedOperationException();
202        }
203    
204        /**
205         * Returns the data.
206         * 
207         * @return the data
208         */
209        public String getData() {
210            throw new UnsupportedOperationException();
211        }
212    
213        /**
214         * Returns the target.
215         * 
216         * @return the target
217         */
218        public String getTarget() {
219            throw new UnsupportedOperationException();
220        }
221    }