KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb > Namer


1 package org.apache.ojb.tools.mapping.reversedb;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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
20
21 /**
22  * @author <a HREF="mailto:wk5657@henleykidd.ns01.us">G. Wayne Kidd</a>
23  *
24  * To change the template for this generated type comment go to
25  * Window>Preferences>Java>Code Generation>Code and Comments
26  */

27 public class Namer
28 {
29     /* (non-Javadoc)
30      * @see org.apache.ojb.tools.mapping.reversedb.Namer#nameClass(java.lang.String, java.lang.String)
31      */

32     public static String JavaDoc nameClass(String JavaDoc tableName)
33     {
34         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
35         char[] chars = new char[tableName.length()];
36         chars = tableName.toCharArray();
37         char c;
38         boolean nextup = false;
39         for (int i = 0; i < chars.length; i++) {
40             if (i==0) c = Character.toUpperCase(chars[i]);
41             else if (chars[i]=='_') {
42                  nextup = true;
43                  continue;
44             }
45             else if (nextup) {
46                 nextup = false;
47                 c = Character.toUpperCase(chars[i]);
48             }
49             else c = Character.toLowerCase(chars[i]);
50             sb.append(c);
51         }
52         return sb.toString();
53     }
54
55     /* (non-Javadoc)
56      * @see org.apache.ojb.tools.mapping.reversedb.Namer#nameField(java.lang.String, java.lang.String)
57      */

58     public static String JavaDoc nameField(String JavaDoc columnName)
59     {
60         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
61         char[] chars = new char[columnName.length()];
62         chars = columnName.toCharArray();
63         char c;
64         boolean nextup = false;
65         for (int i = 0; i < chars.length; i++) {
66             if (chars[i]=='_') {
67                  nextup = true;
68                  continue;
69             }
70             else if (nextup) {
71                 nextup = false;
72                 c = Character.toUpperCase(chars[i]);
73             }
74             else c = Character.toLowerCase(chars[i]);
75             sb.append(c);
76         }
77         return sb.toString();
78     }
79 }
80
Popular Tags