001: //
002: // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.4-b18-fcs
003: // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
004: // Any modifications to this file will be lost upon recompilation of the source schema.
005: // Generated on: 2005.03.04 at 10:20:40 PST
006: //
007:
008: package com.nabhinc.portal.config.impl.runtime;
009:
010: import java.util.StringTokenizer;
011:
012: import javax.xml.bind.Element;
013: import javax.xml.bind.ParseConversionEvent;
014: import javax.xml.bind.ValidationEvent;
015: import javax.xml.bind.helpers.ParseConversionEventImpl;
016: import javax.xml.bind.helpers.ValidationEventImpl;
017: import javax.xml.bind.helpers.ValidationEventLocatorImpl;
018:
019: import org.xml.sax.Attributes;
020: import org.xml.sax.SAXException;
021:
022: import com.sun.xml.bind.JAXBAssertionError;
023: import com.sun.xml.bind.unmarshaller.Messages;
024:
025: /**
026: * Convenient default implementation of
027: * {@link UnmarshallingEventHandler}
028: * to minimize code generation.
029: *
030: * <p>
031: * For historical reasons, sometimes this type is used where
032: * {@link UnmarshallingEventHandler} should be used.
033: *
034: * Once an exception is in the form of UnmarshalException, we consider
035: * it to be already reported to the client app.
036: */
037: public abstract class AbstractUnmarshallingEventHandlerImpl implements
038: UnmarshallingEventHandler {
039: public AbstractUnmarshallingEventHandlerImpl(
040: UnmarshallingContext _ctxt, String _stateTextTypes) {
041:
042: this .context = _ctxt;
043: this .stateTextTypes = _stateTextTypes;
044: }
045:
046: public final UnmarshallingContext context;
047:
048: /**
049: * Text type of states encoded into a string.
050: * 'L' means a list state.
051: */
052: private final String stateTextTypes;
053:
054: //
055: //
056: // methods that will be provided by the generated code.
057: //
058: //
059: // internal events
060: public void enterElement(String uri, String local, String qname,
061: Attributes atts) throws SAXException {
062: unexpectedEnterElement(uri, local, qname, atts);
063: }
064:
065: public void leaveElement(String uri, String local, String qname)
066: throws SAXException {
067: unexpectedLeaveElement(uri, local, qname);
068: }
069:
070: public final void text(String text) throws SAXException {
071: if (isListState()) {
072: // in list state, we don't need to care about whitespaces.
073: // if the text is all whitespace, this won't generate a text event,
074: // so it would be just fine.
075:
076: StringTokenizer tokens = new StringTokenizer(text);
077: if (tokens.countTokens() == 1) {
078: handleText(text);
079: } else {
080: while (tokens.hasMoreTokens())
081: // the handler can be switched during the text processing,
082: // so the current handler has to be obtained inside the loop
083: context.getCurrentHandler()
084: .text(tokens.nextToken());
085: }
086: } else {
087: // otherwise process this token
088: handleText(text);
089: }
090: }
091:
092: protected void handleText(String s) throws SAXException {
093: unexpectedText(s);
094: }
095:
096: public void enterAttribute(String uri, String local, String qname)
097: throws SAXException {
098: unexpectedEnterAttribute(uri, local, qname);
099: }
100:
101: public void leaveAttribute(String uri, String local, String qname)
102: throws SAXException {
103: unexpectedLeaveAttribute(uri, local, qname);
104: }
105:
106: public void leaveChild(int nextState) throws SAXException {
107: this .state = nextState;
108: }
109:
110: /**
111: * Checks if the current state is marked as a list state.
112: */
113: protected final boolean isListState() {
114: return stateTextTypes.charAt(state) == 'L';
115: }
116:
117: /** Current state of this automaton. */
118: public int state;
119:
120: //
121: //
122: // utility methods
123: //
124: //
125: /** Called when a RuntimeException is thrown during unmarshalling a text. */
126: protected void handleUnexpectedTextException(String text,
127: RuntimeException e) throws SAXException {
128: // report this as an error
129: reportError(Messages.format(Messages.UNEXPECTED_TEXT, text), e,
130: true);
131: }
132:
133: /**
134: * Last resort when something goes terribly wrong within the unmarshaller.
135: */
136: protected void handleGenericException(Exception e)
137: throws SAXException {
138: reportError(e.getMessage(), e, false);
139: }
140:
141: protected final void dump() {
142: System.err.println("state is :" + state);
143: }
144:
145: private void reportError(String msg, boolean canRecover)
146: throws SAXException {
147: reportError(msg, null, canRecover);
148: }
149:
150: private void reportError(String msg, Exception nested,
151: boolean canRecover) throws SAXException {
152: context.handleEvent(new ValidationEventImpl(
153: canRecover ? ValidationEvent.ERROR
154: : ValidationEvent.FATAL_ERROR, msg,
155: new ValidationEventLocatorImpl(context.getLocator()),
156: nested), canRecover);
157: }
158:
159: protected final void unexpectedEnterElement(String uri,
160: String local, String qname, Attributes atts)
161: throws SAXException {
162: // notify the error
163: reportError(Messages.format(Messages.UNEXPECTED_ENTER_ELEMENT,
164: uri, local), true);
165: // then recover by ignoring the whole element.
166: context.pushContentHandler(new Discarder(context), state);
167: context.getCurrentHandler().enterElement(uri, local, qname,
168: atts);
169: }
170:
171: protected final void unexpectedLeaveElement(String uri,
172: String local, String qname) throws SAXException {
173: reportError(Messages.format(Messages.UNEXPECTED_LEAVE_ELEMENT,
174: uri, local), false);
175: }
176:
177: protected final void unexpectedEnterAttribute(String uri,
178: String local, String qname) throws SAXException {
179: reportError(Messages.format(
180: Messages.UNEXPECTED_ENTER_ATTRIBUTE, uri, local), false);
181: }
182:
183: protected final void unexpectedLeaveAttribute(String uri,
184: String local, String qname) throws SAXException {
185: reportError(Messages.format(
186: Messages.UNEXPECTED_LEAVE_ATTRIBUTE, uri, local), false);
187: }
188:
189: protected final void unexpectedText(String str) throws SAXException {
190: // make str printable
191: str = str.replace('\r', ' ').replace('\n', ' ').replace('\t',
192: ' ').trim();
193:
194: reportError(Messages.format(Messages.UNEXPECTED_TEXT, str),
195: true);
196: }
197:
198: protected final void unexpectedLeaveChild() throws SAXException {
199: // I believe this is really a bug of the compiler,
200: // since when an object spawns a child object, it must be "prepared"
201: // to receive this event.
202: dump();
203: throw new JAXBAssertionError(Messages
204: .format(Messages.UNEXPECTED_LEAVE_CHILD));
205: }
206:
207: /**
208: * This method is called by the generated derived class
209: * when a datatype parse method throws an exception.
210: */
211: protected void handleParseConversionException(Exception e)
212: throws SAXException {
213: if (e instanceof RuntimeException)
214: throw (RuntimeException) e; // don't catch the runtime exception. just let it go.
215:
216: // wrap it into a ParseConversionEvent and report it
217: ParseConversionEvent pce = new ParseConversionEventImpl(
218: ValidationEvent.ERROR, e.getMessage(),
219: new ValidationEventLocatorImpl(context.getLocator()), e);
220: context.handleEvent(pce, true);
221: }
222:
223: //
224: //
225: // spawn a new child object
226: //
227: //
228: private UnmarshallingEventHandler spawnChild(Class clazz,
229: int memento) {
230:
231: UnmarshallableObject child;
232: try {
233: child = (UnmarshallableObject) clazz.newInstance();
234: } catch (InstantiationException e) {
235: throw new InstantiationError(e.getMessage());
236: } catch (IllegalAccessException e) {
237: throw new IllegalAccessError(e.getMessage());
238: }
239:
240: UnmarshallingEventHandler handler = child
241: .createUnmarshaller(context);
242: context.pushContentHandler(handler, memento);
243: return handler;
244: }
245:
246: protected final Object spawnChildFromEnterElement(Class clazz,
247: int memento, String uri, String local, String qname,
248: Attributes atts) throws SAXException {
249: UnmarshallingEventHandler ueh = spawnChild(clazz, memento);
250: ueh.enterElement(uri, local, qname, atts);
251: return ueh.owner();
252: }
253:
254: protected final Object spawnChildFromEnterAttribute(Class clazz,
255: int memento, String uri, String local, String qname)
256: throws SAXException {
257: UnmarshallingEventHandler ueh = spawnChild(clazz, memento);
258: ueh.enterAttribute(uri, local, qname);
259: return ueh.owner();
260: }
261:
262: protected final Object spawnChildFromText(Class clazz, int memento,
263: String value) throws SAXException {
264: UnmarshallingEventHandler ueh = spawnChild(clazz, memento);
265: ueh.text(value);
266: return ueh.owner();
267: }
268:
269: // these methods can be used if a child object can be nullable
270: protected final Object spawnChildFromLeaveElement(Class clazz,
271: int memento, String uri, String local, String qname)
272: throws SAXException {
273: UnmarshallingEventHandler ueh = spawnChild(clazz, memento);
274: ueh.leaveElement(uri, local, qname);
275: return ueh.owner();
276: }
277:
278: protected final Object spawnChildFromLeaveAttribute(Class clazz,
279: int memento, String uri, String local, String qname)
280: throws SAXException {
281: UnmarshallingEventHandler ueh = spawnChild(clazz, memento);
282: ueh.leaveAttribute(uri, local, qname);
283: return ueh.owner();
284: }
285:
286: protected final Element spawnWildcard(int memento, String uri,
287: String local, String qname, Attributes atts)
288: throws SAXException {
289: UnmarshallingEventHandler ueh = context.getGrammarInfo()
290: .createUnmarshaller(uri, local, context);
291:
292: if (ueh != null) {
293: context.pushContentHandler(ueh, memento);
294: ueh.enterElement(uri, local, qname, atts);
295: return (Element) ueh.owner();
296: } else {
297: // if no class is available to unmarshal this element, discard
298: // the sub-tree by feeding events to discarder.
299: context.pushContentHandler(new Discarder(context), memento);
300: context.getCurrentHandler().enterElement(uri, local, qname,
301: atts);
302: return null; // return null so that the discarder will be ignored
303: }
304: }
305:
306: //
307: //
308: // spawn a new child handler.
309: // used for super class and RELAXNG interleave handling.
310: //
311:
312: protected final void spawnHandlerFromEnterElement(
313: UnmarshallingEventHandler unm, int memento, String uri,
314: String local, String qname, Attributes atts)
315: throws SAXException {
316:
317: context.pushContentHandler(unm, memento);
318: unm.enterElement(uri, local, qname, atts);
319: }
320:
321: protected final void spawnHandlerFromEnterAttribute(
322: UnmarshallingEventHandler unm, int memento, String uri,
323: String local, String qname) throws SAXException {
324:
325: context.pushContentHandler(unm, memento);
326: unm.enterAttribute(uri, local, qname);
327: }
328:
329: protected final void spawnHandlerFromFromText(
330: UnmarshallingEventHandler unm, int memento, String value)
331: throws SAXException {
332:
333: context.pushContentHandler(unm, memento);
334: unm.text(value);
335: }
336:
337: protected final void spawnHandlerFromLeaveElement(
338: UnmarshallingEventHandler unm, int memento, String uri,
339: String local, String qname) throws SAXException {
340:
341: context.pushContentHandler(unm, memento);
342: unm.leaveElement(uri, local, qname);
343: }
344:
345: protected final void spawnHandlerFromLeaveAttribute(
346: UnmarshallingEventHandler unm, int memento, String uri,
347: String local, String qname) throws SAXException {
348:
349: context.pushContentHandler(unm, memento);
350: unm.leaveAttribute(uri, local, qname);
351: }
352:
353: protected final void spawnHandlerFromText(
354: UnmarshallingEventHandler unm, int memento, String text)
355: throws SAXException {
356:
357: context.pushContentHandler(unm, memento);
358: unm.text(text);
359: }
360:
361: //
362: //
363: // revert to parent
364: //
365: //
366: protected final void revertToParentFromEnterElement(String uri,
367: String local, String qname, Attributes atts)
368: throws SAXException {
369: context.popContentHandler();
370: context.getCurrentHandler().enterElement(uri, local, qname,
371: atts);
372: }
373:
374: protected final void revertToParentFromLeaveElement(String uri,
375: String local, String qname) throws SAXException {
376: context.popContentHandler();
377: context.getCurrentHandler().leaveElement(uri, local, qname);
378: }
379:
380: protected final void revertToParentFromEnterAttribute(String uri,
381: String local, String qname) throws SAXException {
382: context.popContentHandler();
383: context.getCurrentHandler().enterAttribute(uri, local, qname);
384: }
385:
386: protected final void revertToParentFromLeaveAttribute(String uri,
387: String local, String qname) throws SAXException {
388: context.popContentHandler();
389: context.getCurrentHandler().leaveAttribute(uri, local, qname);
390: }
391:
392: protected final void revertToParentFromText(String value)
393: throws SAXException {
394: context.popContentHandler();
395: context.getCurrentHandler().text(value);
396: }
397: }
|