1 19 20 package org.netbeans.modules.dbschema.migration.archiver.deserializer; 21 22 import java.lang.*; 23 import javax.xml.parsers.*; 24 25 import org.xml.sax.helpers.*; 26 import org.xml.sax.*; 27 28 public class BaseXMLDeserializer extends java.lang.Object 29 implements XMLDeserializer, org.xml.sax.DocumentHandler , org.xml.sax.DTDHandler , org.xml.sax.ErrorHandler 30 { 31 32 protected java.lang.Object InitialObject; 34 protected org.xml.sax.Parser Parser; 35 public org.xml.sax.Locator TheLocator; 36 protected org.xml.sax.InputSource TheSource; 37 public java.lang.StringBuffer TheCharacters; 38 39 public BaseXMLDeserializer() 41 { 42 this.TheCharacters = new StringBuffer (); 43 } 44 45 public void notationDecl(String name, String publicId, String systemId) throws org.xml.sax.SAXException 47 { 48 49 } 50 public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName) throws org.xml.sax.SAXException 51 { 52 53 } 54 public void processingInstruction(String target, String data) throws org.xml.sax.SAXException 55 { 56 57 } 58 public void setDocumentLocator(org.xml.sax.Locator locator) 59 { 60 this.TheLocator = locator; 61 } 62 public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException 63 { 64 65 } 66 public void endElement(java.lang.String name) throws org.xml.sax.SAXException 67 { 68 this.TheCharacters.delete(0,this.TheCharacters.length()); 69 } 70 71 public void endDocument() throws org.xml.sax.SAXException 72 { 73 this.freeResources(); 74 } 75 public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException 76 { 77 this.TheCharacters.append(ch,start,length); 78 } 79 80 public void startElement(java.lang.String name, org.xml.sax.AttributeList atts) throws org.xml.sax.SAXException 81 { 82 this.TheCharacters.delete(0,this.TheCharacters.length()); 83 } 84 85 public void startDocument() throws org.xml.sax.SAXException 86 { 87 this.freeResources(); 88 } 89 90 public void fatalError(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException 91 { 92 this.commonErrorProcessor(exception); 93 } 94 95 public void warning(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException 96 { 97 98 } 99 100 public void error(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException 101 { 102 this.commonErrorProcessor(exception); 103 } 104 105 public void setInitialObject(java.lang.Object obj) 106 { 107 this.InitialObject = obj; 108 } 109 110 public void freeResources() 111 { 112 this.TheCharacters.delete(0,this.TheCharacters.length()); 113 } 114 115 public java.lang.String getCharacters() 116 { 117 119 int lOffset = 0; 120 121 while (lOffset < this.TheCharacters.length()) 122 { 123 if (lOffset + 2 < this.TheCharacters.length() && 124 this.TheCharacters.substring(lOffset, lOffset + 2).equals("\\n")) 125 { 126 this.TheCharacters.delete(lOffset, lOffset + 2); 127 } 128 else if (this.TheCharacters.charAt(lOffset) == '\n') 129 { 130 this.TheCharacters.deleteCharAt(lOffset); 131 } 132 lOffset++; 133 } 134 135 return this.TheCharacters.toString(); 136 } 137 138 public int Begin() throws org.xml.sax.SAXException { 139 try { 140 if (this.Parser == null) { 141 org.xml.sax.Parser parser; 142 SAXParserFactory factory; 143 144 factory = SAXParserFactory.newInstance(); 145 factory.setValidating(false); factory.setNamespaceAware(false); 147 148 this.Parser = factory.newSAXParser().getParser(); 149 150 this.Parser.setDocumentHandler(this); 151 this.Parser.setDTDHandler(this); 152 this.Parser.setErrorHandler(this); 153 } 154 } catch (ParserConfigurationException e1) { 155 SAXException classError = new SAXException(e1.getMessage()); 156 throw classError; 157 } 158 159 return 1; 160 } 161 162 public void commonErrorProcessor(org.xml.sax.SAXParseException error) throws org.xml.sax.SAXException 163 { 164 throw(error); 165 } 166 167 public java.lang.Object XlateObject() throws org.xml.sax.SAXException , java.io.IOException 168 { 169 this.Begin(); 170 171 this.Parser.parse(this.TheSource); 172 173 return InitialObject; 174 } 175 176 public void setSource(org.xml.sax.InputSource source) 177 { 178 this.TheSource = source; 179 } 180 181 public java.lang.Object XlateObject(java.io.InputStream stream) throws org.xml.sax.SAXException , java.io.IOException 182 { 183 this.Begin(); 184 185 InputSource is = new InputSource(stream); 186 is.setSystemId("archiverNoID"); 187 this.setSource(is); 188 189 this.Parser.parse(this.TheSource); 190 191 return InitialObject; 192 } 193 194 public void DumpStatus() 195 { 196 198 System.out.println("Dump Status from class BaseXMLSerializer"); 199 System.out.println("The initial object is an instance of " + this.InitialObject.getClass().getName()); 200 System.out.println("The initial object state " + this.InitialObject.toString()); 201 System.out.println("The current stream dump is " + this.TheCharacters); 202 System.out.println("Dump Status from class BaseXMLSerializer - END"); 203 204 } 205 206 207 } | Popular Tags |