1 package org.objectweb.celtix.tools.generators.spring; 2 3 import java.util.logging.Logger ; 4 5 import javax.xml.XMLConstants ; 6 import javax.xml.namespace.QName ; 7 8 import org.objectweb.celtix.common.i18n.Message; 9 import org.objectweb.celtix.common.logging.LogUtils; 10 import org.objectweb.celtix.jaxb.JAXBUtils; 11 12 public final class SpringUtils { 13 14 private static final Logger LOG = LogUtils.getL7dLogger(SpringUtils.class); 15 16 20 private SpringUtils() { 21 } 23 24 public static String getBeanClassName(String namespaceURI) { 25 StringBuffer buf = new StringBuffer (JAXBUtils.namespaceURIToPackage(namespaceURI)); 26 int index = buf.lastIndexOf("."); 27 String className = null; 28 if (index >= 0) { 29 className = buf.substring(index + 1); 30 } else { 31 className = buf.toString(); 32 } 33 buf.append(".spring."); 34 int len = buf.length(); 35 className = JAXBUtils.nameToIdentifier(className, JAXBUtils.IdentifierType.CLASS); 36 buf.append(className); 37 if (Character.isLowerCase(buf.charAt(len))) { 38 buf.setCharAt(len, Character.toUpperCase(buf.charAt(len))); 39 } 40 buf.append("Bean"); 41 return buf.toString(); 42 } 43 44 56 public static QName stringToQName(String str) { 57 58 if (str == null) { 59 return null; 60 } 61 62 if (str.startsWith("{")) { 63 int index = str.lastIndexOf("}"); 64 if (index <= 1) { 65 throw new IllegalArgumentException (new Message("ILLEGAL_QNAME_STRING_EXC", 66 LOG, str).toString()); 67 } 68 return new QName (str.substring(1, index), 69 (index < str.length() - 1) ? str.substring(index + 1) : ""); 70 } else { 71 return new QName (XMLConstants.NULL_NS_URI, str); 72 } 73 } 74 } 75 | Popular Tags |