001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: QName.java 669372 2008-06-19 03:39:52Z zongaro $
020     */
021    
022    package org.apache.xalan.xsltc.compiler;
023    
024    /**
025     * @author Jacek Ambroziak
026     * @author Santiago Pericas-Geertsen
027     * @author Morten Jorgensen
028     */
029    final class QName {
030        private final String _localname;
031        private String _prefix;
032        private String _namespace;
033        private String _stringRep;
034        private int    _hashCode;
035    
036        public QName(String namespace, String prefix, String localname) {
037            _namespace = namespace;
038            _prefix    = prefix;
039            _localname = localname;
040    
041            _stringRep = 
042                (namespace != null && !namespace.equals(Constants.EMPTYSTRING)) ?
043                (namespace + ':' + localname) : localname;
044    
045            _hashCode  = _stringRep.hashCode() + 19; // cached for speed
046        }
047    
048        public void clearNamespace() {
049            _namespace = Constants.EMPTYSTRING;
050        }
051    
052        public String toString() {
053            return _stringRep;
054        }
055    
056        public String getStringRep() {
057            return _stringRep;
058        }
059    
060        public boolean equals(Object other) {
061            return (this == other)
062                       || (other instanceof QName
063                               && _stringRep.equals(((QName) other).getStringRep()));
064        }
065    
066        public String getLocalPart() {
067            return _localname;
068        }
069    
070        public String getNamespace() {
071            return _namespace;
072        }
073    
074        public String getPrefix() {
075            return _prefix;
076        }
077    
078        public int hashCode() {
079            return _hashCode;
080        }
081    
082        public String dump() {
083            return "QName: " + _namespace + "(" + _prefix + "):" + _localname;
084        }
085    }