01: package org.apache.ojb.tools.mapping.reversedb;
02:
03: /* Copyright 2003-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author <a href="mailto:wk5657@henleykidd.ns01.us">G. Wayne Kidd</a>
20: *
21: * To change the template for this generated type comment go to
22: * Window>Preferences>Java>Code Generation>Code and Comments
23: */
24: public class Namer {
25: /* (non-Javadoc)
26: * @see org.apache.ojb.tools.mapping.reversedb.Namer#nameClass(java.lang.String, java.lang.String)
27: */
28: public static String nameClass(String tableName) {
29: StringBuffer sb = new StringBuffer();
30: char[] chars = new char[tableName.length()];
31: chars = tableName.toCharArray();
32: char c;
33: boolean nextup = false;
34: for (int i = 0; i < chars.length; i++) {
35: if (i == 0)
36: c = Character.toUpperCase(chars[i]);
37: else if (chars[i] == '_') {
38: nextup = true;
39: continue;
40: } else if (nextup) {
41: nextup = false;
42: c = Character.toUpperCase(chars[i]);
43: } else
44: c = Character.toLowerCase(chars[i]);
45: sb.append(c);
46: }
47: return sb.toString();
48: }
49:
50: /* (non-Javadoc)
51: * @see org.apache.ojb.tools.mapping.reversedb.Namer#nameField(java.lang.String, java.lang.String)
52: */
53: public static String nameField(String columnName) {
54: StringBuffer sb = new StringBuffer();
55: char[] chars = new char[columnName.length()];
56: chars = columnName.toCharArray();
57: char c;
58: boolean nextup = false;
59: for (int i = 0; i < chars.length; i++) {
60: if (chars[i] == '_') {
61: nextup = true;
62: continue;
63: } else if (nextup) {
64: nextup = false;
65: c = Character.toUpperCase(chars[i]);
66: } else
67: c = Character.toLowerCase(chars[i]);
68: sb.append(c);
69: }
70: return sb.toString();
71: }
72: }
|