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.geotools.xml.schema.Facet;
023: import org.xml.sax.Attributes;
024: import org.xml.sax.SAXException;
025: import org.xml.sax.SAXNotRecognizedException;
026:
027: /**
028: * RestrictionHandler purpose.
029: *
030: * <p>
031: * Represents a restriction element
032: * </p>
033: *
034: * @author dzwiers, Refractions Research, Inc. http://www.refractions.net
035: * @author $Author:$ (last modification)
036: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/handlers/xsi/RestrictionHandler.java $
037: * @version $Id: RestrictionHandler.java 22266 2006-10-19 11:30:55Z acuster $
038: */
039: public class RestrictionHandler extends XSIElementHandler {
040: /** 'restriction' */
041: public final static String LOCALNAME = "restriction";
042: private String id;
043: private String base;
044: private Object child;
045: private List constraints;
046: private List attrDecs;
047: private AnyAttributeHandler anyAttribute;
048:
049: /**
050: * @see java.lang.Object#hashCode()
051: */
052: public int hashCode() {
053: return LOCALNAME.hashCode()
054: * ((id == null) ? 1 : id.hashCode())
055: * ((base == null) ? 1 : base.hashCode());
056: }
057:
058: /**
059: * @see org.geotools.xml.XSIElementHandler#getHandler(java.lang.String,
060: * java.lang.String)
061: */
062: public XSIElementHandler getHandler(String namespaceURI,
063: String localName) throws SAXException {
064: if (SchemaHandler.namespaceURI.equalsIgnoreCase(namespaceURI)) {
065: // child types
066: //
067: // simpleType
068: if (SimpleTypeHandler.LOCALNAME.equalsIgnoreCase(localName)) {
069: SimpleTypeHandler sch = new SimpleTypeHandler();
070:
071: if (child == null) {
072: child = sch;
073: } else {
074: throw new SAXNotRecognizedException(getLocalName()
075: + " may only have one '"
076: + SimpleTypeHandler.LOCALNAME
077: + "' declaration.");
078: }
079:
080: return sch;
081: }
082:
083: // enumeration
084: if (EnumerationHandler.LOCALNAME
085: .equalsIgnoreCase(localName)) {
086: if (constraints == null) {
087: constraints = new LinkedList();
088: }
089:
090: EnumerationHandler eh = new EnumerationHandler();
091: constraints.add(eh);
092:
093: return eh;
094: }
095:
096: // fractionDigits
097: if (FractionDigitsHandler.LOCALNAME
098: .equalsIgnoreCase(localName)) {
099: if (constraints == null) {
100: constraints = new LinkedList();
101: }
102:
103: FractionDigitsHandler eh = new FractionDigitsHandler();
104: constraints.add(eh);
105:
106: return eh;
107: }
108:
109: // length
110: if (LengthHandler.LOCALNAME.equalsIgnoreCase(localName)) {
111: if (constraints == null) {
112: constraints = new LinkedList();
113: }
114:
115: LengthHandler eh = new LengthHandler();
116: constraints.add(eh);
117:
118: return eh;
119: }
120:
121: // minInclusive
122: if (MinInclusiveHandler.LOCALNAME
123: .equalsIgnoreCase(localName)) {
124: if (constraints == null) {
125: constraints = new LinkedList();
126: }
127:
128: MinInclusiveHandler eh = new MinInclusiveHandler();
129: constraints.add(eh);
130:
131: return eh;
132: }
133:
134: // maxInclusive
135: if (MaxInclusiveHandler.LOCALNAME
136: .equalsIgnoreCase(localName)) {
137: if (constraints == null) {
138: constraints = new LinkedList();
139: }
140:
141: MaxInclusiveHandler eh = new MaxInclusiveHandler();
142: constraints.add(eh);
143:
144: return eh;
145: }
146:
147: // minExclusive
148: if (MinExclusiveHandler.LOCALNAME
149: .equalsIgnoreCase(localName)) {
150: if (constraints == null) {
151: constraints = new LinkedList();
152: }
153:
154: MinExclusiveHandler eh = new MinExclusiveHandler();
155: constraints.add(eh);
156:
157: return eh;
158: }
159:
160: // maxExclusive
161: if (MaxExclusiveHandler.LOCALNAME
162: .equalsIgnoreCase(localName)) {
163: if (constraints == null) {
164: constraints = new LinkedList();
165: }
166:
167: MaxExclusiveHandler eh = new MaxExclusiveHandler();
168: constraints.add(eh);
169:
170: return eh;
171: }
172:
173: // maxLength
174: if (MaxLengthHandler.LOCALNAME.equalsIgnoreCase(localName)) {
175: if (constraints == null) {
176: constraints = new LinkedList();
177: }
178:
179: MaxLengthHandler eh = new MaxLengthHandler();
180: constraints.add(eh);
181:
182: return eh;
183: }
184:
185: // minLength
186: if (MinLengthHandler.LOCALNAME.equalsIgnoreCase(localName)) {
187: if (constraints == null) {
188: constraints = new LinkedList();
189: }
190:
191: MinLengthHandler eh = new MinLengthHandler();
192: constraints.add(eh);
193:
194: return eh;
195: }
196:
197: // pattern
198: if (PatternHandler.LOCALNAME.equalsIgnoreCase(localName)) {
199: if (constraints == null) {
200: constraints = new LinkedList();
201: }
202:
203: PatternHandler eh = new PatternHandler();
204: constraints.add(eh);
205:
206: return eh;
207: }
208:
209: // totalDigits
210: if (TotalDigitsHandler.LOCALNAME
211: .equalsIgnoreCase(localName)) {
212: if (constraints == null) {
213: constraints = new LinkedList();
214: }
215:
216: TotalDigitsHandler eh = new TotalDigitsHandler();
217: constraints.add(eh);
218:
219: return eh;
220: }
221:
222: // all
223: if (AllHandler.LOCALNAME.equalsIgnoreCase(localName)) {
224: AllHandler sch = new AllHandler();
225:
226: if (child == null) {
227: child = sch;
228: } else {
229: throw new SAXNotRecognizedException(getLocalName()
230: + " may only have one '"
231: + AllHandler.LOCALNAME + "' declaration.");
232: }
233:
234: return sch;
235: }
236:
237: // choice
238: if (ChoiceHandler.LOCALNAME.equalsIgnoreCase(localName)) {
239: ChoiceHandler sch = new ChoiceHandler();
240:
241: if (child == null) {
242: child = sch;
243: } else {
244: throw new SAXNotRecognizedException(getLocalName()
245: + " may only have one '"
246: + ChoiceHandler.LOCALNAME
247: + "' declaration.");
248: }
249:
250: return sch;
251: }
252:
253: // group
254: if (GroupHandler.LOCALNAME.equalsIgnoreCase(localName)) {
255: GroupHandler sch = new GroupHandler();
256:
257: if (child == null) {
258: child = sch;
259: } else {
260: throw new SAXNotRecognizedException(getLocalName()
261: + " may only have one '"
262: + GroupHandler.LOCALNAME + "' declaration.");
263: }
264:
265: return sch;
266: }
267:
268: // sequence
269: if (SequenceHandler.LOCALNAME.equalsIgnoreCase(localName)) {
270: SequenceHandler sch = new SequenceHandler();
271:
272: if (child == null) {
273: child = sch;
274: } else {
275: throw new SAXNotRecognizedException(getLocalName()
276: + " may only have one '"
277: + SequenceHandler.LOCALNAME
278: + "' declaration.");
279: }
280:
281: return sch;
282: }
283:
284: // attribute
285: if (AttributeHandler.LOCALNAME.equalsIgnoreCase(localName)) {
286: if (attrDecs == null) {
287: attrDecs = new LinkedList();
288: }
289:
290: AttributeHandler ah = new AttributeHandler();
291: attrDecs.add(ah);
292:
293: return ah;
294: }
295:
296: // attributeGroup
297: if (AttributeGroupHandler.LOCALNAME
298: .equalsIgnoreCase(localName)) {
299: if (attrDecs == null) {
300: attrDecs = new LinkedList();
301: }
302:
303: AttributeGroupHandler ah = new AttributeGroupHandler();
304: attrDecs.add(ah);
305:
306: return ah;
307: }
308:
309: // anyAttribute
310: if (AnyAttributeHandler.LOCALNAME
311: .equalsIgnoreCase(localName)) {
312: AnyAttributeHandler sch = new AnyAttributeHandler();
313:
314: if (anyAttribute == null) {
315: anyAttribute = sch;
316: } else {
317: throw new SAXNotRecognizedException(getLocalName()
318: + " may only have one '"
319: + AnyAttributeHandler.LOCALNAME
320: + "' declaration.");
321: }
322:
323: return sch;
324: }
325: }
326:
327: return null;
328: }
329:
330: /**
331: * @see org.geotools.xml.XSIElementHandler#startElement(java.lang.String,
332: * java.lang.String, org.xml.sax.Attributes)
333: */
334: public void startElement(String namespaceURI, String localName,
335: Attributes atts) {
336: id = atts.getValue("", "id");
337:
338: if (id == null) {
339: id = atts.getValue(namespaceURI, "id");
340: }
341:
342: base = atts.getValue("", "base");
343:
344: if (base == null) {
345: base = atts.getValue(namespaceURI, "base");
346: }
347: }
348:
349: /**
350: * @see org.geotools.xml.XSIElementHandler#getLocalName()
351: */
352: public String getLocalName() {
353: return LOCALNAME;
354: }
355:
356: /**
357: * <p>
358: * returns the AnyAttribute child element
359: * </p>
360: * TODO use this !
361: *
362: */
363: public AnyAttributeHandler getAnyAttribute() {
364: return anyAttribute;
365: }
366:
367: /**
368: * <p>
369: * returns the list of attribute declarations
370: * </p>
371: *
372: */
373: public List getAttributeDeclarations() {
374: return attrDecs;
375: }
376:
377: /**
378: * <p>
379: * Retusn the 'base' attribute
380: * </p>
381: *
382: */
383: public String getBase() {
384: return base;
385: }
386:
387: /**
388: * <p>
389: * Returns a list of Facets
390: * </p>
391: *
392: */
393: public List getConstraints() {
394: return constraints;
395: }
396:
397: /**
398: * <p>
399: * Returns the id attribute
400: * </p>
401: *
402: */
403: public String getId() {
404: return id;
405: }
406:
407: /**
408: * <p>
409: * Returns a nested child element declaration.
410: * </p>
411: *
412: * @return (ElementGroupingHandler or SimpleTypeHandler)
413: */
414: public Object getChild() {
415: return child;
416: }
417:
418: /**
419: * @see org.geotools.xml.XSIElementHandler#getHandlerType()
420: */
421: public int getHandlerType() {
422: return RESTRICTION;
423: }
424:
425: /**
426: * @see org.geotools.xml.XSIElementHandler#endElement(java.lang.String,
427: * java.lang.String)
428: */
429: public void endElement(String namespaceURI, String localName) {
430: // do nothing
431: }
432: }
433:
434: /**
435: * Represents an Enumeration element
436: *
437: * @author $author$
438: * @version $Revision: 1.9 $
439: */
440: class EnumerationHandler extends FacetHandler {
441: /** 'enumeration' */
442: public final static String LOCALNAME = "enumeration";
443:
444: /**
445: * @see org.geotools.xml.XSIHandlers.FacetHandler#getType()
446: */
447: public int getType() {
448: return Facet.ENUMERATION;
449: }
450:
451: /**
452: * @see org.geotools.xml.XSIElementHandler#getLocalName()
453: */
454: public String getLocalName() {
455: return LOCALNAME;
456: }
457: }
458:
459: /**
460: * Represents a FractionDigits element
461: *
462: * @author $author$
463: * @version $Revision: 1.9 $
464: */
465: class FractionDigitsHandler extends FacetHandler {
466: /** 'fractionDigits' */
467: public final static String LOCALNAME = "fractionDigits";
468:
469: /**
470: * @see org.geotools.xml.XSIHandlers.FacetHandler#getType()
471: */
472: public int getType() {
473: return Facet.FRACTIONDIGITS;
474: }
475:
476: /**
477: * @see org.geotools.xml.XSIElementHandler#getLocalName()
478: */
479: public String getLocalName() {
480: return LOCALNAME;
481: }
482: }
483:
484: /**
485: * Represents a Length element
486: *
487: * @author $author$
488: * @version $Revision: 1.9 $
489: */
490: class LengthHandler extends FacetHandler {
491: /** 'length' */
492: public final static String LOCALNAME = "length";
493:
494: /**
495: * @see org.geotools.xml.XSIHandlers.FacetHandler#getType()
496: */
497: public int getType() {
498: return Facet.LENGTH;
499: }
500:
501: /**
502: * @see org.geotools.xml.XSIElementHandler#getLocalName()
503: */
504: public String getLocalName() {
505: return LOCALNAME;
506: }
507: }
508:
509: /**
510: * Represents a MinInclusive element
511: *
512: * @author $author$
513: * @version $Revision: 1.9 $
514: */
515: class MinInclusiveHandler extends FacetHandler {
516: /** 'minInclusive' */
517: public final static String LOCALNAME = "minInclusive";
518:
519: /**
520: * @see org.geotools.xml.XSIHandlers.FacetHandler#getType()
521: */
522: public int getType() {
523: return Facet.MININCLUSIVE;
524: }
525:
526: /**
527: * @see org.geotools.xml.XSIElementHandler#getLocalName()
528: */
529: public String getLocalName() {
530: return LOCALNAME;
531: }
532: }
533:
534: /**
535: * Represents a MaxInclusive element
536: *
537: * @author $author$
538: * @version $Revision: 1.9 $
539: */
540: class MaxInclusiveHandler extends FacetHandler {
541: /** 'maxInclusive' */
542: public final static String LOCALNAME = "maxInclusive";
543:
544: /**
545: * @see org.geotools.xml.XSIHandlers.FacetHandler#getType()
546: */
547: public int getType() {
548: return Facet.MAXINCLUSIVE;
549: }
550:
551: /**
552: * @see org.geotools.xml.XSIElementHandler#getLocalName()
553: */
554: public String getLocalName() {
555: return LOCALNAME;
556: }
557: }
558:
559: /**
560: * represents a MinExclusive element
561: *
562: * @author $author$
563: * @version $Revision: 1.9 $
564: */
565: class MinExclusiveHandler extends FacetHandler {
566: /** 'minExclusive' */
567: public final static String LOCALNAME = "minExclusive";
568:
569: /**
570: * @see org.geotools.xml.XSIHandlers.FacetHandler#getType()
571: */
572: public int getType() {
573: return Facet.MINEXCLUSIVE;
574: }
575:
576: /**
577: * @see org.geotools.xml.XSIElementHandler#getLocalName()
578: */
579: public String getLocalName() {
580: return LOCALNAME;
581: }
582: }
583:
584: /**
585: * represents the MaxExclusive element
586: *
587: * @author $author$
588: * @version $Revision: 1.9 $
589: */
590: class MaxExclusiveHandler extends FacetHandler {
591: /** 'maxExclusive' */
592: public final static String LOCALNAME = "maxExclusive";
593:
594: /**
595: * @see org.geotools.xml.XSIHandlers.FacetHandler#getType()
596: */
597: public int getType() {
598: return Facet.MAXEXCLUSIVE;
599: }
600:
601: /**
602: * @see org.geotools.xml.XSIElementHandler#getLocalName()
603: */
604: public String getLocalName() {
605: return LOCALNAME;
606: }
607: }
608:
609: /**
610: * represents a minLength element
611: *
612: * @author $author$
613: * @version $Revision: 1.9 $
614: */
615: class MinLengthHandler extends FacetHandler {
616: /** 'minLength' */
617: public final static String LOCALNAME = "minLength";
618:
619: /**
620: * @see org.geotools.xml.XSIHandlers.FacetHandler#getType()
621: */
622: public int getType() {
623: return Facet.MINLENGTH;
624: }
625:
626: /**
627: * @see org.geotools.xml.XSIElementHandler#getLocalName()
628: */
629: public String getLocalName() {
630: return LOCALNAME;
631: }
632: }
633:
634: /**
635: * represents a maxLength element
636: *
637: * @author $author$
638: * @version $Revision: 1.9 $
639: */
640: class MaxLengthHandler extends FacetHandler {
641: /** 'maxLength' */
642: public final static String LOCALNAME = "maxLength";
643:
644: /**
645: * @see org.geotools.xml.XSIHandlers.FacetHandler#getType()
646: */
647: public int getType() {
648: return Facet.MAXLENGTH;
649: }
650:
651: /**
652: * @see org.geotools.xml.XSIElementHandler#getLocalName()
653: */
654: public String getLocalName() {
655: return LOCALNAME;
656: }
657: }
658:
659: /**
660: * represents a pattern element
661: *
662: * @author $author$
663: * @version $Revision: 1.9 $
664: */
665: class PatternHandler extends FacetHandler {
666: /** 'pattern' */
667: public final static String LOCALNAME = "pattern";
668:
669: /**
670: * @see org.geotools.xml.XSIHandlers.FacetHandler#getType()
671: */
672: public int getType() {
673: return Facet.PATTERN;
674: }
675:
676: /**
677: * @see org.geotools.xml.XSIElementHandler#getLocalName()
678: */
679: public String getLocalName() {
680: return LOCALNAME;
681: }
682: }
683:
684: /**
685: * Represents a totaldigits element
686: *
687: * @author $author$
688: * @version $Revision: 1.9 $
689: */
690: class TotalDigitsHandler extends FacetHandler {
691: /** 'totalDigits' */
692: public final static String LOCALNAME = "totalDigits";
693:
694: /**
695: * @see org.geotools.xml.XSIHandlers.FacetHandler#getType()
696: */
697: public int getType() {
698: return Facet.TOTALDIGITS;
699: }
700:
701: /**
702: * @see org.geotools.xml.XSIElementHandler#getLocalName()
703: */
704: public String getLocalName() {
705: return LOCALNAME;
706: }
707: }
|