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 org.geotools.xml.XSIElementHandler;
019: import org.xml.sax.Attributes;
020: import org.xml.sax.SAXException;
021: import org.xml.sax.SAXNotRecognizedException;
022:
023: /**
024: * ListHandler purpose.
025: *
026: * <p>
027: * represents a 'list' element
028: * </p>
029: *
030: * @author dzwiers, Refractions Research, Inc. http://www.refractions.net
031: * @author $Author:$ (last modification)
032: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/handlers/xsi/ListHandler.java $
033: * @version $Id: ListHandler.java 22266 2006-10-19 11:30:55Z acuster $
034: */
035: public class ListHandler extends XSIElementHandler {
036: /** 'list' */
037: public final static String LOCALNAME = "list";
038: private String id;
039: private String itemType;
040: private SimpleTypeHandler simpleType;
041:
042: /**
043: * @see java.lang.Object#hashCode()
044: */
045: public int hashCode() {
046: return LOCALNAME.hashCode()
047: * ((id == null) ? 1 : id.hashCode())
048: * ((itemType == null) ? 1 : itemType.hashCode());
049: }
050:
051: /**
052: * @see org.geotools.xml.XSIElementHandler#getHandler(java.lang.String,
053: * java.lang.String)
054: */
055: public XSIElementHandler getHandler(String namespaceURI,
056: String localName) throws SAXException {
057: if (SchemaHandler.namespaceURI.equalsIgnoreCase(namespaceURI)) {
058: // child types
059: //
060: // simpleType
061: if (SimpleTypeHandler.LOCALNAME.equalsIgnoreCase(localName)) {
062: SimpleTypeHandler sth = new SimpleTypeHandler();
063:
064: if (simpleType == null) {
065: simpleType = sth;
066: } else {
067: throw new SAXNotRecognizedException(getLocalName()
068: + " may only have one '"
069: + AllHandler.LOCALNAME + "' declaration.");
070: }
071:
072: return sth;
073: }
074: }
075:
076: return null;
077: }
078:
079: /**
080: * @see org.geotools.xml.XSIElementHandler#startElement(java.lang.String,
081: * java.lang.String, org.xml.sax.Attributes)
082: */
083: public void startElement(String namespaceURI, String localName,
084: Attributes atts) {
085: id = atts.getValue("", "id");
086:
087: if (id == null) {
088: id = atts.getValue(namespaceURI, "id");
089: }
090:
091: itemType = atts.getValue("", "itemType");
092:
093: if (itemType == null) {
094: itemType = atts.getValue(namespaceURI, "itemType");
095: }
096: }
097:
098: /**
099: * @see org.geotools.xml.XSIElementHandler#getLocalName()
100: */
101: public String getLocalName() {
102: return LOCALNAME;
103: }
104:
105: /**
106: * <p>
107: * returns the itemType attribute
108: * </p>
109: *
110: */
111: public String getItemType() {
112: return itemType;
113: }
114:
115: /**
116: * <p>
117: * returns the nested simpleType if one exists
118: * </p>
119: *
120: */
121: public SimpleTypeHandler getSimpleType() {
122: return simpleType;
123: }
124:
125: /**
126: * @see org.geotools.xml.XSIElementHandler#getHandlerType()
127: */
128: public int getHandlerType() {
129: return LIST;
130: }
131:
132: /**
133: * @see org.geotools.xml.XSIElementHandler#endElement(java.lang.String,
134: * java.lang.String)
135: */
136: public void endElement(String namespaceURI, String localName) {
137: // do nothing
138: }
139: }
|