Class DefaultPolicyLookup
java.lang.Object
name.matthewgreet.strutscommons.util.DefaultPolicyLookup
- All Implemented Interfaces:
PolicyLookup
Standard implementation of PolicyLookup that creates a Singleton instance from an initial configuration
that returns the built-in form field policies and, if classpath scanning is enabled, automatically finds and adds
bespoke ones. Once created, policies can be added and removed but scanning cannot be re-run. Uses
ClassGraph for classpath scanning. If scanning
enabled, scanning the entire classpath can impose a noticeable, three second delay, so it's recommended to set the
known policy packages in configuration.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected Map<Class<?>, InterceptorCommonLibrary.DefaultCollectionConverterEntry<?, ?>> protected Map<Class<?>, InterceptorCommonLibrary.DefaultConverterEntry<?, ?>> protected Map<Class<? extends Annotation>, InterceptorCommonLibrary.PolicyEntry<?, ?, ?>> protected Map<Class<?>, InterceptorCommonLibrary.DefaultCollectionConverterEntry<?, ?>> protected Map<Class<?>, InterceptorCommonLibrary.DefaultConverterEntry<?, ?>> protected Map<Class<? extends Annotation>, InterceptorCommonLibrary.PolicyEntry<?, ?, ?>> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefaultPolicyLookup(DefaultPolicyLookup.Configuration configuration) -
Method Summary
Modifier and TypeMethodDescriptionprotected Class<?> actualTypeFromClassForInterface(Class<?> candidateClass, Class<?> interfaceClass, int genericTypeIndex) Returns actual type declared by class implementing a parameterised interface for a specific generic type.protected StringactualTypeFromClassInfoForInterface(io.github.classgraph.ClassInfo candidateClassInfo, Class<?> interfaceClass, int genericTypeIndex) Returns name of actual type declared by class implementing a parameterised interface for a specific generic type, according to ClassGraph into.protected <A extends Annotation,P extends Policy<A>, T>
voidaddDynamicPolicyInternalAutomatic(InterceptorCommonLibrary.PolicyEntry<A, P, T> policyEntry) protected <A extends Annotation,P extends Policy<A>, T>
InterceptorCommonLibrary.PolicyEntry<A, ?, ?> addDynamicPolicyInternalManual(InterceptorCommonLibrary.PolicyEntry<A, P, T> policyEntry) protected booleandefaultPolicyFromClass(Class<?> candidateClass) protected booleandefaultPolicyFromClassInfo(io.github.classgraph.ClassInfo candidateClassInfo) static voidRemoves Singleton instance.booleanReturns whether instance was created allowing classpath scanning, if run, to replace built-in default converters and collection converters with bespoke one.Returns all default collection converters in use and related metadata.<C extends CollectionConverter<?,T>, T>
InterceptorCommonLibrary.DefaultCollectionConverterEntry<T, C> getDefaultCollectionConverterEntry(Class<? extends T> itemClass) Returns default collection converter configuration for the collection item's type, or null if none set.Returns all default converters in use and related metadata.<C extends Converter<?,T>, T>
InterceptorCommonLibrary.DefaultConverterEntry<T, C> getDefaultConverterEntry(Class<? extends T> fieldClass) Returns default converter configuration for the form field type, or null if none set.booleanReturns whether instance was created with classpath scanning.static DefaultPolicyLookupReturns Singleton instance with default initialisation options, or existing one if already initialised.static DefaultPolicyLookupgetInstance(DefaultPolicyLookup.Configuration configuration) Returns Singleton instance with initialisation options.Returns all policy classes and related metadata.<A extends Annotation,P extends Policy<A>, T>
InterceptorCommonLibrary.PolicyEntry<A, P, T> getPolicyEntry(Class<? extends A> annotationClass) Returns policy implementation configuration for a form field annotation, or null if not set.protected List<InterceptorCommonLibrary.PolicyEntry<?, ?, ?>> getScannedPoliciesByType(io.github.classgraph.ScanResult scanResult, Class<?> interfaceClass, Class<?> supportClass, InterceptorCommonLibrary.AnnotationUsage annotationUsage) protected voidReturns unmodifiable map of all built-in default converters.protected voidReturns unmodifiable map of all built-in default converters.protected voidReturns unmodifiable map of all built-in adjusters, converters, and validators.protected voidprotected voidprotected voidstatic <A extends Annotation,P extends Policy<A>, T>
InterceptorCommonLibrary.PolicyEntry<?, ?, ?> makePolicyEntryFromClassNames(String annotationClassName, String policyClassName, String recipientTypeName, InterceptorCommonLibrary.AnnotationUsage annotationUsage, boolean builtIn, boolean defaultPolicy) <C extends CollectionConverter<?,T>, T>
InterceptorCommonLibrary.DefaultCollectionConverterEntry<T, ?> putDefaultCollectionConverter(Class<C> collectionConverterClass) Sets form field collection converter as the default collection converter for its recipient item type, replacing any existing one.<C extends Converter<?,T>, T>
InterceptorCommonLibrary.DefaultConverterEntry<T, ?> putDefaultConverter(Class<C> converterClass) Sets form field converter as the default converter for its recipient type, replacing any existing converter.<A extends Annotation,P extends Policy<A>, T>
InterceptorCommonLibrary.PolicyEntry<A, ?, ?> Adds a form field policy not found by classpath scanning, so it can be found from the annotation that configures it, replacing any existing using the same annotation.<C extends CollectionConverter<?,T>, T>
InterceptorCommonLibrary.DefaultCollectionConverterEntry<T, C> removeDefaultCollectionConverter(Class<? extends T> itemClass) Removes default collection converter for an item type for collection form fields and returns it, or null if not found.<C extends Converter<?,T>, T>
InterceptorCommonLibrary.DefaultConverterEntry<T, C> removeDefaultConverter(Class<? extends T> fieldClass) Removes default converter for a form field type and returns it, or null if not found.<A extends Annotation,P extends Policy<A>, T>
InterceptorCommonLibrary.PolicyEntry<A, P, T> removePolicy(Class<? extends A> annotationClass) Removes form field policy found from the class of annotation that configures it and returns policy config, or null if not found.protected Class<?> translateDefaultConverterRecipientClass(Class<?> recipientClass) Translates form field class or item type of collection form field into a class used by default converter and collection converter lookups.
-
Field Details
-
BASE_POLICY_PACKAGES
- See Also:
-
builtInPolicyMap
protected Map<Class<? extends Annotation>,InterceptorCommonLibrary.PolicyEntry<?, builtInPolicyMap?, ?>> -
dynamicPolicyMap
protected Map<Class<? extends Annotation>,InterceptorCommonLibrary.PolicyEntry<?, dynamicPolicyMap?, ?>> -
builtInDefaultConverterMap
protected Map<Class<?>,InterceptorCommonLibrary.DefaultConverterEntry<?, builtInDefaultConverterMap?>> -
dynamicDefaultConverterMap
protected Map<Class<?>,InterceptorCommonLibrary.DefaultConverterEntry<?, dynamicDefaultConverterMap?>> -
builtInDefaultCollectionConverterMap
protected Map<Class<?>,InterceptorCommonLibrary.DefaultCollectionConverterEntry<?, builtInDefaultCollectionConverterMap?>> -
dynamicDefaultCollectionConverterMap
protected Map<Class<?>,InterceptorCommonLibrary.DefaultCollectionConverterEntry<?, dynamicDefaultCollectionConverterMap?>> -
builtInPolicyClasses
-
builtInDefaultConverterClasses
-
builtInDefaultCollectionConverterClasses
-
-
Constructor Details
-
DefaultPolicyLookup
-
-
Method Details
-
deleteInstance
public static void deleteInstance()Removes Singleton instance. This only exists for testing. -
getInstance
Returns Singleton instance with default initialisation options, or existing one if already initialised. -
getInstance
Returns Singleton instance with initialisation options. Initialisation options have no effect if the instance is already initialised. -
makePolicyEntryFromClassNames
public static <A extends Annotation,P extends Policy<A>, InterceptorCommonLibrary.PolicyEntry<?,T> ?, makePolicyEntryFromClassNames?> (String annotationClassName, String policyClassName, String recipientTypeName, InterceptorCommonLibrary.AnnotationUsage annotationUsage, boolean builtIn, boolean defaultPolicy) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
actualTypeFromClassForInterface
protected Class<?> actualTypeFromClassForInterface(Class<?> candidateClass, Class<?> interfaceClass, int genericTypeIndex) Returns actual type declared by class implementing a parameterised interface for a specific generic type. genericTypeIndex starts at 0. -
actualTypeFromClassInfoForInterface
protected String actualTypeFromClassInfoForInterface(io.github.classgraph.ClassInfo candidateClassInfo, Class<?> interfaceClass, int genericTypeIndex) Returns name of actual type declared by class implementing a parameterised interface for a specific generic type, according to ClassGraph into. genericTypeIndex starts at 0. -
addDynamicPolicyInternalAutomatic
protected <A extends Annotation,P extends Policy<A>, void addDynamicPolicyInternalAutomaticT> (InterceptorCommonLibrary.PolicyEntry<A, P, T> policyEntry) -
addDynamicPolicyInternalManual
protected <A extends Annotation,P extends Policy<A>, InterceptorCommonLibrary.PolicyEntry<A,T> ?, addDynamicPolicyInternalManual?> (InterceptorCommonLibrary.PolicyEntry<A, P, throws PolicyLookupRejectionExceptionT> policyEntry) - Throws:
PolicyLookupRejectionException
-
defaultPolicyFromClass
-
defaultPolicyFromClassInfo
protected boolean defaultPolicyFromClassInfo(io.github.classgraph.ClassInfo candidateClassInfo) -
getScannedPoliciesByType
protected List<InterceptorCommonLibrary.PolicyEntry<?,?, getScannedPoliciesByType?>> (io.github.classgraph.ScanResult scanResult, Class<?> interfaceClass, Class<?> supportClass, InterceptorCommonLibrary.AnnotationUsage annotationUsage) -
initBuiltInDefaultCollectionConverterMap
protected void initBuiltInDefaultCollectionConverterMap()Returns unmodifiable map of all built-in default converters. -
initBuiltInDefaultConverterMap
protected void initBuiltInDefaultConverterMap()Returns unmodifiable map of all built-in default converters. -
initBuiltInPolicyMap
protected void initBuiltInPolicyMap()Returns unmodifiable map of all built-in adjusters, converters, and validators. -
initDynamicDefaultCollectionConverterMap
protected void initDynamicDefaultCollectionConverterMap() -
initDynamicDefaultConverterMap
protected void initDynamicDefaultConverterMap() -
initDynamicPolicyMap
protected void initDynamicPolicyMap() -
translateDefaultConverterRecipientClass
Translates form field class or item type of collection form field into a class used by default converter and collection converter lookups. -
getAcceptClasses
-
getAcceptPackages
-
getClasspathScanningReplaceBuiltIn
public boolean getClasspathScanningReplaceBuiltIn()Returns whether instance was created allowing classpath scanning, if run, to replace built-in default converters and collection converters with bespoke one. -
getDefaultCollectionConverterEntries
public Collection<InterceptorCommonLibrary.DefaultCollectionConverterEntry<?,?>> getDefaultCollectionConverterEntries()Description copied from interface:PolicyLookupReturns all default collection converters in use and related metadata.- Specified by:
getDefaultCollectionConverterEntriesin interfacePolicyLookup
-
getDefaultCollectionConverterEntry
public <C extends CollectionConverter<?,T>, InterceptorCommonLibrary.DefaultCollectionConverterEntry<T,T> C> getDefaultCollectionConverterEntry(Class<? extends T> itemClass) Returns default collection converter configuration for the collection item's type, or null if none set.- Specified by:
getDefaultCollectionConverterEntryin interfacePolicyLookup
-
getDefaultConverterEntries
Description copied from interface:PolicyLookupReturns all default converters in use and related metadata.- Specified by:
getDefaultConverterEntriesin interfacePolicyLookup
-
getDefaultConverterEntry
public <C extends Converter<?,T>, InterceptorCommonLibrary.DefaultConverterEntry<T,T> C> getDefaultConverterEntry(Class<? extends T> fieldClass) Returns default converter configuration for the form field type, or null if none set.- Specified by:
getDefaultConverterEntryin interfacePolicyLookup
-
getEnableClasspathScanning
public boolean getEnableClasspathScanning()Returns whether instance was created with classpath scanning. -
getPolicyEntries
Description copied from interface:PolicyLookupReturns all policy classes and related metadata.- Specified by:
getPolicyEntriesin interfacePolicyLookup
-
getPolicyEntry
public <A extends Annotation,P extends Policy<A>, InterceptorCommonLibrary.PolicyEntry<A,T> P, getPolicyEntryT> (Class<? extends A> annotationClass) Returns policy implementation configuration for a form field annotation, or null if not set.- Specified by:
getPolicyEntryin interfacePolicyLookup
-
getRejectClasses
-
getRejectPackages
-
putDefaultCollectionConverter
public <C extends CollectionConverter<?,T>, InterceptorCommonLibrary.DefaultCollectionConverterEntry<T,T> ?> putDefaultCollectionConverter(Class<C> collectionConverterClass) throws PolicyLookupRejectionException Sets form field collection converter as the default collection converter for its recipient item type, replacing any existing one. Class must directly implementConverteror inheritAbstractConverterSupport. Cannot replace a built-in collection converter.- Specified by:
putDefaultCollectionConverterin interfacePolicyLookup- Throws:
PolicyLookupRejectionException
-
putDefaultConverter
public <C extends Converter<?,T>, InterceptorCommonLibrary.DefaultConverterEntry<T,T> ?> putDefaultConverter(Class<C> converterClass) throws PolicyLookupRejectionException Sets form field converter as the default converter for its recipient type, replacing any existing converter. Class must directly implementConverteror inheritAbstractConverterSupport. Ignores any attempt to replace a built-in or custom converter.- Specified by:
putDefaultConverterin interfacePolicyLookup- Throws:
PolicyLookupRejectionException
-
putPolicy
public <A extends Annotation,P extends Policy<A>, InterceptorCommonLibrary.PolicyEntry<A,T> ?, putPolicy?> (Class<P> policyClass) throws PolicyLookupRejectionException Adds a form field policy not found by classpath scanning, so it can be found from the annotation that configures it, replacing any existing using the same annotation. Ignores polices referring to built-in annotations or custom annotations (CustomAdjuster,CustomConversion,CustomValidationetc.).- Specified by:
putPolicyin interfacePolicyLookup- Throws:
PolicyLookupRejectionException
-
removeDefaultCollectionConverter
public <C extends CollectionConverter<?,T>, InterceptorCommonLibrary.DefaultCollectionConverterEntry<T,T> C> removeDefaultCollectionConverter(Class<? extends T> itemClass) throws IllegalArgumentException Removes default collection converter for an item type for collection form fields and returns it, or null if not found. Cannot remove a built-in collection converter.- Specified by:
removeDefaultCollectionConverterin interfacePolicyLookup- Throws:
IllegalArgumentException
-
removeDefaultConverter
public <C extends Converter<?,T>, InterceptorCommonLibrary.DefaultConverterEntry<T,T> C> removeDefaultConverter(Class<? extends T> fieldClass) throws IllegalArgumentException Removes default converter for a form field type and returns it, or null if not found. Cannot remove a built-in converter.- Specified by:
removeDefaultConverterin interfacePolicyLookup- Throws:
IllegalArgumentException
-
removePolicy
public <A extends Annotation,P extends Policy<A>, InterceptorCommonLibrary.PolicyEntry<A,T> P, removePolicyT> (Class<? extends A> annotationClass) throws IllegalArgumentException Removes form field policy found from the class of annotation that configures it and returns policy config, or null if not found. Cannot remove for built-in annotations.- Specified by:
removePolicyin interfacePolicyLookup- Throws:
IllegalArgumentException
-