Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
1 /*
2 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 *
25 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
26 */
28 package com.sun.xml.internal.fastinfoset.stax.events;
30 import javax.xml.stream.events.XMLEvent;
31 import javax.xml.stream.EventFilter;
32 import javax.xml.stream.events.Characters;
33 import javax.xml.stream.XMLStreamException;
34 import javax.xml.stream.XMLEventReader;
35 import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
37 public class StAXFilteredEvent implements XMLEventReader {
38 private XMLEventReader eventReader;
39 private EventFilter _filter;
41 /** Creates a new instance of StAXFilteredEvent */
42 public StAXFilteredEvent() {
43 }
45 public StAXFilteredEvent(XMLEventReader reader, EventFilter filter) throws XMLStreamException
46 {
47 eventReader = reader;
48 _filter = filter;
49 }
51 public void setEventReader(XMLEventReader reader) {
52 eventReader = reader;
53 }
55 public void setFilter(EventFilter filter) {
56 _filter = filter;
57 }
59 public Object next() {
60 try {
61 return nextEvent();
62 } catch (XMLStreamException e) {
63 return null;
64 }
65 }
67 public XMLEvent nextEvent() throws XMLStreamException
68 {
69 if (hasNext())
70 return eventReader.nextEvent();
71 return null;
72 }
74 public String getElementText() throws XMLStreamException
75 {
76 StringBuffer buffer = new StringBuffer();
77 XMLEvent e = nextEvent();
78 if (!e.isStartElement())
79 throw new XMLStreamException(
80 CommonResourceBundle.getInstance().getString("message.mustBeOnSTART_ELEMENT"));
82 while(hasNext()) {
83 e = nextEvent();
84 if(e.isStartElement())
85 throw new XMLStreamException(
86 CommonResourceBundle.getInstance().getString("message.getElementTextExpectTextOnly"));
87 if(e.isCharacters())
88 buffer.append(((Characters) e).getData());
89 if(e.isEndElement())
90 return buffer.toString();
91 }
92 throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.END_ELEMENTnotFound"));
93 }
95 public XMLEvent nextTag() throws XMLStreamException {
96 while(hasNext()) {
97 XMLEvent e = nextEvent();
98 if (e.isStartElement() || e.isEndElement())
99 return e;
100 }
101 throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.startOrEndNotFound"));
102 }
105 public boolean hasNext()
106 {
107 try {
108 while(eventReader.hasNext()) {
109 if (_filter.accept(eventReader.peek())) return true;
110 eventReader.nextEvent();
111 }
112 return false;
113 } catch (XMLStreamException e) {
114 return false;
115 }
116 }
118 public void remove() {
119 throw new UnsupportedOperationException();
120 }
122 public XMLEvent peek() throws XMLStreamException
123 {
124 if (hasNext())
125 return eventReader.peek();
126 return null;
127 }
129 public void close() throws XMLStreamException
130 {
131 eventReader.close();
132 }
134 public Object getProperty(String name) {
135 return eventReader.getProperty(name);
136 }
138 }