org.norther.tammi.acorn.util.converter
Class Classes

java.lang.Object
  extended by org.norther.tammi.acorn.util.converter.Classes

public abstract class Classes
extends Object

Converts between object classes.

Author:
Ilkka Priha

Field Summary
static String ANY_DOMAIN
          The domain wildcard.
static String MBEAN_SUFFIX
          The MBean interface suffix.
 
Constructor Summary
Classes()
           
 
Method Summary
static Object getPropertyValue(Object bean, String field)
          Gets the value of the specified property.
static boolean isDateType(String className, boolean arrayp)
          Checks whether the specified class type is a date, i.e.
static void setPropertyValue(Object bean, String field, Object value)
          Sets the value of the specified property.
static String toBaseName(String name)
          Converts a localized name to its base name.
static Class toClass(String type)
          Converts a class or primitive type to the corresponding class by applying the default class loader.
static Class toClass(String type, ClassLoader loader)
          Converts a class or primitive type to the corresponding class by applying the specified class loader.
static Class[] toClassHierarchy(Class clazz)
          Converts the specified class to a class hierarchy of its implemented interfaces and extended superclasses.
static String toExtension(File file, String def)
          Converts a file to its extension.
static String toExtension(String path, String def)
          Converts a path to its extension.
static Locale toLocale(String str)
          Converts a string to a locale.
static String toLocalizedName(String name, Locale locale)
          Converts a base name to a localized name.
static String toLocalizedPath(String path, Locale locale)
          Converts a base path to a localized path.
static Class toMBean(Class clazz)
          Converts a class into its MBean interface.
static Locale toNamedLocale(String name)
          Converts a localized name to its corresponding locale.
static String toPackageName(String uri, String domain)
          Converts an URI path to a package name.
static Object[] toParameters(Object params, Object sign)
          Converts parameters into the corresponding parameter array.
static PropertyDescriptor toPropertyDescriptor(Class clazz, String field)
          Converts a field of a class into the corresponding property descriptor.
static String toSignature(Object param)
          Converts a parameter into the corresponding signature.
static String[] toSignature(Object params, Object sign)
          Converts parameters into the corresponding signature array.
static String toString(Locale locale)
          Converts a locale to a string.
static String[] toTypeHierarchy(String className)
          Converts the named class to a type hierarchy of its implemented interfaces and extended superclasses.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANY_DOMAIN

public static final String ANY_DOMAIN
The domain wildcard.

See Also:
Constant Field Values

MBEAN_SUFFIX

public static final String MBEAN_SUFFIX
The MBean interface suffix.

See Also:
Constant Field Values
Constructor Detail

Classes

public Classes()
Method Detail

toClass

public static Class toClass(String type)
                     throws ClassNotFoundException
Converts a class or primitive type to the corresponding class by applying the default class loader.

Parameters:
type - the type to convert.
Returns:
the corresponding class.
Throws:
ClassNotFoundException - if not found.

toClass

public static Class toClass(String type,
                            ClassLoader loader)
                     throws ClassNotFoundException
Converts a class or primitive type to the corresponding class by applying the specified class loader.

Parameters:
type - the type to convert.
loader - the class loader to apply.
Returns:
the corresponding class.
Throws:
ClassNotFoundException - if not found.

toClassHierarchy

public static Class[] toClassHierarchy(Class clazz)
Converts the specified class to a class hierarchy of its implemented interfaces and extended superclasses. The specified class is at index 0. Primitive types are converted to the corresponding object types and array types to component types.

Parameters:
clazz - the class to convert.
Returns:
an array of interfaces and superclasses.

toTypeHierarchy

public static String[] toTypeHierarchy(String className)
Converts the named class to a type hierarchy of its implemented interfaces and extended superclasses. The named class is at index 0. Primitive types are converted to the corresponding object types and array types to component types.

Parameters:
className - the named class to convert.
Returns:
an array of interface and superclass names.

isDateType

public static boolean isDateType(String className,
                                 boolean arrayp)
