KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > tools > generators > spring > SpringUtils


1 package org.objectweb.celtix.tools.generators.spring;
2
3 import java.util.logging.Logger JavaDoc;
4
5 import javax.xml.XMLConstants JavaDoc;
6 import javax.xml.namespace.QName JavaDoc;
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 JavaDoc LOG = LogUtils.getL7dLogger(SpringUtils.class);
15     
16     /**
17      * prevent instantiation
18      *
19      */

20     private SpringUtils() {
21         //utility class - never constructed
22
}
23     
24     public static String JavaDoc getBeanClassName(String JavaDoc namespaceURI) {
25         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(JAXBUtils.namespaceURIToPackage(namespaceURI));
26         int index = buf.lastIndexOf(".");
27         String JavaDoc 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     /**
45      * Converts a stringified representation of a QName into a QName.
46      * The string representation is assumed to be of the form:
47      * "{" + Namespace URI + "}" + local part. If the Namespace URI
48      * <code>.equals(XMLConstants.NULL_NS_URI)</code>, the string representation
49      * only consists of the local part.
50      *
51      * @throws IllegalArgumentException if the string is not of this format.
52      *
53      * @param str string representation of the QName.
54      * @return the QName.
55      */

56     public static QName JavaDoc stringToQName(String JavaDoc 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 JavaDoc(new Message("ILLEGAL_QNAME_STRING_EXC",
66                                                                LOG, str).toString());
67             }
68             return new QName JavaDoc(str.substring(1, index),
69                               (index < str.length() - 1) ? str.substring(index + 1) : "");
70         } else {
71             return new QName JavaDoc(XMLConstants.NULL_NS_URI, str);
72         }
73     }
74 }
75
Popular Tags