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: * KeyrefHandler purpose.
028: *
029: * <p>
030: * represents a 'keyref' element. This class is not currently used asside from
031: * as 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/KeyrefHandler.java $
038: * @version $Id: KeyrefHandler.java 22266 2006-10-19 11:30:55Z acuster $
039: */
040: public class KeyrefHandler extends XSIElementHandler {
041: /** 'keyref' */
042: public final static String LOCALNAME = "keyref";
043: private String id;
044: private String name;
045: private String refer; //TODO check for referential support when using this type
046: private SelectorHandler selector;
047: private List fields;
048:
049: /**
050: * @see java.lang.Object#hashCode()
051: */
052: public int hashCode() {
053: return LOCALNAME.hashCode()
054: * ((id == null) ? 1 : id.hashCode())
055: * ((refer == null) ? 1 : refer.hashCode())
056: * ((name == null) ? 1 : name.hashCode());
057: }
058:
059: /**
060: * @see org.geotools.xml.XSIElementHandler#getHandler(java.lang.String,
061: * java.lang.String)
062: */
063: public XSIElementHandler getHandler(String namespaceURI,
064: String localName) throws SAXException {
065: if (SchemaHandler.namespaceURI.equalsIgnoreCase(namespaceURI)) {
066: // child types
067: //
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: name = atts.getValue("", "name");
111:
112: if (name == null) {
113: name = atts.getValue(namespaceURI, "name");
114: }
115:
116: refer = atts.getValue("", "refer");
117:
118: if (refer == null) {
119: refer = atts.getValue(namespaceURI, "refer");
120: }
121: }
122:
123: /**
124: * @see org.geotools.xml.XSIElementHandler#getLocalName()
125: */
126: public String getLocalName() {
127: return LOCALNAME;
128: }
129:
130: /**
131: * <p>
132: * returns a list of child field elements
133: * </p>
134: *
135: */
136: public List getFields() {
137: return fields;
138: }
139:
140: /**
141: * <p>
142: * returns the id attribute
143: * </p>
144: *
145: */
146: public String getId() {
147: return id;
148: }
149:
150: /**
151: * <p>
152: * returns the name attribute
153: * </p>
154: *
155: */
156: public String getName() {
157: return name;
158: }
159:
160: /**
161: * <p>
162: * returns the refer attribute
163: * </p>
164: *
165: */
166: public String getRefer() {
167: return refer;
168: }
169:
170: /**
171: * <p>
172: * returns the child selector element
173: * </p>
174: *
175: */
176: public SelectorHandler getSelector() {
177: return selector;
178: }
179:
180: /**
181: * @see org.geotools.xml.XSIElementHandler#getHandlerType()
182: */
183: public int getHandlerType() {
184: return DEFAULT;
185: }
186:
187: /**
188: * @see org.geotools.xml.XSIElementHandler#endElement(java.lang.String,
189: * java.lang.String)
190: */
191: public void endElement(String namespaceURI, String localName) {
192: // do nothing
193: }
194: }
|