325N/A/*
325N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.bind.v2.runtime.unmarshaller;
325N/A
325N/Aimport javax.xml.namespace.QName;
325N/A
325N/Aimport com.sun.xml.internal.bind.v2.runtime.Name;
325N/A
325N/Aimport org.xml.sax.Attributes;
325N/A
325N/A/**
325N/A * Represents an XML tag name (and attributes for start tags.)
325N/A *
325N/A * <p>
325N/A * This object is used so reduce the number of method call parameters
325N/A * among unmarshallers.
325N/A *
325N/A * An instance of this is expected to be reused by the caller of
325N/A * {@link XmlVisitor}. Note that the rest of the unmarshaller may
325N/A * modify any of the fields while processing an event (such as to
325N/A * intern strings, replace attributes),
325N/A * so {@link XmlVisitor} should reset all fields for each use.
325N/A *
325N/A * <p>
325N/A * The 'qname' parameter, which holds the qualified name of the tag
325N/A * (such as 'foo:bar' or 'zot'), is not used in the typical unmarshalling
325N/A * route and it's also expensive to compute for some input.
325N/A * Thus this parameter is computed lazily.
325N/A *
325N/A * @author Kohsuke Kawaguchi
325N/A */
325N/A@SuppressWarnings({"StringEquality"})
325N/Apublic abstract class TagName {
325N/A /**
325N/A * URI of the attribute/element name.
325N/A *
325N/A * Can be empty, but never null. Interned.
325N/A */
325N/A public String uri;
325N/A /**
325N/A * Local part of the attribute/element name.
325N/A *
325N/A * Never be null. Interned.
325N/A */
325N/A public String local;
325N/A
325N/A /**
325N/A * Used only for the enterElement event.
325N/A * Otherwise the value is undefined.
325N/A *
325N/A * This might be {@link AttributesEx}.
325N/A */
325N/A public Attributes atts;
325N/A
325N/A public TagName() {
325N/A }
325N/A
325N/A /**
325N/A * Checks if the given name pair matches this name.
325N/A */
325N/A public final boolean matches( String nsUri, String local ) {
325N/A return this.uri==nsUri && this.local==local;
325N/A }
325N/A
325N/A /**
325N/A * Checks if the given name pair matches this name.
325N/A */
325N/A public final boolean matches( Name name ) {
325N/A return this.local==name.localName && this.uri==name.nsUri;
325N/A }
325N/A
325N/A// /**
325N/A// * @return
325N/A// * Can be empty but always non-null. NOT interned.
325N/A// */
325N/A// public final String getPrefix() {
325N/A// int idx = qname.indexOf(':');
325N/A// if(idx<0) return "";
325N/A// else return qname.substring(0,idx);
325N/A// }
325N/A
325N/A public String toString() {
325N/A return '{'+uri+'}'+local;
325N/A }
325N/A
325N/A /**
325N/A * Gets the qualified name of the tag.
325N/A *
325N/A * @return never null.
325N/A */
325N/A public abstract String getQname();
325N/A
325N/A /**
325N/A * Gets the prefix. This is slow.
325N/A *
325N/A * @return can be "" but never null.
325N/A */
325N/A public String getPrefix() {
325N/A String qname = getQname();
325N/A int idx = qname.indexOf(':');
325N/A if(idx<0) return "";
325N/A else return qname.substring(0,idx);
325N/A }
325N/A
325N/A /**
325N/A * Creates {@link QName}.
325N/A */
325N/A public QName createQName() {
325N/A return new QName(uri,local,getPrefix());
325N/A }
325N/A}