texsoft.java.object
Class XsObjectUtil

java.lang.Object
  extended bytexsoft.java.object.XsObjectUtil

public abstract class XsObjectUtil
extends java.lang.Object

This class provides some usefull utility reflection related methods and provides internal utility methods for the texsoft.java.object package (with package visibility).

The class is declared abstract so only its static methods can be used.


Constructor Summary
XsObjectUtil()
           
 
Method Summary
static java.lang.String capitalize(java.lang.String prop)
          Returns the String passed as argument capitalized.
static java.lang.Object fromNull(java.lang.Class type)
          If type is a primitive type returns an appropriate wrapper set to 0, '\0' or false depending on the type, otherwise simply return null.
static java.lang.Object fromString(java.lang.Class type, java.lang.String v)
          Try a conversion from String to the class type.
static java.lang.Class getClassForName(java.lang.String type)
          Given a full qualified class name type, returns the corresponding Class object.
static java.lang.String getNameForClass(java.lang.String fullname)
          Given a full qualified class name returns the name only of the class, the package part is removed if present.
static java.lang.String getPackageForClass(java.lang.String fullname)
          Given a full qualified class name return the package part only, if the class name has not package part return an empty String.
static java.lang.Class getWrapperFor(java.lang.Class type)
          If type is a primitive type returns the appropriate wrapper Class for it otherwise returns type itself.
static boolean isNumeric(java.lang.Class type)
          Returns true if the passed Class is a numeric primitive Java type or a wrapper class for a numeric primitive Java type.
static boolean isNumericPrimitive(java.lang.Class type)
          Returns true if the passed Class is a numeric primitive Java type.
static boolean isNumericWrapper(java.lang.Class type)
          Returns true if the passed Class is a wrapper for a numeric primitive Java type.
static boolean isPrimitive(java.lang.Class type)
          Returns true if the passed Class is a primitive Java type.
static boolean isPrimitiveWrapper(java.lang.Class type)
          Returns true if the passed Class is a wrapper for a primitive Java type.
static java.lang.Object toObject(boolean v)
          Given a boolean returns a Boolean object initialized with the passed argument.
static java.lang.Object toObject(byte v)
          Given a byte returns a Byte object initialized with the passed argument.
static java.lang.Object toObject(char v)
          Given a char returns a Character object initialized with the passed argument.
static java.lang.Object toObject(double v)
          Given a double returns a Double object initialized with the passed argument.
static java.lang.Object toObject(float v)
          Given a float returns a Float object initialized with the passed argument.
static java.lang.Object toObject(int v)
          Given a int returns a Integer object initialized with the passed argument.
static java.lang.Object toObject(long v)
          Given a long returns a Long object initialized with the passed argument.
static java.lang.Object toObject(short v)
          Given a short returns a Short object initialized with the passed argument.
static java.lang.String unCapitalize(java.lang.String prop)
          Returns the String passed as argument uncapitalized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XsObjectUtil

public XsObjectUtil()
Method Detail

capitalize

public static java.lang.String capitalize(java.lang.String prop)
Returns the String passed as argument capitalized.

Parameters:
prop - a string to be capitalized.
Returns:
the passed string with first character capitalized.

unCapitalize

public static java.lang.String unCapitalize(java.lang.String prop)
Returns the String passed as argument uncapitalized.

Parameters:
prop - a string to be uncapitalized.
Returns:
the passed string with first character uncapitalized.

isPrimitive

public static boolean isPrimitive(java.lang.Class type)
Returns true if the passed Class is a primitive Java type.

Parameters:
type - object to be checked.
Returns:
true if the passed Class is a primitive Java type.

isNumericPrimitive

public static boolean isNumericPrimitive(java.lang.Class type)
Returns true if the passed Class is a numeric primitive Java type.

Parameters:
type - object to be checked.
Returns:
true if the passed Class is a numeric primitive Java type.

isPrimitiveWrapper

public static boolean isPrimitiveWrapper(java.lang.Class type)
Returns true if the passed Class is a wrapper for a primitive Java type.

Parameters:
type - object to be checked.
Returns:
true is the passed Class is a wrapper of a primitive Java type.

isNumericWrapper

public static boolean isNumericWrapper(java.lang.Class type)
Returns true if the passed Class is a wrapper for a numeric primitive Java type.

