1 19 20 package org.netbeans.modules.xml.wsdl.model.impl; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.List ; 25 import java.util.StringTokenizer ; 26 import javax.xml.namespace.QName ; 27 import org.netbeans.modules.xml.wsdl.model.spi.WSDLComponentBase; 28 import org.w3c.dom.Element ; 29 30 34 public class Util { 35 36 public static List <String > parse(String s) { 37 if (s == null) return null; 38 StringTokenizer st = new StringTokenizer (s, SEP); 39 List <String > result = new ArrayList <String >(); 40 while(st.hasMoreTokens()) { 41 result.add(st.nextToken()); 42 } 43 return result; 44 } 45 46 public static String toString(Collection <String > tokens) { 47 if (tokens == null || tokens.isEmpty()) return null; 49 StringBuilder sb = new StringBuilder (); 50 boolean first = true; 51 for (String token : tokens) { 52 if (first) { 53 first = false; 54 } else { 55 sb.append(SEP); 56 } 57 sb.append(token); 58 } 59 return sb.toString(); 60 } 61 62 public static QName getQName(Element el, WSDLComponentBase context) { 63 String namespace = el.getNamespaceURI(); 64 String prefix = el.getPrefix(); 65 if (namespace == null && context != null) { 66 namespace = context.lookupNamespaceURI(prefix); 67 } 68 String localName = el.getLocalName(); 69 assert(localName != null); 70 if (namespace == null && prefix == null) { 71 return new QName (localName); 72 } else if (namespace != null && prefix == null) { 73 return new QName (namespace, localName); 74 } else { 75 return new QName (namespace, localName, prefix); 76 } 77 } 78 79 public static final String SEP = " "; } 81 | Popular Tags |