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 org.geotools.xml.XSIElementHandler;
019: import org.xml.sax.Attributes;
020: import org.xml.sax.SAXException;
021: import org.xml.sax.SAXNotRecognizedException;
022:
023: /**
024: * <p>
025: * represents a complex content element
026: * </p>
027: *
028: * @author dzwiers www.refractions.net
029: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/handlers/xsi/ComplexContentHandler.java $
030: */
031: public class ComplexContentHandler extends XSIElementHandler {
032: /** 'complexContent' */
033: public static final String LOCALNAME = "complexContent";
034: private String id;
035: private String mixed;
036: private Object child;
037:
038: /**
039: * @see java.lang.Object#hashCode()
040: */
041: public int hashCode() {
042: return LOCALNAME.hashCode()
043: * ((id == null) ? 1 : id.hashCode())
044: * ((mixed == null) ? 2 : mixed.hashCode());
045: }
046:
047: /**
048: * @see org.geotools.xml.XSIElementHandler#startElement(java.lang.String,
049: * java.lang.String, org.xml.sax.Attributes)
050: */
051: public void startElement(String namespaceURI, String localName,
052: Attributes atts) {
053: id = atts.getValue("", "id");
054:
055: if (id == null) {
056: id = atts.getValue(namespaceURI, "id");
057: }
058:
059: mixed = atts.getValue("", "mixed");
060:
061: if (mixed == null) {
062: mixed = atts.getValue(namespaceURI, "mixed");
063: }
064: }
065:
066: /**
067: * @see org.geotools.xml.XSIElementHandler#getHandler(java.lang.String,
068: * java.lang.String)
069: */
070: public XSIElementHandler getHandler(String namespaceURI,
071: String localName) throws SAXException {
072: if (SchemaHandler.namespaceURI.equalsIgnoreCase(namespaceURI)) {
073: // child types
074: //
075: // extension
076: if (ExtensionHandler.LOCALNAME.equalsIgnoreCase(localName)) {
077: ExtensionHandler sth = new ExtensionHandler();
078:
079: if (child == null) {
080: child = sth;
081: } else {
082: throw new SAXNotRecognizedException(LOCALNAME
083: + " may only have one child declaration.");
084: }
085:
086: return sth;
087: }
088:
089: // restriction
090: if (RestrictionHandler.LOCALNAME
091: .equalsIgnoreCase(localName)) {
092: RestrictionHandler sth = new RestrictionHandler();
093:
094: if (child == null) {
095: child = sth;
096: } else {
097: throw new SAXNotRecognizedException(LOCALNAME
098: + " may only have one child declaration.");
099: }
100:
101: return sth;
102: }
103: }
104:
105: return null;
106: }
107:
108: /**
109: * <p>
110: * getter for the complexContent's child
111: * </p>
112: *
113: */
114: public Object getChild() {
115: return child;
116: }
117:
118: /**
119: * @see org.geotools.xml.XSIElementHandler#getLocalName()
120: */
121: public String getLocalName() {
122: return LOCALNAME;
123: }
124:
125: /**
126: * @see org.geotools.xml.XSIElementHandler#getHandlerType()
127: */
128: public int getHandlerType() {
129: return DEFAULT;
130: }
131:
132: /**
133: * @see org.geotools.xml.XSIElementHandler#endElement(java.lang.String,
134: * java.lang.String)
135: */
136: public void endElement(String namespaceURI, String localName) {
137: // do nothing
138: }
139: }
|