1 19 20 package org.netbeans.modules.dbschema.migration.archiver.deserializer; 23 24 import java.lang.*; 25 import java.lang.reflect.*; 26 27 import org.xml.sax.*; 28 29 public class BaseSpecificXMLDeserializer extends BaseXMLDeserializer 30 implements SpecificXMLDeserializer 31 { 32 34 public static final String WRONG_TAG = "Saw tag {1} when {2} was expected."; 35 protected java.lang.Integer State; 36 protected java.lang.Class ParameterClass; 37 protected java.lang.Class ParameterSetMethod; 38 39 protected ArrayListStack StateStack; 41 protected ArrayListStack ObjectStack; 42 protected java.util.HashMap ActiveAliasHash; 43 49 50 protected java.util.Vector ParameterArray; 51 public java.util.Vector ParameterTypeArray; 52 protected XMLDeserializer MasterDeserializer; 53 private ClassLoader classLoader; 55 56 58 public BaseSpecificXMLDeserializer (ClassLoader cl) 60 { 61 super(); 62 this.ObjectStack = new ArrayListStack(); 64 this.StateStack = new ArrayListStack(); 65 this.classLoader = (cl != null ? cl : getClass ().getClassLoader ()); 66 70 this.setMasterDeserializer(this); 71 } 72 73 public BaseSpecificXMLDeserializer() 74 { 75 this (null); 76 } 77 78 80 public void setMasterDeserializer(XMLDeserializer master) 81 { 82 this.MasterDeserializer = master; 83 } 84 85 public void unexpectedTag(String actual,String expected, boolean endTagExpected) throws org.xml.sax.SAXException 86 { 87 88 if (endTagExpected) 89 { 90 expected = "/" + expected; 93 94 } 95 96 String message = new String ("Saw tag " + actual + " when " + expected + " was expected."); 97 98 SAXException tagError = new SAXException(message); 99 100 throw tagError; 101 } 102 103 public void validateTag(String actual, String expected, boolean endTagExpected) throws org.xml.sax.SAXException 104 { 105 if ( !actual.equals(expected) ) 106 { 107 this.unexpectedTag(actual, expected, endTagExpected); 108 } 109 } 110 111 public void popState() 112 { 113 this.State = (Integer )(this.StateStack.pop()); 114 } 115 116 public void pushState(int newState) 117 { 118 120 this.StateStack.push( this.State ); 121 122 this.State = new Integer (newState); 124 } 125 126 public void addActiveAlias(String name, String alias) 127 { 128 if (this.ActiveAliasHash == null) 129 { 130 this.ActiveAliasHash = new java.util.HashMap (20); 132 } 133 134 141 this.ActiveAliasHash.put(alias, name); 142 } 143 144 public String lookupAlias(String name) 145 { 146 String retName = null; 153 154 if (this.ActiveAliasHash != null) 155 { 156 retName = (String )(this.ActiveAliasHash.get(name)); 157 158 } 159 if (retName == null) 160 { 161 retName = name; 162 } 163 164 return retName; 165 } 166 167 public Class findClass(String name) throws java.lang.ClassNotFoundException 168 { 169 Class lReturnClass; 170 171 174 175 name= org.netbeans.modules.dbschema.migration.archiver.MapClassName.getRealClassName(name); 176 lReturnClass = java.lang.Class.forName(name, true , this.classLoader); 177 178 return lReturnClass; 179 } 180 181 public Object popObject() 182 { 183 return this.ObjectStack.pop(); 184 } 185 186 public void pushObject(Object obj) 187 { 188 this.ObjectStack.push(obj); 189 } 190 191 public String unescapeName(String name) 192 { 193 196 if (name.startsWith("_-")) { 198 return name.substring(2); 199 } 200 201 int idx = name.indexOf('-'); 202 if (idx >= 0) { 203 StringBuffer buf = new StringBuffer (name); 204 buf.setCharAt(idx, '_'); 205 return buf.toString(); 206 } 207 208 return name; 209 243 } 244 245 public boolean useExistingAttribute(org.xml.sax.AttributeList atts, String attrname, Object existing) throws org.xml.sax.SAXException 246 { 247 boolean retBool = false; 248 249 String useDirective = atts.getValue("USE"); 250 251 if (useDirective != null && 252 useDirective.equals("EXISTING")) 253 { 254 256 java.lang.Object lCurrentObj = this.topObject(); 257 Field lField = null; 258 try 259 { 260 lField = lCurrentObj.getClass().getDeclaredField(attrname); 261 existing = lField.get(lCurrentObj); 262 } 263 catch (IllegalArgumentException e1) 264 { 265 269 String message = ("Illegal Argument used " + lCurrentObj.getClass().getName()); 271 SAXException useError = new SAXException(message); 272 throw useError; 273 } 274 catch (IllegalAccessException e2) 275 { 276 String message = ("Illegal Access of field " + lField); 281 SAXException useError = new SAXException(message); 282 throw useError; 283 } 284 catch (NoSuchFieldException e3) 285 { 286 290 String message = ("No such field " + attrname); 292 SAXException useError = new SAXException(message); 293 throw useError; 294 } 295 296 retBool = true; 297 } 298 else if (useDirective != null) 299 { 300 String message = ("Invalid value USE for attribute " + useDirective); 302 303 SAXException useError = new SAXException(message); 304 throw useError; 305 306 } 308 return retBool; 309 } 310 311 public java.lang.Object topObject() throws org.xml.sax.SAXException 312 { 313 if (this.ObjectStack.size() == 0) 314 { 315 String message = ("Object Stack Empty"); 317 318 SAXException stackError = new SAXException(message); 319 320 throw stackError; 321 322 } 323 324 return this.ObjectStack.peek(); 325 } 326 327 public void freeResources() 328 { 329 super.freeResources(); 330 this.ObjectStack.clear(); 331 StateStack.clear(); 334 if (ActiveAliasHash != null) 335 ActiveAliasHash.clear(); 336 } 337 338 public void DumpStatus() 339 { 340 super.DumpStatus(); 342 343 System.out.println("Dump Status from class BaseSpecificXMLSerializer"); 344 System.out.println("Current state " + this.State); 345 System.out.println("State stack " + this.StateStack); 346 System.out.println("Object Stack " + this.ObjectStack); 347 System.out.println("Dump Status from class BasespecificXMLSerializer - END"); 348 349 } 350 351 } | Popular Tags |