src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/stax/events/EndElementEvent.java

changeset 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/stax/events/EndElementEvent.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,126 @@
     1.4 +/*
     1.5 + * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + *
    1.28 + * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
    1.29 + */
    1.30 +
    1.31 +package com.sun.xml.internal.fastinfoset.stax.events ;
    1.32 +
    1.33 +import java.util.ArrayList;
    1.34 +import java.util.Iterator;
    1.35 +import java.util.List;
    1.36 +
    1.37 +import javax.xml.namespace.QName;
    1.38 +import javax.xml.stream.events.EndElement;
    1.39 +import javax.xml.stream.events.Namespace;
    1.40 +
    1.41 +import com.sun.xml.internal.fastinfoset.stax.events.EmptyIterator;
    1.42 +
    1.43 +
    1.44 +public class EndElementEvent extends EventBase implements EndElement {
    1.45 +
    1.46 +    List _namespaces = null;
    1.47 +    QName _qname ;
    1.48 +
    1.49 +    public void reset() {
    1.50 +        if (_namespaces != null) _namespaces.clear();
    1.51 +    }
    1.52 +
    1.53 +    public EndElementEvent() {
    1.54 +        setEventType(END_ELEMENT);
    1.55 +    }
    1.56 +
    1.57 +    public EndElementEvent(String prefix, String namespaceURI, String localpart) {
    1.58 +        _qname = getQName(namespaceURI,localpart,prefix);
    1.59 +        setEventType(END_ELEMENT);
    1.60 +    }
    1.61 +
    1.62 +    public EndElementEvent(QName qname) {
    1.63 +        _qname = qname;
    1.64 +        setEventType(END_ELEMENT);
    1.65 +    }
    1.66 +
    1.67 +  /**
    1.68 +   * Get the name of this event
    1.69 +   * @return the qualified name of this event
    1.70 +   */
    1.71 +    public QName getName() {
    1.72 +        return _qname;
    1.73 +    }
    1.74 +
    1.75 +    public void setName(QName qname) {
    1.76 +        _qname = qname;
    1.77 +    }
    1.78 +
    1.79 +
    1.80 +    /** Returns an Iterator of namespaces that have gone out
    1.81 +     * of scope.  Returns an empty iterator if no namespaces have gone
    1.82 +     * out of scope.
    1.83 +     * @return an Iterator over Namespace interfaces, or an
    1.84 +     * empty iterator
    1.85 +     */
    1.86 +    public Iterator getNamespaces() {
    1.87 +        if(_namespaces != null)
    1.88 +            return _namespaces.iterator();
    1.89 +        return EmptyIterator.getInstance();
    1.90 +    }
    1.91 +
    1.92 +    public void addNamespace(Namespace namespace){
    1.93 +        if (_namespaces == null) {
    1.94 +            _namespaces = new ArrayList();
    1.95 +        }
    1.96 +        _namespaces.add(namespace);
    1.97 +    }
    1.98 +
    1.99 +    public String toString() {
   1.100 +        StringBuffer sb = new StringBuffer();
   1.101 +        sb.append("</").append(nameAsString());
   1.102 +        Iterator namespaces = getNamespaces();
   1.103 +        while(namespaces.hasNext()) {
   1.104 +            sb.append(" ").append(namespaces.next().toString());
   1.105 +        }
   1.106 +        sb.append(">");
   1.107 +        return sb.toString();
   1.108 +    }
   1.109 +
   1.110 +
   1.111 +    private String nameAsString() {
   1.112 +        if("".equals(_qname.getNamespaceURI()))
   1.113 +            return _qname.getLocalPart();
   1.114 +        if(_qname.getPrefix() != null)
   1.115 +            return "['" + _qname.getNamespaceURI() + "']:" + _qname.getPrefix() + ":" + _qname.getLocalPart();
   1.116 +        else
   1.117 +            return "['" + _qname.getNamespaceURI() + "']:" + _qname.getLocalPart();
   1.118 +    }
   1.119 +    private QName getQName(String uri, String localPart, String prefix){
   1.120 +        QName qn = null;
   1.121 +        if(prefix != null && uri != null)
   1.122 +            qn = new QName(uri, localPart, prefix);
   1.123 +        else if(prefix == null && uri != null)
   1.124 +            qn = new QName(uri, localPart);
   1.125 +        else if(prefix == null && uri == null)
   1.126 +            qn = new QName(localPart);
   1.127 +        return qn;
   1.128 +    }
   1.129 +}

mercurial