Top Description Inners Fields Constructors Methods
com.sun.faces.application

public Class ConverterPropertyEditorFactory

extends Object
Class Inheritance
Static Imports
java.util.logging.Level.FINE, .Level.FINEST, .Level.WARNING

Factory for dynamically generating PropertyEditor classes that extend ConverterPropertyEditorBase and replace any references to the target class from the template with a supplied target class.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ConverterPropertyEditorFactory.ClassTemplateInfo

Capture information extracted from a "template" PropertyEditor class, and perform manipulation of the byte codes in order to generate the bytes for a new PropertyEditor class.

private class
ConverterPropertyEditorFactory.DisposableClassLoader

A custom class loader for the definition of the generated classes.

Field Summary

Modifier and TypeField and Description
private Map<ClassLoader, WeakReference<ConverterPropertyEditorFactory.DisposableClassLoader>>
private static ConverterPropertyEditorFactory
private static final Logger
private static final Pattern
private static final Map<Character, String>
private static final Pattern
private ConverterPropertyEditorFactory.ClassTemplateInfo
private static final Pattern

Constructor Summary

AccessConstructor and Description
public
ConverterPropertyEditorFactory()

Create a ConverterPropertyEditorFactory that uses the default template class (ConverterPropertyEditorFor_XXXX).

public
ConverterPropertyEditorFactory(Class<? extends ConverterPropertyEditorBase>
the template
templateClass
)

Create a ConverterPropertyEditorFactory that uses the specified template class.

Method Summary

Modifier and TypeMethod and Description
public Class<? extends ConverterPropertyEditorBase>

Returns:

the dynamically generated PropertyEditor class.
definePropertyEditorClassFor
(final Class<?>
the class of object that the returned property editor class will be editing.
targetClass
)

Return a PropertyEditor class appropriate for editing the given targetClass.

public static synchronized ConverterPropertyEditorFactory

Returns:

the single default instance of this class (created with the default template class).
getDefaultInstance
()

private ConverterPropertyEditorFactory.ClassTemplateInfo
private static byte[]

Returns:

the bytes for the UTF8Info constant pool entry, including the tag, length, and utf8 content.
getUtf8InfoBytes
(String
the text to create the UTF8 constant from.
text
)

Create a UTF8Info constant pool structure for the given text.

private static String

Returns:

the binary name of the class as used by the VM ('/' instead of '.' as a package name separator).
getVMClassName
(Class<?>
the class to find the name of.
c
)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classLoaderCacheback to summary
private Map<ClassLoader, WeakReference<ConverterPropertyEditorFactory.DisposableClassLoader>> classLoaderCache
defaultInstanceback to summary
private static ConverterPropertyEditorFactory defaultInstance
LOGGERback to summary
private static final Logger LOGGER
MultipleUnderscorePatternback to summary
private static final Pattern MultipleUnderscorePattern
PRIM_MAPback to summary
private static final Map<Character, String> PRIM_MAP
SingleUnderscorePatternback to summary
private static final Pattern SingleUnderscorePattern
templateInfoback to summary
private ConverterPropertyEditorFactory.ClassTemplateInfo templateInfo
UNDERSCORE_PATTERNback to summary
private static final Pattern UNDERSCORE_PATTERN

Constructor Detail

ConverterPropertyEditorFactoryback to summary
public ConverterPropertyEditorFactory()

Create a ConverterPropertyEditorFactory that uses the default template class (ConverterPropertyEditorFor_XXXX).

ConverterPropertyEditorFactoryback to summary
public ConverterPropertyEditorFactory(Class<? extends ConverterPropertyEditorBase> templateClass)

Create a ConverterPropertyEditorFactory that uses the specified template class.

Parameters
templateClass:Class<? extends ConverterPropertyEditorBase>

the template

Method Detail

definePropertyEditorClassForback to summary
public Class<? extends ConverterPropertyEditorBase> definePropertyEditorClassFor(final Class<?> targetClass)

Return a PropertyEditor class appropriate for editing the given targetClass. The new class will be defined from a DisposableClassLoader.

Parameters
targetClass:Class<?>

the class of object that the returned property editor class will be editing.

Returns:Class<? extends ConverterPropertyEditorBase>

the dynamically generated PropertyEditor class.

