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.parsers;
17:
18: import java.util.List;
19: import java.util.Map;
20:
21: import org.csvbeans.specs.SpecificationsFile;
22:
23: /**
24: * Define the specifications of a CSV parser.
25: *
26: * Implement this interface if you want to create your own parser.
27: *
28: * @author Fouad Hamdi
29: * @since 0.5
30: */
31: public interface ParsingStrategy {
32: /**
33: * @return Returns the header.
34: */
35: Object getHeader();
36:
37: /**
38: * Set the parser listener. The listener will be notified of the beginning
39: * and the end of the parsing. When a record is parsed, it will also be
40: * notified of the matching bean object.
41: *
42: * @param listener
43: * The listener to set
44: */
45: void setListener(CSVParserListener listener);
46:
47: /**
48: * Return the beans associated with a tag. Each bean represents a CSV
49: * record. If no beans are associated, a null value is returned.
50: *
51: * @param tag
52: * the tag representing the records.
53: * @return the list of beans associated with a tag.
54: */
55: List getBeans(String tag);
56:
57: /**
58: * Parse the content of the specified reader.
59: */
60: void parse(LinesReader reader) throws ParsingException;
61:
62: /**
63: * Define the CSV specifications.
64: *
65: * @param specifications
66: * The CSV specifications.
67: */
68: void setSpecifications(SpecificationsFile specifications);
69:
70: /**
71: * Add a property to the parsing strategy. It is used to set some properties
72: * to specific parsers.
73: *
74: * @param name
75: * @param value
76: */
77: void addProperty(String name, String value);
78:
79: /**
80: * Define the properties of the parser.
81: *
82: * @param properties
83: * the parser properties.
84: */
85: void setProperties(Map properties);
86:
87: /**
88: * Return the value of the specified property.
89: *
90: * @param name
91: * the property name
92: * @return the property value
93: */
94: String getPropertyValue(String name);
95: }
|