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: * <p>
028: * Represents an Extension element
029: * </p>
030: *
031: * @author dzwiers www.refractions.net
032: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/handlers/xsi/ExtensionHandler.java $
033: */
034: public class ExtensionHandler extends XSIElementHandler {
035: /** 'extension' */
036: public static final String LOCALNAME = "extension";
037: private String base;
038:
039: // private AnyAttributeHandler anyAttribute;
040: // TODO USE the anyAttribute !
041: private Object child;
042: private List attributeDec;
043:
044: /**
045: * @see java.lang.Object#hashCode()
046: */
047: public int hashCode() {
048: return LOCALNAME.hashCode()
049: * ((base == null) ? 1 : base.hashCode())
050: * ((child == null) ? 1 : child.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) throws SAXException {
059: if (SchemaHandler.namespaceURI.equalsIgnoreCase(namespaceURI)) {
060: // child types
061: //
062: logger.fine("Getting Handler for " + localName
063: + " inside Extension");
064:
065: // all
066: if (AllHandler.LOCALNAME.equalsIgnoreCase(localName)) {
067: AllHandler ah = new AllHandler();
068:
069: if (child == null) {
070: child = ah;
071: } else {
072: throw new SAXNotRecognizedException(getLocalName()
073: + " may only have one '"
074: + AllHandler.LOCALNAME + "' declaration.");
075: }
076:
077: return ah;
078: }
079: if (AttributeHandler.LOCALNAME.equalsIgnoreCase(localName)) {
080: if (attributeDec == null) {
081: attributeDec = new LinkedList();
082: }
083:
084: AttributeHandler ah = new AttributeHandler();
085: attributeDec.add(ah);
086:
087: return ah;
088: }
089:
090: // attributeGroup
091: if (AttributeGroupHandler.LOCALNAME
092: .equalsIgnoreCase(localName)) {
093: if (attributeDec == null) {
094: attributeDec = new LinkedList();
095: }
096:
097: AttributeGroupHandler ah = new AttributeGroupHandler();
098: attributeDec.add(ah);
099:
100: return ah;
101: }
102:
103: // choice
104: if (ChoiceHandler.LOCALNAME.equalsIgnoreCase(localName)) {
105: ChoiceHandler ah = new ChoiceHandler();
106:
107: if (child == null) {
108: child = ah;
109: } else {
110: throw new SAXNotRecognizedException(getLocalName()
111: + " may only have one '"
112: + ChoiceHandler.LOCALNAME
113: + "' declaration.");
114: }
115:
116: return ah;
117: }
118:
119: // group
120: if (GroupHandler.LOCALNAME.equalsIgnoreCase(localName)) {
121: GroupHandler ah = new GroupHandler();
122:
123: if (child == null) {
124: child = ah;
125: } else {
126: throw new SAXNotRecognizedException(getLocalName()
127: + " may only have one '"
128: + GroupHandler.LOCALNAME + "' declaration.");
129: }
130: return ah;
131: }
132:
133: // sequence
134: if (SequenceHandler.LOCALNAME.equalsIgnoreCase(localName)) {
135: SequenceHandler ah = new SequenceHandler();
136:
137: if (child == null) {
138: child = ah;
139: } else {
140: throw new SAXNotRecognizedException(getLocalName()
141: + " may only have one '"
142: + SequenceHandler.LOCALNAME
143: + "' declaration.");
144: }
145:
146: return ah;
147: }
148: }
149:
150: logger.info("Handler not found for " + localName
151: + " in Extension");
152:
153: return null;
154: }
155:
156: /**
157: * @see org.geotools.xml.XSIElementHandler#getLocalName()
158: */
159: public String getLocalName() {
160: return LOCALNAME;
161: }
162:
163: /**
164: * @see org.geotools.xml.XSIElementHandler#startElement(java.lang.String,
165: * java.lang.String, org.xml.sax.Attributes)
166: */
167: public void startElement(String namespaceURI, String localName,
168: Attributes atts) {
169: base = atts.getValue("", "base");
170:
171: if (base == null) {
172: base = atts.getValue(namespaceURI, "base");
173: }
174: }
175:
176: /**
177: * <p>
178: * gets a list of AttributeHandlers
179: * </p>
180: *
181: */
182: public List getAttributeDeclarations() {
183: return attributeDec;
184: }
185:
186: /**
187: * <p>
188: * Returns the 'base' attribute
189: * </p>
190: *
191: */
192: public String getBase() {
193: return base;
194: }
195:
196: /**
197: * <p>
198: * Returns the child handler
199: * </p>
200: *
201: */
202: public Object getChild() {
203: return child;
204: }
205:
206: /* (non-Javadoc)
207: * @see schema.XSIElementHandler#getHandlerType()
208: */
209: public int getHandlerType() {
210: return DEFAULT;
211: }
212:
213: /**
214: * @see org.geotools.xml.XSIElementHandler#endElement(java.lang.String,
215: * java.lang.String)
216: */
217: public void endElement(String namespaceURI, String localName) {
218: // do nothing
219: }
220: }
|