jsonxmlstreamreader.java
来自「resetful样式的ws样例,一种面向资源的webservices服务」· Java 代码 · 共 704 行 · 第 1/2 页
JAVA
704 行
} break; // AFTER_ARRAY_ELEM case BEFORE_NEXT_ARRAY_ELEM: StartElementEvent event = generateSEEvent(processingStack.get(depth - 1).lastName); switch (lastToken.tokenType) { case JsonToken.START_OBJECT: processingStack.add(new ProcessingState(LaState.AFTER_OBJ_START_BRACE)); processingStack.get(depth).eventToReadAttributesFor = event; depth++; break; case JsonToken.START_ARRAY: processingStack.add(new ProcessingState(LaState.AFTER_ARRAY_START_BRACE)); depth++; break; case JsonToken.STRING: eventQueue.add(new CharactersEvent(lastToken.tokenText, new MyLocation(lexer))); processingStack.get(depth).state = LaState.AFTER_ARRAY_ELEM; break; default: // TODO: handle problem } break; // BEFORE_NEXT_ARRAY_ELEM case AFTER_ARRAY_ELEM: switch (lastToken.tokenType) { case JsonToken.END_ARRAY: processingStack.remove(depth); depth--; valueRead(); break; case JsonToken.COMMA: processingStack.get(depth).state = LaState.BEFORE_NEXT_ARRAY_ELEM; generateEEEvent(processingStack.get(depth - 1).lastName); break; default: // TODO: handle problem } break; // AFTER_ARRAY_ELEM } } // end while lastEvent null //System.out.println("Next event = " + eventQueue.peek()); } public int getAttributeCount() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getAttributeCount"); assert !eventQueue.isEmpty(); if (!eventQueue.peek().attributesChecked) { try { readNext(true); } catch (IOException e) { // TODO: handle it!!! } eventQueue.peek().attributesChecked = true; } int result = eventQueue.peek().getAttributeCount(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getAttributeCount", result); return result; } public int getEventType() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getEventType"); assert !eventQueue.isEmpty(); int result = eventQueue.peek().getEventType(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getEventType", result); return result; } public int getNamespaceCount() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getNamespaceCount"); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getNamespaceCount", 0); return 0; } public int getTextLength() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getTextLength"); assert !eventQueue.isEmpty(); int result = eventQueue.peek().getTextLength(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getTextLength", result); return result; } public int getTextStart() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getTextStart"); assert !eventQueue.isEmpty(); int result = eventQueue.peek().getTextStart(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getTextStart", result); return result; } public int next() throws XMLStreamException { try { readNext(); return eventQueue.peek().getEventType(); } catch (IOException ex) { Logger.getLogger(JsonXmlStreamReader.class.getName()).log(Level.SEVERE, null, ex); throw new XMLStreamException(ex); } } public int nextTag() throws XMLStreamException { throw new UnsupportedOperationException("Not supported yet."); } public void close() throws XMLStreamException { throw new UnsupportedOperationException("Not supported yet."); } public boolean hasName() { throw new UnsupportedOperationException("Not supported yet."); } public boolean hasNext() throws XMLStreamException { throw new UnsupportedOperationException("Not supported yet."); } public boolean hasText() { throw new UnsupportedOperationException("Not supported yet."); } public boolean isCharacters() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "isCharacters"); assert !eventQueue.isEmpty(); boolean result = eventQueue.peek().isCharacters(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "isCharacters", result); return result; } public boolean isEndElement() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "isEndElement"); assert !eventQueue.isEmpty(); boolean result = eventQueue.peek().isEndElement(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "isEndElement", result); return result; } public boolean isStandalone() { throw new UnsupportedOperationException("Not supported yet."); } public boolean isStartElement() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "isStartElement"); assert !eventQueue.isEmpty(); boolean result = eventQueue.peek().isStartElement(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "isStartElement", result); return result; } public boolean isWhiteSpace() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "isWhiteSpace"); boolean result = false; // white space processed by lexer LOGGER.exiting(JsonXmlStreamReader.class.getName(), "isWhiteSpace", result); return result; } public boolean standaloneSet() { throw new UnsupportedOperationException("Not supported yet."); } public char[] getTextCharacters() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getTextCharacters"); assert !eventQueue.isEmpty(); char[] result = eventQueue.peek().getTextCharacters(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getTextCharacters", result); return result; } public boolean isAttributeSpecified(int attribute) { LOGGER.entering(JsonXmlStreamReader.class.getName(), "isAttributeSpecified"); assert !eventQueue.isEmpty(); boolean result = eventQueue.peek().isAttributeSpecified(attribute); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "isAttributeSpecified", result); return result; } public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getTextCharacters"); assert !eventQueue.isEmpty(); int result = eventQueue.peek().getTextCharacters(sourceStart, target, targetStart, length); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getTextCharacters", result); return result; } public String getCharacterEncodingScheme() { throw new UnsupportedOperationException("Not supported yet."); } public String getElementText() throws XMLStreamException { throw new UnsupportedOperationException("Not supported yet."); } public String getEncoding() { throw new UnsupportedOperationException("Not supported yet."); } public String getLocalName() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getLocalName"); assert !eventQueue.isEmpty(); String result = eventQueue.peek().getLocalName(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getLocalName", result); return result; } public String getNamespaceURI() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getNamespaceURI"); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getNamespaceURI", null); return null; } public String getPIData() { throw new UnsupportedOperationException("Not supported yet."); } public String getPITarget() { throw new UnsupportedOperationException("Not supported yet."); } public String getPrefix() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getPrefix"); assert !eventQueue.isEmpty(); String result = eventQueue.peek().getPrefix(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getPrefix", result); return result; } public String getText() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getText"); assert !eventQueue.isEmpty(); String result = eventQueue.peek().getText(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getText", result); return result; } public String getVersion() { throw new UnsupportedOperationException("Not supported yet."); } public String getAttributeLocalName(int index) { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getAttributeLocalName"); assert !eventQueue.isEmpty(); String result = eventQueue.peek().getAttributeLocalName(index); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getAttributeLocalName", result); return result; } public QName getAttributeName(int index) { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getAttributeName"); assert !eventQueue.isEmpty(); QName result = eventQueue.peek().getAttributeName(index); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getAttributeName", result); return result; } public String getAttributeNamespace(int index) { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getAttributeNamespace"); assert !eventQueue.isEmpty(); String result = eventQueue.peek().getAttributeNamespace(index); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getAttributeNamespace", result); return result; } public String getAttributePrefix(int index) { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getAttributePrefix"); assert !eventQueue.isEmpty(); String result = eventQueue.peek().getAttributePrefix(index); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getAttributePrefix", result); return result; } public String getAttributeType(int index) { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getAttributeType"); assert !eventQueue.isEmpty(); String result = eventQueue.peek().getAttributeType(index); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getAttributeType", result); return result; } public String getAttributeValue(int index) { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getAttributeValue"); assert !eventQueue.isEmpty(); String result = eventQueue.peek().getAttributeValue(index); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getAttributeValue", result); return result; } public String getAttributeValue(String namespaceURI, String localName) { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getAttributeValue"); assert !eventQueue.isEmpty(); String result = eventQueue.peek().getAttributeValue(namespaceURI, localName); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getAttributeValue", result); return result; } public String getNamespacePrefix(int arg0) { throw new UnsupportedOperationException("Not supported yet."); } public String getNamespaceURI(int arg0) { throw new UnsupportedOperationException("Not supported yet."); } public NamespaceContext getNamespaceContext() { // TODO: put/take it to/from processing stack LOGGER.entering(JsonXmlStreamReader.class.getName(), "getNamespaceContext"); NamespaceContext result = new JsonNamespaceContext(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getNamespaceContext", result); return result; } public QName getName() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getName"); assert !eventQueue.isEmpty(); QName result = eventQueue.peek().getName(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getName"); return result; } public Location getLocation() { LOGGER.entering(JsonXmlStreamReader.class.getName(), "getLocation"); assert !eventQueue.isEmpty(); Location result = eventQueue.peek().getLocation(); LOGGER.exiting(JsonXmlStreamReader.class.getName(), "getLocation", result); return result; } public Object getProperty(String arg0) throws IllegalArgumentException { throw new UnsupportedOperationException("Not supported yet."); } public void require(int arg0, String arg1, String arg2) throws XMLStreamException { throw new UnsupportedOperationException("Not supported yet."); } public String getNamespaceURI(String arg0) { throw new UnsupportedOperationException("Not supported yet."); } private StartElementEvent generateSEEvent(String name) { StartElementEvent event = null; if (!"$".equals(name)) { event = new StartElementEvent(name, new MyLocation(lexer)); eventQueue.add(event); } return event; } private void generateEEEvent(String name) { if (!"$".equals(name)) { eventQueue.add(new EndElementEvent(name, new MyLocation(lexer))); } } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?