Class SimpleClassNameDiscriminatorStrategy
- java.lang.Object
-
- org.soulwing.prospecto.api.discriminator.SimpleClassNameDiscriminatorStrategy
-
- All Implemented Interfaces:
DiscriminatorStrategy
public class SimpleClassNameDiscriminatorStrategy extends Object implements DiscriminatorStrategy
ADiscriminatorStrategy
that utilizes the simple (unqualified) class name.This strategy provides options for stripping a prefix and/or suffix from the simple class name and for de-capitalizing the (stripped) name (according to the unusual rules of
Introspector.decapitalize(String)
.In oder for this strategy to successfully recover the
Class
object for a subtype from the simple names produced bytoDiscriminator(Class, Class)
, the subtype classes must be in the same package as the base type and loaded by the same class loader as the base type.- Author:
- Carl Harris
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SimpleClassNameDiscriminatorStrategy.Builder
A builder that produces aSimpleClassNameDiscriminatorStrategy
instance.
-
Constructor Summary
Constructors Constructor Description SimpleClassNameDiscriminatorStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getName()
Gets thename
property.String
getPrefix()
Gets theprefix
property.String
getSuffix()
Gets thesuffix
property.boolean
isDecapitalize()
Gets thedecapitalize
property.void
setDecapitalize(boolean decapitalize)
Sets thedecapitalize
property.void
setName(String name)
Sets thename
property.void
setPrefix(String prefix)
Sets theprefix
property.void
setSuffix(String suffix)
Sets thesuffix
property.Discriminator
toDiscriminator(Class<?> base, Class<?> subtype)
Produces a discriminator for the given subtype of a base type.<T> Class<T>
toSubtype(Class<T> base, Discriminator discriminator)
Determines the subtype that corresponds to a given discriminator.
-
-
-
Method Detail
-
toDiscriminator
public Discriminator toDiscriminator(Class<?> base, Class<?> subtype)
Description copied from interface:DiscriminatorStrategy
Produces a discriminator for the given subtype of a base type.- Specified by:
toDiscriminator
in interfaceDiscriminatorStrategy
- Parameters:
base
- the base typesubtype
- a subtype of base- Returns:
- discriminator
-
toSubtype
public <T> Class<T> toSubtype(Class<T> base, Discriminator discriminator) throws ClassNotFoundException
Description copied from interface:DiscriminatorStrategy
Determines the subtype that corresponds to a given discriminator.- Specified by:
toSubtype
in interfaceDiscriminatorStrategy
- Type Parameters:
T
- base type- Parameters:
base
- base typediscriminator
- discriminator- Returns:
- type that corresponds to
discriminator
- Throws:
ClassNotFoundException
-
getName
public String getName()
Gets thename
property.- Returns:
- property value
-
setName
public void setName(String name)
Sets thename
property.- Parameters:
name
- the property value to set
-
getPrefix
public String getPrefix()
Gets theprefix
property.- Returns:
- property value
-
setPrefix
public void setPrefix(String prefix)
Sets theprefix
property.- Parameters:
prefix
- the property value to set
-
getSuffix
public String getSuffix()
Gets thesuffix
property.- Returns:
- property value
-
setSuffix
public void setSuffix(String suffix)
Sets thesuffix
property.- Parameters:
suffix
- the property value to set
-
isDecapitalize
public boolean isDecapitalize()
Gets thedecapitalize
property.- Returns:
- property value
-
setDecapitalize
public void setDecapitalize(boolean decapitalize)
Sets thedecapitalize
property.- Parameters:
decapitalize
- the property value to set
-
-