KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > dbschema > migration > archiver > deserializer > BaseSpecificXMLDeserializer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 // GENERATED CODE FOR Sun ONE Studio class.
21
//
22
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     // Fields
33

34     public static final String JavaDoc WRONG_TAG = "Saw tag {1} when {2} was expected.";
35     protected java.lang.Integer JavaDoc State;
36     protected java.lang.Class JavaDoc ParameterClass;
37     protected java.lang.Class JavaDoc ParameterSetMethod;
38
39 //@olsen+MBO: used unsynchronized HashMap and ArrayListStack
40
protected ArrayListStack StateStack;
41     protected ArrayListStack ObjectStack;
42     protected java.util.HashMap JavaDoc ActiveAliasHash;
43 /*
44     protected java.util.Stack StateStack;
45     protected java.util.Stack ObjectStack;
46     protected java.util.Hashtable ActiveAliasHash;
47     protected java.util.Hashtable ClassHash; // @olsen+MBO: NOT USED!
48 */

49
50     protected java.util.Vector JavaDoc ParameterArray;
51     public java.util.Vector JavaDoc ParameterTypeArray;
52     protected XMLDeserializer MasterDeserializer;
53     private ClassLoader JavaDoc classLoader; //@lars
54

55
56     // Constructors
57

58     //@lars: added classloader-constructor
59
public BaseSpecificXMLDeserializer (ClassLoader JavaDoc cl)
60     {
61         super();
62 //@olsen+MBO: used unsynchronized HashMap and ArrayListStack
63
this.ObjectStack = new ArrayListStack();
64         this.StateStack = new ArrayListStack();
65         this.classLoader = (cl != null ? cl : getClass ().getClassLoader ());
66 /*
67         this.ObjectStack = new java.util.Stack();
68         this.StateStack = new java.util.Stack();
69 */

70         this.setMasterDeserializer(this);
71     } /*Constructor-End*/
72
73     public BaseSpecificXMLDeserializer()
74     {
75         this (null);
76     } /*Constructor-End*/
77
78     // Methods
79

