Source Code Cross Referenced for StAXEventReader.java in  » 6.0-JDK-Modules-com.sun » fastinfoset » com » sun » xml » fastinfoset » stax » events » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules com.sun » fastinfoset » com.sun.xml.fastinfoset.stax.events 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Fast Infoset ver. 0.1 software ("Software")
003:         * 
004:         * Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved. 
005:         * 
006:         * Software is licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License. You may
008:         * 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, software
013:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015:         * License for the specific language governing permissions and limitations.
016:         * 
017:         *    Sun supports and benefits from the global community of open source
018:         * developers, and thanks the community for its important contributions and
019:         * open standards-based technology, which Sun has adopted into many of its
020:         * products.
021:         * 
022:         *    Please note that portions of Software may be provided with notices and
023:         * open source licenses from such communities and third parties that govern the
024:         * use of those portions, and any licenses granted hereunder do not alter any
025:         * rights and obligations you may have under such open source licenses,
026:         * however, the disclaimer of warranty and limitation of liability provisions
027:         * in this License will apply to all Software in this distribution.
028:         * 
029:         *    You acknowledge that the Software is not designed, licensed or intended
030:         * for use in the design, construction, operation or maintenance of any nuclear
031:         * facility.
032:         *
033:         * Apache License
034:         * Version 2.0, January 2004
035:         * http://www.apache.org/licenses/
036:         *
037:         */
038:
039:        package com.sun.xml.fastinfoset.stax.events;
040:
041:        import com.sun.xml.fastinfoset.stax.*;
042:        import java.util.NoSuchElementException;
043:        import javax.xml.stream.XMLInputFactory;
044:        import javax.xml.stream.XMLStreamException;
045:        import javax.xml.stream.XMLStreamReader;
046:        import javax.xml.stream.events.XMLEvent;
047:        import javax.xml.stream.util.XMLEventAllocator;
048:        import com.sun.xml.fastinfoset.CommonResourceBundle;
049:
050:        public class StAXEventReader implements  javax.xml.stream.XMLEventReader {
051:            protected XMLStreamReader _streamReader;
052:            protected XMLEventAllocator _eventAllocator;
053:            private XMLEvent _currentEvent; //the current event
054:            private XMLEvent[] events = new XMLEvent[3];
055:            private int size = 3;
056:            private int currentIndex = 0;
057:            private boolean hasEvent = false; //true when current event exists, false initially & at end
058:
059:            //only constructor will do because we delegate everything to underlying XMLStreamReader
060:            public StAXEventReader(XMLStreamReader reader)
061:                    throws XMLStreamException {
062:                _streamReader = reader;
063:                _eventAllocator = (XMLEventAllocator) reader
064:                        .getProperty(XMLInputFactory.ALLOCATOR);
065:                if (_eventAllocator == null) {
066:                    _eventAllocator = new StAXEventAllocatorBase();
067:                }
068:                //initialize
069:                if (_streamReader.hasNext()) {
070:                    _streamReader.next();
071:                    _currentEvent = _eventAllocator.allocate(_streamReader);
072:                    events[0] = _currentEvent;
073:                    hasEvent = true;
074:                } else {
075:                    throw new XMLStreamException(CommonResourceBundle
076:                            .getInstance().getString("message.noElement"));
077:                }
078:            }
079:
080:            public boolean hasNext() {
081:                return hasEvent;
082:            }
083:
084:            public XMLEvent nextEvent() throws XMLStreamException {
085:                XMLEvent event = null;
086:                XMLEvent nextEvent = null;
087:                if (hasEvent) {
088:                    event = events[currentIndex];
089:                    events[currentIndex] = null;
090:                    if (_streamReader.hasNext()) {
091:                        //advance and read the next
092:                        _streamReader.next();
093:                        nextEvent = _eventAllocator.allocate(_streamReader);
094:                        if (++currentIndex == size)
095:                            currentIndex = 0;
096:                        events[currentIndex] = nextEvent;
097:                        hasEvent = true;
098:                    } else {
099:                        _currentEvent = null;
100:                        hasEvent = false;
101:                    }
102:                    return event;
103:                } else {
104:                    throw new NoSuchElementException();
105:                }
106:            }
107:
108:            public void remove() {
109:                //stream reader is read-only.
110:                throw new java.lang.UnsupportedOperationException();
111:            }
112:
113:            public void close() throws XMLStreamException {
114:                _streamReader.close();
115:            }
116:
117:            /** Reads the content of a text-only element. Precondition:
118:             * the current event is START_ELEMENT. Postcondition:
119:             * The current event is the corresponding END_ELEMENT.
120:             * @throws XMLStreamException if the current event is not a START_ELEMENT
121:             * or if a non text element is encountered
122:             */
123:            public String getElementText() throws XMLStreamException {
124:                if (!hasEvent) {
125:                    throw new NoSuchElementException();
126:                }
127:
128:                if (!_currentEvent.isStartElement()) {
129:                    StAXDocumentParser parser = (StAXDocumentParser) _streamReader;
130:                    return parser.getElementText(true);
131:                } else {
132:                    return _streamReader.getElementText();
133:                }
134:            }
135:
136:            /** Get the value of a feature/property from the underlying implementation
137:             * @param name The name of the property
138:             * @return The value of the property
139:             * @throws IllegalArgumentException if the property is not supported
140:             */
141:            public Object getProperty(java.lang.String name)
142:                    throws java.lang.IllegalArgumentException {
143:                return _streamReader.getProperty(name);
144:            }
145:
146:            /** Skips any insignificant space events until a START_ELEMENT or
147:             * END_ELEMENT is reached. If anything other than space characters are
148:             * encountered, an exception is thrown. This method should
149:             * be used when processing element-only content because
150:             * the parser is not able to recognize ignorable whitespace if
151:             * the DTD is missing or not interpreted.
152:             * @throws XMLStreamException if anything other than space characters are encountered
153:             */
154:            public XMLEvent nextTag() throws XMLStreamException {
155:                if (!hasEvent) {
156:                    throw new NoSuchElementException();
157:                }
158:                StAXDocumentParser parser = (StAXDocumentParser) _streamReader;
159:                parser.nextTag(true);
160:                return _eventAllocator.allocate(_streamReader);
161:            }
162:
163:            //XMLEventReader extends Iterator;
164:            public Object next() {
165:                try {
166:                    return nextEvent();
167:                } catch (XMLStreamException streamException) {
168:                    return null;
169:                }
170:            }
171:
172:            public XMLEvent peek() throws XMLStreamException {
173:                if (!hasEvent)
174:                    throw new XMLStreamException(CommonResourceBundle
175:                            .getInstance().getString("message.noElement"));
176:                _currentEvent = events[currentIndex];
177:                return _currentEvent;
178:            }
179:
180:            public void setAllocator(XMLEventAllocator allocator) {
181:                if (allocator == null)
182:                    throw new IllegalArgumentException(CommonResourceBundle
183:                            .getInstance().getString(
184:                                    "message.nullXMLEventAllocator"));
185:
186:                _eventAllocator = allocator;
187:            }
188:
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.