Annotations
@SuppressWarnings:unchecked
getDefaultInstanceback to summary
public static synchronized ConverterPropertyEditorFactory getDefaultInstance()
Returns:ConverterPropertyEditorFactory

the single default instance of this class (created with the default template class).

getTemplateInfoback to summary
private ConverterPropertyEditorFactory.ClassTemplateInfo getTemplateInfo()
getUtf8InfoBytesback to summary
private static byte[] getUtf8InfoBytes(String text)

Create a UTF8Info constant pool structure for the given text.

Parameters
text:String

the text to create the UTF8 constant from.

Returns:byte[]

the bytes for the UTF8Info constant pool entry, including the tag, length, and utf8 content.

getVMClassNameback to summary
private static String getVMClassName(Class<?> c)
Parameters
c:Class<?>

the class to find the name of.

Returns:String

the binary name of the class as used by the VM ('/' instead of '.' as a package name separator).

com.sun.faces.application back to summary

private Class ConverterPropertyEditorFactory.ClassTemplateInfo

extends Object
Class Inheritance
  • java.lang.Object
  • com.sun.faces.application.ConverterPropertyEditorFactory.ClassTemplateInfo

Capture information extracted from a "template" PropertyEditor class, and perform manipulation of the byte codes in order to generate the bytes for a new PropertyEditor class.

The new class bytes are generated by identifying UTF8Info entries in the constant pool of the template class, and replacing them with new UTF8 constants to define a new class. The constants to be replaced are those for:

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef

Capture details of the location of a UTF8Info entry in the constant pool of the template class.

private static class
ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoReplacement

Capture details of a single substitution to be made in the template class while generating the new class.

Field Summary

Modifier and TypeField and Description
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef
private int
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef
private byte[]
private Class<? extends ConverterPropertyEditorBase>

Constructor Summary

AccessConstructor and Description
public
ClassTemplateInfo()

Default constructor uses the ConverterPropertyEditorFor_XXXX class as the source template.

public
ClassTemplateInfo(Class<? extends ConverterPropertyEditorBase>
is a "template" class (but not in the java generics sense) which must extend ConverterPropertyEditorBase and override the ConverterPropertyEditorBase#getTargetClass method.
templateClass
)

Construct a template info instance based on the supplied class.

Method Summary

Modifier and TypeMethod and Description
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef

Returns:

A Utf8InfoRef instance refering to the matched constant pool entry, or null if no match was found.
findConstant
(String
the text that the UTF8Info must contain.
text
)

Find an instance of UTF8Info in the source class's constant pool where the text matches the given argument.

public byte[]

Returns:

the bytes for a new class with the given name and target class.
generateClassBytesFor
(String
the binary name of the new class.
newClassName
,
String
the binary name of the PropertyEditor's target class.
targetClassName
)

public String

Returns:

The full name to use for the generated PropertyEditor class.
generateClassNameFor
(Class<?>
The target class which the PropertyEditor will operate on.
targetClass
,
boolean
If true, the package name components will be '/' separated. Otherwise they will be '.' separated.
vmFormat
)

Generate a class name to use for the generated PropertyEditor class, based on the full name of the target class.

public String

Returns:

the target class name, or null if the given className was not a generated PropertyEditor name.
getTargetClassName
(String
name of the generated PropertyEditor class.
className
)

Extract the original target class name from the generated PropertyEditor class name.

private void
loadTemplateBytes()

Obtain the bytes that define the given class by looking for the ".class" resource and loading the binary data.

private boolean

Returns:

true if the bytes from targetBytes match the bytes from templateBytes.
matchAtIndex
(byte[]
byte array to compare.
targetBytes
,
int
the index into templateBytes at which to compare.
index
)

Check whether the targetBytes match the content of the templateBytes at the given index.

private byte[]

Returns:

the bytes for the new class definition.
replaceInTemplate
(ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoReplacement...
one or more Utf8InfoReplacments
replacements
)

Generate the bytes for a new class based on the templateBytes, but with all the replacements in replacements performed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classNameConstantback to summary
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef classNameConstant
classNameRefConstantback to summary
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef classNameRefConstant
constant_pool_countback to summary
private int constant_pool_count
targetClassConstantback to summary
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef targetClassConstant
templateBytesback to summary
private byte[] templateBytes
templateClassback to summary
private Class<? extends ConverterPropertyEditorBase> templateClass

Constructor Detail

