1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package jdbcadmin.core.data;
21
22 import java.io.Serializable;
23 import java.util.HashMap;
24 import java.util.Iterator;
25 import java.util.Map;
26
27 import jdbcadmin.core.exceptions.TechnicalException;
28 import jdbcadmin.core.util.StringUtil;
29
30 /***
31 * Represents a table line.
32 */
33 public class Line implements Serializable{
34
35
36
37
38 /*** Line values : Map column name/value as String. */
39 private Map values;
40
41 /*** Line's table */
42 private Table table;
43
44
45
46 /***
47 * Constructor which specifies the line's table.
48 * @param aTable the line's table
49 */
50 public Line (Table aTable) {
51 table = aTable;
52
53 values = new HashMap(table.getColumnNumber());
54 Iterator it = table.iterateColumnNames();
55 while (it.hasNext() ) {
56 values.put(it.next(), null);
57 }
58 }
59
60
61
62 /***
63 * Adds a value
64 * @param aNomColonne column name
65 * @param aVal value
66 * @throws TechnicalException Technical error
67 */
68 public void addValue (String aNomColonne, String aVal) throws TechnicalException {
69
70
71 if (!table.containsColumn(aNomColonne)) {
72 throw new TechnicalException("La table " + table.getName()
73 + " ne contient pas de colonne nommée |" + aNomColonne + "|");
74 }
75
76
77 values.put(aNomColonne, aVal);
78 }
79
80 /***
81 * Retrieves a value for athe specified columns
82 * @param aColName column name
83 * @return the value
84 */
85 public String getValue(String aColName) {
86 return (String) values.get(aColName);
87 }
88
89 /***
90 * Retrieves a Map containing values, the key of the map is the column name.
91 * @return the values
92 */
93 public Map getValues() {
94 return values;
95 }
96
97
98
99 /***
100 * Represente la ligne sous forme de String
101 * {@inheritDoc}
102 * */
103 public String toString() {
104 StringBuffer buff = new StringBuffer();
105 Iterator it = table.iterateColumnNames();
106 while (it.hasNext()) {
107 String nomCol = (String) it.next();
108 String val = (String) values.get(nomCol);
109 if (val != null) {
110 val = "<" + val + ">";
111 }
112 StringUtil.append(buff, null, null, val,
113 ((Integer) table.getColumnSizes().get(nomCol)).intValue(), "|", ' ');
114 }
115 return buff.toString();
116 }
117 /***
118 * Returns the table.
119 * @return Table
120 */
121 public Table getTable() {
122 return table;
123 }
124
125 }