View Javadoc

1   /***
2    * Copyright (C) 2008 rweber <quietgenie@users.sourceforge.net>
3    * 
4    * This file is part of CsvObjectMapper.
5    * 
6    * CsvObjectMapper is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Lesser General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   * 
11   * CsvObjectMapper is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Lesser General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Lesser General Public License
17   * along with CsvObjectMapper.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  /***
21   * 
22   */
23  package com.projectnine.csvmapper;
24  
25  import java.util.List;
26  
27  import org.apache.commons.chain.Chain;
28  import org.apache.commons.chain.impl.ContextBase;
29  
30  /***
31   * This is the context that is passed between {@link CsvFieldValidator} in the
32   * same {@link Chain}.
33   * 
34   * @author robweber
35   * 
36   */
37  public class CsvFieldValidationContext extends ContextBase {
38      private static final long serialVersionUID = 8773791574677655162L;
39  
40      /***
41       * The RAW CSV String value to validate.
42       */
43      private String valueToValidate;
44  
45      /***
46       * The Object to which the CSV Field value will be stored once it has been
47       * validated and adjusted.
48       */
49      private Object generatedObject;
50  
51      /***
52       * A list of every other CSV field value on the same line as the CSV FIeld
53       * value that will be validated.
54       */
55      private List<String> currentCsvLine;
56  
57      /***
58       * String used to track the progress of this context through a {@link Chain}
59       * of {@link CsvFieldValidator}s.
60       */
61      private String currentValidationCommandName;
62  
63      /***
64       * @return the valueToValidate
65       */
66      public String getValueToValidate() {
67          return valueToValidate;
68      }
69  
70      /***
71       * @param valueToValidate
72       *            the valueToValidate to set
73       */
74      public void setValueToValidate(String valueToValidate) {
75          this.valueToValidate = valueToValidate;
76      }
77  
78      /***
79       * Set the Object to which the CSV Field value will be stored once it has
80       * been validated and adjusted.
81       * 
82       * @param generatedObject
83       */
84      public void setGeneratedObject(Object generatedObject) {
85          this.generatedObject = generatedObject;
86      }
87  
88      /***
89       * @return the generatedObject
90       */
91      public Object getGeneratedObject() {
92          return generatedObject;
93      }
94  
95      /***
96       * Set the list of every other CSV field value on the same line as the CSV
97       * Field value that will be validated.
98       * 
99       * @param currentCsvLine
100      */
101     public void setCurrentCsvLine(List<String> currentCsvLine) {
102         this.currentCsvLine = currentCsvLine;
103     }
104 
105     /***
106      * @return the currentCsvLine
107      */
108     public List<String> getCurrentCsvLine() {
109         return currentCsvLine;
110     }
111 
112     /***
113      * Set the String used to track the progress of this context through a
114      * {@link Chain} of {@link CsvFieldValidator}s.
115      * 
116      * @param currentValidationCommandName
117      */
118     public void setCurrentValidationCommandName(
119             String currentValidationCommandName) {
120         this.currentValidationCommandName = currentValidationCommandName;
121     }
122 
123     /***
124      * Get the String used to track the progress of this context through a
125      * {@link Chain} of {@link CsvFieldValidator}s.
126      * 
127      * @return
128      */
129     public String getCurrentValidationCommandName() {
130         return currentValidationCommandName;
131     }
132 }