Java examples for Reflection:Class Name
Extracts the name from the given qualified reference value.
/******************************************************************************* * Copyright (c) 2004 Actuate Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w ww .ja va 2 s . c o m*/ * Actuate Corporation - initial API and implementation *******************************************************************************/ public class Main{ public static void main(String[] argv){ String qualifiedName = "java2s.com"; System.out.println(extractName(qualifiedName)); } /** * Extracts the name from the given qualified reference value. * * <p> * For example, * <ul> * <li>"style1" is extracted from "LibA.style1" * <li>"style1" is returned from "style1" * </ul> * * @param qualifiedName * the qualified reference value * @return the name */ public static String extractName(String qualifiedName) { if (qualifiedName == null) return null; int pos = qualifiedName.indexOf('.'); if (pos == -1) return qualifiedName; return trimString(qualifiedName.substring(pos + 1)); } /** * Trim a string. Removes leading and trailing blanks. If the resulting * string is empty, normalizes the string to an null string. * * @param value * the string to trim * @return the trimmed string, or null if the string is empty */ public static String trimString(String value) { if (value == null) return null; value = value.trim(); if (value.length() == 0) return null; return value; } }