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: * RedefineHandler purpose.
026: *
027: * <p>
028: * represents a 'redefine' 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/RedefineHandler.java $
034: * @version $Id: RedefineHandler.java 22266 2006-10-19 11:30:55Z acuster $
035: */
036: public class RedefineHandler extends XSIElementHandler {
037: /** 'redefine' */
038: public final static String LOCALNAME = "redefine";
039: private static int offset = 0;
040: private String id;
041: private String schemaLocation;
042: private List simpleTypes;
043: private List complexTypes;
044: private List groups;
045: private List attributeGroups;
046: private int hashCodeOffset = getOffset();
047:
048: /*
049: * helper for hashCode();
050: */
051: private static int getOffset() {
052: return offset++;
053: }
054:
055: /**
056: * @see java.lang.Object#hashCode()
057: */
058: public int hashCode() {
059: return (LOCALNAME.hashCode()
060: * ((id == null) ? 1 : id.hashCode()) * ((schemaLocation == null) ? 1
061: : schemaLocation.hashCode()))
062: + hashCodeOffset;
063: }
064:
065: /**
066: * @see org.geotools.xml.XSIElementHandler#getHandler(java.lang.String,
067: * java.lang.String)
068: */
069: public XSIElementHandler getHandler(String namespaceURI,
070: String localName) {
071: if (SchemaHandler.namespaceURI.equalsIgnoreCase(namespaceURI)) {
072: // child types
073: //
074: // simpleType
075: if (SimpleTypeHandler.LOCALNAME.equalsIgnoreCase(localName)) {
076: if (simpleTypes == null) {
077: simpleTypes = new LinkedList();
078: }
079:
080: SimpleTypeHandler sth = new SimpleTypeHandler();
081: simpleTypes.add(sth);
082:
083: return sth;
084: }
085:
086: // complexType
087: if (ComplexTypeHandler.LOCALNAME
088: .equalsIgnoreCase(localName)) {
089: if (complexTypes == null) {
090: complexTypes = new LinkedList();
091: }
092:
093: ComplexTypeHandler sth = new ComplexTypeHandler();
094: complexTypes.add(sth);
095:
096: return sth;
097: }
098:
099: // group
100: if (GroupHandler.LOCALNAME.equalsIgnoreCase(localName)) {
101: if (groups == null) {
102: groups = new LinkedList();
103: }
104:
105: GroupHandler sth = new GroupHandler();
106: groups.add(sth);
107:
108: return sth;
109: }
110:
111: // attributeGroup
112: if (AttributeGroupHandler.LOCALNAME
113: .equalsIgnoreCase(localName)) {
114: if (attributeGroups == null) {
115: attributeGroups = new LinkedList();
116: }
117:
118: AttributeGroupHandler sth = new AttributeGroupHandler();
119: attributeGroups.add(sth);
120:
121: return sth;
122: }
123: }
124:
125: return null;
126: }
127:
128: /**
129: * @see org.geotools.xml.XSIElementHandler#startElement(java.lang.String,
130: * java.lang.String, org.xml.sax.Attributes)
131: */
132: public void startElement(String namespaceURI, String localName,
133: Attributes atts) {
134: id = atts.getValue("", "id");
135:
136: if (id == null) {
137: id = atts.getValue(namespaceURI, "id");
138: }
139:
140: schemaLocation = atts.getValue("", "schemaLocation");
141:
142: if (schemaLocation == null) {
143: schemaLocation = atts.getValue(namespaceURI,
144: "schemaLocation");
145: }
146: }
147:
148: /**
149: * @see org.geotools.xml.XSIElementHandler#getLocalName()
150: */
151: public String getLocalName() {
152: return LOCALNAME;
153: }
154:
155: /**
156: * <p>
157: * Returns a list of AttributeGroupHandlers
158: * </p>
159: *
160: */
161: public List getAttributeGroups() {
162: return attributeGroups;
163: }
164:
165: /**
166: * <p>
167: * Returns a list of ComplexTypeHandlers
168: * </p>
169: *
170: */
171: public List getComplexTypes() {
172: return complexTypes;
173: }
174:
175: /**
176: * <p>
177: * Returns a list of GroupHandlers
178: * </p>
179: *
180: */
181: public List getGroups() {
182: return groups;
183: }
184:
185: /**
186: * <p>
187: * Returns the id attribute
188: * </p>
189: *
190: */
191: public String getId() {
192: return id;
193: }
194:
195: /**
196: * <p>
197: * Returns the schemaLocation attribute
198: * </p>
199: *
200: */
201: public String getSchemaLocation() {
202: return schemaLocation;
203: }
204:
205: /**
206: * <p>
207: * Returns a list of SimpleTypeHandlers
208: * </p>
209: *
210: */
211: public List getSimpleTypes() {
212: return simpleTypes;
213: }
214:
215: /**
216: * @see org.geotools.xml.XSIElementHandler#getHandlerType()
217: */
218: public int getHandlerType() {
219: return DEFAULT;
220: }
221:
222: /**
223: * @see org.geotools.xml.XSIElementHandler#endElement(java.lang.String,
224: * java.lang.String)
225: */
226: public void endElement(String namespaceURI, String localName) {
227: // do nothing
228: }
229: }
|