com.projectnine.csvmapper
Class CsvToObjectMapper

java.lang.Object
  extended by com.projectnine.csvmapper.CsvToObjectMapper

public class CsvToObjectMapper
extends java.lang.Object

This class is the only class in which users should be directly interested. First of all, if you don't want to go insane, use a spring application context to configure your CsvMappingDefinitions and add them the csvMappingDefinitions Map. Check out the test cases for examples (src/test). Not thread safe. May never be. We'll see.

Author:
robweber

Field Summary
static java.lang.String ARGUMENT_TOKEN
          JEXL expressions for property names in the CsvFieldMapping should include this token somewhere.
protected static java.util.Map<java.lang.String,CsvMappingDefinition> csvMappingDefinitions
          All of the mapping definitions that are available to you.
 
Constructor Summary
CsvToObjectMapper()
          Default constructor.
CsvToObjectMapper(org.springframework.core.io.Resource csvResource, boolean containsHeader, java.lang.String mappingDefinition)
          This constructor is pretty useful.
 
Method Summary
 java.lang.Object generateNextObjectFromCsv()
          Generate the next Object from CSV.
 long getCurrentLineNumber()
          On what line number is the csvReader?
 void init(org.springframework.core.io.Resource csvResource, boolean containsHeader, java.lang.String mappingDefinition)
          Initializes the object by setting the mappingDefinition and instantiating the csvReader.
static void main(java.lang.String[] args)
           
 void seek(long parserPosition)
          Move the cursor of the csvReader to the specified line number.
 void setCsvMappingDefinitions(java.util.Map<java.lang.String,CsvMappingDefinition> csvMappingDefinitions)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARGUMENT_TOKEN

public static final java.lang.String ARGUMENT_TOKEN
JEXL expressions for property names in the CsvFieldMapping should include this token somewhere. The token is a placeholder for the adjusted RAW CSV Field String value. So if you want your JEXL expression to do something like this: getFooMap().put('bar', adjustedCsvValue) you really want to type this: getFooMap().put('bar', %ARGUMENT%)

See Also:
Constant Field Values

csvMappingDefinitions

protected static java.util.Map<java.lang.String,CsvMappingDefinition> csvMappingDefinitions
All of the mapping definitions that are available to you.

Constructor Detail

CsvToObjectMapper

public CsvToObjectMapper()
Default constructor. Mainly, it just does nothing. Do not forget to init(Resource, boolean, String)!!!


CsvToObjectMapper

public CsvToObjectMapper(org.springframework.core.io.Resource csvResource,
                         boolean containsHeader,
                         java.lang.String mappingDefinition)
This constructor is pretty useful. It initializes the object without you having to do it explicitly.

Parameters:
csvResource - The Resource containing the CSV file.
containsHeader - Does this CSV file contain a header? I need to know so that I can skip the header if it's there. There might be problems otherwise...
mappingDefinition - The name of the mapping definition that we are using from the csvMappingDefinitions.
Method Detail

init

public void init(org.springframework.core.io.Resource csvResource,
                 boolean containsHeader,
                 java.lang.String mappingDefinition)
Initializes the object by setting the mappingDefinition and instantiating the csvReader.

See Also:
CsvToObjectMapper(Resource, boolean, String)

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

generateNextObjectFromCsv

public java.lang.Object generateNextObjectFromCsv()
                                           throws java.lang.Exception
Generate the next Object from CSV.

Returns:
An Object; null if there are no more records; throws an Exception if there is a problem loading the next record. Note that a thrown Exception does necessarily indicate a show stopper.
Throws:
java.lang.Exception

setCsvMappingDefinitions

public void setCsvMappingDefinitions(java.util.Map<java.lang.String,CsvMappingDefinition> csvMappingDefinitions)
Parameters:
csvMappingDefinitions - the csvMappingDefinitions to set

getCurrentLineNumber

public long getCurrentLineNumber()
On what line number is the csvReader?

Returns:

seek

public void seek(long parserPosition)
Move the cursor of the csvReader to the specified line number.

Parameters:
parserPosition -


Copyright © 2008. All Rights Reserved.