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.util.LinkedList;
019: import java.util.List;
020:
021: import org.geotools.xml.XSIElementHandler;
022: import org.xml.sax.Attributes;
023: import org.xml.sax.SAXException;
024: import org.xml.sax.SAXNotRecognizedException;
025:
026: /**
027: * KeyHandler purpose.
028: *
029: * <p>
030: * represents a 'key' element. This class is not currently used asside from as
031: * a placeholder.
032: * </p>
033: * TODO use this class semantically
034: *
035: * @author dzwiers, Refractions Research, Inc. http://www.refractions.net
036: * @author $Author:$ (last modification)
037: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/handlers/xsi/KeyHandler.java $
038: * @version $Id: KeyHandler.java 22266 2006-10-19 11:30:55Z acuster $
039: */
040: public class KeyHandler extends XSIElementHandler {
041: /** 'key' */
042: public final static String LOCALNAME = "key";
043: private String id;
044: private String name;
045: private SelectorHandler selector;
046: private List fields;
047:
048: /**
049: * @see java.lang.Object#hashCode()
050: */
051: public int hashCode() {
052: return LOCALNAME.hashCode()
053: * ((id == null) ? 1 : id.hashCode())
054: * ((name == null) ? 1 : name.hashCode());
055: }
056:
057: /**
058: * @see org.geotools.xml.XSIElementHandler#getHandler(java.lang.String,
059: * java.lang.String)
060: */
061: public XSIElementHandler getHandler(String namespaceURI,
062: String localName) throws SAXException {
063: if (SchemaHandler.namespaceURI.equalsIgnoreCase(namespaceURI)) {
064: // child types
065: //
066: // field
067: if (FieldHandler.LOCALNAME.equalsIgnoreCase(localName)) {
068: if (fields == null) {
069: fields = new LinkedList();
070: }
071:
072: FieldHandler fh = new FieldHandler();
073: fields.add(fh);
074:
075: return fh;
076: }
077:
078: // selector
079: if (SelectorHandler.LOCALNAME.equalsIgnoreCase(localName)) {
080: SelectorHandler sth = new SelectorHandler();
081:
082: if (selector == null) {
083: selector = sth;
084: } else {
085: throw new SAXNotRecognizedException(LOCALNAME
086: + " may only have one child.");
087: }
088:
089: return sth;
090: }
091: }
092:
093: return null;
094: }
095:
096: /**
097: * @see org.geotools.xml.XSIElementHandler#startElement(java.lang.String,
098: * java.lang.String, org.xml.sax.Attributes)
099: */
100: public void startElement(String namespaceURI, String localName,
101: Attributes atts) {
102: id = atts.getValue("", "id");
103:
104: if (id == null) {
105: id = atts.getValue(namespaceURI, "id");
106: }
107:
108: name = atts.getValue("", "name");
109:
110: if (name == null) {
111: name = atts.getValue(namespaceURI, "name");
112: }
113: }
114:
115: /**
116: * @see org.geotools.xml.XSIElementHandler#getLocalName()
117: */
118: public String getLocalName() {
119: return LOCALNAME;
120: }
121:
122: /**
123: * getFields purpose.
124: *
125: * <p>
126: * Returns a list of fields child declarations
127: * </p>
128: *
129: */
130: public List getFields() {
131: return fields;
132: }
133:
134: /**
135: * getId purpose.
136: *
137: * <p>
138: * returns the id attribute
139: * </p>
140: *
141: */
142: public String getId() {
143: return id;
144: }
145:
146: /**
147: * getName purpose.
148: *
149: * <p>
150: * returns the name attribute
151: * </p>
152: *
153: */
154: public String getName() {
155: return name;
156: }
157:
158: /**
159: * getSelector purpose.
160: *
161: * <p>
162: * returns the child selector element
163: * </p>
164: *
165: */
166: public SelectorHandler getSelector() {
167: return selector;
168: }
169:
170: /**
171: * @see org.geotools.xml.XSIElementHandler#getHandlerType()
172: */
173: public int getHandlerType() {
174: return DEFAULT;
175: }
176:
177: /**
178: * @see org.geotools.xml.XSIElementHandler#endElement(java.lang.String,
179: * java.lang.String)
180: */
181: public void endElement(String namespaceURI, String localName) {
182: // do nothing
183: }
184: }
|