org.springframework.osgi.util
Class ClassUtils

java.lang.Object
  extended by org.springframework.osgi.util.ClassUtils

public abstract class ClassUtils
extends Object

Class utility used internally. Contains mianly class inheritance mechanisms used when creating OSGi service proxies.

Author:
Costin Leau

Field Summary
static int INCLUDE_ALL_CLASSES
          Include all inherited classes (classes or interfaces).
static int INCLUDE_CLASS_HIERARCHY
          Include only the class hierarchy (interfaces are excluded).
static int INCLUDE_INTERFACES
          Include only the interfaces inherited from superclasses or implemented by the current class.
 
Constructor Summary
ClassUtils()
           
 
Method Summary
static boolean concurrentLibAvailable()
          Check the present of approapriate concurrent collection in the classpath.
static void configureFactoryForClass(ProxyFactory factory, Class[] classes)
          Based on the given class, properly instruct the ProxyFactory proxies.
static boolean containsUnrelatedClasses(Class[] classes)
          Determining if multiple classes(not interfaces) are specified, without any relation to each other.
static Class[] getAllInterfaces(Class clazz)
          Get all interfaces implemented by the given class.
static Class[] getClassHierarchy(Class clazz, int mode)
          Return an array of parent classes for the given class.
static ClassLoader getClassLoader(Class clazz)
          Return the classloader for the given class.
static Class[] getVisibleClasses(Class[] classes, Bundle bundle)
          Given an array of classes, eliminate the ones that cannot be loaded by the given bundle.
static Class[] getVisibleClasses(Class[] classes, ClassLoader classLoader)
          Given an array of classes, eliminate the ones that cannot be loaded by the given classloader.
static Class[] getVisibleClassHierarchy(Class clazz, int mode, Bundle bundle)
          'Sugar' method that determines the class hierarchy of the given class, returning only the classes visible to the given bundle.
static Class[] getVisibleClassHierarchy(Class clazz, int mode, ClassLoader loader)
          Sugar method, determining the class hierarchy of a given class and then filtering based on the given classloader.
static boolean isPresent(String className, Bundle bundle)
          Check the present of a class inside a bundle.
static Class[] removeParents(Class[] classes)
          Parse the given class array and eliminate parents of existing classes.
static String[] toStringArray(Class[] array)
          Return an array of class string names for the given classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INCLUDE_INTERFACES

public static final int INCLUDE_INTERFACES
Include only the interfaces inherited from superclasses or implemented by the current class.

See Also:
Constant Field Values

INCLUDE_CLASS_HIERARCHY

public static final int INCLUDE_CLASS_HIERARCHY
Include only the class hierarchy (interfaces are excluded).

See Also:
Constant Field Values

INCLUDE_ALL_CLASSES

public static final int INCLUDE_ALL_CLASSES
Include all inherited classes (classes or interfaces).

See Also:
Constant Field Values
Constructor Detail

ClassUtils

public ClassUtils()
Method Detail

getClassHierarchy

public static Class[] getClassHierarchy(Class clazz,
                                        int mode)
Return an array of parent classes for the given class. The mode paramater indicates whether only interfaces should be included, classes or both. This method is normally used for publishing services and determing the Constants.OBJECTCLASS property.

Note: this method does class expansion returning parent as well as children classes.

Parameters:
clazz -
mode -
classLoader -
Returns:
array of classes extended or implemented by the given class
See Also:
INCLUDE_ALL_CLASSES, INCLUDE_CLASS_HIERARCHY, INCLUDE_INTERFACES

getVisibleClassHierarchy

public static Class[] getVisibleClassHierarchy(Class clazz,
                                               int mode,
                                               ClassLoader loader)
Sugar method, determining the class hierarchy of a given class and then filtering based on the given classloader. If a null classloader, the one of the given class will be used.

Parameters:
clazz -
mode -
loader -
Returns:

getVisibleClassHierarchy

public static Class[] getVisibleClassHierarchy(Class clazz,
                                               int mode,
                                               Bundle bundle)
'Sugar' method that determines the class hierarchy of the given class, returning only the classes visible to the given bundle.

Parameters:
clazz - the class for which the hierarchy has to be determined
mode - discovery mode
bundle - bundle used for class visibility
Returns:
array of visible classes part of the hierarchy

getVisibleClasses

public static Class[] getVisibleClasses(Class[] classes,
                                        ClassLoader classLoader)
Given an array of classes, eliminate the ones that cannot be loaded by the given classloader.

Returns:

getVisibleClasses

public static Class[] getVisibleClasses(Class[] classes,
                                        Bundle bundle)
Given an array of classes, eliminate the ones that cannot be loaded by the given bundle.

Returns:

getAllInterfaces

public static Class[] getAllInterfaces(Class clazz)
Get all interfaces implemented by the given class. This method returns both parent and children interfaces (i.e. Map and SortedMap).

Parameters:
clazz -
Returns:
all interfaces implemented by the given class.

isPresent

public static boolean isPresent(String className,
                                Bundle bundle)
Check the present of a class inside a bundle. This method returns true if the given bundle can load the given class or false otherwise.

Parameters:
className -
bundle -
Returns:

getClassLoader

public static ClassLoader getClassLoader(Class clazz)
Return the classloader for the given class. This method deals with JDK classes which return by default, a null classloader.

Parameters:
clazz -
Returns:

toStringArray

public static String[] toStringArray(Class[] array)
Return an array of class string names for the given classes.

Parameters:
array -
Returns:

concurrentLibAvailable

public static boolean concurrentLibAvailable()
Check the present of approapriate concurrent collection in the classpath. This means backport-concurrent on Java 1.4, or Java5+.

Returns:
true if a ConcurrentHashMap is available on the classpath.

containsUnrelatedClasses

public static boolean containsUnrelatedClasses(Class[] classes)
Determining if multiple classes(not interfaces) are specified, without any relation to each other. Interfaces will simply be ignored.

Parameters:
classes - an array of classes
Returns:
true if at least two classes unrelated to each other are found, false otherwise

removeParents

public static Class[] removeParents(Class[] classes)
Parse the given class array and eliminate parents of existing classes. Useful when creating proxies to minimize the number of implemented interfaces and redundant class information.

Parameters:
classes - array of classes
Returns:
a new array without superclasses
See Also:
containsUnrelatedClasses(Class[]), configureFactoryForClass(ProxyFactory, Class[])

configureFactoryForClass

public static void configureFactoryForClass(ProxyFactory factory,
                                            Class[] classes)
Based on the given class, properly instruct the ProxyFactory proxies. For additional sanity checks on the passed classes, check the methods below.

Parameters:
factory -
classes -
See Also:
containsUnrelatedClasses(Class[]), removeParents(Class[])


Copyright © 2006-2007 Spring Framework. All Rights Reserved.