001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.xml;
017:
018: import java.io.Serializable;
019: import java.net.URI;
020: import java.util.Map;
021: import java.util.logging.Level;
022: import java.util.logging.Logger;
023:
024: import javax.naming.OperationNotSupportedException;
025:
026: import org.geotools.xml.schema.Element;
027: import org.xml.sax.Attributes;
028: import org.xml.sax.SAXException;
029: import org.xml.sax.SAXNotSupportedException;
030:
031: /**
032: * XSIElementHandler purpose.
033: *
034: * <p>
035: * This abstract class is intended to act as both a definition of a generic
036: * handler.
037: * </p>
038: *
039: * @author dzwiers, Refractions Research, Inc. http://www.refractions.net
040: * @author $Author:$ (last modification)
041: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/XMLElementHandler.java $
042: * @version $Id: XMLElementHandler.java 27862 2007-11-12 19:51:19Z desruisseaux $
043: */
044: public abstract class XMLElementHandler implements Serializable {
045: /**
046: * the logger -- should be used for debugging (assuming there are bugs LOL)
047: */
048: protected final static Logger logger = org.geotools.util.logging.Logging
049: .getLogger("net.refractions.xml.element");
050:
051: /**
052: * Creates a new XSIElementHandler object. Intended to limit creation to
053: * the sub-packages
054: */
055: protected XMLElementHandler() {
056: // do nothing
057: }
058:
059: /**
060: * This method throws a SAXNotSupportedException if it is called and not
061: * overwritten. When overridding this method, you should be careful to
062: * understand that it may be called more than once per element. Therefore
063: * it would be advisable to log the text and handle the text's
064: * interpretation at a later time (
065: *
066: * @param text
067: *
068: * @throws SAXException
069: * @throws SAXNotSupportedException
070: *
071: * @see endElement(String,String)).
072: */
073: public void characters(String text) throws SAXException {
074: throw new SAXNotSupportedException(
075: "Should overide this method.");
076: }
077:
078: /**
079: * handles SAX end Element events. This matches the end of the element
080: * declaration in the document ... and responds to the event generated by
081: * the SAX parser. This is an opportunity to complete some
082: * post-processing.
083: *
084: * @param namespaceURI
085: * @param localName
086: * @param hints DOCUMENT ME!
087: *
088: * @throws SAXException
089: * @throws OperationNotSupportedException
090: *
091: * @see SchemaContentHandler#endElement
092: */
093: public abstract void endElement(URI namespaceURI, String localName,
094: Map hints) throws SAXException,
095: OperationNotSupportedException;
096:
097: /**
098: * handles SAX start Element events. This matches the start of the element
099: * declaration in the document ... and responds to the event generated by
100: * the SAX parser. This is an opportunity to complete some pre-processing.
101: *
102: * @param namespaceURI
103: * @param localName
104: * @param attr
105: *
106: * @throws SAXException
107: *
108: * @see SchemaContentHandler#startElement
109: */
110: public abstract void startElement(URI namespaceURI,
111: String localName, Attributes attr) throws SAXException;
112:
113: /**
114: * This will find an appropriate XMLElementHandler for the specified child
115: * if appropriate. This method may return or throw an exception, depending
116: * on the severity, if an error occurs. This method should be used to
117: * complete a SAX parse of a document for which the Schema is known, and
118: * parsed.
119: *
120: * @param namespaceURI
121: * @param localName
122: * @param hints DOCUMENT ME!
123: *
124: * @return XMLElementHandler, or null
125: *
126: * @throws SAXException
127: */
128: public abstract XMLElementHandler getHandler(URI namespaceURI,
129: String localName, Map hints) throws SAXException;
130:
131: /**
132: * This method will get the value of the element depending on it's type.
133: *
134: * @return Object (may be null)
135: *
136: * @throws SAXException
137: *
138: * @see Type#getValue
139: */
140: public abstract Object getValue() throws SAXException;
141:
142: /**
143: * This returns the name of the element being represented by this handler.
144: * This name matches the name specified in the Schema.
145: *
146: * @return The Name (may not be null)
147: */
148: public abstract String getName();
149:
150: /**
151: * This returns the Element specified.
152: *
153: * @return Element (may not be null)
154: */
155: public abstract Element getElement();
156:
157: /**
158: * <p>
159: * Sets the logger level for all XMLElementHandlers.
160: * </p>
161: *
162: * @param l
163: */
164: public static void setLogLevel(Level l) {
165: logger.setLevel(l);
166: }
167: }
|