| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package rs.mgifos.mosquito.model; |
| 19 | |
|
| 20 | |
import java.util.Collection; |
| 21 | |
import java.util.Enumeration; |
| 22 | |
import java.util.Hashtable; |
| 23 | |
import java.util.Iterator; |
| 24 | |
import java.util.Vector; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
public class MetaTable implements Iterable<MetaColumn> { |
| 32 | |
|
| 33 | |
protected String code; |
| 34 | |
|
| 35 | |
protected String comment; |
| 36 | |
|
| 37 | 5 | protected Hashtable<String, MetaColumn> htColumns = new Hashtable<String, MetaColumn>(); |
| 38 | |
|
| 39 | 5 | protected Hashtable<String, MetaKey> htKeys = new Hashtable<String, MetaKey>(); |
| 40 | |
|
| 41 | 5 | protected Hashtable<String, MetaReference> htRefs = new Hashtable<String, MetaReference>(); |
| 42 | |
|
| 43 | |
protected String name; |
| 44 | |
|
| 45 | 5 | protected Vector<MetaColumn> vColumns = new Vector<MetaColumn>(); |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
public MetaTable(String aCode, String aName, String aComment) { |
| 56 | 5 | super(); |
| 57 | 5 | code = aCode; |
| 58 | 5 | name = aName; |
| 59 | 5 | comment = aComment; |
| 60 | 5 | } |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
public void addCol(MetaColumn aMC) { |
| 68 | 18 | aMC.setParentTable(code); |
| 69 | 18 | Enumeration<MetaKey> eKeys = htKeys.elements(); |
| 70 | 36 | while (eKeys.hasMoreElements()) { |
| 71 | 18 | MetaKey mk = (MetaKey) eKeys.nextElement(); |
| 72 | 18 | if (mk.containsColumn(aMC)) |
| 73 | 5 | aMC.setParentKey(mk); |
| 74 | 18 | } |
| 75 | 18 | vColumns.add(aMC); |
| 76 | 18 | htColumns.put(aMC.getTableDotColumnCode(), aMC); |
| 77 | 18 | } |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
public void addKey(MetaKey aMK) { |
| 83 | 5 | htKeys.put(aMK.getCode(), aMK); |
| 84 | 5 | } |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
public void addRef(MetaReference aMR) { |
| 90 | 4 | htRefs.put(aMR.getCode(), aMR); |
| 91 | 4 | } |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
public Collection cColumns() { |
| 99 | 0 | return vColumns; |
| 100 | |
} |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
public boolean contains(MetaColumn aMC) { |
| 110 | 0 | return htColumns.contains(aMC); |
| 111 | |
} |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
public Enumeration eColumns() { |
| 119 | 0 | return vColumns.elements(); |
| 120 | |
} |
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
public Enumeration eKeys() { |
| 126 | 0 | return htKeys.elements(); |
| 127 | |
} |
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
public Enumeration eRefs() { |
| 133 | 0 | return htRefs.elements(); |
| 134 | |
} |
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
public String getCode() { |
| 142 | 28 | return code; |
| 143 | |
} |
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
public Object getColByTableDotColumnCode(String aTableDotColumnCode) |
| 158 | |
throws NullPointerException { |
| 159 | 18 | return htColumns.get(aTableDotColumnCode); |
| 160 | |
} |
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
public String getComment() { |
| 168 | 0 | return comment; |
| 169 | |
} |
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
public MetaKey getKeyByCode(String aKeyCode) { |
| 176 | 0 | MetaKey retVal = null; |
| 177 | |
try { |
| 178 | 0 | retVal = (MetaKey) htKeys.get(aKeyCode); |
| 179 | 0 | } catch (Exception e) { |
| 180 | 0 | retVal = null; |
| 181 | 0 | } |
| 182 | 0 | return retVal; |
| 183 | |
} |
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
public String getName() { |
| 191 | 0 | return name; |
| 192 | |
} |
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
public int getTotalColumns() { |
| 200 | 5 | return vColumns.size(); |
| 201 | |
} |
| 202 | |
|
| 203 | |
public Iterator<MetaColumn> iterator() { |
| 204 | |
|
| 205 | 5 | return vColumns.iterator(); |
| 206 | |
} |
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
public void setCode(String code) { |
| 215 | 0 | this.code = code; |
| 216 | 0 | } |
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
public void setComment(String aDescription) { |
| 225 | 0 | comment = aDescription; |
| 226 | 0 | } |
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
public void setName(String name) { |
| 235 | 0 | this.name = name; |
| 236 | 0 | } |
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
public String toString() { |
| 244 | 0 | return name; |
| 245 | |
} |
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
public String toStringVerbose() { |
| 253 | 0 | String retVal = "<HTML><TABLE border=\"1\">" + "<CAPTION><B>" + code |
| 254 | |
+ "</B></CAPTION>"; |
| 255 | 0 | retVal += "<TBODY>"; |
| 256 | 0 | retVal += "<TR><TD align=\"right\">" + "<B>name</B>" + "</TD>" |
| 257 | |
+ "<TD align=\"left\">" + name + "</TD></TR>"; |
| 258 | 0 | retVal += "<TR><TD align=\"right\">" + "<B>code</B>" + "</TD>" |
| 259 | |
+ "<TD align=\"left\">" + code + "</TD></TR>"; |
| 260 | 0 | retVal += "<TR><TD align=\"right\">" + "<B>comment</B>" + "</TD>" |
| 261 | |
+ "<TD align=\"left\" ROWSPAN=\"2\">" |
| 262 | |
+ MetaUtils.insertHTMLBreaks(comment, 50) + "</TD></TR>"; |
| 263 | 0 | retVal += "</TBODY></TABLE>"; |
| 264 | |
|
| 265 | 0 | retVal += "<TABLE border=\"1\">" + "<CAPTION><B> KEYS" |
| 266 | |
+ "</B></CAPTION>"; |
| 267 | 0 | retVal += "<TH><I>Name</I></TH><TH><I>Code</I></TH><TH><I>Columns</I></TH><TBODY>"; |
| 268 | 0 | Enumeration<MetaKey> eKeys = htKeys.elements(); |
| 269 | 0 | while (eKeys.hasMoreElements()) { |
| 270 | 0 | MetaKey crntKey = eKeys.nextElement(); |
| 271 | 0 | retVal += "<TR><TD>"; |
| 272 | 0 | retVal += crntKey.getName(); |
| 273 | 0 | retVal += "</TD><TD>"; |
| 274 | 0 | retVal += crntKey.getCode(); |
| 275 | 0 | retVal += "</TD><TD><TABLE><TBODY>"; |
| 276 | 0 | Enumeration<MetaColumn> eKeyCols = crntKey.eColumns(); |
| 277 | 0 | while (eKeyCols.hasMoreElements()) { |
| 278 | 0 | MetaColumn crntKeyCol = eKeyCols.nextElement(); |
| 279 | 0 | retVal += "<TR><TD>" + crntKeyCol.getCode() + "</TD><TD>"; |
| 280 | 0 | retVal += crntKeyCol.getName() + "</TD></TR>"; |
| 281 | 0 | } |
| 282 | 0 | retVal += "</TBODY></TABLE>"; |
| 283 | 0 | } |
| 284 | 0 | retVal += "</TBODY></TABLE>"; |
| 285 | |
|
| 286 | |
|
| 287 | 0 | retVal += "<TABLE border=\"1\">" + "<CAPTION><B> REFERENCES" |
| 288 | |
+ "</B></CAPTION>"; |
| 289 | 0 | retVal += "<TH><I>Name</I></TH><TH><I>Code</I></TH><TH><I>Parent Table</I></TH>" |
| 290 | |
+ "<TH><I>Columns</I></TH><TBODY>"; |
| 291 | 0 | Enumeration<MetaReference> eRefs = htRefs.elements(); |
| 292 | 0 | while (eRefs.hasMoreElements()) { |
| 293 | 0 | MetaReference currRef = eRefs.nextElement(); |
| 294 | 0 | retVal += "<TR><TD>"; |
| 295 | 0 | retVal += currRef.getName(); |
| 296 | 0 | retVal += "</TD><TD>"; |
| 297 | 0 | retVal += currRef.getCode(); |
| 298 | 0 | retVal += "</TD><TD>"; |
| 299 | 0 | retVal += currRef.getParentTable(); |
| 300 | 0 | retVal += "</TD><TD><TABLE><TBODY>"; |
| 301 | 0 | Enumeration<MetaColumn> eKeyCols = currRef.eColumns(); |
| 302 | 0 | while (eKeyCols.hasMoreElements()) { |
| 303 | 0 | MetaColumn crntKeyCol = eKeyCols.nextElement(); |
| 304 | 0 | retVal += "<TR><TD>" + crntKeyCol.getCode() + "</TD><TD>"; |
| 305 | 0 | retVal += crntKeyCol.getName() + "</TD></TR>"; |
| 306 | 0 | } |
| 307 | 0 | retVal += "</TD></TBODY></TABLE>"; |
| 308 | 0 | } |
| 309 | 0 | retVal += "</TBODY></TABLE>"; |
| 310 | |
|
| 311 | |
|
| 312 | 0 | retVal += "<TABLE border=\"1\">" + "<CAPTION><B> COLUMNS" |
| 313 | |
+ "</B></CAPTION>"; |
| 314 | 0 | retVal += "<TH><I>No</I></TH><TH><I>Name</I></TH><TH><I>Code</I></TH><TBODY>"; |
| 315 | 0 | int count = 0; |
| 316 | 0 | Enumeration<MetaColumn> eCols = vColumns.elements(); |
| 317 | 0 | while (eCols.hasMoreElements()) { |
| 318 | 0 | MetaColumn crntCol = (MetaColumn) eCols.nextElement(); |
| 319 | 0 | retVal += "<TR><TD align=\"right\">"; |
| 320 | 0 | retVal += ++count; |
| 321 | 0 | retVal += "</TD><TD>"; |
| 322 | 0 | retVal += crntCol.getName(); |
| 323 | 0 | retVal += "</TD><TD>"; |
| 324 | 0 | retVal += crntCol.getCode(); |
| 325 | 0 | retVal += "</TD></TR>"; |
| 326 | 0 | } |
| 327 | 0 | retVal += "</TBODY></TABLE></HTML>"; |
| 328 | |
|
| 329 | 0 | return retVal; |
| 330 | |
} |
| 331 | |
} |