src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/QName.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
permissions -rw-r--r--
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked Reviewed-by: lancea, rriggs, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    21
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xml.internal.utils;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    24
import com.sun.org.apache.xml.internal.res.XMLErrorResources;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    25
import com.sun.org.apache.xml.internal.res.XMLMessages;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import java.util.Stack;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import java.util.StringTokenizer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import org.w3c.dom.Element;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * Class to represent a qualified name: "The name of an internal XSLT object,
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * specifically a named template (see [7 Named Templates]), a mode (see [6.7 Modes]),
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * an attribute set (see [8.1.4 Named Attribute Sets]), a key (see [14.2 Keys]),
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 * a locale (see [14.3 Number Formatting]), a variable or a parameter (see
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 * [12 Variables and Parameters]) is specified as a QName. If it has a prefix,
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * then the prefix is expanded into a URI reference using the namespace declarations
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * in effect on the attribute in which the name occurs. The expanded name
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * consisting of the local part of the name and the possibly null URI reference
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * is used as the name of the object. The default namespace is not used for
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * unprefixed names."
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * @xsl.usage general
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
public class QName implements java.io.Serializable
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
    static final long serialVersionUID = 467434581652829920L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
   * The local name.
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
   * @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
  protected String _localName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
   * The namespace URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
   * @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
  protected String _namespaceURI;
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
   * The namespace prefix.
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
   * @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
  protected String _prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
   * The XML namespace.
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
  public static final String S_XMLNAMESPACEURI =
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    "http://www.w3.org/XML/1998/namespace";
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
   * The cached hashcode, which is calculated at construction time.
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
   * @serial
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
  private int m_hashCode;
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
   * Constructs an empty QName.
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
   * 20001019: Try making this public, to support Serializable? -- JKESS
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
  public QName(){}
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
   * Constructs a new QName with the specified namespace URI and
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
   * local name.
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
   * @param namespaceURI The namespace URI if known, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
   * @param localName The local name
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
  public QName(String namespaceURI, String localName)
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
    this(namespaceURI, localName, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
   * Constructs a new QName with the specified namespace URI and
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
   * local name.
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
   * @param namespaceURI The namespace URI if known, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
   * @param localName The local name
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
   * @param validate If true the new QName will be validated and an IllegalArgumentException will
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
   *                 be thrown if it is invalid.
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
  public QName(String namespaceURI, String localName, boolean validate)
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    // This check was already here.  So, for now, I will not add it to the validation
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
    // that is done when the validate parameter is true.
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    if (localName == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
      throw new IllegalArgumentException(XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
            XMLErrorResources.ER_ARG_LOCALNAME_NULL, null)); //"Argument 'localName' is null");
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    if (validate)
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
        if (!XML11Char.isXML11ValidNCName(localName))
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
            throw new IllegalArgumentException(XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
            XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    _namespaceURI = namespaceURI;
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    _localName = localName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    m_hashCode = toString().hashCode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
   * Constructs a new QName with the specified namespace URI, prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
   * and local name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
   * @param namespaceURI The namespace URI if known, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
   * @param prefix The namespace prefix is known, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
   * @param localName The local name
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
  public QName(String namespaceURI, String prefix, String localName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
     this(namespaceURI, prefix, localName, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
 /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
   * Constructs a new QName with the specified namespace URI, prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
   * and local name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
   * @param namespaceURI The namespace URI if known, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
   * @param prefix The namespace prefix is known, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
   * @param localName The local name
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
   * @param validate If true the new QName will be validated and an IllegalArgumentException will
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
   *                 be thrown if it is invalid.
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
  public QName(String namespaceURI, String prefix, String localName, boolean validate)
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
    // This check was already here.  So, for now, I will not add it to the validation
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
    // that is done when the validate parameter is true.
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
    if (localName == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
      throw new IllegalArgumentException(XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
            XMLErrorResources.ER_ARG_LOCALNAME_NULL, null)); //"Argument 'localName' is null");
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    if (validate)
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
        if (!XML11Char.isXML11ValidNCName(localName))
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
            throw new IllegalArgumentException(XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
            XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
        if ((null != prefix) && (!XML11Char.isXML11ValidNCName(prefix)))
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
            throw new IllegalArgumentException(XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
            XMLErrorResources.ER_ARG_PREFIX_INVALID,null )); //"Argument 'prefix' not a valid NCName");
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
    _namespaceURI = namespaceURI;
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
    _prefix = prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
    _localName = localName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
    m_hashCode = toString().hashCode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
   * Construct a QName from a string, without namespace resolution.  Good
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
   * for a few odd cases.
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
   * @param localName Local part of qualified name
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
  public QName(String localName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
    this(localName, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
   * Construct a QName from a string, without namespace resolution.  Good
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
   * for a few odd cases.
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
   * @param localName Local part of qualified name
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
   * @param validate If true the new QName will be validated and an IllegalArgumentException will
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
   *                 be thrown if it is invalid.
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
  public QName(String localName, boolean validate)
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
    // This check was already here.  So, for now, I will not add it to the validation
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
    // that is done when the validate parameter is true.
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    if (localName == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
      throw new IllegalArgumentException(XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
            XMLErrorResources.ER_ARG_LOCALNAME_NULL, null)); //"Argument 'localName' is null");
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
    if (validate)
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
        if (!XML11Char.isXML11ValidNCName(localName))
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
            throw new IllegalArgumentException(XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
            XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    _namespaceURI = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    _localName = localName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
    m_hashCode = toString().hashCode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
   * Construct a QName from a string, resolving the prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
   * using the given namespace stack. The default namespace is
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
   * not resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
   * @param qname Qualified name to resolve
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
   * @param namespaces Namespace stack to use to resolve namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
   */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   231
  public QName(String qname, Stack<NameSpace> namespaces)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
    this(qname, namespaces, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
   * Construct a QName from a string, resolving the prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
   * using the given namespace stack. The default namespace is
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
   * not resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
   * @param qname Qualified name to resolve
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
   * @param namespaces Namespace stack to use to resolve namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
   * @param validate If true the new QName will be validated and an IllegalArgumentException will
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
   *                 be thrown if it is invalid.
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
   */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   246
  public QName(String qname, Stack<NameSpace> namespaces, boolean validate)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
    String namespace = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
    String prefix = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
    int indexOfNSSep = qname.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
    if (indexOfNSSep > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
      prefix = qname.substring(0, indexOfNSSep);
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
      if (prefix.equals("xml"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
        namespace = S_XMLNAMESPACEURI;
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
      // Do we want this?
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
      else if (prefix.equals("xmlns"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
        return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        int depth = namespaces.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
        for (int i = depth - 1; i >= 0; i--)
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
        {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   272
          NameSpace ns = namespaces.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
          while (null != ns)
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
            if ((null != ns.m_prefix) && prefix.equals(ns.m_prefix))
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
              namespace = ns.m_uri;
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
              i = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
              break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
            ns = ns.m_next;
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
      if (null == namespace)
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
        throw new RuntimeException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
          XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
            XMLErrorResources.ER_PREFIX_MUST_RESOLVE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
            new Object[]{ prefix }));  //"Prefix must resolve to a namespace: "+prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
    _localName = (indexOfNSSep < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
                 ? qname : qname.substring(indexOfNSSep + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
    if (validate)
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        if ((_localName == null) || (!XML11Char.isXML11ValidNCName(_localName)))
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
           throw new IllegalArgumentException(XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
            XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
    _namespaceURI = namespace;
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
    _prefix = prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
    m_hashCode = toString().hashCode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
   * Construct a QName from a string, resolving the prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
   * using the given namespace context and prefix resolver.
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
   * The default namespace is not resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
   * @param qname Qualified name to resolve
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
   * @param namespaceContext Namespace Context to use
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
   * @param resolver Prefix resolver for this context
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
  public QName(String qname, Element namespaceContext,
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
               PrefixResolver resolver)
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
      this(qname, namespaceContext, resolver, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
   * Construct a QName from a string, resolving the prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
   * using the given namespace context and prefix resolver.
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
   * The default namespace is not resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
   * @param qname Qualified name to resolve
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
   * @param namespaceContext Namespace Context to use
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
   * @param resolver Prefix resolver for this context
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
   * @param validate If true the new QName will be validated and an IllegalArgumentException will
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
   *                 be thrown if it is invalid.
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
  public QName(String qname, Element namespaceContext,
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
               PrefixResolver resolver, boolean validate)
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
    _namespaceURI = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
    int indexOfNSSep = qname.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
    if (indexOfNSSep > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
      if (null != namespaceContext)
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
        String prefix = qname.substring(0, indexOfNSSep);
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
        _prefix = prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
        if (prefix.equals("xml"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
          _namespaceURI = S_XMLNAMESPACEURI;
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
        // Do we want this?
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
        else if (prefix.equals("xmlns"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
          return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
          _namespaceURI = resolver.getNamespaceForPrefix(prefix,
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
                  namespaceContext);
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
        if (null == _namespaceURI)
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
          throw new RuntimeException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
            XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
              XMLErrorResources.ER_PREFIX_MUST_RESOLVE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
              new Object[]{ prefix }));  //"Prefix must resolve to a namespace: "+prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
        // TODO: error or warning...
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
    _localName = (indexOfNSSep < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
                 ? qname : qname.substring(indexOfNSSep + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
    if (validate)
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
        if ((_localName == null) || (!XML11Char.isXML11ValidNCName(_localName)))
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
           throw new IllegalArgumentException(XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
            XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
    m_hashCode = toString().hashCode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
   * Construct a QName from a string, resolving the prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
   * using the given namespace stack. The default namespace is
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
   * not resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
   * @param qname Qualified name to resolve
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
   * @param resolver Prefix resolver for this context
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
  public QName(String qname, PrefixResolver resolver)
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
    this(qname, resolver, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
   * Construct a QName from a string, resolving the prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
   * using the given namespace stack. The default namespace is
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
   * not resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
   * @param qname Qualified name to resolve
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
   * @param resolver Prefix resolver for this context
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
   * @param validate If true the new QName will be validated and an IllegalArgumentException will
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
   *                 be thrown if it is invalid.
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
  public QName(String qname, PrefixResolver resolver, boolean validate)
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
        String prefix = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
    _namespaceURI = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
    int indexOfNSSep = qname.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
    if (indexOfNSSep > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
      prefix = qname.substring(0, indexOfNSSep);
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
      if (prefix.equals("xml"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
        _namespaceURI = S_XMLNAMESPACEURI;
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
        _namespaceURI = resolver.getNamespaceForPrefix(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
      if (null == _namespaceURI)
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
        throw new RuntimeException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
          XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
            XMLErrorResources.ER_PREFIX_MUST_RESOLVE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
            new Object[]{ prefix }));  //"Prefix must resolve to a namespace: "+prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
      _localName = qname.substring(indexOfNSSep + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
    else if (indexOfNSSep == 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
      throw new RuntimeException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
         XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
           XMLErrorResources.ER_NAME_CANT_START_WITH_COLON,
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
           null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
      _localName = qname;
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
    if (validate)
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
        if ((_localName == null) || (!XML11Char.isXML11ValidNCName(_localName)))
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
           throw new IllegalArgumentException(XMLMessages.createXMLMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
            XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
    m_hashCode = toString().hashCode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
    _prefix = prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
   * Returns the namespace URI. Returns null if the namespace URI
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
   * is not known.
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
   * @return The namespace URI, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
  public String getNamespaceURI()
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
    return _namespaceURI;
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
   * Returns the namespace prefix. Returns null if the namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
   * prefix is not known.
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
   * @return The namespace prefix, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
  public String getPrefix()
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
    return _prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
   * Returns the local part of the qualified name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
   * @return The local part of the qualified name
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
  public String getLocalName()
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
    return _localName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
   * Return the string representation of the qualified name, using the
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
   * prefix if available, or the '{ns}foo' notation if not. Performs
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
   * string concatenation, so beware of performance issues.
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
   * @return the string representation of the namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
  public String toString()
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
    return _prefix != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
           ? (_prefix + ":" + _localName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
           : (_namespaceURI != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
              ? ("{"+_namespaceURI + "}" + _localName) : _localName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
   * Return the string representation of the qualified name using the
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
   * the '{ns}foo' notation. Performs
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
   * string concatenation, so beware of performance issues.
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
   * @return the string representation of the namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
  public String toNamespacedString()
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
    return (_namespaceURI != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
              ? ("{"+_namespaceURI + "}" + _localName) : _localName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
   * Get the namespace of the qualified name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
   * @return the namespace URI of the qualified name
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
  public String getNamespace()
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
    return getNamespaceURI();
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
   * Get the local part of the qualified name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
   * @return the local part of the qualified name
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
  public String getLocalPart()
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
    return getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
   * Return the cached hashcode of the qualified name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
   * @return the cached hashcode of the qualified name
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
  public int hashCode()
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
    return m_hashCode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
   * Override equals and agree that we're equal if
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
   * the passed object is a string and it matches
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
   * the name of the arg.
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
   * @param ns Namespace URI to compare to
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
   * @param localPart Local part of qualified name to compare to
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
   * @return True if the local name and uri match
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
  public boolean equals(String ns, String localPart)
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
    String thisnamespace = getNamespaceURI();
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
    return getLocalName().equals(localPart)
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
           && (((null != thisnamespace) && (null != ns))
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
               ? thisnamespace.equals(ns)
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
               : ((null == thisnamespace) && (null == ns)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
   * Override equals and agree that we're equal if
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
   * the passed object is a QName and it matches
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
   * the name of the arg.
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
   * @return True if the qualified names are equal
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
  public boolean equals(Object object)
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
    if (object == this)
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
      return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
    if (object instanceof QName) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
      QName qname = (QName) object;
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
      String thisnamespace = getNamespaceURI();
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
      String thatnamespace = qname.getNamespaceURI();
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
      return getLocalName().equals(qname.getLocalName())
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
             && (((null != thisnamespace) && (null != thatnamespace))
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
                 ? thisnamespace.equals(thatnamespace)
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
                 : ((null == thisnamespace) && (null == thatnamespace)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
      return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
   * Given a string, create and return a QName object
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
   * @param name String to use to create QName
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
   * @return a QName object
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
  public static QName getQNameFromString(String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
    StringTokenizer tokenizer = new StringTokenizer(name, "{}", false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
    QName qname;
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
    String s1 = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
    String s2 = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
    if (null == s2)
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
      qname = new QName(null, s1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
      qname = new QName(s1, s2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
    return qname;
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
   * This function tells if a raw attribute name is a
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
   * xmlns attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
   * @param attRawName Raw name of attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
   * @return True if the attribute starts with or is equal to xmlns
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
  public static boolean isXMLNSDecl(String attRawName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
    return (attRawName.startsWith("xmlns")
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
            && (attRawName.equals("xmlns")
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
                || attRawName.startsWith("xmlns:")));
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
   * This function tells if a raw attribute name is a
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
   * xmlns attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
   * @param attRawName Raw name of attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
   * @return Prefix of attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
  public static String getPrefixFromXMLNSDecl(String attRawName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
    int index = attRawName.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
    return (index >= 0) ? attRawName.substring(index + 1) : "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
   * Returns the local name of the given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
   * @param qname Input name
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
   * @return Local part of the name if prefixed, or the given name if not
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
  public static String getLocalPart(String qname)
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
    int index = qname.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
    return (index < 0) ? qname : qname.substring(index + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
   * Returns the local name of the given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
   * @param qname Input name
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
   * @return Prefix of name or empty string if none there
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
  public static String getPrefixPart(String qname)
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
    int index = qname.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
    return (index >= 0) ? qname.substring(0, index) : "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
}