Top Description Inners Fields Constructors Methods
org.springframework.cglib.core

public abstract Class KeyFactory

extends Object
Class Inheritance
Annotations
@SuppressWarnings:rawtypes, unchecked
Imports
java.lang.reflect.Method, java.security.ProtectionDomain, java.util.Collections, .List, org.springframework.asm.ClassVisitor, .Label, .Type, org.springframework.cglib.core.internal.CustomizerRegistry

Generates classes to handle multi-valued keys, for use in things such as Maps and Sets. Code for equals and hashCode methods follow the the rules laid out in Effective Java by Joshua Bloch.

To generate a KeyFactory, you need to supply an interface which describes the structure of the key. The interface should have a single method named newInstance, which returns an Object. The arguments array can be anything--Objects, primitive values, or single or multi-dimension arrays of either. For example:

    private interface IntStringKey {
        public Object newInstance(int i, String s);
    }

Once you have made a KeyFactory, you generate a new key by calling the newInstance method defined by your interface.

    IntStringKey factory = (IntStringKey)KeyFactory.create(IntStringKey.class);
    Object key1 = factory.newInstance(4, "Hello");
    Object key2 = factory.newInstance(4, "World");

Note

hashCode equality between two keys key1 and key2 is only guaranteed if key1.equals(key2) and the keys were produced by the same factory.

Version
$Id: KeyFactory.java,v 1.26 2006/03/05 02:43:19 herbyderby Exp $

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private static final Signature
public static final Customizer
private static final Signature
private static final Signature
private static final Signature
private static final Signature
public static final HashCodeCustomizer
HASH_ASM_TYPE

Type#hashCode() is very expensive as it traverses full descriptor to calculate hash code.

private static final Signature
private static final Type
public static final Customizer
OBJECT_BY_CLASS

Deprecated this customizer might result in unexpected class leak since key object still holds a strong reference to the Object and class. It is recommended to have pre-processing method that would strip Objects and represent Classes as Strings
private static final int[]
public static final FieldTypeCustomizer
private static final Signature

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static KeyFactory
create(Class<T> keyInterface)

public static KeyFactory
create(Class<T> keyInterface, Customizer customizer)

public static KeyFactory
public static KeyFactory
create(ClassLoader loader, Class<T> keyInterface, Customizer customizer)

public static KeyFactory
create(ClassLoader loader, Class<T> keyInterface, KeyFactoryCustomizer customizer, List<KeyFactoryCustomizer> next)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

APPEND_STRINGback to summary
private static final Signature APPEND_STRING
CLASS_BY_NAMEback to summary
public static final Customizer CLASS_BY_NAME
EQUALSback to summary
private static final Signature EQUALS
GET_CLASSback to summary
private static final Signature GET_CLASS
GET_NAMEback to summary
private static final Signature GET_NAME
GET_SORTback to summary
private static final Signature GET_SORT
HASH_ASM_TYPEback to summary
public static final HashCodeCustomizer HASH_ASM_TYPE

Type#hashCode() is very expensive as it traverses full descriptor to calculate hash code. This customizer uses Type#getSort() as a hash code.

HASH_CODEback to summary
private static final Signature HASH_CODE
KEY_FACTORYback to summary
private static final Type KEY_FACTORY
OBJECT_BY_CLASSback to summary
public static final Customizer OBJECT_BY_CLASS

Deprecated

this customizer might result in unexpected class leak since key object still holds a strong reference to the Object and class. It is recommended to have pre-processing method that would strip Objects and represent Classes as Strings

Annotations
@Deprecated
PRIMESback to summary
private static final int[] PRIMES
STORE_CLASS_AS_STRINGback to summary
public static final FieldTypeCustomizer STORE_CLASS_AS_STRING
TO_STRINGback to summary
private static final Signature TO_STRING

Constructor Detail

KeyFactoryback to summary
protected KeyFactory()

Method Detail

