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:
024: /**
025: * UnionHandler purpose.
026: *
027: * <p>
028: * represents a union element
029: * </p>
030: *
031: * @author dzwiers, Refractions Research, Inc. http://www.refractions.net
032: * @author $Author:$ (last modification)
033: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/handlers/xsi/UnionHandler.java $
034: * @version $Id: UnionHandler.java 20703 2006-07-24 16:57:44Z jgarnett $
035: */
036: public class UnionHandler extends XSIElementHandler {
037: /** 'union' */
038: public final static String LOCALNAME = "union";
039: private String id;
040: private String memberTypes;
041: private List simpleTypes;
042:
043: /**
044: * @see java.lang.Object#hashCode()
045: */
046: public int hashCode() {
047: return LOCALNAME.hashCode()
048: * ((id == null) ? 1 : id.hashCode())
049: * ((memberTypes == null) ? 1 : memberTypes.hashCode())
050: * ((simpleTypes == null) ? 1 : simpleTypes.hashCode());
051: }
052:
053: /**
054: * @see org.geotools.xml.XSIElementHandler#getHandler(java.lang.String,
055: * java.lang.String)
056: */
057: public XSIElementHandler getHandler(String namespaceURI,
058: String localName) {
059: if (SchemaHandler.namespaceURI.equalsIgnoreCase(namespaceURI)) {
060: // child types
061: //
062: // simpleType
063: if (SimpleTypeHandler.LOCALNAME.equalsIgnoreCase(localName)) {
064: if (simpleTypes == null) {
065: simpleTypes = new LinkedList();
066: }
067:
068: SimpleTypeHandler sth = new SimpleTypeHandler();
069: simpleTypes.add(sth);
070:
071: return sth;
072: }
073: }
074:
075: return null;
076: }
077:
078: /**
079: * @see org.geotools.xml.XSIElementHandler#startElement(java.lang.String,
080: * java.lang.String, org.xml.sax.Attributes)
081: */
082: public void startElement(String namespaceURI, String localName,
083: Attributes atts) {
084: id = atts.getValue("", "id");
085:
086: if (id == null) {
087: id = atts.getValue(namespaceURI, "id");
088: }
089:
090: memberTypes = atts.getValue("", "memberTypes");
091:
092: if (memberTypes == null) {
093: memberTypes = atts.getValue(namespaceURI, "memberTypes");
094: }
095: }
096:
097: /**
098: * @see org.geotools.xml.XSIElementHandler#getLocalName()
099: */
100: public String getLocalName() {
101: return LOCALNAME;
102: }
103:
104: /**
105: * DOCUMENT ME!
106: *
107: * @return memberTypes attribute value
108: */
109: public String getMemberTypes() {
110: return memberTypes;
111: }
112:
113: /**
114: * DOCUMENT ME!
115: *
116: * @return list of simpleTypeHandlers representing the nested simpleTypes
117: */
118: public List getSimpleTypes() {
119: return simpleTypes;
120: }
121:
122: /**
123: * @see org.geotools.xml.XSIElementHandler#getHandlerType()
124: */
125: public int getHandlerType() {
126: return UNION;
127: }
128:
129: /**
130: * @see org.geotools.xml.XSIElementHandler#endElement(java.lang.String,
131: * java.lang.String)
132: */
133: public void endElement(String namespaceURI, String localName) {
134: // do nothing
135: }
136: }
|