Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | * |
aoqi@0 | 25 | * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. |
aoqi@0 | 26 | */ |
aoqi@0 | 27 | |
aoqi@0 | 28 | package com.sun.xml.internal.fastinfoset.stax.events ; |
aoqi@0 | 29 | |
aoqi@0 | 30 | import java.util.ArrayList; |
aoqi@0 | 31 | import java.util.Collection; |
aoqi@0 | 32 | import java.util.HashMap; |
aoqi@0 | 33 | import java.util.Iterator; |
aoqi@0 | 34 | import java.util.List; |
aoqi@0 | 35 | import java.util.Map; |
aoqi@0 | 36 | |
aoqi@0 | 37 | import javax.xml.namespace.NamespaceContext; |
aoqi@0 | 38 | import javax.xml.namespace.QName; |
aoqi@0 | 39 | import javax.xml.stream.XMLStreamConstants; |
aoqi@0 | 40 | import javax.xml.stream.events.Attribute; |
aoqi@0 | 41 | import javax.xml.stream.events.Namespace; |
aoqi@0 | 42 | import javax.xml.stream.events.StartElement; |
aoqi@0 | 43 | |
aoqi@0 | 44 | |
aoqi@0 | 45 | public class StartElementEvent extends EventBase implements StartElement { |
aoqi@0 | 46 | |
aoqi@0 | 47 | private Map _attributes; |
aoqi@0 | 48 | private List _namespaces; |
aoqi@0 | 49 | private NamespaceContext _context = null; |
aoqi@0 | 50 | private QName _qname; |
aoqi@0 | 51 | |
aoqi@0 | 52 | public void reset() { |
aoqi@0 | 53 | if (_attributes != null) _attributes.clear(); |
aoqi@0 | 54 | if (_namespaces != null) _namespaces.clear(); |
aoqi@0 | 55 | if (_context != null) _context = null; |
aoqi@0 | 56 | } |
aoqi@0 | 57 | |
aoqi@0 | 58 | public StartElementEvent() { |
aoqi@0 | 59 | init(); |
aoqi@0 | 60 | } |
aoqi@0 | 61 | |
aoqi@0 | 62 | public StartElementEvent(String prefix, String uri, String localpart) { |
aoqi@0 | 63 | init(); |
aoqi@0 | 64 | if (uri == null) uri = ""; |
aoqi@0 | 65 | if (prefix == null) prefix =""; |
aoqi@0 | 66 | _qname = new QName(uri, localpart, prefix); |
aoqi@0 | 67 | setEventType(START_ELEMENT); |
aoqi@0 | 68 | } |
aoqi@0 | 69 | |
aoqi@0 | 70 | public StartElementEvent(QName qname) { |
aoqi@0 | 71 | init(); |
aoqi@0 | 72 | _qname = qname; |
aoqi@0 | 73 | } |
aoqi@0 | 74 | |
aoqi@0 | 75 | public StartElementEvent(StartElement startelement) { |
aoqi@0 | 76 | this(startelement.getName()); |
aoqi@0 | 77 | addAttributes(startelement.getAttributes()); |
aoqi@0 | 78 | addNamespaces(startelement.getNamespaces()); |
aoqi@0 | 79 | } |
aoqi@0 | 80 | |
aoqi@0 | 81 | protected void init() { |
aoqi@0 | 82 | setEventType(XMLStreamConstants.START_ELEMENT); |
aoqi@0 | 83 | _attributes = new HashMap(); |
aoqi@0 | 84 | _namespaces = new ArrayList(); |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | // ---------------------methods defined by StartElement-----------------// |
aoqi@0 | 88 | /** |
aoqi@0 | 89 | * Get the name of this event |
aoqi@0 | 90 | * @return the qualified name of this event |
aoqi@0 | 91 | */ |
aoqi@0 | 92 | public QName getName() { |
aoqi@0 | 93 | return _qname; |
aoqi@0 | 94 | } |
aoqi@0 | 95 | /** |
aoqi@0 | 96 | * Returns an Iterator of non-namespace declared attributes |
aoqi@0 | 97 | * returns an empty iterator if there are no attributes. The |
aoqi@0 | 98 | * iterator must contain only implementations of the javax.xml.stream.Attribute |
aoqi@0 | 99 | * interface. Attributes are fundamentally unordered and may not be reported |
aoqi@0 | 100 | * in any order. |
aoqi@0 | 101 | * |
aoqi@0 | 102 | * @return a readonly Iterator over Attribute interfaces, or an |
aoqi@0 | 103 | * empty iterator |
aoqi@0 | 104 | */ |
aoqi@0 | 105 | public Iterator getAttributes() { |
aoqi@0 | 106 | if(_attributes != null){ |
aoqi@0 | 107 | Collection coll = _attributes.values(); |
aoqi@0 | 108 | return new ReadIterator(coll.iterator()); |
aoqi@0 | 109 | } |
aoqi@0 | 110 | return EmptyIterator.getInstance(); |
aoqi@0 | 111 | } |
aoqi@0 | 112 | |
aoqi@0 | 113 | /** |
aoqi@0 | 114 | * Returns an Iterator of namespaces declared on this element. |
aoqi@0 | 115 | * This Iterator does not contain previously declared namespaces |
aoqi@0 | 116 | * unless they appear on the current START_ELEMENT. |
aoqi@0 | 117 | * Therefore this list may contain redeclared namespaces and duplicate namespace |
aoqi@0 | 118 | * declarations. Use the getNamespaceContext() method to get the |
aoqi@0 | 119 | * current context of namespace declarations. |
aoqi@0 | 120 | * |
aoqi@0 | 121 | * <p>The iterator must contain only implementations of the |
aoqi@0 | 122 | * javax.xml.stream.Namespace interface. |
aoqi@0 | 123 | * |
aoqi@0 | 124 | * <p>A Namespace is an Attribute. One |
aoqi@0 | 125 | * can iterate over a list of namespaces as a list of attributes. |
aoqi@0 | 126 | * However this method returns only the list of namespaces |
aoqi@0 | 127 | * declared on this START_ELEMENT and does not |
aoqi@0 | 128 | * include the attributes declared on this START_ELEMENT. |
aoqi@0 | 129 | * |
aoqi@0 | 130 | * @return a readonly Iterator over Namespace interfaces, or an |
aoqi@0 | 131 | * empty iterator if there are no namespaces. |
aoqi@0 | 132 | * |
aoqi@0 | 133 | */ |
aoqi@0 | 134 | public Iterator getNamespaces() { |
aoqi@0 | 135 | if(_namespaces != null){ |
aoqi@0 | 136 | return new ReadIterator(_namespaces.iterator()); |
aoqi@0 | 137 | } |
aoqi@0 | 138 | return EmptyIterator.getInstance(); |
aoqi@0 | 139 | } |
aoqi@0 | 140 | |
aoqi@0 | 141 | /** |
aoqi@0 | 142 | * Returns the attribute referred to by this name |
aoqi@0 | 143 | * @param qname the qname of the desired name |
aoqi@0 | 144 | * @return the attribute corresponding to the name value or null |
aoqi@0 | 145 | */ |
aoqi@0 | 146 | public Attribute getAttributeByName(QName qname) { |
aoqi@0 | 147 | if(qname == null) |
aoqi@0 | 148 | return null; |
aoqi@0 | 149 | return (Attribute)_attributes.get(qname); |
aoqi@0 | 150 | } |
aoqi@0 | 151 | |
aoqi@0 | 152 | /** Gets a read-only namespace context. If no context is |
aoqi@0 | 153 | * available this method will return an empty namespace context. |
aoqi@0 | 154 | * The NamespaceContext contains information about all namespaces |
aoqi@0 | 155 | * in scope for this StartElement. |
aoqi@0 | 156 | * |
aoqi@0 | 157 | * @return the current namespace context |
aoqi@0 | 158 | */ |
aoqi@0 | 159 | public NamespaceContext getNamespaceContext() { |
aoqi@0 | 160 | return _context; |
aoqi@0 | 161 | } |
aoqi@0 | 162 | // ---------------------end of methods defined by StartElement-----------------// |
aoqi@0 | 163 | |
aoqi@0 | 164 | public void setName(QName qname) { |
aoqi@0 | 165 | this._qname = qname; |
aoqi@0 | 166 | } |
aoqi@0 | 167 | |
aoqi@0 | 168 | |
aoqi@0 | 169 | public String getNamespace(){ |
aoqi@0 | 170 | return _qname.getNamespaceURI(); |
aoqi@0 | 171 | } |
aoqi@0 | 172 | |
aoqi@0 | 173 | /** |
aoqi@0 | 174 | * Gets the value that the prefix is bound to in the |
aoqi@0 | 175 | * context of this element. Returns null if |
aoqi@0 | 176 | * the prefix is not bound in this context |
aoqi@0 | 177 | * @param prefix the prefix to lookup |
aoqi@0 | 178 | * @return the uri bound to the prefix or null |
aoqi@0 | 179 | */ |
aoqi@0 | 180 | public String getNamespaceURI(String prefix) { |
aoqi@0 | 181 | //first check if the URI was supplied when creating this startElement event |
aoqi@0 | 182 | if( getNamespace() != null ) return getNamespace(); |
aoqi@0 | 183 | //else check the namespace context |
aoqi@0 | 184 | if(_context != null) |
aoqi@0 | 185 | return _context.getNamespaceURI(prefix); |
aoqi@0 | 186 | return null; |
aoqi@0 | 187 | } |
aoqi@0 | 188 | |
aoqi@0 | 189 | public String toString() { |
aoqi@0 | 190 | final StringBuilder sb = new StringBuilder(64); |
aoqi@0 | 191 | |
aoqi@0 | 192 | sb.append('<').append(nameAsString()); |
aoqi@0 | 193 | |
aoqi@0 | 194 | if(_attributes != null){ |
aoqi@0 | 195 | Iterator it = this.getAttributes(); |
aoqi@0 | 196 | Attribute attr = null; |
aoqi@0 | 197 | while(it.hasNext()){ |
aoqi@0 | 198 | attr = (Attribute)it.next(); |
aoqi@0 | 199 | sb.append(' ').append(attr.toString()); |
aoqi@0 | 200 | } |
aoqi@0 | 201 | } |
aoqi@0 | 202 | |
aoqi@0 | 203 | if(_namespaces != null){ |
aoqi@0 | 204 | Iterator it = _namespaces.iterator(); |
aoqi@0 | 205 | Namespace attr = null; |
aoqi@0 | 206 | while(it.hasNext()){ |
aoqi@0 | 207 | attr = (Namespace)it.next(); |
aoqi@0 | 208 | sb.append(' ').append(attr.toString()); |
aoqi@0 | 209 | } |
aoqi@0 | 210 | } |
aoqi@0 | 211 | sb.append('>'); |
aoqi@0 | 212 | return sb.toString(); |
aoqi@0 | 213 | } |
aoqi@0 | 214 | |
aoqi@0 | 215 | /** Return this event as String |
aoqi@0 | 216 | * @return String Event returned as string. |
aoqi@0 | 217 | */ |
aoqi@0 | 218 | public String nameAsString() { |
aoqi@0 | 219 | if("".equals(_qname.getNamespaceURI())) |
aoqi@0 | 220 | return _qname.getLocalPart(); |
aoqi@0 | 221 | if(_qname.getPrefix() != null) |
aoqi@0 | 222 | return "['" + _qname.getNamespaceURI() + "']:" + _qname.getPrefix() + ":" + _qname.getLocalPart(); |
aoqi@0 | 223 | else |
aoqi@0 | 224 | return "['" + _qname.getNamespaceURI() + "']:" + _qname.getLocalPart(); |
aoqi@0 | 225 | } |
aoqi@0 | 226 | |
aoqi@0 | 227 | |
aoqi@0 | 228 | public void setNamespaceContext(NamespaceContext context) { |
aoqi@0 | 229 | _context = context; |
aoqi@0 | 230 | } |
aoqi@0 | 231 | |
aoqi@0 | 232 | public void addAttribute(Attribute attr){ |
aoqi@0 | 233 | _attributes.put(attr.getName(),attr); |
aoqi@0 | 234 | } |
aoqi@0 | 235 | |
aoqi@0 | 236 | public void addAttributes(Iterator attrs){ |
aoqi@0 | 237 | if(attrs != null) { |
aoqi@0 | 238 | while(attrs.hasNext()){ |
aoqi@0 | 239 | Attribute attr = (Attribute)attrs.next(); |
aoqi@0 | 240 | _attributes.put(attr.getName(),attr); |
aoqi@0 | 241 | } |
aoqi@0 | 242 | } |
aoqi@0 | 243 | } |
aoqi@0 | 244 | |
aoqi@0 | 245 | public void addNamespace(Namespace namespace){ |
aoqi@0 | 246 | if(namespace != null) { |
aoqi@0 | 247 | _namespaces.add(namespace); |
aoqi@0 | 248 | } |
aoqi@0 | 249 | } |
aoqi@0 | 250 | |
aoqi@0 | 251 | public void addNamespaces(Iterator namespaces){ |
aoqi@0 | 252 | if(namespaces != null) { |
aoqi@0 | 253 | while(namespaces.hasNext()){ |
aoqi@0 | 254 | Namespace namespace = (Namespace)namespaces.next(); |
aoqi@0 | 255 | _namespaces.add(namespace); |
aoqi@0 | 256 | } |
aoqi@0 | 257 | } |
aoqi@0 | 258 | } |
aoqi@0 | 259 | |
aoqi@0 | 260 | } |