Coverage Report - rs.mgifos.mosquito.model.MetaModel
 
Classes in this File Line Coverage Branch Coverage Complexity
MetaModel
32%
23/72
17%
2/12
0
 
 1  
 /* 
 2  
  * This file is part of Mosquito meta-loader.
 3  
  *
 4  
  * Mosquito meta-loader is free software; you can redistribute it and/or modify
 5  
  * it under the terms of the GNU Lesser General Public License as published by
 6  
  * the Free Software Foundation; either version 3 of the License, or
 7  
  * (at your option) any later version.
 8  
  *
 9  
  * Mosquito meta-loader is distributed in the hope that it will be useful,
 10  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  
  * GNU Lesser General Public License for more details.
 13  
  *
 14  
  * You should have received a copy of the GNU Lesser General Public License
 15  
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 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  
  * @author <a href="mailto:nikola.petkov@gmail.com">Nikola Petkov &lt;nikola.petkov@gmail.com&gt;</a>
 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  
      * @param aCode
 44  
      *            code
 45  
      * @param aName
 46  
      *            name
 47  
      * @param aComment
 48  
      *            comment for this MetaModel
 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  
      * @param aTable
 59  
      *            MetaTable to add
 60  
      * @throws NullPointerException
 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  
      * Returns collection of tables
 69  
      * 
 70  
      * @return collection of tables
 71  
      */
 72  
     public Collection cTables() {
 73  0
         return vTables;
 74  
     }
 75  
 
 76  
     /**
 77  
      * Returns enumeration of sorted tables by name
 78  
      * 
 79  
      * @return enumeration of sorted tables by name
 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  
      * Returns enumeration of tables
 106  
      * 
 107  
      * @return enumeration of tables
 108  
      */
 109  
     public Enumeration eTables() {
 110  0
         return vTables.elements();
 111  
     }
 112  
 
 113  
     /**
 114  
      * Returns code of this MetaModel
 115  
      * 
 116  
      * @return code of this MetaModel
 117  
      */
 118  
     public String getCode() {
 119  2
         return code;
 120  
     }
 121  
 
 122  
     /**
 123  
      * Returns total columns of all tables within this MetaModel
 124  
      * 
 125  
      * @return total columns of all tables within this MetaModel
 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  
      * Returns description of this MetaModel
 139  
      * 
 140  
      * @return description of this MetaModel
 141  
      */
 142  
     public String getComment() {
 143  1
         return comment;
 144  
     }
 145  
 
 146  
     /**
 147  
      * Returns name of this MetaModel
 148  
      * 
 149  
      * @return name of this MetaModel
 150  
      */
 151  
     public String getName() {
 152  1
         return name;
 153  
     }
 154  
 
 155  
     /**
 156  
      * Returns reference of MetaTable with specified code
 157  
      * 
 158  
      * @param aCode
 159  
      *            code of MetaTable
 160  
      * @return reference of MetaTable with specified code
 161  
      * @throws NullPointerException
 162  
      */
 163  
     public MetaTable getTableByCode(String aCode) throws NullPointerException {
 164  10
         return (MetaTable) htTables.get(aCode);
 165  
     }
 166  
 
 167  
     /**
 168  
      * Returns total count of all MetaTable(s) within this MetaModel
 169  
      * 
 170  
      * @return total count of all MetaTable(s) within this MetaModel
 171  
      */
 172  
     public int getTableCount() {
 173  1
         return htTables.size();
 174  
     }
 175  
 
 176  
     /**
 177  
      * Sets the code of this MetaModel
 178  
      * 
 179  
      * @param aCode
 180  
      *            code to set
 181  
      */
 182  
     public void setCode(String aCode) {
 183  0
         code = aCode;
 184  0
     }
 185  
 
 186  
     /**
 187  
      * Sets description of this MetaModel
 188  
      * 
 189  
      * @param aDescription
 190  
      *            the description to set
 191  
      */
 192  
     public void setComment(String aDescription) {
 193  0
         comment = aDescription;
 194  0
     }
 195  
 
 196  
     /**
 197  
      * Sets the name of this MetaModel
 198  
      * 
 199  
      * @param aName
 200  
      *            The name to set.
 201  
      */
 202  
     public void setName(String aName) {
 203  0
         name = aName;
 204  0
     }
 205  
 
 206  
     /**
 207  
      * Returns the string representation of this MetaModel
 208  
      * 
 209  
      * @see java.lang.Object#toString()
 210  
      */
 211  
     public String toString() {
 212  0
         return name;
 213  
     }
 214  
 
 215  
     /**
 216  
      * Returns verbose description of this MetaModel
 217  
      * 
 218  
      * @return verbose description of this MetaModel
 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  
 }