001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.impl.xs.opti;
019:
020: import org.w3c.dom.Attr;
021: import org.w3c.dom.Document;
022: import org.w3c.dom.NamedNodeMap;
023: import org.w3c.dom.Node;
024:
025: /**
026: * @xerces.internal
027: *
028: * @author Rahul Srivastava, Sun Microsystems Inc.
029: * @author Sandy Gao, IBM
030: *
031: * @version $Id: ElementImpl.java 446728 2006-09-15 20:43:46Z mrglavas $
032: */
033: public class ElementImpl extends DefaultElement {
034:
035: SchemaDOM schemaDOM;
036: Attr[] attrs;
037: int row;
038: int col;
039: int parentRow;
040:
041: int line;
042: int column;
043: int charOffset;
044: String fAnnotation;
045: String fSyntheticAnnotation;
046:
047: public ElementImpl(int line, int column, int offset) {
048: row = -1;
049: col = -1;
050: parentRow = -1;
051: nodeType = Node.ELEMENT_NODE;
052:
053: this .line = line;
054: this .column = column;
055: charOffset = offset;
056: }
057:
058: public ElementImpl(int line, int column) {
059: this (line, column, -1);
060: }
061:
062: public ElementImpl(String prefix, String localpart, String rawname,
063: String uri, int line, int column, int offset) {
064: super (prefix, localpart, rawname, uri, Node.ELEMENT_NODE);
065: row = -1;
066: col = -1;
067: parentRow = -1;
068:
069: this .line = line;
070: this .column = column;
071: charOffset = offset;
072: }
073:
074: public ElementImpl(String prefix, String localpart, String rawname,
075: String uri, int line, int column) {
076: this (prefix, localpart, rawname, uri, line, column, -1);
077: }
078:
079: //
080: // org.w3c.dom.Node methods
081: //
082:
083: public Document getOwnerDocument() {
084: return schemaDOM;
085: }
086:
087: public Node getParentNode() {
088: return schemaDOM.relations[row][0];
089: }
090:
091: public boolean hasChildNodes() {
092: if (parentRow == -1) {
093: return false;
094: } else {
095: return true;
096: }
097: }
098:
099: public Node getFirstChild() {
100: if (parentRow == -1) {
101: return null;
102: }
103: return schemaDOM.relations[parentRow][1];
104: }
105:
106: public Node getLastChild() {
107: if (parentRow == -1) {
108: return null;
109: }
110: int i = 1;
111: for (; i < schemaDOM.relations[parentRow].length; i++) {
112: if (schemaDOM.relations[parentRow][i] == null) {
113: return schemaDOM.relations[parentRow][i - 1];
114: }
115: }
116: if (i == 1) {
117: i++;
118: }
119: return schemaDOM.relations[parentRow][i - 1];
120: }
121:
122: public Node getPreviousSibling() {
123: if (col == 1) {
124: return null;
125: }
126: return schemaDOM.relations[row][col - 1];
127: }
128:
129: public Node getNextSibling() {
130: if (col == schemaDOM.relations[row].length - 1) {
131: return null;
132: }
133: return schemaDOM.relations[row][col + 1];
134: }
135:
136: public NamedNodeMap getAttributes() {
137: return new NamedNodeMapImpl(attrs);
138: }
139:
140: public boolean hasAttributes() {
141: return (attrs.length == 0 ? false : true);
142: }
143:
144: //
145: // org.w3c.dom.Element methods
146: //
147:
148: public String getTagName() {
149: return rawname;
150: }
151:
152: public String getAttribute(String name) {
153:
154: for (int i = 0; i < attrs.length; i++) {
155: if (attrs[i].getName().equals(name)) {
156: return attrs[i].getValue();
157: }
158: }
159: return "";
160: }
161:
162: public Attr getAttributeNode(String name) {
163: for (int i = 0; i < attrs.length; i++) {
164: if (attrs[i].getName().equals(name)) {
165: return attrs[i];
166: }
167: }
168: return null;
169: }
170:
171: public String getAttributeNS(String namespaceURI, String localName) {
172: for (int i = 0; i < attrs.length; i++) {
173: if (attrs[i].getLocalName().equals(localName)
174: && attrs[i].getNamespaceURI().equals(namespaceURI)) {
175: return attrs[i].getValue();
176: }
177: }
178: return "";
179: }
180:
181: public Attr getAttributeNodeNS(String namespaceURI, String localName) {
182: for (int i = 0; i < attrs.length; i++) {
183: if (attrs[i].getName().equals(localName)
184: && attrs[i].getNamespaceURI().equals(namespaceURI)) {
185: return attrs[i];
186: }
187: }
188: return null;
189: }
190:
191: public boolean hasAttribute(String name) {
192: for (int i = 0; i < attrs.length; i++) {
193: if (attrs[i].getName().equals(name)) {
194: return true;
195: }
196: }
197: return false;
198: }
199:
200: public boolean hasAttributeNS(String namespaceURI, String localName) {
201: for (int i = 0; i < attrs.length; i++) {
202: if (attrs[i].getName().equals(localName)
203: && attrs[i].getNamespaceURI().equals(namespaceURI)) {
204: return true;
205: }
206: }
207: return false;
208: }
209:
210: public void setAttribute(String name, String value) {
211: for (int i = 0; i < attrs.length; i++) {
212: if (attrs[i].getName().equals(name)) {
213: attrs[i].setValue(value);
214: return;
215: }
216: }
217: }
218:
219: /** Returns the line number. */
220: public int getLineNumber() {
221: return line;
222: }
223:
224: /** Returns the column number. */
225: public int getColumnNumber() {
226: return column;
227: }
228:
229: /** Returns the character offset. */
230: public int getCharacterOffset() {
231: return charOffset;
232: }
233:
234: public String getAnnotation() {
235: return fAnnotation;
236: }
237:
238: public String getSyntheticAnnotation() {
239: return fSyntheticAnnotation;
240: }
241: }
|