001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.spring.util;
016    
017    /**
018     * @author Shuyang Zhou
019     */
020    public class ClassNameUtil {
021    
022            public static String getClassName(String className)
023                    throws ClassNotFoundException {
024    
025                    Thread currentThread = Thread.currentThread();
026    
027                    ClassLoader classLoader = currentThread.getContextClassLoader();
028    
029                    return getClassName(className, classLoader);
030            }
031    
032            public static String getClassName(String className, ClassLoader classLoader)
033                    throws ClassNotFoundException {
034    
035                    Class<?> clazz = Class.forName(className, false, classLoader);
036    
037                    return clazz.getName();
038            }
039    
040            public static String getSimpleClassName(String className)
041                    throws ClassNotFoundException {
042    
043                    Thread currentThread = Thread.currentThread();
044    
045                    ClassLoader classLoader = currentThread.getContextClassLoader();
046    
047                    return getSimpleClassName(className, classLoader);
048            }
049    
050            public static String getSimpleClassName(
051                            String className, ClassLoader classLoader)
052                    throws ClassNotFoundException {
053    
054                    Class<?> clazz = Class.forName(className, false, classLoader);
055    
056                    return clazz.getSimpleName();
057            }
058    
059    }