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.util.logging.Level;
020: import java.util.logging.Logger;
021:
022: import org.xml.sax.Attributes;
023: import org.xml.sax.SAXException;
024: import org.xml.sax.SAXNotSupportedException;
025:
026: /**
027: * XSIElementHandler purpose.
028: *
029: * <p>
030: * This abstract class is intended to act as both a definition of what a
031: * generic handler is, and a default handler.
032: * </p>
033: *
034: * <p>
035: * When extending this class, one should as a minimum replace the start/end
036: * Element methods.
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/XSIElementHandler.java $
042: * @version $Id: XSIElementHandler.java 27862 2007-11-12 19:51:19Z desruisseaux $
043: */
044: public abstract class XSIElementHandler implements Serializable {
045: /**
046: * the logger -- should be used for debugging (assuming there are bugs LOL)
047: */
048: public final static Logger logger = org.geotools.util.logging.Logging
049: .getLogger("net.refractions.xsi.element");
050: private static Level level = Level.WARNING;
051:
052: /** Type constants */
053: public static final int DEFAULT = 0; // for those cases where type is not
054:
055: /** Type constants */
056: public static final int UNION = 1;
057:
058: /** Type constants */
059: public static final int LIST = 2;
060:
061: /** Type constants */
062: public static final int RESTRICTION = 4;
063:
064: /** Type constants */
065: public static final int EXTENSION = 64;
066:
067: /** Type constants */
068: public static final int SIMPLETYPE = 8;
069:
070: /** Type constants */
071: public static final int SEQUENCE = 16;
072:
073: /** Type constants */
074: public static final int FACET = 32;
075:
076: /**
077: * Creates a new XSIElementHandler object. Intended to limit creation to
078: * the sub-packages
079: */
080: protected XSIElementHandler() {
081: logger.setLevel(level);
082: }
083:
084: /**
085: * Returns one of the Specified types ... intended for use by the child
086: * packages only
087: *
088: * @return int (DEFAULT?)
089: */
090: public abstract int getHandlerType();
091:
092: /**
093: * In most cases this class should not be called within this framework as
094: * we do not intend to parse + store all the information required to
095: * recreate the exact Schema document being parsed. As a result,
096: * information such as annotations are ignored. When used, they method may
097: * be called multiple times for one element. This means the implementor
098: * should keep this in mind when overriding this method.
099: *
100: * @param text
101: *
102: * @throws SAXException
103: * @throws SAXNotSupportedException
104: */
105: public void characters(String text) throws SAXException {
106: throw new SAXNotSupportedException(
107: "Should overide this method.");
108: }
109:
110: /**
111: * handles SAX end Element events. this is an opportunity to complete some
112: * post-processing
113: *
114: * @param namespaceURI
115: * @param localName
116: *
117: * @throws SAXException
118: *
119: */
120: public abstract void endElement(String namespaceURI,
121: String localName) throws SAXException;
122:
123: /**
124: * handles SAX start Element events. This is an opportunity to complete
125: * some pre-processing.
126: *
127: * @param namespaceURI
128: * @param localName
129: * @param attr
130: *
131: * @throws SAXException
132: *
133: */
134: public abstract void startElement(String namespaceURI,
135: String localName, Attributes attr) throws SAXException;
136:
137: /**
138: * This method will be used to create the XSI document. Validation and
139: * in-fix processing is expected to exist within this method, along with
140: * data logging for post-processing. This method will directly affect the
141: * stack being used to complete the parse.
142: *
143: * @param namespaceURI
144: * @param localName
145: *
146: * @return XSIElementHandler, or null
147: *
148: * @throws SAXException
149: */
150: public abstract XSIElementHandler getHandler(String namespaceURI,
151: String localName) throws SAXException;
152:
153: /**
154: * Returns the LocalName for this element (ie this declaration in the
155: * Schema ... so ComplexType or Sequence ...)
156: *
157: * @return String (not-null)
158: */
159: public abstract String getLocalName();
160:
161: /**
162: * @see java.lang.Object#equals(java.lang.Object)
163: */
164: public boolean equals(Object obj) {
165: if (super .equals(obj)) {
166: return true;
167: }
168:
169: if (obj instanceof XSIElementHandler) {
170: XSIElementHandler ob = (XSIElementHandler) obj;
171:
172: if (getLocalName() != null) {
173: return getLocalName().equals(ob.getLocalName());
174: }
175:
176: return (null == ob.getLocalName());
177: }
178:
179: return false;
180: }
181:
182: /**
183: * @see java.lang.Object#hashCode()
184: */
185: public abstract int hashCode();
186:
187: /**
188: * <p>
189: * Sets the logging level for all XSIElementHandlers
190: * </p>
191: *
192: * @param l
193: */
194: public static void setLogLevel(Level l) {
195: level = l;
196: logger.setLevel(l);
197: }
198: }
|