View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  package org.apache.jdo.impl.enhancer.generator;
18  
19  
20  /***
21   * Helps with class name conversions.
22   */
23  class NameHelper
24  {
25      static String normalizeClassName(String classname)
26      {
27          if (classname == null) {
28              return null;
29          }
30          return classname.replace('/', '.').replace('$', '.');
31      }
32  
33  /*
34      static String convertClassName(String classname)
35      {
36          if (classname == null) {
37              return null;
38          }
39          return classname.replace('.', '_').replace('$', '_');
40      }
41  */
42      
43      static String getPackageName(String classname)
44      {
45          if (classname == null) {
46              return null;
47          }
48          classname = classname.replace('/', '.');
49          final int p = classname.lastIndexOf('.');
50          return classname.substring(0, p > 0 ? p : 0);
51      }
52  
53      static String getEnclosedClassName(String classname)
54      {
55          if (classname == null) {
56              return null;
57          }
58          classname = classname.replace('/', '.');
59          final int p = classname.lastIndexOf('.');
60          return classname.substring(p + 1);
61      }
62  
63      static String getClassName(String classname)
64      {
65          if (classname == null) {
66              return null;
67          }
68          classname = normalizeClassName(classname);
69          final int p = classname.lastIndexOf('.');
70          return classname.substring(p + 1);
71      } 
72  }