001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.wsdl.model.impl;
043:
044: import java.util.ArrayList;
045: import java.util.Collection;
046: import java.util.List;
047: import java.util.StringTokenizer;
048: import javax.xml.namespace.QName;
049: import org.netbeans.modules.xml.wsdl.model.spi.WSDLComponentBase;
050: import org.w3c.dom.Element;
051:
052: /**
053: *
054: * @author Nam Nguyen
055: */
056: public class Util {
057:
058: public static List<String> parse(String s) {
059: if (s == null)
060: return null;
061: StringTokenizer st = new StringTokenizer(s, SEP);
062: List<String> result = new ArrayList<String>();
063: while (st.hasMoreTokens()) {
064: result.add(st.nextToken());
065: }
066: return result;
067: }
068:
069: public static String toString(Collection<String> tokens) {
070: // this is used only in setX/addX/removeX methods so, null when empty
071: if (tokens == null || tokens.isEmpty())
072: return null;
073: StringBuilder sb = new StringBuilder();
074: boolean first = true;
075: for (String token : tokens) {
076: if (first) {
077: first = false;
078: } else {
079: sb.append(SEP);
080: }
081: sb.append(token);
082: }
083: return sb.toString();
084: }
085:
086: public static QName getQName(Element el, WSDLComponentBase context) {
087: String namespace = el.getNamespaceURI();
088: String prefix = el.getPrefix();
089: if (namespace == null && context != null) {
090: namespace = context.lookupNamespaceURI(prefix);
091: }
092: String localName = el.getLocalName();
093: assert (localName != null);
094: if (namespace == null && prefix == null) {
095: return new QName(localName);
096: } else if (namespace != null && prefix == null) {
097: return new QName(namespace, localName);
098: } else {
099: return new QName(namespace, localName, prefix);
100: }
101: }
102:
103: public static final String SEP = " "; //NOI18N
104: }
|