001 /** 002 * Copyright (c) 2003 Daffodil Software Ltd all rights reserved, 003 * Modifications Copyright (c) 2008 Regiscope Digital Imaging Co, LLC, All rights reserved. 004 * This program is free software; you can redistribute it and/or modify 005 * it under the terms of version 2 of the GNU General Public License as 006 * published by the Free Software Foundation. 007 * There are special exceptions to the terms and conditions of the GPL 008 * as it is applied to this software. See the GNU General Public License for more details. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License 016 * along with this program; if not, write to the Free Software 017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018 */ 019 020 package org.dbreplicator.replication.xml; 021 022 import java.util.*; 023 import org.dbreplicator.replication.EncoderDecoder; 024 025 /** 026 * This class is the representation of the XML elements , written in the XML files. 027 * It stores different parameters of the XML element as it's value, attribute, parent 028 * element, child element etc. This all helps at the time of parsing. 029 * 030 */ 031 032 public class XMLElement 033 { 034 035 public String elementValue = ""; 036 public ArrayList elementList; 037 public String elementName; 038 public XMLElement parentElement; 039 String encodingAttValue; 040 String attValue; 041 // for each table its unique; 042 HashMap columnTypes; 043 044 public XMLElement(String elementName0) 045 { 046 elementList = new ArrayList(); 047 elementName = elementName0; 048 // System.out.println("XMLElement.XMLElement(elementName0) elementName ="+elementName); 049 } 050 051 public void addChild(XMLElement child) 052 { 053 elementList.add(child); 054 } 055 056 public void setParentElement(XMLElement parentElement0) 057 { 058 parentElement = parentElement0; 059 } 060 061 public XMLElement getParentElement() 062 { 063 return parentElement; 064 } 065 066 public ArrayList getChildElements() 067 { 068 return elementList; 069 } 070 071 public void addEncodeAtt(String value) 072 { 073 // System.out.println("XMLElement.addAtt(value) value ="+value); 074 encodingAttValue = value; 075 } 076 077 public void addAtt(String value) 078 { 079 attValue = value; 080 } 081 082 public String getAttribute() 083 { 084 return attValue; 085 } 086 087 public void setElementValue(String value0) 088 { 089 elementValue = elementValue + value0; 090 } 091 092 // private void createColumnTypeObject(int type, String typeName, int index) { 093 // columnTypes = new HashMap(); 094 // int[] varType = new int[]{-4,-3,-1,1,12,1111,2000}; // should be sorted 095 // 096 // int[] dateType = new int[]{-4,-3,-1,1,12,1111,2000}; // should be sorted 097 // 098 // int[] timeType = new int[]{-4,-3,-1,1,12,1111,2000}; // should be sorted 099 // 100 // int isVar = java.util.Arrays.binarySearch(varType,type); 101 // } 102 103 public String toString() 104 { 105 StringBuffer s = new StringBuffer(" [ " + elementName + " - " + 106 elementValue); 107 for (int i = 0; i < elementList.size(); i++) 108 { 109 s.append( (XMLElement) elementList.get(i)).toString(); 110 } 111 s.append(" ] "); 112 return s.toString(); 113 } 114 115 public void checkEncoding(){ 116 //System.out.println(" CHECK ENCODING ---------------encodingAttValue :"+encodingAttValue); 117 if(encodingAttValue != null && encodingAttValue.equalsIgnoreCase("y")){ 118 // System.out.println("att value "+ attValue); 119 // System.out.println(" elementValue ="+elementValue); 120 if(elementValue.length()== 4 && elementValue.equalsIgnoreCase("null")) 121 return; 122 elementValue = EncoderDecoder.decodeNew(elementValue); 123 124 // System.out.println(" element value "+ elementValue); 125 } 126 } 127 128 129 }

