01: package org.objectweb.celtix.tools.generators.spring;
02:
03: import java.util.logging.Logger;
04:
05: import javax.xml.XMLConstants;
06: import javax.xml.namespace.QName;
07:
08: import org.objectweb.celtix.common.i18n.Message;
09: 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
15: .getL7dLogger(SpringUtils.class);
16:
17: /**
18: * prevent instantiation
19: *
20: */
21: private SpringUtils() {
22: //utility class - never constructed
23: }
24:
25: public static String getBeanClassName(String namespaceURI) {
26: StringBuffer buf = new StringBuffer(JAXBUtils
27: .namespaceURIToPackage(namespaceURI));
28: int index = buf.lastIndexOf(".");
29: String className = null;
30: if (index >= 0) {
31: className = buf.substring(index + 1);
32: } else {
33: className = buf.toString();
34: }
35: buf.append(".spring.");
36: int len = buf.length();
37: className = JAXBUtils.nameToIdentifier(className,
38: JAXBUtils.IdentifierType.CLASS);
39: buf.append(className);
40: if (Character.isLowerCase(buf.charAt(len))) {
41: buf.setCharAt(len, Character.toUpperCase(buf.charAt(len)));
42: }
43: buf.append("Bean");
44: return buf.toString();
45: }
46:
47: /**
48: * Converts a stringified representation of a QName into a QName.
49: * The string representation is assumed to be of the form:
50: * "{" + Namespace URI + "}" + local part. If the Namespace URI
51: * <code>.equals(XMLConstants.NULL_NS_URI)</code>, the string representation
52: * only consists of the local part.
53: *
54: * @throws IllegalArgumentException if the string is not of this format.
55: *
56: * @param str string representation of the QName.
57: * @return the QName.
58: */
59: public static QName stringToQName(String str) {
60:
61: if (str == null) {
62: return null;
63: }
64:
65: if (str.startsWith("{")) {
66: int index = str.lastIndexOf("}");
67: if (index <= 1) {
68: throw new IllegalArgumentException(new Message(
69: "ILLEGAL_QNAME_STRING_EXC", LOG, str)
70: .toString());
71: }
72: return new QName(str.substring(1, index), (index < str
73: .length() - 1) ? str.substring(index + 1) : "");
74: } else {
75: return new QName(XMLConstants.NULL_NS_URI, str);
76: }
77: }
78: }
|