Checks whether the specified class type is a date, i.e. a subclass of java.util.Date.

Parameters:
className - the class type to check.
arrayp - true if an array type is accepted.
Returns:
true for a date type, otherwise false.

toString

public static String toString(Locale locale)
Converts a locale to a string. A plain variant without a language or country is accepted.

Parameters:
locale - the locale.
Returns:
the converted string or null.

toLocale

public static Locale toLocale(String str)
Converts a string to a locale. A null string, an empty string and an invalid string returns null.

Note that the conversion is case insensitive.

Parameters:
str - the locale string.
Returns:
the converted locale or null.

toNamedLocale

public static Locale toNamedLocale(String name)
Converts a localized name to its corresponding locale.

Parameters:
name - the localized name.
Returns:
the named locale or null.

toBaseName

public static String toBaseName(String name)
Converts a localized name to its base name.

Parameters:
name - the localized name.
Returns:
the corresponding base name.

toLocalizedName

public static String toLocalizedName(String name,
                                     Locale locale)
Converts a base name to a localized name.

Parameters:
name - the base name.
locale - the locale.
Returns:
the localized name.

toLocalizedPath

public static String toLocalizedPath(String path,
                                     Locale locale)
Converts a base path to a localized path.

Parameters:
path - the base name.
locale - the locale.
Returns:
the localized path.

toPackageName

public static String toPackageName(String uri,
                                   String domain)
Converts an URI path to a package name.

Parameters:
uri - the URI path to convert.
domain - the default domain to replace '*'.
Returns:
the corresponding package name or null i fnot valid.

toExtension

public static String toExtension(String path,
                                 String def)
Converts a path to its extension.

Parameters:
path - the path.
def - the default.
Returns:
the extension.

toExtension

public static String toExtension(File file,
                                 String def)
Converts a file to its extension.

Parameters:
file - the file.
def - the default.
Returns:
the extension.

toMBean

public static Class toMBean(Class clazz)
Converts a class into its MBean interface.

Parameters:
clazz - the class to convert.
Returns:
the MBean interface or null if not implemented.

toSignature

public static String toSignature(Object param)
Converts a parameter into the corresponding signature. Primitive types have precedence over the corresponding object types.

Parameters:
param - a parameter to convert.
Returns:
the converted signature.

toSignature

public static String[] toSignature(Object params,
                                   Object sign)
Converts parameters into the corresponding signature array. A list without a signature is treated as a list of separate parameters. Primitive types have precedence over corresponding object types.

Parameters:
params - parameters to convert.
sign - an optional signature.
Returns:
the converted signature.

toParameters

public static Object[] toParameters(Object params,
                                    Object sign)
Converts parameters into the corresponding parameter array. A list without a signature is treated as a list of separate parameters.

Parameters:
params - parameters to convert.
sign - an optional signature.
Returns:
the converted parameters.

toPropertyDescriptor

public static PropertyDescriptor toPropertyDescriptor(Class clazz,
                                                      String field)
Converts a field of a class into the corresponding property descriptor.

Parameters:
clazz - the class.
field - the field.
Returns:
the descriptor or null.

getPropertyValue

public static Object getPropertyValue(Object bean,
                                      String field)
                               throws IllegalAccessException,
                                      InvocationTargetException
Gets the value of the specified property.

Parameters:
bean - the bean.
field - the field.
Returns:
the value or null.
Throws:
IllegalAccessException - if inaccessible.
InvocationTargetException - if failed.
IllegalArgumentException - if not available.

setPropertyValue

public static void setPropertyValue(Object bean,
                                    String field,
                                    Object value)
                             throws IllegalAccessException,
                                    InvocationTargetException
Sets the value of the specified property.

Parameters:
bean - the bean.
field - the field.
value - the value.
Throws:
IllegalAccessException - if inaccessible.
InvocationTargetException - if failed.
IllegalArgumentException - if not available.


Copyright © 2004 The Norther Organization. All rights reserved.