Class DirectCopyClassTransformer
java.lang.Object
org.broadleafcommerce.common.extensibility.jpa.copy.AbstractClassTransformer
org.broadleafcommerce.common.extensibility.jpa.copy.DirectCopyClassTransformer
- All Implemented Interfaces:
jakarta.persistence.spi.ClassTransformer,BroadleafClassTransformer,org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
OptionalDirectCopyClassTransformer
public class DirectCopyClassTransformer
extends AbstractClassTransformer
implements BroadleafClassTransformer
This class transformer will copy fields, methods, and interface definitions from a source class to a target class,
based on the xformTemplates map. It will fail if it encounters any duplicate definitions.
- Author:
- Andre Azzolini (apazzolini), Jeff Fischer
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConditionalDirectCopyTransformersManagerprotected List<DirectCopyIgnorePattern>protected Stringprotected Booleanprotected Stringprotected BooleanFields inherited from class org.broadleafcommerce.common.extensibility.jpa.copy.AbstractClassTransformer
alreadyLoadedClasses, preLoadClassNamePatterns -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddXformTemplate(String classToTransform, String contributingClass) protected voidbuildClassCacheAnnotation(javassist.bytecode.ClassFile classFile, javassist.bytecode.ClassFile templateClassFile, javassist.bytecode.ConstPool constantPool) Allows replacing of Cache annotations at the class levelprotected voidbuildClassLevelAnnotations(javassist.bytecode.ClassFile classFile, javassist.bytecode.ClassFile templateClassFile, javassist.bytecode.ConstPool constantPool) protected voidbuildEntityListenerAnnotations(javassist.bytecode.ClassFile classFile, javassist.bytecode.ClassFile templateClassFile, javassist.bytecode.ConstPool constantPool) protected javassist.bytecode.annotation.AnnotationcloneIndexAnnotation(javassist.bytecode.annotation.Annotation annotation, javassist.bytecode.ConstPool constantPool) protected javassist.bytecode.annotation.AnnotationcloneUniqueAnnotation(javassist.bytecode.annotation.Annotation annotation, javassist.bytecode.ConstPool constantPool) protected DirectCopyClassTransformer.XFormParamscombineXFormParams(DirectCopyClassTransformer.XFormParams defaultParams, DirectCopyClassTransformer.XFormParams conditionalParams) Combines twoDirectCopyClassTransformer.XFormParamstogether with first passed in xformParama supercedes the second passed in parameter.voidcompileJPAProperties(Properties props, Object key) protected javassist.bytecode.annotation.AnnotationgetEntityListeners(javassist.bytecode.ConstPool constantPool, javassist.bytecode.annotation.Annotation existingEntityListeners, javassist.bytecode.annotation.Annotation templateEntityListeners) protected StringgetImplementationType(String className) This method will do its best to return an implementation type for a given classname.protected javassist.bytecode.annotation.AnnotationgetIndexes(javassist.bytecode.ConstPool constantPool, javassist.bytecode.annotation.Annotation existingTable, javassist.bytecode.annotation.Annotation templateTable, List<IndexAnnotationDto> indexes) protected javassist.bytecode.annotation.AnnotationgetNewCacheAnnotation(javassist.bytecode.ConstPool constantPool, javassist.bytecode.annotation.Annotation annotation) protected StringmethodDescription(javassist.CtMethod method) protected DirectCopyClassTransformer.XFormParamsreviewConditionalDirectCopyTransforms(String convertedClassName, List<DirectCopyIgnorePattern> matchedPatterns) RetrievesDirectCopyTransformTypesthat are conditionally/optionally included via properties file.protected DirectCopyClassTransformer.XFormParamsreviewDirectCopyTransformAnnotations(javassist.CtClass clazz, boolean mySkipOverlaps, boolean myRenameMethodOverlaps, List<DirectCopyIgnorePattern> matchedPatterns) RetrievesDirectCopyTransformTypesthat are placed as annotations on classes.reviewTemplateTokens(List<DirectCopyIgnorePattern> matchedPatterns, String val) voidsetIgnorePatterns(List<DirectCopyIgnorePattern> ignorePatterns) voidsetRenameMethodOverlaps(Boolean renameMethodOverlaps) voidsetRenameMethodPrefix(String renameMethodPrefix) voidsetSkipOverlaps(Boolean skipOverlaps) voidsetTemplateTokens(Map<String, String> templateTokens) voidsetXformTemplates(Map<String, String> xformTemplates) byte[]transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) protected voidtransformIndexAnnotations(javassist.bytecode.ClassFile classFile, javassist.bytecode.ClassFile templateClassFile, javassist.bytecode.ConstPool constantPool, List<IndexAnnotationDto> indexes) Methods inherited from class org.broadleafcommerce.common.extensibility.jpa.copy.AbstractClassTransformer
afterPropertiesSet, setPreLoadClassNamePatterns
-
Field Details
-
transformedMethods
-
transformedClasses
-
moduleName
-
xformTemplates
-
renameMethodOverlaps
-
renameMethodPrefix
-
skipOverlaps
-
templateTokens
-
ignorePatterns
-
conditionalDirectCopyTransformersManager
-
-
Constructor Details
-
DirectCopyClassTransformer
-
-
Method Details
-
compileJPAProperties
- Specified by:
compileJPAPropertiesin interfaceBroadleafClassTransformer- Throws:
Exception
-
transform
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException - Specified by:
transformin interfacejakarta.persistence.spi.ClassTransformer- Throws:
IllegalClassFormatException
-
combineXFormParams
protected DirectCopyClassTransformer.XFormParams combineXFormParams(DirectCopyClassTransformer.XFormParams defaultParams, DirectCopyClassTransformer.XFormParams conditionalParams) Combines twoDirectCopyClassTransformer.XFormParamstogether with first passed in xformParama supercedes the second passed in parameter.- Parameters:
defaultParams-conditionalParams-- Returns:
-
reviewDirectCopyTransformAnnotations
protected DirectCopyClassTransformer.XFormParams reviewDirectCopyTransformAnnotations(javassist.CtClass clazz, boolean mySkipOverlaps, boolean myRenameMethodOverlaps, List<DirectCopyIgnorePattern> matchedPatterns) RetrievesDirectCopyTransformTypesthat are placed as annotations on classes.- Parameters:
clazz-mySkipOverlaps-myRenameMethodOverlaps-matchedPatterns-- Returns:
-
reviewConditionalDirectCopyTransforms
protected DirectCopyClassTransformer.XFormParams reviewConditionalDirectCopyTransforms(String convertedClassName, List<DirectCopyIgnorePattern> matchedPatterns) RetrievesDirectCopyTransformTypesthat are conditionally/optionally included via properties file.- Parameters:
convertedClassName-matchedPatterns-- Returns:
- See Also:
-
reviewTemplateTokens
protected List<String> reviewTemplateTokens(List<DirectCopyIgnorePattern> matchedPatterns, String val) -
transformIndexAnnotations
protected void transformIndexAnnotations(javassist.bytecode.ClassFile classFile, javassist.bytecode.ClassFile templateClassFile, javassist.bytecode.ConstPool constantPool, List<IndexAnnotationDto> indexes) throws javassist.NotFoundException - Throws:
javassist.NotFoundException
-
getIndexes
protected javassist.bytecode.annotation.Annotation getIndexes(javassist.bytecode.ConstPool constantPool, javassist.bytecode.annotation.Annotation existingTable, javassist.bytecode.annotation.Annotation templateTable, List<IndexAnnotationDto> indexes) -
cloneIndexAnnotation
protected javassist.bytecode.annotation.Annotation cloneIndexAnnotation(javassist.bytecode.annotation.Annotation annotation, javassist.bytecode.ConstPool constantPool) -
cloneUniqueAnnotation
protected javassist.bytecode.annotation.Annotation cloneUniqueAnnotation(javassist.bytecode.annotation.Annotation annotation, javassist.bytecode.ConstPool constantPool) -
buildClassLevelAnnotations
protected void buildClassLevelAnnotations(javassist.bytecode.ClassFile classFile, javassist.bytecode.ClassFile templateClassFile, javassist.bytecode.ConstPool constantPool) throws javassist.NotFoundException - Throws:
javassist.NotFoundException
-
buildEntityListenerAnnotations
protected void buildEntityListenerAnnotations(javassist.bytecode.ClassFile classFile, javassist.bytecode.ClassFile templateClassFile, javassist.bytecode.ConstPool constantPool) throws javassist.NotFoundException - Throws:
javassist.NotFoundException
-
getEntityListeners
protected javassist.bytecode.annotation.Annotation getEntityListeners(javassist.bytecode.ConstPool constantPool, javassist.bytecode.annotation.Annotation existingEntityListeners, javassist.bytecode.annotation.Annotation templateEntityListeners) -
buildClassCacheAnnotation
protected void buildClassCacheAnnotation(javassist.bytecode.ClassFile classFile, javassist.bytecode.ClassFile templateClassFile, javassist.bytecode.ConstPool constantPool) throws javassist.NotFoundException Allows replacing of Cache annotations at the class level- Parameters:
classFile-templateClassFile-constantPool-- Throws:
javassist.NotFoundException
-
getNewCacheAnnotation
protected javassist.bytecode.annotation.Annotation getNewCacheAnnotation(javassist.bytecode.ConstPool constantPool, javassist.bytecode.annotation.Annotation annotation) -
getImplementationType
This method will do its best to return an implementation type for a given classname. This will allow weaving template classes to have initialized values.We provide default implementations for List, Map, and Set, and will attempt to utilize a default constructor for other classes.
If the className contains an '[', we will return null.
-
methodDescription
-
getXformTemplates
-
setXformTemplates
-
addXformTemplate
public DirectCopyClassTransformer addXformTemplate(String classToTransform, String contributingClass) - Parameters:
classToTransform- the class that will be transformed at runtimecontributingClass- the class that should be bytecode-merged into classToTransform- Returns:
-
getRenameMethodOverlaps
-
setRenameMethodOverlaps
-
getRenameMethodPrefix
-
setRenameMethodPrefix
-
getSkipOverlaps
-
setSkipOverlaps
-
getTemplateTokens
-
setTemplateTokens
-
getIgnorePatterns
-
setIgnorePatterns
-