ClassTemplateInfoback to summary
public ClassTemplateInfo()

Default constructor uses the ConverterPropertyEditorFor_XXXX class as the source template.

ClassTemplateInfoback to summary
public ClassTemplateInfo(Class<? extends ConverterPropertyEditorBase> templateClass)

Construct a template info instance based on the supplied class.

Parameters
templateClass:Class<? extends ConverterPropertyEditorBase>

is a "template" class (but not in the java generics sense) which must extend ConverterPropertyEditorBase and override the ConverterPropertyEditorBase#getTargetClass method.

Method Detail

findConstantback to summary
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef findConstant(String text)

Find an instance of UTF8Info in the source class's constant pool where the text matches the given argument.

Parameters
text:String

the text that the UTF8Info must contain.

Returns:ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef

A Utf8InfoRef instance refering to the matched constant pool entry, or null if no match was found.

generateClassBytesForback to summary
public byte[] generateClassBytesFor(String newClassName, String targetClassName)
Parameters
newClassName:String

the binary name of the new class.

targetClassName:String

the binary name of the PropertyEditor's target class.

Returns:byte[]

the bytes for a new class with the given name and target class.

generateClassNameForback to summary
public String generateClassNameFor(Class<?> targetClass, boolean vmFormat)

Generate a class name to use for the generated PropertyEditor class, based on the full name of the target class. This is done by replacing the "XXXX" in the template class name with a version of the target class name.

Parameters
targetClass:Class<?>

The target class which the PropertyEditor will operate on.

vmFormat:boolean

If true, the package name components will be '/' separated. Otherwise they will be '.' separated.

Returns:String

The full name to use for the generated PropertyEditor class.

getTargetClassNameback to summary
public String getTargetClassName(String className)

Extract the original target class name from the generated PropertyEditor class name. (This is the reverse of generateClassNameFor).

Parameters
className:String

name of the generated PropertyEditor class.

Returns:String

the target class name, or null if the given className was not a generated PropertyEditor name.

loadTemplateBytesback to summary
private void loadTemplateBytes() throws IOException

Obtain the bytes that define the given class by looking for the ".class" resource and loading the binary data.

Exceptions
IOException:
if an error occurs loading the binary data
matchAtIndexback to summary
private boolean matchAtIndex(byte[] targetBytes, int index)

Check whether the targetBytes match the content of the templateBytes at the given index.

Parameters
targetBytes:byte[]

byte array to compare.

index:int

the index into templateBytes at which to compare.

Returns:boolean

true if the bytes from targetBytes match the bytes from templateBytes.

replaceInTemplateback to summary
private byte[] replaceInTemplate(ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoReplacement... replacements)

Generate the bytes for a new class based on the templateBytes, but with all the replacements in replacements performed.

Parameters
replacements:ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoReplacement[]

one or more Utf8InfoReplacments

Returns:byte[]

the bytes for the new class definition.

com.sun.faces.application back to summary

private Class ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef

extends Object
Class Inheritance
  • java.lang.Object
  • com.sun.faces.application.ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef

Capture details of the location of a UTF8Info entry in the constant pool of the template class.

Field Summary

Modifier and TypeField and Description
pack-priv int
index

The position of the constant in the byte array that defines the template class.

pack-priv int
length

The number of bytes that the constant occupies in the byte array that defines the template class.

Constructor Summary

AccessConstructor and Description
public
Utf8InfoRef(int index, int length)

Field Detail

indexback to summary
pack-priv int index

The position of the constant in the byte array that defines the template class.

lengthback to summary
pack-priv int length

The number of bytes that the constant occupies in the byte array that defines the template class.

Constructor Detail

Utf8InfoRefback to summary
public Utf8InfoRef(int index, int length)
com.sun.faces.application back to summary

private Class ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoReplacement

extends Object
implements Comparable<ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoReplacement>
Class Inheritance
  • java.lang.Object
  • com.sun.faces.application.ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoReplacement
All Implemented Interfaces
java.lang.Comparable

Capture details of a single substitution to be made in the template class while generating the new class. Implements java.lang.Comparable so that the replacements can be ordered according to the order they appear in the source.

Field Summary

Modifier and TypeField and Description
pack-priv ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef
ref

The utf8 constant reference from the template source.

pack-priv byte[]
replacement

The bytes to replace the constant with (must also be a valid utf8 constant pool entry).

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoReplacement
the object to be compared.
rhs
)

