Determine whether the supplied string represents a well-formed fully-qualified Java classname. : Class « Reflection « Java Tutorial






/*
 * JBoss DNA (http://www.jboss.org/dna)
 * See the COPYRIGHT.txt file distributed with this work for information
 * regarding copyright ownership.  Some portions may be licensed
 * to Red Hat, Inc. under one or more contributor license agreements.
 * See the AUTHORS.txt file in the distribution for a full listing of 
 * individual contributors. 
 *
 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
 * is licensed to you under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * JBoss DNA is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

import java.text.CharacterIterator;
import java.text.StringCharacterIterator;


public class Utils {

  /**
   * Determine whether the supplied string represents a well-formed fully-qualified Java classname. This utility method enforces
   * no conventions (e.g., packages are all lowercase) nor checks whether the class is available on the classpath.
   * 
   * @param classname
   * @return true if the string is a fully-qualified class name
   */
  public static boolean isFullyQualifiedClassname( String classname ) {
      if (classname == null) return false;
      String[] parts = classname.split("[\\.]");
      if (parts.length == 0) return false;
      for (String part : parts) {
          CharacterIterator iter = new StringCharacterIterator(part);
          // Check first character (there should at least be one character for each part) ...
          char c = iter.first();
          if (c == CharacterIterator.DONE) return false;
          if (!Character.isJavaIdentifierStart(c) && !Character.isIdentifierIgnorable(c)) return false;
          c = iter.next();
          // Check the remaining characters, if there are any ...
          while (c != CharacterIterator.DONE) {
              if (!Character.isJavaIdentifierPart(c) && !Character.isIdentifierIgnorable(c)) return false;
              c = iter.next();
          }
      }
      return true;
  }

}








7.1.Class
7.1.1.Get class name for various object
7.1.2.Create new instance
7.1.3.Get Canonical Name for a class
7.1.4.Demonstrates the use of getDeclaringClass()
7.1.5.Demonstrates the use of instance comparisons
7.1.6.Demonstrates usage of various class information methods
7.1.7.Demonstrates how to get declaration information on a Class
7.1.8.Demonstrates Dynamic class type checking
7.1.9.Demonstrates how to set public field objects
7.1.10.Demonstrates fetching nested class info from a Class object
7.1.11.Demonstration of how to obtain instances of java.lang.Class
7.1.12.Demonstrates getting immediate superclass info
7.1.13.Get declared method by name and parameter type
7.1.14.get class from an object
7.1.15.Returns the name of a class without the package name
7.1.16.Class comparator: compare and sort classes and their superclasses.
7.1.17.Is Type Compatible
7.1.18.Is the Same Signature
7.1.19.Determine whether the supplied string represents a well-formed fully-qualified Java classname.