80     public void setMasterDeserializer(XMLDeserializer master)
81     {
82         this.MasterDeserializer = master;
83     } /*Method-End*/
84
85     public void unexpectedTag(String JavaDoc actual,String JavaDoc expected, boolean endTagExpected) throws org.xml.sax.SAXException JavaDoc
86     {
87
88         if (endTagExpected)
89         {
90             //String endTag = new String("/" + expected);
91
//expected = endTag;
92
expected = "/" + expected;
93
94         }
95
96         String JavaDoc message = new String JavaDoc("Saw tag " + actual + " when " + expected + " was expected.");
97
98         SAXException tagError = new SAXException(message);
99
100         throw tagError;
101     } /*Method-End*/
102
103     public void validateTag(String JavaDoc actual, String JavaDoc expected, boolean endTagExpected) throws org.xml.sax.SAXException JavaDoc
104     {
105         if ( !actual.equals(expected) )
106         {
107             this.unexpectedTag(actual, expected, endTagExpected);
108         }
109     } /*Method-End*/
110
111     public void popState()
112     {
113         this.State = (Integer JavaDoc)(this.StateStack.pop());
114     } /*Method-End*/
115
116     public void pushState(int newState)
117     {
118         // put the old state on the top of the stack
119

120         this.StateStack.push( this.State );
121
122         // and now set the state to the new state
123
this.State = new Integer JavaDoc(newState);
124     } /*Method-End*/
125
126     public void addActiveAlias(String JavaDoc name, String JavaDoc alias)
127     {
128         if (this.ActiveAliasHash == null)
129         {
130             //this.ActiveAliasHash = new java.util.Hashtable(20, 0.75F);
131
this.ActiveAliasHash = new java.util.HashMap JavaDoc(20);
132         }
133
134 //@olsen+MBO: removed redundant code
135
/*
136         if (this.ActiveAliasHash.containsKey(alias))
137         {
138             this.ActiveAliasHash.remove(alias);
139         }
140 */

141         this.ActiveAliasHash.put(alias, name);
142     } /*Method-End*/
143
144     public String JavaDoc lookupAlias(String JavaDoc name)
145     {
146         //
147
// this method searches the alias hashtable
148
// if it exists and returns the name of the alias
149
// otherwise it simply returns the name that was
150
// passed in
151
//
152
String JavaDoc retName = null;
153
154         if (this.ActiveAliasHash != null)
155         {
156             retName = (String JavaDoc)(this.ActiveAliasHash.get(name));
157
158         }
159         if (retName == null)
160         {
161             retName = name;
162         }
163
164         return retName;
165     } /*Method-End*/
166
167     public Class JavaDoc findClass(String JavaDoc name) throws java.lang.ClassNotFoundException JavaDoc
168     {
169         Class JavaDoc lReturnClass;
170
171 //@lars: added classloader
172
// lReturnClass = Class.forName (name);
173

174         
175         name= org.netbeans.modules.dbschema.migration.archiver.MapClassName.getRealClassName(name);
176         lReturnClass = java.lang.Class.forName(name, true /*initialize the class*/, this.classLoader);
177
178         return lReturnClass;
179     } /*Method-End*/
180
181     public Object JavaDoc popObject()
182     {
183         return this.ObjectStack.pop();
184     } /*Method-End*/
185
186     public void pushObject(Object JavaDoc obj)
187     {
188         this.ObjectStack.push(obj);
189     } /*Method-End*/
190
191     public String JavaDoc unescapeName(String JavaDoc name)
192     {
193         // this method is going to strip the _ and - from
194
// the beginning of the name
195

196 //@olsen+MBO: minimized number of objects and operations
197
if (name.startsWith("_-")) {
198             return name.substring(2);
199         }
200
201         int idx = name.indexOf('-');
202         if (idx >= 0) {
203             StringBuffer JavaDoc buf = new StringBuffer JavaDoc(name);
204             buf.setCharAt(idx, '_');
205             return buf.toString();
206         }
207
208         return name;
209 /*
210         StringBuffer lStr = new StringBuffer(name);
211
212         if ( (lStr.charAt(0) == '_') &&
213              (lStr.charAt(1) == '-') )
214         {
215             lStr.delete(0,2);
216         }
217         else
218         {
219             boolean lFound = false;
220             int lLocation;
221             // search for dash
222             loop:
223             for (lLocation = 0; lLocation < lStr.length(); lLocation++)
224             {
225                 if (lStr.charAt(lLocation) == '-')
226                 {
227                     lFound = true;
228                      break loop;
229                 }// end if
230             }// end for
231
232             // if we find an dash replace it with a underscore
233             if (lFound)
234             {
235                 lStr.replace(lLocation, lLocation + 1, "_");
236
237             }// end if
238
239
240         }// end if
241         return lStr.toString();
242 */

243     } /*Method-End*/
244
245     public boolean useExistingAttribute(org.xml.sax.AttributeList JavaDoc atts, String JavaDoc attrname, Object JavaDoc existing) throws org.xml.sax.SAXException JavaDoc
246     {
247         boolean retBool = false;
248
249         String JavaDoc useDirective = atts.getValue("USE");
250
251         if (useDirective != null &&
252             useDirective.equals("EXISTING"))
253         {
254 //@olsen+MBO: ever stepped in?
255

256             java.lang.Object JavaDoc 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 JavaDoc e1)
264             {
265                 // add the illegal arg exception to the exception stack
266
// and then mask it under a SAXexception and raise the
267
// SAXException
268

269                 //String message = new String("Illegal Argument used " + lCurrentObj.getClass().getName());
270
String JavaDoc message = ("Illegal Argument used " + lCurrentObj.getClass().getName());
271                 SAXException useError = new SAXException(message);
272                 throw useError;
273             }
274             catch (IllegalAccessException JavaDoc e2)
275              {
276                  // add the illegal access exception to the exception stack
277
// and then mask it under a SAXexception and raise the
278
// SAXException
279
//String message = new String("Illegal Access of field " + lField);
280
String JavaDoc message = ("Illegal Access of field " + lField);
281                  SAXException useError = new SAXException(message);
282                  throw useError;
283              }
284             catch (NoSuchFieldException JavaDoc e3)
285              {
286                  // add the no such field exception to the exception stack
287
// and then mask it under a SAXexception and raise the
288
// SAXException
289

290                  //String message = new String("No such field " + attrname);
291
String JavaDoc 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 = new String("Invalid value USE for attribute " + useDirective);
301
String JavaDoc message = ("Invalid value USE for attribute " + useDirective);
302
303             SAXException useError = new SAXException(message);
304             throw useError;
305
306         }// end if
307

308         return retBool;
309     } /*Method-End*/
310
311     public java.lang.Object JavaDoc topObject() throws org.xml.sax.SAXException JavaDoc
312     {
313         if (this.ObjectStack.size() == 0)
314         {
315             //String message = new String("Object Stack Empty");
316
String JavaDoc message = ("Object Stack Empty");
317
318             SAXException stackError = new SAXException(message);
319
320             throw stackError;
321
322         }
323
324         return this.ObjectStack.peek();
325     } /*Method-End*/
326
327     public void freeResources()
328     {
329         super.freeResources();
330         this.ObjectStack.clear();
331         //ParameterArray.clear();
332
//ParameterTypeArray.clear();
333
StateStack.clear();
334         if (ActiveAliasHash != null)
335             ActiveAliasHash.clear();
336     } /*Method-End*/
337
338     public void DumpStatus()
339     {
340         // This method is a debug method to dump status information about this object
341
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 } // end of class
352
Popular Tags