Implements java.lang.Comparable.compareTo.

Order by the index position of the source UTF8Info reference.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

refback to summary
pack-priv ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef ref

The utf8 constant reference from the template source.

replacementback to summary
pack-priv byte[] replacement

The bytes to replace the constant with (must also be a valid utf8 constant pool entry).

Constructor Detail

Utf8InfoReplacementback to summary
public Utf8InfoReplacement(ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef ref, String replacement)

Method Detail

compareToback to summary
public int compareTo(ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoReplacement rhs)

Implements java.lang.Comparable.compareTo.

Order by the index position of the source UTF8Info reference.

Parameters
rhs:ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoReplacement

Doc from java.lang.Comparable.compareTo.

the object to be compared.

Returns:int

Doc from java.lang.Comparable.compareTo.

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
com.sun.faces.application back to summary

private Class ConverterPropertyEditorFactory.DisposableClassLoader

extends ClassLoader
Class Inheritance

A custom class loader for the definition of the generated classes. When the generated class is loaded, it will need to be able to resolve both the base class (ConverterPropertyEditorBase) which comes from myLoader and the target class which comes from targetLoader. This class loader defines only the generated class, and delegates to the above two loaders for the rest.

The ConverterPropertyEditorFactory will keep a cache of these class loaders (via weak references), one for each class loader that the target classes come from. That way the target class loader (which is likely to be a webapp specific loader) can be disposed of and replaced when the webapp is removed or reinstalled.

Field Summary

Modifier and TypeField and Description
private ClassLoader
private ClassLoader

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected Class<?>
findClass(String
The binary name of the class
className
)

Overrides java.lang.ClassLoader.findClass.

If super.loadClass is unable to locate a class, it will call this method to define it.
protected synchronized Class<?>
loadClass(String
The binary name of the class
name
,
boolean
If true then resolve the class
resolve
)

Overrides java.lang.ClassLoader.loadClass.

Override class loading to enable possible delegation to the two class loaders, rather than just to the parent.
Inherited from java.lang.ClassLoader:
clearAssertionStatusdefineClassdefineClassdefineClassdefineClassdefinePackagefindClassfindLibraryfindLoadedClassfindResourcefindResourcefindResourcesfindSystemClassgetClassLoadingLockgetDefinedPackagegetDefinedPackagesgetNamegetPackagegetPackagesgetParentgetPlatformClassLoadergetResourcegetResourceAsStreamgetResourcesgetSystemClassLoadergetSystemResourcegetSystemResourceAsStreamgetSystemResourcesgetUnnamedModuleisRegisteredAsParallelCapableloadClassregisterAsParallelCapableresolveClassresourcessetClassAssertionStatussetDefaultAssertionStatussetPackageAssertionStatussetSigners

Field Detail

myLoaderback to summary
private ClassLoader myLoader
targetLoaderback to summary
private ClassLoader targetLoader

Constructor Detail

DisposableClassLoaderback to summary
public DisposableClassLoader(ClassLoader targetLoader)

Method Detail

findClassback to summary
protected Class<?> findClass(String className) throws ClassNotFoundException

Overrides java.lang.ClassLoader.findClass.

If super.loadClass is unable to locate a class, it will call this method to define it. If the className is a generated PropertyEditor class name, then create the new class. Otherwise call super.findClass which will throw a ClassNotFoundException.

Parameters
className:String

Doc from java.lang.ClassLoader.findClass.

The binary name of the class

Returns:Class<?>

Doc from java.lang.ClassLoader.findClass.

The resulting Class object

Annotations
@Override
Exceptions
ClassNotFoundException:

Doc from java.lang.ClassLoader.findClass.

If the class could not be found

loadClassback to summary
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException

Overrides java.lang.ClassLoader.loadClass.

Override class loading to enable possible delegation to the two class loaders, rather than just to the parent.

Parameters
name:String

Doc from java.lang.ClassLoader.loadClass.

The binary name of the class

resolve:boolean

Doc from java.lang.ClassLoader.loadClass.

If true then resolve the class

Returns:Class<?>

Doc from java.lang.ClassLoader.loadClass.

The resulting Class object

Annotations
@Override
Exceptions
ClassNotFoundException:

Doc from java.lang.ClassLoader.loadClass.

If the class could not be found