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 classClass that describes the actual type parameters and generic types of superclass extracted using ClassGraph.static classClass that describes the actual type parameters and generic types of superclass extracted using reflection. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected Map<Class<?>, InterceptorCommonLibrary.DefaultConverterEntry<?, ?>> protected Map<Class<? extends Annotation>, InterceptorCommonLibrary.PolicyEntry<?, ?, ?>> protected Map<Class<?>, InterceptorCommonLibrary.DefaultConverterEntry<?, ?>> protected Map<Class<? extends Annotation>, InterceptorCommonLibrary.PolicyEntry<?, ?, ?>> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedDefaultPolicyLookup(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) Adds policy found by class scanning.protected <A extends Annotation,P extends Policy<A>, T>
InterceptorCommonLibrary.PolicyEntry<A, ?, ?> addDynamicPolicyInternalManual(InterceptorCommonLibrary.PolicyEntry<A, P, T> policyEntry) Adds policy set by client code and returns previous policy found by configuring annotation.protected booleandefaultPolicyFromClass(Class<?> candidateClass) Returns whether policy class means it can be a default for a field type, meaning it implements DefaultPolicy.protected booleandefaultPolicyFromClassInfo(io.github.classgraph.ClassInfo candidateClassInfo) Returns whether policy class info (found by class scanning) means it can be a default for a field type, meaning it implements DefaultPolicy.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 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) Returns info about all policies found by class scanning matching policy type.protected voidReturns unmodifiable map of all built-in default converters.protected voidCreates unmodifiable map of all built-in policies.protected voidCreates modifiable map of default converters from policies already found by class scanning.protected voidCreates modifiable map of policies found by class scanning.static <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 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.protected DefaultPolicyLookup.ConfigurationReturns configuration read from stuts.xml.<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 voidsetConfiguration(DefaultPolicyLookup.Configuration configuration) Sets configuration.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?>> -
builtInPolicyClasses
-
builtInDefaultConverterClasses
-
builtInDefaultListConverterClasses
-
-
Constructor Details
-
DefaultPolicyLookup
protected DefaultPolicyLookup() -
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) Adds policy found by class scanning. Blocks policies configured by a built-in or custom annotation. -
addDynamicPolicyInternalManual
protected <A extends Annotation,P extends Policy<A>, InterceptorCommonLibrary.PolicyEntry<A,T> ?, addDynamicPolicyInternalManual?> (InterceptorCommonLibrary.PolicyEntry<A, P, throws PolicyLookupRejectionExceptionT> policyEntry) Adds policy set by client code and returns previous policy found by configuring annotation. Can replace policies configured by a built-in annotation but not custom ones.- Throws:
PolicyLookupRejectionException
-
defaultPolicyFromClass
Returns whether policy class means it can be a default for a field type, meaning it implements DefaultPolicy. -
defaultPolicyFromClassInfo
protected boolean defaultPolicyFromClassInfo(io.github.classgraph.ClassInfo candidateClassInfo) Returns whether policy class info (found by class scanning) means it can be a default for a field type, meaning it implements DefaultPolicy. -
getScannedPoliciesByType
protected List<InterceptorCommonLibrary.PolicyEntry<?,?, getScannedPoliciesByType?>> (io.github.classgraph.ScanResult scanResult, Class<?> interfaceClass, Class<?> supportClass, InterceptorCommonLibrary.AnnotationUsage annotationUsage) Returns info about all policies found by class scanning matching policy type. -
initBuiltInDefaultConverterMap
protected void initBuiltInDefaultConverterMap()Returns unmodifiable map of all built-in default converters. -
initBuiltInPolicyMap
protected void initBuiltInPolicyMap()Creates unmodifiable map of all built-in policies. -
initDynamicDefaultConverterMap
protected void initDynamicDefaultConverterMap()Creates modifiable map of default converters from policies already found by class scanning. Ignores default converters that would replace a built-in one unless classpathScanningReplaceBuiltIn is true. -
initDynamicPolicyMap
protected void initDynamicPolicyMap()Creates modifiable map of policies found by class scanning. -
readConfiguration
Returns configuration read from stuts.xml. -
setConfiguration
Sets configuration. -
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. -
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
-
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 custom annotations (CustomAdjuster,CustomConversion,CustomValidationetc.).- Specified by:
putPolicyin interfacePolicyLookup- Throws:
PolicyLookupRejectionException
-
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
-