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: 1.3 $
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         * @return
048         */
049        public QName get(String localName) {
050            if (uri != null && uri.length() > 0) {
051                if (prefix != null) {
052                    return new QName(uri, localName, prefix);
053                }
054                else {
055                    return new QName(uri, localName);
056                }
057            }
058            else {
059                return new QName(localName);
060            }
061        }
062    
063        /**
064         * Returns the prefix mapped to this namespace
065         * 
066         * @return the prefix assigned to this namespace or null if no namespace is
067         *         mapped.
068         */
069        public String getPrefix() {
070            return prefix;
071        }
072    
073        /**
074         * Returns the URI of this namespace
075         * 
076         * @return the URI of this namespace
077         */
078        public String getUri() {
079            return uri;
080        }
081    
082    }