001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: // GENERATED CODE FOR Sun ONE Studio class.
043: //
044: package org.netbeans.modules.dbschema.migration.archiver.deserializer;
045:
046: import java.lang.*;
047: import java.lang.reflect.*;
048:
049: import org.xml.sax.*;
050:
051: public class BaseSpecificXMLDeserializer extends BaseXMLDeserializer
052: implements SpecificXMLDeserializer {
053: // Fields
054:
055: public static final String WRONG_TAG = "Saw tag {1} when {2} was expected.";
056: protected java.lang.Integer State;
057: protected java.lang.Class ParameterClass;
058: protected java.lang.Class ParameterSetMethod;
059:
060: //@olsen+MBO: used unsynchronized HashMap and ArrayListStack
061: protected ArrayListStack StateStack;
062: protected ArrayListStack ObjectStack;
063: protected java.util.HashMap ActiveAliasHash;
064: /*
065: protected java.util.Stack StateStack;
066: protected java.util.Stack ObjectStack;
067: protected java.util.Hashtable ActiveAliasHash;
068: protected java.util.Hashtable ClassHash; // @olsen+MBO: NOT USED!
069: */
070:
071: protected java.util.Vector ParameterArray;
072: public java.util.Vector ParameterTypeArray;
073: protected XMLDeserializer MasterDeserializer;
074: private ClassLoader classLoader; //@lars
075:
076: // Constructors
077:
078: //@lars: added classloader-constructor
079: public BaseSpecificXMLDeserializer(ClassLoader cl) {
080: super ();
081: //@olsen+MBO: used unsynchronized HashMap and ArrayListStack
082: this .ObjectStack = new ArrayListStack();
083: this .StateStack = new ArrayListStack();
084: this .classLoader = (cl != null ? cl : getClass()
085: .getClassLoader());
086: /*
087: this.ObjectStack = new java.util.Stack();
088: this.StateStack = new java.util.Stack();
089: */
090: this .setMasterDeserializer(this );
091: } /*Constructor-End*/
092:
093: public BaseSpecificXMLDeserializer() {
094: this (null);
095: } /*Constructor-End*/
096:
097: // Methods
098:
099: public void setMasterDeserializer(XMLDeserializer master) {
100: this .MasterDeserializer = master;
101: } /*Method-End*/
102:
103: public void unexpectedTag(String actual, String expected,
104: boolean endTagExpected) throws org.xml.sax.SAXException {
105:
106: if (endTagExpected) {
107: //String endTag = new String("/" + expected);
108: //expected = endTag;
109: expected = "/" + expected;
110:
111: }
112:
113: String message = ("Saw tag " + actual + " when " + expected + " was expected.");
114:
115: SAXException tagError = new SAXException(message);
116:
117: throw tagError;
118: } /*Method-End*/
119:
120: public void validateTag(String actual, String expected,
121: boolean endTagExpected) throws org.xml.sax.SAXException {
122: if (!actual.equals(expected)) {
123: this .unexpectedTag(actual, expected, endTagExpected);
124: }
125: } /*Method-End*/
126:
127: public void popState() {
128: this .State = (Integer) (this .StateStack.pop());
129: } /*Method-End*/
130:
131: public void pushState(int newState) {
132: // put the old state on the top of the stack
133:
134: this .StateStack.push(this .State);
135:
136: // and now set the state to the new state
137: this .State = new Integer(newState);
138: } /*Method-End*/
139:
140: public void addActiveAlias(String name, String alias) {
141: if (this .ActiveAliasHash == null) {
142: //this.ActiveAliasHash = new java.util.Hashtable(20, 0.75F);
143: this .ActiveAliasHash = new java.util.HashMap(20);
144: }
145:
146: //@olsen+MBO: removed redundant code
147: /*
148: if (this.ActiveAliasHash.containsKey(alias))
149: {
150: this.ActiveAliasHash.remove(alias);
151: }
152: */
153: this .ActiveAliasHash.put(alias, name);
154: } /*Method-End*/
155:
156: public String lookupAlias(String name) {
157: //
158: // this method searches the alias hashtable
159: // if it exists and returns the name of the alias
160: // otherwise it simply returns the name that was
161: // passed in
162: //
163: String retName = null;
164:
165: if (this .ActiveAliasHash != null) {
166: retName = (String) (this .ActiveAliasHash.get(name));
167:
168: }
169: if (retName == null) {
170: retName = name;
171: }
172:
173: return retName;
174: } /*Method-End*/
175:
176: public Class findClass(String name)
177: throws java.lang.ClassNotFoundException {
178: Class lReturnClass;
179:
180: //@lars: added classloader
181: // lReturnClass = Class.forName (name);
182:
183: name = org.netbeans.modules.dbschema.migration.archiver.MapClassName
184: .getRealClassName(name);
185: lReturnClass = java.lang.Class.forName(name,
186: true /*initialize the class*/, this .classLoader);
187:
188: return lReturnClass;
189: } /*Method-End*/
190:
191: public Object popObject() {
192: return this .ObjectStack.pop();
193: } /*Method-End*/
194:
195: public void pushObject(Object obj) {
196: this .ObjectStack.push(obj);
197: } /*Method-End*/
198:
199: public String unescapeName(String name) {
200: // this method is going to strip the _ and - from
201: // the beginning of the name
202:
203: //@olsen+MBO: minimized number of objects and operations
204: if (name.startsWith("_-")) {
205: return name.substring(2);
206: }
207:
208: int idx = name.indexOf('-');
209: if (idx >= 0) {
210: StringBuffer buf = new StringBuffer(name);
211: buf.setCharAt(idx, '_');
212: return buf.toString();
213: }
214:
215: return name;
216: /*
217: StringBuffer lStr = new StringBuffer(name);
218:
219: if ( (lStr.charAt(0) == '_') &&
220: (lStr.charAt(1) == '-') )
221: {
222: lStr.delete(0,2);
223: }
224: else
225: {
226: boolean lFound = false;
227: int lLocation;
228: // search for dash
229: loop:
230: for (lLocation = 0; lLocation < lStr.length(); lLocation++)
231: {
232: if (lStr.charAt(lLocation) == '-')
233: {
234: lFound = true;
235: break loop;
236: }// end if
237: }// end for
238:
239: // if we find an dash replace it with a underscore
240: if (lFound)
241: {
242: lStr.replace(lLocation, lLocation + 1, "_");
243:
244: }// end if
245:
246:
247: }// end if
248: return lStr.toString();
249: */
250: } /*Method-End*/
251:
252: public boolean useExistingAttribute(org.xml.sax.AttributeList atts,
253: String attrname, Object existing)
254: throws org.xml.sax.SAXException {
255: boolean retBool = false;
256:
257: String useDirective = atts.getValue("USE");
258:
259: if (useDirective != null && useDirective.equals("EXISTING")) {
260: //@olsen+MBO: ever stepped in?
261:
262: java.lang.Object lCurrentObj = this .topObject();
263: Field lField = null;
264: try {
265: lField = lCurrentObj.getClass().getDeclaredField(
266: attrname);
267: existing = lField.get(lCurrentObj);
268: } catch (IllegalArgumentException e1) {
269: // add the illegal arg exception to the exception stack
270: // and then mask it under a SAXexception and raise the
271: // SAXException
272:
273: //String message = new String("Illegal Argument used " + lCurrentObj.getClass().getName());
274: String message = ("Illegal Argument used " + lCurrentObj
275: .getClass().getName());
276: SAXException useError = new SAXException(message);
277: throw useError;
278: } catch (IllegalAccessException e2) {
279: // add the illegal access exception to the exception stack
280: // and then mask it under a SAXexception and raise the
281: // SAXException
282: //String message = new String("Illegal Access of field " + lField);
283: String message = ("Illegal Access of field " + lField);
284: SAXException useError = new SAXException(message);
285: throw useError;
286: } catch (NoSuchFieldException e3) {
287: // add the no such field exception to the exception stack
288: // and then mask it under a SAXexception and raise the
289: // SAXException
290:
291: //String message = new String("No such field " + attrname);
292: String message = ("No such field " + attrname);
293: SAXException useError = new SAXException(message);
294: throw useError;
295: }
296:
297: retBool = true;
298: } else if (useDirective != null) {
299: //String message = new String("Invalid value USE for attribute " + useDirective);
300: String message = ("Invalid value USE for attribute " + useDirective);
301:
302: SAXException useError = new SAXException(message);
303: throw useError;
304:
305: }// end if
306:
307: return retBool;
308: } /*Method-End*/
309:
310: public java.lang.Object topObject() throws org.xml.sax.SAXException {
311: if (this .ObjectStack.size() == 0) {
312: //String message = new String("Object Stack Empty");
313: String message = ("Object Stack Empty");
314:
315: SAXException stackError = new SAXException(message);
316:
317: throw stackError;
318:
319: }
320:
321: return this .ObjectStack.peek();
322: } /*Method-End*/
323:
324: public void freeResources() {
325: super .freeResources();
326: this .ObjectStack.clear();
327: //ParameterArray.clear();
328: //ParameterTypeArray.clear();
329: StateStack.clear();
330: if (ActiveAliasHash != null)
331: ActiveAliasHash.clear();
332: } /*Method-End*/
333:
334: public void DumpStatus() {
335: // This method is a debug method to dump status information about this object
336: super .DumpStatus();
337:
338: System.out
339: .println("Dump Status from class BaseSpecificXMLSerializer");
340: System.out.println("Current state " + this .State);
341: System.out.println("State stack " + this .StateStack);
342: System.out.println("Object Stack " + this .ObjectStack);
343: System.out
344: .println("Dump Status from class BasespecificXMLSerializer - END");
345:
346: }
347:
348: } // end of class
|