FileDocCategorySizeDatePackage
JavaTypeHelper.javaAPI DocGlassfish v2 API8237Fri May 04 22:35:20 BST 2007com.sun.jdo.spi.persistence.utility

JavaTypeHelper

public class JavaTypeHelper extends Object
This is a helper class which provides some basic java type convenience methods: extraction of a package from a fully qualified class name, extraction of a short (non-qualified) name from a fully qualified class name, and various wrapper and primitive type methods.
author
Rochelle Raccah

Fields Summary
private static final Map
_primitiveToWrappers
Map of primitive to wrapper classes
private static final Map
_primitiveNamesToPrimitives
Map of primitive names to primitive classes
private static final Map
_primitiveNamesToWrapperNames
Map of primitive names to wrapper names
private static final Map
_wrapperToPrimitiveNames
Map of wrapper classes to primitive names
Constructors Summary
Methods Summary
public static java.lang.StringgetPackageName(java.lang.String className)
Returns the package portion of the specified class

param
className the name of the class from which to extract the package
return
package portion of the specified class

		_primitiveToWrappers = new HashMap(9);
		_primitiveToWrappers.put(Boolean.TYPE, Boolean.class);
		_primitiveToWrappers.put(Byte.TYPE, Byte.class);
		_primitiveToWrappers.put(Character.TYPE, Character.class);
		_primitiveToWrappers.put(Double.TYPE, Double.class);
		_primitiveToWrappers.put(Float.TYPE, Float.class);
		_primitiveToWrappers.put(Integer.TYPE, Integer.class);
		_primitiveToWrappers.put(Long.TYPE, Long.class);
		_primitiveToWrappers.put(Short.TYPE, Short.class);
		_primitiveToWrappers.put(Void.TYPE, Void.class);

		_primitiveNamesToPrimitives = new HashMap(9);
		_primitiveNamesToPrimitives.put("boolean", Boolean.TYPE);	// NOI18N
		_primitiveNamesToPrimitives.put("byte", Byte.TYPE);			// NOI18N
		_primitiveNamesToPrimitives.put("char", Character.TYPE);	// NOI18N
		_primitiveNamesToPrimitives.put("double", Double.TYPE);		// NOI18N
		_primitiveNamesToPrimitives.put("float", Float.TYPE);		// NOI18N
		_primitiveNamesToPrimitives.put("int", Integer.TYPE);		// NOI18N
		_primitiveNamesToPrimitives.put("long", Long.TYPE);			// NOI18N
		_primitiveNamesToPrimitives.put("short", Short.TYPE);		// NOI18N
		_primitiveNamesToPrimitives.put("void", Void.TYPE);			// NOI18N

		_primitiveNamesToWrapperNames =  new HashMap(9);
		_primitiveNamesToWrapperNames.put("boolean", "Boolean");	// NOI18N
		_primitiveNamesToWrapperNames.put("byte", "Byte");			// NOI18N
		_primitiveNamesToWrapperNames.put("char", "Character");		// NOI18N
		_primitiveNamesToWrapperNames.put("double", "Double");		// NOI18N
		_primitiveNamesToWrapperNames.put("float", "Float");		// NOI18N
		_primitiveNamesToWrapperNames.put("int", "Integer");		// NOI18N
		_primitiveNamesToWrapperNames.put("long", "Long");			// NOI18N
		_primitiveNamesToWrapperNames.put("short", "Short");		// NOI18N
		_primitiveNamesToWrapperNames.put("void", "Void");			// NOI18N

		_wrapperToPrimitiveNames = new HashMap(9);
		_wrapperToPrimitiveNames.put(Boolean.class, "boolean");	// NOI18N
		_wrapperToPrimitiveNames.put(Byte.class, "byte");		// NOI18N
		_wrapperToPrimitiveNames.put(Character.class, "char");	// NOI18N
		_wrapperToPrimitiveNames.put(Double.class, "double");	// NOI18N
		_wrapperToPrimitiveNames.put(Float.class, "float");		// NOI18N
		_wrapperToPrimitiveNames.put(Integer.class, "int");		// NOI18N
		_wrapperToPrimitiveNames.put(Long.class, "long");		// NOI18N
		_wrapperToPrimitiveNames.put(Short.class, "short");		// NOI18N
		_wrapperToPrimitiveNames.put(Void.class, "void");		// NOI18N
	 
		if (className != null)
		{
			final int index = className.lastIndexOf('.");

			return ((index != -1) ? 
				className.substring(0, index) : ""); // NOI18N
		}

		return null;
    
public static java.lang.ClassgetPrimitiveClass(java.lang.String primitiveName)
Returns the primitive class associated with the supplied primitive type name.

param
primitiveName the name of the primitive to be used for lookup.
return
the associated primitive class.

		return (Class)_primitiveNamesToPrimitives.get(primitiveName);
	
public static java.lang.StringgetPrimitiveName(java.lang.Class wrapper)
Returns the name of the primitive type associated with the supplied wrapper class.

param
wrapper the wrapper class to be used for lookup.
return
the associated primitive type name.

		return (String)_wrapperToPrimitiveNames.get(wrapper);
	
public static java.lang.StringgetShortClassName(java.lang.String className)
Returns the name of a class without the package name. For example: if input = "java.lang.Object" , then output = "Object".

param
fully qualified classname

		if (className != null)
		{
			final int index = className.lastIndexOf('.");

			return className.substring(index + 1);
		}
		return null;
	
public static java.lang.ClassgetWrapperClass(java.lang.Class primitive)
Returns the wrapper class associated with the supplied primitive class.

param
primitive the primitive class to be used for lookup.
return
the associated wrapper class.

		return (Class)_primitiveToWrappers.get(primitive);
	
public static java.lang.StringgetWrapperName(java.lang.String primitiveName)
Returns the name of the wrapper class associated with the supplied primitive type name.

param
primitiveName the name of the primitive to be used for lookup.
return
the associated wrapper class name.

		return (String)_primitiveNamesToWrapperNames.get(primitiveName);
	
public static java.lang.BooleanvalueOf(boolean flag)
Returns the Boolean wrapper object for true or false corresponding to the supplied argument. This is to provide a convenience method for this conversion but to prevent calling the Boolean constructor which has been determined to be unnecessary and a performance problem. JDK 1.4 provides such a method, but some of our code still works with JDK 1.3.

param
flag the primitive boolean object to be translated to a Boolean wrapper.
return
the associated true/false shared wrapper object

		return (flag ? Boolean.TRUE : Boolean.FALSE);