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 javax.xml.bind.ValidationEvent;
011: import javax.xml.bind.helpers.ValidationEventImpl;
012: import javax.xml.bind.helpers.ValidationEventLocatorImpl;
013:
014: import org.xml.sax.Attributes;
015: import org.xml.sax.ContentHandler;
016: import org.xml.sax.SAXException;
017:
018: /**
019: * Redirects events to another SAX ContentHandler.
020: *
021: * <p>
022: * Note that the SAXException returned by the ContentHandler is
023: * unreported. So we have to catch them and report it, then rethrow
024: * it if necessary.
025: *
026: * @author
027: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
028: */
029: public class UnmarshallingEventHandlerAdaptor implements
030: UnmarshallingEventHandler {
031:
032: protected final UnmarshallingContext context;
033:
034: /** This handler will receive SAX events. */
035: protected final ContentHandler handler;
036:
037: public UnmarshallingEventHandlerAdaptor(UnmarshallingContext _ctxt,
038: ContentHandler _handler) throws SAXException {
039: this .context = _ctxt;
040: this .handler = _handler;
041:
042: // emulate the start of documents
043: try {
044: handler.setDocumentLocator(context.getLocator());
045: handler.startDocument();
046: declarePrefixes(context.getAllDeclaredPrefixes());
047: } catch (SAXException e) {
048: error(e);
049: }
050: }
051:
052: public Object owner() {
053: return null;
054: }
055:
056: // nest level of elements.
057: private int depth = 0;
058:
059: public void enterAttribute(String uri, String local, String qname)
060: throws SAXException {
061: }
062:
063: public void enterElement(String uri, String local, String qname,
064: Attributes atts) throws SAXException {
065: depth++;
066: context.pushAttributes(atts, true);
067: try {
068: declarePrefixes(context.getNewlyDeclaredPrefixes());
069: handler.startElement(uri, local, qname, atts);
070: } catch (SAXException e) {
071: error(e);
072: }
073: }
074:
075: public void leaveAttribute(String uri, String local, String qname)
076: throws SAXException {
077: }
078:
079: public void leaveElement(String uri, String local, String qname)
080: throws SAXException {
081: try {
082: handler.endElement(uri, local, qname);
083: undeclarePrefixes(context.getNewlyDeclaredPrefixes());
084: } catch (SAXException e) {
085: error(e);
086: }
087: context.popAttributes();
088:
089: depth--;
090: if (depth == 0) {
091: // emulate the end of the document
092: try {
093: undeclarePrefixes(context.getAllDeclaredPrefixes());
094: handler.endDocument();
095: } catch (SAXException e) {
096: error(e);
097: }
098: context.popContentHandler();
099: }
100: }
101:
102: private void declarePrefixes(String[] prefixes) throws SAXException {
103: for (int i = prefixes.length - 1; i >= 0; i--)
104: handler.startPrefixMapping(prefixes[i], context
105: .getNamespaceURI(prefixes[i]));
106: }
107:
108: private void undeclarePrefixes(String[] prefixes)
109: throws SAXException {
110: for (int i = prefixes.length - 1; i >= 0; i--)
111: handler.endPrefixMapping(prefixes[i]);
112: }
113:
114: public void text(String s) throws SAXException {
115: try {
116: handler.characters(s.toCharArray(), 0, s.length());
117: } catch (SAXException e) {
118: error(e);
119: }
120: }
121:
122: private void error(SAXException e) throws SAXException {
123: context.handleEvent(
124: new ValidationEventImpl(ValidationEvent.ERROR, e
125: .getMessage(), new ValidationEventLocatorImpl(
126: context.getLocator()), e), false);
127: }
128:
129: public void leaveChild(int nextState) throws SAXException {
130: }
131: }
|