14c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson/*
24c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one or more
34c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * contributor license agreements.  See the NOTICE file distributed with
44c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * this work for additional information regarding copyright ownership.
54c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * The ASF licenses this file to You under the Apache License, Version 2.0
64c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * (the "License"); you may not use this file except in compliance with
74c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * the License.  You may obtain a copy of the License at
84c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson *
94c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson *     http://www.apache.org/licenses/LICENSE-2.0
104c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson *
114c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Unless required by applicable law or agreed to in writing, software
124c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
134c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
144c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * See the License for the specific language governing permissions and
154c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * limitations under the License.
164c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */
174c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
184c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson// $Id: QName.java 754581 2009-03-15 01:32:39Z mrglavas $
194c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
204c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonpackage javax.xml.namespace;
214c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
224c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport java.io.IOException;
234c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport java.io.ObjectInputStream;
244c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport java.io.Serializable;
254c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport java.security.AccessController;
264c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport java.security.PrivilegedAction;
274c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
284c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonimport javax.xml.XMLConstants;
294c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
304c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson/**
314c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * <p><code>QName</code> represents a <strong>qualified name</strong>
324c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * as defined in the XML specifications: <a
334c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * href="http://www.w3.org/TR/xmlschema-2/#QName">XML Schema Part2:
344c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * Datatypes specification</a>, <a
354c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * href="http://www.w3.org/TR/REC-xml-names/#ns-qualnames">Namespaces
364c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * in XML</a>, <a
374c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * href="http://www.w3.org/XML/xml-names-19990114-errata">Namespaces
384c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * in XML Errata</a>.</p>
394c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson *
404c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * <p>The value of a <code>QName</code> contains a <strong>Namespace
414c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * URI</strong>, <strong>local part</strong> and
424c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * <strong>prefix</strong>.</p>
434c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson *
444c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * <p>The prefix is included in <code>QName</code> to retain lexical
454c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * information <strong><em>when present</em></strong> in an {@link
464c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * javax.xml.transform.Source XML input source}. The prefix is
474c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * <strong><em>NOT</em></strong> used in {@link #equals(Object)
484c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * QName.equals(Object)} or to compute the {@link #hashCode()
494c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * QName.hashCode()}.  Equality and the hash code are defined using
504c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * <strong><em>only</em></strong> the Namespace URI and local part.</p>
514c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson *
524c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * <p>If not specified, the Namespace URI is set to {@link
534c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI}.
544c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * If not specified, the prefix is set to {@link
554c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * javax.xml.XMLConstants#DEFAULT_NS_PREFIX
564c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * XMLConstants.DEFAULT_NS_PREFIX}.</p>
574c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson *
584c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * <p><code>QName</code> is immutable.</p>
594c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson *
604c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
614c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @version $Revision: 754581 $, $Date: 2009-03-14 18:32:39 -0700 (Sat, 14 Mar 2009) $
624c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @see <a href="http://www.w3.org/TR/xmlschema-2/#QName">XML Schema Part2: Datatypes specification</a>
634c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @see <a href="http://www.w3.org/TR/REC-xml-names/#ns-qualnames">Namespaces in XML</a>
644c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @see <a href="http://www.w3.org/XML/xml-names-19990114-errata">Namespaces in XML Errata</a>
654c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson * @since 1.5
664c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson */
674c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
684c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilsonpublic class QName implements Serializable {
694c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
704c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
714c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>Stream Unique Identifier.</p>
724c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
734c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>To enable the compatibility <code>serialVersionUID</code>
744c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * set the System Property
754c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <code>org.apache.xml.namespace.QName.useCompatibleSerialVersionUID</code>
764c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * to a value of "1.0".</p>
774c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
784c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    private static final long serialVersionUID;
794c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
804c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
814c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>The original default Stream Unique Identifier.</p>
824c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
834c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    private static final long defaultSerialVersionUID = -9120448754896609940L;
844c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
854c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
864c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>The compatibility Stream Unique Identifier that was introduced
874c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * with Java 5 SE SDK.</p>
884c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
894c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    private static final long compatabilitySerialVersionUID = 4418622981026545151L;
904c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
914c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    static {
924c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        String compatPropValue = null;
934c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        try {
944c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            compatPropValue = (String)AccessController.doPrivileged(
954c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                    new PrivilegedAction() {
964c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                        public Object run() {
974c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                            return System.getProperty("org.apache.xml.namespace.QName.useCompatibleSerialVersionUID");
984c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                        }
994c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                    });
1004c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        }
1014c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        catch (Exception e) {}
1024c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        // If 1.0 use compatibility serialVersionUID
1034c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        serialVersionUID = !"1.0".equals(compatPropValue) ? defaultSerialVersionUID : compatabilitySerialVersionUID;
1044c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    }
1054c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
1064c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
1074c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>Namespace URI of this <code>QName</code>.</p>
1084c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
1094c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    private final String namespaceURI;
1104c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
1114c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
1124c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>local part of this <code>QName</code>.</p>
1134c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
1144c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    private final String localPart;
1154c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
1164c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
1174c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>prefix of this <code>QName</code>.</p>
1184c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
1194c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    private String prefix;
1204c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
1214c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
1224c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p><code>String</code> representation of this <code>QName</code>.</p>
1234c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
1244c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    private transient String qNameAsString;
1254c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
1264c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
1274c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p><code>QName</code> constructor specifying the Namespace URI
1284c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * and local part.</p>
1294c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
1304c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>If the Namespace URI is <code>null</code>, it is set to
1314c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * {@link javax.xml.XMLConstants#NULL_NS_URI
1324c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * XMLConstants.NULL_NS_URI}.  This value represents no
1334c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * explicitly defined Namespace as defined by the <a
1344c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * href="http://www.w3.org/TR/REC-xml-names/#ns-qualnames">Namespaces
1354c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * in XML</a> specification.  This action preserves compatible
1364c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * behavior with QName 1.0.  Explicitly providing the {@link
1374c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * javax.xml.XMLConstants#NULL_NS_URI
1384c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * XMLConstants.NULL_NS_URI} value is the preferred coding
1394c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * style.</p>
1404c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
1414c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>If the local part is <code>null</code> an
1424c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <code>IllegalArgumentException</code> is thrown.
1434c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * A local part of "" is allowed to preserve
1444c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * compatible behavior with QName 1.0. </p>
1454c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
1464c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>When using this constructor, the prefix is set to {@link
1474c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * javax.xml.XMLConstants#DEFAULT_NS_PREFIX
1484c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * XMLConstants.DEFAULT_NS_PREFIX}.</p>
1494c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
1504c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>The Namespace URI is not validated as a
1514c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <a href="http://www.ietf.org/rfc/rfc2396.txt">URI reference</a>.
1524c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * The local part is not validated as a
1534c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName">NCName</a>
1544c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * as specified in <a href="http://www.w3.org/TR/REC-xml-names/">Namespaces
1554c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * in XML</a>.</p>
1564c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
1574c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @param namespaceURI Namespace URI of the <code>QName</code>
1584c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @param localPart    local part of the <code>QName</code>
1594c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
1604c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @see #QName(String namespaceURI, String localPart, String
1614c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * prefix) QName(String namespaceURI, String localPart, String
1624c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * prefix)
1634c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
1644c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    public QName(final String namespaceURI, final String localPart) {
1654c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        this(namespaceURI, localPart, XMLConstants.DEFAULT_NS_PREFIX);
1664c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    }
1674c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
1684c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
1694c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p><code>QName</code> constructor specifying the Namespace URI,
1704c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * local part and prefix.</p>
1714c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
1724c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>If the Namespace URI is <code>null</code>, it is set to
1734c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * {@link javax.xml.XMLConstants#NULL_NS_URI
1744c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * XMLConstants.NULL_NS_URI}.  This value represents no
1754c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * explicitly defined Namespace as defined by the <a
1764c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * href="http://www.w3.org/TR/REC-xml-names/#ns-qualnames">Namespaces
1774c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * in XML</a> specification.  This action preserves compatible
1784c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * behavior with QName 1.0.  Explicitly providing the {@link
1794c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * javax.xml.XMLConstants#NULL_NS_URI
1804c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * XMLConstants.NULL_NS_URI} value is the preferred coding
1814c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * style.</p>
1824c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
1834c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>If the local part is <code>null</code> an
1844c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <code>IllegalArgumentException</code> is thrown.
1854c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * A local part of "" is allowed to preserve
1864c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * compatible behavior with QName 1.0. </p>
1874c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
1884c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>If the prefix is <code>null</code>, an
1894c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <code>IllegalArgumentException</code> is thrown.  Use {@link
1904c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * javax.xml.XMLConstants#DEFAULT_NS_PREFIX
1914c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * XMLConstants.DEFAULT_NS_PREFIX} to explicitly indicate that no
1924c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * prefix is present or the prefix is not relevant.</p>
1934c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
1944c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>The Namespace URI is not validated as a
1954c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <a href="http://www.ietf.org/rfc/rfc2396.txt">URI reference</a>.
1964c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * The local part and prefix are not validated as a
1974c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName">NCName</a>
1984c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * as specified in <a href="http://www.w3.org/TR/REC-xml-names/">Namespaces
1994c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * in XML</a>.</p>
2004c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
2014c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @param namespaceURI Namespace URI of the <code>QName</code>
2024c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @param localPart    local part of the <code>QName</code>
2034c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @param prefix       prefix of the <code>QName</code>
2044c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
2054c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    public QName(String namespaceURI, String localPart, String prefix) {
2064c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
2074c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        // map null Namespace URI to default to preserve compatibility with QName 1.0
2084c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        if (namespaceURI == null) {
2094c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            this.namespaceURI = XMLConstants.NULL_NS_URI;
2104c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        } else {
2114c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            this.namespaceURI = namespaceURI;
2124c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        }
2134c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
2144c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        // local part is required.  "" is allowed to preserve compatibility with QName 1.0
2154c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        if (localPart == null) {
2164c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            throw new IllegalArgumentException("local part cannot be \"null\" when creating a QName");
2174c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        }
2184c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        this.localPart = localPart;
2194c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
2204c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        // prefix is required
2214c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        if (prefix == null) {
2224c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            throw new IllegalArgumentException("prefix cannot be \"null\" when creating a QName");
2234c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        }
2244c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        this.prefix = prefix;
2254c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    }
2264c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
2274c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
2284c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p><code>QName</code> constructor specifying the local part.</p>
2294c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
2304c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>If the local part is <code>null</code> an
2314c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <code>IllegalArgumentException</code> is thrown.
2324c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * A local part of "" is allowed to preserve
2334c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * compatible behavior with QName 1.0. </p>
2344c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
2354c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>When using this constructor, the Namespace URI is set to
2364c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * {@link javax.xml.XMLConstants#NULL_NS_URI
2374c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * XMLConstants.NULL_NS_URI} and the prefix is set to {@link
2384c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * javax.xml.XMLConstants#DEFAULT_NS_PREFIX
2394c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * XMLConstants.DEFAULT_NS_PREFIX}.</p>
2404c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
2414c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p><em>In an XML context, all Element and Attribute names exist
2424c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * in the context of a Namespace.  Making this explicit during the
2434c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * construction of a <code>QName</code> helps prevent hard to
2444c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * diagnosis XML validity errors.  The constructors {@link
2454c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * #QName(String namespaceURI, String localPart) QName(String
2464c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * namespaceURI, String localPart)} and
2474c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * {@link #QName(String namespaceURI, String localPart, String prefix)}
2484c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * are preferred.</em></p>
2494c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
2504c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>The local part is not validated as a
2514c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName">NCName</a>
2524c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * as specified in <a href="http://www.w3.org/TR/REC-xml-names/">Namespaces
2534c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * in XML</a>.</p>
2544c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
2554c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @param localPart local part of the <code>QName</code>
2564c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @see #QName(String namespaceURI, String localPart) QName(String
2574c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * namespaceURI, String localPart)
2584c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @see #QName(String namespaceURI, String localPart, String
2594c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * prefix) QName(String namespaceURI, String localPart, String
2604c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * prefix)
2614c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
2624c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    public QName(String localPart) {
2634c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        this(
2644c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            XMLConstants.NULL_NS_URI,
2654c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            localPart,
2664c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            XMLConstants.DEFAULT_NS_PREFIX);
2674c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    }
2684c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
2694c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
2704c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>Get the Namespace URI of this <code>QName</code>.</p>
2714c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
2724c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @return Namespace URI of this <code>QName</code>
2734c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
2744c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    public String getNamespaceURI() {
2754c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        return namespaceURI;
2764c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    }
2774c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
2784c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
2794c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>Get the local part of this <code>QName</code>.</p>
2804c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
2814c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *  @return local part of this <code>QName</code>
2824c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
2834c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    public String getLocalPart() {
2844c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        return localPart;
2854c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    }
2864c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
2874c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
2884c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>Get the prefix of this <code>QName</code>.</p>
2894c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
2904c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>The prefix assigned to a <code>QName</code> might
2914c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <strong><em>NOT</em></strong> be valid in a different
2924c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * context. For example, a <code>QName</code> may be assigned a
2934c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * prefix in the context of parsing a document but that prefix may
2944c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * be invalid in the context of a different document.</p>
2954c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
2964c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *  @return prefix of this <code>QName</code>
2974c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
2984c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    public String getPrefix() {
2994c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        return prefix;
3004c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    }
3014c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
3024c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
3034c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>Test this <code>QName</code> for equality with another
3044c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <code>Object</code>.</p>
3054c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
3064c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>If the <code>Object</code> to be tested is not a
3074c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <code>QName</code> or is <code>null</code>, then this method
3084c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * returns <code>false</code>.</p>
3094c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
3104c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>Two <code>QName</code>s are considered equal if and only if
3114c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * both the Namespace URI and local part are equal. This method
3124c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * uses <code>String.equals()</code> to check equality of the
3134c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * Namespace URI and local part. The prefix is
3144c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <strong><em>NOT</em></strong> used to determine equality.</p>
3154c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
3164c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>This method satisfies the general contract of {@link
3174c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * java.lang.Object#equals(Object) Object.equals(Object)}</p>
3184c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
3194c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @param objectToTest the <code>Object</code> to test for
3204c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * equality with this <code>QName</code>
3214c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @return <code>true</code> if the given <code>Object</code> is
3224c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * equal to this <code>QName</code> else <code>false</code>
3234c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
3244c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    public final boolean equals(Object objectToTest) {
3254c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        // Is this the same object?
3264c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        if (objectToTest == this) {
3274c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            return true;
3284c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        }
3294c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        // Is this a QName?
3304c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        if (objectToTest instanceof QName) {
3314c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            QName qName = (QName) objectToTest;
3324c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            return localPart.equals(qName.localPart) && namespaceURI.equals(qName.namespaceURI);
3334c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        }
3344c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        return false;
3354c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    }
3364c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
3374c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
3384c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>Generate the hash code for this <code>QName</code>.</p>
3394c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
3404c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>The hash code is calculated using both the Namespace URI and
3414c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * the local part of the <code>QName</code>.  The prefix is
3424c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <strong><em>NOT</em></strong> used to calculate the hash
3434c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * code.</p>
3444c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
3454c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>This method satisfies the general contract of {@link
3464c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * java.lang.Object#hashCode() Object.hashCode()}.</p>
3474c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
3484c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @return hash code for this <code>QName</code> <code>Object</code>
3494c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
3504c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    public final int hashCode() {
3514c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        return namespaceURI.hashCode() ^ localPart.hashCode();
3524c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    }
3534c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
3544c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	/**
3554c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * <p><code>String</code> representation of this
3564c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * <code>QName</code>.</p>
3574c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 *
3584c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * <p>The commonly accepted way of representing a <code>QName</code>
3594c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * as a <code>String</code> was <a href="http://jclark.com/xml/xmlns.htm">defined</a>
3604c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * by James Clark.  Although this is not a <em>standard</em>
3614c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * specification, it is in common use,  e.g. {@link javax.xml.transform.Transformer#setParameter(String name, Object value)}.
3624c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * This implementation represents a <code>QName</code> as:
3634c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * "{" + Namespace URI + "}" + local part.  If the Namespace URI
3644c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * <code>.equals(XMLConstants.NULL_NS_URI)</code>, only the
3654c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * local part is returned.  An appropriate use of this method is
3664c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * for debugging or logging for human consumption.</p>
3674c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 *
3684c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * <p>Note the prefix value is <strong><em>NOT</em></strong>
3694c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * returned as part of the <code>String</code> representation.</p>
3704c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 *
3714c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * <p>This method satisfies the general contract of {@link
3724c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * java.lang.Object#toString() Object.toString()}.</p>
3734c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 *
3744c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 * @return <code>String</code> representation of this <code>QName</code>
3754c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson	 */
3764c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    public String toString() {
3774c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        String _qNameAsString = qNameAsString;
3784c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        if (_qNameAsString == null) {
3794c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            final int nsLength = namespaceURI.length();
3804c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            if (nsLength == 0) {
3814c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                _qNameAsString = localPart;
3824c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            }
3834c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            else {
3844c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                StringBuffer buffer = new StringBuffer(nsLength + localPart.length() + 2);
3854c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                buffer.append('{');
3864c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                buffer.append(namespaceURI);
3874c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                buffer.append('}');
3884c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                buffer.append(localPart);
3894c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                _qNameAsString = buffer.toString();
3904c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            }
3914c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            qNameAsString = _qNameAsString;
3924c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        }
3934c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        return _qNameAsString;
3944c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    }
3954c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
3964c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /**
3974c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p><code>QName</code> derived from parsing the formatted
3984c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <code>String</code>.</p>
3994c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
4004c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>If the <code>String</code> is <code>null</code> or does not conform to
4014c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * {@link #toString() QName.toString()} formatting, an
4024c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <code>IllegalArgumentException</code> is thrown.</p>
4034c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
4044c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p><em>The <code>String</code> <strong>MUST</strong> be in the
4054c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * form returned by {@link #toString() QName.toString()}.</em></p>
4064c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
4074c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>The commonly accepted way of representing a <code>QName</code>
4084c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * as a <code>String</code> was <a href="http://jclark.com/xml/xmlns.htm">defined</a>
4094c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * by James Clark.  Although this is not a <em>standard</em>
4104c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * specification, it is in common use,  e.g. {@link javax.xml.transform.Transformer#setParameter(String name, Object value)}.
4114c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * This implementation parses a <code>String</code> formatted
4124c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * as: "{" + Namespace URI + "}" + local part.  If the Namespace
4134c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * URI <code>.equals(XMLConstants.NULL_NS_URI)</code>, only the
4144c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * local part should be provided.</p>
4154c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
4164c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>The prefix value <strong><em>CANNOT</em></strong> be
4174c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * represented in the <code>String</code> and will be set to
4184c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * {@link javax.xml.XMLConstants#DEFAULT_NS_PREFIX
4194c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * XMLConstants.DEFAULT_NS_PREFIX}.</p>
4204c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
4214c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>This method does not do full validation of the resulting
4224c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <code>QName</code>.
4234c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <p>The Namespace URI is not validated as a
4244c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <a href="http://www.ietf.org/rfc/rfc2396.txt">URI reference</a>.
4254c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * The local part is not validated as a
4264c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName">NCName</a>
4274c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * as specified in
4284c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <a href="http://www.w3.org/TR/REC-xml-names/">Namespaces in XML</a>.</p>
4294c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     *
4304c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @param qNameAsString <code>String</code> representation
4314c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * of the <code>QName</code>
4324c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @return <code>QName</code> corresponding to the given <code>String</code>
4334c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * @see #toString() QName.toString()
4344c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
4354c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    public static QName valueOf(String qNameAsString) {
4364c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
4374c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        // null is not valid
4384c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        if (qNameAsString == null) {
4394c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            throw new IllegalArgumentException("cannot create QName from \"null\" or \"\" String");
4404c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        }
4414c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
4424c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        // "" local part is valid to preserve compatible behavior with QName 1.0
4434c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        if (qNameAsString.length() == 0) {
4444c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            return new QName(
4454c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                XMLConstants.NULL_NS_URI,
4464c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                qNameAsString,
4474c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                XMLConstants.DEFAULT_NS_PREFIX);
4484c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        }
4494c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
4504c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        // local part only?
4514c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        if (qNameAsString.charAt(0) != '{') {
4524c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            return new QName(
4534c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                XMLConstants.NULL_NS_URI,
4544c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                qNameAsString,
4554c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                XMLConstants.DEFAULT_NS_PREFIX);
4564c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        }
4574c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
4584c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        // Namespace URI improperly specified?
4594c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        if (qNameAsString.startsWith("{" + XMLConstants.NULL_NS_URI + "}")) {
4604c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            throw new IllegalArgumentException(
4614c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                "Namespace URI .equals(XMLConstants.NULL_NS_URI), "
4624c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                + ".equals(\"" + XMLConstants.NULL_NS_URI + "\"), "
4634c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                + "only the local part, "
4644c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                + "\"" + qNameAsString.substring(2 + XMLConstants.NULL_NS_URI.length()) + "\", "
4654c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                + "should be provided.");
4664c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        }
4674c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
4684c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        // Namespace URI and local part specified
4694c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        int endOfNamespaceURI = qNameAsString.indexOf('}');
4704c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        if (endOfNamespaceURI == -1) {
4714c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            throw new IllegalArgumentException(
4724c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                "cannot create QName from \""
4734c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                    + qNameAsString
4744c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson                    + "\", missing closing \"}\"");
4754c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        }
4764c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        return new QName(
4774c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            qNameAsString.substring(1, endOfNamespaceURI),
4784c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            qNameAsString.substring(endOfNamespaceURI + 1),
4794c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            XMLConstants.DEFAULT_NS_PREFIX);
4804c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    }
4814c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson
4824c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    /*
4834c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * For old versions of QName which didn't have a prefix field,
4844c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * <code>ObjectInputStream.defaultReadObject()</code> will initialize
4854c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * the prefix to <code>null</code> instead of the empty string. This
4864c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * method fixes up the prefix field if it didn't exist in the serialized
4874c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     * object.
4884c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson     */
4894c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    private void readObject(ObjectInputStream in)
4904c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        throws IOException, ClassNotFoundException {
4914c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        in.defaultReadObject();
4924c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        if (prefix == null) {
4934c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson            prefix = XMLConstants.DEFAULT_NS_PREFIX;
4944c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson        }
4954c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson    }
4964c7a0d97cf2b27790e6236965a1d798d710d7ec7Jesse Wilson}
497