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: import java.net.URISyntaxException;
020:
021: import org.geotools.xml.XSIElementHandler;
022: import org.xml.sax.Attributes;
023: import org.xml.sax.SAXException;
024:
025: /**
026: * ImportHandler purpose.
027: *
028: * <p>
029: * Represents an 'import' element.
030: * </p>
031: *
032: * @author dzwiers, Refractions Research, Inc. http://www.refractions.net
033: * @author $Author:$ (last modification)
034: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/handlers/xsi/ImportHandler.java $
035: * @version $Id: ImportHandler.java 22266 2006-10-19 11:30:55Z acuster $
036: */
037: public class ImportHandler extends XSIElementHandler {
038: /** 'import' */
039: public final static String LOCALNAME = "import";
040: private static int offset = 0;
041:
042: // private String id;
043: private URI namespace;
044: private URI schemaLocation;
045: private int hashCodeOffset = getOffset();
046:
047: /*
048: * helper method for hashCode()
049: */
050: private static int getOffset() {
051: return offset++;
052: }
053:
054: /**
055: * @see java.lang.Object#hashCode()
056: */
057: public int hashCode() {
058: return (LOCALNAME.hashCode() * ((schemaLocation == null) ? 1
059: : schemaLocation.hashCode()))
060: + hashCodeOffset;
061: }
062:
063: /**
064: * @see org.geotools.xml.XSIElementHandler#getHandler(java.lang.String,
065: * java.lang.String)
066: */
067: public XSIElementHandler getHandler(String namespaceURI,
068: String localName) {
069: return null;
070: }
071:
072: /**
073: * @see org.geotools.xml.XSIElementHandler#startElement(java.lang.String,
074: * java.lang.String, org.xml.sax.Attributes)
075: */
076: public void startElement(String namespaceURI, String localName,
077: Attributes atts) throws SAXException {
078: String sl = atts.getValue("", "schemaLocation");
079:
080: if (sl == null) {
081: sl = atts.getValue(namespaceURI, "schemaLocation");
082: }
083: try {
084: schemaLocation = sl != null ? new URI(sl) : null;
085: } catch (URISyntaxException e) {
086: logger.warning(e.toString());
087: throw new SAXException(e);
088: }
089:
090: String namespace1 = atts.getValue("", "namespace");
091:
092: if (namespace1 == null) {
093: namespace1 = atts.getValue(namespaceURI, "namespace");
094: }
095:
096: try {
097: this .namespace = new URI(namespace1);
098: } catch (URISyntaxException e) {
099: logger.warning(e.toString());
100: throw new SAXException(e);
101: }
102:
103: if (namespaceURI.equalsIgnoreCase(namespace1)) {
104: throw new SAXException(
105: "You may not import a namespace with the same name as the current namespace");
106: }
107: }
108:
109: /**
110: * @see org.geotools.xml.XSIElementHandler#getLocalName()
111: */
112: public String getLocalName() {
113: return LOCALNAME;
114: }
115:
116: /**
117: * <p>
118: * gets the namespace attribute
119: * </p>
120: *
121: */
122: public URI getNamespace() {
123: return namespace;
124: }
125:
126: /**
127: * <p>
128: * gets the schemaLocation attribute
129: * </p>
130: *
131: */
132: public URI getSchemaLocation() {
133: return schemaLocation;
134: }
135:
136: /**
137: * @see org.geotools.xml.XSIElementHandler#getHandlerType()
138: */
139: public int getHandlerType() {
140: return DEFAULT;
141: }
142:
143: /**
144: * @see org.geotools.xml.XSIElementHandler#endElement(java.lang.String,
145: * java.lang.String)
146: */
147: public void endElement(String namespaceURI, String localName) {
148: // do nothing
149: }
150: }
|