Coverage Report - rs.mgifos.mosquito.impl.pdm.PDMetaLoader
 
Classes in this File Line Coverage Branch Coverage Complexity
PDMetaLoader
82%
84/103
75%
18/24
0
PDMetaLoader$ActualRefStack
100%
5/5
N/A
0
PDMetaLoader$ActualXEStack
100%
9/9
100%
2/2
0
PDMetaLoader$HT_ID_XOE
100%
5/5
N/A
0
PDMetaLoader$PDMColumn
84%
31/37
62%
5/8
0
PDMetaLoader$PDMElement
100%
5/5
N/A
0
PDMetaLoader$PDMKey
81%
13/16
100%
2/2
0
PDMetaLoader$PDMModel
81%
13/16
100%
2/2
0
PDMetaLoader$PDMReference
100%
9/9
N/A
0
PDMetaLoader$PDMShortcut
100%
1/1
N/A
0
PDMetaLoader$PDMTable
81%
35/43
100%
6/6
0
PDMetaLoader$ReferenceJoin
73%
8/11
N/A
0
PDMetaLoader$XmlElem
100%
34/34
N/A
0
PDMetaLoader$XmlHandlerDelegate
85%
242/286
74%
175/236
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.impl.pdm;
 19  
 
 20  
 import java.io.File;
 21  
 import java.io.FileNotFoundException;
 22  
 import java.io.IOException;
 23  
 import java.util.ArrayList;
 24  
 import java.util.EmptyStackException;
 25  
 import java.util.Enumeration;
 26  
 import java.util.Hashtable;
 27  
 import java.util.Iterator;
 28  
 import java.util.Properties;
 29  
 import java.util.Stack;
 30  
 
 31  
 import javax.xml.parsers.ParserConfigurationException;
 32  
 import javax.xml.parsers.SAXParser;
 33  
 import javax.xml.parsers.SAXParserFactory;
 34  
 
 35  
 import org.apache.log4j.Logger;
 36  
 import org.xml.sax.Attributes;
 37  
 import org.xml.sax.SAXException;
 38  
 import org.xml.sax.helpers.DefaultHandler;
 39  
 
 40  
 import rs.mgifos.mosquito.IMetaLoader;
 41  
 import rs.mgifos.mosquito.LoadingException;
 42  
 import rs.mgifos.mosquito.model.MetaColumn;
 43  
 import rs.mgifos.mosquito.model.MetaKey;
 44  
 import rs.mgifos.mosquito.model.MetaModel;
 45  
 import rs.mgifos.mosquito.model.MetaReference;
 46  
 import rs.mgifos.mosquito.model.MetaTable;
 47  
 
 48  
 /**
 49  
  * PowerDesigner's pdm(xml) file loader.
 50  
  * 
 51  
  * @author <a href="mailto:nikola.petkov@gmail.com">Nikola Petkov
 52  
  *         &lt;nikola.petkov@gmail.com&gt;</a>
 53  
  */
 54  66
 public class PDMetaLoader implements IMetaLoader {
 55  
 
 56  1
         class ActualRefStack {
 57  1
                 private Stack<PDMReference> stk = new Stack<PDMReference>();
 58  
 
 59  
                 public PDMReference peek() throws EmptyStackException {
 60  2255
                         return (PDMReference) stk.peek();
 61  
                 }
 62  
 
 63  
                 public PDMReference pop() throws EmptyStackException {
 64  8
                         return (PDMReference) stk.pop();
 65  
                 }
 66  
 
 67  
                 public PDMReference push(PDMReference aActualRef) {
 68  8
                         return (PDMReference) stk.push(aActualRef);
 69  
                 }
 70  
         }
 71  
 
 72  1
         class ActualXEStack {
 73  1
                 private Stack<XmlElem> stk = new Stack<XmlElem>();
 74  
 
 75  
                 public XmlElem peek() throws EmptyStackException {
 76  2843
                         return (XmlElem) stk.peek();
 77  
                 }
 78  
 
 79  
                 public XmlElem pop() throws EmptyStackException {
 80  603
                         return (XmlElem) stk.pop();
 81  
                 }
 82  
 
 83  
                 public XmlElem push(XmlElem aXE) {
 84  603
                         return (XmlElem) stk.push(aXE);
 85  
                 }
 86  
 
 87  
                 public XmlElem underPeek() throws EmptyStackException {
 88  2284
                         int len = stk.size();
 89  2284
                         if (len < 2)
 90  2
                                 throw new EmptyStackException();
 91  2282
                         return (XmlElem) stk.elementAt(len - 2);
 92  
                 }
 93  
 
 94  
         }
 95  
 
 96  
         /**
 97  
          * Stores xoe when when it is declared \ <nmsp:Elem Id="aKey"/>
 98  
          */
 99  
 
 100  
         class HT_ID_XOE {
 101  
                 private Hashtable<String, XmlElem> htId_XOE;
 102  
 
 103  1
                 public HT_ID_XOE(int ainitCap) {
 104  1
                         htId_XOE = new Hashtable<String, XmlElem>(ainitCap);
 105  1
                 }
 106  
 
 107  
                 /**
 108  
                  * @param aId
 109  
                  * @return xoe
 110  
                  */
 111  
                 public XmlElem get(String aId) {
 112  14
                         return (XmlElem) htId_XOE.get(aId);
 113  
                 }
 114  
 
 115  
                 /**
 116  
                  * @param id
 117  
                  *            string (key)
 118  
                  * @param xe
 119  
                  *            (value)
 120  
                  * @return prev xe
 121  
                  */
 122  
                 public XmlElem put(String aId, XmlElem aXOE) {
 123  25
                         return (XmlElem) htId_XOE.put(aId, aXOE);
 124  
                 }
 125  
         }
 126  
 
 127  18
         class PDMColumn extends PDMElement {
 128  
 
 129  18
                 protected String comment = "";
 130  
 
 131  18
                 protected String datatype = "";
 132  
 
 133  18
                 protected String defaultVal = "";
 134  
 
 135  
                 protected PDMColumn fkParent;
 136  
 
 137  18
                 protected String length = "";
 138  
 
 139  18
                 protected String listOfVals = "";
 140  
 
 141  18
                 protected boolean mandatory = false;
 142  
 
 143  18
                 protected String parentTable = "";
 144  
 
 145  18
                 protected boolean partOfPK = false;
 146  
 
 147  18
                 protected String precision = "";
 148  
 
 149  
                 protected MetaColumn getCreateMetaColumn() throws SAXException {
 150  45
                         MetaColumn retVal = null;
 151  45
                         if ((retVal = getMetaColumnByPDMColId(id)) == null) {
 152  
                                 // IT DOESN'T EXIST. Creating ...
 153  18
                                 int len = 0, prec = 0;
 154  
                                 try {
 155  18
                                         len = Integer.parseInt(this.length);
 156  2
                                 } catch (NumberFormatException nfe) {
 157  16
                                 }
 158  
                                 try {
 159  18
                                         prec = Integer.parseInt(this.precision);
 160  17
                                 } catch (NumberFormatException nfe) {
 161  1
                                 }
 162  
 
 163  18
                                 String dataTypeName = new String(datatype);
 164  18
                                 int index = dataTypeName.indexOf("(");
 165  18
                                 if (index != -1)
 166  16
                                         dataTypeName = dataTypeName.substring(0, index);
 167  
 
 168  
                                 // String matchDT = datatype.
 169  18
                                 String jClassName = jClassResolver.getJClassName(dataTypeName
 170  
                                                 .trim(), len, prec);
 171  
 
 172  
                                 // Fk MetaColumn parent is temporarly set to null
 173  
                                 // it will be resolved later
 174  18
                                 MetaColumn fkMetaCol = null;
 175  
 
 176  18
                                 retVal = new MetaColumn(this.code, this.name, this.parentTable,
 177  
                                                 this.mandatory, fkMetaCol, jClassName, len, prec,
 178  
                                                 comment);
 179  18
                                 retVal.setDefaultVal(defaultVal);
 180  
                                 // list of values...
 181  18
                                 if (!"".equals(listOfVals)) {
 182  0
                                         String spEntries[] = listOfVals.split("\n");
 183  0
                                         for (int i = 0; i < spEntries.length; i++) {
 184  0
                                                 String spValueLabel[] = spEntries[i].trim().split("\t");
 185  0
                                                 retVal.put(spValueLabel[0].trim(), spValueLabel[1]
 186  
                                                                 .trim());
 187  
                                         }
 188  
                                 }
 189  
                                 try {
 190  18
                                         htCreatedMetaColumns_ID_MC.put(id, retVal);
 191  0
                                 } catch (Exception e) {
 192  
                                         // if (id == null || retVal == null)
 193  0
                                         throw new SAXException("Column already exists! id = " + id
 194  
                                                         + e.getMessage());
 195  18
                                 }
 196  
                         }
 197  45
                         return retVal;
 198  
                 }
 199  
         }
 200  
 
 201  38
         class PDMElement {
 202  
 
 203  38
                 protected String code = "";
 204  
 
 205  38
                 protected String comment = "";
 206  
 
 207  38
                 protected String id = "";
 208  
 
 209  38
                 protected String name = "";
 210  
 
 211  
         }
 212  
 
 213  5
         class PDMKey extends PDMElement {
 214  5
                 ArrayList<String> alColumns = new ArrayList<String>();
 215  
 
 216  
                 public void addCol(String aColId) {
 217  5
                         alColumns.add(aColId);
 218  5
                 }
 219  
 
 220  
                 public MetaKey createMetaKey(Hashtable<String, PDMElement> aIdResources)
 221  
                                 throws SAXException {
 222  5
                         MetaKey retVal = new MetaKey(name, code);
 223  5
                         Iterator<String> iKeyCols = alColumns.iterator();
 224  10
                         while (iKeyCols.hasNext()) {
 225  5
                                 String crntColId = iKeyCols.next();
 226  
                                 try {
 227  5
                                         PDMColumn col = (PDMColumn) aIdResources.get(crntColId);
 228  5
                                         retVal.addColumn(col.getCreateMetaColumn());
 229  0
                                 } catch (Exception e) {
 230  0
                                         logger.error("Can't find MetaColumn to add "
 231  
                                                         + "to MetaKey from id: " + crntColId + ". "
 232  
                                                         + e.getMessage());
 233  0
                                         throw new SAXException("PDML: " + e.getMessage());
 234  5
                                 }
 235  5
                         }
 236  5
                         return retVal;
 237  
                 }
 238  
         }
 239  
 
 240  1
         class PDMModel extends PDMElement {
 241  1
                 ArrayList<String> alTableIds = new ArrayList<String>();
 242  
 
 243  
                 protected void addTable(String aPDMTableId) throws SAXException {
 244  5
                         alTableIds.add(aPDMTableId);
 245  5
                 }
 246  
 
 247  
                 protected MetaModel createMetaModel(
 248  
                                 Hashtable<String, PDMElement> aIdResources) throws SAXException {
 249  1
                         MetaModel retVal = new MetaModel(code, name, comment);
 250  1
                         Iterator<String> iIdTables = alTableIds.iterator();
 251  6
                         while (iIdTables.hasNext()) {
 252  5
                                 String crntTableId = iIdTables.next();
 253  
                                 try {
 254  5
                                         PDMTable pdmTable = (PDMTable) aIdResources
 255  
                                                         .get(crntTableId);
 256  5
                                         retVal.addTable(pdmTable.createMetaTable(aIdResources));
 257  0
                                 } catch (Exception e) {
 258  0
                                         logger.error("Can't create MetaTable from id: "
 259  
                                                         + crntTableId + ". " + e.getMessage());
 260  0
                                         throw new SAXException("PDML: " + e.getMessage());
 261  5
                                 }
 262  5
                         }
 263  1
                         return retVal;
 264  
                 }
 265  
         }
 266  
 
 267  8
         class PDMReference extends PDMElement {
 268  
 
 269  4
                 private ArrayList<String> alRefJoins = new ArrayList<String>();
 270  
 
 271  4
                 String parentTableId = "";
 272  
 
 273  4
                 String sourceTableId = "";
 274  
 
 275  
                 public void addRefJoin(String aRefJoin) {
 276  4
                         alRefJoins.add(aRefJoin);
 277  4
                 }
 278  
 
 279  
                 public MetaReference createMetaReference(Hashtable aIdResources)
 280  
                                 throws SAXException {
 281  4
                         MetaReference retVal = new MetaReference(name, code);
 282  4
                         htCreatedRefs.put(id, retVal);
 283  
                         /*
 284  
                          * try{ retVal.setParentTable((MetaTable)
 285  
                          * htCreatedMetaTables.get(parentTableId));
 286  
                          * retVal.setSourceTable((MetaTable)
 287  
                          * htCreatedMetaTables.get(sourceTableId)); }catch(Exception e) {
 288  
                          * logger.error("Can't find parent MetaTable to add " + "to
 289  
                          * MetaReference id: " + parentTableId + ". " + e.getMessage());
 290  
                          * throw new SAXException("PDML: " + e.getMessage()); } Iterator
 291  
                          * iJoins = alRefJoins.iterator(); while (iJoins.hasNext()) { String
 292  
                          * currRefJoinId = (String) iJoins.next(); ReferenceJoin currRefJoin =
 293  
                          * (ReferenceJoin) aIdResources.get(currRefJoinId); try { MetaColumn
 294  
                          * col = getMetaColumnByPDMColId(currRefJoin.colId);
 295  
                          * retVal.addColumn(col); } catch (Exception e) {
 296  
                          * logger.error("Can't find MetaColumn to add " + "to MetaReference
 297  
                          * from id: " + currRefJoin.colId + ". " + e.getMessage()); throw
 298  
                          * new SAXException("PDML: " + e.getMessage()); } }
 299  
                          */
 300  4
                         return retVal;
 301  
                 }
 302  
         }
 303  
 
 304  1
         class PDMShortcut extends PDMElement {
 305  
         }
 306  
 
 307  5
         class PDMTable extends PDMElement {
 308  5
                 private ArrayList<String> alColumns = new ArrayList<String>();
 309  
 
 310  5
                 private ArrayList<String> alKeys = new ArrayList<String>();
 311  
 
 312  5
                 private ArrayList<String> alRefs = new ArrayList<String>();
 313  
 
 314  5
                 protected String comment = "";
 315  
 
 316  
                 protected void addCol(String aColId) throws SAXException {
 317  18
                         alColumns.add(aColId);
 318  18
                 }
 319  
 
 320  
                 public void addKey(String aKeyId) {
 321  5
                         alKeys.add(aKeyId);
 322  5
                 }
 323  
 
 324  
                 public void addRef(String aRefId) {
 325  4
                         alRefs.add(aRefId);
 326  4
                 }
 327  
 
 328  
                 protected MetaTable createMetaTable(
 329  
                                 Hashtable<String, PDMElement> aIdResources) throws SAXException {
 330  5
                         MetaTable retVal = new MetaTable(code, name, comment);
 331  5
                         htCreatedTables.put(id, retVal);
 332  5
                         htCreatedTablesByCode.put(code, retVal);
 333  
                         // create/add MetaKeys
 334  5
                         Iterator<String> iKeys = alKeys.iterator();
 335  10
                         while (iKeys.hasNext()) {
 336  5
                                 String crntPDMKeyId = (String) iKeys.next();
 337  
                                 try {
 338  5
                                         PDMKey crntPDMKey = (PDMKey) aIdResources.get(crntPDMKeyId);
 339  5
                                         retVal.addKey(crntPDMKey.createMetaKey(aIdResources));
 340  0
                                 } catch (Exception e) {
 341  0
                                         logger.error("Can't create MetaKey from id: "
 342  
                                                         + crntPDMKeyId + ". " + e.getMessage());
 343  0
                                         throw new SAXException("PDML: " + e.getMessage());
 344  5
                                 }
 345  5
                         }
 346  
 
 347  
                         // create/add References
 348  5
                         Iterator<String> iRefs = alRefs.iterator();
 349  9
                         while (iRefs.hasNext()) {
 350  4
                                 String currRefId = (String) iRefs.next();
 351  4
                                 PDMReference currRef = (PDMReference) aIdResources
 352  
                                                 .get(currRefId);
 353  
                                 try {
 354  4
                                         retVal.addRef(currRef.createMetaReference(aIdResources));
 355  0
                                 } catch (Exception e) {
 356  0
                                         logger.error("Can't create MetaReference from id: "
 357  
                                                         + currRefId + ". " + e.getMessage());
 358  0
                                         throw new SAXException("PDML: " + e.getMessage());
 359  4
                                 }
 360  4
                         }
 361  
 
 362  
                         // create/add MetaColumns
 363  5
                         Iterator<String> iIdColumns = alColumns.iterator();
 364  23
                         while (iIdColumns.hasNext()) {
 365  
                                 try {
 366  18
                                         String crntColId = (String) iIdColumns.next();
 367  18
                                         PDMColumn pdmCol = (PDMColumn) aIdResources.get(crntColId);
 368  18
                                         retVal.addCol(pdmCol.getCreateMetaColumn());
 369  0
                                 } catch (Exception e) {
 370  18
                                 }
 371  
                         }
 372  
 
 373  5
                         return retVal;
 374  
                 }
 375  
 
 376  
                 public Iterator elements() {
 377  0
                         return alColumns.iterator();
 378  
                 }
 379  
 
 380  
         }
 381  
 
 382  4
         class ReferenceJoin extends PDMElement {
 383  
 
 384  4
                 String colId = "";
 385  
 
 386  4
                 String fkParentColId = "";
 387  
 
 388  
                 public void join(Hashtable<String, PDMElement> aIdResources)
 389  
                                 throws SAXException {
 390  
                         try {
 391  4
                                 PDMColumn pdmCol = (PDMColumn) aIdResources.get(colId);
 392  4
                                 PDMColumn pdmFkCol = (PDMColumn) aIdResources
 393  
                                                 .get(fkParentColId);
 394  4
                                 pdmCol.fkParent = pdmFkCol;
 395  0
                         } catch (Exception e) {
 396  0
                                 logger.error("ReferenceJoin: Columns(" + colId + ", "
 397  
                                                 + fkParentColId);
 398  0
                                 throw new SAXException("PDML: id=" + colId + e.getMessage());
 399  4
                         }
 400  4
                 }
 401  
         }
 402  
 
 403  
         /**
 404  
          * PD's <o:Object Attr="o123"> Object :=
 405  
          * {Model|Table|Column|RefernceJoin|Key} Attr := {Id|Ref}
 406  
          */
 407  
         class XmlElem {
 408  
 
 409  
                 public final static String A_CODE = "a:Code";
 410  
 
 411  
                 public final static String A_COMMENT = "a:Comment";
 412  
 
 413  
                 public final static String A_DATATYPE = "a:DataType";
 414  
 
 415  
                 public final static String A_DEFAULT = "a:DefaultValue";
 416  
 
 417  
                 public final static String A_DESCRIPTION = "a:Description";
 418  
 
 419  
                 public final static String A_LENGTH = "a:Length";
 420  
 
 421  
                 public final static String A_LISTOFVALS = "a:ListOfValues";
 422  
 
 423  
                 public final static String A_MANDATORY = "a:Mandatory";
 424  
 
 425  
                 public final static String A_NAME = "a:Name";
 426  
 
 427  
                 public final static String A_PRECISION = "a:Precision";
 428  
 
 429  
                 public final static String C_CHILD_TABLE = "c:ChildTable";
 430  
 
 431  
                 public final static String C_COLUMNS = "c:Columns";
 432  
 
 433  
                 public final static String C_KEY_COLUMNS = "c:Key.Columns";
 434  
 
 435  
                 public final static String C_KEYS = "c:Keys";
 436  
 
 437  
                 public final static String C_OBJECT_1 = "c:Object1";
 438  
 
 439  
                 public final static String C_OBJECT_2 = "c:Object2";
 440  
 
 441  
                 public final static String C_PARENT_TABLE = "c:ParentTable";
 442  
 
 443  
                 public final static String C_REFERENCES = "c:References";
 444  
 
 445  
                 public final static String C_TABLES = "c:Tables";
 446  
 
 447  
                 public final static String O_COLUMN = "o:Column";
 448  
 
 449  
                 public final static String O_KEY = "o:Key";
 450  
 
 451  
                 public final static String O_MODEL = "o:Model";
 452  
 
 453  
                 public final static String O_REFERECE_JOIN = "o:ReferenceJoin";
 454  
 
 455  
                 public final static String O_REFERENCE = "o:Reference";
 456  
 
 457  
                 public final static String O_SHORTCUT = "o:Shortcut";
 458  
 
 459  
                 public final static String O_TABLE = "o:Table";
 460  
 
 461  199
                 protected String id = null;
 462  
 
 463  199
                 protected PDMElement pdmElement = null;
 464  
 
 465  199
                 protected String qName = null;
 466  
 
 467  199
                 public XmlElem(String aQName, String aId, PDMElement aPDMElement) {
 468  199
                         qName = aQName;
 469  199
                         id = aId;
 470  199
                         pdmElement = aPDMElement;
 471  199
                 }
 472  
 
 473  
                 public boolean isACode() {
 474  506
                         return A_CODE.equals(qName);
 475  
                 }
 476  
 
 477  
                 public boolean isAComment() {
 478  466
                         return A_COMMENT.equals(qName);
 479  
                 }
 480  
 
 481  
                 public boolean isADataType() {
 482  466
                         return A_DATATYPE.equals(qName);
 483  
                 }
 484  
 
 485  
                 public boolean isADefaultVal() {
 486  472
                         return A_DEFAULT.equals(qName);
 487  
                 }
 488  
 
 489  
                 public boolean isADescription() {
 490  472
                         return A_DESCRIPTION.equals(qName);
 491  
                 }
 492  
 
 493  
                 public boolean isALength() {
 494  448
                         return A_LENGTH.equals(qName);
 495  
                 }
 496  
 
 497  
                 public boolean isAListOfVals() {
 498  472
                         return A_LISTOFVALS.equals(qName);
 499  
                 }
 500  
 
 501  
                 public boolean isAMandatory() {
 502  472
                         return A_MANDATORY.equals(qName);
 503  
                 }
 504  
 
 505  
                 public boolean isAName() {
 506  540
                         return A_NAME.equals(qName);
 507  
                 }
 508  
 
 509  
                 public boolean isAPrecision() {
 510  432
                         return A_PRECISION.equals(qName);
 511  
                 }
 512  
 
 513  
                 public boolean isCChildTable() {
 514  4
                         return C_CHILD_TABLE.equals(qName);
 515  
                 }
 516  
 
 517  
                 public boolean isCColumns() {
 518  31
                         return C_COLUMNS.equals(qName);
 519  
                 }
 520  
 
 521  
                 public boolean isCKeyColumns() {
 522  13
                         return C_KEY_COLUMNS.equals(qName);
 523  
                 }
 524  
 
 525  
                 public boolean isCKeys() {
 526  5
                         return C_KEYS.equals(qName);
 527  
                 }
 528  
 
 529  
                 public boolean isCObject1() {
 530  8
                         return C_OBJECT_1.equals(qName);
 531  
                 }
 532  
 
 533  
                 public boolean isCObject2() {
 534  4
                         return C_OBJECT_2.equals(qName);
 535  
                 }
 536  
 
 537  
                 public boolean isCReferences() {
 538  4
                         return C_REFERENCES.equals(qName);
 539  
                 }
 540  
 
 541  
                 public boolean isCTables() {
 542  13
                         return C_TABLES.equals(qName);
 543  
                 }
 544  
 
 545  
                 public boolean isOColumn() {
 546  109
                         return pdmElement instanceof PDMColumn;
 547  
                 }
 548  
 
 549  
                 public boolean isOKey() {
 550  32
                         return O_KEY.equals(qName);
 551  
                 }
 552  
 
 553  
                 public boolean isOModel() {
 554  12
                         return pdmElement instanceof PDMModel;
 555  
                 }
 556  
 
 557  
                 public boolean isOReference() {
 558  18
                         return O_REFERENCE.equals(qName);
 559  
                 }
 560  
 
 561  
                 public boolean isCParentTable() {
 562  8
                         return C_PARENT_TABLE.equals(qName);
 563  
                 }
 564  
 
 565  
                 public boolean isOReferenceJoin() {
 566  8
                         return O_REFERECE_JOIN.equals(qName);
 567  
                 }
 568  
 
 569  
                 public boolean isOShortcut() {
 570  1
                         return O_SHORTCUT.equals(qName);
 571  
                 }
 572  
 
 573  
                 // public boolean isPackage() {
 574  
                 // return objType == OT_PACKAGE;
 575  
                 // }
 576  
 
 577  
                 public boolean isOTable() {
 578  22
                         return pdmElement instanceof PDMTable;
 579  
                 }
 580  
 
 581  
         }
 582  
 
 583  
         /**
 584  
          * Handles SAX2 events
 585  
          */
 586  
 
 587  1
         class XmlHandlerDelegate extends DefaultHandler {
 588  1
                 PDMColumn actualColumn = null;
 589  
 
 590  1
                 PDMKey actualKey = null;
 591  
 
 592  1
                 PDMReference actualRef = null;
 593  
 
 594  1
                 ReferenceJoin actualRJ = null;
 595  
 
 596  1
                 PDMShortcut actualShortcut = null;
 597  
 
 598  1
                 PDMTable actualTable = null;
 599  
 
 600  1
                 XmlElem actualXE = null;
 601  
 
 602  1
                 HT_ID_XOE htId_XE = new HT_ID_XOE(INIT_HT_CAP);
 603  
 
 604  1
                 XmlElem prevActualXE = null;
 605  
 
 606  1
                 ActualRefStack stkActualRef = new ActualRefStack();
 607  
 
 608  1
                 ActualXEStack stkActualXE = new ActualXEStack();
 609  
 
 610  
                 /**
 611  
                  * @see org.xml.sax.ContentHandler#characters(char[], int, int)
 612  
                  */
 613  
                 public void characters(char[] ch, int start, int length)
 614  
                                 throws SAXException {
 615  2240
                         String sCh = (new String(ch, start, length));
 616  2240
                         XmlElem actualXE = null;
 617  2240
                         XmlElem prevActualXE = null;
 618  
                         try {
 619  2240
                                 actualXE = stkActualXE.peek();
 620  2240
                                 prevActualXE = stkActualXE.underPeek();
 621  2
                         } catch (EmptyStackException ese) {
 622  2
                                 return;
 623  2238
                         }
 624  
                         try {
 625  2238
                                 actualRef = stkActualRef.peek();
 626  2038
                         } catch (EmptyStackException ese) {
 627  200
                         }
 628  
 
 629  2238
                         if (prevActualXE == null || actualXE == null)
 630  1698
                                 return;
 631  
 
 632  
                         // ok ...
 633  540
                         if (actualXE.isAName()) {
 634  
                                 // ________________________________________________________A_NAME
 635  34
                                 if (prevActualXE.isOColumn()) {
 636  18
                                         actualColumn.name += sCh;
 637  16
                                 } else if (prevActualXE.isOKey()) {
 638  5
                                         actualKey.name += sCh;
 639  11
                                 } else if (prevActualXE.isOTable()) {
 640  5
                                         actualTable.name += sCh;
 641  6
                                 } else if (prevActualXE.isOModel()) {
 642  1
                                         actualMModel.name += sCh;
 643  5
                                 } else if (prevActualXE.isOReference()) {
 644  4
                                         actualRef.name += sCh;
 645  
                                 } 
 646  506
                         } else if (actualXE.isACode()) {
 647  
                                 // ________________________________________________________A_CODE
 648  34
                                 if (prevActualXE.isOColumn()) {
 649  18
                                         actualColumn.code += sCh;
 650  16
                                 } else if (prevActualXE.isOKey()) {
 651  5
                                         actualKey.code += sCh;
 652  11
                                 } else if (prevActualXE.isOTable()) {
 653  5
                                         actualTable.code += sCh;
 654  6
                                 } else if (prevActualXE.isOModel()) {
 655  1
                                         actualMModel.code += sCh;
 656  5
                                 } else if (prevActualXE.isOReference()) {
 657  4
                                         actualRef.code += sCh;
 658  1
                                 } else if (prevActualXE.isOShortcut()) {
 659  1
                                         actualShortcut.code += sCh;
 660  
                                 }
 661  472
                         } else if (actualXE.isADefaultVal()) {
 662  
                                 // _____________________________________________________A_DEFAULT
 663  0
                                 if (prevActualXE.isOColumn()) {
 664  0
                                         actualColumn.defaultVal += sCh;
 665  
                                 }
 666  472
                         } else if (actualXE.isADescription()) {
 667  
                                 // _________________________________________________A_DESCRIPTION
 668  0
                                 if (prevActualXE.isOTable()) {
 669  0
                                         actualTable.comment += sCh;
 670  0
                                 } else if (prevActualXE.isOModel()) {
 671  0
                                         actualMModel.comment += sCh;
 672  
                                 }
 673  472
                         } else if (actualXE.isAListOfVals()) {
 674  
                                 // __________________________________________________A_LISTOFVALS
 675  0
                                 if (prevActualXE.isOColumn()) {
 676  0
                                         actualColumn.listOfVals += sCh;
 677  
                                 }
 678  472
                         } else if (actualXE.isAMandatory()) {
 679  
                                 // ___________________________________________________A_MANDATORY
 680  6
                                 if (prevActualXE.isOColumn()) {
 681  6
                                         actualColumn.mandatory = ("1".equals(sCh));
 682  
                                 }
 683  466
                         } else if (actualXE.isAComment()) {
 684  
                                 // _____________________________________________________A_COMMENT
 685  0
                                 if (prevActualXE.isOColumn()) {
 686  0
                                         actualColumn.comment += sCh;
 687  0
                                 } else if (prevActualXE.isOTable()) {
 688  0
                                         actualTable.comment += sCh;
 689  0
                                 } else if (prevActualXE.isOModel()) {
 690  0
                                         actualMModel.comment += sCh;
 691  
                                 }
 692  466
                         } else if (actualXE.isADataType()) {
 693  
                                 // ____________________________________________________A_DATATYPE
 694  18
                                 if (prevActualXE.isOColumn()) {
 695  18
                                         actualColumn.datatype += sCh;
 696  
                                 }
 697  448
                         } else if (actualXE.isALength()) {
 698  
                                 // ______________________________________________________A_LENGTH
 699  16
                                 if (prevActualXE.isOColumn()) {
 700  16
                                         actualColumn.length += sCh;
 701  
                                 }
 702  432
                         } else if (actualXE.isAPrecision()) {
 703  
                                 // ___________________________________________________A_PRECISION
 704  1
                                 if (prevActualXE.isOColumn()) {
 705  1
                                         actualColumn.precision += sCh;
 706  
                                 }
 707  
                         }
 708  540
                 }
 709  
 
 710  
                 /**
 711  
                  * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
 712  
                  *      java.lang.String, java.lang.String)
 713  
                  */
 714  
                 public void endElement(String uri, String localName, String qName)
 715  
                                 throws SAXException {
 716  603
                         if (qName.equals(XmlElem.A_CODE)) {
 717  
                                 // In case of shortcut
 718  37
                                 if (actualShortcut != null) {
 719  1
                                         htShortcuts.put(actualShortcut.id, actualShortcut);
 720  
                                 }
 721  566
                         } else if (qName.equals(XmlElem.O_COLUMN)) {
 722  31
                                 actualColumn = null;
 723  535
                         } else if (qName.equals(XmlElem.C_KEY_COLUMNS)) {
 724  530
                         } else if (qName.equals(XmlElem.O_REFERECE_JOIN)) {
 725  4
                                 actualRJ = null;
 726  526
                         } else if (qName.equals(XmlElem.O_REFERENCE)) {
 727  
                                 try {
 728  8
                                         stkActualRef.pop();
 729  0
                                 } catch (EmptyStackException e) {
 730  0
                                         logger
 731  
                                                         .error("Invalid pdm file! Unbalanced Reference tags!");
 732  0
                                         throw new SAXException(
 733  
                                                         "Invalid pdm file! Unbalanced Reference tags!");
 734  8
                                 }
 735  518
                         } else if (qName.equals(XmlElem.O_SHORTCUT)) {
 736  2
                                 actualShortcut = null;
 737  516
                         } else if (qName.equals(XmlElem.O_KEY)) {
 738  14
                                 actualKey = null;
 739  502
                         } else if (qName.equals(XmlElem.C_COLUMNS)) {
 740  497
                         } else if (qName.equals(XmlElem.O_TABLE)) {
 741  18
                                 actualTable = null;
 742  479
                         } else if (qName.equals(XmlElem.C_TABLES)) {
 743  478
                         } else if (qName.equals(XmlElem.O_MODEL)) {
 744  
                         }
 745  
                         try {
 746  603
                                 stkActualXE.pop();
 747  0
                         } catch (EmptyStackException ese) {
 748  
                                 // do nothing
 749  603
                         }
 750  603
                 }
 751  
 
 752  
                 /**
 753  
                  * @see org.xml.sax.ContentHandler#startDocument()
 754  
                  */
 755  
                 public void startDocument() throws SAXException {
 756  1
                 }
 757  
 
 758  
                 /**
 759  
                  * @see org.xml.sax.ContentHandler#startElement(java.lang.String,
 760  
                  *      java.lang.String, java.lang.String, org.xml.sax.Attributes)
 761  
                  */
 762  
                 public void startElement(String uri, String localName, String qName,
 763  
                                 Attributes attributes) throws SAXException {
 764  
                         try {
 765  603
                                 prevActualXE = stkActualXE.peek();
 766  1
                         } catch (EmptyStackException e) {
 767  1
                                 prevActualXE = null;
 768  602
                         }
 769  603
                         actualXE = null;
 770  603
                         String id = attributes.getValue("Id");
 771  603
                         String ref = attributes.getValue("Ref");
 772  
 
 773  
                         // CASE ELEMENT
 774  
 
 775  603
                         if (qName.equals(XmlElem.A_NAME)) {
 776  
                                 // ________________________________________________________A_NAME
 777  37
                                 actualXE = new XmlElem(qName, null, null);
 778  566
                         } else if (qName.equals(XmlElem.A_CODE)) {
 779  
                                 // ________________________________________________________A_CODE
 780  37
                                 actualXE = new XmlElem(qName, null, null);
 781  529
                         } else if (qName.equals(XmlElem.A_DEFAULT)) {
 782  
                                 // _____________________________________________________A_DEFAULT
 783  0
                                 actualXE = new XmlElem(qName, null, null);
 784  529
                         } else if (qName.equals(XmlElem.A_DESCRIPTION)) {
 785  
                                 // _________________________________________________A_DESCRIPTION
 786  0
                                 actualXE = new XmlElem(qName, null, null);
 787  529
                         } else if (qName.equals(XmlElem.A_LISTOFVALS)) {
 788  
                                 // __________________________________________________A_LISTOFVALS
 789  0
                                 actualXE = new XmlElem(qName, null, null);
 790  529
                         } else if (qName.equals(XmlElem.A_MANDATORY)) {
 791  
                                 // ___________________________________________________A_MANDATORY
 792  6
                                 actualXE = new XmlElem(qName, null, null);
 793  523
                         } else if (qName.equals(XmlElem.A_COMMENT)) {
 794  
                                 // _____________________________________________________A_COMMENT
 795  0
                                 actualXE = new XmlElem(qName, null, null);
 796  523
                         } else if (qName.equals(XmlElem.A_DATATYPE)) {
 797  
                                 // ____________________________________________________A_DATATYPE
 798  18
                                 actualXE = new XmlElem(qName, null, null);
 799  505
                         } else if (qName.equals(XmlElem.A_LENGTH)) {
 800  
                                 // ______________________________________________________A_LENGTH
 801  16
                                 actualXE = new XmlElem(qName, null, null);
 802  
 
 803  489
                         } else if (qName.equals(XmlElem.A_PRECISION)) {
 804  
                                 // ___________________________________________________A_PRECISION
 805  1
                                 actualXE = new XmlElem(qName, null, null);
 806  488
                         } else if (qName.equals(XmlElem.O_COLUMN)) {
 807  
                                 // ______________________________________________________O_COLUMN
 808  31
                                 String colIdToAdd = null;
 809  31
                                 if (id != null) {
 810  18
                                         PDMColumn newCol = new PDMColumn();
 811  18
                                         newCol.id = id;
 812  18
                                         colIdToAdd = id;
 813  18
                                         actualXE = new XmlElem(qName, id, newCol);
 814  18
                                         htId_PDMObject.put(id, newCol);
 815  18
                                         htId_XE.put(id, actualXE);
 816  18
                                         actualColumn = newCol;
 817  18
                                 } else if (ref != null) {
 818  13
                                         colIdToAdd = ref;
 819  
                                 }
 820  31
                                 if (colIdToAdd != null && prevActualXE != null) {
 821  31
                                         XmlElem prevPrevActualXE = null;
 822  
                                         try {
 823  31
                                                 prevPrevActualXE = stkActualXE.underPeek();
 824  0
                                         } catch (EmptyStackException ese) {
 825  31
                                         }
 826  
                                         // Ok, detecting context of <o:column>
 827  31
                                         if (prevActualXE.isCColumns()) {
 828  
                                                 try {
 829  18
                                                         actualTable.addCol(colIdToAdd);
 830  0
                                                 } catch (NullPointerException npe) {
 831  0
                                                         logger.error(npe.getMessage());
 832  0
                                                         throw new SAXException("PDML: Can't add column to "
 833  
                                                                         + "null table - actualTable == null");
 834  18
                                                 }
 835  13
                                         } else if (prevActualXE.isCKeyColumns()) {
 836  5
                                                 if (actualKey == null) {
 837  0
                                                         logger
 838  
                                                                         .error("Can't initialize actualKey - it is null!");
 839  0
                                                         throw new SAXException(
 840  
                                                                         "PDML: Can't initialize actualKey - it is null!");
 841  
                                                 }
 842  5
                                                 actualKey.addCol(colIdToAdd);
 843  8
                                         } else if (prevActualXE.isCObject1()) {
 844  4
                                                 if (actualRJ == null || prevPrevActualXE == null
 845  
                                                                 || !prevPrevActualXE.isOReferenceJoin()) {
 846  0
                                                         logger
 847  
                                                                         .error("actualRJ is null or this is not "
 848  
                                                                                         + "a context of ReferenceJoin/Object1/Columns");
 849  0
                                                         throw new SAXException(
 850  
                                                                         "PDML: actualRJ is null or this is not "
 851  
                                                                                         + "a context of ReferenceJoin/Object1/Column");
 852  
                                                 }
 853  4
                                                 actualRJ.fkParentColId = colIdToAdd;
 854  4
                                         } else if (prevActualXE.isCObject2()) {
 855  4
                                                 if (actualRJ == null || prevPrevActualXE == null
 856  
                                                                 || !prevPrevActualXE.isOReferenceJoin()) {
 857  0
                                                         logger
 858  
                                                                         .error("actualRJ is null or this is not "
 859  
                                                                                         + "a context of ReferenceJoin/Object2/Column");
 860  0
                                                         throw new SAXException(
 861  
                                                                         "PDML: actualRJ is null or this is not "
 862  
                                                                                         + "a context of ReferenceJoin/Object2/Column");
 863  
                                                 }
 864  4
                                                 actualRJ.colId = colIdToAdd;
 865  
                                         }
 866  
                                 }
 867  31
                         } else if (qName.equals(XmlElem.C_OBJECT_1)) {
 868  4
                                 actualXE = new XmlElem(qName, null, null);
 869  453
                         } else if (qName.equals(XmlElem.C_CHILD_TABLE)) {
 870  4
                                 actualXE = new XmlElem(qName, null, null);
 871  449
                         } else if (qName.equals(XmlElem.C_PARENT_TABLE)) {
 872  4
                                 actualXE = new XmlElem(qName, null, null);
 873  445
                         } else if (qName.equals(XmlElem.C_OBJECT_1)) {
 874  0
                                 actualXE = new XmlElem(qName, null, null);
 875  445
                         } else if (qName.equals(XmlElem.C_OBJECT_2)) {
 876  4
                                 actualXE = new XmlElem(qName, null, null);
 877  441
                         } else if (qName.equals(XmlElem.C_KEY_COLUMNS)) {
 878  5
                                 actualXE = new XmlElem(qName, null, null);
 879  436
                         } else if (qName.equals(XmlElem.C_REFERENCES)) {
 880  1
                                 actualXE = new XmlElem(qName, null, null);
 881  435
                         } else if (qName.equals(XmlElem.O_REFERENCE)) {
 882  8
                                 String RefIdToAdd = null;
 883  8
                                 if (id != null) {
 884  4
                                         actualRef = new PDMReference();
 885  4
                                         actualRef.id = id;
 886  4
                                         RefIdToAdd = id;
 887  4
                                         htId_PDMObject.put(id, actualRef);
 888  4
                                 } else if (ref != null) {
 889  4
                                         RefIdToAdd = ref;
 890  4
                                         actualRef = (PDMReference) htId_PDMObject.get(ref);
 891  
                                 }
 892  8
                                 stkActualRef.push(actualRef);
 893  8
                                 actualXE = new XmlElem(qName, id, actualRef);
 894  
 
 895  8
                                 if (RefIdToAdd != null && prevActualXE != null
 896  
                                                 && prevActualXE.isCReferences()) {
 897  
                                         try {
 898  4
                                                 alReferences.add(RefIdToAdd);
 899  0
                                         } catch (Exception e) {
 900  
                                                 // logger.error("alReference is null!");
 901  0
                                                 throw new SAXException("PDML: alReference is null!");
 902  4
                                         }
 903  
 
 904  
                                 }
 905  
 
 906  8
                         } else if (qName.equals(XmlElem.O_REFERECE_JOIN)) {
 907  
                                 // _______________________________________________O_REFERECE_JOIN
 908  4
                                 if (id != null) {
 909  
                                         // String refJoinIdToAdd = id;
 910  4
                                         actualRJ = new ReferenceJoin();
 911  4
                                         actualXE = new XmlElem(qName, id, actualRJ);
 912  4
                                         htId_PDMObject.put(id, actualRJ);
 913  4
                                         alJoins.add(actualRJ);
 914  
                                 } else {
 915  
                                         // logger.error("ReferenceJoin without Id");
 916  0
                                         throw new SAXException("PDML: ReferenceJoin without Id");
 917  
                                 }
 918  
 
 919  4
                                 actualRef = null;
 920  
                                 try {
 921  4
                                         actualRef = stkActualRef.peek();
 922  0
                                 } catch (EmptyStackException e) {
 923  4
                                 }
 924  
 
 925  4
                                 if (actualRef != null) {
 926  4
                                         actualRef.addRefJoin(id);
 927  
 
 928  
                                 } else {
 929  
                                         // logger.error("ReferenceJoin without Reference");
 930  0
                                         throw new SAXException(
 931  
                                                         "PDML: ReferenceJoin without Reference");
 932  
                                 }
 933  423
                         } else if (qName.equals(XmlElem.O_KEY)) {
 934  
                                 // _________________________________________________________O_KEY
 935  14
                                 String keyIdToAdd = null;
 936  14
                                 if (id != null) {
 937  5
                                         actualKey = new PDMKey();
 938  5
                                         actualKey.id = id;
 939  5
                                         htId_PDMObject.put(id, actualKey);
 940  5
                                         keyIdToAdd = id;
 941  9
                                 } else if (ref != null) {
 942  9
                                         keyIdToAdd = ref;
 943  
                                 }
 944  14
                                 actualXE = new XmlElem(qName, null, null);
 945  14
                                 if (keyIdToAdd != null && prevActualXE != null
 946  
                                                 && prevActualXE.isCKeys()) {
 947  5
                                         if (actualTable == null) {
 948  
                                                 // logger
 949  
                                                 // .error("c:Keys section must be declared within the "
 950  
                                                 // + "o:Table section. id = " + keyIdToAdd);
 951  0
                                                 throw new SAXException(
 952  
                                                                 "c:Keys section must be declared within the "
 953  
                                                                                 + "o:Table section. id = " + keyIdToAdd);
 954  
                                         }
 955  5
                                         actualTable.addKey(keyIdToAdd);
 956  
                                 }
 957  14
                         } else if (qName.equals(XmlElem.C_KEYS)) {
 958  
                                 // ________________________________________________________C_KEYS
 959  5
                                 actualXE = new XmlElem(qName, null, null);
 960  404
                         } else if (qName.equals(XmlElem.C_COLUMNS)) {
 961  
                                 // _____________________________________________________C_COLUMNS
 962  5
                                 actualXE = new XmlElem(qName, null, null);
 963  399
                         } else if (qName.equals(XmlElem.O_TABLE)
 964  
                                         || qName.equals(XmlElem.O_SHORTCUT)) {
 965  
                                 // _______________________________________________________O_TABLE
 966  20
                                 String tableIdToAdd = null;
 967  20
                                 if (id != null) {
 968  6
                                         tableIdToAdd = id;
 969  6
                                         if (!qName.equals(XmlElem.O_SHORTCUT)) {
 970  5
                                                 PDMTable pdmTableToAdd = new PDMTable();
 971  5
                                                 pdmTableToAdd.id = id;
 972  5
                                                 actualXE = new XmlElem(qName, id, pdmTableToAdd);
 973  5
                                                 htId_XE.put(id, actualXE);
 974  5
                                                 actualTable = pdmTableToAdd;
 975  5
                                                 htId_PDMObject.put(id, actualTable);
 976  5
                                         } else {
 977  1
                                                 actualShortcut = new PDMShortcut();
 978  1
                                                 actualShortcut.id = id;
 979  1
                                                 actualXE = new XmlElem(qName, id, actualShortcut);
 980  1
                                                 htId_XE.put(id, actualXE);
 981  
                                         }
 982  14
                                 } else if (ref != null) {
 983  14
                                         tableIdToAdd = ref;
 984  14
                                         actualXE = htId_XE.get(ref);
 985  
                                 }
 986  20
                                 if (tableIdToAdd != null && prevActualXE != null) {
 987  13
                                         XmlElem prevPrevActualXE = null;
 988  
                                         try {
 989  13
                                                 prevPrevActualXE = stkActualXE.underPeek();
 990  0
                                         } catch (EmptyStackException ese) {
 991  13
                                         }
 992  
                                         try {
 993  13
                                                 actualRef = stkActualRef.peek();
 994  5
                                         } catch (EmptyStackException ese) {
 995  8
                                         }
 996  
                                         // Detecting context of <o:Table>
 997  13
                                         if (prevActualXE.isCTables()
 998  
                                                         && !qName.equals(XmlElem.O_SHORTCUT)) {
 999  
                                                 try {
 1000  5
                                                         actualMModel.addTable(tableIdToAdd);
 1001  0
                                                 } catch (NullPointerException npe) {
 1002  
                                                         // logger.error(npe.getMessage());
 1003  0
                                                         throw new SAXException("PDML: Can't add table to "
 1004  
                                                                         + "null MetaModel - actualMModel == null");
 1005  5
                                                 }
 1006  8
                                         } else if (prevActualXE.isCParentTable()) {
 1007  4
                                                 if (actualRef == null || prevPrevActualXE == null
 1008  
                                                                 || !prevPrevActualXE.isOReference()) {
 1009  
                                                         // logger.error("actualRef is null or this is not "
 1010  
                                                         // + "a context of Reference/Object1/Table");
 1011  0
                                                         throw new SAXException(
 1012  
                                                                         "PDML: actualRef is null or this is not "
 1013  
                                                                                         + "a context of Reference/Object1/Table");
 1014  
                                                 }
 1015  4
                                                 actualRef.parentTableId = tableIdToAdd;
 1016  4
                                         } else if (prevActualXE.isCChildTable()) {
 1017  4
                                                 if (actualRef == null || prevPrevActualXE == null
 1018  
                                                                 || !prevPrevActualXE.isOReference()) {
 1019  
                                                         // logger
 1020  
                                                         // .error("actualRef is null or this is not "
 1021  
                                                         // + "a context of Reference/Object2/Table. RefId="
 1022  
                                                         // + tableIdToAdd);
 1023  0
                                                         throw new SAXException(
 1024  
                                                                         "PDML: actualRef is null or this is not "
 1025  
                                                                                         + "a context of Reference/Object2/Table. RefId="
 1026  
                                                                                         + tableIdToAdd);
 1027  
                                                 }
 1028  4
                                                 actualRef.sourceTableId = tableIdToAdd;
 1029  
                                         }
 1030  
                                 }
 1031  20
                         } else if (qName.equals(XmlElem.C_TABLES)) {
 1032  
                                 // ______________________________________________________C_TABLES
 1033  1
                                 actualXE = new XmlElem(qName, null, null);
 1034  378
                         } else if (qName.equals(XmlElem.O_MODEL)) {
 1035  
                                 // _______________________________________________________O_MODEL
 1036  1
                                 if (id != null && actualMModel == null) {
 1037  1
                                         actualMModel = new PDMModel();
 1038  1
                                         actualMModel.id = id;
 1039  1
                                         actualXE = new XmlElem(qName, id, actualMModel);
 1040  1
                                         htId_XE.put(id, actualXE);
 1041  
                                         
 1042  
                                 }
 1043  
                         }
 1044  603
                         stkActualXE.push(actualXE);
 1045  603
                 }
 1046  
         }
 1047  
 
 1048  
         private final static int INIT_HT_CAP = 500;
 1049  
 
 1050  
         public static final String FILENAME = "file";
 1051  
 
 1052  2
         protected PDMModel actualMModel = null;
 1053  
 
 1054  2
         private ArrayList<ReferenceJoin> alJoins = new ArrayList<ReferenceJoin>();
 1055  
 
 1056  2
         private ArrayList<String> alReferences = new ArrayList<String>();
 1057  
 
 1058  2
         protected Hashtable<String, MetaColumn> htCreatedMetaColumns_ID_MC = new Hashtable<String, MetaColumn>();
 1059  
 
 1060  2
         protected Hashtable<String, MetaReference> htCreatedRefs = new Hashtable<String, MetaReference>();
 1061  
 
 1062  2
         protected Hashtable<String, MetaTable> htCreatedTables = new Hashtable<String, MetaTable>();
 1063  
 
 1064  2
         protected Hashtable<String, MetaTable> htCreatedTablesByCode = new Hashtable<String, MetaTable>();
 1065  
 
 1066  2
         private final Hashtable<String, PDMElement> htId_PDMObject = new Hashtable<String, PDMElement>(
 1067  
                         5000);
 1068  
 
 1069  2
         protected Hashtable<String, PDMShortcut> htShortcuts = new Hashtable<String, PDMShortcut>();
 1070  
 
 1071  2
         private JClassResolver jClassResolver = null;
 1072  
 
 1073  2
         Logger logger = Logger.getLogger(PDMetaLoader.class);
 1074  
 
 1075  
         public PDMetaLoader() {
 1076  2
                 super();
 1077  2
                 jClassResolver = JClassResolver.getInstance();
 1078  2
         }
 1079  
 
 1080  
         public MetaColumn getMetaColumnByPDMColId(String aPDMColId) {
 1081  49
                 MetaColumn retVal = null;
 1082  
                 try {
 1083  49
                         retVal = (MetaColumn) htCreatedMetaColumns_ID_MC.get(aPDMColId);
 1084  0
                 } catch (Exception e) {
 1085  0
                         retVal = null;
 1086  49
                 }
 1087  49
                 return retVal;
 1088  
         }
 1089  
 
 1090  
         /**
 1091  
          * @param Configuration
 1092  
          *            properties of PDM. These are the mandatory properties:
 1093  
          *            <p>
 1094  
          *            <code><ul>
 1095  
          *                            <li>file</li>
 1096  
          *                    </ul></code>
 1097  
          *            </p>.
 1098  
          * 
 1099  
          * @see rs.mgifos.mosquito.IMetaLoader#getMetaModel(java.util.Properties)
 1100  
          */
 1101  
         public MetaModel getMetaModel(Properties config) throws LoadingException {
 1102  2
                 MetaModel retVal = null;
 1103  2
                 File file = new File(config.getProperty(FILENAME));
 1104  2
                 logger.info("Retrieving model from the file: " + file);
 1105  
 
 1106  2
                 if (!file.canRead())
 1107  1
                         throw new LoadingException("File is locked or it doesn't exist");
 1108  
                 try {
 1109  1
                         SAXParserFactory factory = SAXParserFactory.newInstance();
 1110  1
                         SAXParser saxParser = factory.newSAXParser();
 1111  
                         // logger.info("MODEL PARSING STARTED...");
 1112  1
                         saxParser.parse(file, new XmlHandlerDelegate());
 1113  
                         // resolve all PDMColumn fks
 1114  1
                         this.resolveAllPDMColFks();
 1115  
                         // resolve all PDMReferences
 1116  1
                         resolveAllPDMReferences();
 1117  1
                         retVal = actualMModel.createMetaModel(htId_PDMObject);
 1118  
                         // resolve all MetaColumn fks
 1119  1
                         this.resolveAllMetaColFks();
 1120  1
                         resolveAllMetaReferences();
 1121  1
                         htCreatedMetaColumns_ID_MC.clear();
 1122  1
                         htCreatedRefs.clear();
 1123  
                         // logger.info("DONE.");
 1124  0
                 } catch (FileNotFoundException fnfe) {
 1125  0
                         throw new LoadingException(fnfe);
 1126  0
                 } catch (IOException ioe) {
 1127  0
                         throw new LoadingException(ioe);
 1128  0
                 } catch (SAXException saxe) {
 1129  0
                         throw new LoadingException(saxe);
 1130  0
                 } catch (ParserConfigurationException pce) {
 1131  0
                         throw new LoadingException(pce);
 1132  1
                 }
 1133  1
                 return retVal;
 1134  
         }
 1135  
 
 1136  
         private void resolveAllMetaColFks() throws SAXException {
 1137  1
                 Enumeration<String> eColIds = htCreatedMetaColumns_ID_MC.keys();
 1138  19
                 while (eColIds.hasMoreElements()) {
 1139  18
                         String crntColId = eColIds.nextElement();
 1140  
                         try {
 1141  18
                                 PDMColumn pdmCol = (PDMColumn) htId_PDMObject.get(crntColId);
 1142  18
                                 MetaColumn metaCol = pdmCol.getCreateMetaColumn();
 1143  18
                                 MetaColumn fkMetaCol = pdmCol.fkParent.getCreateMetaColumn();
 1144  4
                                 metaCol.setFkColParent(fkMetaCol);
 1145  14
                         } catch (Exception e) {
 1146  4
                         }
 1147  18
                 }
 1148  1
         }
 1149  
 
 1150  
         private void resolveAllMetaReferences() throws SAXException {
 1151  1
                 Enumeration<String> eRefs = htCreatedRefs.keys();
 1152  5
                 while (eRefs.hasMoreElements()) {
 1153  4
                         String refId = (String) eRefs.nextElement();
 1154  
                         try {
 1155  4
                                 PDMReference currRef = (PDMReference) htId_PDMObject.get(refId);
 1156  
 
 1157  4
                                 MetaReference currMRef = (MetaReference) htCreatedRefs
 1158  
                                                 .get(refId);
 1159  4
                                 if (currMRef == null) {
 1160  0
                                         throw new SAXException("Reference not created!. RefId = "
 1161  
                                                         + refId);
 1162  
                                 }
 1163  4
                                 MetaTable srcTable = (MetaTable) htCreatedTables
 1164  
                                                 .get(currRef.sourceTableId);
 1165  4
                                 if (srcTable == null) {
 1166  0
                                         String srcTableCode = ((PDMShortcut) htShortcuts
 1167  
                                                         .get(currRef.sourceTableId)).code;
 1168  0
                                         srcTable = (MetaTable) htCreatedTablesByCode
 1169  
                                                         .get(srcTableCode);
 1170  
                                 }
 1171  4
                                 MetaTable parentTable = (MetaTable) htCreatedTables
 1172  
                                                 .get(currRef.parentTableId);
 1173  4
                                 if (parentTable == null) {
 1174  0
                                         String parentTableCode = ((PDMShortcut) htShortcuts
 1175  
                                                         .get(currRef.parentTableId)).code;
 1176  0
                                         parentTable = (MetaTable) htCreatedTablesByCode
 1177  
                                                         .get(parentTableCode);
 1178  
                                 }
 1179  4
                                 if (srcTable == null || parentTable == null) {
 1180  0
                                         throw new SAXException(
 1181  
                                                         "Invalid reference! Source or parent table is null. RefId = "
 1182  
                                                                         + refId);
 1183  
                                 }
 1184  4
                                 currMRef.setSourceTable(srcTable);
 1185  4
                                 currMRef.setParentTable(parentTable);
 1186  4
                                 Iterator<String> joins = currRef.alRefJoins.iterator();
 1187  8
                                 while (joins.hasNext()) {
 1188  4
                                         String joinId = (String) joins.next();
 1189  4
                                         ReferenceJoin join = (ReferenceJoin) htId_PDMObject
 1190  
                                                         .get(joinId);
 1191  4
                                         currMRef.addColumn(getMetaColumnByPDMColId(join.colId));
 1192  4
                                 }
 1193  0
                         } catch (Exception e) {
 1194  
                                 // logger.error(e.getMessage());
 1195  0
                                 throw new SAXException(e.getMessage());
 1196  4
                         }
 1197  4
                 }
 1198  1
         }
 1199  
 
 1200  
         private void resolveAllPDMColFks() throws SAXException {
 1201  1
                 Iterator<ReferenceJoin> iRJoins = alJoins.iterator();
 1202  5
                 while (iRJoins.hasNext()) {
 1203  4
                         ReferenceJoin rj = (ReferenceJoin) iRJoins.next();
 1204  4
                         rj.join(htId_PDMObject);
 1205  4
                 }
 1206  1
         }
 1207  
 
 1208  
         private void resolveAllPDMReferences() throws SAXException {
 1209  1
                 Iterator<String> itRefs = alReferences.iterator();
 1210  5
                 while (itRefs.hasNext()) {
 1211  4
                         String currPDMRefId = (String) itRefs.next();
 1212  4
                         PDMReference currPDMRef = (PDMReference) htId_PDMObject
 1213  
                                         .get(currPDMRefId);
 1214  4
                         PDMTable srcTbl = (PDMTable) htId_PDMObject
 1215  
                                         .get(currPDMRef.sourceTableId);
 1216  4
                         if (srcTbl != null) {
 1217  4
                                 srcTbl.addRef(currPDMRef.id);
 1218  
                         } else {
 1219  
                                 // logger
 1220  
                                 // .error("Invalid reference! Source table is null. RefId = "
 1221  
                                 // + currPDMRefId);
 1222  0
                                 throw new SAXException(
 1223  
                                                 "Invalid reference! Source table is null. RefId = "
 1224  
                                                                 + currPDMRefId);
 1225  
                         }
 1226  4
                 }
 1227  1
         }
 1228  
 }