src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/unmarshaller/TagName.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/bind/v2/runtime/unmarshaller/TagName.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,134 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 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 +
    1.29 +package com.sun.xml.internal.bind.v2.runtime.unmarshaller;
    1.30 +
    1.31 +import javax.xml.namespace.QName;
    1.32 +
    1.33 +import com.sun.xml.internal.bind.v2.runtime.Name;
    1.34 +
    1.35 +import org.xml.sax.Attributes;
    1.36 +
    1.37 +/**
    1.38 + * Represents an XML tag name (and attributes for start tags.)
    1.39 + *
    1.40 + * <p>
    1.41 + * This object is used so reduce the number of method call parameters
    1.42 + * among unmarshallers.
    1.43 + *
    1.44 + * An instance of this is expected to be reused by the caller of
    1.45 + * {@link XmlVisitor}. Note that the rest of the unmarshaller may
    1.46 + * modify any of the fields while processing an event (such as to
    1.47 + * intern strings, replace attributes),
    1.48 + * so {@link XmlVisitor} should reset all fields for each use.
    1.49 + *
    1.50 + * <p>
    1.51 + * The 'qname' parameter, which holds the qualified name of the tag
    1.52 + * (such as 'foo:bar' or 'zot'), is not used in the typical unmarshalling
    1.53 + * route and it's also expensive to compute for some input.
    1.54 + * Thus this parameter is computed lazily.
    1.55 + *
    1.56 + * @author Kohsuke Kawaguchi
    1.57 + */
    1.58 +@SuppressWarnings({"StringEquality"})
    1.59 +public abstract class TagName {
    1.60 +    /**
    1.61 +     * URI of the attribute/element name.
    1.62 +     *
    1.63 +     * Can be empty, but never null. Interned.
    1.64 +     */
    1.65 +    public String uri;
    1.66 +    /**
    1.67 +     * Local part of the attribute/element name.
    1.68 +     *
    1.69 +     * Never be null. Interned.
    1.70 +     */
    1.71 +    public String local;
    1.72 +
    1.73 +    /**
    1.74 +     * Used only for the enterElement event.
    1.75 +     * Otherwise the value is undefined.
    1.76 +     *
    1.77 +     * This might be {@link AttributesEx}.
    1.78 +     */
    1.79 +    public Attributes atts;
    1.80 +
    1.81 +    public TagName() {
    1.82 +    }
    1.83 +
    1.84 +    /**
    1.85 +     * Checks if the given name pair matches this name.
    1.86 +     */
    1.87 +    public final boolean matches( String nsUri, String local ) {
    1.88 +        return this.uri==nsUri && this.local==local;
    1.89 +    }
    1.90 +
    1.91 +    /**
    1.92 +     * Checks if the given name pair matches this name.
    1.93 +     */
    1.94 +    public final boolean matches( Name name ) {
    1.95 +        return this.local==name.localName && this.uri==name.nsUri;
    1.96 +    }
    1.97 +
    1.98 +//    /**
    1.99 +//     * @return
   1.100 +//     *      Can be empty but always non-null. NOT interned.
   1.101 +//     */
   1.102 +//    public final String getPrefix() {
   1.103 +//        int idx = qname.indexOf(':');
   1.104 +//        if(idx<0)   return "";
   1.105 +//        else        return qname.substring(0,idx);
   1.106 +//    }
   1.107 +
   1.108 +    public String toString() {
   1.109 +        return '{'+uri+'}'+local;
   1.110 +    }
   1.111 +
   1.112 +    /**
   1.113 +     * Gets the qualified name of the tag.
   1.114 +     *
   1.115 +     * @return never null.
   1.116 +     */
   1.117 +    public abstract String getQname();
   1.118 +
   1.119 +    /**
   1.120 +     * Gets the prefix. This is slow.
   1.121 +     *
   1.122 +     * @return can be "" but never null.
   1.123 +     */
   1.124 +    public String getPrefix() {
   1.125 +        String qname = getQname();
   1.126 +        int idx = qname.indexOf(':');
   1.127 +        if(idx<0)   return "";
   1.128 +        else        return qname.substring(0,idx);
   1.129 +    }
   1.130 +
   1.131 +    /**
   1.132 +     * Creates {@link QName}.
   1.133 +     */
   1.134 +    public QName createQName() {
   1.135 +        return new QName(uri,local,getPrefix());
   1.136 +    }
   1.137 +}

mercurial