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.
| Modifier and Type | Class 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. |
| Modifier and Type | Field and Description |
|---|---|
| private Map | |
| private static ConverterPropertyEditorFactory | |
| private static final Logger | |
| private static final Pattern | |
| private static final Map | |
| private static final Pattern | |
| private ConverterPropertyEditorFactory. | |
| private static final Pattern |
| Access | Constructor and Description |
|---|---|
| public | ConverterPropertyEditorFactory()
Create a |
| public | ConverterPropertyEditorFactory(Class<? extends ConverterPropertyEditorBase>
the template templateClass)Create a |
| Modifier and Type | Method and Description |
|---|---|
| public Class | Returns: the dynamically generated PropertyEditor class.the class of object that the returned property editor class will be
editing. targetClass)Return a PropertyEditor class appropriate for editing the given |
| public static synchronized ConverterPropertyEditorFactory | Returns: the single default instance of this class (created with the default template class).
|
| private ConverterPropertyEditorFactory. | |
| private static byte[] | Returns: the bytes for the UTF8Info constant pool entry, including the tag, length, and utf8 content.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).the class to find the name of. c)
|
| classLoaderCache | back to summary |
|---|---|
| private Map<ClassLoader, WeakReference<ConverterPropertyEditorFactory. | |
| defaultInstance | back to summary |
|---|---|
| private static ConverterPropertyEditorFactory defaultInstance | |
| LOGGER | back to summary |
|---|---|
| private static final Logger LOGGER | |
| MultipleUnderscorePattern | back to summary |
|---|---|
| private static final Pattern MultipleUnderscorePattern | |
| PRIM_MAP | back to summary |
|---|---|
| private static final Map<Character, String> PRIM_MAP | |
| SingleUnderscorePattern | back to summary |
|---|---|
| private static final Pattern SingleUnderscorePattern | |
| templateInfo | back to summary |
|---|---|
| private ConverterPropertyEditorFactory. | |
| UNDERSCORE_PATTERN | back to summary |
|---|---|
| private static final Pattern UNDERSCORE_PATTERN | |
| ConverterPropertyEditorFactory | back to summary |
|---|---|
| public ConverterPropertyEditorFactory() Create a | |
| ConverterPropertyEditorFactory | back to summary |
|---|---|
| public ConverterPropertyEditorFactory(Class<? extends ConverterPropertyEditorBase> templateClass) Create a
| |
| definePropertyEditorClassFor | back to summary |
|---|---|
| public Class Return a PropertyEditor class appropriate for editing the given
| |
| getDefaultInstance | back to summary |
|---|---|
public static synchronized ConverterPropertyEditorFactory getDefaultInstance()
| |
| getTemplateInfo | back to summary |
|---|---|
| private ConverterPropertyEditorFactory. | |
| getUtf8InfoBytes | back to summary |
|---|---|
| private static byte[] getUtf8InfoBytes(String text) Create a UTF8Info constant pool structure for the given text.
| |
| getVMClassName | back to summary |
|---|---|
| private static String getVMClassName(Class<?> c) | |
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:
| Modifier and Type | Class 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. |
| Modifier and Type | Field and Description |
|---|---|
| private ConverterPropertyEditorFactory. | |
| private ConverterPropertyEditorFactory. | |
| private int | |
| private ConverterPropertyEditorFactory. | |
| private byte[] | |
| private Class |
| Access | Constructor and Description |
|---|---|
| public | ClassTemplateInfo()
Default constructor uses the |
| public | ClassTemplateInfo(Class<? extends ConverterPropertyEditorBase>
is a "template" class (but not in the java generics sense) which
must extend templateClass)ConverterPropertyEditorBase and override the
ConverterPropertyEditorBase#getTargetClass method.Construct a template info instance based on the supplied class. |
| Modifier and Type | Method and Description |
|---|---|
| private ConverterPropertyEditorFactory. | Returns: AUtf8InfoRef instance refering to the matched constant pool entry, or
null if no match was found.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.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.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 givenclassName was not a
generated PropertyEditor name.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 fromtargetBytes match the bytes from
templateBytes.byte array to compare. targetBytes, int the index into index)templateBytes at which to compare.Check whether the |
| private byte[] | Returns: the bytes for the new class definition.one or more Utf8InfoReplacments replacementsGenerate the bytes for a new class based on the |
| classNameConstant | back to summary |
|---|---|
| private ConverterPropertyEditorFactory. | |
| classNameRefConstant | back to summary |
|---|---|
| private ConverterPropertyEditorFactory. | |
| constant_pool_count | back to summary |
|---|---|
| private int constant_pool_count | |
| targetClassConstant | back to summary |
|---|---|
| private ConverterPropertyEditorFactory. | |
| templateBytes | back to summary |
|---|---|
| private byte[] templateBytes | |
| templateClass | back to summary |
|---|---|
| private Class<? extends ConverterPropertyEditorBase> templateClass | |
| ClassTemplateInfo | back to summary |
|---|---|
| public ClassTemplateInfo() Default constructor uses the | |
| ClassTemplateInfo | back to summary |
|---|---|
| public ClassTemplateInfo(Class<? extends ConverterPropertyEditorBase> templateClass) Construct a template info instance based on the supplied class.
| |
| findConstant | back to summary |
|---|---|
| private ConverterPropertyEditorFactory. Find an instance of UTF8Info in the source class's constant pool where the text matches the given argument.
| |
| generateClassBytesFor | back to summary |
|---|---|
| public byte[] generateClassBytesFor(String newClassName, String targetClassName) | |
| generateClassNameFor | back 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. | |
| getTargetClassName | back to summary |
|---|---|
| public String getTargetClassName(String className) Extract the original target class name from the generated PropertyEditor class name.
(This is the reverse of | |
| loadTemplateBytes | back 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.
| |
| matchAtIndex | back to summary |
|---|---|
| private boolean matchAtIndex(byte[] targetBytes, int index) Check whether the
| |
| replaceInTemplate | back to summary |
|---|---|
| private byte[] replaceInTemplate(ConverterPropertyEditorFactory. Generate the bytes for a new class based on the
| |
| Modifier and Type | Field 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. |
| Access | Constructor and Description |
|---|---|
| public |
| index | back to summary |
|---|---|
| pack-priv int index The position of the constant in the byte array that defines the template class. | |
| length | back to summary |
|---|---|
| pack-priv int length The number of bytes that the constant occupies in the byte array that defines the template class. | |
| Utf8InfoRef | back to summary |
|---|---|
| public Utf8InfoRef(int index, int length) | |
java.lang.Comparable so that the
replacements can be ordered according to the order they appear in the source.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv ConverterPropertyEditorFactory. | 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). |
| Access | Constructor and Description |
|---|---|
| public | Utf8InfoReplacement(ConverterPropertyEditorFactory.
|
| Modifier and Type | Method and Description |
|---|---|
| public int | compareTo(ConverterPropertyEditorFactory.
the object to be compared. rhsImplements java. |
| ref | back to summary |
|---|---|
| pack-priv ConverterPropertyEditorFactory. The utf8 constant reference from the template source. | |
| replacement | back to summary |
|---|---|
| pack-priv byte[] replacement The bytes to replace the constant with (must also be a valid utf8 constant pool entry). | |
| Utf8InfoReplacement | back to summary |
|---|---|
| public Utf8InfoReplacement(ConverterPropertyEditorFactory. | |
| compareTo | back to summary |
|---|---|
| public int compareTo(ConverterPropertyEditorFactory. Implements java. Order by the index position of the source UTF8Info reference.
| |
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.
| Modifier and Type | Field and Description |
|---|---|
| private ClassLoader | |
| private ClassLoader |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected Class | findClass(String
The binary name of the class className)Overrides java. 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 resolve)true then resolve the classOverrides java. |
| myLoader | back to summary |
|---|---|
| private ClassLoader myLoader | |
| targetLoader | back to summary |
|---|---|
| private ClassLoader targetLoader | |
| DisposableClassLoader | back to summary |
|---|---|
| public DisposableClassLoader(ClassLoader targetLoader) | |
| findClass | back to summary |
|---|---|
| protected Class Overrides java. If
| |
| loadClass | back to summary |
|---|---|
| protected synchronized Class Overrides java. Override class loading to enable possible delegation to the two class loaders, rather than just to the parent.
| |