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: * UniqueHandler purpose.
028: *
029: * <p>
030: * represents a unique element. This class is not currently used except as a
031: * placeholder.
032: * </p>
033: * TODO used 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/UniqueHandler.java $
038: * @version $Id: UniqueHandler.java 20703 2006-07-24 16:57:44Z jgarnett $
039: */
040: public class UniqueHandler extends XSIElementHandler {
041: /** 'unique' */
042: public final static String LOCALNAME = "unique";
043: private String id;
044: private String xpath;
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: * ((xpath == null) ? 1 : xpath.hashCode())
055: * ((fields == null) ? 1 : fields.hashCode());
056: }
057:
058: /**
059: * @see org.geotools.xml.XSIElementHandler#getHandler(java.lang.String,
060: * java.lang.String)
061: */
062: public XSIElementHandler getHandler(String namespaceURI,
063: String localName) throws SAXException {
064: if (SchemaHandler.namespaceURI.equalsIgnoreCase(namespaceURI)) {
065: // child types
066: //
067: // annotation
068: // field
069: if (FieldHandler.LOCALNAME.equalsIgnoreCase(localName)) {
070: if (fields == null) {
071: fields = new LinkedList();
072: }
073:
074: FieldHandler fh = new FieldHandler();
075: fields.add(fh);
076:
077: return fh;
078: }
079:
080: // selector
081: if (SelectorHandler.LOCALNAME.equalsIgnoreCase(localName)) {
082: SelectorHandler sth = new SelectorHandler();
083:
084: if (selector == null) {
085: selector = sth;
086: } else {
087: throw new SAXNotRecognizedException(LOCALNAME
088: + " may only have one child.");
089: }
090:
091: return sth;
092: }
093: }
094:
095: return null;
096: }
097:
098: /**
099: * @see org.geotools.xml.XSIElementHandler#startElement(java.lang.String,
100: * java.lang.String, org.xml.sax.Attributes)
101: */
102: public void startElement(String namespaceURI, String localName,
103: Attributes atts) {
104: id = atts.getValue("", "id");
105:
106: if (id == null) {
107: id = atts.getValue(namespaceURI, "id");
108: }
109:
110: xpath = atts.getValue("", "xpath");
111:
112: if (xpath == null) {
113: xpath = atts.getValue(namespaceURI, "xpath");
114: }
115: }
116:
117: /**
118: * @see org.geotools.xml.XSIElementHandler#getLocalName()
119: */
120: public String getLocalName() {
121: return LOCALNAME;
122: }
123:
124: /**
125: * DOCUMENT ME!
126: *
127: * @return the id attribute value
128: */
129: public String getId() {
130: return id;
131: }
132:
133: /**
134: * DOCUMENT ME!
135: *
136: * @return the xpath attribute value
137: */
138: public String getXpath() {
139: return xpath;
140: }
141:
142: /**
143: * DOCUMENT ME!
144: *
145: * @return List of FieldHandlers representing sub-elements
146: */
147: public List getFields() {
148: return fields;
149: }
150:
151: /**
152: * DOCUMENT ME!
153: *
154: * @return the selector sub-element
155: */
156: public SelectorHandler getSelector() {
157: return selector;
158: }
159:
160: /**
161: * @see org.geotools.xml.XSIElementHandler#getHandlerType()
162: */
163: public int getHandlerType() {
164: return DEFAULT;
165: }
166:
167: /**
168: * @see org.geotools.xml.XSIElementHandler#endElement(java.lang.String,
169: * java.lang.String)
170: */
171: public void endElement(String namespaceURI, String localName) {
172: // do nothing
173: }
174: }
|