Here you can find the source of getClassName(QName qname)
Returns the className for a given qname e.g., {http://www.w3.org/2001/XMLSchema}decimal → org.w3.2001.XMLSchema.decimal
Parameter | Description |
---|---|
qname | qualified name |
public static String getClassName(QName qname)
//package com.java2s; /*/*from ww w .jav a2 s .c om*/ * Copyright (c) 2007-2016 Siemens AG * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import javax.xml.namespace.QName; public class Main { /** * Returns the className for a given qname e.g., * {http://www.w3.org/2001/XMLSchema}decimal → * org.w3.2001.XMLSchema.decimal * * @param qname qualified name * @return className or null if converting is not possible */ public static String getClassName(QName qname) { try { StringBuilder className = new StringBuilder(); // e.g., {http://www.w3.org/2001/XMLSchema}decimal StringTokenizer st1 = new StringTokenizer(qname.getNamespaceURI(), "/"); // --> "http:" -> "www.w3.org" --> "2001" -> "XMLSchema" st1.nextToken(); // protocol, e.g. "http:" String domain = st1.nextToken(); // "www.w3.org" StringTokenizer st2 = new StringTokenizer(domain, "."); List<String> lDomain = new ArrayList<String>(); while (st2.hasMoreTokens()) { lDomain.add(st2.nextToken()); } assert (lDomain.size() >= 2); className.append(lDomain.get(lDomain.size() - 1)); // "org" className.append('.'); className.append(lDomain.get(lDomain.size() - 2)); // "w3" while (st1.hasMoreTokens()) { className.append('.'); className.append(st1.nextToken()); } className.append('.'); className.append(qname.getLocalPart()); return className.toString(); } catch (Exception e) { return null; } } /** * Returns the local part of the given raw qname. * * @param qname * raw qname input * * @return Local part of the name if prefixed, or the given name if not */ public static String getLocalPart(String qname) { int index = qname.indexOf(':'); return (index < 0) ? qname : qname.substring(index + 1); } }