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: * represtents a simpleContent 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/SimpleContentHandler.java $
030: */
031: public class SimpleContentHandler extends XSIElementHandler {
032: /** 'simpleContent' */
033: public static final String LOCALNAME = "simpleContent";
034:
035: // private String id;
036: private Object child;
037:
038: /**
039: * @see java.lang.Object#hashCode()
040: */
041: public int hashCode() {
042: return LOCALNAME.hashCode()
043: * ((child == null) ? 1 : child.hashCode());
044: }
045:
046: /**
047: * @see org.geotools.xml.XSIElementHandler#startElement(java.lang.String,
048: * java.lang.String, org.xml.sax.Attributes)
049: */
050: public void startElement(String namespaceURI, String localName,
051: Attributes atts) {
052: // do nothing
053: }
054:
055: /**
056: * @see org.geotools.xml.XSIElementHandler#getHandler(java.lang.String,
057: * java.lang.String)
058: */
059: public XSIElementHandler getHandler(String namespaceURI,
060: String localName) throws SAXException {
061: if (SchemaHandler.namespaceURI.equalsIgnoreCase(namespaceURI)) {
062: // child types
063: //
064: // extension
065: if (ExtensionHandler.LOCALNAME.equalsIgnoreCase(localName)) {
066: ExtensionHandler lh = new ExtensionHandler();
067:
068: if (child == null) {
069: child = lh;
070: } else {
071: throw new SAXNotRecognizedException(getLocalName()
072: + " may only have one child declaration.");
073: }
074:
075: return lh;
076: }
077:
078: // restriction
079: if (RestrictionHandler.LOCALNAME
080: .equalsIgnoreCase(localName)) {
081: RestrictionHandler lh = new RestrictionHandler();
082:
083: if (child == null) {
084: child = lh;
085: } else {
086: throw new SAXNotRecognizedException(getLocalName()
087: + " may only have one child declaration.");
088: }
089:
090: return lh;
091: }
092: }
093:
094: return null;
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 the Child element
108: */
109: public Object getChild() {
110: return child;
111: }
112:
113: /**
114: * @see org.geotools.xml.XSIElementHandler#getHandlerType()
115: */
116: public int getHandlerType() {
117: return DEFAULT;
118: }
119:
120: /**
121: * @see org.geotools.xml.XSIElementHandler#endElement(java.lang.String,
122: * java.lang.String)
123: */
124: public void endElement(String namespaceURI, String localName) {
125: // do nothing
126: }
127: }
|