This mapping strategy knows of the existence of binding annotations, but
assumes through getBindingAnnotations() they are not in use.
Anyone is welcome to use it as a base class for their own mapping strategies.
| Modifier and Type | Class and Description |
|---|---|
| protected static class | AbstractMappingStrategy.
Encapsulates a bean type and all of the member variables that need to be recursed into. |
| Modifier and Type | Field and Description |
|---|---|
| protected Locale | errorLocale
Locale for error messages. |
| private static final Set | FORBIDDEN_CLASSES_FOR_RECURSION
Set of classes where recursion is not allowed. |
| protected final HeaderIndex | headerIndex
Maintains a bi-directional mapping between column position(s) and header name. |
| private MultiValuedMap | ignoredFields
Storage for all manually excluded class/field pairs. |
| protected String | profile
The profile for configuring bean fields. |
| protected AbstractMappingStrategy. | recursiveTypeTree
A tree of the types encountered during recursion through the root bean type. |
| protected Class | type
This is the class of the bean to be manipulated. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | assembleCompleteFieldList(AbstractMappingStrategy.
The root of the type tree at this level of recursion root,A collection of all fields thus far included
in the new representation. This collection will
be added to and is the result of this method. encounteredFields)Creates a non-tree (fairly flat) representation of all of the fields bound from all types. |
| protected abstract K | Returns: The index to be used for this mapping strategy forBeanField#indexAndSplitMultivaluedField(java.The current column position while transmuting a bean to CSV
output index)For |
| protected Map | Returns: A new instance of the class being mapped.Implementation will return a bean of the type of object being mapped. |
| private static void | createSubordinateBeans(AbstractMappingStrategy.
|
| protected CsvConverter | Returns: The appropriate converter for the necessary conversionThe field of the bean type in question field, Class<?> The type to be generated by the converter (on reading) elementType, String The locale for conversion on reading. May be null or an
empty string if a locale is not in use. locale, String The locale for conversion on writing. May be null or
an empty string if a locale is not in use. writeLocale, Class<? extends AbstractCsvConverter> An optional custom converter customConverter)Given the information provided, determines the appropriate built-in
converter to be passed in to the |
| protected List | Returns: A list of fields that exist for opencsvThe class from which type, Field[] fields come. This must be the
class as opencsv would seek to instantiate it, which in the
case of inheritance is not necessarily the declaring class.The fields to be filtered fields)Filters all fields that opencsv has been instructed to ignore and returns a list of the rest. |
| protected abstract BeanField | Returns: BeanField containing the field for a given column position, or null if one could not be foundThe column to find the field for col)Gets the field for a given column position. |
| public abstract String | Returns: The name of the headerThe column number for which the header is sought col)Gets the name (or position number) of the header for the given column number. |
| public String[] | generateHeader(T bean)
Implements com. This method generates a header that can be used for writing beans of the type provided back to a file. |
| protected Set | Returns: Annotations of the sortCsvBindByName or
CsvBindByPosition that are relevant for binding input fields to
bean members in this mapping strategyReturns a set of the annotations that are used for binding in this mapping strategy. |
| protected String | Returns: The column name or null if the position is larger than the header array or there are no headers defined.Column position. col)Get the column name for a given column position. |
| protected abstract FieldMap | Returns: TheFieldMap used by this strategyReturns the |
| public Class | Returns: Class of the object that thisMappingStrategy will create.Get the class type that the strategy is mapping. |
| public void | ignoreFields(MultiValuedMap<Class<?>, Field> fields)
Overrides default com. When processing a bean for reading or writing, ignore the given fields from the given classes completely, including all annotations and requirements. |
| protected Map | Returns: The index from type to instanceThe root bean to be indexed bean)Creates an index of necessary types according to the mapping strategy and existing instances of (subordinate) beans. |
| private static void | indexSubordinateBeans(AbstractMappingStrategy.
|
| protected abstract void | initializeFieldMap()
Creates an empty binding-type-specific field map that can be filled in later steps. |
| protected BeanField | Returns: The custom converterThe class for a custom converter converter)Attempts to instantiate the class of the custom converter specified. |
| protected boolean | isForbiddenClassForRecursion(Class<?>
Class to be checked type)Returns: Whether the type may be recursed into ( |
| protected void | loadAnnotatedFieldMap(ListValuedMap<Class<?>, Field>
A list of fields annotated with a binding annotation
in the bean to be processed fields)Creates a map of annotated fields in the bean to be processed. |
| protected void | |
| protected AbstractMappingStrategy. | Returns: A representation of this type and all of the types beneath it in a treeThe type that is meant to be added to the tree newType, Set<Class<?>> A set of types already encountered during
recursion, as types may not be recursed into
more than once. encounteredTypes)Creates a tree of beans embedded in each other. |
| protected abstract void | loadUnadornedFieldMap(ListValuedMap<Class<?>, Field>
A list of all non-synthetic fields in the bean to be
processed fields)Creates a map of fields in the bean to be processed that have no annotations. |
| protected Map | Returns: A multi-valued map (class to multiple fields in that class) in which all annotated fields are mapped underBoolean#TRUE, and
all non-annotated fields are mapped under Boolean#FALSE.Partitions all non-synthetic fields of the bean type being processed
into annotated and non-annotated fields according to
|
| public T | populateNewBean(String[] line)
Implements com. Takes a line of input from a CSV file and creates a bean out of it. |
| protected < The annotation type being tested A extends Annotation> A | Returns: The annotation with the appropriate profile ornull if
nothing appropriate is foundAll annotations of a given type annotations, Function<A, String[]> A function mapping an annotation of type getProfiles)A to
the list of profiles it applies toDetermines which one of a list of annotations applies to the currently selected profile. |
| public void | setErrorLocale(Locale errorLocale)
Overrides default com. Sets the locale for all error messages. |
| protected void | setFieldValue(Map<Class<?>, Object>
Object containing the field to be set. beanTree, String String containing the value to set the field to. value, int The column position from the CSV file under which this
value was found. column)Populates the field corresponding to the column position indicated of the bean passed in according to the rules of the mapping strategy. |
| public void | setProfile(String profile)
Overrides default com. Sets the profile this mapping strategy will use when configuring bean fields. |
| public void | setType(Class<? extends T> type)
Implements com. Sets the class type that is being mapped. |
| public String[] | transmuteBean(T bean)
Implements com. Transmutes a bean instance into an array of |
| protected abstract void | verifyLineLength(int
The number of fields present in the line of input numberOfFields)Must be called once the length of input for a line/record is known to verify that the line was complete. |
| errorLocale | back to summary |
|---|---|
| protected Locale errorLocale Locale for error messages. | |
| FORBIDDEN_CLASSES_FOR_RECURSION | back to summary |
|---|---|
| private static final Set<Class<?>> FORBIDDEN_CLASSES_FOR_RECURSION Set of classes where recursion is not allowed. Using HashSet because, given the large number of types, the contains method is quicker than an Array or ArrayList (Granted the number where Set is more efficient is different per Java release and system configuration). And being a Set we are noting that each value is unique. | |
| headerIndex | back to summary |
|---|---|
| protected final HeaderIndex headerIndex Maintains a bi-directional mapping between column position(s) and header name. | |
| ignoredFields | back to summary |
|---|---|
| private MultiValuedMap<Class<?>, Field> ignoredFields Storage for all manually excluded class/field pairs. | |
| profile | back to summary |
|---|---|
| protected String profile The profile for configuring bean fields. | |
| recursiveTypeTree | back to summary |
|---|---|
| protected AbstractMappingStrategy. A tree of the types encountered during recursion through the root bean
type.
These are only the types (and associated fields) specifically annotated
with | |
| type | back to summary |
|---|---|
| protected Class<? extends T> type This is the class of the bean to be manipulated. | |
| AbstractMappingStrategy | back to summary |
|---|---|
| public AbstractMappingStrategy() | |
| assembleCompleteFieldList | back to summary |
|---|---|
| private void assembleCompleteFieldList(AbstractMappingStrategy. Creates a non-tree (fairly flat) representation of all of the fields bound from all types. This method is used recursively.
| |
| chooseMultivaluedFieldIndexFromHeaderIndex | back to summary |
|---|---|
| protected abstract K chooseMultivaluedFieldIndexFromHeaderIndex(int index) For
| |
| createBean | back to summary |
|---|---|
| protected Map Implementation will return a bean of the type of object being mapped.
| |
| createSubordinateBeans | back to summary |
|---|---|
| private static void createSubordinateBeans(AbstractMappingStrategy. | |
| determineConverter | back to summary |
|---|---|
| protected CsvConverter determineConverter(Field field, Class<?> elementType, String locale, String writeLocale, Class<? extends AbstractCsvConverter> customConverter) throws CsvBadConverterException Given the information provided, determines the appropriate built-in
converter to be passed in to the
| |
| filterIgnoredFields | back to summary |
|---|---|
| protected List Filters all fields that opencsv has been instructed to ignore and returns a list of the rest. | |
| findField | back to summary |
|---|---|
| protected abstract BeanField Gets the field for a given column position.
| |
| findHeader | back to summary |
|---|---|
| public abstract String findHeader(int col) Gets the name (or position number) of the header for the given column number. The column numbers are zero-based.
| |
| generateHeader | back to summary |
|---|---|
| public String[] generateHeader(T bean) throws CsvRequiredFieldEmptyException Implements com. This method generates a header that can be used for writing beans of the type provided back to a file. The ordering of the headers is determined by the
This method should be called first by all overriding classes to make
certain
| |
| getBindingAnnotations | back to summary |
|---|---|
| protected Set Returns a set of the annotations that are used for binding in this mapping strategy. The default implementation returns the empty set.
| |
| getColumnName | back to summary |
|---|---|
| protected String getColumnName(int col) Get the column name for a given column position.
| |
| getFieldMap | back to summary |
|---|---|
| protected abstract FieldMap Returns the | |
| getType | back to summary |
|---|---|
| public Class Get the class type that the strategy is mapping.
| |
| ignoreFields | back to summary |
|---|---|
| public void ignoreFields(MultiValuedMap<Class<?>, Field> fields) throws IllegalArgumentException Overrides default com. Doc from com. When processing a bean for reading or writing, ignore the given fields from the given classes completely, including all annotations and requirements. This method has two compelling applications:
Calling this method overwrites the fields passed in from any previous
calls. It is legal to call this method before calling
Caution must be exercised with this method when letting opencsv
automatically determine the mapping strategy. When a field is ignored,
opencsv pretends it does not exist at all. If, for instance, all fields
annotated with opencsv binding annotations are ignored, opencsv will
automatically switch to An implementation of this interface is not required to implement this
method. The default implementation throws
| |
| indexBean | back to summary |
|---|---|
| protected Map Creates an index of necessary types according to the mapping strategy and existing instances of (subordinate) beans.
| |
| indexSubordinateBeans | back to summary |
|---|---|
| private static void indexSubordinateBeans(AbstractMappingStrategy. | |
| initializeFieldMap | back to summary |
|---|---|
| protected abstract void initializeFieldMap() Creates an empty binding-type-specific field map that can be filled in later steps. This method may be called multiple times and must erase any state information from previous calls.
| |
| instantiateCustomConverter | back to summary |
|---|---|
| protected BeanField Attempts to instantiate the class of the custom converter specified.
| |
| isForbiddenClassForRecursion | back to summary |
|---|---|
protected boolean isForbiddenClassForRecursion(Class<?> type)
| |
| loadAnnotatedFieldMap | back to summary |
|---|---|
| protected void loadAnnotatedFieldMap(ListValuedMap<Class<?>, Field> fields) Creates a map of annotated fields in the bean to be processed. This method is called by The default implementation assumes there are no annotations and does nothing.
| |
| loadFieldMap | back to summary |
|---|---|
| protected void loadFieldMap() throws CsvBadConverterException Builds a map of columns from the input to fields of the bean type.
| |
| loadRecursiveClasses | back to summary |
|---|---|
| protected AbstractMappingStrategy. Creates a tree of beans embedded in each other.
These are the member variables annotated with
| |
| loadUnadornedFieldMap | back to summary |
|---|---|
| protected abstract void loadUnadornedFieldMap(ListValuedMap<Class<?>, Field> fields) Creates a map of fields in the bean to be processed that have no
annotations.
This method is called by
| |
| partitionFields | back to summary |
|---|---|
| protected Map Partitions all non-synthetic fields of the bean type being processed
into annotated and non-annotated fields according to
| |
| populateNewBean | back to summary |
|---|---|
| public T populateNewBean(String[] line) throws CsvBeanIntrospectionException, CsvFieldAssignmentException, CsvChainedException Implements com. Doc from com. Takes a line of input from a CSV file and creates a bean out of it.
| |
| selectAnnotationForProfile | back to summary |
|---|---|
| protected <A extends Annotation> A selectAnnotationForProfile(A[] annotations, Function<A, String[]> getProfiles) Determines which one of a list of annotations applies to the currently
selected profile.
If no annotation specific to the profile is found, the annotation for
the default profile is returned. If neither is found,
| |
| setErrorLocale | back to summary |
|---|---|
| public void setErrorLocale(Locale errorLocale) Overrides default com. Doc from com. Sets the locale for all error messages. The default implementation does nothing, as it is expected that most implementations of this interface will not support multiple languages.
| |
| setFieldValue | back to summary |
|---|---|
| protected void setFieldValue(Map<Class<?>, Object> beanTree, String value, int column) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException, CsvConstraintViolationException, CsvValidationException Populates the field corresponding to the column position indicated of the bean passed in according to the rules of the mapping strategy. This method performs conversion on the input string and assigns the result to the proper field in the provided bean.
| |
| setProfile | back to summary |
|---|---|
| public void setProfile(String profile) Overrides default com. Sets the profile this mapping strategy will use when configuring bean fields.
| |
| setType | back to summary |
|---|---|
| public void setType(Class<? extends T> type) throws CsvBadConverterException Implements com. Sets the class type that is being mapped. Also initializes the mapping between column names and bean fields and attempts to create one example bean to be certain there are no fundamental problems with creation.
| |
| transmuteBean | back to summary |
|---|---|
| public String[] transmuteBean(T bean) throws CsvFieldAssignmentException, CsvChainedException Implements com. Doc from com. Transmutes a bean instance into an array of
| |
| verifyLineLength | back to summary |
|---|---|
| protected abstract void verifyLineLength(int numberOfFields) throws CsvRequiredFieldEmptyException Must be called once the length of input for a line/record is known to verify that the line was complete. Complete in this context means, no required fields are missing. The issue here is, as long as a column is present but empty, we can check whether the field is required and throw an exception if it is not, but if the data end prematurely, we never have this chance without indication that no more data are on the way. Another validation is that the number of fields must match the number of headers to prevent a data mismatch situation.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Map | |
| private final Class |
| Access | Constructor and Description |
|---|---|
| protected | RecursiveType(Class<?>
Type associated with this branch type)Constructs a |
| Modifier and Type | Method and Description |
|---|---|
| public void | addRecursiveMember(FieldAccess<Object>
Field access member to add a recursive type to member, AbstractMappingStrategy.RecursiveType to addUsed to add a recursive type. |
| public Map | |
| public Class |
| recursiveMembers | back to summary |
|---|---|
| private final Map<FieldAccess<Object>, AbstractMappingStrategy. | |
| type | back to summary |
|---|---|
| private final Class<?> type | |
| RecursiveType | back to summary |
|---|---|
| protected RecursiveType(Class<?> type) Constructs a
| |
| addRecursiveMember | back to summary |
|---|---|
| public void addRecursiveMember(FieldAccess<Object> member, AbstractMappingStrategy. Used to add a recursive type.
| |
| getRecursiveMembers | back to summary |
|---|---|
public Map
| |
| getType | back to summary |
|---|---|
public Class
| |