org.apache.tapestry5.ioc.services
Class ClassFabUtils

java.lang.Object
  extended by org.apache.tapestry5.ioc.services.ClassFabUtils

public final class ClassFabUtils
extends Object

Handy method useful when creating new classes using ClassFab.


Constructor Summary
ClassFabUtils()
           
 
Method Summary
static String castReference(String reference, String desiredType)
          Takes a reference and casts it to the desired type.
static
<T> T
createObjectCreatorProxy(ClassFab classFab, Class<T> serviceInterface, ObjectCreator creator, String description)
          Creates a proxy for a given service interface around an ObjectCreator that can provide (on demand) an object (implementing the service interface) to delegate to.
static String generateClassName(Class interfaceClass)
          Returns a class name derived from the provided interfaceClass.
static String generateClassName(String baseName)
          Generates a unique class name, which will be in the default package.
static Class getPrimitiveType(Class wrapperType)
          Given a wrapper type, determines the corresponding primitive type.
static Class getPrimitiveType(String primitiveTypeName)
           
static String getTypeCode(Class type)
          Converts a Class to a JVM type code (the way class information is expressed in a class file).
static String getUnwrapMethodName(Class primitiveType)
          Given a primitive type, finds the unwrap method of the corresponding wrapper type.
static Class getWrapperType(Class type)
          Returns the wrapper type for an input type; for most types, this is the type.
static boolean isPrimitiveType(String typeName)
          Given a type name, determines if that is the name of a primitive type.
static boolean isToString(Method method)
          Returns true if the method is the standard toString() method.
static String toJavaClassName(Class inputClass)
          Javassist needs the class name to be as it appears in source code, even for arrays.
static String toJVMBinaryName(String type)
          Translates types from standard Java format to Java VM format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFabUtils

public ClassFabUtils()
Method Detail

generateClassName

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


generateClassName

public static String generateClassName(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).


toJavaClassName

public static String toJavaClassName(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(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.


getPrimitiveType

public static Class getPrimitiveType(String primitiveTypeName)

toJVMBinaryName

public static String toJVMBinaryName(String type)
Translates types from standard Java format to Java VM format. For example, java.util.Locale remains java.util.Locale, but int[][] is translated to [[I and java.lang.Object[] to [Ljava.lang.Object;


getPrimitiveType

public static Class getPrimitiveType(Class wrapperType)
Given a wrapper type, determines the corresponding primitive type.


getWrapperType

public static Class getWrapperType(Class type)
Returns the wrapper type for an input type; for most types, this is the type. For primitive types, it is the corresponding wrapper type.

Parameters:
type - type to check
Returns:
type or corresponding wrapper type

castReference

public static String castReference(String reference,
                                   String desiredType)
Takes a reference and casts it to the desired type. If the desired type is a primitive type, then the reference is cast to the correct wrapper type and a call to the correct unwrapper method is added. The end result is code that can be assigned to a field or parameter of the desired type (even if desired type is a primitive).

Parameters:
reference - to be cast
desiredType - desired object or primitive type
Returns:
Javassist code to peform the cast

getUnwrapMethodName

public static String getUnwrapMethodName(Class primitiveType)
Given a primitive type, finds the unwrap method of the corresponding wrapper type.

Parameters:
primitiveType -
Returns:
method name

isPrimitiveType

public static boolean isPrimitiveType(String typeName)
Given a type name, determines if that is the name of a primitive type.


getTypeCode

public static String getTypeCode(Class type)
Converts a Class to a JVM type code (the way class information is expressed in a class file).


createObjectCreatorProxy

public static <T> T createObjectCreatorProxy(ClassFab classFab,
                                             Class<T> serviceInterface,
                                             ObjectCreator creator,
                                             String description)
Creates a proxy for a given service interface around an ObjectCreator that can provide (on demand) an object (implementing the service interface) to delegate to. The ObjectCreator will be invoked on every method invocation (if it is caching, that should be internal to its implementation).

Type Parameters:
T -
Parameters:
classFab - used to create the new class
serviceInterface - the interface the proxy will implement
creator - the createor which will provide an instance of the interface
description - description to be returned from the proxy's toString() method
Returns:
the instantiated proxy object


Copyright © 2006-2009 Apache Software Foundation. All Rights Reserved.