001    /**
002     * 
003     * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
004     * 
005     * Licensed under the Apache License, Version 2.0 (the "License"); 
006     * you may not use this file except in compliance with the License. 
007     * You may obtain a copy of the License at 
008     * 
009     * http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS, 
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
014     * See the License for the specific language governing permissions and 
015     * limitations under the License. 
016     * 
017     **/
018    package groovy.xml;
019    
020    /**
021     * A simple helper class which acts as a factory of {@link QName} instances.
022     * 
023     * @version $Revision: 4032 $
024     */
025    public class Namespace {
026    
027        private String uri;
028        private String prefix;
029    
030        public Namespace() {
031        }
032    
033        public Namespace(String uri) {
034            this.uri = uri;
035        }
036    
037        public Namespace(String uri, String prefix) {
038            this.uri = uri;
039            this.prefix = prefix;
040        }
041    
042        /**
043         * Returns the QName for the given localName.
044         * 
045         * @param localName
046         *            the local name within this
047         */
048        public QName get(String localName) {
049            if (uri != null && uri.length() > 0) {
050                if (prefix != null) {
051                    return new QName(uri, localName, prefix);
052                }
053                else {
054                    return new QName(uri, localName);
055                }
056            }
057            else {
058                return new QName(localName);
059            }
060        }
061    
062        /**
063         * Returns the prefix mapped to this namespace
064         * 
065         * @return the prefix assigned to this namespace or null if no namespace is
066         *         mapped.
067         */
068        public String getPrefix() {
069            return prefix;
070        }
071    
072        /**
073         * Returns the URI of this namespace
074         * 
075         * @return the URI of this namespace
076         */
077        public String getUri() {
078            return uri;
079        }
080    
081    }