org.apache.hivemind.service
Class ClassFabUtils

java.lang.Object
  extended by org.apache.hivemind.service.ClassFabUtils

public class ClassFabUtils
extends java.lang.Object

Static class containing utility methods.

Author:
Howard Lewis Ship

Method Summary
static void addNoOpMethod(ClassFab cf, MethodSignature m)
          Adds a method that does nothing.
static void addToStringMethod(ClassFab classFab, java.lang.String toStringResult)
          Adds a toString() method to a class that returns a fixed, pre-computed value.
static java.lang.String generateClassName(java.lang.Class interfaceClass)
          Returns a class name derived from the provided interfaceClass.
static java.lang.String generateClassName(java.lang.String baseName)
          Generates a unique class name, which will be in the default package.
static java.lang.Class getInstanceClass(java.lang.Object instance, java.lang.Class interfaceClass)
          Returns the class of an instance.
static java.lang.String getJavaClassName(java.lang.Class inputClass)
          Javassist needs the class name to be as it appears in source code, even for arrays.
static boolean isToString(java.lang.reflect.Method method)
          Returns true if the method is the standard toString() method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

generateClassName

public static java.lang.String generateClassName(java.lang.String baseName)
Generates a unique class name, which will be in the default package.


generateClassName

public static java.lang.String generateClassName(java.lang.Class interfaceClass)
Returns a class name derived from the provided interfaceClass. The package part of the interface name is stripped out, and the result passed to generateClassName(String).

Since:
1.1

getJavaClassName

public static java.lang.String getJavaClassName(java.lang.Class inputClass)
Javassist needs the class name to be as it appears in source code, even for arrays. Invoking getName() on a Class instance representing an array returns the internal format (i.e, "[...;" or something). This returns it as it would appear in Java code.


isToString

public static boolean isToString(java.lang.reflect.Method method)
Returns true if the method is the standard toString() method. Very few interfaces will ever include this method as part of the interface, but we have to be sure.


addToStringMethod

public static void addToStringMethod(ClassFab classFab,
                                     java.lang.String toStringResult)
Adds a toString() method to a class that returns a fixed, pre-computed value.

Parameters:
classFab - ClassFab used to construct the new class.
toStringResult - fixed result to be returned by the method.

getInstanceClass

public static java.lang.Class getInstanceClass(java.lang.Object instance,
                                               java.lang.Class interfaceClass)
Returns the class of an instance. However, if the instance is, in fact, a JDK proxy, returns the interfaceClass (because JDK proxies do not work with Javassist).

Parameters:
instance - the object instance to obtain a class from
interfaceClass - the interface class to return if the instance is a JDK proxy.

addNoOpMethod

public static void addNoOpMethod(ClassFab cf,
                                 MethodSignature m)
Adds a method that does nothing. If the method returns a value, it will return null, 0 or false (depending on the type).

Since:
1.1