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.handlers.xsi;
017:
018: import java.net.URI;
019:
020: import org.geotools.xml.XSIElementHandler;
021: import org.geotools.xml.schema.Schema;
022: import org.xml.sax.Attributes;
023: import org.xml.sax.SAXException;
024: import org.xml.sax.SAXNotSupportedException;
025:
026: /**
027: * RootHandler purpose.
028: *
029: * <p>
030: * This is intended to bootstrap the schema parsing
031: * </p>
032: *
033: * @author dzwiers, Refractions Research, Inc. http://www.refractions.net
034: * @author $Author:$ (last modification)
035: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/handlers/xsi/RootHandler.java $
036: * @version $Id: RootHandler.java 22266 2006-10-19 11:30:55Z acuster $
037: */
038: public class RootHandler extends XSIElementHandler {
039: /** 'root' */
040: public final static String LOCALNAME = "root";
041: private SchemaHandler schema;
042: private URI uri;
043:
044: /*
045: * should not be called
046: */
047: private RootHandler() {
048: // do nothing
049: }
050:
051: /**
052: * Creates a new RootHandler object.
053: *
054: * @param uri
055: */
056: public RootHandler(URI uri) {
057: this .uri = uri;
058: schema = new SchemaHandler();
059: }
060:
061: /**
062: * @see java.lang.Object#hashCode()
063: */
064: public int hashCode() {
065: return LOCALNAME.hashCode()
066: * ((uri == null) ? 1 : uri.hashCode());
067: }
068:
069: /**
070: * @see org.geotools.xml.XSIElementHandler#getHandler(java.lang.String,
071: * java.lang.String)
072: */
073: public XSIElementHandler getHandler(String namespaceURI,
074: String localName) {
075: if (SchemaHandler.LOCALNAME.equalsIgnoreCase(localName)
076: && SchemaHandler.namespaceURI
077: .equalsIgnoreCase(namespaceURI)) {
078: if (schema == null) {
079: schema = new SchemaHandler();
080: }
081:
082: return schema;
083: }
084:
085: logger.warning("Starting schema with " + localName
086: + " element.");
087:
088: return null;
089: }
090:
091: /**
092: * @see org.geotools.xml.XSIElementHandler#startElement(java.lang.String,
093: * java.lang.String, org.xml.sax.Attributes)
094: */
095: public void startElement(String namespaceURI, String localName,
096: Attributes attr) throws SAXException {
097: throw new SAXNotSupportedException(
098: "Should never have elements at the root level");
099: }
100:
101: /**
102: * @see org.geotools.xml.XSIElementHandler#getLocalName()
103: */
104: public String getLocalName() {
105: return LOCALNAME;
106: }
107:
108: /**
109: * <p>
110: * intended to be called after the parse, this generates a Schema object
111: * from the schema which was parsed in.
112: * </p>
113: *
114: *
115: * @throws SAXException
116: */
117: public Schema getSchema() throws SAXException {
118: Schema s = schema.compress(uri);
119:
120: return s;
121: }
122:
123: /**
124: * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String,
125: * java.lang.String)
126: */
127: public void startPrefixMapping(String arg0, String arg1) {
128: schema.startPrefixMapping(arg0, arg1);
129: }
130:
131: /**
132: * @see org.geotools.xml.XSIElementHandler#getHandlerType()
133: */
134: public int getHandlerType() {
135: return DEFAULT;
136: }
137:
138: /**
139: * @see org.geotools.xml.XSIElementHandler#endElement(java.lang.String,
140: * java.lang.String)
141: */
142: public void endElement(String namespaceURI, String localName) {
143: // do nothing
144: }
145: }
|