private static class ConverterPropertyEditorFactory.ClassTemplateInfo
extends java.lang.Object
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.ClassTemplateInfo.Utf8InfoRef |
classNameConstant |
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef |
classNameRefConstant |
private int |
constant_pool_count |
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef |
targetClassConstant |
private byte[] |
templateBytes |
private java.lang.Class<? extends ConverterPropertyEditorBase> |
templateClass |
Constructor and Description |
---|
ClassTemplateInfo()
Default constructor uses the
ConverterPropertyEditorFor_XXXX
class as the source template. |
ClassTemplateInfo(java.lang.Class<? extends ConverterPropertyEditorBase> templateClass)
Construct a template info instance based on the supplied class.
|
Modifier and Type | Method and Description |
---|---|
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef |
findConstant(java.lang.String text)
Find an instance of UTF8Info in the source class's constant pool
where the text matches the given argument.
|
byte[] |
generateClassBytesFor(java.lang.String newClassName,
java.lang.String targetClassName) |
java.lang.String |
generateClassNameFor(java.lang.Class<?> targetClass,
boolean vmFormat)
Generate a class name to use for the generated PropertyEditor class,
based on the full name of the target class.
|
java.lang.String |
getTargetClassName(java.lang.String 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 |
matchAtIndex(byte[] targetBytes,
int index)
Check whether the
targetBytes match the content of the
templateBytes at the given index . |
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. |
private java.lang.Class<? extends ConverterPropertyEditorBase> templateClass
private byte[] templateBytes
private int constant_pool_count
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef classNameConstant
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef classNameRefConstant
private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef targetClassConstant
public ClassTemplateInfo()
ConverterPropertyEditorFor_XXXX
class as the source template.public ClassTemplateInfo(java.lang.Class<? extends ConverterPropertyEditorBase> templateClass)
templateClass
- is a "template" class (but not in the java generics sense)
which must extend ConverterPropertyEditorBase
and
override the
ConverterPropertyEditorBase.getTargetClass()
method.private boolean matchAtIndex(byte[] targetBytes, int index)
targetBytes
match the content of the
templateBytes
at the given index
.targetBytes
- byte array to compare.index
- the index into templateBytes
at which to
compare.targetBytes
match the
bytes from templateBytes
.private ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef findConstant(java.lang.String text)
text
- the text that the UTF8Info must contain.ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoRef
instance refering to the matched
constant pool entry, or null
if no match was
found.private void loadTemplateBytes() throws java.io.IOException
java.io.IOException
- if an error occurs loading the binary datapublic java.lang.String generateClassNameFor(java.lang.Class<?> targetClass, boolean vmFormat)
targetClass
- The target class which the PropertyEditor will operate on.vmFormat
- If true, the package name components will be '/'
separated. Otherwise they will be '.' separated.public java.lang.String getTargetClassName(java.lang.String className)
generateClassNameFor(java.lang.Class<?>, boolean)
).className
- name of the generated PropertyEditor class.className
was not a generated PropertyEditor
name.private byte[] replaceInTemplate(ConverterPropertyEditorFactory.ClassTemplateInfo.Utf8InfoReplacement... replacements)
templateBytes
, but with all the replacements in
replacements
performed.replacements
- one or more Utf8InfoReplacmentspublic byte[] generateClassBytesFor(java.lang.String newClassName, java.lang.String targetClassName)
newClassName
- the binary name of the new class.targetClassName
- the binary name of the PropertyEditor's target class.Copyright © 2002-2013 Oracle America, Inc. All Rights Reserved.