| 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 | |
public class MetaModel implements Iterable<MetaTable> { |
| 31 | |
|
| 32 | |
protected String code; |
| 33 | |
|
| 34 | |
protected String comment; |
| 35 | |
|
| 36 | 1 | protected Hashtable<String, MetaTable> htTables = new Hashtable<String, MetaTable>(); |
| 37 | |
|
| 38 | 1 | protected Vector<MetaTable> vTables = new Vector<MetaTable>(); |
| 39 | |
|
| 40 | |
protected String name; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public MetaModel(String aCode, String aName, String aComment) { |
| 51 | 1 | super(); |
| 52 | 1 | code = aCode; |
| 53 | 1 | name = aName; |
| 54 | 1 | comment = aComment; |
| 55 | 1 | } |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
public void addTable(MetaTable aTable) throws NullPointerException { |
| 63 | 5 | vTables.add(aTable); |
| 64 | 5 | htTables.put(aTable.getCode(), aTable); |
| 65 | 5 | } |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
public Collection cTables() { |
| 73 | 0 | return vTables; |
| 74 | |
} |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
public Enumeration<MetaTable> eSortedTables() { |
| 82 | 0 | Vector<MetaTable> retVal = new Vector<MetaTable>(); |
| 83 | 0 | if (!vTables.isEmpty()) { |
| 84 | 0 | Enumeration<MetaTable> eTables = vTables.elements(); |
| 85 | 0 | MetaTable crntTable = eTables.nextElement(); |
| 86 | 0 | retVal.add(crntTable); |
| 87 | 0 | while (eTables.hasMoreElements()) { |
| 88 | 0 | crntTable = (MetaTable) eTables.nextElement(); |
| 89 | 0 | Enumeration<MetaTable> eVTables = retVal.elements(); |
| 90 | 0 | int index = 0; |
| 91 | 0 | while (eVTables.hasMoreElements()) { |
| 92 | 0 | MetaTable crntVTable = eVTables.nextElement(); |
| 93 | 0 | if (crntTable.getName().compareToIgnoreCase( |
| 94 | |
crntVTable.getName()) < 0) |
| 95 | 0 | break; |
| 96 | 0 | index += 1; |
| 97 | 0 | } |
| 98 | 0 | retVal.add(index, crntTable); |
| 99 | 0 | } |
| 100 | |
} |
| 101 | 0 | return retVal.elements(); |
| 102 | |
} |
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
public Enumeration eTables() { |
| 110 | 0 | return vTables.elements(); |
| 111 | |
} |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
public String getCode() { |
| 119 | 2 | return code; |
| 120 | |
} |
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
public int getColumnCount() { |
| 128 | 1 | int retVal = 0; |
| 129 | 1 | Enumeration<MetaTable> eTables = vTables.elements(); |
| 130 | 6 | while (eTables.hasMoreElements()) { |
| 131 | 5 | MetaTable crntTable = eTables.nextElement(); |
| 132 | 5 | retVal += crntTable.getTotalColumns(); |
| 133 | 5 | } |
| 134 | 1 | return retVal; |
| 135 | |
} |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
public String getComment() { |
| 143 | 1 | return comment; |
| 144 | |
} |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
public String getName() { |
| 152 | 1 | return name; |
| 153 | |
} |
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
public MetaTable getTableByCode(String aCode) throws NullPointerException { |
| 164 | 10 | return (MetaTable) htTables.get(aCode); |
| 165 | |
} |
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
public int getTableCount() { |
| 173 | 1 | return htTables.size(); |
| 174 | |
} |
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
public void setCode(String aCode) { |
| 183 | 0 | code = aCode; |
| 184 | 0 | } |
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
public void setComment(String aDescription) { |
| 193 | 0 | comment = aDescription; |
| 194 | 0 | } |
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
public void setName(String aName) { |
| 203 | 0 | name = aName; |
| 204 | 0 | } |
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
public String toString() { |
| 212 | 0 | return name; |
| 213 | |
} |
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
public String toStringVerbose() { |
| 221 | 0 | String retVal = "<HTML><TABLE border=\"1\">" + "<CAPTION><B>" + code |
| 222 | |
+ "</B></CAPTION>"; |
| 223 | 0 | retVal += "<TBODY>"; |
| 224 | 0 | retVal += "<TR><TD align=\"right\">" + "<B>name</B>" + "</TD>" |
| 225 | |
+ "<TD align=\"left\">" + name + "</TD></TR>"; |
| 226 | 0 | retVal += "<TR><TD align=\"right\">" + "<B>code</B>" + "</TD>" |
| 227 | |
+ "<TD align=\"left\">" + code + "</TD></TR>"; |
| 228 | 0 | retVal += "<TR><TD align=\"right\">" + "<B>comment</B>" + "</TD>" |
| 229 | |
+ "<TD align=\"left\">" |
| 230 | |
+ MetaUtils.insertHTMLBreaks(comment, 50) + "</TD></TR>"; |
| 231 | 0 | retVal += "</TBODY></TABLE>"; |
| 232 | 0 | retVal += "<TABLE border=\"1\">" + "<CAPTION><B> TABLES" |
| 233 | |
+ "</B></CAPTION><TBODY>"; |
| 234 | 0 | retVal += "<TH><I>No.</I></TH><TH><I>Name</I></TH><TH><I>Code</I></TH>"; |
| 235 | 0 | int count = 0; |
| 236 | 0 | Enumeration<MetaTable> eTables = this.eSortedTables(); |
| 237 | 0 | while (eTables.hasMoreElements()) { |
| 238 | 0 | MetaTable crntTable = (MetaTable) eTables.nextElement(); |
| 239 | 0 | retVal += "<TR><TD align=\"right\">"; |
| 240 | 0 | retVal += ++count; |
| 241 | 0 | retVal += "</TD><TD>"; |
| 242 | 0 | retVal += crntTable.getName(); |
| 243 | 0 | retVal += "</TD><TD>"; |
| 244 | 0 | retVal += crntTable.getCode(); |
| 245 | 0 | retVal += "</TD></TR>"; |
| 246 | 0 | } |
| 247 | 0 | retVal += "</TBODY></TABLE></HTML>"; |
| 248 | 0 | return retVal; |
| 249 | |
} |
| 250 | |
|
| 251 | |
public Iterator<MetaTable> iterator() { |
| 252 | 1 | return vTables.iterator(); |
| 253 | |
} |
| 254 | |
} |