001    /** 
002     * 
003     * Copyright 2004 Protique Ltd
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 org.codehaus.activesoap.util;
019    
020    import javax.xml.namespace.QName;
021    import javax.xml.namespace.NamespaceContext;
022    
023    /**
024     * @version $Revision: 1.1 $
025     */
026    public class QNameHelper {
027        public static String getQualifiedName(QName qname) {
028            String prefix = qname.getPrefix();
029            String localPart = qname.getLocalPart();
030            if (prefix != null && prefix.length() > 0) {
031                return prefix + ":" + localPart;
032            }
033            return localPart;
034        }
035    
036        /**
037         * Turns the given String into a QName using the current namespace context
038         */
039        public static QName asQName(NamespaceContext context, String text) {
040            int idx = text.indexOf(':');
041            if (idx >= 0) {
042                String prefix = text.substring(0, idx);
043                String localPart = text.substring(idx + 1);
044                String uri = context.getNamespaceURI(prefix);
045                return new QName(uri, localPart, prefix);
046            }
047            else {
048                return new QName(text);
049            }
050        }
051    }