Parameters:
type - Class to be checked
Returns:
true if the passed Class is a wrapper for a numeric primitive Java type

isNumeric

public static boolean isNumeric(java.lang.Class type)
Returns true if the passed Class is a numeric primitive Java type or a wrapper class for a numeric primitive Java type.

Parameters:
type - Class object to be checked.
Returns:
Returns true if the passed Class is a numeric primitive Java type or a wrapper class for a numeric primitive Java type.

getNameForClass

public static java.lang.String getNameForClass(java.lang.String fullname)
Given a full qualified class name returns the name only of the class, the package part is removed if present.

Parameters:
fullname - full qualified class name.
Returns:
only the name of the class without the package part.

getPackageForClass

public static java.lang.String getPackageForClass(java.lang.String fullname)
Given a full qualified class name return the package part only, if the class name has not package part return an empty String.

Parameters:
fullname - full qualified class name.
Returns:
returns the package part of the class name, or an empty String if no package part is present.

fromString

public static java.lang.Object fromString(java.lang.Class type,
                                          java.lang.String v)
Try a conversion from String to the class type.

If type is a primitive types return a corresponding wrapper. If type is a non primitive type try to create a new instance of it with a constructor that get a String parameter. It assumes that the given class has a constructor that accept a String argument from which the object itselft can be initialized.

Returns null if it can't convert, in which case the caller must handle the situation and throw and exception if appropriate. NullPointerException and numeric conversion exceptions are not catched inside and may be thrown and should be handled by the caller.

Parameters:
type - class type to which the String parameter v has to be converted.
v - string value to be converted into object of class type.
Returns:
an object of class type or null if the string can't be converted to type.

fromNull

public static java.lang.Object fromNull(java.lang.Class type)
If type is a primitive type returns an appropriate wrapper set to 0, '\0' or false depending on the type, otherwise simply return null.

Parameters:
type - class for which a null rapresentation has to be returned.
Returns:
a wrapper for primitive types set to 0, \0 or false, or simply null if the argument class is not a primitive Java type.

getWrapperFor

public static java.lang.Class getWrapperFor(java.lang.Class type)
If type is a primitive type returns the appropriate wrapper Class for it otherwise returns type itself.

Parameters:
type - class for which a wrapper class has to be returned.
Returns:
a wrapper for primitive type if type is a primitive Java type, type otherwise.

getClassForName

public static java.lang.Class getClassForName(java.lang.String type)
                                       throws java.lang.ClassNotFoundException
Given a full qualified class name type, returns the corresponding Class object. Manages primitive type names too.

Parameters:
type - class name for which the Class object has to be returned, can be also a primitive type as "int", "char", "void", etc.
Returns:
a wrapper for primitive type if type is a primitive Java type, type otherwise.
Throws:
java.lang.ClassNotFoundException - throws if the given class name type does not match any loaded class.

toObject

public static java.lang.Object toObject(byte v)
Given a byte returns a Byte object initialized with the passed argument.

Parameters:
v - a byte value
Returns:
return a wrapper for the method's argument

toObject

public static java.lang.Object toObject(short v)
Given a short returns a Short object initialized with the passed argument.

Parameters:
v - a short value
Returns:
return a wrapper for the method's argument

toObject

public static java.lang.Object toObject(int v)
Given a int returns a Integer object initialized with the passed argument.

Parameters:
v - a int value
Returns:
return a wrapper for the method's argument

toObject

public static java.lang.Object toObject(long v)
Given a long returns a Long object initialized with the passed argument.

Parameters:
v - a long value
Returns:
return a wrapper for the method's argument

toObject

public static java.lang.Object toObject(float v)
Given a float returns a Float object initialized with the passed argument.

Parameters:
v - a float value
Returns:
return a wrapper for the method's argument

toObject

public static java.lang.Object toObject(double v)
Given a double returns a Double object initialized with the passed argument.

Parameters:
v - a double value
Returns:
return a wrapper for the method's argument

toObject

public static java.lang.Object toObject(char v)
Given a char returns a Character object initialized with the passed argument.

Parameters:
v - a char value
Returns:
return a wrapper for the method's argument

toObject

public static java.lang.Object toObject(boolean v)
Given a boolean returns a Boolean object initialized with the passed argument.

Parameters:
v - a boolean value
Returns:
return a wrapper for the method's argument