1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Copyright 2001-2004 The Apache Software Foundation.
   7  *
   8  * Licensed under the Apache License, Version 2.0 (the "License");
   9  * you may not use this file except in compliance with the License.
  10  * You may obtain a copy of the License at
  11  *
  12  *     http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 /*
  21  * $Id: QName.java,v 1.2.4.1 2005/09/02 11:45:56 pvedula Exp $
  22  */
  23 
  24 package com.sun.org.apache.xalan.internal.xsltc.compiler;
  25 
  26 /**
  27  * @author Jacek Ambroziak
  28  * @author Santiago Pericas-Geertsen
  29  * @author Morten Jorgensen
  30  */
  31 final class QName {
  32     private final String _localname;
  33     private String _prefix;
  34     private String _namespace;
  35     private String _stringRep;
  36     private int    _hashCode;
  37 
  38     public QName(String namespace, String prefix, String localname) {
  39         _namespace = namespace;
  40         _prefix    = prefix;
  41         _localname = localname;
  42 
  43         _stringRep =
  44             (namespace != null && !namespace.equals(Constants.EMPTYSTRING)) ?
  45             (namespace + ':' + localname) : localname;
  46 
  47         _hashCode  = _stringRep.hashCode() + 19; // cached for speed
  48     }
  49 
  50     public void clearNamespace() {
  51         _namespace = Constants.EMPTYSTRING;
  52     }
  53 
  54     public String toString() {
  55         return _stringRep;
  56     }
  57 
  58     public String getStringRep() {
  59         return _stringRep;
  60     }
  61 
  62     public boolean equals(Object other) {
  63         return (this == other)
  64                    || (other instanceof QName
  65                            && _stringRep.equals(((QName) other).getStringRep()));
  66     }
  67 
  68     public String getLocalPart() {
  69         return _localname;
  70     }
  71 
  72     public String getNamespace() {
  73         return _namespace;
  74     }
  75 
  76     public String getPrefix() {
  77         return _prefix;
  78     }
  79 
  80     public int hashCode() {
  81         return _hashCode;
  82     }
  83 
  84     public String dump() {
  85         return "QName: " + _namespace + "(" + _prefix + "):" + _localname;
  86     }
  87 }