View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.apt.generate;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  public class ClassUtils {
26  
27    private static final Map<String, Class> PRIMITIVE_MAP;
28  
29    static {
30      PRIMITIVE_MAP = new HashMap<String, Class>(8);
31      PRIMITIVE_MAP.put("boolean", Boolean.class);
32      PRIMITIVE_MAP.put("byte", Byte.class);
33      PRIMITIVE_MAP.put("char", Character.class);
34      PRIMITIVE_MAP.put("short", Short.class);
35      PRIMITIVE_MAP.put("int", Integer.class);
36      PRIMITIVE_MAP.put("long", Long.class);
37      PRIMITIVE_MAP.put("float", Float.class);
38      PRIMITIVE_MAP.put("double", Double.class);
39    }
40  
41    private ClassUtils() {
42    }
43  
44    public static String getPackageName(String qualifiedName) {
45      int pos = qualifiedName.lastIndexOf('.');
46      if (pos != -1) {
47        return qualifiedName.substring(0, pos);
48      }
49      return null;
50    }
51  
52    public static String getSimpleName(String qualifiedName) {
53      int pos = qualifiedName.lastIndexOf('.');
54      if (pos != -1) {
55        return qualifiedName.substring(pos + 1);
56      }
57      return null;
58    }
59  
60    public static boolean isSystemClass(String qualifiedClassName) {
61      return qualifiedClassName.startsWith("java.lang.");
62    }
63  
64    public static boolean isPrimitive(String name) {
65      return PRIMITIVE_MAP.containsKey(name);
66    }
67  
68    public static Class getWrapper(String primitive) {
69      return PRIMITIVE_MAP.get(primitive);
70    }
71  }