1 /* 2 * Copyright 2007 Kasper B. Graversen 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.supercsv.io; 17 18 import java.io.IOException; 19 20 import org.supercsv.cellprocessor.ift.CellProcessor; 21 import org.supercsv.exception.SuperCsvConstraintViolationException; 22 import org.supercsv.exception.SuperCsvException; 23 import org.supercsv.exception.SuperCsvReflectionException; 24 25 /** 26 * Interface for all CSV writers writing to beans. 27 * 28 * @author Kasper B. Graversen 29 */ 30 public interface ICsvBeanWriter extends ICsvWriter { 31 32 /** 33 * Writes the fields of the object as columns of a CSV file, using the supplied name mapping to map fields to the 34 * appropriate columns. <tt>toString()</tt> will be called on each element prior to writing. 35 * 36 * @param source 37 * the object (bean instance) containing the values to write 38 * @param nameMapping 39 * an array of Strings linking the fields in the bean to their corresponding CSV columns (the array 40 * length should match the number of columns). A <tt>null</tt> entry in the array indicates that the 41 * column should be ignored (the column will be empty). 42 * @throws IOException 43 * if an I/O error occurred 44 * @throws NullPointerException 45 * if source or nameMapping are null 46 * @throws SuperCsvException 47 * if there was a general exception while writing 48 * @throws SuperCsvReflectionException 49 * if there was an reflection exception while mapping the values from the bean 50 * @since 1.0 51 */ 52 void write(Object source, String... nameMapping) throws IOException; 53 54 /** 55 * Writes the fields of the object as columns of a CSV file, using the supplied name mapping to map fields to the 56 * appropriate columns. <tt>toString()</tt> will be called on each (processed) element prior to writing. 57 * 58 * @param source 59 * the object (bean instance) containing the values to write 60 * @param nameMapping 61 * an array of Strings linking the fields in the bean to their corresponding CSV columns (the array 62 * length should match the number of columns). A <tt>null</tt> entry in the array indicates that the 63 * column should be ignored (the column will be empty). 64 * @param processors 65 * an array of CellProcessors used to further process data before it is written (each element in the 66 * processors array corresponds with a CSV column - the number of processors should match the number of 67 * columns). A <tt>null</tt> entry indicates no further processing is required (the value returned by 68 * toString() will be written as the column value). 69 * @throws IOException 70 * if an I/O error occurred 71 * @throws NullPointerException 72 * if source, nameMapping or processors are null 73 * @throws SuperCsvConstraintViolationException 74 * if a CellProcessor constraint failed 75 * @throws SuperCsvException 76 * if there was a general exception while writing/processing 77 * @throws SuperCsvReflectionException 78 * if there was an reflection exception while mapping the values from the bean 79 * @since 1.29 80 */ 81 void write(Object source, String[] nameMapping, CellProcessor[] processors) throws IOException; 82 83 }