01: /*
02: * ColumnWidthDefinition.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.sql.wbcommands;
13:
14: import java.util.HashMap;
15: import java.util.List;
16: import java.util.Map;
17: import workbench.db.ColumnIdentifier;
18: import workbench.util.StringUtil;
19: import workbench.util.StringUtil;
20:
21: /**
22: * Parse the argument for defining column widths for a fixed-width
23: * import file.
24: * @see WbImport#ARG_COL_WIDTHS
25: * @author support@sql-workbench.net
26: */
27: public class ColumnWidthDefinition {
28: private Map<ColumnIdentifier, Integer> columnWidths;
29:
30: public ColumnWidthDefinition(String paramValue)
31: throws MissingWidthDefinition {
32: List<String> entries = StringUtil.stringToList(paramValue, ",",
33: true, true);
34: if (entries == null || entries.size() == 0) {
35: return;
36: }
37: this .columnWidths = new HashMap<ColumnIdentifier, Integer>();
38:
39: for (String def : entries) {
40: String[] parms = def.split("=");
41:
42: if (parms == null || parms.length != 2) {
43: throw new MissingWidthDefinition(def);
44: }
45: ColumnIdentifier col = new ColumnIdentifier(parms[0]);
46: int width = StringUtil.getIntValue(parms[1], -1);
47: if (width <= 0) {
48: throw new MissingWidthDefinition(def);
49: }
50: this .columnWidths.put(col, new Integer(width));
51: }
52: }
53:
54: public Map<ColumnIdentifier, Integer> getColumnWidths() {
55: return columnWidths;
56: }
57: }
|