/* Copyright (c) 2006 Ricebridge. All Rights Reserved. * * This file is available under the terms and conditions of the * Ricebridge "Open Source API" policy; Ricebridge grants use of this * copyrighted work under the terms of a BSD-style license only. See * http://www.opensource.org/licenses/bsd-license.php for more * information. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * - Neither the name of the Ricebridge nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.ricebridge.csvman; import org.jostraca.util.Internal; import java.lang.reflect.*; import java.util.*; /** Stores metadata about each data field. * <p>Converting CSV to data structures such as Java Beans requires additional information about * each data field. For example, in the case of Java Beans, the <code>LineSpec</code> identifies the correct get and set methods for * each data field (see {@link CsvManager#loadBeans CsvManager.loadBeans(Object,LineSpec,BeanSpec)} for more details).</p> * <p>You can also use a <code>LineSpec</code> in your own {@link LineListener LineListeners} and {@link LineProvider LineProviders}. * Simply create a subclass of <code>LineSpec</code> with your own settings. Be careful when you do this to make sure that * you use unique names for your methods and member variables, otherwise they may clash with future versions of <code>LineSpec</code>. * The best idea is to prefix or suffix your custom methods with the name of your company or project.</p> * <p>This class differs from {@link CsvSpec} in that it is concerned with individual lines and fields of data, and their * interpretation. <code>CsvSpec</code> controls the entire CSV loading and saving process.</p> * <p><code>LineSpec</code> is optional, so all {@link CsvManager} load and save methods are available * with and without a <code>LineSpec</code> parameter.</p> * <p>In the current version of <a href="http://www.ricebridge.com/products/csvman.htm">CSV Manager</a>, you only really need to * use a <code>LineSpec</code> when working with Java Beans. * None of the other built-in data formats use a <code>LineSpec</code>.</p> * <p>The <b><a href="LineSpec.java.html">Source Code</a></b> of this Java class * is available under a <a href="http://www.opensource.org/licenses/bsd-license.php">BSD-style license</a>.</p> * * @see CsvSpec * @see BeanLineListener * @see BeanLineProvider */ public class LineSpec { // protected instance /** The list of field names for each data row. The meaning of these names depends on the * {@link LineListener}. For {@link BeanLineListener}, these names correspond to the get and set method * names. For other LineListeners, the field names may have another interpretation. */ protected String[] iFieldNames = new String[] {}; // constructors /** Create an empty <code>LineSpec</code>. */ public LineSpec() { // do nothing } /** Create a <code>LineSpec</code> with the specified list of field names. * @param pFieldNames <code>String[]</code> array of field names */ public LineSpec( String[] pFieldNames ) { iFieldNames = Internal.null_array( pFieldNames ); } // public methods /** Get the list of field names. */ public String[] getFieldNames() { return (String[]) iFieldNames.clone(); } /** A human-friendly description of the current line specification settings. */ public String toString() { return "LineSpec[fieldnames="+Arrays.asList(iFieldNames)+"]"; } }