Source Code Cross Referenced for AbstractXmlStreamReader.java in  » Web-Services » spring-ws-1.0.0 » org » springframework » xml » stream » 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 » Web Services » spring ws 1.0.0 » org.springframework.xml.stream 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.xml.stream;
018:
019:        import javax.xml.namespace.QName;
020:        import javax.xml.stream.XMLStreamConstants;
021:        import javax.xml.stream.XMLStreamException;
022:        import javax.xml.stream.XMLStreamReader;
023:
024:        import org.springframework.util.Assert;
025:
026:        /**
027:         * Abstract base class for <code>XMLStreamReader</code>s.
028:         *
029:         * @author Arjen Poutsma
030:         * @since 1.0.0
031:         */
032:        public abstract class AbstractXmlStreamReader implements 
033:                XMLStreamReader {
034:
035:            public String getElementText() throws XMLStreamException {
036:                if (getEventType() != XMLStreamConstants.START_ELEMENT) {
037:                    throw new XMLStreamException(
038:                            "parser must be on START_ELEMENT to read next text",
039:                            getLocation());
040:                }
041:                int eventType = next();
042:                StringBuffer buffer = new StringBuffer();
043:                while (eventType != XMLStreamConstants.END_ELEMENT) {
044:                    if (eventType == XMLStreamConstants.CHARACTERS
045:                            || eventType == XMLStreamConstants.CDATA
046:                            || eventType == XMLStreamConstants.SPACE
047:                            || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
048:                        buffer.append(getText());
049:                    } else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
050:                            || eventType == XMLStreamConstants.COMMENT) {
051:                        // skipping
052:                    } else if (eventType == XMLStreamConstants.END_DOCUMENT) {
053:                        throw new XMLStreamException(
054:                                "unexpected end of document when reading element text content",
055:                                getLocation());
056:                    } else if (eventType == XMLStreamConstants.START_ELEMENT) {
057:                        throw new XMLStreamException(
058:                                "element text content may not contain START_ELEMENT",
059:                                getLocation());
060:                    } else {
061:                        throw new XMLStreamException("Unexpected event type "
062:                                + eventType, getLocation());
063:                    }
064:                    eventType = next();
065:                }
066:                return buffer.toString();
067:            }
068:
069:            public String getAttributeLocalName(int index) {
070:                return getAttributeName(index).getLocalPart();
071:            }
072:
073:            public String getAttributeNamespace(int index) {
074:                return getAttributeName(index).getNamespaceURI();
075:            }
076:
077:            public String getAttributePrefix(int index) {
078:                return getAttributeName(index).getPrefix();
079:            }
080:
081:            public String getNamespaceURI() {
082:                int eventType = getEventType();
083:                if (eventType == XMLStreamConstants.START_ELEMENT
084:                        || eventType == XMLStreamConstants.END_ELEMENT) {
085:                    return getName().getNamespaceURI();
086:                } else {
087:                    throw new IllegalStateException(
088:                            "parser must be on START_ELEMENT or END_ELEMENT state");
089:                }
090:            }
091:
092:            public String getNamespaceURI(String prefix) {
093:                Assert.notNull(prefix, "No prefix given");
094:                return getNamespaceContext().getNamespaceURI(prefix);
095:            }
096:
097:            public boolean hasText() {
098:                int eventType = getEventType();
099:                return eventType == XMLStreamConstants.SPACE
100:                        || eventType == XMLStreamConstants.CHARACTERS
101:                        || eventType == XMLStreamConstants.COMMENT
102:                        || eventType == XMLStreamConstants.CDATA
103:                        || eventType == XMLStreamConstants.ENTITY_REFERENCE;
104:            }
105:
106:            public String getPrefix() {
107:                int eventType = getEventType();
108:                if (eventType == XMLStreamConstants.START_ELEMENT
109:                        || eventType == XMLStreamConstants.END_ELEMENT) {
110:                    return getName().getPrefix();
111:                } else {
112:                    throw new IllegalStateException(
113:                            "parser must be on START_ELEMENT or END_ELEMENT state");
114:                }
115:            }
116:
117:            public boolean hasName() {
118:                int eventType = getEventType();
119:                return eventType == XMLStreamConstants.START_ELEMENT
120:                        || eventType == XMLStreamConstants.END_ELEMENT;
121:            }
122:
123:            public boolean isWhiteSpace() {
124:                return getEventType() == XMLStreamConstants.SPACE;
125:            }
126:
127:            public boolean isStartElement() {
128:                return getEventType() == XMLStreamConstants.START_ELEMENT;
129:            }
130:
131:            public boolean isEndElement() {
132:                return getEventType() == XMLStreamConstants.END_ELEMENT;
133:            }
134:
135:            public boolean isCharacters() {
136:                return getEventType() == XMLStreamConstants.CHARACTERS;
137:            }
138:
139:            public int nextTag() throws XMLStreamException {
140:                int eventType = next();
141:                while (eventType == XMLStreamConstants.CHARACTERS
142:                        && isWhiteSpace()
143:                        || eventType == XMLStreamConstants.CDATA
144:                        && isWhiteSpace()
145:                        || eventType == XMLStreamConstants.SPACE
146:                        || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
147:                        || eventType == XMLStreamConstants.COMMENT) {
148:                    eventType = next();
149:                }
150:                if (eventType != XMLStreamConstants.START_ELEMENT
151:                        && eventType != XMLStreamConstants.END_ELEMENT) {
152:                    throw new XMLStreamException("expected start or end tag",
153:                            getLocation());
154:                }
155:                return eventType;
156:            }
157:
158:            public void require(int expectedType, String namespaceURI,
159:                    String localName) throws XMLStreamException {
160:                int eventType = getEventType();
161:                if (eventType != expectedType) {
162:                    throw new XMLStreamException("Expected [" + expectedType
163:                            + "] but read [" + eventType + "]");
164:                }
165:            }
166:
167:            public String getAttributeValue(String namespaceURI,
168:                    String localName) {
169:                for (int i = 0; i < getAttributeCount(); i++) {
170:                    QName name = getAttributeName(i);
171:                    if (name.getNamespaceURI().equals(namespaceURI)
172:                            && name.getLocalPart().equals(localName)) {
173:                        return getAttributeValue(i);
174:                    }
175:                }
176:                return null;
177:            }
178:
179:            public boolean hasNext() throws XMLStreamException {
180:                return getEventType() != END_DOCUMENT;
181:            }
182:
183:            public String getLocalName() {
184:                return getName().getLocalPart();
185:            }
186:
187:            public char[] getTextCharacters() {
188:                return getText().toCharArray();
189:            }
190:
191:            public int getTextCharacters(int sourceStart, char[] target,
192:                    int targetStart, int length) throws XMLStreamException {
193:                char[] source = getTextCharacters();
194:                length = Math.min(length, source.length);
195:                System.arraycopy(source, sourceStart, target, targetStart,
196:                        length);
197:                return length;
198:            }
199:
200:            public int getTextLength() {
201:                return getText().length();
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.