001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.databinding.utils.reader;
020:
021: import javax.xml.namespace.NamespaceContext;
022: import javax.xml.namespace.QName;
023: import javax.xml.stream.Location;
024: import javax.xml.stream.XMLStreamException;
025:
026: public class NullXMLStreamReader implements ADBXMLStreamReader {
027:
028: private QName outerQName = null;
029:
030: private static final int START_ELEMENT_STATE = 1;
031: private static final int END_ELEMENT_STATE = 2;
032:
033: private static final QName NIL_QNAME = new QName(
034: "http://www.w3.org/2001/XMLSchema-instance", "nil", "xsi");
035: private static final String NIL_VALUE_TRUE = "true";
036:
037: private int currentState = START_ELEMENT;
038:
039: public NullXMLStreamReader(QName outerQName) {
040: this .outerQName = outerQName;
041: }
042:
043: public Object getProperty(String key)
044: throws IllegalArgumentException {
045: //since optimization is a global property
046: //we've to implement it everywhere
047: if (OPTIMIZATION_ENABLED.equals(key)) {
048: return Boolean.TRUE;
049: } else {
050: return null;
051: }
052: }
053:
054: public int next() throws XMLStreamException {
055: int returnEvent = START_DOCUMENT;
056: switch (currentState) {
057: case START_ELEMENT_STATE:
058: currentState = END_ELEMENT_STATE;
059: returnEvent = END_ELEMENT;
060: break;
061: case END_ELEMENT_STATE:
062: throw new XMLStreamException("parser completed!");
063:
064: }
065:
066: return returnEvent;
067: }
068:
069: public void require(int i, String string, String string1)
070: throws XMLStreamException {
071: //nothing
072: }
073:
074: public String getElementText() throws XMLStreamException {
075: return null;
076: }
077:
078: public int nextTag() throws XMLStreamException {
079: throw new UnsupportedOperationException();
080: }
081:
082: public boolean hasNext() throws XMLStreamException {
083: return (currentState != END_ELEMENT_STATE);
084:
085: }
086:
087: public void close() throws XMLStreamException {
088: //do nothing
089: }
090:
091: public String getNamespaceURI(String string) {
092: if (outerQName.getPrefix() != null
093: && outerQName.getPrefix().equals(string)) {
094: return outerQName.getNamespaceURI();
095: } else {
096: return null;
097: }
098: }
099:
100: public boolean isStartElement() {
101: return (currentState == START_ELEMENT_STATE);
102: }
103:
104: public boolean isEndElement() {
105: return (currentState == END_ELEMENT_STATE);
106: }
107:
108: public boolean isCharacters() {
109: return false;
110: }
111:
112: public boolean isWhiteSpace() {
113: return false;
114: }
115:
116: public String getAttributeValue(String string, String string1) {
117: if (string == null) {//null namespace - ignore it
118: if (NIL_QNAME.getLocalPart().equals(string1)) {
119: return NIL_VALUE_TRUE;
120: }
121: }
122: return null;
123: }
124:
125: public int getAttributeCount() {
126: return 1;
127: }
128:
129: public QName getAttributeName(int i) {
130: return (i == 0) ? NIL_QNAME : null;
131: }
132:
133: public String getAttributeNamespace(int i) {
134: return (i == 0) ? NIL_QNAME.getNamespaceURI() : null;
135: }
136:
137: public String getAttributeLocalName(int i) {
138: return (i == 0) ? NIL_QNAME.getLocalPart() : null;
139: }
140:
141: public String getAttributePrefix(int i) {
142: return (i == 0) ? NIL_QNAME.getPrefix() : null;
143: }
144:
145: public String getAttributeType(int i) {
146: throw new UnsupportedOperationException();
147: }
148:
149: public String getAttributeValue(int i) {
150: return (i == 0) ? NIL_VALUE_TRUE : null;
151: }
152:
153: public boolean isAttributeSpecified(int i) {
154: return (i == 0);
155: }
156:
157: public int getNamespaceCount() {
158: return 0;
159: }
160:
161: public String getNamespacePrefix(int i) {
162: return null;
163: }
164:
165: public String getNamespaceURI(int i) {
166: return null;
167: }
168:
169: public NamespaceContext getNamespaceContext() {
170: throw new UnsupportedOperationException();
171: }
172:
173: public int getEventType() {
174: int returnEvent = START_DOCUMENT;
175: switch (currentState) {
176: case START_ELEMENT_STATE:
177: returnEvent = START_ELEMENT;
178: break;
179: case END_ELEMENT_STATE:
180: returnEvent = END_ELEMENT;
181: break;
182:
183: }
184: return returnEvent;
185: }
186:
187: public String getText() {
188: return null;
189: }
190:
191: public char[] getTextCharacters() {
192: return new char[0]; //To change body of implemented methods use File | Settings | File Templates.
193: }
194:
195: public int getTextCharacters(int i, char[] chars, int i1, int i2)
196: throws XMLStreamException {
197: return 0;
198: }
199:
200: public int getTextStart() {
201: return 0;
202: }
203:
204: public int getTextLength() {
205: return 0;
206: }
207:
208: public String getEncoding() {
209: return null;
210: }
211:
212: public boolean hasText() {
213: return false;
214: }
215:
216: public Location getLocation() {
217: return new Location() {
218: public int getLineNumber() {
219: return 0;
220: }
221:
222: public int getColumnNumber() {
223: return 0;
224: }
225:
226: public int getCharacterOffset() {
227: return 0;
228: }
229:
230: public String getPublicId() {
231: return null;
232: }
233:
234: public String getSystemId() {
235: return null;
236: }
237: };
238: }
239:
240: public QName getName() {
241: return outerQName;
242: }
243:
244: public String getLocalName() {
245: return outerQName.getLocalPart();
246: }
247:
248: public boolean hasName() {
249: return true;
250: }
251:
252: public String getNamespaceURI() {
253: return outerQName.getNamespaceURI();
254: }
255:
256: public String getPrefix() {
257: return outerQName.getPrefix();
258: }
259:
260: public String getVersion() {
261: throw new UnsupportedOperationException();
262: }
263:
264: public boolean isStandalone() {
265: throw new UnsupportedOperationException();
266: }
267:
268: public boolean standaloneSet() {
269: throw new UnsupportedOperationException();
270: }
271:
272: public String getCharacterEncodingScheme() {
273: throw new UnsupportedOperationException();
274: }
275:
276: public String getPITarget() {
277: throw new UnsupportedOperationException();
278: }
279:
280: public String getPIData() {
281: throw new UnsupportedOperationException();
282: }
283:
284: public boolean isDone() {
285: return (currentState == END_ELEMENT_STATE);
286: }
287:
288: public void addNamespaceContext(NamespaceContext nsContext) {
289: //To change body of implemented methods use File | Settings | File Templates.
290: }
291:
292: public void init() {
293: //To change body of implemented methods use File | Settings | File Templates.
294: }
295: }
|