Source Code Cross Referenced for GMLComplexTypes.java in  » GIS » GeoTools-2.4.1 » org » geotools » xml » gml » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoTools 2.4.1 » org.geotools.xml.gml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:/*
0002: *    GeoTools - OpenSource mapping toolkit
0003: *    http://geotools.org
0004: *    (C) 2004-2006, GeoTools Project Managment Committee (PMC)
0005: *    
0006: *    This library is free software; you can redistribute it and/or
0007: *    modify it under the terms of the GNU Lesser General Public
0008: *    License as published by the Free Software Foundation;
0009: *    version 2.1 of the License.
0010: *
0011: *    This library is distributed in the hope that it will be useful,
0012: *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013: *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014: *    Lesser General Public License for more details.
0015: */
0016:package org.geotools.xml.gml;
0017:
0018:import java.io.IOException;
0019:import java.net.URI;
0020:import java.util.HashMap;
0021:import java.util.Iterator;
0022:import java.util.LinkedList;
0023:import java.util.List;
0024:import java.util.Map;
0025:import java.util.logging.Level;
0026:import java.util.logging.Logger;
0027:
0028:import javax.naming.OperationNotSupportedException;
0029:
0030:import org.geotools.data.DataUtilities;
0031:import org.geotools.feature.AttributeType;
0032:import org.geotools.feature.AttributeTypeFactory;
0033:import org.geotools.feature.Feature;
0034:import org.geotools.feature.FeatureCollection;
0035:import org.geotools.feature.FeatureIterator;
0036:import org.geotools.feature.FeatureType;
0037:import org.geotools.feature.FeatureTypeBuilder;
0038:import org.geotools.feature.GeometryAttributeType;
0039:import org.geotools.feature.IllegalAttributeException;
0040:import org.geotools.feature.SchemaException;
0041:import org.opengis.filter.Filter;
0042:import org.geotools.xml.PrintHandler;
0043:import org.geotools.xml.XMLHandlerHints;
0044:import org.geotools.xml.gml.FCBuffer.StopException;
0045:import org.geotools.xml.gml.GMLSchema.AttributeList;
0046:import org.geotools.xml.gml.GMLSchema.GMLAttribute;
0047:import org.geotools.xml.gml.GMLSchema.GMLComplexType;
0048:import org.geotools.xml.gml.GMLSchema.GMLElement;
0049:import org.geotools.xml.gml.GMLSchema.GMLNullType;
0050:import org.geotools.xml.schema.All;
0051:import org.geotools.xml.schema.Attribute;
0052:import org.geotools.xml.schema.Choice;
0053:import org.geotools.xml.schema.ComplexType;
0054:import org.geotools.xml.schema.Element;
0055:import org.geotools.xml.schema.ElementGrouping;
0056:import org.geotools.xml.schema.ElementValue;
0057:import org.geotools.xml.schema.Group;
0058:import org.geotools.xml.schema.Sequence;
0059:import org.geotools.xml.schema.SimpleType;
0060:import org.geotools.xml.schema.Type;
0061:import org.geotools.xml.xLink.XLinkSchema;
0062:import org.geotools.xml.xsi.XSISimpleTypes;
0063:import org.xml.sax.Attributes;
0064:import org.xml.sax.SAXException;
0065:import org.xml.sax.SAXNotSupportedException;
0066:import org.xml.sax.helpers.AttributesImpl;
0067:
0068:import com.vividsolutions.jts.geom.Coordinate;
0069:import com.vividsolutions.jts.geom.CoordinateSequence;
0070:import com.vividsolutions.jts.geom.DefaultCoordinateSequenceFactory;
0071:import com.vividsolutions.jts.geom.Envelope;
0072:import com.vividsolutions.jts.geom.Geometry;
0073:import com.vividsolutions.jts.geom.GeometryCollection;
0074:import com.vividsolutions.jts.geom.GeometryFactory;
0075:import com.vividsolutions.jts.geom.LineString;
0076:import com.vividsolutions.jts.geom.LinearRing;
0077:import com.vividsolutions.jts.geom.MultiLineString;
0078:import com.vividsolutions.jts.geom.MultiPoint;
0079:import com.vividsolutions.jts.geom.MultiPolygon;
0080:import com.vividsolutions.jts.geom.Point;
0081:import com.vividsolutions.jts.geom.Polygon;
0082:
0083:
0084:/**
0085: * This class is intended to act as a collection of package visible GML
0086: * complexType definition to be used by the GMLSchema
0087: *
0088: * @author $author$
0089: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/gml/GMLComplexTypes.java $
0090: * @version $Revision: 1.9 $
0091: *
0092: * @see GMLSchema
0093: * @see ComplexType
0094: */
0095:public class GMLComplexTypes {
0096:    // used for debugging
0097:    protected static Logger logger = getLogger();
0098:
0099:    /**
0100:     * Returns the logger to be used for this class.
0101:     *
0102:     * @todo Logger.setLevel(...) should not be invoked, because it override any user setting in
0103:     *       {@code jre/lib/logging.properties}. Users should edit their properties file instead.
0104:     *       If Geotools is too verbose below the warning level, then some log messages should
0105:     *       probably be changed from Level.INFO to Level.FINE.
0106:     *
0107:     * @todo The logger package should probably be {@code "org.geotools.xml.gml"}.
0108:     */
0109:    private static final Logger getLogger(){
0110:    	Logger l = org.geotools.util.logging.Logging.getLogger("net.refractions.gml.static");
0111:    	l.setLevel(Level.WARNING);
0112:    	return l;
0113:    }
0114:
0115:
0116:    private static final String STREAM_FEATURE_NAME_HINT = "org.geotools.xml.gml.STREAM_FEATURE_NAME_HINT";
0117:
0118:    static void encode(Element e, Geometry g, PrintHandler output)
0119:        throws OperationNotSupportedException, IOException {
0120:        if (g instanceof  Point) {
0121:            encode(e, (Point) g, output);
0122:
0123:            return;
0124:        }
0125:
0126:        if (g instanceof  Polygon) {
0127:            encode(e, (Polygon) g, output);
0128:
0129:            return;
0130:        }
0131:
0132:        if (g instanceof  LinearRing) {
0133:            encode(e, (LinearRing) g, output);
0134:
0135:            return;
0136:        }
0137:
0138:        if (g instanceof  LineString) {
0139:            encode(e, (LineString) g, output);
0140:
0141:            return;
0142:        }
0143:
0144:        if (g instanceof  MultiLineString) {
0145:            encode(e, (MultiLineString) g, output);
0146:
0147:            return;
0148:        }
0149:
0150:        if (g instanceof  MultiPolygon) {
0151:            encode(e, (MultiPolygon) g, output);
0152:
0153:            return;
0154:        }
0155:
0156:        if (g instanceof  MultiPoint) {
0157:            encode(e, (MultiPoint) g, output);
0158:
0159:            return;
0160:        }
0161:
0162:        if (g instanceof  GeometryCollection) {
0163:            encode(e, (GeometryCollection) g, output);
0164:
0165:            return;
0166:        }
0167:    }
0168:
0169:    static void encode(Element e, Point g, PrintHandler output)
0170:        throws IOException {
0171:        if ((g == null) || (g.getCoordinate() == null)) {
0172:        	throw new IOException("Bad Point Data");
0173:        }
0174:
0175:        AttributesImpl ai = new AttributesImpl();
0176:
0177:        // no GID
0178:        if (g.getUserData() != null) {
0179:            // TODO Fix this when parsing is better ... should be a coord reference system
0180:            ai.addAttribute("", "srsName", "", "anyURI",
0181:                g.getUserData().toString());
0182:        } else {
0183://            if (g.getSRID() != 0) {
0184://                // deprecated version
0185://                ai.addAttribute("", "srsName", "", "anyURI", "" + g.getSRID());
0186://            } else {
0187:                ai = null;
0188://            }
0189:        }
0190:
0191:        if (e == null) {
0192:            output.startElement(GMLSchema.NAMESPACE, "Point", ai);
0193:        } else {
0194:            output.startElement(e.getNamespace(), e.getName(), ai);
0195:        }
0196:
0197:        encodeCoords(null, g.getCoordinates(), output);
0198:
0199:        if (e == null) {
0200:            output.endElement(GMLSchema.NAMESPACE, "Point");
0201:        } else {
0202:            output.endElement(e.getNamespace(), e.getName());
0203:        }
0204:    }
0205:
0206:    static void encode(Element e, LineString g, PrintHandler output)
0207:        throws IOException {
0208:        if ((g == null) || (g.getNumPoints() == 0)) {
0209:        	throw new IOException("Bad LineString Data");
0210:        }
0211:
0212:        AttributesImpl ai = new AttributesImpl();
0213:
0214:        // no GID
0215:        if (g.getUserData() != null) {
0216:            // TODO Fix this when parsing is better ... should be a coord reference system
0217:            ai.addAttribute("", "srsName", "", "anyURI",
0218:                g.getUserData().toString());
0219:        } else {
0220://            if (g.getSRID() != 0) {
0221://                // deprecated version
0222://                ai.addAttribute("", "srsName", "", "anyURI", "" + g.getSRID());
0223://            } else {
0224:                ai = null;
0225://            }
0226:        }
0227:
0228:        if (e == null) {
0229:            output.startElement(GMLSchema.NAMESPACE, "LineString", ai);
0230:        } else {
0231:            output.startElement(e.getNamespace(), e.getName(), ai);
0232:        }
0233:
0234:        encodeCoords(null, g.getCoordinates(), output);
0235:
0236:        if (e == null) {
0237:            output.endElement(GMLSchema.NAMESPACE, "LineString");
0238:        } else {
0239:            output.endElement(e.getNamespace(), e.getName());
0240:        }
0241:    }
0242:
0243:    static void encode(Element e, LinearRing g, PrintHandler output)
0244:        throws IOException {
0245:        if ((g == null) || (g.getNumPoints() == 0)) {
0246:        	throw new IOException("Bad LinearRing Data");
0247:        }
0248:
0249:        if (e == null) {
0250:            encode(((GMLSchema.getInstance()).getElements()[39]), (LineString) g, output);
0251:        } else {
0252:            encode(e, (LineString) g, output);
0253:        }
0254:    }
0255:
0256:    static void encode(Element e, Polygon g, PrintHandler output)
0257:        throws OperationNotSupportedException, IOException {
0258:        if ((g == null) || (g.getNumPoints() == 0)) {
0259:        	throw new IOException("Bad Polygon Data");
0260:        }
0261:
0262:        AttributesImpl ai = new AttributesImpl();
0263:
0264:        // no GID
0265:        if (g.getUserData() != null) {
0266:            // TODO Fix this when parsing is better ... should be a coord reference system
0267:            ai.addAttribute("", "srsName", "", "anyURI",
0268:                g.getUserData().toString());
0269:        } else {
0270://            if (g.getSRID() != 0) {
0271://                // deprecated version
0272://                ai.addAttribute("", "srsName", "", "anyURI", "" + g.getSRID());
0273://            } else {
0274:                ai = null;
0275://            }
0276:        }
0277:
0278:        if (e == null) {
0279:            output.startElement(GMLSchema.NAMESPACE, "Polygon", ai);
0280:        } else {
0281:            output.startElement(e.getNamespace(), e.getName(), ai);
0282:        }
0283:
0284:        ((GMLSchema.getInstance()).getElements()[35]).getType().encode((GMLSchema.getInstance()).getElements()[35],g.getExteriorRing(),output,null);
0285:
0286:        if (g.getNumInteriorRing() > 0) {
0287:            for (int i = 0; i < g.getNumInteriorRing(); i++)
0288:            	((GMLSchema.getInstance()).getElements()[36]).getType().encode((GMLSchema.getInstance()).getElements()[36],g.getInteriorRingN(i),output,null);
0289:        }
0290:
0291:        if (e == null) {
0292:            output.endElement(GMLSchema.NAMESPACE, "Polygon");
0293:        } else {
0294:            output.endElement(e.getNamespace(), e.getName());
0295:        }
0296:    }
0297:
0298:    static void encode(Element e, MultiPoint g, PrintHandler output)
0299:        throws IOException {
0300:        if ((g == null) || (g.getNumGeometries() <= 0)) {
0301:        	throw new IOException("Bad MultiPoint Data");
0302:        }
0303:
0304:        AttributesImpl ai = new AttributesImpl();
0305:
0306:        // 	no GID
0307:        if (g.getUserData() != null) {
0308:            ai.addAttribute("", "srsName", "", "anyURI",
0309:                g.getUserData().toString());
0310:        } else {
0311:            if (g.getSRID() != 0) {
0312:                // deprecated version
0313:                ai.addAttribute("", "srsName", "", "anyURI", "" + g.getSRID());
0314:            } else {
0315:            	throw new IOException("srsName required for MultiPoint "+e.getName());
0316:            }
0317:        }
0318:
0319:        if (e == null) {
0320:            output.startElement(GMLSchema.NAMESPACE, "MultiPoint", ai);
0321:        } else {
0322:            output.startElement(e.getNamespace(), e.getName(), ai);
0323:        }
0324:
0325:        for (int i = 0; i < g.getNumGeometries(); i++) {
0326:            output.startElement(GMLSchema.NAMESPACE, "pointMember", null);
0327:            encode(null, (Point) g.getGeometryN(i), output);
0328:            output.endElement(GMLSchema.NAMESPACE, "pointMember");
0329:        }
0330:
0331:        if (e == null) {
0332:            output.endElement(GMLSchema.NAMESPACE, "MultiPoint");
0333:        } else {
0334:            output.endElement(e.getNamespace(), e.getName());
0335:        }
0336:    }
0337:
0338:    static void encode(Element e, MultiLineString g, PrintHandler output)
0339:        throws IOException {
0340:
0341:        if ((g == null) || g.getNumGeometries() <= 0) {
0342:        	throw new IOException("Bad MultiLineString Data");
0343:        }
0344:
0345:        AttributesImpl ai = new AttributesImpl();
0346:
0347:        // 	no GID
0348:        if (g.getUserData() != null) {
0349:            ai.addAttribute("", "srsName", "", "anyURI",
0350:                g.getUserData().toString());
0351:        } else {
0352:            if (g.getSRID() != 0) {
0353:                // deprecated version
0354:                ai.addAttribute("", "srsName", "", "anyURI", "" + g.getSRID());
0355:            } else {
0356:            	throw new IOException("srsName required for MultiPoint "+(e==null?"":e.getName()));
0357:            }
0358:        }
0359:
0360:        if (e == null) {
0361:            output.startElement(GMLSchema.NAMESPACE, "MultiLineString", ai);
0362:        } else {
0363:            output.startElement(e.getNamespace(), e.getName(), ai);
0364:        }
0365:
0366:        for (int i = 0; i < g.getNumGeometries(); i++) {
0367:            output.startElement(GMLSchema.NAMESPACE, "lineStringMember", null);
0368:            encode(null, (LineString) g.getGeometryN(i), output);
0369:            output.endElement(GMLSchema.NAMESPACE, "lineStringMember");
0370:        }
0371:
0372:        if (e == null) {
0373:            output.endElement(GMLSchema.NAMESPACE, "MultiLineString");
0374:        } else {
0375:            output.endElement(e.getNamespace(), e.getName());
0376:        }
0377:    }
0378:
0379:    static void encode(Element e, MultiPolygon g, PrintHandler output)
0380:        throws OperationNotSupportedException, IOException {
0381:        if ((g == null) || (g.getNumGeometries() <= 0)) {
0382:        	throw new IOException("Bad MultiPolygon Data");
0383:        }
0384:
0385:        AttributesImpl ai = new AttributesImpl();
0386:
0387:        // 	no GID
0388:        if (g.getUserData() != null) {
0389:            ai.addAttribute("", "srsName", "", "anyURI",
0390:                g.getUserData().toString());
0391:        } else {
0392:            if (g.getSRID() != 0) {
0393:                // deprecated version
0394:                ai.addAttribute("", "srsName", "", "anyURI", "" + g.getSRID());
0395:            } else {
0396:            	throw new IOException("srsName required for MultiPoint "+e.getName());
0397:            }
0398:        }
0399:
0400:        if (e == null) {
0401:            output.startElement(GMLSchema.NAMESPACE, "MultiPolygon", ai);
0402:        } else {
0403:            output.startElement(e.getNamespace(), e.getName(), ai);
0404:        }
0405:
0406:        for (int i = 0; i < g.getNumGeometries(); i++) {
0407:            output.startElement(GMLSchema.NAMESPACE, "polygonMember", null);
0408:            encode(null, (Polygon) g.getGeometryN(i), output);
0409:            output.endElement(GMLSchema.NAMESPACE, "polygonMember");
0410:        }
0411:
0412:        if (e == null) {
0413:            output.endElement(GMLSchema.NAMESPACE, "MultiPolygon");
0414:        } else {
0415:            output.endElement(e.getNamespace(), e.getName());
0416:        }
0417:    }
0418:
0419:    static void encode(Element e, GeometryCollection g, PrintHandler output)
0420:        throws OperationNotSupportedException, IOException {
0421:        if ((g == null) || (g.getNumGeometries() <= 0)) {
0422:        	throw new IOException("Bad GeometryCollection Data");
0423:        }
0424:
0425:        AttributesImpl ai = new AttributesImpl();
0426:
0427:        // 	no GID
0428:        if (g.getUserData() != null) {
0429:            // TODO Fix this when parsing is better ... should be a coord reference system
0430:            ai.addAttribute("", "srsName", "", "anyURI",
0431:                g.getUserData().toString());
0432:        } else {
0433://            if (g.getSRID() != 0) {
0434://                // deprecated version
0435://                ai.addAttribute("", "srsName", "", "anyURI", "" + g.getSRID());
0436://            } else {
0437:                ai = null;
0438://            }
0439:        }
0440:
0441:        if (e == null) {
0442:            output.startElement(GMLSchema.NAMESPACE, "MultiGeometry", ai);
0443:        } else {
0444:            output.startElement(e.getNamespace(), e.getName(), ai);
0445:        }
0446:
0447:        for (int i = 0; i < g.getNumGeometries(); i++) {
0448:            output.startElement(GMLSchema.NAMESPACE, "geometryMember", null);
0449:            encode(null, (Polygon) g.getGeometryN(i), output);
0450:            output.endElement(GMLSchema.NAMESPACE, "geometryMember");
0451:        }
0452:
0453:        if (e == null) {
0454:            output.endElement(GMLSchema.NAMESPACE, "MultiGeometry");
0455:        } else {
0456:            output.endElement(e.getNamespace(), e.getName());
0457:        }
0458:    }
0459:
0460:    static void encodeCoord(Element e, Coordinate coord, PrintHandler output)
0461:        throws IOException {
0462:        if (coord == null) {
0463:            return;
0464:        }
0465:
0466:        AttributesImpl ai = new AttributesImpl();
0467:        ai.addAttribute("", "X", "", "decimal", "" + coord.x);
0468:        ai.addAttribute("", "Y", "", "decimal", "" + coord.y);
0469:
0470:        if (coord.z != Double.NaN) {
0471:            ai.addAttribute("", "Z", "", "decimal", "" + coord.z);
0472:        }
0473:
0474:        if (e == null) {
0475:            output.element(GMLSchema.NAMESPACE, "coord", ai);
0476:        } else {
0477:            output.element(e.getNamespace(), e.getName(), ai);
0478:        }
0479:    }
0480:
0481:    static void encodeCoords(Element e, CoordinateSequence coords,
0482:        PrintHandler output) throws IOException {
0483:        if ((coords == null) || (coords.size() == 0)) {
0484:            return;
0485:        }
0486:
0487:        encodeCoords(e, coords.toCoordinateArray(), output);
0488:    }
0489:
0490:    static void encodeCoords(Element e, Coordinate[] coords, PrintHandler output)
0491:        throws IOException {
0492:        if ((coords == null) || (coords.length == 0)) {
0493:            return;
0494:        }
0495:
0496:        AttributesImpl ai = new AttributesImpl();
0497:        String dec;
0498:        String cs;
0499:        String ts;
0500:        dec = ".";
0501:        cs = ",";
0502:        ts = " ";
0503:        ai.addAttribute("", "decimal", "", "string", dec);
0504:        ai.addAttribute("", "cs", "", "string", cs);
0505:        ai.addAttribute("", "ts", "", "string", ts);
0506:
0507:        if (e == null) {
0508:            output.startElement(GMLSchema.NAMESPACE, "coordinates", ai);
0509:        } else {
0510:            output.startElement(e.getNamespace(), e.getName(), ai);
0511:        }
0512:
0513:        Coordinate c = coords[0];
0514:
0515:        if (Double.isNaN(c.z)) {
0516:            output.characters(c.x + cs + c.y);
0517:        } else {
0518:            output.characters(c.x + cs + c.y + cs + c.z);
0519:        }
0520:
0521:        for (int i = 1; i < coords.length; i++) {
0522:            c = coords[i];
0523:
0524:            if (Double.isNaN(c.z)) {
0525:                output.characters(ts + c.x + cs + c.y);
0526:            } else {
0527:                output.characters(ts + c.x + cs + c.y + cs + c.z);
0528:            }
0529:        }
0530:
0531:        if (e == null) {
0532:            output.endElement(GMLSchema.NAMESPACE, "coordinates");
0533:        } else {
0534:            output.endElement(e.getNamespace(), e.getName());
0535:        }
0536:    }
0537:
0538:    static void encodeCoords(Element e, Envelope env, PrintHandler output)
0539:        throws IOException {
0540:        if ((env == null)) {
0541:            return;
0542:        }
0543:
0544:        AttributesImpl ai = new AttributesImpl();
0545:        String dec;
0546:        String cs;
0547:        String ts;
0548:        dec = ".";
0549:        cs = ",";
0550:        ts = " ";
0551:        ai.addAttribute("", "decimal", "", "string", dec);
0552:        ai.addAttribute("", "cs", "", "string", cs);
0553:        ai.addAttribute("", "ts", "", "string", ts);
0554:
0555:        if (e == null) {
0556:            output.startElement(GMLSchema.NAMESPACE, "coordinates", ai);
0557:        } else {
0558:            output.startElement(e.getNamespace(), e.getName(), ai);
0559:        }
0560:
0561:        output.characters(env.getMinX() + cs + env.getMinY() + ts + env.getMaxX() + cs + env.getMaxY());
0562:
0563:        if (e == null) {
0564:            output.endElement(GMLSchema.NAMESPACE, "coordinates");
0565:        } else {
0566:            output.endElement(e.getNamespace(), e.getName());
0567:        }
0568:    }
0569:
0570:    /**
0571:     * <p>
0572:     * Default implementation, used to pass data to parents in the  inheritance
0573:     * tree.
0574:     * </p>
0575:     *
0576:     * @author dzwiers
0577:     *
0578:     * @see ElementValue
0579:     */
0580:    private static class DefaultElementValue implements  ElementValue {
0581:        // local data variables
0582:        private Element elem;
0583:        private Object value;
0584:
0585:        /**
0586:         * The input method for the data to store.
0587:         *
0588:         * @param elem
0589:         * @param value
0590:         */
0591:        public DefaultElementValue(Element elem, Object value) {
0592:            this .elem = elem;
0593:            this .value = value;
0594:        }
0595:
0596:        /**
0597:         * @see schema.ElementValue#getElement()
0598:         */
0599:        public Element getElement() {
0600:            return elem;
0601:        }
0602:
0603:        /**
0604:         * @see schema.ElementValue#getValue()
0605:         */
0606:        public Object getValue() {
0607:            return value;
0608:        }
0609:        /* (non-Javadoc)
0610:		 * @see java.lang.Object#toString()
0611:		 */
0612:		public String toString() {
0613:			StringBuffer buf = new StringBuffer();
0614:			if( getElement() != null && getElement().toString() != null){
0615:				buf.append( getElement().toString() );				
0616:			}
0617:			else {
0618:				buf.append( getClass().getName() );
0619:			}
0620:			buf.append("[");
0621:			buf.append( value );
0622:			buf.append("]");
0623:			return buf.toString();
0624:		}
0625:    }
0626:
0627:    /**
0628:     * <p>
0629:     * Many complexTypes have Choices as part of their definition. Instances of
0630:     * this class are used to represent these choices.
0631:     * </p>
0632:     *
0633:     * @author dzwiers
0634:     *
0635:     * @see Choice
0636:     */
0637:    private static class DefaultChoice implements  Choice {
0638:        // the element set to pick one of
0639:        private Element[] elements = null;
0640:
0641:        /*
0642:         * Should not be called
0643:         */
0644:        private DefaultChoice() {
0645:            // Should not be called
0646:        }
0647:
0648:        /**
0649:         * Initializes this instance with a set of elements to choose from.
0650:         *
0651:         * @param elems
0652:         */
0653:        public DefaultChoice(Element[] elems) {
0654:            elements = elems;
0655:        }
0656:
0657:        /**
0658:         * @see schema.Choice#getId()
0659:         */
0660:        public String getId() {
0661:            return null;
0662:        }
0663:
0664:        /**
0665:         * @see schema.Choice#getMaxOccurs()
0666:         */
0667:        public int getMaxOccurs() {
0668:            return 1;
0669:        }
0670:
0671:        /**
0672:         * @see schema.Choice#getMinOccurs()
0673:         */
0674:        public int getMinOccurs() {
0675:            return 1;
0676:        }
0677:
0678:        /**
0679:         * @see schema.Choice#getChildren()
0680:         */
0681:        public ElementGrouping[] getChildren() {
0682:            return elements;
0683:        }
0684:
0685:        /**
0686:         * @see schema.ElementGrouping#getGrouping()
0687:         */
0688:        public int getGrouping() {
0689:            return CHOICE;
0690:        }
0691:
0692:        /**
0693:         * @see schema.ElementGrouping#findChildElement(java.lang.String)
0694:         */
0695:        public Element findChildElement(String name) {
0696:            if ((elements == null) || (elements.length == 0) || (name == null)) {
0697:                return null;
0698:            }
0699:
0700:            for (int i = 0; i < elements.length; i++)
0701:                if (name.equals(elements[i].getName())) {
0702:                    return elements[i];
0703:                }
0704:
0705:            return null;
0706:        }
0707:
0708:		public Element findChildElement(String localName, URI namespaceURI) {
0709:            if ((elements == null) || (elements.length == 0) || (localName == null)) {
0710:                return null;
0711:            }
0712:
0713:            for (int i = 0; i < elements.length; i++)
0714:                if (localName.equals(elements[i].getName())
0715:                		&& namespaceURI.equals(elements[i].getNamespace())) {
0716:                    return elements[i];
0717:                }
0718:
0719:            return null;
0720:		}
0721:    }
0722:
0723:    /**
0724:     * <p>
0725:     * Many complexTypes have Sequences as part of their definition. Instances
0726:     * of this class are used to represent these sequences.
0727:     * </p>
0728:     *
0729:     * @author dzwiers
0730:     */
0731:    private static class DefaultSequence implements  Sequence {
0732:        // the list of elements in the sequence (order matters here)
0733:        private Element[] elements = null;
0734:
0735:        /*
0736:         * Should not be called
0737:         */
0738:        private DefaultSequence() {
0739:            // Should not be called
0740:        }
0741:
0742:        /**
0743:         * Initializes the Sequence with a list of elements within the Sequence
0744:         *
0745:         * @param elems
0746:         */
0747:        public DefaultSequence(Element[] elems) {
0748:            elements = elems;
0749:        }
0750:
0751:        /**
0752:         * @see schema.Sequence#getChildren()
0753:         */
0754:        public ElementGrouping[] getChildren() {
0755:            return elements;
0756:        }
0757:
0758:        /**
0759:         * @see schema.Sequence#getId()
0760:         */
0761:        public String getId() {
0762:            return null;
0763:        }
0764:
0765:        /**
0766:         * @see schema.Sequence#getMaxOccurs()
0767:         */
0768:        public int getMaxOccurs() {
0769:            return 1;
0770:        }
0771:
0772:        /**
0773:         * @see schema.Sequence#getMinOccurs()
0774:         */
0775:        public int getMinOccurs() {
0776:            return 1;
0777:        }
0778:
0779:        /**
0780:         * @see schema.ElementGrouping#getGrouping()
0781:         */
0782:        public int getGrouping() {
0783:            return SEQUENCE;
0784:        }
0785:
0786:        /**
0787:         * @see schema.ElementGrouping#findChildElement(java.lang.String)
0788:         */
0789:        public Element findChildElement(String name) {
0790:            if ((elements == null) || (elements.length == 0) || (name == null)) {
0791:                return null;
0792:            }
0793:
0794:            for (int i = 0; i < elements.length; i++)
0795:                if (name.equals(elements[i].getName())) {
0796:                    return elements[i];
0797:                }
0798:
0799:            return null;
0800:        }
0801:
0802:		public Element findChildElement(String localName, URI namespaceURI) {
0803:			if ((elements == null) || (elements.length == 0) || (localName == null)) {
0804:                return null;
0805:            }
0806:
0807:            for (int i = 0; i < elements.length; i++)
0808:                if (localName.equals(elements[i].getName())
0809:                		&& namespaceURI.equals(elements[i].getNamespace())) {
0810:                    return elements[i];
0811:                }
0812:
0813:            return null;
0814:		}
0815:    }
0816:
0817:    /**
0818:     * <p>
0819:     * This class represents an AbstractGeometryType within the GML Schema.
0820:     * This includes both the data and parsing functionality associated  with
0821:     * an AbstractGeometryType.
0822:     * </p>
0823:     *
0824:     * @author dzwiers
0825:     *
0826:     * @see GMLComplexType
0827:     * @see ComplexType
0828:     */
0829:    public static class AbstractGeometryType extends GMLComplexType {
0830:
0831:        /**
0832:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
0833:         */
0834:        public Element[] getChildElements() {
0835:            return null;
0836:        }
0837:
0838:        // singleton instance
0839:        private static final GMLComplexType instance = new AbstractGeometryType();
0840:
0841:        // static list of attributes
0842:        protected static Attribute[] attributes = {
0843:                new GMLSchema.GMLAttribute("gid",
0844:                    XSISimpleTypes.ID.getInstance()),
0845:                new GMLSchema.GMLAttribute("srsName",
0846:                    XSISimpleTypes.AnyURI.getInstance())
0847:            };
0848:
0849:        /*
0850:         * part of the singleton pattern
0851:         *
0852:         * @see GMLComplexType#getInstance()
0853:         */
0854:        public static GMLComplexType getInstance() {
0855:            return instance;
0856:        }
0857:
0858:        /**
0859:         * @see schema.ComplexType#isAbstract()
0860:         */
0861:        public boolean isAbstract() {
0862:            return true;
0863:        }
0864:
0865:        /**
0866:         * @see schema.ComplexType#getAnyAttributeNameSpace()
0867:         */
0868:        public String getAnyAttributeNameSpace() {
0869:            return null;
0870:        }
0871:
0872:        /**
0873:         * @see schema.ComplexType#getAttributes()
0874:         */
0875:        public Attribute[] getAttributes() {
0876:            return new Attribute[0];
0877:        }
0878:
0879:        /**
0880:         * @see schema.ComplexType#getChildren()
0881:         */
0882:        public ElementGrouping getChild() {
0883:            return new DefaultSequence(new Element[0]);
0884:        }
0885:
0886:        /**
0887:         * @see schema.ComplexType#getName()
0888:         */
0889:        public String getName() {
0890:            return "AbstractGeometryType";
0891:        }
0892:
0893:        /**
0894:         * @see org.geotools.xml.xsi.Type#getValue(org.geotools.xml.xsi.Element,
0895:         *      org.geotools.xml.xsi.ElementValue[], org.xml.sax.Attributes)
0896:         */
0897:        public Object getValue(Element element, ElementValue[] value,
0898:            Attributes attrs, Map hints) throws SAXException {
0899:            try {
0900:                Geometry g = (Geometry) value[0].getValue();
0901:
0902:                //TODO have someone that knows more help.
0903:                String srsName = attrs.getValue("srsName");
0904:
0905:                if ((srsName != null) && !"".equals(srsName)) {
0906:                    //TODO support real coord systems here
0907:                    //                    if(srsName.matches(".*epsg#\\d*")){
0908:                    //                        String[] t = srsName.split(".*epsg#");
0909:                    //                        if(t!=null && t.length==1){
0910:                    //                            String epsg = t[0];
0911:                    //                            CoordinateSystem cs = (new CoordinateSystemEPSGFactory()).createCoordinateSystem(epsg);
0912:                    //                            g.setUserData(cs);
0913:                    //                        }
0914:                    //                    }
0915:                    g.setUserData(srsName);
0916:                }
0917:
0918:                return g;
0919:            } catch (ClassCastException e) {
0920:                // there was an error, this is an abstract type
0921:                throw new SAXException(
0922:                    "Expected a Geometry to be passed to this abstract type");
0923:
0924:                //            } catch (FactoryException e) {
0925:                //                throw new SAXException(e);
0926:            }
0927:        }
0928:
0929:        /**
0930:         * @see org.geotools.xml.xsi.Type#getInstanceType()
0931:         */
0932:        public Class getInstanceType() {
0933:            return Geometry.class;
0934:        }
0935:
0936:        /**
0937:         * @see schema.ComplexType#findChildElement(java.lang.String)
0938:         */
0939:        public Element findChildElement(String name) {
0940:            return null;
0941:        }
0942:
0943:        /**
0944:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
0945:         *      java.lang.Object, java.util.Map)
0946:         */
0947:        public boolean canEncode(Element element, Object value, Map hints) {
0948:            if( element.getType()==null || !( value instanceof  Geometry))
0949:            		return false;
0950:            // need to check inheritance ... 
0951:            if(element.getType() instanceof  SimpleType)
0952:            	return false;
0953:            return true;
0954:        }
0955:
0956:        /**
0957:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
0958:         *      java.lang.Object, org.geotools.xml.PrintHandler,
0959:         *      java.util.Map)
0960:         */
0961:        public void encode(Element element, Object value, PrintHandler output,
0962:            Map hints) throws IOException, OperationNotSupportedException {
0963:            if(!canEncode(element,value,hints))
0964:                throw new OperationNotSupportedException();
0965:            Geometry g = (Geometry)value;
0966:            GMLComplexTypes.encode(null, g, output);
0967:        }
0968:    }
0969:
0970:    /**
0971:     * <p>
0972:     * This class represents an AbstractGeometryCollectionBaseType within the
0973:     * GML Schema.  This includes both the data and parsing functionality
0974:     * associated  with an AbstractGeometryCollectionBaseType.
0975:     * </p>
0976:     *
0977:     * @author dzwiers
0978:     *
0979:     * @see GMLComplexType
0980:     * @see ComplexType
0981:     */
0982:    public static class AbstractGeometryCollectionBaseType extends GMLComplexType {
0983:
0984:        /**
0985:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
0986:         */
0987:        public Element[] getChildElements() {
0988:            return null;
0989:        }
0990:
0991:        protected static final Attribute[] attributes = {
0992:                new GMLSchema.GMLAttribute("gid",
0993:                    XSISimpleTypes.ID.getInstance()),
0994:                new GMLSchema.GMLAttribute("srsName",
0995:                    XSISimpleTypes.AnyURI.getInstance(), Attribute.REQUIRED)
0996:            };
0997:
0998:        // singleton instance
0999:        private static final GMLComplexType instance = new AbstractGeometryCollectionBaseType();
1000:
1001:        /**
1002:         * @see schema.ComplexType#isAbstract()
1003:         */
1004:        public boolean isAbstract() {
1005:            return true;
1006:        }
1007:
1008:        /**
1009:         * @see schema.ComplexType#getAnyAttributeNameSpace()
1010:         */
1011:        public String getAnyAttributeNameSpace() {
1012:            return null;
1013:        }
1014:
1015:        /**
1016:         * @see schema.ComplexType#getAttributes()
1017:         */
1018:        public Attribute[] getAttributes() {
1019:            return new Attribute[0];
1020:        }
1021:
1022:        /**
1023:         * @see schema.ComplexType#getChildren()
1024:         */
1025:        public ElementGrouping getChild() {
1026:            return new DefaultSequence(new Element[0]);
1027:        }
1028:
1029:        /**
1030:         * @see schema.ComplexType#getName()
1031:         */
1032:        public String getName() {
1033:            return "AbstractGeometryCollectionBaseType";
1034:        }
1035:
1036:        /**
1037:         * @see org.geotools.xml.xsi.Type#getValue(org.geotools.xml.xsi.Element,
1038:         *      org.geotools.xml.xsi.ElementValue[], org.xml.sax.Attributes)
1039:         */
1040:        public Object getValue(Element element, ElementValue[] value,
1041:            Attributes attrs, Map hints) throws SAXException {
1042:            try {
1043:                Geometry g = (Geometry) value[0].getValue();
1044:
1045:                //TODO have someone that knows more help.
1046:                String srsName = attrs.getValue("srsName");
1047:
1048:                if ((srsName != null) && !"".equals(srsName)) {
1049:                    //TODO support real coord systems here
1050:                    //                    if(srsName.matches(".*epsg#\\d*")){
1051:                    //                        String[] t = srsName.split(".*epsg#");
1052:                    //                        if(t!=null && t.length==1){
1053:                    //                            String epsg = t[0];
1054:                    //                            CoordinateSystem cs = (new CoordinateSystemEPSGFactory()).createCoordinateSystem(epsg);
1055:                    //                            g.setUserData(cs);
1056:                    //                        }
1057:                    //                    }
1058:                    g.setUserData(srsName);
1059:                }
1060:
1061:                return g;
1062:            } catch (ClassCastException e) {
1063:                // there was an error, this is an abstract type
1064:                throw new SAXException(
1065:                    "Expected a Geometry to be passed to this abstract type");
1066:
1067:                //            } catch (FactoryException e) {
1068:                //                throw new SAXException(e);
1069:            }
1070:        }
1071:
1072:        /**
1073:         * @see org.geotools.xml.xsi.Type#getInstanceType()
1074:         */
1075:        public Class getInstanceType() {
1076:            return Geometry.class;
1077:        }
1078:
1079:        /*
1080:         * part of the singleton pattern
1081:         *
1082:         * @see GMLComplexType#getInstance()
1083:         */
1084:        public static GMLComplexType getInstance() {
1085:            return instance;
1086:        }
1087:
1088:        /**
1089:         * @see schema.ComplexType#findChildElement(java.lang.String)
1090:         */
1091:        public Element findChildElement(String name) {
1092:            return null;
1093:        }
1094:
1095:        /**
1096:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
1097:         *      java.lang.Object, java.util.Map)
1098:         */
1099:        public boolean canEncode(Element element, Object value, Map hints) {
1100:            return false;
1101:        }
1102:
1103:        /**
1104:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
1105:         *      java.lang.Object, org.geotools.xml.PrintHandler,
1106:         *      java.util.Map)
1107:         */
1108:        public void encode(Element element, Object value, PrintHandler output,
1109:            Map hints) throws OperationNotSupportedException {
1110:            throw new OperationNotSupportedException();
1111:        }
1112:    }
1113:
1114:    /**
1115:     * <p>
1116:     * This class represents an GeometryAssociationType within the GML Schema.
1117:     * This includes both the data and parsing functionality associated  with
1118:     * an GeometryAssociationType.
1119:     * </p>
1120:     *
1121:     * @author dzwiers
1122:     *
1123:     * @see GMLComplexType
1124:     * @see ComplexType
1125:     */
1126:    public static class GeometryAssociationType extends GMLComplexType {
1127:
1128:        /**
1129:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
1130:         */
1131:        public Element[] getChildElements() {
1132:            return elems;
1133:        }
1134:
1135:        // singleton instance
1136:        private static final GMLComplexType instance = new GeometryAssociationType();
1137:
1138:        // the static attribute list
1139:        protected static final Attribute[] attributes = loadAttributes();
1140:
1141:        // the static element list
1142:        private static final Element[] elems = {
1143:                new GMLElement("_Geometry",
1144:                    GMLComplexTypes.AbstractGeometryType.getInstance(), 0, 1,
1145:                    true, null),
1146:            };
1147:
1148:        // static child sequence
1149:        private static final DefaultSequence elements = new DefaultSequence(elems);
1150:
1151:        /*
1152:         * part of the singleton pattern
1153:         *
1154:         * @see GMLComplexType#getInstance()
1155:         */
1156:        public static GMLComplexType getInstance() {
1157:            return instance;
1158:        }
1159:
1160:        /**
1161:         * @see schema.ComplexType#isAbstract()
1162:         */
1163:        public boolean isAbstract() {
1164:            return false;
1165:        }
1166:
1167:        /**
1168:         * @see schema.ComplexType#getAnyAttributeNameSpace()
1169:         */
1170:        public String getAnyAttributeNameSpace() {
1171:            return null;
1172:        }
1173:
1174:        /*
1175:         * statically loads the attributes which GeometryAssociations include
1176:         */
1177:        private static Attribute[] loadAttributes() {
1178:            Attribute[] gp = XLinkSchema.SimpleLink.getInstance().getAttributes();
1179:            Attribute[] r = new Attribute[gp.length + 1];
1180:
1181:            for (int i = 1; i < gp.length; i++)
1182:                r[i] = gp[i];
1183:
1184:            r[gp.length] = AttributeList.attributes1[0];
1185:
1186:            return r;
1187:        }
1188:
1189:        /**
1190:         * @see schema.ComplexType#getAttributes()
1191:         */
1192:        public Attribute[] getAttributes() {
1193:            return attributes;
1194:        }
1195:
1196:        /**
1197:         * @see schema.ComplexType#getChildren()
1198:         */
1199:        public ElementGrouping getChild() {
1200:            return elements;
1201:        }
1202:
1203:        /**
1204:         * @see schema.ComplexType#getName()
1205:         */
1206:        public String getName() {
1207:            return "GeometryAssociationType";
1208:        }
1209:
1210:        /**
1211:         * @see schema.Type#getValue(java.util.List)
1212:         */
1213:        public Object getValue(Element element, ElementValue[] value,
1214:            Attributes attrs, Map hints) throws SAXException {
1215:            if ((value == null) || (value.length == 0) || (value[0] == null)) {
1216:                return null; // do nothing ... this is allowed
1217:            }
1218:
1219:            if (value.length > 1) {
1220:                throw new SAXException("Cannot have more than one geom per "
1221:                    + getName());
1222:            }
1223:
1224:            Element e = value[0].getElement();
1225:
1226:            if (e == null) {
1227:                throw new SAXException(
1228:                    "Internal error, ElementValues require an associated Element.");
1229:            }
1230:
1231:            return (Geometry) value[0].getValue();
1232:        }
1233:
1234:        public Class getInstanceType() {
1235:            return Geometry.class;
1236:        }
1237:
1238:        /**
1239:         * @see schema.ComplexType#findChildElement(java.lang.String)
1240:         */
1241:        public Element findChildElement(String name) {
1242:            if (name == null) {
1243:                return null;
1244:            }
1245:
1246:            for (int i = 0; i < elems.length; i++)
1247:                if (name.equals(elems[i].getName())) {
1248:                    return elems[i];
1249:                }
1250:
1251:            return null;
1252:        }
1253:
1254:        /**
1255:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
1256:         *      java.lang.Object, java.util.Map)
1257:         */
1258:        public boolean canEncode(Element element, Object value, Map hints) {
1259:            ComplexType t = (element.getType() instanceof  ComplexType)
1260:                ? (ComplexType) element.getType() : null;
1261:
1262:            while ((t != null) && (t != this ))
1263:                t = (t.getParent() instanceof  ComplexType)
1264:                    ? (ComplexType) t.getParent() : null;
1265:
1266:            return ((t != null) && (value instanceof  Geometry));
1267:        }
1268:
1269:        /**
1270:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
1271:         *      java.lang.Object, org.geotools.xml.PrintHandler,
1272:         *      java.util.Map)
1273:         */
1274:        public void encode(Element element, Object value, PrintHandler output,
1275:            Map hints) throws IOException, OperationNotSupportedException {
1276:            if (!canEncode(element, value, hints)) {
1277:                throw new OperationNotSupportedException("Cannot encode");
1278:            }
1279:
1280:            Geometry g = (Geometry) value;
1281:
1282:            output.startElement(element.getNamespace(), element.getName(), null);
1283:            GMLComplexTypes.encode(null, g, output);
1284:            output.endElement(element.getNamespace(), element.getName());
1285:        }
1286:    }
1287:
1288:    /**
1289:     * <p>
1290:     * This class represents an PointMemberType within the GML Schema.  This
1291:     * includes both the data and parsing functionality associated  with an
1292:     * PointMemberType.
1293:     * </p>
1294:     *
1295:     * @author dzwiers
1296:     *
1297:     * @see GMLComplexType
1298:     * @see ComplexType
1299:     */
1300:    public static class PointMemberType extends GMLComplexType {
1301:
1302:        /**
1303:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
1304:         */
1305:        public Element[] getChildElements() {
1306:            return elements;
1307:        }
1308:
1309:        // singleton instance
1310:        private static final GMLComplexType instance = new PointMemberType();
1311:
1312:        // static list of attributes
1313:        private static final Attribute[] attributes = loadAttributes();
1314:
1315:        // static list of elements
1316:        private static final Element[] elements = {
1317:                new GMLElement("Point",
1318:                    GMLComplexTypes.PointType.getInstance(), 0, 1, false,
1319:                    new GMLElement("_Geometry",
1320:                        GMLComplexTypes.AbstractGeometryType.getInstance(), 1,
1321:                        1, true, null)),
1322:            };
1323:
1324:        // static sequence
1325:        private static final DefaultSequence seq = new DefaultSequence(elements);
1326:
1327:        /*
1328:         * part of the singleton pattern
1329:         *
1330:         * @see GMLComplexType#getInstance()
1331:         */
1332:        public static GMLComplexType getInstance() {
1333:            return instance;
1334:        }
1335:
1336:        /**
1337:         * @see schema.ComplexType#isAbstract()
1338:         */
1339:        public boolean isAbstract() {
1340:            return false;
1341:        }
1342:
1343:        /**
1344:         * @see schema.ComplexType#getAnyAttributeNameSpace()
1345:         */
1346:        public String getAnyAttributeNameSpace() {
1347:            return null;
1348:        }
1349:
1350:        /*
1351:         * statically loads the attributes required for a PointMember
1352:         */
1353:        private static Attribute[] loadAttributes() {
1354:            Attribute[] parent = GeometryAssociationType.attributes;
1355:            Attribute[] gp = GMLSchema.GMLAssociationAttributeGroup.attributes1;
1356:            Attribute[] r = new Attribute[parent.length + gp.length];
1357:
1358:            for (int i = 0; i < parent.length; i++)
1359:                r[i] = parent[i];
1360:
1361:            for (int i = 0; i < gp.length; i++)
1362:                r[i + parent.length] = gp[i];
1363:
1364:            return r;
1365:        }
1366:
1367:        /**
1368:         * @see schema.ComplexType#getAttributes()
1369:         */
1370:        public Attribute[] getAttributes() {
1371:            return attributes;
1372:        }
1373:
1374:        /**
1375:         * @see schema.ComplexType#getChildren()
1376:         */
1377:        public ElementGrouping getChild() {
1378:            return seq;
1379:        }
1380:
1381:        /**
1382:         * @see schema.ComplexType#getName()
1383:         */
1384:        public String getName() {
1385:            return "PointMemberType";
1386:        }
1387:
1388:        /**
1389:         * @see schema.Type#getValue(java.util.List)
1390:         */
1391:        public Object getValue(Element element, ElementValue[] value,
1392:            Attributes attrs, Map hints) throws SAXException {
1393:            if ((value == null) || (value.length == 0) || (value[0] == null)) {
1394:                return null; // do nothing ... this is allowed
1395:            }
1396:
1397:            if (value.length > 1) {
1398:                throw new SAXException("Cannot have more than one geom per "
1399:                    + getName());
1400:            }
1401:
1402:            Element e = value[0].getElement();
1403:
1404:            if (e == null) {
1405:                throw new SAXException(
1406:                    "Internal error, ElementValues require an associated Element.");
1407:            }
1408:
1409:            return (Point) value[0].getValue();
1410:        }
1411:
1412:        /**
1413:         * @see org.geotools.xml.xsi.Type#getInstanceType()
1414:         */
1415:        public Class getInstanceType() {
1416:            return Point.class;
1417:        }
1418:
1419:        /**
1420:         * @see schema.ComplexType#findChildElement(java.lang.String)
1421:         */
1422:        public Element findChildElement(String name) {
1423:            if (name == null) {
1424:                return null;
1425:            }
1426:
1427:            for (int i = 0; i < elements.length; i++)
1428:                if (name.equals(elements[i].getName())) {
1429:                    return elements[i];
1430:                }
1431:
1432:            return null;
1433:        }
1434:
1435:        /**
1436:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
1437:         *      java.lang.Object, java.util.Map)
1438:         */
1439:        public boolean canEncode(Element element, Object value, Map hints) {
1440:            ComplexType t = (element.getType() instanceof  ComplexType)
1441:                ? (ComplexType) element.getType() : null;
1442:
1443:            while ((t != null) && (t != this ))
1444:                t = (t.getParent() instanceof  ComplexType)
1445:                    ? (ComplexType) t.getParent() : null;
1446:
1447:            return ((t != null) && (value instanceof  Geometry));
1448:        }
1449:
1450:        /**
1451:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
1452:         *      java.lang.Object, org.geotools.xml.PrintHandler,
1453:         *      java.util.Map)
1454:         */
1455:        public void encode(Element element, Object value, PrintHandler output,
1456:            Map hints) throws IOException, OperationNotSupportedException {
1457:            if (!canEncode(element, value, hints)) {
1458:                throw new OperationNotSupportedException("Cannot encode");
1459:            }
1460:
1461:            Point g = (Point) value;
1462:
1463:            output.startElement(element.getNamespace(), element.getName(), null);
1464:            GMLComplexTypes.encode(null, g, output);
1465:            output.endElement(element.getNamespace(), element.getName());
1466:        }
1467:    }
1468:
1469:    /**
1470:     * <p>
1471:     * This class represents an LineStringMemberType within the GML Schema.
1472:     * This includes both the data and parsing functionality associated  with
1473:     * an LineStringMemberType.
1474:     * </p>
1475:     *
1476:     * @author dzwiers
1477:     *
1478:     * @see GMLComplexType
1479:     * @see ComplexType
1480:     */
1481:    public static class LineStringMemberType extends GMLComplexType {
1482:
1483:        /**
1484:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
1485:         */
1486:        public Element[] getChildElements() {
1487:            return elements;
1488:        }
1489:
1490:        // singleton instance
1491:        private static final GMLComplexType instance = new LineStringMemberType();
1492:
1493:        // static list of attributes
1494:        private static final Attribute[] attributes = loadAttributes();
1495:
1496:        // static list of elements
1497:        private static final Element[] elements = {
1498:                new GMLElement("LineString",
1499:                    GMLComplexTypes.LineStringType.getInstance(), 0, 1, false,
1500:                    new GMLElement("_Geometry",
1501:                        GMLComplexTypes.AbstractGeometryType.getInstance(), 1,
1502:                        1, true, null)),
1503:            };
1504:
1505:        // static sequence
1506:        private static final DefaultSequence seq = new DefaultSequence(elements);
1507:
1508:        /*
1509:         * part of the singleton pattern
1510:         *
1511:         * @see GMLComplexType#getInstance()
1512:         */
1513:        public static GMLComplexType getInstance() {
1514:            return instance;
1515:        }
1516:
1517:        /**
1518:         * @see schema.ComplexType#isAbstract()
1519:         */
1520:        public boolean isAbstract() {
1521:            return false;
1522:        }
1523:
1524:        /**
1525:         * @see schema.ComplexType#getAnyAttributeNameSpace()
1526:         */
1527:        public String getAnyAttributeNameSpace() {
1528:            return null;
1529:        }
1530:
1531:        /*
1532:         * statically loads the attributes required for a LineStringMember
1533:         */
1534:        private static Attribute[] loadAttributes() {
1535:            Attribute[] parent = GeometryAssociationType.attributes;
1536:            Attribute[] gp = GMLSchema.GMLAssociationAttributeGroup.attributes1;
1537:            Attribute[] r = new Attribute[parent.length + gp.length];
1538:
1539:            for (int i = 0; i < parent.length; i++)
1540:                r[i] = parent[i];
1541:
1542:            for (int i = 0; i < gp.length; i++)
1543:                r[i + parent.length] = gp[i];
1544:
1545:            return r;
1546:        }
1547:
1548:        /**
1549:         * @see schema.ComplexType#getAttributes()
1550:         */
1551:        public Attribute[] getAttributes() {
1552:            return attributes;
1553:        }
1554:
1555:        /**
1556:         * @see schema.ComplexType#getChildren()
1557:         */
1558:        public ElementGrouping getChild() {
1559:            return seq;
1560:        }
1561:
1562:        /**
1563:         * @see schema.ComplexType#getName()
1564:         */
1565:        public String getName() {
1566:            return "LineStringMemberType";
1567:        }
1568:
1569:        /**
1570:         * @see schema.Type#getValue(java.util.List)
1571:         */
1572:        public Object getValue(Element element, ElementValue[] value,
1573:            Attributes attrs, Map hints) throws SAXException {
1574:            if ((value == null) || (value.length == 0) || (value[0] == null)) {
1575:                return null; // do nothing ... this is allowed
1576:            }
1577:
1578:            if (value.length > 1) {
1579:                throw new SAXException("Cannot have more than one geom per "
1580:                    + getName());
1581:            }
1582:
1583:            Element e = value[0].getElement();
1584:
1585:            if (e == null) {
1586:            	if(!element.isNillable())
1587:            		throw new SAXException(
1588:                    	"Internal error, ElementValues require an associated Element.");
1589:            	return null;
1590:            }
1591:
1592:            return (LineString) value[0].getValue();
1593:        }
1594:
1595:        public Class getInstanceType() {
1596:            return LineString.class;
1597:        }
1598:
1599:        /**
1600:         * @see schema.ComplexType#findChildElement(java.lang.String)
1601:         */
1602:        public Element findChildElement(String name) {
1603:            if (name == null) {
1604:                return null;
1605:            }
1606:
1607:            for (int i = 0; i < elements.length; i++)
1608:                if (name.equals(elements[i].getName())) {
1609:                    return elements[i];
1610:                }
1611:
1612:            return null;
1613:        }
1614:
1615:        /**
1616:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
1617:         *      java.lang.Object, java.util.Map)
1618:         */
1619:        public boolean canEncode(Element element, Object value, Map hints) {
1620:            ComplexType t = (element.getType() instanceof  ComplexType)
1621:                ? (ComplexType) element.getType() : null;
1622:
1623:            while ((t != null) && (t != this ))
1624:                t = (t.getParent() instanceof  ComplexType)
1625:                    ? (ComplexType) t.getParent() : null;
1626:
1627:            return ((t != null) && (value instanceof  LineString));
1628:        }
1629:
1630:        /**
1631:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
1632:         *      java.lang.Object, org.geotools.xml.PrintHandler,
1633:         *      java.util.Map)
1634:         */
1635:        public void encode(Element element, Object value, PrintHandler output,
1636:            Map hints) throws IOException, OperationNotSupportedException {
1637:            if (!canEncode(element, value, hints)) {
1638:                throw new OperationNotSupportedException("Cannot encode");
1639:            }
1640:
1641:            LineString g = (LineString) value;
1642:
1643:            output.startElement(element.getNamespace(), element.getName(), null);
1644:            GMLComplexTypes.encode(null, g, output);
1645:            output.endElement(element.getNamespace(), element.getName());
1646:        }
1647:    }
1648:
1649:    /**
1650:     * <p>
1651:     * This class represents an PolygonMemberType within the GML Schema.  This
1652:     * includes both the data and parsing functionality associated  with an
1653:     * PolygonMemberType.
1654:     * </p>
1655:     *
1656:     * @author dzwiers
1657:     *
1658:     * @see GMLComplexType
1659:     * @see ComplexType
1660:     */
1661:    public static class PolygonMemberType extends GMLComplexType {
1662:
1663:        /**
1664:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
1665:         */
1666:        public Element[] getChildElements() {
1667:            return elements;
1668:        }
1669:
1670:        // singleton instance
1671:        private static final GMLComplexType instance = new PolygonMemberType();
1672:
1673:        // static attribute list
1674:        private static final Attribute[] attributes = loadAttributes();
1675:
1676:        // static list of elements
1677:        private static final Element[] elements = {
1678:                new GMLElement("Polygon",
1679:                    GMLComplexTypes.PolygonType.getInstance(), 0, 1, false,
1680:                    new GMLElement("_Geometry",
1681:                        GMLComplexTypes.AbstractGeometryType.getInstance(), 1,
1682:                        1, true, null)),
1683:            };
1684:
1685:        // static sequence
1686:        private static final DefaultSequence seq = new DefaultSequence(elements);
1687:
1688:        /*
1689:         * part of the singleton pattern
1690:         *
1691:         * @see GMLComplexType#getInstance()
1692:         */
1693:        public static GMLComplexType getInstance() {
1694:            return instance;
1695:        }
1696:
1697:        /**
1698:         * @see schema.ComplexType#isAbstract()
1699:         */
1700:        public boolean isAbstract() {
1701:            return false;
1702:        }
1703:
1704:        /**
1705:         * @see schema.ComplexType#getAnyAttributeNameSpace()
1706:         */
1707:        public String getAnyAttributeNameSpace() {
1708:            return null;
1709:        }
1710:
1711:        /*
1712:         * statically loads the attributes required for a PolygonMember
1713:         */
1714:        private static Attribute[] loadAttributes() {
1715:            Attribute[] parent = GeometryAssociationType.attributes;
1716:            Attribute[] gp = GMLSchema.GMLAssociationAttributeGroup.attributes1;
1717:            Attribute[] r = new Attribute[parent.length + gp.length];
1718:
1719:            for (int i = 0; i < parent.length; i++)
1720:                r[i] = parent[i];
1721:
1722:            for (int i = 0; i < gp.length; i++)
1723:                r[i + parent.length] = gp[i];
1724:
1725:            return r;
1726:        }
1727:
1728:        /**
1729:         * @see schema.ComplexType#getAttributes()
1730:         */
1731:        public Attribute[] getAttributes() {
1732:            return attributes;
1733:        }
1734:
1735:        /**
1736:         * @see schema.ComplexType#getChildren()
1737:         */
1738:        public ElementGrouping getChild() {
1739:            return seq;
1740:        }
1741:
1742:        /**
1743:         * @see schema.ComplexType#getName()
1744:         */
1745:        public String getName() {
1746:            return "PolygonMemberType";
1747:        }
1748:
1749:        /**
1750:         * @see schema.Type#getValue(java.util.List)
1751:         */
1752:        public Object getValue(Element element, ElementValue[] value,
1753:            Attributes attrs, Map hints) throws SAXException {
1754:            if ((value == null) || (value.length == 0) || (value[0] == null)) {
1755:                return null; // do nothing ... this is allowed
1756:            }
1757:
1758:            if (value.length > 1) {
1759:                throw new SAXException("Cannot have more than one geom per "
1760:                    + getName());
1761:            }
1762:
1763:            Element e = value[0].getElement();
1764:
1765:            if (e == null) {
1766:            	if(!element.isNillable())
1767:            		throw new SAXException(
1768:                    	"Internal error, ElementValues require an associated Element.");
1769:            	return null;
1770:            }
1771:
1772:            return (Polygon) value[0].getValue();
1773:        }
1774:
1775:        /**
1776:         * @see org.geotools.xml.xsi.Type#getInstanceType()
1777:         */
1778:        public Class getInstanceType() {
1779:            return Polygon.class;
1780:        }
1781:
1782:        /**
1783:         * @see schema.ComplexType#findChildElement(java.lang.String)
1784:         */
1785:        public Element findChildElement(String name) {
1786:            if (name == null) {
1787:                return null;
1788:            }
1789:
1790:            for (int i = 0; i < elements.length; i++)
1791:                if (name.equals(elements[i].getName())) {
1792:                    return elements[i];
1793:                }
1794:
1795:            return null;
1796:        }
1797:
1798:        /**
1799:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
1800:         *      java.lang.Object, java.util.Map)
1801:         */
1802:        public boolean canEncode(Element element, Object value, Map hints) {
1803:            ComplexType t = (element.getType() instanceof  ComplexType)
1804:                ? (ComplexType) element.getType() : null;
1805:
1806:            while ((t != null) && (t != this ))
1807:                t = (t.getParent() instanceof  ComplexType)
1808:                    ? (ComplexType) t.getParent() : null;
1809:
1810:            return ((t != null) && (value instanceof  Polygon));
1811:        }
1812:
1813:        /**
1814:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
1815:         *      java.lang.Object, org.geotools.xml.PrintHandler,
1816:         *      java.util.Map)
1817:         */
1818:        public void encode(Element element, Object value, PrintHandler output,
1819:            Map hints) throws IOException, OperationNotSupportedException {
1820:            if (!canEncode(element, value, hints)) {
1821:                throw new OperationNotSupportedException("Cannot encode");
1822:            }
1823:
1824:            Polygon g = (Polygon) value;
1825:
1826:            output.startElement(element.getNamespace(), element.getName(), null);
1827:            GMLComplexTypes.encode(null, g, output);
1828:            output.endElement(element.getNamespace(), element.getName());
1829:        }
1830:    }
1831:
1832:    /**
1833:     * <p>
1834:     * This class represents an LinearRingMemberType within the GML Schema.
1835:     * This includes both the data and parsing functionality associated  with
1836:     * an LinearRingMemberType.
1837:     * </p>
1838:     *
1839:     * @author dzwiers
1840:     *
1841:     * @see GMLComplexType
1842:     * @see ComplexType
1843:     */
1844:    public static class LinearRingMemberType extends GMLComplexType {
1845:
1846:        /**
1847:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
1848:         */
1849:        public Element[] getChildElements() {
1850:            return elements;
1851:        }
1852:
1853:        // singleton instance
1854:        private static final GMLComplexType instance = new LinearRingMemberType();
1855:
1856:        // static attribute list
1857:        private static final Attribute[] attributes = loadAttributes();
1858:
1859:        // static element list
1860:        private static final Element[] elements = {
1861:                new GMLElement("LinearRing",
1862:                    GMLComplexTypes.LinearRingType.getInstance(), 0, 1, false,
1863:                    new GMLElement("_Geometry",
1864:                        GMLComplexTypes.AbstractGeometryType.getInstance(), 1,
1865:                        1, true, null)),
1866:            };
1867:
1868:        // static sequence
1869:        private static final DefaultSequence seq = new DefaultSequence(elements);
1870:
1871:        /*
1872:         * part of the singleton pattern
1873:         *
1874:         * @see GMLComplexType#getInstance()
1875:         */
1876:        public static GMLComplexType getInstance() {
1877:            return instance;
1878:        }
1879:
1880:        /**
1881:         * @see schema.ComplexType#isAbstract()
1882:         */
1883:        public boolean isAbstract() {
1884:            return false;
1885:        }
1886:
1887:        /**
1888:         * @see schema.ComplexType#getAnyAttributeNameSpace()
1889:         */
1890:        public String getAnyAttributeNameSpace() {
1891:            return null;
1892:        }
1893:
1894:        /*
1895:         * statically loads the attributes required for a LinearRingMember
1896:         */
1897:        private static Attribute[] loadAttributes() {
1898:            Attribute[] parent = GeometryAssociationType.attributes;
1899:            Attribute[] gp = GMLSchema.GMLAssociationAttributeGroup.attributes1;
1900:            Attribute[] r = new Attribute[parent.length + gp.length];
1901:
1902:            for (int i = 0; i < parent.length; i++)
1903:                r[i] = parent[i];
1904:
1905:            for (int i = 0; i < gp.length; i++)
1906:                r[i + parent.length] = gp[i];
1907:
1908:            return r;
1909:        }
1910:
1911:        /**
1912:         * @see schema.ComplexType#getAttributes()
1913:         */
1914:        public Attribute[] getAttributes() {
1915:            return attributes;
1916:        }
1917:
1918:        /**
1919:         * @see schema.ComplexType#getChildren()
1920:         */
1921:        public ElementGrouping getChild() {
1922:            return seq;
1923:        }
1924:
1925:        /**
1926:         * @see schema.ComplexType#getName()
1927:         */
1928:        public String getName() {
1929:            return "LinearRingMemberType";
1930:        }
1931:
1932:        /**
1933:         * @see schema.Type#getValue(java.util.List)
1934:         */
1935:        public Object getValue(Element element, ElementValue[] value,
1936:            Attributes attrs, Map hints) throws SAXException {
1937:            if ((value == null) || (value.length == 0) || (value[0] == null)) {
1938:                return null; // do nothing ... this is allowed
1939:            }
1940:
1941:            if (value.length > 1) {
1942:                throw new SAXException("Cannot have more than one geom per "
1943:                    + getName());
1944:            }
1945:
1946:            Element e = value[0].getElement();
1947:
1948:            if (e == null) {
1949:            	if(!element.isNillable())
1950:            		throw new SAXException(
1951:                    	"Internal error, ElementValues require an associated Element.");
1952:            	return null;
1953:            }
1954:            return (LinearRing) value[0].getValue();
1955:        }
1956:
1957:        /**
1958:         * @see org.geotools.xml.xsi.Type#getInstanceType()
1959:         */
1960:        public Class getInstanceType() {
1961:            return LinearRing.class;
1962:        }
1963:
1964:        /**
1965:         * @see schema.ComplexType#findChildElement(java.lang.String)
1966:         */
1967:        public Element findChildElement(String name) {
1968:            if (name == null) {
1969:                return null;
1970:            }
1971:
1972:            for (int i = 0; i < elements.length; i++)
1973:                if (name.equals(elements[i].getName())) {
1974:                    return elements[i];
1975:                }
1976:
1977:            return null;
1978:        }
1979:
1980:        /**
1981:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
1982:         *      java.lang.Object, java.util.Map)
1983:         */
1984:        public boolean canEncode(Element element, Object value, Map hints) {
1985:            ComplexType t = (element.getType() instanceof  ComplexType)
1986:                ? (ComplexType) element.getType() : null;
1987:
1988:            while ((t != null) && (t != this ))
1989:                t = (t.getParent() instanceof  ComplexType)
1990:                    ? (ComplexType) t.getParent() : null;
1991:
1992:            return ((t != null) && (value instanceof  LinearRing));
1993:        }
1994:
1995:        /**
1996:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
1997:         *      java.lang.Object, org.geotools.xml.PrintHandler,
1998:         *      java.util.Map)
1999:         */
2000:        public void encode(Element element, Object value, PrintHandler output,
2001:            Map hints) throws IOException, OperationNotSupportedException {
2002:            if (!canEncode(element, value, hints)) {
2003:                throw new OperationNotSupportedException("Cannot encode");
2004:            }
2005:
2006:            LinearRing g = (LinearRing) value;
2007:
2008:            output.startElement(element.getNamespace(), element.getName(), null);
2009:            GMLComplexTypes.encode(null, g, output);
2010:            output.endElement(element.getNamespace(), element.getName());
2011:        }
2012:    }
2013:
2014:    /**
2015:     * <p>
2016:     * This class represents an PointType within the GML Schema.  This includes
2017:     * both the data and parsing functionality associated  with an PointType.
2018:     * </p>
2019:     *
2020:     * @author dzwiers
2021:     *
2022:     * @see GMLComplexType
2023:     * @see ComplexType
2024:     */
2025:    public static class PointType extends GMLComplexType {
2026:
2027:        /**
2028:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
2029:         */
2030:        public Element[] getChildElements() {
2031:            return elements;
2032:        }
2033:
2034:        // singleton instance
2035:        private static final GMLComplexType instance = new PointType();
2036:
2037:        // static element list
2038:        private static final Element[] elements = {
2039:                new GMLElement("coord",
2040:                    GMLComplexTypes.CoordType.getInstance(), 1, 1, false, null),
2041:                new GMLElement("coordinates",
2042:                    GMLComplexTypes.CoordinatesType.getInstance(), 1, 1, false,
2043:                    null)
2044:            };
2045:
2046:        // static choice
2047:        private static final DefaultChoice seq = new DefaultChoice(elements);
2048:
2049:        /*
2050:         * part of the singleton pattern
2051:         *
2052:         * @see GMLComplexType#getInstance()
2053:         */
2054:        public static GMLComplexType getInstance() {
2055:            return instance;
2056:        }
2057:
2058:        /**
2059:         * @see schema.ComplexType#isAbstract()
2060:         */
2061:        public boolean isAbstract() {
2062:            return false;
2063:        }
2064:
2065:        /**
2066:         * @see schema.ComplexType#getAnyAttributeNameSpace()
2067:         */
2068:        public String getAnyAttributeNameSpace() {
2069:            return null;
2070:        }
2071:
2072:        /**
2073:         * @see schema.ComplexType#getAttributes()
2074:         */
2075:        public Attribute[] getAttributes() {
2076:            return AbstractGeometryType.attributes;
2077:        }
2078:
2079:        /**
2080:         * @see schema.ComplexType#getChildren()
2081:         */
2082:        public ElementGrouping getChild() {
2083:            return seq;
2084:        }
2085:
2086:        /**
2087:         * @see schema.ComplexType#getName()
2088:         */
2089:        public String getName() {
2090:            return "PointType";
2091:        }
2092:
2093:        /**
2094:         * @throws SAXException
2095:         * @throws OperationNotSupportedException
2096:         * @see schema.Type#getValue(java.util.List)
2097:         */
2098:        public Object getValue(Element element, ElementValue[] value,
2099:            Attributes attrs, Map hints) throws OperationNotSupportedException, SAXException {
2100:            if (value.length > 1) {
2101:                throw new SAXException("Cannot have more than one coord per "
2102:                    + getName());
2103:            }
2104:
2105:            Element e = value[0].getElement();
2106:
2107:            if (e == null) {
2108:            	if(!element.isNillable())
2109:            		throw new SAXException(
2110:                    	"Internal error, ElementValues require an associated Element.");
2111:            	return null;
2112:            }
2113:
2114:            Object t = value[0].getValue();
2115:            Point p = null;
2116:
2117:            if (t == null) {
2118:                throw new SAXException("Invalid coordinate specified");
2119:            }
2120:
2121:            GeometryFactory gf = new GeometryFactory(DefaultCoordinateSequenceFactory
2122:                    .instance());
2123:
2124:            if (t instanceof  Coordinate) {
2125:                Coordinate c = (Coordinate) t;
2126:                p = gf.createPoint(c);
2127:            } else {
2128:                CoordinateSequence c = (CoordinateSequence) t;
2129:                p = gf.createPoint(c);
2130:            }
2131:
2132:            ElementValue[] ev = new ElementValue[1];
2133:            ev[0] = new DefaultElementValue(element, p);
2134:
2135:            return AbstractGeometryType.getInstance().getValue(element, ev,
2136:                attrs, hints);
2137:        }
2138:
2139:        /**
2140:         * @see org.geotools.xml.xsi.Type#getInstanceType()
2141:         */
2142:        public Class getInstanceType() {
2143:            return Point.class;
2144:        }
2145:
2146:        /**
2147:         * @see schema.ComplexType#findChildElement(java.lang.String)
2148:         */
2149:        public Element findChildElement(String name) {
2150:            if (name == null) {
2151:                return null;
2152:            }
2153:
2154:            for (int i = 0; i < elements.length; i++)
2155:                if (name.equals(elements[i].getName())) {
2156:                    return elements[i];
2157:                }
2158:
2159:            return null;
2160:        }
2161:
2162:        /**
2163:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
2164:         *      java.lang.Object, java.util.Map)
2165:         */
2166:        public boolean canEncode(Element element, Object value, Map hints) {
2167:            ComplexType t = (element.getType() instanceof  ComplexType)
2168:                ? (ComplexType) element.getType() : null;
2169:
2170:            while ((t != null) && (t != this ))
2171:                t = (t.getParent() instanceof  ComplexType)
2172:                    ? (ComplexType) t.getParent() : null;
2173:
2174:            return ((t != null) && (value instanceof  Point));
2175:        }
2176:
2177:        /**
2178:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
2179:         *      java.lang.Object, org.geotools.xml.PrintHandler,
2180:         *      java.util.Map)
2181:         */
2182:        public void encode(Element element, Object value, PrintHandler output,
2183:            Map hints) throws IOException, OperationNotSupportedException {
2184:            if (!canEncode(element, value, hints)) {
2185:                throw new OperationNotSupportedException("Cannot encode");
2186:            }
2187:
2188:            Point g = (Point) value;
2189:
2190:            GMLComplexTypes.encode(element, g, output);
2191:        }
2192:    }
2193:
2194:    /**
2195:     * <p>
2196:     * This class represents an LineStringType within the GML Schema.  This
2197:     * includes both the data and parsing functionality associated  with an
2198:     * LineStringType.
2199:     * </p>
2200:     *
2201:     * @author dzwiers
2202:     *
2203:     * @see GMLComplexType
2204:     * @see ComplexType
2205:     */
2206:    public static class LineStringType extends GMLComplexType {
2207:
2208:        /**
2209:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
2210:         */
2211:        public Element[] getChildElements() {
2212:            return elements;
2213:        }
2214:
2215:        // singleton instance
2216:        private static final GMLComplexType instance = new LineStringType();
2217:
2218:        // static element list
2219:        private static final Element[] elements = {
2220:                new GMLElement("coord",
2221:                    GMLComplexTypes.CoordType.getInstance(), 2,
2222:                    ElementGrouping.UNBOUNDED, false, null),
2223:                new GMLElement("coordinates",
2224:                    GMLComplexTypes.CoordinatesType.getInstance(), 1, 1, false,
2225:                    null)
2226:            };
2227:
2228:        // static choice
2229:        private static final DefaultChoice seq = new DefaultChoice(elements);
2230:
2231:        /*
2232:         * part of the singleton pattern
2233:         *
2234:         * @see GMLComplexType#getInstance()
2235:         */
2236:        public static GMLComplexType getInstance() {
2237:            return instance;
2238:        }
2239:
2240:        /**
2241:         * @see schema.ComplexType#isAbstract()
2242:         */
2243:        public boolean isAbstract() {
2244:            return false;
2245:        }
2246:
2247:        /**
2248:         * @see schema.ComplexType#getAnyAttributeNameSpace()
2249:         */
2250:        public String getAnyAttributeNameSpace() {
2251:            return null;
2252:        }
2253:
2254:        /**
2255:         * @see schema.ComplexType#getAttributes()
2256:         */
2257:        public Attribute[] getAttributes() {
2258:            return AbstractGeometryType.attributes;
2259:        }
2260:
2261:        /**
2262:         * @see schema.ComplexType#getChildren()
2263:         */
2264:        public ElementGrouping getChild() {
2265:            return seq;
2266:        }
2267:
2268:        /**
2269:         * @see schema.ComplexType#getName()
2270:         */
2271:        public String getName() {
2272:            return "LineStringType";
2273:        }
2274:
2275:        /**
2276:         * @throws SAXException
2277:         * @throws OperationNotSupportedException
2278:         * @see schema.Type#getValue(java.util.List)
2279:         */
2280:        public Object getValue(Element element, ElementValue[] value,
2281:            Attributes attrs, Map hints) throws OperationNotSupportedException, SAXException {
2282:            Element e = value[0].getElement();
2283:
2284:            if (e == null) {
2285:            	if(!element.isNillable())
2286:            		throw new SAXException(
2287:                    	"Internal error, ElementValues require an associated Element.");
2288:            	return null;
2289:            }
2290:
2291:            Object t = value[0].getValue();
2292:            LineString p = null;
2293:
2294:            if (t == null) {
2295:                throw new SAXException("Invalid coordinate specified");
2296:            }
2297:
2298:            GeometryFactory gf = new GeometryFactory(DefaultCoordinateSequenceFactory
2299:                    .instance());
2300:
2301:            if (t instanceof  Coordinate) {
2302:                if (value.length < 2) {
2303:                    throw new SAXException(
2304:                        "Cannot have more than one coord per " + getName());
2305:                }
2306:
2307:                // there should be more
2308:                Coordinate[] c = new Coordinate[value.length];
2309:
2310:                for (int i = 0; i < c.length; i++)
2311:                    c[i] = (Coordinate) value[i].getValue();
2312:
2313:                p = gf.createLineString(c);
2314:            } else {
2315:                if (value.length > 1) {
2316:                    throw new SAXException(
2317:                        "Cannot have more than one coordinate sequence per "
2318:                        + getName());
2319:                }
2320:
2321:                CoordinateSequence c = (CoordinateSequence) t;
2322:                // TODO -- be forgiving
2323:                if(c.size() == 1){
2324:                    c = DefaultCoordinateSequenceFactory.instance().create(new Coordinate[]{c.getCoordinate(0),c.getCoordinate(0)});
2325:                }
2326:                p = gf.createLineString(c);
2327:            }
2328:
2329:            ElementValue[] ev = new ElementValue[1];
2330:            ev[0] = new DefaultElementValue(element, p);
2331:
2332:            return AbstractGeometryType.getInstance().getValue(element, ev,
2333:                attrs, hints);
2334:        }
2335:
2336:        /**
2337:         * @see org.geotools.xml.xsi.Type#getInstanceType()
2338:         */
2339:        public Class getInstanceType() {
2340:            return LineString.class;
2341:        }
2342:
2343:        /**
2344:         * @see schema.ComplexType#findChildElement(java.lang.String)
2345:         */
2346:        public Element findChildElement(String name) {
2347:            if (name == null) {
2348:                return null;
2349:            }
2350:
2351:            for (int i = 0; i < elements.length; i++)
2352:                if (name.equals(elements[i].getName())) {
2353:                    return elements[i];
2354:                }
2355:
2356:            return null;
2357:        }
2358:
2359:        /**
2360:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
2361:         *      java.lang.Object, java.util.Map)
2362:         */
2363:        public boolean canEncode(Element element, Object value, Map hints) {
2364:            ComplexType t = (element.getType() instanceof  ComplexType)
2365:                ? (ComplexType) element.getType() : null;
2366:
2367:            while ((t != null) && (t != this ))
2368:                t = (t.getParent() instanceof  ComplexType)
2369:                    ? (ComplexType) t.getParent() : null;
2370:
2371:            return ((t != null) && (value instanceof  LineString));
2372:        }
2373:
2374:        /**
2375:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
2376:         *      java.lang.Object, org.geotools.xml.PrintHandler,
2377:         *      java.util.Map)
2378:         */
2379:        public void encode(Element element, Object value, PrintHandler output,
2380:            Map hints) throws IOException, OperationNotSupportedException {
2381:            if (!canEncode(element, value, hints)) {
2382:                throw new OperationNotSupportedException("Cannot encode");
2383:            }
2384:
2385:            LineString g = (LineString) value;
2386:
2387:            GMLComplexTypes.encode(element, g, output);
2388:        }
2389:    }
2390:
2391:    /**
2392:     * <p>
2393:     * This class represents an LinearRingType within the GML Schema.  This
2394:     * includes both the data and parsing functionality associated  with an
2395:     * LinearRingType.
2396:     * </p>
2397:     *
2398:     * @author dzwiers
2399:     *
2400:     * @see GMLComplexType
2401:     * @see ComplexType
2402:     */
2403:    public static class LinearRingType extends GMLComplexType {
2404:
2405:        /**
2406:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
2407:         */
2408:        public Element[] getChildElements() {
2409:            return elements;
2410:        }
2411:
2412:        // singleton instance
2413:        private static final GMLComplexType instance = new LinearRingType();
2414:
2415:        // static element list
2416:        private static final Element[] elements = {
2417:                new GMLElement("coord",
2418:                    GMLComplexTypes.CoordType.getInstance(), 2, 4, false, null),
2419:                new GMLElement("coordinates",
2420:                    GMLComplexTypes.CoordinatesType.getInstance(), 1, 1, false,
2421:                    null)
2422:            };
2423:
2424:        // static sequence
2425:        private static final DefaultChoice seq = new DefaultChoice(elements);
2426:
2427:        /*
2428:         * part of the singleton pattern
2429:         *
2430:         * @see GMLComplexType#getInstance()
2431:         */
2432:        public static GMLComplexType getInstance() {
2433:            return instance;
2434:        }
2435:
2436:        /**
2437:         * @see schema.ComplexType#isAbstract()
2438:         */
2439:        public boolean isAbstract() {
2440:            return false;
2441:        }
2442:
2443:        /**
2444:         * @see schema.ComplexType#getAnyAttributeNameSpace()
2445:         */
2446:        public String getAnyAttributeNameSpace() {
2447:            return null;
2448:        }
2449:
2450:        /**
2451:         * @see schema.ComplexType#getAttributes()
2452:         */
2453:        public Attribute[] getAttributes() {
2454:            return AbstractGeometryType.attributes;
2455:        }
2456:
2457:        /**
2458:         * @see schema.ComplexType#getChildren()
2459:         */
2460:        public ElementGrouping getChild() {
2461:            return seq;
2462:        }
2463:
2464:        /**
2465:         * @see schema.ComplexType#getName()
2466:         */
2467:        public String getName() {
2468:            return "LinearRingType";
2469:        }
2470:
2471:        /**
2472:         * @throws SAXException
2473:         * @throws OperationNotSupportedException
2474:         * @see schema.Type#getValue(java.util.List)
2475:         */
2476:        public Object getValue(Element element, ElementValue[] value,
2477:            Attributes attrs, Map hints) throws OperationNotSupportedException, SAXException {
2478:            Element e = value[0].getElement();
2479:
2480:            if (e == null) {
2481:            	if(!element.isNillable())
2482:            		throw new SAXException(
2483:                    	"Internal error, ElementValues require an associated Element.");
2484:            	return null;
2485:            }
2486:
2487:            Object t = value[0].getValue();
2488:            LinearRing p = null;
2489:
2490:            if (t == null) {
2491:                throw new SAXException("Invalid coordinate specified");
2492:            }
2493:
2494:            GeometryFactory gf = new GeometryFactory(DefaultCoordinateSequenceFactory
2495:                    .instance());
2496:
2497:            if (t instanceof  Coordinate) {
2498:                if (value.length < 4) {
2499:                    throw new SAXException(
2500:                        "Cannot have more than one coord per " + getName());
2501:                }
2502:
2503:                // there should be more
2504:                Coordinate[] c = new Coordinate[value.length];
2505:
2506:                for (int i = 0; i < c.length; i++)
2507:                    c[i] = (Coordinate) value[i].getValue();
2508:
2509:                p = gf.createLinearRing(c);
2510:            } else {
2511:                if (value.length > 1) {
2512:                    throw new SAXException(
2513:                        "Cannot have more than one coordinate sequence per "
2514:                        + getName());
2515:                }
2516:
2517:                CoordinateSequence c = (CoordinateSequence) t;
2518:                p = gf.createLinearRing(c);
2519:            }
2520:
2521:            ElementValue[] ev = new ElementValue[1];
2522:            ev[0] = new DefaultElementValue(element, p);
2523:
2524:            return AbstractGeometryType.getInstance().getValue(element, ev,
2525:                attrs, hints);
2526:        }
2527:
2528:        /**
2529:         * @see org.geotools.xml.xsi.Type#getInstanceType()
2530:         */
2531:        public Class getInstanceType() {
2532:            return LinearRing.class;
2533:        }
2534:
2535:        /**
2536:         * @see schema.ComplexType#findChildElement(java.lang.String)
2537:         */
2538:        public Element findChildElement(String name) {
2539:            if (name == null) {
2540:                return null;
2541:            }
2542:
2543:            for (int i = 0; i < elements.length; i++)
2544:                if (name.equals(elements[i].getName())) {
2545:                    return elements[i];
2546:                }
2547:
2548:            return null;
2549:        }
2550:
2551:        /**
2552:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
2553:         *      java.lang.Object, java.util.Map)
2554:         */
2555:        public boolean canEncode(Element element, Object value, Map hints) {
2556:            ComplexType t = (element.getType() instanceof  ComplexType)
2557:                ? (ComplexType) element.getType() : null;
2558:
2559:            while ((t != null) && (t != this ))
2560:                t = (t.getParent() instanceof  ComplexType)
2561:                    ? (ComplexType) t.getParent() : null;
2562:
2563:            return ((t != null) && (value instanceof  LinearRing));
2564:        }
2565:
2566:        /**
2567:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
2568:         *      java.lang.Object, org.geotools.xml.PrintHandler,
2569:         *      java.util.Map)
2570:         */
2571:        public void encode(Element element, Object value, PrintHandler output,
2572:            Map hints) throws IOException, OperationNotSupportedException {
2573:            if (!canEncode(element, value, hints)) {
2574:                throw new OperationNotSupportedException("Cannot encode");
2575:            }
2576:
2577:            LinearRing g = (LinearRing) value;
2578:
2579:            GMLComplexTypes.encode(element, g, output);
2580:        }
2581:    }
2582:
2583:    /**
2584:     * <p>
2585:     * This class represents an BoxType within the GML Schema.  This includes
2586:     * both the data and parsing functionality associated  with an BoxType.
2587:     * </p>
2588:     *
2589:     * @author dzwiers
2590:     *
2591:     * @see GMLComplexType
2592:     * @see ComplexType
2593:     */
2594:    public static class BoxType extends GMLComplexType {
2595:
2596:        /**
2597:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
2598:         */
2599:        public Element[] getChildElements() {
2600:            return elements;
2601:        }
2602:
2603:        // singleton instance
2604:        private static final GMLComplexType instance = new BoxType();
2605:
2606:        // static element list
2607:        private static final Element[] elements = {
2608:                new GMLElement("coord",
2609:                    GMLComplexTypes.CoordType.getInstance(), 2, 2, false, null),
2610:                new GMLElement("coordinates",
2611:                    GMLComplexTypes.CoordinatesType.getInstance(), 1, 1, false,
2612:                    null)
2613:            };
2614:
2615:        // static sequence
2616:        private static final DefaultChoice seq = new DefaultChoice(elements);
2617:
2618:        /*
2619:         * part of the singleton pattern
2620:         *
2621:         * @see GMLComplexType#getInstance()
2622:         */
2623:        public static GMLComplexType getInstance() {
2624:            return instance;
2625:        }
2626:
2627:        /**
2628:         * @see schema.ComplexType#isAbstract()
2629:         */
2630:        public boolean isAbstract() {
2631:            return false;
2632:        }
2633:
2634:        /**
2635:         * @see schema.ComplexType#getAnyAttributeNameSpace()
2636:         */
2637:        public String getAnyAttributeNameSpace() {
2638:            return null;
2639:        }
2640:
2641:        /**
2642:         * @see schema.ComplexType#getAttributes()
2643:         */
2644:        public Attribute[] getAttributes() {
2645:            return AbstractGeometryType.attributes;
2646:        }
2647:
2648:        /**
2649:         * @see schema.ComplexType#getChildren()
2650:         */
2651:        public ElementGrouping getChild() {
2652:            return seq;
2653:        }
2654:
2655:        /**
2656:         * @see schema.ComplexType#getName()
2657:         */
2658:        public String getName() {
2659:            return "BoxType";
2660:        }
2661:
2662:        /**
2663:         * @throws SAXException
2664:         * @throws OperationNotSupportedException
2665:         * @see schema.Type#getValue(java.util.List)
2666:         */
2667:        public Object getValue(Element element, ElementValue[] value,
2668:            Attributes attrs, Map hints) throws OperationNotSupportedException, SAXException {
2669:            Element e = value[0].getElement();
2670:
2671:            if (e == null) {
2672:            	if(!element.isNillable())
2673:            		throw new SAXException(
2674:                    	"Internal error, ElementValues require an associated Element.");
2675:            	return null;
2676:            }
2677:
2678:            Object t = value[0].getValue();
2679:            LineString p = null;
2680:
2681:            if (t == null) {
2682:                throw new SAXException("Invalid coordinate specified");
2683:            }
2684:
2685:            GeometryFactory gf = new GeometryFactory(DefaultCoordinateSequenceFactory
2686:                    .instance());
2687:
2688:            try {
2689:                if (t instanceof  Coordinate) {
2690:                    if (value.length != 2) {
2691:                        throw new SAXException(
2692:                            "Cannot have more than one coord per " + getName());
2693:                    }
2694:
2695:                    // there should be more
2696:                    Coordinate[] c = new Coordinate[value.length];
2697:
2698:                    for (int i = 0; i < c.length; i++)
2699:                        c[i] = (Coordinate) value[i].getValue();
2700:
2701:                    p = gf.createLineString(c);
2702:                } else {
2703:                    if (value.length > 1) {
2704:                        throw new SAXException(
2705:                            "Cannot have more than one coordinate sequence per "
2706:                            + getName());
2707:                    }
2708:
2709:                    CoordinateSequence c = (CoordinateSequence) t;
2710:                    p = gf.createLineString(c);
2711:                }
2712:            } catch (ClassCastException cce) {
2713:                logger.warning(cce.toString());
2714:                logger.warning(t + ((t == null) ? "" : t.getClass().getName()));
2715:                throw cce;
2716:            }
2717:
2718:            ElementValue[] ev = new ElementValue[1];
2719:            ev[0] = new DefaultElementValue(element, p.getEnvelope());
2720:
2721:            return AbstractGeometryType.getInstance().getValue(element, ev,
2722:                attrs, hints);
2723:        }
2724:
2725:        /**
2726:         * @see org.geotools.xml.xsi.Type#getInstanceType()
2727:         */
2728:        public Class getInstanceType() {
2729:            return Geometry.class;
2730:        }
2731:
2732:        /**
2733:         * @see schema.ComplexType#findChildElement(java.lang.String)
2734:         */
2735:        public Element findChildElement(String name) {
2736:            if (name == null) {
2737:                return null;
2738:            }
2739:
2740:            for (int i = 0; i < elements.length; i++)
2741:                if (name.equals(elements[i].getName())) {
2742:                    return elements[i];
2743:                }
2744:
2745:            return null;
2746:        }
2747:
2748:        /**
2749:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
2750:         *      java.lang.Object, java.util.Map)
2751:         */
2752:        public boolean canEncode(Element element, Object value, Map hints) {
2753:            //since bounds is a derived attibute in our feature model and not 
2754:            // an attribute which is modelled explicitly in feature types, there
2755:            // might not be an element around for it, so we dont require that 
2756:            // there be one and simply check that the value being encoded is a 
2757:            // geometry
2758:            return value instanceof  Geometry;
2759:        }
2760:
2761:        /**
2762:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
2763:         *      java.lang.Object, org.geotools.xml.PrintHandler,
2764:         *      java.util.Map)
2765:         */
2766:        public void encode(Element element, Object value, PrintHandler output,
2767:            Map hints) throws IOException, OperationNotSupportedException {
2768:            if (!canEncode(element, value, hints)) {
2769:                throw new OperationNotSupportedException("Cannot encode");
2770:            }
2771:
2772:            Geometry g = null;
2773:            	g=(Geometry) value;
2774:
2775:            AttributesImpl ai = new AttributesImpl();
2776:
2777:            // no GID
2778:            if (g.getUserData() != null) {
2779:                // TODO Fix this when parsing is better ... should be a coord reference system
2780:                ai.addAttribute("", "srsName", "", "anyURI",
2781:                    g.getUserData().toString());
2782:            } else {
2783://                if (g.getSRID() != 0) {
2784://                    // deprecated version
2785://                    ai.addAttribute("", "srsName", "", "anyURI",
2786://                        "" + g.getSRID());
2787://                } else {
2788:                    ai = null;
2789://                }
2790:            }
2791:
2792:            if ((g == null) || (g.getNumPoints() == 0)
2793:                    || (g.getCoordinates().length == 0)) {
2794:                return;
2795:            }
2796:
2797:            //we handle the case for a null element, see canEncode for details
2798:            if (element != null) {
2799:                output.startElement(GMLSchema.NAMESPACE, element.getName(), ai);
2800:            }
2801:            else { 
2802:                output.startElement(GMLSchema.NAMESPACE, "Box", ai);
2803:            }
2804:            
2805://            Coordinate[] coords = g.getCoordinates();
2806:            Envelope e = g.getEnvelopeInternal();
2807:            encodeCoords(elements[1], e, output);
2808:            
2809:            if (element != null) {
2810:                output.endElement(GMLSchema.NAMESPACE, element.getName());
2811:            }
2812:            else { 
2813:                output.endElement(GMLSchema.NAMESPACE, "Box");
2814:            }
2815:        }
2816:    }
2817:
2818:    /**
2819:     * <p>
2820:     * This class represents an PolygonType within the GML Schema.  This
2821:     * includes both the data and parsing functionality associated  with an
2822:     * PolygonType.
2823:     * </p>
2824:     *
2825:     * @author dzwiers
2826:     *
2827:     * @see GMLComplexType
2828:     * @see ComplexType
2829:     */
2830:    public static class PolygonType extends GMLComplexType {
2831:
2832:        /**
2833:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
2834:         */
2835:        public Element[] getChildElements() {
2836:            return elements;
2837:        }
2838:
2839:        // singleton instance
2840:        private static final GMLComplexType instance = new PolygonType();
2841:
2842:        // static list of elements
2843:        private static final Element[] elements = {
2844:                new GMLElement("outerBoundaryIs",
2845:                    GMLComplexTypes.LinearRingMemberType.getInstance(), 1, 1,
2846:                    false, null),
2847:                new GMLElement("innerBoundaryIs",
2848:                    GMLComplexTypes.LinearRingMemberType.getInstance(), 0,
2849:                    ElementGrouping.UNBOUNDED, false, null)
2850:            };
2851:
2852:        // static sequence
2853:        private static final DefaultSequence seq = new DefaultSequence(elements);
2854:
2855:        /*
2856:         * part of the singleton pattern
2857:         *
2858:         * @see GMLComplexType#getInstance()
2859:         */
2860:        public static GMLComplexType getInstance() {
2861:            return instance;
2862:        }
2863:
2864:        /**
2865:         * @see schema.ComplexType#isAbstract()
2866:         */
2867:        public boolean isAbstract() {
2868:            return false;
2869:        }
2870:
2871:        /**
2872:         * @see schema.ComplexType#getAnyAttributeNameSpace()
2873:         */
2874:        public String getAnyAttributeNameSpace() {
2875:            return null;
2876:        }
2877:
2878:        /**
2879:         * @see schema.ComplexType#getAttributes()
2880:         */
2881:        public Attribute[] getAttributes() {
2882:            return AbstractGeometryType.attributes;
2883:        }
2884:
2885:        /**
2886:         * @see schema.ComplexType#getChildren()
2887:         */
2888:        public ElementGrouping getChild() {
2889:            return seq;
2890:        }
2891:
2892:        /**
2893:         * @see schema.ComplexType#getName()
2894:         */
2895:        public String getName() {
2896:            return "PolygonType";
2897:        }
2898:
2899:        /**
2900:         * @throws SAXException
2901:         * @throws OperationNotSupportedException
2902:         * @see schema.Type#getValue(java.util.List)
2903:         */
2904:        public Object getValue(Element element, ElementValue[] value,
2905:            Attributes attrs, Map hints) throws OperationNotSupportedException, SAXException {
2906:            Element e = value[0].getElement();
2907:
2908:            if (e == null) {
2909:            	if(!element.isNillable())
2910:            		throw new SAXException(
2911:                    	"Internal error, ElementValues require an associated Element.");
2912:            	return null;
2913:            }
2914:
2915:            GeometryFactory gf = new GeometryFactory(DefaultCoordinateSequenceFactory
2916:                    .instance());
2917:
2918:            LinearRing outerLR = null;
2919:            LinearRing[] innerLR = new LinearRing[(value.length > 1)
2920:                ? (value.length - 1) : 0];
2921:            int innerIndex = 0;
2922:
2923:            for (int i = 0; i < value.length; i++) {
2924:                if (elements[0].getName().equalsIgnoreCase(value[i].getElement()
2925:                                                                       .getName())) {
2926:                    outerLR = (LinearRing) value[i].getValue();
2927:                } else {
2928:                    innerLR[innerIndex++] = (LinearRing) value[i].getValue();
2929:                }
2930:            }
2931:
2932:            Polygon p = gf.createPolygon(outerLR, innerLR);
2933:
2934:            ElementValue[] ev = new ElementValue[1];
2935:            ev[0] = new DefaultElementValue(element, p);
2936:
2937:            return AbstractGeometryType.getInstance().getValue(element, ev,
2938:                attrs, hints);
2939:        }
2940:
2941:        /**
2942:         * @see org.geotools.xml.xsi.Type#getInstanceType()
2943:         */
2944:        public Class getInstanceType() {
2945:            return Polygon.class;
2946:        }
2947:
2948:        /**
2949:         * @see schema.ComplexType#findChildElement(java.lang.String)
2950:         */
2951:        public Element findChildElement(String name) {
2952:            if (name == null) {
2953:                return null;
2954:            }
2955:
2956:            for (int i = 0; i < elements.length; i++)
2957:                if (name.equals(elements[i].getName())) {
2958:                    return elements[i];
2959:                }
2960:
2961:            return null;
2962:        }
2963:
2964:        /**
2965:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
2966:         *      java.lang.Object, java.util.Map)
2967:         */
2968:        public boolean canEncode(Element element, Object value, Map hints) {
2969:            ComplexType t = (element.getType() instanceof  ComplexType)
2970:                ? (ComplexType) element.getType() : null;
2971:
2972:            while ((t != null) && (t != this )){
2973:                
2974:                if (t.getParent() instanceof  ComplexType){
2975:                    t = (ComplexType) t.getParent();
2976:                }else
2977:                    t=null;
2978:            }
2979:
2980:            return ((t != null) && (value instanceof  Polygon));
2981:        }
2982:
2983:        /**
2984:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
2985:         *      java.lang.Object, org.geotools.xml.PrintHandler,
2986:         *      java.util.Map)
2987:         */
2988:        public void encode(Element element, Object value, PrintHandler output,
2989:            Map hints) throws IOException, OperationNotSupportedException {
2990:            if (!canEncode(element, value, hints)) {
2991:                throw new OperationNotSupportedException("Cannot encode");
2992:            }
2993:
2994:            Polygon g = (Polygon) value;
2995:
2996:            GMLComplexTypes.encode(element, g, output);
2997:        }
2998:    }
2999:
3000:    /**
3001:     * <p>
3002:     * This class represents an GeometryCollectionType within the GML Schema.
3003:     * This includes both the data and parsing functionality associated  with
3004:     * an GeometryCollectionType.
3005:     * </p>
3006:     *
3007:     * @author dzwiers
3008:     *
3009:     * @see GMLComplexType
3010:     * @see ComplexType
3011:     */
3012:    public static class GeometryCollectionType extends GMLComplexType {
3013:
3014:        /**
3015:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
3016:         */
3017:        public Element[] getChildElements() {
3018:            return elements;
3019:        }
3020:
3021:        // singleton instance
3022:        private static final GMLComplexType instance = new GeometryCollectionType();
3023:
3024:        // static lsit of elements
3025:        private static final Element[] elements = {
3026:                new GMLElement("geometryMember",
3027:                    GMLComplexTypes.GeometryAssociationType.getInstance(), 1,
3028:                    ElementGrouping.UNBOUNDED, false, null),
3029:            };
3030:
3031:        // static sequence
3032:        private static final DefaultSequence seq = new DefaultSequence(elements);
3033:
3034:        /*
3035:         * part of the singleton pattern
3036:         *
3037:         * @see GMLComplexType#getInstance()
3038:         */
3039:        public static GMLComplexType getInstance() {
3040:            return instance;
3041:        }
3042:
3043:        /**
3044:         * @see schema.ComplexType#isAbstract()
3045:         */
3046:        public boolean isAbstract() {
3047:            return false;
3048:        }
3049:
3050:        /**
3051:         * @see schema.ComplexType#getAnyAttributeNameSpace()
3052:         */
3053:        public String getAnyAttributeNameSpace() {
3054:            return null;
3055:        }
3056:
3057:        /**
3058:         * @see schema.ComplexType#getAttributes()
3059:         */
3060:        public Attribute[] getAttributes() {
3061:            return AbstractGeometryCollectionBaseType.attributes;
3062:        }
3063:
3064:        /**
3065:         * @see schema.ComplexType#getChildren()
3066:         */
3067:        public ElementGrouping getChild() {
3068:            return seq;
3069:        }
3070:
3071:        /**
3072:         * @see schema.ComplexType#getName()
3073:         */
3074:        public String getName() {
3075:            return "GeometryCollectionType";
3076:        }
3077:
3078:        /**
3079:         * @see schema.Type#getValue(java.util.List)
3080:         */
3081:        public Object getValue(Element element, ElementValue[] value,
3082:            Attributes attrs, Map hints) throws SAXException {
3083:            Element e = value[0].getElement();
3084:
3085:            if (e == null) {
3086:            	if(!element.isNillable())
3087:            		throw new SAXException(
3088:                    	"Internal error, ElementValues require an associated Element.");
3089:            	return null;
3090:            }
3091:
3092:            GeometryFactory gf = new GeometryFactory(DefaultCoordinateSequenceFactory
3093:                    .instance());
3094:
3095:            Geometry[] geoms = new Geometry[value.length];
3096:
3097:            for (int i = 0; i < value.length; i++) {
3098:                geoms[i] = (Geometry) value[i].getValue();
3099:            }
3100:
3101:            return gf.createGeometryCollection(geoms);
3102:        }
3103:
3104:        /**
3105:         * @see org.geotools.xml.xsi.Type#getInstanceType()
3106:         */
3107:        public Class getInstanceType() {
3108:            return GeometryCollection.class;
3109:        }
3110:
3111:        /**
3112:         * @see schema.ComplexType#findChildElement(java.lang.String)
3113:         */
3114:        public Element findChildElement(String name) {
3115:            if (name == null) {
3116:                return null;
3117:            }
3118:
3119:            for (int i = 0; i < elements.length; i++)
3120:                if (name.equals(elements[i].getName())) {
3121:                    return elements[i];
3122:                }
3123:
3124:            return null;
3125:        }
3126:
3127:        /**
3128:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
3129:         *      java.lang.Object, java.util.Map)
3130:         */
3131:        public boolean canEncode(Element element, Object value, Map hints) {
3132:            ComplexType t = (element.getType() instanceof  ComplexType)
3133:                ? (ComplexType) element.getType() : null;
3134:
3135:            while ((t != null) && (t != this ))
3136:                t = (t.getParent() instanceof  ComplexType)
3137:                    ? (ComplexType) t.getParent() : null;
3138:
3139:            return ((t != null) && (value instanceof  GeometryCollection));
3140:        }
3141:
3142:        /**
3143:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
3144:         *      java.lang.Object, org.geotools.xml.PrintHandler,
3145:         *      java.util.Map)
3146:         */
3147:        public void encode(Element element, Object value, PrintHandler output,
3148:            Map hints) throws IOException, OperationNotSupportedException {
3149:            if (!canEncode(element, value, hints)) {
3150:                throw new OperationNotSupportedException("Cannot encode");
3151:            }
3152:
3153:            GeometryCollection g = (GeometryCollection) value;
3154:
3155:            GMLComplexTypes.encode(element, g, output);
3156:        }
3157:    }
3158:
3159:    /**
3160:     * <p>
3161:     * This class represents an MultiPointType within the GML Schema.  This
3162:     * includes both the data and parsing functionality associated  with an
3163:     * MultiPointType.
3164:     * </p>
3165:     *
3166:     * @author dzwiers
3167:     *
3168:     * @see GMLComplexType
3169:     * @see ComplexType
3170:     */
3171:    public static class MultiPointType extends GMLComplexType {
3172:
3173:        /**
3174:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
3175:         */
3176:        public Element[] getChildElements() {
3177:            return elements;
3178:        }
3179:
3180:        // singleton instance
3181:        private static final GMLComplexType instance = new MultiPointType();
3182:
3183:        // static element list
3184:        private static final Element[] elements = {
3185:                new GMLElement("pointMember",
3186:                    GMLComplexTypes.PointMemberType.getInstance(), 1,
3187:                    ElementGrouping.UNBOUNDED, false,
3188:                    new GMLElement("geometryMember",
3189:                        GMLComplexTypes.GeometryAssociationType.getInstance(),
3190:                        1, 1, false, null)),
3191:            };
3192:
3193:        // static sequence
3194:        private static final DefaultSequence seq = new DefaultSequence(elements);
3195:
3196:        /*
3197:         * part of the singleton pattern
3198:         *
3199:         * @see GMLComplexType#getInstance()
3200:         */
3201:        public static GMLComplexType getInstance() {
3202:            return instance;
3203:        }
3204:
3205:        /**
3206:         * @see schema.ComplexType#isAbstract()
3207:         */
3208:        public boolean isAbstract() {
3209:            return false;
3210:        }
3211:
3212:        /**
3213:         * @see schema.ComplexType#getAnyAttributeNameSpace()
3214:         */
3215:        public String getAnyAttributeNameSpace() {
3216:            return null;
3217:        }
3218:
3219:        /**
3220:         * @see schema.ComplexType#getAttributes()
3221:         */
3222:        public Attribute[] getAttributes() {
3223:            return AbstractGeometryCollectionBaseType.attributes;
3224:        }
3225:
3226:        /**
3227:         * @see schema.ComplexType#getChildren()
3228:         */
3229:        public ElementGrouping getChild() {
3230:            return seq;
3231:        }
3232:
3233:        /**
3234:         * @see schema.ComplexType#getName()
3235:         */
3236:        public String getName() {
3237:            return "MultiPointType";
3238:        }
3239:
3240:        /**
3241:         * @throws OperationNotSupportedException 
3242:         * @see schema.Type#getValue(java.util.List)
3243:         */
3244:        public Object getValue(Element element, ElementValue[] value,
3245:            Attributes attrs, Map hints) throws SAXException, OperationNotSupportedException {
3246:            Element e = value[0].getElement();
3247:
3248:            if (e == null) {
3249:            	if(!element.isNillable())
3250:            		throw new SAXException(
3251:                    	"Internal error, ElementValues require an associated Element.");
3252:            	return null;
3253:            }
3254:
3255:            GeometryFactory gf = new GeometryFactory(DefaultCoordinateSequenceFactory
3256:                    .instance());
3257:
3258:            Point[] geoms = new Point[value.length];
3259:
3260:            for (int i = 0; i < value.length; i++) {
3261:                geoms[i] = (Point) value[i].getValue();
3262:            }
3263:
3264:            MultiPoint mp = gf.createMultiPoint(geoms);
3265:
3266:            ElementValue[] ev = new ElementValue[1];
3267:            ev[0] = new DefaultElementValue(element, mp);
3268:
3269:            return AbstractGeometryType.getInstance().getValue(element, ev,
3270:                attrs, hints);
3271:        }
3272:
3273:        /**
3274:         * @see org.geotools.xml.xsi.Type#getInstanceType()
3275:         */
3276:        public Class getInstanceType() {
3277:            return MultiPoint.class;
3278:        }
3279:
3280:        /**
3281:         * @see schema.ComplexType#findChildElement(java.lang.String)
3282:         */
3283:        public Element findChildElement(String name) {
3284:            if (name == null) {
3285:                return null;
3286:            }
3287:
3288:            for (int i = 0; i < elements.length; i++)
3289:                if (name.equals(elements[i].getName())) {
3290:                    return elements[i];
3291:                }
3292:
3293:            return null;
3294:        }
3295:
3296:        /**
3297:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
3298:         *      java.lang.Object, java.util.Map)
3299:         */
3300:        public boolean canEncode(Element element, Object value, Map hints) {
3301:            ComplexType t = (element.getType() instanceof  ComplexType)
3302:                ? (ComplexType) element.getType() : null;
3303:
3304:            while ((t != null) && (t != this ))
3305:                t = (t.getParent() instanceof  ComplexType)
3306:                    ? (ComplexType) t.getParent() : null;
3307:
3308:            return ((t != null) && (value instanceof  MultiPoint));
3309:        }
3310:
3311:        /**
3312:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
3313:         *      java.lang.Object, org.geotools.xml.PrintHandler,
3314:         *      java.util.Map)
3315:         */
3316:        public void encode(Element element, Object value, PrintHandler output,
3317:            Map hints) throws IOException, OperationNotSupportedException {
3318:            if (!canEncode(element, value, hints)) {
3319:                throw new OperationNotSupportedException("Cannot encode");
3320:            }
3321:
3322:            MultiPoint g = (MultiPoint) value;
3323:
3324:            GMLComplexTypes.encode(element, g, output);
3325:        }
3326:    }
3327:
3328:    /**
3329:     * <p>
3330:     * This class represents an MultiLineStringType within the GML Schema. This
3331:     * includes both the data and parsing functionality associated  with an
3332:     * MultiLineStringType.
3333:     * </p>
3334:     *
3335:     * @author dzwiers
3336:     *
3337:     * @see GMLComplexType
3338:     * @see ComplexType
3339:     */
3340:    public static class MultiLineStringType extends GMLComplexType {
3341:
3342:        /**
3343:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
3344:         */
3345:        public Element[] getChildElements() {
3346:            return elements;
3347:        }
3348:
3349:        // singleton instance
3350:        private static final GMLComplexType instance = new MultiLineStringType();
3351:
3352:        // static element list
3353:        private static final Element[] elements = {
3354:                new GMLElement("lineStringMember",
3355:                    GMLComplexTypes.LineStringMemberType.getInstance(), 1,
3356:                    ElementGrouping.UNBOUNDED, false,
3357:                    new GMLElement("geometryMember",
3358:                        GMLComplexTypes.GeometryAssociationType.getInstance(),
3359:                        1, 1, false, null)),
3360:            };
3361:
3362:        // static sequence
3363:        private static final DefaultSequence seq = new DefaultSequence(elements);
3364:
3365:        /*
3366:         * part of the singleton pattern
3367:         *
3368:         * @see GMLComplexType#getInstance()
3369:         */
3370:        public static GMLComplexType getInstance() {
3371:            return instance;
3372:        }
3373:
3374:        /**
3375:         * @see schema.ComplexType#isAbstract()
3376:         */
3377:        public boolean isAbstract() {
3378:            return false;
3379:        }
3380:
3381:        /**
3382:         * @see schema.ComplexType#getAnyAttributeNameSpace()
3383:         */
3384:        public String getAnyAttributeNameSpace() {
3385:            return null;
3386:        }
3387:
3388:        /**
3389:         * @see schema.ComplexType#getAttributes()
3390:         */
3391:        public Attribute[] getAttributes() {
3392:            return AbstractGeometryCollectionBaseType.attributes;
3393:        }
3394:
3395:        /**
3396:         * @see schema.ComplexType#getChildren()
3397:         */
3398:        public ElementGrouping getChild() {
3399:            return seq;
3400:        }
3401:
3402:        /**
3403:         * @see schema.ComplexType#getName()
3404:         */
3405:        public String getName() {
3406:            return "MultiLineStringType";
3407:        }
3408:
3409:        /**
3410:         * @throws OperationNotSupportedException 
3411:         * @see schema.Type#getValue(java.util.List)
3412:         */
3413:        public Object getValue(Element element, ElementValue[] value,
3414:            Attributes attrs, Map hints) throws SAXException, OperationNotSupportedException {
3415:            Element e = value[0].getElement();
3416:
3417:            if (e == null) {
3418:            	if(!element.isNillable())
3419:            		throw new SAXException(
3420:                    	"Internal error, ElementValues require an associated Element.");
3421:            	return null;
3422:            }
3423:
3424:            GeometryFactory gf = new GeometryFactory(DefaultCoordinateSequenceFactory
3425:                    .instance());
3426:
3427:            LineString[] geoms = new LineString[value.length];
3428:
3429:            for (int i = 0; i < value.length; i++) {
3430:                geoms[i] = (LineString) value[i].getValue();
3431:            }
3432:
3433:            MultiLineString mp = gf.createMultiLineString(geoms);
3434:
3435:            ElementValue[] ev = new ElementValue[1];
3436:            ev[0] = new DefaultElementValue(element, mp);
3437:
3438:            return AbstractGeometryType.getInstance().getValue(element, ev,
3439:                attrs, hints);
3440:        }
3441:
3442:        /**
3443:         * @see org.geotools.xml.xsi.Type#getInstanceType()
3444:         */
3445:        public Class getInstanceType() {
3446:            return MultiLineString.class;
3447:        }
3448:
3449:        /**
3450:         * @see schema.ComplexType#findChildElement(java.lang.String)
3451:         */
3452:        public Element findChildElement(String name) {
3453:            if (name == null) {
3454:                return null;
3455:            }
3456:
3457:            for (int i = 0; i < elements.length; i++)
3458:                if (name.equals(elements[i].getName())) {
3459:                    return elements[i];
3460:                }
3461:
3462:            return null;
3463:        }
3464:
3465:        /**
3466:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
3467:         *      java.lang.Object, java.util.Map)
3468:         */
3469:        public boolean canEncode(Element element, Object value, Map hints) {
3470:            ComplexType t = (element.getType() instanceof  ComplexType)
3471:                ? (ComplexType) element.getType() : null;
3472:
3473:            while ((t != null) && (t != this ))
3474:                t = (t.getParent() instanceof  ComplexType)
3475:                    ? (ComplexType) t.getParent() : null;
3476:
3477:            return ((t != null) && (value instanceof  MultiLineString));
3478:        }
3479:
3480:        /**
3481:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
3482:         *      java.lang.Object, org.geotools.xml.PrintHandler,
3483:         *      java.util.Map)
3484:         */
3485:        public void encode(Element element, Object value, PrintHandler output,
3486:            Map hints) throws IOException, OperationNotSupportedException {
3487:            if (!canEncode(element, value, hints)) {
3488:                throw new OperationNotSupportedException("Cannot encode");
3489:            }
3490:
3491:            MultiLineString g = (MultiLineString) value;
3492:
3493:            GMLComplexTypes.encode(element, g, output);
3494:        }
3495:    }
3496:
3497:    /**
3498:     * <p>
3499:     * This class represents an MultiPolygonType within the GML Schema.  This
3500:     * includes both the data and parsing functionality associated  with an
3501:     * MultiPolygonType.
3502:     * </p>
3503:     *
3504:     * @author dzwiers
3505:     *
3506:     * @see GMLComplexType
3507:     * @see ComplexType
3508:     */
3509:    public static class MultiPolygonType extends GMLComplexType {
3510:
3511:        /**
3512:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
3513:         */
3514:        public Element[] getChildElements() {
3515:            return elements;
3516:        }
3517:
3518:        // singleton instance
3519:        private static final GMLComplexType instance = new MultiPolygonType();
3520:
3521:        // static element list
3522:        private static final Element[] elements = {
3523:                new GMLElement("polygonMember",
3524:                    GMLComplexTypes.PolygonMemberType.getInstance(), 1,
3525:                    ElementGrouping.UNBOUNDED, false,
3526:                    new GMLElement("geometryMember",
3527:                        GMLComplexTypes.GeometryAssociationType.getInstance(),
3528:                        1, 1, false, null)),
3529:            };
3530:
3531:        // static sequence
3532:        private static final DefaultSequence seq = new DefaultSequence(elements);
3533:
3534:        /*
3535:         * part of the singleton pattern
3536:         *
3537:         * @see GMLComplexType#getInstance()
3538:         */
3539:        public static GMLComplexType getInstance() {
3540:            return instance;
3541:        }
3542:
3543:        /**
3544:         * @see schema.ComplexType#isAbstract()
3545:         */
3546:        public boolean isAbstract() {
3547:            return false;
3548:        }
3549:
3550:        /**
3551:         * @see schema.ComplexType#getAnyAttributeNameSpace()
3552:         */
3553:        public String getAnyAttributeNameSpace() {
3554:            return null;
3555:        }
3556:
3557:        /**
3558:         * @see schema.ComplexType#getAttributes()
3559:         */
3560:        public Attribute[] getAttributes() {
3561:            return AbstractGeometryCollectionBaseType.attributes;
3562:        }
3563:
3564:        /**
3565:         * @see schema.ComplexType#getChildren()
3566:         */
3567:        public ElementGrouping getChild() {
3568:            return seq;
3569:        }
3570:
3571:        /**
3572:         * @see schema.ComplexType#getName()
3573:         */
3574:        public String getName() {
3575:            return "MultiPolygonType";
3576:        }
3577:
3578:        /**
3579:         * @throws OperationNotSupportedException 
3580:         * @see schema.Type#getValue(java.util.List)
3581:         */
3582:        public Object getValue(Element element, ElementValue[] value,
3583:            Attributes attrs, Map hints) throws SAXException, OperationNotSupportedException {
3584:            Element e = value[0].getElement();
3585:
3586:            if (e == null) {
3587:            	if(!element.isNillable())
3588:            		throw new SAXException(
3589:                    	"Internal error, ElementValues require an associated Element.");
3590:            	return null;
3591:            }
3592:
3593:            GeometryFactory gf = new GeometryFactory(DefaultCoordinateSequenceFactory
3594:                    .instance());
3595:
3596:            Polygon[] geoms = new Polygon[value.length];
3597:
3598:            for (int i = 0; i < value.length; i++) {
3599:                geoms[i] = (Polygon) value[i].getValue();
3600:            }
3601:
3602:            MultiPolygon mp = gf.createMultiPolygon(geoms);
3603:
3604:            ElementValue[] ev = new ElementValue[1];
3605:            ev[0] = new DefaultElementValue(element, mp);
3606:
3607:            return AbstractGeometryType.getInstance().getValue(element, ev,
3608:                attrs, hints);
3609:        }
3610:
3611:        /**
3612:         * @see org.geotools.xml.xsi.Type#getInstanceType()
3613:         */
3614:        public Class getInstanceType() {
3615:            return MultiPolygon.class;
3616:        }
3617:
3618:        /**
3619:         * @see schema.ComplexType#findChildElement(java.lang.String)
3620:         */
3621:        public Element findChildElement(String name) {
3622:            if (name == null) {
3623:                return null;
3624:            }
3625:
3626:            for (int i = 0; i < elements.length; i++)
3627:                if (name.equals(elements[i].getName())) {
3628:                    return elements[i];
3629:                }
3630:
3631:            return null;
3632:        }
3633:
3634:        /**
3635:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
3636:         *      java.lang.Object, java.util.Map)
3637:         */
3638:        public boolean canEncode(Element element, Object value, Map hints) {
3639:            ComplexType t = (element.getType() instanceof  ComplexType)
3640:                ? (ComplexType) element.getType() : null;
3641:
3642:            while ((t != null) && (t != this ))
3643:                t = (t.getParent() instanceof  ComplexType)
3644:                    ? (ComplexType) t.getParent() : null;
3645:
3646:            return ((t != null) && (value instanceof  MultiPolygon));
3647:        }
3648:
3649:        /**
3650:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
3651:         *      java.lang.Object, org.geotools.xml.PrintHandler,
3652:         *      java.util.Map)
3653:         */
3654:        public void encode(Element element, Object value, PrintHandler output,
3655:            Map hints) throws IOException, OperationNotSupportedException {
3656:            if (!canEncode(element, value, hints)) {
3657:                throw new OperationNotSupportedException("Cannot encode");
3658:            }
3659:
3660:            MultiPolygon g = (MultiPolygon) value;
3661:
3662:            GMLComplexTypes.encode(element, g, output);
3663:        }
3664:    }
3665:
3666:    /**
3667:     * <p>
3668:     * This class represents an CoordType within the GML Schema.  This includes
3669:     * both the data and parsing functionality associated  with an CoordType.
3670:     * </p>
3671:     *
3672:     * @author dzwiers
3673:     *
3674:     * @see GMLComplexType
3675:     * @see ComplexType
3676:     */
3677:    public static class CoordType extends GMLComplexType {
3678:
3679:        /**
3680:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
3681:         */
3682:        public Element[] getChildElements() {
3683:            return elements;
3684:        }
3685:
3686:        // singleton instance
3687:        private static final GMLComplexType instance = new CoordType();
3688:
3689:        // static element list
3690:        private static final Element[] elements = {
3691:                new GMLElement("X", XSISimpleTypes.Decimal.getInstance(), 1, 1,
3692:                    false, null),
3693:                new GMLElement("Y", XSISimpleTypes.Decimal.getInstance(), 0, 1,
3694:                    false, null),
3695:                new GMLElement("Z", XSISimpleTypes.Decimal.getInstance(), 0, 1,
3696:                    false, null)
3697:            };
3698:
3699:        // static sequence
3700:        private static final DefaultSequence seq = new DefaultSequence(elements);
3701:
3702:        /*
3703:         * part of the singleton pattern
3704:         *
3705:         * @see GMLComplexType#getInstance()
3706:         */
3707:        public static GMLComplexType getInstance() {
3708:            return instance;
3709:        }
3710:
3711:        /**
3712:         * @see schema.ComplexType#isAbstract()
3713:         */
3714:        public boolean isAbstract() {
3715:            return false;
3716:        }
3717:
3718:        /**
3719:         * @see schema.ComplexType#getAnyAttributeNameSpace()
3720:         */
3721:        public String getAnyAttributeNameSpace() {
3722:            return null;
3723:        }
3724:
3725:        /**
3726:         * @see schema.ComplexType#getAttributes()
3727:         */
3728:        public Attribute[] getAttributes() {
3729:            return AbstractGeometryCollectionBaseType.attributes;
3730:        }
3731:
3732:        /**
3733:         * @see schema.ComplexType#getChildren()
3734:         */
3735:        public ElementGrouping getChild() {
3736:            return seq;
3737:        }
3738:
3739:        /**
3740:         * @see schema.ComplexType#getName()
3741:         */
3742:        public String getName() {
3743:            return "CoordType";
3744:        }
3745:
3746:        /**
3747:         * @see schema.Type#getValue(java.util.List)
3748:         */
3749:        public Object getValue(Element element, ElementValue[] value,
3750:            Attributes attrs, Map hints) throws SAXException {
3751:            Element e = value[0].getElement();
3752:
3753:            if (e == null) {
3754:            	if(!element.isNillable())
3755:            		throw new SAXException(
3756:                    	"Internal error, ElementValues require an associated Element.");
3757:            	return null;
3758:            }
3759:
3760:            Double x;
3761:            Double y;
3762:            Double z;
3763:            x = y = z = null;
3764:
3765:            for (int i = 0; i < value.length; i++) {
3766:                if (elements[0].getName().equals(value[i].getElement()
3767:                                                             .getName())) {
3768:                    x = (Double) value[i].getValue();
3769:                }
3770:
3771:                if (elements[1].getName().equals(value[i].getElement()
3772:                                                             .getName())) {
3773:                    y = (Double) value[i].getValue();
3774:                }
3775:
3776:                if (elements[2].getName().equals(value[i].getElement()
3777:                                                             .getName())) {
3778:                    z = (Double) value[i].getValue();
3779:                }
3780:            }
3781:
3782:            if (x == null) {
3783:                throw new SAXException("An X coord is required");
3784:            }
3785:
3786:            if (y == null) {
3787:                return new Coordinate(x.doubleValue(), 0);
3788:            }
3789:
3790:            if (z == null) {
3791:                return new Coordinate(x.doubleValue(), y.doubleValue());
3792:            }
3793:
3794:            return new Coordinate(x.doubleValue(), y.doubleValue(),
3795:                z.doubleValue());
3796:        }
3797:
3798:        /**
3799:         * @see org.geotools.xml.xsi.Type#getInstanceType()
3800:         */
3801:        public Class getInstanceType() {
3802:            return Coordinate.class;
3803:        }
3804:
3805:        /**
3806:         * @see schema.ComplexType#findChildElement(java.lang.String)
3807:         */
3808:        public Element findChildElement(String name) {
3809:            if (name == null) {
3810:                return null;
3811:            }
3812:
3813:            for (int i = 0; i < elements.length; i++)
3814:                if (name.equals(elements[i].getName())) {
3815:                    return elements[i];
3816:                }
3817:
3818:            return null;
3819:        }
3820:
3821:        /**
3822:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
3823:         *      java.lang.Object, java.util.Map)
3824:         */
3825:        public boolean canEncode(Element element, Object value, Map hints) {
3826:            ComplexType t = (element.getType() instanceof  ComplexType)
3827:                ? (ComplexType) element.getType() : null;
3828:
3829:            while ((t != null) && (t != this ))
3830:                t = (t.getParent() instanceof  ComplexType)
3831:                    ? (ComplexType) t.getParent() : null;
3832:
3833:            return ((t != null) && (value instanceof  Coordinate));
3834:        }
3835:
3836:        /**
3837:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
3838:         *      java.lang.Object, org.geotools.xml.PrintHandler,
3839:         *      java.util.Map)
3840:         */
3841:        public void encode(Element element, Object value, PrintHandler output,
3842:            Map hints) throws IOException, OperationNotSupportedException {
3843:            if (!canEncode(element, value, hints)) {
3844:                throw new OperationNotSupportedException("Cannot encode");
3845:            }
3846:
3847:            Coordinate g = (Coordinate) value;
3848:
3849:            GMLComplexTypes.encodeCoord(element, g, output);
3850:        }
3851:    }
3852:
3853:    /**
3854:     * <p>
3855:     * This class represents an CoordinatesType within the GML Schema.  This
3856:     * includes both the data and parsing functionality associated  with an
3857:     * CoordinatesType.
3858:     * </p>
3859:     *
3860:     * @author dzwiers
3861:     *
3862:     * @see GMLComplexType
3863:     * @see ComplexType
3864:     */
3865:    public static class CoordinatesType extends GMLComplexType {
3866:
3867:        /**
3868:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
3869:         */
3870:        public Element[] getChildElements() {
3871:            return null;
3872:        }
3873:
3874:        // singleton instance
3875:        private static final GMLComplexType instance = new CoordinatesType();
3876:
3877:        // static attribute list
3878:        private static final Attribute[] attributes = {
3879:                new GMLAttribute("decimal",
3880:                    XSISimpleTypes.String.getInstance(), Attribute.OPTIONAL, "."),
3881:                new GMLAttribute("cs", XSISimpleTypes.String.getInstance(),
3882:                    Attribute.OPTIONAL, ","),
3883:                new GMLAttribute("ts", XSISimpleTypes.String.getInstance(),
3884:                    Attribute.OPTIONAL, "\t")
3885:            };
3886:
3887:        /*
3888:         * part of the singleton pattern
3889:         *
3890:         * @see GMLComplexType#getInstance()
3891:         */
3892:        public static GMLComplexType getInstance() {
3893:            return instance;
3894:        }
3895:
3896:        /**
3897:         * @see schema.ComplexType#isAbstract()
3898:         */
3899:        public boolean isAbstract() {
3900:            return false;
3901:        }
3902:
3903:        /**
3904:         * @see schema.ComplexType#getAnyAttributeNameSpace()
3905:         */
3906:        public String getAnyAttributeNameSpace() {
3907:            return null;
3908:        }
3909:
3910:        /**
3911:         * @see schema.ComplexType#getAttributes()
3912:         */
3913:        public Attribute[] getAttributes() {
3914://            return AbstractGeometryCollectionBaseType.attributes;
3915:        	return attributes;
3916:        }
3917:
3918:        /**
3919:         * @see schema.ComplexType#getChildren()
3920:         */
3921:        public ElementGrouping getChild() {
3922:            return new DefaultSequence(new Element[0]);
3923:        }
3924:
3925:        /**
3926:         * @see schema.ComplexType#getName()
3927:         */
3928:        public String getName() {
3929:            return "CoordinatesType";
3930:        }
3931:
3932:        /**
3933:         * @see schema.Type#getValue(java.util.List)
3934:         */
3935:        public Object getValue(Element element, ElementValue[] value,
3936:            Attributes attrs, Map hints) throws SAXException {
3937:            if (value.length != 1) {
3938:                throw new SAXException(
3939:                    "Internal error, ElementValues require an associated Element.");
3940:            }
3941:
3942:            String dec;
3943:            String cs;
3944:            String ts;
3945:            dec = attrs.getValue("", "decimal");
3946:
3947:            if (dec == null) {
3948:                dec = attrs.getValue(GMLSchema.NAMESPACE.toString(), "decimal");
3949:            }
3950:
3951:            dec = ((dec == null) || (dec == "")) ? "." : dec;
3952:
3953:            cs = attrs.getValue("", "cs");
3954:
3955:            if (cs == null) {
3956:                cs = attrs.getValue(GMLSchema.NAMESPACE.toString(), "cs");
3957:            }
3958:
3959:            cs = ((cs == null) || (cs == "")) ? ",\\s*" : (cs + "\\s*");
3960:            ts = attrs.getValue("", "ts");
3961:
3962:            if (ts == null) {
3963:                ts = attrs.getValue(GMLSchema.NAMESPACE.toString(), "ts");
3964:            }
3965:
3966:            ts = ((ts == null) || (ts == "") || ts.matches("\\s")) ? "\\s+"
3967:                                                                   : (ts
3968:                + "\\s*"); // handle whitespace
3969:
3970:            String val = (String) value[0].getValue();
3971:
3972:            String[] touples = val.split(ts);
3973:            Coordinate[] coordinates = new Coordinate[touples.length];
3974:
3975:            for (int i = 0; i < touples.length; i++) {
3976:                String[] points = touples[i].split(cs);
3977:                double[] pts = new double[points.length];
3978:
3979:                for (int j = 0; j < points.length; j++) {
3980:                    String t = "";
3981:
3982:                    try {
3983:                        if (!dec.equals(".")) {
3984:                            dec = dec.replaceAll("\\", "\\");
3985:                            t = points[j].replaceAll(dec, ".");
3986:                        } else {
3987:                            t = points[j];
3988:                        }
3989:
3990:                        pts[j] = Double.parseDouble(t);
3991:                    } catch (NumberFormatException e) {
3992:                        logger.warning(e.toString());
3993:                        logger.warning("Double = '" + t + "' " + j + "/"
3994:                            + points.length + "  Touples = " + i + "/"
3995:                            + touples.length);
3996:                        throw e;
3997:                    }
3998:                }
3999:
4000:                if (pts.length == 1) {
4001:                    coordinates[i] = new Coordinate(pts[0], 0);
4002:                } else {
4003:                    if (pts.length == 2) {
4004:                        coordinates[i] = new Coordinate(pts[0], pts[1]);
4005:                    } else {
4006:                        // should be three or there was an error
4007:                        coordinates[i] = new Coordinate(pts[0], pts[1], pts[2]);
4008:                    }
4009:                }
4010:            }
4011:
4012:            return DefaultCoordinateSequenceFactory.instance().create(coordinates);
4013:        }
4014:
4015:        /**
4016:         * @see org.geotools.xml.xsi.Type#getInstanceType()
4017:         */
4018:        public Class getInstanceType() {
4019:            return CoordinateSequence.class;
4020:        }
4021:
4022:        /**
4023:         * @see schema.ComplexType#findChildElement(java.lang.String)
4024:         */
4025:        public Element findChildElement(String name) {
4026:            return null;
4027:        }
4028:
4029:        /**
4030:         * @see schema.ComplexType#isMixed()
4031:         */
4032:        public boolean isMixed() {
4033:            return true;
4034:        }
4035:
4036:        /**
4037:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
4038:         *      java.lang.Object, java.util.Map)
4039:         */
4040:        public boolean canEncode(Element element, Object value, Map hints) {
4041:            ComplexType t = (element.getType() instanceof  ComplexType)
4042:                ? (ComplexType) element.getType() : null;
4043:
4044:            while ((t != null) && (t != this ))
4045:                t = (t.getParent() instanceof  ComplexType)
4046:                    ? (ComplexType) t.getParent() : null;
4047:
4048:            return ((t != null) && (value instanceof  CoordinateSequence));
4049:        }
4050:
4051:        /**
4052:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
4053:         *      java.lang.Object, org.geotools.xml.PrintHandler,
4054:         *      java.util.Map)
4055:         */
4056:        public void encode(Element element, Object value, PrintHandler output,
4057:            Map hints) throws IOException, OperationNotSupportedException {
4058:            if (!canEncode(element, value, hints)) {
4059:                throw new OperationNotSupportedException("Cannot encode");
4060:            }
4061:
4062:            CoordinateSequence g = (CoordinateSequence) value;
4063:
4064:            GMLComplexTypes.encodeCoords(element, g, output);
4065:        }
4066:    }
4067:
4068:    /**
4069:     * <p>
4070:     * This class represents an AbstractFeatureType within the GML Schema. This
4071:     * includes both the data and parsing functionality associated  with an
4072:     * AbstractFeatureType.
4073:     * </p>
4074:     *
4075:     * @author dzwiers
4076:     *
4077:     * @see GMLComplexType
4078:     * @see ComplexType
4079:     */
4080:    public static class AbstractFeatureType extends GMLComplexType {
4081:
4082:        /**
4083:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
4084:         */
4085:        public Element[] getChildElements() {
4086:            return elements;
4087:        }
4088:
4089:        // static attribute list
4090:        protected static final Attribute[] attributes = {
4091:                new GMLAttribute("fid", XSISimpleTypes.ID.getInstance(),
4092:                    Attribute.OPTIONAL),
4093:            };
4094:
4095:        // static element list
4096:        private static final Element[] elements = {
4097:                new GMLElement("description",
4098:                    XSISimpleTypes.String.getInstance(), 0, 1, false, null){
4099:                    public boolean isNillable() {
4100:                        return true;
4101:                    }
4102:                },
4103:                new GMLElement("name", XSISimpleTypes.String.getInstance(), 0,1,false,null){
4104:                    public boolean isNillable() {
4105:                        return true;
4106:                    }
4107:                },
4108:                new GMLElement("boundedBy",
4109:                    GMLComplexTypes.BoundingShapeType.getInstance(), 0, 1,
4110:                    false, null){
4111:                        public boolean isNillable() {
4112:                            return true;
4113:                        }
4114:                    },
4115:            };
4116:
4117:        // static sequence
4118:        private static final DefaultSequence seq = new DefaultSequence(elements);
4119:
4120:        // singleton instance
4121:        private static final GMLComplexType instance = new AbstractFeatureType();
4122:
4123:        // used for mapping ftName + namespace to actual FTs
4124:        private static final HashMap featureTypeMappings = new HashMap();
4125:
4126:        /*
4127:         * part of the singleton pattern
4128:         *
4129:         * @see GMLComplexType#getInstance()
4130:         */
4131:        public static GMLComplexType getInstance() {
4132:            return instance;
4133:        }
4134:
4135:        /**
4136:         * @see schema.ComplexType#isAbstract()
4137:         */
4138:        public boolean isAbstract() {
4139:            return true;
4140:        }
4141:
4142:        /**
4143:         * @see schema.ComplexType#getAnyAttributeNameSpace()
4144:         */
4145:        public String getAnyAttributeNameSpace() {
4146:            return null;
4147:        }
4148:
4149:        /**
4150:         * @see schema.ComplexType#getAttributes()
4151:         */
4152:        public Attribute[] getAttributes() {
4153:            return attributes;
4154:        }
4155:
4156:        /**
4157:         * @see schema.ComplexType#getChildren()
4158:         */
4159:        public ElementGrouping getChild() {
4160:            return seq;
4161:        }
4162:
4163:        /**
4164:         * @see schema.ComplexType#getName()
4165:         */
4166:        public String getName() {
4167:            return "AbstractFeatureType";
4168:        }
4169:
4170:        /**
4171:         * @see schema.Type#getValue(java.util.List)
4172:         */
4173:        public Object getValue(Element element, ElementValue[] value,
4174:            Attributes attrs, Map hints) throws SAXException {
4175:
4176:            if ((hints == null) || (hints.get(XMLHandlerHints.STREAM_HINT) == null)) {
4177:                return getFeature(element, value, attrs, hints, null);
4178:            }
4179:
4180:            if (hints.get(STREAM_FEATURE_NAME_HINT) == null) {
4181:                hints.put(STREAM_FEATURE_NAME_HINT, element.getName());
4182:            }
4183:
4184:            String nm = (String) hints.get(STREAM_FEATURE_NAME_HINT);
4185:            Feature f;
4186:            if ((nm != null) && nm.equals(element.getName())) {
4187:                f = getFeature(element, value, attrs, hints, ((FCBuffer) hints.get(XMLHandlerHints.STREAM_HINT)).ft);
4188:                stream(f, (FCBuffer) hints.get(XMLHandlerHints.STREAM_HINT));
4189:
4190:                return null;
4191:            }
4192:            f = getFeature(element, value, attrs, hints, null);
4193:            return f;
4194:        }
4195:
4196:        public Feature getFeature(Element element, ElementValue[] value,
4197:            Attributes attrs, Map hints, FeatureType ft) throws SAXException {
4198:            if(ft == null)
4199:                ft = (FeatureType) featureTypeMappings.get(element.getType()
4200:                    .getNamespace() + "#" + element.getName());
4201:
4202:            if (ft == null) {
4203:                ft = loadFeatureType(element, value, attrs);
4204:            }
4205:
4206:            Object[] values = new Object[ft.getAttributeCount()];
4207:            for(int i=0;i<values.length;i++)
4208:                values[i] = null;
4209:
4210:            for (int i = 0; i < value.length; i++){
4211:                //find index for value
4212:                int j = -1;
4213:                setAttribute(value, ft, values, i, j);
4214:            }
4215:
4216:            String fid = attrs.getValue("", "fid");
4217:
4218:            if ((fid == null) || "".equals(fid)) {
4219:                fid = attrs.getValue(GMLSchema.NAMESPACE.toString(), "fid");
4220:            }
4221:
4222:            Feature rt = null;
4223:            if ((fid != null) || !"".equals(fid)) {
4224:                try {
4225:                    rt =  ft.create(values, fid);
4226:                } catch (IllegalAttributeException e) {
4227:                    logger.warning(e.toString());
4228:                    throw new SAXException(e);
4229:                }
4230:            }
4231:
4232:            try {
4233:                if(rt == null)
4234:                rt = ft.create(values);
4235:            } catch (IllegalAttributeException e1) {
4236:                logger.warning(e1.toString());
4237:                throw new SAXException(e1);
4238:            }
4239:            
4240:            return rt;
4241:        }
4242:
4243:		private void setAttribute(ElementValue[] value, FeatureType ft, Object[] values, int i, int j) {
4244:			j = searchByName(value, ft, i, j);
4245:			if(j!=-1){
4246:                assignValue(value, values, ft.getAttributeType(j), i, j);
4247:			}else{
4248:			    searchByType(value, ft, values, i);
4249:			}
4250:		}
4251:
4252:		/**
4253:		 * HACK !!!
4254:		 * 
4255:		 * not found ... is it the same name as the FT
4256:		 * (ie ... is this part of the consequences of GT's featureType model)?
4257:		 * 
4258:		 */
4259:		private void searchByType(ElementValue[] value, FeatureType ft, Object[] values, int i) {
4260:			
4261:			if(value[i].getValue()!=null){
4262:				// first check same index since it is supposed to be the same...
4263:				if( isMatch(value, ft, i, i) ){
4264:					assignValue(value, values, ft.getAttributeType(i), i, i);
4265:					return;
4266:				}
4267:				for(int k=0;k<ft.getAttributeCount();k++){
4268:				    if(isMatch(value, ft, i, k)){
4269:				    	if( values[i]==null)
4270:				    		assignValue(value, values, ft.getAttributeType(k), i, k);
4271:				    }
4272:				}
4273:			}
4274:		}
4275:
4276:		private void assignValue(ElementValue[] value, Object[] values, AttributeType at, int i, int k) {
4277:			if( at instanceof  ChoiceAttributeType ){
4278:				ChoiceAttributeType choiceAT = (ChoiceAttributeType) at;
4279:				values[k]=choiceAT.convert(value[i].getValue());
4280:			}else
4281:				values[k] = value[i].getValue();
4282:		}
4283:
4284:		private boolean isMatch(ElementValue[] value, FeatureType ft, int i, int k) {
4285:			AttributeType attributeType = ft.getAttributeType(k);
4286:			String typeName = ft.getTypeName();
4287:			
4288:			if( !attributeType.getName().equals(typeName) )
4289:				return false;
4290:			
4291:			Class instanceClass = value[i].getValue().getClass();
4292:			
4293:			if( attributeType instanceof  ChoiceAttributeType ){
4294:				ChoiceAttributeType choiceAT=(ChoiceAttributeType) attributeType;
4295:				Class[] choices = choiceAT.getChoices();
4296:				for (int j = 0; j < choices.length; j++) {
4297:					if( choices[j].isAssignableFrom(instanceClass))
4298:						return true;
4299:				}
4300:			}
4301:			return attributeType.getType().isAssignableFrom(instanceClass);
4302:		}
4303:
4304:		private int searchByName(ElementValue[] value, FeatureType ft, int i, int j) {
4305:			for (int k=0;k<ft.getAttributeCount() && j==-1;k++){
4306:			    // TODO use equals
4307:			    if((ft.getAttributeType(k).getName()==null && value[i].getElement().getName()==null) ||
4308:			            ft.getAttributeType(k).getName().equals(value[i].getElement().getName()))
4309:			        j = k;
4310:			}
4311:			return j;
4312:		}
4313:
4314:        private void stream(Feature feature, FCBuffer featureCollectionBuffer)
4315:            throws SAXNotSupportedException, SAXException {
4316:            if (!featureCollectionBuffer.addFeature(feature)) {
4317:                throw new SAXException("Buffer overflow");
4318:            }
4319:
4320:            if (featureCollectionBuffer.state <= 0) {
4321:                switch (featureCollectionBuffer.state) {
4322:                case FCBuffer.STOP:
4323:                    throw new StopException(); // alternative to stop()
4324:
4325:                case FCBuffer.FINISH:
4326:                    return;
4327:
4328:                default:
4329:                    featureCollectionBuffer.state = (featureCollectionBuffer
4330:                        .getCapacity() - featureCollectionBuffer.getSize()) / 3;
4331:                    logger.finest("New State " + featureCollectionBuffer.state
4332:                        + " " + featureCollectionBuffer.getSize());
4333:
4334:                    while (featureCollectionBuffer.getSize() > (featureCollectionBuffer
4335:                            .getCapacity() - 1)) {
4336:                        logger.finest("waiting for reader");
4337:                        synchronized (featureCollectionBuffer) {
4338:                            try {
4339:                                featureCollectionBuffer.wait(100);
4340:                            } catch (InterruptedException e) {
4341:                                throw new StopException();  // alternative to stop()
4342:                            }
4343:                        }
4344://                        Thread.yield();
4345:                        if(featureCollectionBuffer.state == FCBuffer.STOP)
4346:                        	throw new StopException(); // alternative to stop()
4347:                    }
4348:                }
4349:            } else {
4350:                featureCollectionBuffer.state--;
4351:                logger.finest("New State " + featureCollectionBuffer.state
4352:                    + " " + featureCollectionBuffer.getSize());
4353:            }
4354:        }
4355:
4356:        /**
4357:         * @see org.geotools.xml.xsi.Type#getInstanceType()
4358:         */
4359:        public Class getInstanceType() {
4360:            return Feature.class;
4361:        }
4362:
4363:        /*
4364:         * Creates a FT from the information provided
4365:         */
4366:        private FeatureType loadFeatureType(Element element,
4367:            ElementValue[] value, Attributes attrs) throws SAXException {
4368:
4369:            FeatureType ft = createFeatureType(element);
4370:                featureTypeMappings.put(element.getType().getNamespace() + "#"
4371:                    + element.getName(), ft);
4372:                return ft;
4373:        }
4374:
4375:        /**
4376:         * @see schema.ComplexType#findChildElement(java.lang.String)
4377:         */
4378:        public Element findChildElement(String name) {
4379:            if (name == null) {
4380:                return null;
4381:            }
4382:
4383:            for (int i = 0; i < elements.length; i++)
4384:                if (name.equals(elements[i].getName())) {
4385:                    return elements[i];
4386:                }
4387:
4388:            return null;
4389:        }
4390:
4391:        /**
4392:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
4393:         *      java.lang.Object, java.util.Map)
4394:         */
4395:        public boolean canEncode(Element element, Object value, Map hints) {
4396:            if ((value == null) || (element == null)
4397:                    || value instanceof  FeatureCollection || !(value instanceof  Feature)) {
4398:                return false;
4399:            }
4400:
4401:            ComplexType t = (element.getType() instanceof  ComplexType)
4402:                ? (ComplexType) element.getType() : null;
4403:
4404:            while ((t != null) && (t != this ))
4405:                t = (t.getParent() instanceof  ComplexType)
4406:                    ? (ComplexType) t.getParent() : null;
4407:            return t != null;
4408:        }
4409:
4410:        /**
4411:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
4412:         *      java.lang.Object, org.geotools.xml.PrintHandler,
4413:         *      java.util.Map)
4414:         */
4415:        public void encode(Element element, Object value, PrintHandler output,
4416:            Map hints) throws IOException, OperationNotSupportedException {
4417:            if (canEncode(element, value, hints)) {
4418:                Feature f = (Feature) value;
4419:                if (element == null) {
4420:                    print(f, output, hints);
4421:                } else {
4422:                    print(element, f, output, hints);
4423:                }
4424:            }
4425:        }
4426:
4427:        private void print(Element e, Feature f, PrintHandler ph, Map hints)
4428:            throws OperationNotSupportedException, IOException {
4429:            AttributesImpl ai = new AttributesImpl();
4430:
4431:            if ((f.getID() != null) && !f.getID().equals("")) {
4432:                ai.addAttribute("", "fid", "", "ID", f.getID());
4433:            } else {
4434:                ai = null;
4435:            }
4436:
4437:            ph.startElement(e.getNamespace(), e.getName(), ai);
4438:
4439:            FeatureType ft = f.getFeatureType();
4440:            AttributeType[] ats = ft.getAttributeTypes();
4441:
4442:            if (ats != null) {
4443:                for (int i = 0; i < ats.length; i++) {
4444:                    Element e2 = e.findChildElement(ats[i].getName());
4445:                    e2.getType().encode(e2, f.getAttribute(i), ph, hints);
4446:                }
4447:            }
4448:
4449:            ph.endElement(e.getNamespace(), e.getName());
4450:        }
4451:
4452:        private void print(Feature f, PrintHandler ph, Map hints)
4453:            throws OperationNotSupportedException, IOException {
4454:            AttributesImpl ai = new AttributesImpl();
4455:
4456:            if ((f.getID() != null) && !f.getID().equals("")) {
4457:                ai.addAttribute("", "fid", "", "ID", f.getID());
4458:            } else {
4459:                ai = null;
4460:            }
4461:
4462:            ph.startElement(GMLSchema.NAMESPACE, "_Feature", ai);
4463:
4464:            FeatureType ft = f.getFeatureType();
4465:            AttributeType[] ats = ft.getAttributeTypes();
4466:
4467:            if (ats != null) {
4468:                for (int i = 0; i < ats.length; i++) {
4469:                    Type t = XSISimpleTypes.find(ats[i].getType());
4470:                    t.encode(null, f.getAttribute(i), ph, hints);
4471:                }
4472:            }
4473:
4474:            ph.endElement(GMLSchema.NAMESPACE, "_Feature");
4475:        }
4476:    }
4477:
4478:    /**
4479:     * <p>
4480:     * This class represents an AbstractFeatureCollectionsBaseType within the
4481:     * GML Schema.  This includes both the data and parsing functionality
4482:     * associated  with an AbstractFeatureCollectionsBaseType.
4483:     * </p>
4484:     *
4485:     * @author dzwiers
4486:     *
4487:     * @see GMLComplexType
4488:     * @see ComplexType
4489:     */
4490:    public static class AbstractFeatureCollectionsBaseType extends AbstractFeatureType {
4491:        // static element list
4492:        private static final Element[] elements1 = {
4493:                new GMLElement("description",
4494:                    XSISimpleTypes.String.getInstance(), 0, 1, false, null),
4495:                new GMLElement("name", XSISimpleTypes.String.getInstance(), 0,
4496:                    1, false, null),
4497:                new GMLElement("boundedBy",
4498:                    GMLComplexTypes.BoundingShapeType.getInstance(), 1, 1,
4499:                    false, null),
4500:            };
4501:
4502:        //static sequence
4503:        private static final DefaultSequence seq1 = new DefaultSequence(elements1);
4504:
4505:        // singleton instance
4506:        private static final GMLComplexType instance1 = new AbstractFeatureCollectionsBaseType();
4507:
4508:        /*
4509:         * part of the singleton pattern
4510:         *
4511:         * @see GMLComplexType#getInstance()
4512:         */
4513:        public static GMLComplexType getInstance() {
4514:            return instance1;
4515:        }
4516:
4517:        /**
4518:         * @see schema.ComplexType#isAbstract()
4519:         */
4520:        public boolean isAbstract() {
4521:            return true;
4522:        }
4523:
4524:        /**
4525:         * @see schema.ComplexType#getAnyAttributeNameSpace()
4526:         */
4527:        public String getAnyAttributeNameSpace() {
4528:            return null;
4529:        }
4530:
4531:        /**
4532:         * @see schema.ComplexType#getAttributes()
4533:         */
4534:        public Attribute[] getAttributes() {
4535:            return AbstractFeatureType.attributes;
4536:        }
4537:
4538:        /**
4539:         * @see schema.ComplexType#getChildren()
4540:         */
4541:        public ElementGrouping getChild() {
4542:            return seq1;
4543:        }
4544:
4545:        /**
4546:         * @see schema.ComplexType#getName()
4547:         */
4548:        public String getName() {
4549:            return "AbstractFeatureCollectionBaseType";
4550:        }
4551:
4552:        /**
4553:         * @see schema.ComplexType#findChildElement(java.lang.String)
4554:         */
4555:        public Element findChildElement(String name) {
4556:            if (name == null) {
4557:                return null;
4558:            }
4559:
4560:            for (int i = 0; i < elements1.length; i++)
4561:                if (name.equals(elements1[i].getName())) {
4562:                    return elements1[i];
4563:                }
4564:
4565:            return null;
4566:        }
4567:    }
4568:
4569:    /**
4570:     * <p>
4571:     * This class represents an AbstractFeatureCollectionType within the GML
4572:     * Schema.  This includes both the data and parsing functionality
4573:     * associated  with an AbstractFeatureCollectionType.
4574:     * </p>
4575:     *
4576:     * @author dzwiers
4577:     *
4578:     * @see GMLComplexType
4579:     * @see ComplexType
4580:     */
4581:    public static class AbstractFeatureCollectionType extends GMLComplexType {
4582:
4583:        /**
4584:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
4585:         */
4586:        public Element[] getChildElements() {
4587:            return elements;
4588:        }
4589:
4590:        // singleton instance
4591:        private static final GMLComplexType instance = new AbstractFeatureCollectionType();
4592:
4593:        // static element list
4594:        private static final Element[] elements = {
4595:                new GMLElement("description",
4596:                    XSISimpleTypes.String.getInstance(), 0, 1, false, null),
4597:                new GMLElement("name", XSISimpleTypes.String.getInstance(), 0,
4598:                    1, false, null),
4599:                new GMLElement("boundedBy",
4600:                    GMLComplexTypes.BoundingShapeType.getInstance(), 1, 1,
4601:                    false, null),
4602:                new GMLElement("featureMember",
4603:                    GMLComplexTypes.FeatureAssociationType.getInstance(), 0,
4604:                    ElementGrouping.UNBOUNDED, false, null),
4605:            };
4606:
4607:        // static sequence
4608:        private static final DefaultSequence seq = new DefaultSequence(elements);
4609:
4610:        /*
4611:         * part of the singleton pattern
4612:         *
4613:         * @see GMLComplexType#getInstance()
4614:         */
4615:        public static GMLComplexType getInstance() {
4616:            return instance;
4617:        }
4618:
4619:        /**
4620:         * @see schema.ComplexType#isAbstract()
4621:         */
4622:        public boolean isAbstract() {
4623:            return true;
4624:        }
4625:
4626:        /**
4627:         * @see schema.ComplexType#getAnyAttributeNameSpace()
4628:         */
4629:        public String getAnyAttributeNameSpace() {
4630:            return null;
4631:        }
4632:
4633:        /**
4634:         * @see schema.ComplexType#getAttributes()
4635:         */
4636:        public Attribute[] getAttributes() {
4637:            return null;
4638:        }
4639:
4640:        /**
4641:         * @see schema.Type#getValue(java.util.List)
4642:         */
4643:        public Object getValue(Element element, ElementValue[] value,
4644:            Attributes attrs, Map hints){
4645:            if ((hints == null) || (hints.get(XMLHandlerHints.STREAM_HINT) == null)) {
4646:                return getCollection(attrs,value);
4647:            }
4648:
4649:            FCBuffer fcb = (FCBuffer) hints.get(XMLHandlerHints.STREAM_HINT);
4650:            fcb.state = FCBuffer.FINISH;
4651:
4652:            return null;
4653:        }
4654:
4655:        /**
4656:         * @see org.geotools.xml.schema.ComplexType#cache(org.geotools.xml.schema.Element,
4657:         *      java.util.Map)
4658:         */
4659:        public boolean cache(Element element, Map hints) {
4660:            if ((hints == null) || (hints.get(XMLHandlerHints.STREAM_HINT) == null)) {
4661:                return true;
4662:            }
4663:
4664:            ComplexType e = (element.getType() instanceof  ComplexType)
4665:                ? (ComplexType) element.getType() : null;
4666:
4667:            while (e != null) {
4668:                if ((e.getName() != null)
4669:                        && e.getName().equals(BoxType.getInstance().getName())) {
4670:                    return true;
4671:                }
4672:
4673:                e = (e.getParent() instanceof  ComplexType)
4674:                    ? (ComplexType) e.getParent() : null;
4675:            }
4676:
4677:            return false;
4678:        }
4679:
4680:        private FeatureCollection getCollection(Attributes attrs, ElementValue[] value) {
4681:        	
4682:        	String id = "";
4683:        	id = attrs.getValue("", "ID");
4684:        	if(id == null)
4685:        		id = attrs.getValue(GMLSchema.NAMESPACE.toString(),"ID");
4686:            Object value2 = value[0].getValue();
4687:            Envelope envelopeInternal = ((Geometry)value2).getEnvelopeInternal();
4688:            //bbox slot
4689:            GMLFeatureCollection fc = new GMLFeatureCollection(id,envelopeInternal);
4690:
4691:
4692:            for (int i = 1; i < value.length; i++) // bbox is slot 0
4693:                fc.add(value[i].getValue());
4694:
4695:            return fc;
4696:        }
4697:
4698:        /**
4699:         * @see org.geotools.xml.xsi.Type#getInstanceType()
4700:         */
4701:        public Class getInstanceType() {
4702:            return FeatureCollection.class;
4703:        }
4704:
4705:        /**
4706:         * @see schema.ComplexType#getChildren()
4707:         */
4708:        public ElementGrouping getChild() {
4709:            return seq;
4710:        }
4711:
4712:        /**
4713:         * @see schema.ComplexType#getName()
4714:         */
4715:        public String getName() {
4716:            return "AbstractFeatureCollectionType";
4717:        }
4718:
4719:        /**
4720:         * @see schema.ComplexType#findChildElement(java.lang.String)
4721:         */
4722:        public Element findChildElement(String name) {
4723:            if (name == null) {
4724:                return null;
4725:            }
4726:
4727:            for (int i = 0; i < elements.length; i++)
4728:                if (name.equals(elements[i].getName())) {
4729:                    return elements[i];
4730:                }
4731:
4732:            return null;
4733:        }
4734:
4735:        /**
4736:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
4737:         *      java.lang.Object, java.util.Map)
4738:         */
4739:        public boolean canEncode(Element element, Object value, Map hints) {
4740:            ComplexType t = (element.getType() instanceof  ComplexType)
4741:                ? (ComplexType) element.getType() : null;
4742:
4743:            while ((t != null) && (t != this ))
4744:                t = (t.getParent() instanceof  ComplexType)
4745:                    ? (ComplexType) t.getParent() : null;
4746:
4747:            return ((t != null) && (value instanceof  FeatureCollection)
4748:            		&& ((FeatureCollection)value).getBounds()!=null);
4749:        }
4750:
4751:        /**
4752:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
4753:         *      java.lang.Object, org.geotools.xml.PrintHandler,
4754:         *      java.util.Map)
4755:         */
4756:        public void encode(Element element, Object value, PrintHandler output,
4757:            Map hints) throws IOException, OperationNotSupportedException {
4758:            if ((value == null) || (!(value instanceof  FeatureCollection))) {
4759:                return;
4760:            }
4761:
4762:            if (element == null) {
4763:                output.startElement(GMLSchema.NAMESPACE, "_featureCollection",
4764:                    null);
4765:            } else {
4766:                output.startElement(element.getNamespace(), element.getName(),
4767:                    null);
4768:            }
4769:
4770:            FeatureCollection fc = (FeatureCollection) value;
4771:
4772:            if (fc.getBounds() != null) {
4773:                BoundingShapeType.getInstance().encode(null, fc.getBounds(),
4774:                    output, hints);
4775:            }else{
4776:            	throw new IOException("Bounding box required for the FeatureCollection");
4777:            }
4778:
4779:            FeatureIterator i = fc.features();
4780:            Element e = null;
4781:
4782:            while (i.hasNext()) {
4783:                Feature f = i.next();
4784:                output.startElement(GMLSchema.NAMESPACE, "featureMember", null);
4785:
4786:                if (e == null) { // first time
4787:                    e = output.findElement(f.getFeatureType().getTypeName());
4788:                    // should go to an abstract FT eventually
4789:                    ComplexType t = e.getType() instanceof  ComplexType? (ComplexType)e.getType():null;
4790:                    while(t!=null && t!=AbstractFeatureType.getInstance())
4791:                        t = t.getParent() instanceof  ComplexType? (ComplexType)t.getParent():null;
4792:                    if(t!=AbstractFeatureType.getInstance()){
4793:                        // not the right element ... try by type
4794:                        e = output.findElement(value);
4795:                        // should go to an abstract FT eventually
4796:                        t = e.getType() instanceof  ComplexType? (ComplexType)e.getType():null;
4797:                        while(t!=null && t!=AbstractFeatureType.getInstance())
4798:                            t = t.getParent() instanceof  ComplexType? (ComplexType)t.getParent():null;
4799:                        if(t!=AbstractFeatureType.getInstance()){
4800:                            throw new OperationNotSupportedException("Could not find a correct Element for FeatureType "+f.getFeatureType().getTypeName());
4801:                        }
4802:                    }
4803:                }
4804:
4805:                if (e == null) {
4806:                    throw new NullPointerException(
4807:                        "Feature Definition not found in Schema "
4808:                        + element.getNamespace());
4809:                }
4810:
4811:                AbstractFeatureType.getInstance().encode(e, f, output, hints);
4812:                output.endElement(GMLSchema.NAMESPACE, "featureMember");
4813:            }
4814:
4815:            if (element == null) {
4816:                output.endElement(GMLSchema.NAMESPACE, "_featureCollection");
4817:            } else {
4818:                output.endElement(element.getNamespace(), element.getName());
4819:            }
4820:        }
4821:    }
4822:
4823:    /**
4824:     * <p>
4825:     * This class represents an GeometryPropertyType within the GML Schema.
4826:     * This includes both the data and parsing functionality associated  with
4827:     * an GeometryPropertyType.
4828:     * </p>
4829:     *
4830:     * @author dzwiers
4831:     *
4832:     * @see GMLComplexType
4833:     * @see ComplexType
4834:     */
4835:    public static class GeometryPropertyType extends GMLComplexType {
4836:
4837:        /**
4838:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
4839:         */
4840:        public Element[] getChildElements() {
4841:            return elements;
4842:        }
4843:
4844:        // singleton instance
4845:        private static final GMLComplexType instance = new GeometryPropertyType();
4846:
4847:        // static attribute list
4848:        private static final Attribute[] attributes = loadAttributes();
4849:
4850:        // static element list
4851:        private static final Element[] elements = {
4852:                new GMLElement("_Geometry",
4853:                    GMLComplexTypes.AbstractGeometryType.getInstance(), 0, 1,
4854:                    true, null),
4855:            };
4856:
4857:        // static sequence
4858:        private static final DefaultSequence seq = new DefaultSequence(elements);
4859:
4860:        /*
4861:         * part of the singleton pattern
4862:         *
4863:         * @see GMLComplexType#getInstance()
4864:         */
4865:        public static GMLComplexType getInstance() {
4866:            return instance;
4867:        }
4868:
4869:        /**
4870:         * @see schema.ComplexType#isAbstract()
4871:         */
4872:        public boolean isAbstract() {
4873:            return false;
4874:        }
4875:
4876:        /**
4877:         * @see schema.ComplexType#getAnyAttributeNameSpace()
4878:         */
4879:        public String getAnyAttributeNameSpace() {
4880:            return null;
4881:        }
4882:
4883:        /*
4884:         * statically loads the attributes for a Geom Prop Type
4885:         */
4886:        private static Attribute[] loadAttributes() {
4887:            Attribute[] gp = XLinkSchema.SimpleLink.getInstance().getAttributes();
4888:            Attribute[] r = new Attribute[gp.length + 1];
4889:
4890:            for (int i = 1; i < gp.length; i++)
4891:                r[i] = gp[i];
4892:
4893:            r[gp.length] = GMLSchema.AttributeList.attributes1[0];
4894:
4895:            return r;
4896:        }
4897:
4898:        /**
4899:         * @see schema.ComplexType#getAttributes()
4900:         */
4901:        public Attribute[] getAttributes() {
4902:            return attributes;
4903:        }
4904:
4905:        /**
4906:         * @see schema.ComplexType#getChildren()
4907:         */
4908:        public ElementGrouping getChild() {
4909:            return seq;
4910:        }
4911:
4912:        /**
4913:         * @see schema.ComplexType#getName()
4914:         */
4915:        public String getName() {
4916:            return "GeometryPropertyType";
4917:        }
4918:
4919:        /**
4920:         * @see schema.Type#getValue(java.util.List)
4921:         */
4922:        public Object getValue(Element element, ElementValue[] value,
4923:            Attributes attrs, Map hints) throws SAXException {
4924:            if ((value == null) || (value.length != 1)) {
4925:                throw new SAXException("must be one geometry");
4926:            }
4927:
4928:            return (Geometry) value[0].getValue();
4929:        }
4930:
4931:        /**
4932:         * @see org.geotools.xml.xsi.Type#getInstanceType()
4933:         */
4934:        public Class getInstanceType() {
4935:            return Geometry.class;
4936:        }
4937:
4938:        /**
4939:         * @see schema.ComplexType#findChildElement(java.lang.String)
4940:         */
4941:        public Element findChildElement(String name) {
4942:            if (name == null) {
4943:                return null;
4944:            }
4945:
4946:            for (int i = 0; i < elements.length; i++)
4947:                if (name.equals(elements[i].getName())) {
4948:                    return elements[i];
4949:                }
4950:
4951:            return null;
4952:        }
4953:
4954:        /**
4955:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
4956:         *      java.lang.Object, java.util.Map)
4957:         */
4958:        public boolean canEncode(Element element, Object value, Map hints) {
4959:            ComplexType t = (element.getType() instanceof  ComplexType)
4960:                ? (ComplexType) element.getType() : null;
4961:
4962:            while ((t != null) && (t != this ))
4963:                t = (t.getParent() instanceof  ComplexType)
4964:                    ? (ComplexType) t.getParent() : null;
4965:
4966:            return ((t != null) && (value instanceof  Geometry));
4967:        }
4968:
4969:        /**
4970:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
4971:         *      java.lang.Object, org.geotools.xml.PrintHandler,
4972:         *      java.util.Map)
4973:         */
4974:        public void encode(Element element, Object value, PrintHandler output,
4975:            Map hints) throws IOException, OperationNotSupportedException {
4976:            if (!(value instanceof  Geometry)) {
4977:                return;
4978:            }
4979:
4980:            Geometry g = (Geometry) value;
4981:
4982:            if (element == null) {
4983:                output.startElement(GMLSchema.NAMESPACE, "geometryProperty",
4984:                    null);
4985:            } else {
4986:                output.startElement(element.getNamespace(), element.getName(),
4987:                    null);
4988:            }
4989:
4990:            GMLComplexTypes.encode(null, g, output);
4991:
4992:            if (element == null) {
4993:                output.endElement(GMLSchema.NAMESPACE, "geometryProperty");
4994:            } else {
4995:                output.endElement(element.getNamespace(), element.getName());
4996:            }
4997:        }
4998:    }
4999:
5000:    /**
5001:     * <p>
5002:     * This class represents an FeatureAssociationType within the GML Schema.
5003:     * This includes both the data and parsing functionality associated  with
5004:     * an FeatureAssociationType.
5005:     * </p>
5006:     *
5007:     * @author dzwiers
5008:     *
5009:     * @see GMLComplexType
5010:     * @see ComplexType
5011:     */
5012:    public static class FeatureAssociationType extends GMLComplexType {
5013:
5014:        /**
5015:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
5016:         */
5017:        public Element[] getChildElements() {
5018:            return elements;
5019:        }
5020:
5021:        // singleton instance
5022:        private static final GMLComplexType instance = new FeatureAssociationType();
5023:
5024:        // static attribute list
5025:        protected static final Attribute[] attributes = loadAttributes();
5026:
5027:        // static element list
5028:        private static final Element[] elements = {
5029:                new GMLElement("_Feature",
5030:                    GMLComplexTypes.AbstractFeatureType.getInstance(), 0, 1,
5031:                    true, null),
5032:            };
5033:
5034:        // static sequence
5035:        static final DefaultSequence seq = new DefaultSequence(elements);
5036:
5037:        /*
5038:         * part of the singleton pattern
5039:         *
5040:         * @see GMLComplexType#getInstance()
5041:         */
5042:        public static GMLComplexType getInstance() {
5043:            return instance;
5044:        }
5045:
5046:        /**
5047:         * @see schema.ComplexType#isAbstract()
5048:         */
5049:        public boolean isAbstract() {
5050:            return false;
5051:        }
5052:
5053:        /**
5054:         * @see schema.ComplexType#getAnyAttributeNameSpace()
5055:         */
5056:        public String getAnyAttributeNameSpace() {
5057:            return null;
5058:        }
5059:
5060:        /*
5061:         * statically loads the attributes for a Feature Association Type
5062:         */
5063:        private static Attribute[] loadAttributes() {
5064:            Attribute[] gp = XLinkSchema.SimpleLink.getInstance().getAttributes();
5065:            Attribute[] r = new Attribute[gp.length + 1];
5066:
5067:            for (int i = 1; i < gp.length; i++)
5068:                r[i] = gp[i];
5069:
5070:            r[gp.length] = GMLSchema.AttributeList.attributes1[0];
5071:
5072:            return r;
5073:        }
5074:
5075:        /**
5076:         * @see schema.ComplexType#getAttributes()
5077:         */
5078:        public Attribute[] getAttributes() {
5079:            return attributes;
5080:        }
5081:
5082:        /**
5083:         * @see schema.ComplexType#getChildren()
5084:         */
5085:        public ElementGrouping getChild() {
5086:            return seq;
5087:        }
5088:
5089:        /**
5090:         * @see schema.ComplexType#getName()
5091:         */
5092:        public String getName() {
5093:            return "FeatureAssociationType";
5094:        }
5095:
5096:        /**
5097:         * @see schema.Type#getValue(java.util.List)
5098:         */
5099:        public Object getValue(Element element, ElementValue[] value,
5100:            Attributes attrs, Map hints) throws SAXException {
5101:            if ((value == null) || (value.length != 1)) {
5102:                throw new SAXException("must be one feature " + value.length);
5103:            }
5104:
5105:            logger.finest((value[0].getValue() == null) ? "null"
5106:                                                        : value[0].getValue()
5107:                                                                  .getClass()
5108:                                                                  .getName());
5109:
5110:            return (Feature) value[0].getValue();
5111:        }
5112:
5113:        /**
5114:         * @see org.geotools.xml.xsi.Type#getInstanceType()
5115:         */
5116:        public Class getInstanceType() {
5117:            return Feature.class;
5118:        }
5119:
5120:        /**
5121:         * @see schema.ComplexType#findChildElement(java.lang.String)
5122:         */
5123:        public Element findChildElement(String name) {
5124:            if (name == null) {
5125:                return null;
5126:            }
5127:
5128:            for (int i = 0; i < elements.length; i++)
5129:                if (name.equals(elements[i].getName())) {
5130:                    return elements[i];
5131:                }
5132:
5133:            return null;
5134:        }
5135:
5136:        /**
5137:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
5138:         *      java.lang.Object, java.util.Map)
5139:         */
5140:        public boolean canEncode(Element element, Object value, Map hints) {
5141:            if (!(value instanceof  Feature)) {
5142:                return false;
5143:            }
5144:
5145:            ComplexType t = (element.getType() instanceof  ComplexType)
5146:                ? (ComplexType) element.getType() : null;
5147:
5148:            while ((t != null) && (t != this ))
5149:                t = (t.getParent() instanceof  ComplexType)
5150:                    ? (ComplexType) t.getParent() : null;
5151:
5152:            return t == this ;
5153:        }
5154:
5155:        /**
5156:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
5157:         *      java.lang.Object, org.geotools.xml.PrintHandler,
5158:         *      java.util.Map)
5159:         */
5160:        public void encode(Element element, Object value, PrintHandler output,
5161:            Map hints) throws IOException, OperationNotSupportedException {
5162:            if (!(value instanceof  Feature)) {
5163:                return;
5164:            }
5165:
5166:            if (element == null) {
5167:                output.startElement(GMLSchema.NAMESPACE, "featureMember", null);
5168:                AbstractFeatureType.getInstance().encode(null, value, output,
5169:                    hints);
5170:                output.endElement(GMLSchema.NAMESPACE, "featureMember");
5171:            } else {
5172:                output.startElement(element.getNamespace(), element.getName(),
5173:                    null);
5174:                AbstractFeatureType.getInstance().encode(element
5175:                    .findChildElement(((Feature) value).getFeatureType()
5176:                                       .getTypeName()), value, output, hints);
5177:                output.endElement(element.getNamespace(), element.getName());
5178:            }
5179:        }
5180:    }
5181:
5182:    /**
5183:     * <p>
5184:     * This class represents an BoundingShapeType within the GML Schema.  This
5185:     * includes both the data and parsing functionality associated  with an
5186:     * BoundingShapeType.
5187:     * </p>
5188:     *
5189:     * @author dzwiers
5190:     *
5191:     * @see GMLComplexType
5192:     * @see ComplexType
5193:     */
5194:    public static class BoundingShapeType extends GMLComplexType {
5195:
5196:        /**
5197:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
5198:         */
5199:        public Element[] getChildElements() {
5200:            return elements;
5201:        }
5202:
5203:        // singleton instance
5204:        private static final GMLComplexType instance = new BoundingShapeType();
5205:
5206:        // static element list
5207:        private static final Element[] elements = {
5208:                new GMLElement("Box", GMLComplexTypes.BoxType.getInstance(), 1,
5209:                    1, false, null),
5210:                new GMLElement("null", new GMLNullType(), 1, 1, false, null),
5211:            };
5212:
5213:        // static choice
5214:        private static final DefaultChoice seq = new DefaultChoice(elements);
5215:
5216:        private static final Geometry NULL_ENV;
5217:        static {
5218:            GeometryFactory fac=new GeometryFactory();
5219:            NULL_ENV=fac.toGeometry(new Envelope());
5220:        }
5221:
5222:        /*
5223:         * part of the singleton pattern
5224:         *
5225:         * @see GMLComplexType#getInstance()
5226:         */
5227:        public static GMLComplexType getInstance() {
5228:            return instance;
5229:        }
5230:
5231:        /**
5232:         * @see schema.ComplexType#isAbstract()
5233:         */
5234:        public boolean isAbstract() {
5235:            return false;
5236:        }
5237:
5238:        /**
5239:         * @see schema.ComplexType#getAnyAttributeNameSpace()
5240:         */
5241:        public String getAnyAttributeNameSpace() {
5242:            return null;
5243:        }
5244:
5245:        /**
5246:         * @see schema.ComplexType#getAttributes()
5247:         */
5248:        public Attribute[] getAttributes() {
5249:            return null;
5250:        }
5251:
5252:        /**
5253:         * @see schema.ComplexType#getChildren()
5254:         */
5255:        public ElementGrouping getChild() {
5256:            return seq;
5257:        }
5258:
5259:        /**
5260:         * @see schema.ComplexType#getName()
5261:         */
5262:        public String getName() {
5263:            return "BoundingShapeType";
5264:        }
5265:
5266:        /**
5267:         * @see schema.Type#getValue(java.util.List)
5268:         */
5269:        public Object getValue(Element element, ElementValue[] value,
5270:            Attributes attrs, Map hints) throws SAXException {
5271:            if ((value == null) || (value.length != 1)) {
5272:                throw new SAXException("must be one geometry");
5273:            }
5274:
5275:            return value[0].getValue() instanceof  Geometry?(Geometry) value[0].getValue():NULL_ENV;
5276:        }
5277:
5278:        /**
5279:         * @see org.geotools.xml.xsi.Type#getInstanceType()
5280:         */
5281:        public Class getInstanceType() {
5282:            return Geometry.class;
5283:        }
5284:
5285:        /**
5286:         * @see schema.ComplexType#findChildElement(java.lang.String)
5287:         */
5288:        public Element findChildElement(String name) {
5289:            if (name == null) {
5290:                return null;
5291:            }
5292:
5293:            for (int i = 0; i < elements.length; i++)
5294:                if (name.equals(elements[i].getName())) {
5295:                    return elements[i];
5296:                }
5297:
5298:            return null;
5299:        }
5300:
5301:        /**
5302:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
5303:         *      java.lang.Object, java.util.Map)
5304:         */
5305:        public boolean canEncode(Element element, Object value, Map hints) {
5306:            if ((value == null) || (element == null)
5307:                    || !(value instanceof  Geometry)) {
5308:                return false;
5309:            }
5310:
5311:            ComplexType t = (element.getType() instanceof  ComplexType)
5312:                ? (ComplexType) element.getType() : null;
5313:
5314:            while ((t != null) && (t != this ))
5315:                t = (t.getParent() instanceof  ComplexType)
5316:                    ? (ComplexType) t.getParent() : null;
5317:
5318:            return t != null;
5319:        }
5320:
5321:        /**
5322:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
5323:         *      java.lang.Object, org.geotools.xml.PrintHandler,
5324:         *      java.util.Map)
5325:         */
5326:        public void encode(Element element, Object value, PrintHandler output,
5327:            Map hints) throws IOException, OperationNotSupportedException {
5328:            if (!(value instanceof  Geometry)) {
5329:                return;
5330:            }
5331:
5332:            if (element == null) {
5333:                output.startElement(GMLSchema.NAMESPACE, "boundedBy", null);
5334:                BoxType.getInstance().encode(null, value, output, hints);
5335:                output.endElement(GMLSchema.NAMESPACE, "boundedBy");
5336:            } else {
5337:                output.startElement(element.getNamespace(), element.getName(),
5338:                    null);
5339:
5340://                if (element.findChildElement("Box") != null) {
5341://                    if (element.findChildElement("Box").getType().canEncode(element
5342://                                .findChildElement("Box"), value, hints)) {
5343://                        element.findChildElement("Box").getType().encode(element
5344://                            .findChildElement("Box"), value, output, hints);
5345://                    }
5346://                }else{
5347:                	BoxType.getInstance().encode(null, value, output, hints);
5348://                }
5349:
5350://                BoxType.getInstance().encode(null, value, output, hints);
5351:                output.endElement(element.getNamespace(), element.getName());
5352:            }
5353:        }
5354:    }
5355:
5356:    /**
5357:     * <p>
5358:     * This class represents an PointPropertyType within the GML Schema.  This
5359:     * includes both the data and parsing functionality associated  with an
5360:     * PointPropertyType.
5361:     * </p>
5362:     *
5363:     * @author dzwiers
5364:     *
5365:     * @see GMLComplexType
5366:     * @see ComplexType
5367:     */
5368:    public static class PointPropertyType extends GMLComplexType {
5369:
5370:        /**
5371:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
5372:         */
5373:        public Element[] getChildElements() {
5374:            return elements;
5375:        }
5376:
5377:        // singleton instance
5378:        private static final GMLComplexType instance = new PointPropertyType();
5379:
5380:        // static element list
5381:        private static final Element[] elements = {
5382:                new GMLElement("Point",
5383:                    GMLComplexTypes.PointType.getInstance(), 0, 1, false,
5384:                    new GMLElement("_Geometry",
5385:                        GMLComplexTypes.AbstractGeometryType.getInstance(), 1,
5386:                        1, true, null)),
5387:            };
5388:
5389:        // static sequence
5390:        private static final DefaultSequence seq = new DefaultSequence(elements);
5391:
5392:        /*
5393:         * part of the singleton pattern
5394:         *
5395:         * @see GMLComplexType#getInstance()
5396:         */
5397:        public static GMLComplexType getInstance() {
5398:            return instance;
5399:        }
5400:
5401:        /**
5402:         * @see schema.ComplexType#isAbstract()
5403:         */
5404:        public boolean isAbstract() {
5405:            return false;
5406:        }
5407:
5408:        /**
5409:         * @see schema.ComplexType#getAnyAttributeNameSpace()
5410:         */
5411:        public String getAnyAttributeNameSpace() {
5412:            return null;
5413:        }
5414:
5415:        /**
5416:         * @see schema.ComplexType#getAttributes()
5417:         */
5418:        public Attribute[] getAttributes() {
5419:            return FeatureAssociationType.attributes;
5420:        }
5421:
5422:        /**
5423:         * @see schema.ComplexType#getChildren()
5424:         */
5425:        public ElementGrouping getChild() {
5426:            return seq;
5427:        }
5428:
5429:        /**
5430:         * @see schema.ComplexType#getName()
5431:         */
5432:        public String getName() {
5433:            return "PointPropertyType";
5434:        }
5435:
5436:        /**
5437:         * @see schema.Type#getValue(java.util.List)
5438:         */
5439:        public Object getValue(Element element, ElementValue[] value,
5440:            Attributes attrs, Map hints) throws SAXException {
5441:            if ((value == null) || (value.length != 1)) {
5442:                throw new SAXException("must be one geometry");
5443:            }
5444:
5445:            return (Point) value[0].getValue();
5446:        }
5447:
5448:        /**
5449:         * @see org.geotools.xml.xsi.Type#getInstanceType()
5450:         */
5451:        public Class getInstanceType() {
5452:            return Point.class;
5453:        }
5454:
5455:        /**
5456:         * @see schema.ComplexType#findChildElement(java.lang.String)
5457:         */
5458:        public Element findChildElement(String name) {
5459:            if (name == null) {
5460:                return null;
5461:            }
5462:
5463:            for (int i = 0; i < elements.length; i++)
5464:                if (name.equals(elements[i].getName())) {
5465:                    return elements[i];
5466:                }
5467:
5468:            return null;
5469:        }
5470:
5471:        /**
5472:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
5473:         *      java.lang.Object, java.util.Map)
5474:         */
5475:        public boolean canEncode(Element element, Object value, Map hints) {
5476:            if ((value == null) || !(value instanceof  Point)) {
5477:                return false;
5478:            }
5479:
5480:            ComplexType t = (element.getType() instanceof  ComplexType)
5481:                ? (ComplexType) element.getType() : null;
5482:
5483:            while ((t != null) && (t != this ))
5484:                t = (t.getParent() instanceof  ComplexType)
5485:                    ? (ComplexType) t.getParent() : null;
5486:
5487:            return t != null;
5488:        }
5489:
5490:        /**
5491:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
5492:         *      java.lang.Object, org.geotools.xml.PrintHandler,
5493:         *      java.util.Map)
5494:         */
5495:        public void encode(Element element, Object value, PrintHandler output,
5496:            Map hints) throws IOException, OperationNotSupportedException {
5497:            if ((value == null) || !(value instanceof  Point)) {
5498:            	throw new OperationNotSupportedException("Value is "+value == null?"null":value.getClass().getName());
5499:            }
5500:
5501:            if (element == null) {
5502:                output.startElement(GMLSchema.NAMESPACE, "pointProperty", null);
5503:                GMLComplexTypes.encode(null, (Point) value, output);
5504:                output.endElement(GMLSchema.NAMESPACE, "pointProperty");
5505:            } else {
5506:                output.startElement(element.getNamespace(), element.getName(),
5507:                    null);
5508:                GMLComplexTypes.encode(null, (Point) value, output);
5509:                output.endElement(element.getNamespace(), element.getName());
5510:            }
5511:        }
5512:    }
5513:
5514:    /**
5515:     * <p>
5516:     * This class represents an PolygonPropertyType within the GML Schema. This
5517:     * includes both the data and parsing functionality associated  with an
5518:     * PolygonPropertyType.
5519:     * </p>
5520:     *
5521:     * @author dzwiers
5522:     *
5523:     * @see GMLComplexType
5524:     * @see ComplexType
5525:     */
5526:    public static class PolygonPropertyType extends GMLComplexType {
5527:
5528:        /**
5529:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
5530:         */
5531:        public Element[] getChildElements() {
5532:            return elements;
5533:        }
5534:
5535:        // singleton instance
5536:        private static final GMLComplexType instance = new PolygonPropertyType();
5537:
5538:        // static element list
5539:        private static final Element[] elements = {
5540:                new GMLElement("Polygon",
5541:                    GMLComplexTypes.PolygonType.getInstance(), 0, 1, false,
5542:                    new GMLElement("_Geometry",
5543:                        GMLComplexTypes.AbstractGeometryType.getInstance(), 1,
5544:                        1, true, null)),
5545:            };
5546:
5547:        // static sequence
5548:        private static final DefaultSequence seq = new DefaultSequence(elements);
5549:
5550:        /*
5551:         * part of the singleton pattern
5552:         *
5553:         * @see GMLComplexType#getInstance()
5554:         */
5555:        public static GMLComplexType getInstance() {
5556:            return instance;
5557:        }
5558:
5559:        /**
5560:         * @see schema.ComplexType#isAbstract()
5561:         */
5562:        public boolean isAbstract() {
5563:            return false;
5564:        }
5565:
5566:        /**
5567:         * @see schema.ComplexType#getAnyAttributeNameSpace()
5568:         */
5569:        public String getAnyAttributeNameSpace() {
5570:            return null;
5571:        }
5572:
5573:        /**
5574:         * @see schema.ComplexType#getAttributes()
5575:         */
5576:        public Attribute[] getAttributes() {
5577:            return FeatureAssociationType.attributes;
5578:        }
5579:
5580:        /**
5581:         * @see schema.ComplexType#getChildren()
5582:         */
5583:        public ElementGrouping getChild() {
5584:            return seq;
5585:        }
5586:
5587:        /**
5588:         * @see schema.ComplexType#getName()
5589:         */
5590:        public String getName() {
5591:            return "PolygonPropertyType";
5592:        }
5593:
5594:        /**
5595:         * @see schema.Type#getValue(java.util.List)
5596:         */
5597:        public Object getValue(Element element, ElementValue[] value,
5598:            Attributes attrs, Map hints) throws SAXException {
5599:            if ((value == null) || (value.length != 1)) {
5600:                throw new SAXException("must be one geometry");
5601:            }
5602:
5603:            return (Polygon) value[0].getValue();
5604:        }
5605:
5606:        /**
5607:         * @see org.geotools.xml.xsi.Type#getInstanceType()
5608:         */
5609:        public Class getInstanceType() {
5610:            return Polygon.class;
5611:        }
5612:
5613:        /**
5614:         * @see schema.ComplexType#findChildElement(java.lang.String)
5615:         */
5616:        public Element findChildElement(String name) {
5617:            if (name == null) {
5618:                return null;
5619:            }
5620:
5621:            for (int i = 0; i < elements.length; i++)
5622:                if (name.equals(elements[i].getName())) {
5623:                    return elements[i];
5624:                }
5625:
5626:            return null;
5627:        }
5628:
5629:        /**
5630:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
5631:         *      java.lang.Object, java.util.Map)
5632:         */
5633:        public boolean canEncode(Element element, Object value, Map hints) {
5634:            if ((value == null) || !(value instanceof  Polygon)) {
5635:                return false;
5636:            }
5637:
5638:            ComplexType t = (element.getType() instanceof  ComplexType)
5639:                ? (ComplexType) element.getType() : null;
5640:
5641:            while ((t != null) && (t != this ))
5642:                t = (t.getParent() instanceof  ComplexType)
5643:                    ? (ComplexType) t.getParent() : null;
5644:
5645:            return t != null;
5646:        }
5647:
5648:        /**
5649:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
5650:         *      java.lang.Object, org.geotools.xml.PrintHandler,
5651:         *      java.util.Map)
5652:         */
5653:        public void encode(Element element, Object value, PrintHandler output,
5654:            Map hints) throws IOException, OperationNotSupportedException {
5655:            if ((value == null) || !(value instanceof  Polygon)) {
5656:            	throw new OperationNotSupportedException("Value is "+value == null?"null":value.getClass().getName());
5657:            }
5658:
5659:            if (element == null) {
5660:                output.startElement(GMLSchema.NAMESPACE, "polygonProperty", null);
5661:                GMLComplexTypes.encode(null, (Polygon) value, output);
5662:                output.endElement(GMLSchema.NAMESPACE, "polygonProperty");
5663:            } else {
5664:                output.startElement(element.getNamespace(), element.getName(),
5665:                    null);
5666:                GMLComplexTypes.encode(null, (Polygon) value, output);
5667:                output.endElement(element.getNamespace(), element.getName());
5668:            }
5669:        }
5670:    }
5671:
5672:    /**
5673:     * <p>
5674:     * This class represents an LineStringPropertyType within the GML Schema.
5675:     * This includes both the data and parsing functionality associated  with
5676:     * an LineStringPropertyType.
5677:     * </p>
5678:     *
5679:     * @author dzwiers
5680:     *
5681:     * @see GMLComplexType
5682:     * @see ComplexType
5683:     */
5684:    public static class LineStringPropertyType extends GMLComplexType {
5685:
5686:        /**
5687:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
5688:         */
5689:        public Element[] getChildElements() {
5690:            return elements;
5691:        }
5692:
5693:        // singleton instance
5694:        private static final GMLComplexType instance = new LineStringPropertyType();
5695:
5696:        // static element list
5697:        private static final Element[] elements = {
5698:                new GMLElement("LineString",
5699:                    GMLComplexTypes.LineStringType.getInstance(), 0, 1, false,
5700:                    new GMLElement("_Geometry",
5701:                        GMLComplexTypes.AbstractGeometryType.getInstance(), 1,
5702:                        1, true, null)),
5703:            };
5704:
5705:        // static sequence
5706:        private static final DefaultSequence seq = new DefaultSequence(elements);
5707:
5708:        /*
5709:         * part of the singleton pattern
5710:         *
5711:         * @see GMLComplexType#getInstance()
5712:         */
5713:        public static GMLComplexType getInstance() {
5714:            return instance;
5715:        }
5716:
5717:        /**
5718:         * @see schema.ComplexType#isAbstract()
5719:         */
5720:        public boolean isAbstract() {
5721:            return false;
5722:        }
5723:
5724:        /**
5725:         * @see schema.ComplexType#getAnyAttributeNameSpace()
5726:         */
5727:        public String getAnyAttributeNameSpace() {
5728:            return null;
5729:        }
5730:
5731:        /**
5732:         * @see schema.ComplexType#getAttributes()
5733:         */
5734:        public Attribute[] getAttributes() {
5735:            return FeatureAssociationType.attributes;
5736:        }
5737:
5738:        /**
5739:         * @see schema.ComplexType#getChildren()
5740:         */
5741:        public ElementGrouping getChild() {
5742:            return seq;
5743:        }
5744:
5745:        /**
5746:         * @see schema.ComplexType#getName()
5747:         */
5748:        public String getName() {
5749:            return "LineStringPropertyType";
5750:        }
5751:
5752:        /**
5753:         * @see schema.Type#getValue(java.util.List)
5754:         */
5755:        public Object getValue(Element element, ElementValue[] value,
5756:            Attributes attrs, Map hints) throws SAXException {
5757:            if ((value == null) || (value.length != 1)) {
5758:                throw new SAXException("must be one geometry");
5759:            }
5760:
5761:            return (LineString) value[0].getValue();
5762:        }
5763:
5764:        /**
5765:         * @see org.geotools.xml.xsi.Type#getInstanceType()
5766:         */
5767:        public Class getInstanceType() {
5768:            return LineString.class;
5769:        }
5770:
5771:        /**
5772:         * @see schema.ComplexType#findChildElement(java.lang.String)
5773:         */
5774:        public Element findChildElement(String name) {
5775:            if (name == null) {
5776:                return null;
5777:            }
5778:
5779:            for (int i = 0; i < elements.length; i++)
5780:                if (name.equals(elements[i].getName())) {
5781:                    return elements[i];
5782:                }
5783:
5784:            return null;
5785:        }
5786:
5787:        /**
5788:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
5789:         *      java.lang.Object, java.util.Map)
5790:         */
5791:        public boolean canEncode(Element element, Object value, Map hints) {
5792:            if ((value == null) || !(value instanceof  LineString)) {
5793:                return false;
5794:            }
5795:
5796:            ComplexType t = (element.getType() instanceof  ComplexType)
5797:                ? (ComplexType) element.getType() : null;
5798:
5799:            while ((t != null) && (t != this ))
5800:                t = (t.getParent() instanceof  ComplexType)
5801:                    ? (ComplexType) t.getParent() : null;
5802:
5803:            return t != null;
5804:        }
5805:
5806:        /**
5807:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
5808:         *      java.lang.Object, org.geotools.xml.PrintHandler,
5809:         *      java.util.Map)
5810:         */
5811:        public void encode(Element element, Object value, PrintHandler output,
5812:            Map hints) throws IOException, OperationNotSupportedException {
5813:            if ((value == null) || !(value instanceof  Point)) {
5814:            	throw new OperationNotSupportedException("Value is "+value == null?"null":value.getClass().getName());
5815:            }
5816:
5817:            if (element == null) {
5818:                output.startElement(GMLSchema.NAMESPACE, "lineStringProperty",
5819:                    null);
5820:                GMLComplexTypes.encode(null, (LineString) value, output);
5821:                output.endElement(GMLSchema.NAMESPACE, "lineStringProperty");
5822:            } else {
5823:                output.startElement(element.getNamespace(), element.getName(),
5824:                    null);
5825:                GMLComplexTypes.encode(null, (LineString) value, output);
5826:                output.endElement(element.getNamespace(), element.getName());
5827:            }
5828:        }
5829:    }
5830:
5831:    /**
5832:     * <p>
5833:     * This class represents an MultiPointPropertyType within the GML Schema.
5834:     * This includes both the data and parsing functionality associated  with
5835:     * an MultiPointPropertyType.
5836:     * </p>
5837:     *
5838:     * @author dzwiers
5839:     *
5840:     * @see GMLComplexType
5841:     * @see ComplexType
5842:     */
5843:    public static class MultiPointPropertyType extends GMLComplexType {
5844:
5845:        /**
5846:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
5847:         */
5848:        public Element[] getChildElements() {
5849:            return elements;
5850:        }
5851:
5852:        // singleton instance
5853:        private static final GMLComplexType instance = new MultiPointPropertyType();
5854:
5855:        // static element list
5856:        private static final Element[] elements = {
5857:                new GMLElement("MultiPoint",
5858:                    GMLComplexTypes.MultiPointType.getInstance(), 0, 1, false,
5859:                    new GMLElement("_Geometry",
5860:                        GMLComplexTypes.AbstractGeometryType.getInstance(), 1,
5861:                        1, true, null)),
5862:            };
5863:
5864:        // static sequence
5865:        private static final DefaultSequence seq = new DefaultSequence(elements);
5866:
5867:        /*
5868:         * part of the singleton pattern
5869:         *
5870:         * @see GMLComplexType#getInstance()
5871:         */
5872:        public static GMLComplexType getInstance() {
5873:            return instance;
5874:        }
5875:
5876:        /**
5877:         * @see schema.ComplexType#isAbstract()
5878:         */
5879:        public boolean isAbstract() {
5880:            return false;
5881:        }
5882:
5883:        /**
5884:         * @see schema.ComplexType#getAnyAttributeNameSpace()
5885:         */
5886:        public String getAnyAttributeNameSpace() {
5887:            return null;
5888:        }
5889:
5890:        /**
5891:         * @see schema.ComplexType#getAttributes()
5892:         */
5893:        public Attribute[] getAttributes() {
5894:            return FeatureAssociationType.attributes;
5895:        }
5896:
5897:        /**
5898:         * @see schema.ComplexType#getChildren()
5899:         */
5900:        public ElementGrouping getChild() {
5901:            return seq;
5902:        }
5903:
5904:        /**
5905:         * @see schema.ComplexType#getName()
5906:         */
5907:        public String getName() {
5908:            return "MultiPointPropertyType";
5909:        }
5910:
5911:        /**
5912:         * @see schema.Type#getValue(java.util.List)
5913:         */
5914:        public Object getValue(Element element, ElementValue[] value,
5915:            Attributes attrs, Map hints) throws SAXException {
5916:            if ((value == null) || (value.length != 1)) {
5917:                throw new SAXException("must be one geometry");
5918:            }
5919:
5920:            Object value2 = value[0].getValue();
5921:        	return (MultiPoint) value2;
5922://            if( value2 instanceof MultiPoint)
5923://            	return (MultiPoint) value2;
5924://            else if( value2 instanceof Point ){
5925://            	GeometryFactory fac=new GeometryFactory();
5926://            	return fac.createMultiPoint(new Point[]{(Point) value2});
5927://            }
5928://            throw new SAXException("Expected value was a MultiPoint, instead it was a: "+value2.getClass());
5929:        }
5930:
5931:        /**
5932:         * @see org.geotools.xml.xsi.Type#getInstanceType()
5933:         */
5934:        public Class getInstanceType() {
5935:            return MultiPoint.class;
5936:        }
5937:
5938:        /**
5939:         * @see schema.ComplexType#findChildElement(java.lang.String)
5940:         */
5941:        public Element findChildElement(String name) {
5942:            if (name == null) {
5943:                return null;
5944:            }
5945:
5946:            for (int i = 0; i < elements.length; i++)
5947:                if (name.equals(elements[i].getName())) {
5948:                    return elements[i];
5949:                }
5950:
5951:            return null;
5952:        }
5953:
5954:        /**
5955:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
5956:         *      java.lang.Object, java.util.Map)
5957:         */
5958:        public boolean canEncode(Element element, Object value, Map hints) {
5959:            if ((value == null) || !(value instanceof  MultiPoint)) {
5960:                return false;
5961:            }
5962:
5963:            ComplexType t = (element.getType() instanceof  ComplexType)
5964:                ? (ComplexType) element.getType() : null;
5965:
5966:            while ((t != null) && (t != this ))
5967:                t = (t.getParent() instanceof  ComplexType)
5968:                    ? (ComplexType) t.getParent() : null;
5969:
5970:            return t != null;
5971:        }
5972:
5973:        /**
5974:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
5975:         *      java.lang.Object, org.geotools.xml.PrintHandler,
5976:         *      java.util.Map)
5977:         */
5978:        public void encode(Element element, Object value, PrintHandler output,
5979:            Map hints) throws IOException, OperationNotSupportedException {
5980:            if ((value == null) || !(value instanceof  MultiPoint)) {
5981:            	throw new OperationNotSupportedException("Value is "+value == null?"null":value.getClass().getName());
5982:            }
5983:
5984:            if (element == null) {
5985:                output.startElement(GMLSchema.NAMESPACE, "multiPointProperty",
5986:                    null);
5987:                GMLComplexTypes.encode(null, (MultiPoint) value, output);
5988:                output.endElement(GMLSchema.NAMESPACE, "multiPointProperty");
5989:            } else {
5990:                output.startElement(element.getNamespace(), element.getName(),
5991:                    null);
5992:                GMLComplexTypes.encode(null, (MultiPoint) value, output);
5993:                output.endElement(element.getNamespace(), element.getName());
5994:            }
5995:        }
5996:    }
5997:
5998:    /**
5999:     * <p>
6000:     * This class represents an MultiLineStringPropertyType within the GML
6001:     * Schema.  This includes both the data and parsing functionality
6002:     * associated  with an MultiLineStringPropertyType.
6003:     * </p>
6004:     *
6005:     * @author dzwiers
6006:     *
6007:     * @see GMLComplexType
6008:     * @see ComplexType
6009:     */
6010:    public static class MultiLineStringPropertyType extends GMLComplexType {
6011:
6012:        /**
6013:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
6014:         */
6015:        public Element[] getChildElements() {
6016:            return elements;
6017:        }
6018:
6019:        // singleton instance
6020:        private static final GMLComplexType instance = new MultiLineStringPropertyType();
6021:
6022:        // static element list
6023:        private static final Element[] elements = {
6024:                new GMLElement("MultiLineString",
6025:                    GMLComplexTypes.MultiLineStringType.getInstance(), 0, 1,
6026:                    false,
6027:                    new GMLElement("_Geometry",
6028:                        GMLComplexTypes.AbstractGeometryType.getInstance(), 1,
6029:                        1, true, null)),
6030:            };
6031:
6032:        // static sequence
6033:        private static final DefaultSequence seq = new DefaultSequence(elements);
6034:
6035:        /*
6036:         * part of the singleton pattern
6037:         *
6038:         * @see GMLComplexType#getInstance()
6039:         */
6040:        public static GMLComplexType getInstance() {
6041:            return instance;
6042:        }
6043:
6044:        /**
6045:         * @see schema.ComplexType#isAbstract()
6046:         */
6047:        public boolean isAbstract() {
6048:            return false;
6049:        }
6050:
6051:        /**
6052:         * @see schema.ComplexType#getAnyAttributeNameSpace()
6053:         */
6054:        public String getAnyAttributeNameSpace() {
6055:            return null;
6056:        }
6057:
6058:        /**
6059:         * @see schema.ComplexType#getAttributes()
6060:         */
6061:        public Attribute[] getAttributes() {
6062:            return FeatureAssociationType.attributes;
6063:        }
6064:
6065:        /**
6066:         * @see schema.ComplexType#getChildren()
6067:         */
6068:        public ElementGrouping getChild() {
6069:            return seq;
6070:        }
6071:
6072:        /**
6073:         * @see schema.ComplexType#getName()
6074:         */
6075:        public String getName() {
6076:            return "MultiLineStringPropertyType";
6077:        }
6078:
6079:        /**
6080:         * @see schema.Type#getValue(java.util.List)
6081:         */
6082:        public Object getValue(Element element, ElementValue[] value,
6083:            Attributes attrs, Map hints) throws SAXException {
6084:            if ((value == null) || (value.length != 1)) {
6085:                throw new SAXException("must be one geometry");
6086:            }
6087:
6088:            Object value2 = value[0].getValue();
6089:        	return (MultiLineString) value2;
6090:        	
6091://            if( value2 instanceof MultiLineString)
6092://            	return (MultiLineString) value2;
6093://            else if( value2 instanceof LineString ){
6094://            	GeometryFactory fac=new GeometryFactory();
6095://            	return fac.createMultiLineString(new LineString[]{(LineString) value2});
6096://            }
6097://            throw new SAXException("Expected value was a MultiLineString, instead it was a: "+value2.getClass());
6098:        }
6099:
6100:        /**
6101:         * @see org.geotools.xml.xsi.Type#getInstanceType()
6102:         */
6103:        public Class getInstanceType() {
6104:            return MultiLineString.class;
6105:        }
6106:
6107:        /**
6108:         * @see schema.ComplexType#findChildElement(java.lang.String)
6109:         */
6110:        public Element findChildElement(String name) {
6111:            if (name == null) {
6112:                return null;
6113:            }
6114:
6115:            for (int i = 0; i < elements.length; i++)
6116:                if (name.equals(elements[i].getName())) {
6117:                    return elements[i];
6118:                }
6119:
6120:            return null;
6121:        }
6122:
6123:        /**
6124:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
6125:         *      java.lang.Object, java.util.Map)
6126:         */
6127:        public boolean canEncode(Element element, Object value, Map hints) {
6128:            if ((value == null) || !(value instanceof  MultiLineString)) {
6129:                return false;
6130:            }
6131:
6132:            ComplexType t = (element.getType() instanceof  ComplexType)
6133:                ? (ComplexType) element.getType() : null;
6134:
6135:            while ((t != null) && (t != this ))
6136:                t = (t.getParent() instanceof  ComplexType)
6137:                    ? (ComplexType) t.getParent() : null;
6138:
6139:            return t != null;
6140:        }
6141:
6142:        /**
6143:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
6144:         *      java.lang.Object, org.geotools.xml.PrintHandler,
6145:         *      java.util.Map)
6146:         */
6147:        public void encode(Element element, Object value, PrintHandler output,
6148:            Map hints) throws IOException, OperationNotSupportedException {
6149:            if ((value == null) || !(value instanceof  MultiLineString)) {
6150:            	throw new OperationNotSupportedException("Value is "+value == null?"null":value.getClass().getName());
6151:            }
6152:
6153:            if (element == null) {
6154:                output.startElement(GMLSchema.NAMESPACE,
6155:                    "multiLineStringProperty", null);
6156:                GMLComplexTypes.encode(null, (MultiLineString) value, output);
6157:                output.endElement(GMLSchema.NAMESPACE, "multiLineStringProperty");
6158:            } else {
6159:                output.startElement(element.getNamespace(), element.getName(),
6160:                    null);
6161:                GMLComplexTypes.encode(null, (MultiLineString) value, output);
6162:                output.endElement(element.getNamespace(), element.getName());
6163:            }
6164:        }
6165:    }
6166:
6167:    /**
6168:     * <p>
6169:     * This class represents an MultiPolygonPropertyType within the GML Schema.
6170:     * This includes both the data and parsing functionality associated  with
6171:     * an MultiPolygonPropertyType.
6172:     * </p>
6173:     *
6174:     * @author dzwiers
6175:     *
6176:     * @see GMLComplexType
6177:     * @see ComplexType
6178:     */
6179:    public static class MultiPolygonPropertyType extends GMLComplexType {
6180:
6181:        /**
6182:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
6183:         */
6184:        public Element[] getChildElements() {
6185:            return elements;
6186:        }
6187:
6188:        // singleton instance
6189:        private static final GMLComplexType instance = new MultiPolygonPropertyType();
6190:
6191:        // static element list
6192:        private static final Element[] elements = {
6193:                new GMLElement("MultiPolygon",
6194:                    GMLComplexTypes.MultiPolygonType.getInstance(), 0, 1,
6195:                    false,
6196:                    new GMLElement("_Geometry",
6197:                        GMLComplexTypes.AbstractGeometryType.getInstance(), 1,
6198:                        1, true, null)),
6199:            };
6200:
6201:        // static sequence
6202:        private static final DefaultSequence seq = new DefaultSequence(elements);
6203:
6204:        /*
6205:         * part of the singleton pattern
6206:         *
6207:         * @see GMLComplexType#getInstance()
6208:         */
6209:        public static GMLComplexType getInstance() {
6210:            return instance;
6211:        }
6212:
6213:        /**
6214:         * @see schema.ComplexType#isAbstract()
6215:         */
6216:        public boolean isAbstract() {
6217:            return false;
6218:        }
6219:
6220:        /**
6221:         * @see schema.ComplexType#getAnyAttributeNameSpace()
6222:         */
6223:        public String getAnyAttributeNameSpace() {
6224:            return null;
6225:        }
6226:
6227:        /**
6228:         * @see schema.ComplexType#getAttributes()
6229:         */
6230:        public Attribute[] getAttributes() {
6231:            return FeatureAssociationType.attributes;
6232:        }
6233:
6234:        /**
6235:         * @see schema.ComplexType#getChildren()
6236:         */
6237:        public ElementGrouping getChild() {
6238:            return seq;
6239:        }
6240:
6241:        /**
6242:         * @see schema.ComplexType#getName()
6243:         */
6244:        public String getName() {
6245:            return "MultiPolygonPropertyType";
6246:        }
6247:
6248:        /**
6249:         * @see schema.Type#getValue(java.util.List)
6250:         */
6251:        public Object getValue(Element element, ElementValue[] value,
6252:            Attributes attrs, Map hints) throws SAXException {
6253:            if ((value == null) || (value.length != 1)) {
6254:                throw new SAXException("must be one geometry");
6255:            }
6256:            
6257:            Object value2 = value[0].getValue();
6258:
6259:        	return (MultiPolygon) value2;
6260://            if( value2 instanceof MultiPolygon)
6261://            	return (MultiPolygon) value2;
6262://            else if( value2 instanceof Polygon ){
6263://            	GeometryFactory fac=new GeometryFactory();
6264://            	return fac.createMultiPolygon(new Polygon[]{(Polygon) value2});
6265://            }
6266://            throw new SAXException("Expected value was a MultiPolygon, instead it was a: "+value2.getClass());
6267:
6268:        }
6269:
6270:        /**
6271:         * @see org.geotools.xml.xsi.Type#getInstanceType()
6272:         */
6273:        public Class getInstanceType() {
6274:            return MultiPolygon.class;
6275:        }
6276:
6277:        /**
6278:         * @see schema.ComplexType#findChildElement(java.lang.String)
6279:         */
6280:        public Element findChildElement(String name) {
6281:            if (name == null) {
6282:                return null;
6283:            }
6284:
6285:            for (int i = 0; i < elements.length; i++)
6286:                if (name.equals(elements[i].getName())) {
6287:                    return elements[i];
6288:                }
6289:
6290:            return null;
6291:        }
6292:
6293:        /**
6294:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
6295:         *      java.lang.Object, java.util.Map)
6296:         */
6297:        public boolean canEncode(Element element, Object value, Map hints) {
6298:            if ((value == null) || !(value instanceof  MultiPolygon)) {
6299:                return false;
6300:            }
6301:
6302:            ComplexType t = (element.getType() instanceof  ComplexType)
6303:                ? (ComplexType) element.getType() : null;
6304:
6305:            while ((t != null) && (t != this ))
6306:                t = (t.getParent() instanceof  ComplexType)
6307:                    ? (ComplexType) t.getParent() : null;
6308:
6309:            return t != null;
6310:        }
6311:
6312:        /**
6313:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
6314:         *      java.lang.Object, org.geotools.xml.PrintHandler,
6315:         *      java.util.Map)
6316:         */
6317:        public void encode(Element element, Object value, PrintHandler output,
6318:            Map hints) throws IOException, OperationNotSupportedException {
6319:            if ((value == null) || !(value instanceof  MultiPolygon)) {
6320:            	throw new OperationNotSupportedException("Value is "+value == null?"null":value.getClass().getName());
6321:            }
6322:
6323:            if (element == null) {
6324:                output.startElement(GMLSchema.NAMESPACE,
6325:                    "multiPolygonProperty", null);
6326:                GMLComplexTypes.encode(null, (MultiPolygon) value, output);
6327:                output.endElement(GMLSchema.NAMESPACE, "multiPolygonProperty");
6328:            } else {
6329:                output.startElement(element.getNamespace(), element.getName(),
6330:                    null);
6331:                GMLComplexTypes.encode(null, (MultiPolygon) value, output);
6332:                output.endElement(element.getNamespace(), element.getName());
6333:            }
6334:        }
6335:    }
6336:
6337:    /**
6338:     * <p>
6339:     * This class represents an MultiGeometryPropertyType within the GML
6340:     * Schema.  This includes both the data and parsing functionality
6341:     * associated  with an MultiGeometryPropertyType.
6342:     * </p>
6343:     *
6344:     * @author dzwiers
6345:     *
6346:     * @see GMLComplexType
6347:     * @see ComplexType
6348:     */
6349:    public static class MultiGeometryPropertyType extends GMLComplexType {
6350:
6351:        /**
6352:         * @see org.geotools.xml.schema.ComplexType#getChildElements()
6353:         */
6354:        public Element[] getChildElements() {
6355:            return elements;
6356:        }
6357:
6358:        // singleton instance
6359:        private static final GMLComplexType instance = new MultiGeometryPropertyType();
6360:
6361:        // static element list
6362:        private static final Element[] elements = {
6363:                new GMLElement("MultiGeometry",
6364:                    GMLComplexTypes.GeometryCollectionType.getInstance(), 0, 1,
6365:                    false,
6366:                    new GMLElement("_Geometry",
6367:                        GMLComplexTypes.AbstractGeometryType.getInstance(), 1,
6368:                        1, true, null)),
6369:            };
6370:
6371:        // static sequence
6372:        private static final DefaultSequence seq = new DefaultSequence(elements);
6373:
6374:        /*
6375:         * part of the singleton pattern
6376:         *
6377:         * @see GMLComplexType#getInstance()
6378:         */
6379:        public static GMLComplexType getInstance() {
6380:            return instance;
6381:        }
6382:
6383:        /**
6384:         * @see schema.ComplexType#isAbstract()
6385:         */
6386:        public boolean isAbstract() {
6387:            return false;
6388:        }
6389:
6390:        /**
6391:         * @see schema.ComplexType#getAnyAttributeNameSpace()
6392:         */
6393:        public String getAnyAttributeNameSpace() {
6394:            return null;
6395:        }
6396:
6397:        /**
6398:         * @see schema.ComplexType#getAttributes()
6399:         */
6400:        public Attribute[] getAttributes() {
6401:            return FeatureAssociationType.attributes;
6402:        }
6403:
6404:        /**
6405:         * @see schema.ComplexType#getChildren()
6406:         */
6407:        public ElementGrouping getChild() {
6408:            return seq;
6409:        }
6410:
6411:        /**
6412:         * @see schema.ComplexType#getName()
6413:         */
6414:        public String getName() {
6415:            return "MultiGeometryPropertyType";
6416:        }
6417:
6418:        /**
6419:         * @see schema.Type#getValue(java.util.List)
6420:         */
6421:        public Object getValue(Element element, ElementValue[] value,
6422:            Attributes attrs, Map hints) throws SAXException {
6423:            if ((value == null) || (value.length != 1)) {
6424:                throw new SAXException("must be one geometry");
6425:            }
6426:
6427:            Object value2 = value[0].getValue();
6428:        	return (GeometryCollection) value2;
6429:            
6430://            if( value2 instanceof GeometryCollection)
6431://            	return (GeometryCollection) value2;
6432://            else if( value2 instanceof Geometry ){
6433://            	GeometryFactory fac=new GeometryFactory();
6434://            	return fac.createGeometryCollection(new Geometry[]{(Geometry) value2});
6435://            }
6436://            throw new SAXException("Expected value was a Geometry, instead it was a: "+value2.getClass());
6437:        }
6438:
6439:        /**
6440:         * @see org.geotools.xml.xsi.Type#getInstanceType()
6441:         */
6442:        public Class getInstanceType() {
6443:            return GeometryCollection.class;
6444:        }
6445:
6446:        /**
6447:         * @see schema.ComplexType#findChildElement(java.lang.String)
6448:         */
6449:        public Element findChildElement(String name) {
6450:            if (name == null) {
6451:                return null;
6452:            }
6453:
6454:            for (int i = 0; i < elements.length; i++)
6455:                if (name.equals(elements[i].getName())) {
6456:                    return elements[i];
6457:                }
6458:
6459:            return null;
6460:        }
6461:
6462:        /**
6463:         * @see org.geotools.xml.schema.Type#canEncode(org.geotools.xml.schema.Element,
6464:         *      java.lang.Object, java.util.Map)
6465:         */
6466:        public boolean canEncode(Element element, Object value, Map hints) {
6467:            if ((value == null) || !(value instanceof  GeometryCollection)) {
6468:                return false;
6469:            }
6470:
6471:            ComplexType t = (element.getType() instanceof  ComplexType)
6472:                ? (ComplexType) element.getType() : null;
6473:
6474:            while ((t != null) && (t != this ))
6475:                t = (t.getParent() instanceof  ComplexType)
6476:                    ? (ComplexType) t.getParent() : null;
6477:
6478:            return t != null;
6479:        }
6480:
6481:        /**
6482:         * @see org.geotools.xml.schema.Type#encode(org.geotools.xml.schema.Element,
6483:         *      java.lang.Object, org.geotools.xml.PrintHandler,
6484:         *      java.util.Map)
6485:         */
6486:        public void encode(Element element, Object value, PrintHandler output,
6487:            Map hints) throws IOException, OperationNotSupportedException {
6488:            if ((value == null) || !(value instanceof  GeometryCollection)) {
6489:            	throw new OperationNotSupportedException("Value is "+value == null?"null":value.getClass().getName());
6490:            }
6491:
6492:            if (element == null) {
6493:                output.startElement(GMLSchema.NAMESPACE,
6494:                    "multiGeometryProperty", null);
6495:                GMLComplexTypes.encode(null, (GeometryCollection) value, output);
6496:                output.endElement(GMLSchema.NAMESPACE, "multiGeometryProperty");
6497:            } else {
6498:                output.startElement(element.getNamespace(), element.getName(),
6499:                    null);
6500:                GMLComplexTypes.encode(null, (GeometryCollection) value, output);
6501:                output.endElement(element.getNamespace(), element.getName());
6502:            }
6503:        }
6504:    }
6505:
6506:
6507:    /*
6508:     * Creates a FT from the information provided
6509:     */
6510:    public static FeatureType createFeatureType(Element element) throws SAXException {
6511:        String ftName = element.getName();
6512:        URI ftNS = element.getType().getNamespace();
6513:        logger.finest("Creating feature type for " + ftName + ":" + ftNS);
6514:
6515:        FeatureTypeBuilder typeFactory = FeatureTypeBuilder.newInstance(ftName);
6516:        typeFactory.setNamespace(ftNS);
6517:        typeFactory.setName(ftName);
6518:
6519:        GeometryAttributeType geometryAttribute = null;
6520:
6521:        ElementGrouping child = ((ComplexType)element.getType()).getChild();
6522://        FeatureType parent = null;
6523://        if(((ComplexType)element.getType()).getParent()instanceof ComplexType)
6524://            parent = createFeatureType((ComplexType)((ComplexType)element.getType()).getParent());
6525:
6526://        if(parent != null && parent.getAttributeTypes()!=null){
6527://            typeFactory.addTypes(parent.getAttributeTypes());
6528://            if(parent.getDefaultGeometry()!=null){
6529://                geometryAttribute = parent.getDefaultGeometry();
6530://            }
6531://        }
6532:
6533:        AttributeType[] attrs = (AttributeType[])getAttributes(element.getName(),child).toArray(new AttributeType[]{,});
6534:        for(int i=0;i<attrs.length;i++){
6535:        	if(attrs[i]!=null){
6536:        		typeFactory.addType(attrs[i]);
6537:
6538:        if ((geometryAttribute == null)
6539:                && attrs[i] instanceof  GeometryAttributeType) {
6540:            if (!attrs[i].getName()
6541://                    .equalsIgnoreCase(BoxType.getInstance().getName())) {
6542:                .equalsIgnoreCase(AbstractFeatureType.getInstance().getChildElements()[2].getName())){
6543:                geometryAttribute = (GeometryAttributeType) attrs[i];
6544:            }
6545:        }}
6546:        }
6547:
6548:        if (geometryAttribute != null) {
6549:            typeFactory.setDefaultGeometry(geometryAttribute);
6550:        }
6551:
6552:        try {
6553:            FeatureType ft = typeFactory.getFeatureType();
6554:            return ft;
6555:        } catch (SchemaException e) {
6556:            logger.warning(e.toString());
6557:            throw new SAXException(e);
6558:        }
6559:    }
6560:    public static FeatureType createFeatureType(ComplexType element) throws SAXException {
6561:        String ftName = element.getName();
6562:        URI ftNS = element.getNamespace();
6563:        logger.finest("Creating feature type for " + ftName + ":" + ftNS);
6564:
6565:        FeatureTypeBuilder typeFactory = FeatureTypeBuilder.newInstance(ftName);
6566:        typeFactory.setNamespace(ftNS);
6567:        typeFactory.setName(ftName);
6568:
6569:        GeometryAttributeType geometryAttribute = null;
6570:
6571:        ElementGrouping child = (element).getChild();
6572:
6573:        AttributeType[] attrs = (AttributeType[])getAttributes(element.getName(),child).toArray(new AttributeType[]{,});
6574:        for(int i=0;i<attrs.length;i++){
6575:        	if(attrs[i]!=null){
6576:            typeFactory.addType(attrs[i]);
6577:
6578:            if ((geometryAttribute == null)
6579:                && attrs[i] instanceof  GeometryAttributeType) {
6580:                if (!attrs[i].getName()
6581:                    .equalsIgnoreCase(AbstractFeatureType.getInstance().getChildElements()[2].getName())){
6582:                    geometryAttribute = (GeometryAttributeType) attrs[i];
6583:                }
6584:            }}
6585:        }
6586:
6587:        if (geometryAttribute != null) {
6588:            typeFactory.setDefaultGeometry(geometryAttribute);
6589:        }
6590:
6591:        try {
6592:            FeatureType ft = typeFactory.getFeatureType();
6593:            return ft;
6594:        } catch (SchemaException e) {
6595:            logger.warning(e.toString());
6596:            throw new SAXException(e);
6597:        }
6598:    }
6599:
6600:    private static List getAttributes(String name, ElementGrouping eg){
6601:        List l = new LinkedList();
6602:        AttributeType t = null;
6603:        switch(eg.getGrouping()){
6604:
6605:        case ElementGrouping.CHOICE:
6606:            t = getAttribute(name, (Choice)eg);
6607:            if(t!=null)
6608:                l.add(t);
6609:            break;
6610:        case ElementGrouping.GROUP:
6611:            l.addAll(getAttributes(name,((Group)eg).getChild()));
6612:            break;
6613:        case ElementGrouping.ELEMENT:
6614:            t = getAttribute((Element)eg);
6615:            if(t!=null)
6616:                l.add(t);
6617:        	return l;
6618:
6619:        case ElementGrouping.ALL:
6620:            Element[] elems = ((All)eg).getElements();
6621:            if(elems!=null)
6622:                for(int i=0;i<elems.length;i++)
6623:                    l.add(getAttribute(elems[i]));
6624:        	break;
6625:        case ElementGrouping.SEQUENCE:
6626:            ElementGrouping[] children = ((Sequence)eg).getChildren();
6627:            if(children!=null)
6628:                for(int i=0;i<children.length;i++)
6629:                    l.addAll(getAttributes(name, children[i]));
6630:    	break;
6631:        }
6632:        return l;
6633:    }
6634:
6635:    private static AttributeType getAttribute(Element eg){
6636:    	if(eg.getNamespace() == GMLSchema.NAMESPACE && (AbstractFeatureType.getInstance().getChildElements()[0] == eg || AbstractFeatureType.getInstance().getChildElements()[1] == eg || AbstractFeatureType.getInstance().getChildElements()[2] == eg))
6637:    		return null;
6638:
6639:        Class type = Object.class;
6640:    	if(eg.getType() != null){
6641:	        if(eg.getType() instanceof  SimpleType){
6642:	            type = eg.getType().getInstanceType();
6643:	        }else{
6644:	            if(Object.class.equals(eg.getType().getInstanceType()) || Object[].class.equals(eg.getType().getInstanceType())){
6645:	                // some work now
6646:	                ElementGrouping child = ((ComplexType)eg.getType()).getChild();
6647:	                if(child != null){
6648:	                    List l = getAttributes(eg.getName(),child);
6649:	                    if(l.isEmpty()){
6650:	                        // who knows ... this really shouldn't happen
6651:	                        type = eg.getType().getInstanceType();
6652:	                    }else{
6653:	                        if(l.size() == 1){
6654:	                            return (AttributeType)l.iterator().next();
6655:	                        }
6656:	                        // Do some magic to find the type
6657:	                        type = getCommonType(l);
6658:	                    }
6659:	                }else{
6660:	                    // who knows ... this really shouldn't happen
6661:	                    type = eg.getType().getInstanceType();
6662:	                }
6663:	            }else{
6664:	                // we have a real type
6665:	                type = eg.getType().getInstanceType();
6666:	            }
6667:	        }
6668:    	}
6669:        if(type == null)
6670:            type = Object.class;
6671:        
6672:        // nillable should really be nillable, but in gt2.X nillable in an attribute is equivalent to minOccurs == 0 as well
6673:		boolean nillable = eg.isNillable()||eg.getMinOccurs() == 0;
6674:        if( !nillable ){
6675:            try{
6676:                Object defaultValue = DataUtilities.defaultValue(type);
6677:                return AttributeTypeFactory.newAttributeType( eg.getName(), type, nillable, Filter.INCLUDE, defaultValue, null);
6678:            }catch( IllegalArgumentException e ){
6679:                // can happen if the type is not supported by the method.  
6680:                // in this case I'm taking the easy way out and just not 
6681:                // having a default value.
6682:                logger.warning("Don't know how to make a default value for: "+type
6683:                        +". Consider making it nillable.");
6684:                
6685:                return AttributeTypeFactory.newAttributeType(eg.getName(),type,(nillable));
6686:            }
6687:        }
6688:        return AttributeTypeFactory.newAttributeType(eg.getName(),type,(nillable));
6689:    }
6690:
6691:    private static AttributeType getAttribute(String name, Choice eg){
6692:        
6693:        List l = new LinkedList();
6694:        ElementGrouping[] children = eg.getChildren();
6695:        if(children!=null)
6696:            for(int i=0;i<children.length;i++){
6697:                l.addAll(getAttributes(name, children[i]));
6698:            }
6699:        
6700:        if(l.isEmpty()){
6701:            // who knows ... this really shouldn't happen
6702:            return null;
6703:        }
6704:        if(l.size() == 1){
6705:            return (AttributeType)l.iterator().next();
6706:        }
6707:            // Do some magic to find the type
6708:            Class type = getCommonType(l);
6709:            if(type == null)
6710:                type = Object.class;
6711:            // Take the first name ... cause we need one anyways
6712:            // nillable should really be nillable, but in gt2.X nillable in an attribute is equivalent to minOccurs == 0 as well
6713:            boolean nillable = eg.getMinOccurs() == 0;
6714:            if(!nillable && children != null){
6715:                for(int i=0;i<children.length && !nillable;i++){
6716:                    if(eg.getMinOccurs() == 0)
6717:                        nillable = true;
6718:                }
6719:            }
6720:            Class[] choices=collectionChoices(l);
6721:            if( Geometry.class.isAssignableFrom(type))
6722:            	return new ChoiceAttributeTypeImpl.Geometry(name,choices,type,nillable,1,1,null, null, Filter.INCLUDE);
6723:            return new ChoiceAttributeTypeImpl(name,choices,type,nillable,1,1,null, Filter.INCLUDE);
6724:    }
6725:    
6726:    private static Class[] collectionChoices(List l) {
6727:    	Class[] choices=new Class[l.size()];
6728:    	int i=0;
6729:    	for (Iterator iter = l.iterator(); iter.hasNext(); i++) {
6730:			AttributeType type = (AttributeType) iter.next();
6731:			choices[i]=type.getType();
6732:		}
6733:    	return choices;
6734:	}
6735:
6736:	// takes List<AttributeType>
6737:    private static Class getCommonType(List attributeTypes){
6738:        if(attributeTypes == null || attributeTypes.isEmpty())
6739:            return null;
6740:        if(attributeTypes.size() == 1)
6741:            return attributeTypes.iterator().next().getClass();
6742:        
6743:        Class common = null;
6744:        AttributeType at = null;
6745:        Iterator i = attributeTypes.iterator();
6746:        while(i.hasNext()){
6747:            at = (AttributeType)i.next();
6748:            if(at!= null){
6749:                if(common == null){
6750:                    common = at.getType();
6751:                }else{
6752:                    // merge two types
6753:                    Class t = at.getType();
6754:                    if(t!=null){
6755:                        if(!common.isAssignableFrom(t)){
6756:                            // either t is super class .. or they share one
6757:                            if(t.isAssignableFrom(common)){
6758:                                common = t;
6759:                            }else{
6760:                            	int selection = findCompatible(common, t);
6761:                            	switch (selection) {
6762:								case 0:
6763:									
6764:									common = findCommon(common,t);
6765:									break;
6766:								case 1:
6767:									// common=common;  
6768:									break;
6769:								case 2:
6770:									common=t;
6771:									break;
6772:
6773:								default:
6774:									break;
6775:								}
6776:                            }
6777:                        }
6778:                    }
6779:                }
6780:            }
6781:        }
6782:        return common;
6783:    }
6784:    
6785:    /**
6786:     * This is a bit of a hack to allow certain special cases.  This is required because the feature model does not 
6787:     * support choices and making a Choice (Polygon, MultiPolygon) a Geometry is terrible because editing will allow all
6788:     * types to be added but really that is incorrect.
6789:     * 
6790:     * <p>For example:
6791:     * Polygon and MultiPolygon are compatible.  Polygons can be made MultiPolygons easily.
6792:     *   
6793:     * @return 0 if no compatibility is possible, 1 if c1 is a good choice, 2 if c2 is a good choice.
6794:     */
6795:    private static int findCompatible(Class c1, Class c2){
6796:    	if( c1==Polygon.class && c2==MultiPolygon.class ){
6797:    		return 2;
6798:    	}
6799:    	if( c2==Polygon.class && c1==MultiPolygon.class ){
6800:    		return 1;
6801:    	}
6802:    	if( c1==Point.class && c2==MultiPoint.class ){
6803:    		return 2;
6804:    	}
6805:    	if( c2==Point.class && c1==MultiPoint.class ){
6806:    		return 1;
6807:    	}
6808:    	if( c1==LineString.class && c2==MultiLineString.class ){
6809:    		return 2;
6810:    	}
6811:    	if( c2==LineString.class && c1==MultiLineString.class ){
6812:    		return 1;
6813:    	}
6814:    	if( c1==Geometry.class && c2==GeometryCollection.class ){
6815:    		return 2;
6816:    	}
6817:    	if( c2==Geometry.class && c1==GeometryCollection.class ){
6818:    		return 1;
6819:    	}
6820:    	
6821:    	return 0;
6822:    	
6823:    }
6824:    private static Class findCommon(Class c1, Class c2){
6825:        if(Object.class == c1)
6826:            return c2;
6827:        if(Object.class == c2)
6828:            return c1;
6829:        
6830:        Class p1 = c1.getSuperclass();
6831:        if(p1.isAssignableFrom(c2))
6832:            return p1;
6833:        Class p2 = c2.getSuperclass();
6834:        if(p2.isAssignableFrom(c1))
6835:            return p2;
6836:        
6837:        Class t = findCommon(p1,p2);
6838:        if(!(t == Object.class))
6839:            return t;
6840:        
6841:            // interfaces?
6842:        Class[] it1 = c1.getInterfaces();
6843:        Class[] it2 = c2.getInterfaces();
6844:        
6845:        if(it1 != null && it1.length>0 && it2 != null && it2.length>0){
6846:            for(int i=0;i<it1.length;i++){
6847:                for(int j=0;j<it2.length;j++){
6848:                    if(it1[i].isAssignableFrom(it2[j]))
6849:                        return it1[i];
6850:                    if(it2[j].isAssignableFrom(it1[i]))
6851:                        return it2[j];
6852:                }
6853:            }
6854:        }
6855:            
6856:        return Object.class;
6857:    }
6858:}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.