Java examples for Reflection:Class Name
Extracts the library namespace 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:// w w w . j av a 2s . 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(extractNamespace(qualifiedName)); } /** * Extracts the library namespace from the given qualified reference value. * <p> * For example, * <ul> * <li>"LibA" is extracted from "LibA.style1" * <li>null is returned from "style1" * </ul> * * @param qualifiedName * the qualified reference value * @return the library namespace */ public static String extractNamespace(String qualifiedName) { if (qualifiedName == null) return null; int pos = qualifiedName.indexOf('.'); if (pos == -1) return null; return trimString(qualifiedName.substring(0, pos)); } /** * 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; } }