createback to summary
public static KeyFactory create(Class<T> keyInterface)
createback to summary
public static KeyFactory create(Class<T> keyInterface, Customizer customizer)
createback to summary
public static KeyFactory create(Class<T> keyInterface, KeyFactoryCustomizer first, List<KeyFactoryCustomizer> next)
createback to summary
public static KeyFactory create(ClassLoader loader, Class<T> keyInterface, Customizer customizer)
createback to summary
public static KeyFactory create(ClassLoader loader, Class<T> keyInterface, KeyFactoryCustomizer customizer, List<KeyFactoryCustomizer> next)
org.springframework.cglib.core back to summary

public Class KeyFactory.Generator

extends AbstractClassGenerator
Class Inheritance

Field Summary

Modifier and TypeField and Description
private int
private CustomizerRegistry
private Class<T>
private static final Class<T>[]
private int
private static final AbstractClassGenerator.Source

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public KeyFactory
protected Object
public void
public <T> List<T>
protected ClassLoader
private String
getFieldName(int arg)

protected ProtectionDomain
getProtectionDomain()

Overrides org.springframework.cglib.core.AbstractClassGenerator.getProtectionDomain.

Returns the protection domain to use when defining the class.
protected Object
public void
setCustomizer(Customizer customizer)

Deprecated Use addCustomizer(KeyFactoryCustomizer) instead.
public void
setHashConstant(int constant)

public void
setHashMultiplier(int multiplier)

public void
setInterface(Class<T> keyInterface)

Inherited from org.springframework.cglib.core.AbstractClassGenerator:
creategenerategetAttemptLoadgetClassLoadergetClassNamegetCurrentgetNamingPolicygetStrategygetUseCachesetAttemptLoadsetClassLoadersetContextClasssetNamePrefixsetNamingPolicysetStrategysetUseCacheunwrapCachedValuewrapCachedClass

Field Detail

constantback to summary
private int constant
customizersback to summary
private CustomizerRegistry customizers
keyInterfaceback to summary
private Class<T> keyInterface
KNOWN_CUSTOMIZER_TYPESback to summary
private static final Class<T>[] KNOWN_CUSTOMIZER_TYPES
multiplierback to summary
private int multiplier
SOURCEback to summary
private static final AbstractClassGenerator.Source SOURCE

Constructor Detail

Generatorback to summary
public Generator()

Method Detail

addCustomizerback to summary
public void addCustomizer(KeyFactoryCustomizer customizer)
createback to summary
public KeyFactory create()
firstInstanceback to summary
protected Object firstInstance(Class<T> type)

Implements abstract org.springframework.cglib.core.AbstractClassGenerator.firstInstance.

Annotations
@Override
generateClassback to summary
public void generateClass(ClassVisitor v)

Implements org.springframework.cglib.core.ClassGenerator.generateClass.

Annotations
@Override
getCustomizersback to summary
public <T> List<T> getCustomizers(Class<T> klass)
getDefaultClassLoaderback to summary
protected ClassLoader getDefaultClassLoader()

Implements abstract org.springframework.cglib.core.AbstractClassGenerator.getDefaultClassLoader.

Annotations
@Override
getFieldNameback to summary
private String getFieldName(int arg)
getProtectionDomainback to summary
protected ProtectionDomain getProtectionDomain()

Overrides org.springframework.cglib.core.AbstractClassGenerator.getProtectionDomain.

Doc from org.springframework.cglib.core.AbstractClassGenerator.getProtectionDomain.

Returns the protection domain to use when defining the class.

Default implementation returns null for using a default protection domain. Sub-classes may override to use a more specific protection domain.

Returns:ProtectionDomain

the protection domain (null for using a default)

Annotations
@Override
nextInstanceback to summary
protected Object nextInstance(Object instance)

Implements abstract org.springframework.cglib.core.AbstractClassGenerator.nextInstance.

Annotations
@Override
setCustomizerback to summary
public void setCustomizer(Customizer customizer)

Deprecated

Use addCustomizer(KeyFactoryCustomizer) instead.

Annotations
@Deprecated
setHashConstantback to summary
public void setHashConstant(int constant)
setHashMultiplierback to summary
public void setHashMultiplier(int multiplier)
setInterfaceback to summary
public void setInterface(Class<T> keyInterface)