01: /*
02: * Copyright 2004-2006 Fouad HAMDI.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.csvbeans.converters;
17:
18: import org.csvbeans.specs.SpecificationsFile;
19:
20: /**
21: * Converter definition. A converter allows to transform an object into a string
22: * (encoding) that will be put in a CSV field or to transform a string into an
23: * object (decoding) when reading a CSV field.
24: *
25: * @author Fouad Hamdi
26: * @since 0.5
27: */
28: public interface Converter {
29: /**
30: * Add a property to the converter.
31: *
32: * @param name
33: * name of the property
34: * @param value
35: * value of the property
36: */
37: void addProperty(String name, String value);
38:
39: /**
40: * Initialize the converter. Will be called once created.
41: */
42: void init(SpecificationsFile specifications);
43:
44: /**
45: * Transform an object into a string. When a field is associated with the
46: * converter, its value will be the result of the encoding operation when
47: * building a CSV file.
48: *
49: * @param object
50: * the field value to encode
51: * @return the result of the encoding operation
52: */
53: String encode(Object object) throws ConverterException;
54:
55: /**
56: * Transform a CSV value into an object. When reading a CSV file, it can be
57: * interesting to perform some operations on some field value. This method
58: * can be used to perform such work.
59: *
60: * @param value
61: * the value to decode
62: * @return an object built from the given value
63: */
64: Object decode(String value) throws ConverterException;
65: }
|