Source Code Cross Referenced for SampleFeatureFixtures.java in  » GIS » GeoTools-2.4.1 » org » geotools » feature » 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.feature 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2002-2006, Geotools Project Managment Committee (PMC)
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation; either
009:         *    version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.feature;
017:
018:        import com.vividsolutions.jts.geom.Coordinate;
019:        import com.vividsolutions.jts.geom.GeometryFactory;
020:        import com.vividsolutions.jts.geom.LineString;
021:        import com.vividsolutions.jts.geom.MultiLineString;
022:        import com.vividsolutions.jts.geom.Point;
023:        import com.vividsolutions.jts.geom.PrecisionModel;
024:        import org.geotools.feature.type.ChoiceAttributeType;
025:
026:        /**
027:         * This is a support class which creates test features for use in testing.
028:         *
029:         * @author jamesm
030:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/test/java/org/geotools/feature/SampleFeatureFixtures.java $
031:         */
032:        public class SampleFeatureFixtures {
033:            /**
034:             * Feature on which to preform tests
035:             */
036:
037:            // private Feature testFeature = null;
038:            /**
039:             * Creates a new instance of SampleFeatureFixtures
040:             */
041:            public SampleFeatureFixtures() {
042:            }
043:
044:            public static Feature createFeature() {
045:                try {
046:                    FeatureType testType = createTestType();
047:                    Object[] attributes = createAttributes();
048:
049:                    return testType.create(attributes);
050:                } catch (Exception e) {
051:                    Error ae = new AssertionError(
052:                            "Sample Feature for tests has been misscoded");
053:                    ae.initCause(e);
054:                    throw ae;
055:                }
056:            }
057:
058:            public static Feature createAddressFeature() {
059:                try {
060:                    return createFeature();
061:
062:                    //FeatureType addressType = createAddressType();
063:                    //Object[] attributes = createComplexAttributes();
064:                    //return addressType.create(attributes);
065:                } catch (Exception e) {
066:                    Error ae = new AssertionError(
067:                            "Sample Feature for tests has been misscoded");
068:                    ae.initCause(e);
069:                    throw ae;
070:                }
071:            }
072:
073:            /**
074:             * creates and returns an array of sample attributes.
075:             *
076:             */
077:            public static Object[] createAttributes() {
078:                Object[] attributes = new Object[10];
079:                GeometryFactory gf = new GeometryFactory();
080:                attributes[0] = gf.createPoint(new Coordinate(1, 2));
081:                attributes[1] = new Boolean(true);
082:                attributes[2] = new Character('t');
083:                attributes[3] = new Byte("10");
084:                attributes[4] = new Short("101");
085:                attributes[5] = new Integer(1002);
086:                attributes[6] = new Long(10003);
087:                attributes[7] = new Float(10000.4);
088:                attributes[8] = new Double(100000.5);
089:                attributes[9] = "test string data";
090:
091:                return attributes;
092:            }
093:
094:            //If we go to factories/protected constructors this won't work, will need
095:            //to move to a types directory, or use the factory
096:            public static AttributeType getChoiceAttrType1() {
097:                return createChoiceAttrType("choiceTest1", createType1Choices());
098:            }
099:
100:            public static AttributeType[] createType1Choices() {
101:                AttributeType[] choices = new AttributeType[3];
102:                choices[0] = AttributeTypeFactory.newAttributeType("testByte",
103:                        Byte.class);
104:                choices[1] = AttributeTypeFactory.newAttributeType(
105:                        "testDouble", Double.class);
106:                choices[2] = AttributeTypeFactory.newAttributeType(
107:                        "testString", String.class);
108:
109:                return choices;
110:            }
111:
112:            public static AttributeType getChoiceAttrType2() {
113:                AttributeType[] choices = new AttributeType[2];
114:                choices[0] = AttributeTypeFactory.newAttributeType(
115:                        "testString", String.class, false);
116:                choices[1] = AttributeTypeFactory.newAttributeType("testInt",
117:                        Integer.class, false);
118:
119:                return createChoiceAttrType("choiceTest2", choices);
120:            }
121:
122:            public static AttributeType createChoiceAttrType(String name,
123:                    AttributeType[] choices) {
124:                return new ChoiceAttributeType(name, choices);
125:            }
126:
127:            public static AttributeType createGeomChoiceAttrType(String name,
128:                    GeometryAttributeType[] choices) {
129:                return new ChoiceAttributeType.Geometric(name, choices);
130:            }
131:
132:            public static AttributeType getChoiceGeomType() {
133:                GeometryAttributeType[] choices = new GeometryAttributeType[2];
134:                choices[0] = (GeometryAttributeType) AttributeTypeFactory
135:                        .newAttributeType("testLine", LineString.class);
136:                choices[1] = (GeometryAttributeType) AttributeTypeFactory
137:                        .newAttributeType("testMultiLine",
138:                                MultiLineString.class);
139:
140:                return createGeomChoiceAttrType("choiceGeom", choices);
141:            }
142:
143:            public static FeatureType createChoiceFeatureType() {
144:                FeatureTypeFactory typeFactory = FeatureTypeFactory
145:                        .newInstance("test");
146:                typeFactory.addType(getChoiceAttrType1());
147:                typeFactory.addType(getChoiceAttrType2());
148:                typeFactory.addType(getChoiceGeomType());
149:                typeFactory
150:                        .setDefaultGeometry((GeometryAttributeType) typeFactory
151:                                .get(2));
152:
153:                try {
154:                    return typeFactory.getFeatureType();
155:                } catch (SchemaException se) {
156:                    throw new RuntimeException(
157:                            "Programmer error making choice ftype", se);
158:                }
159:            }
160:
161:            /**
162:             * DOCUMENT ME!
163:             *
164:             *
165:             * @throws SchemaException
166:             */
167:            public static FeatureType createTestType() throws SchemaException {
168:                FeatureTypeFactory typeFactory = FeatureTypeFactory
169:                        .newInstance("test");
170:                typeFactory.addType(AttributeTypeFactory.newAttributeType(
171:                        "testGeometry", Point.class));
172:
173:                typeFactory.addType(AttributeTypeFactory.newAttributeType(
174:                        "testBoolean", Boolean.class));
175:
176:                typeFactory.addType(AttributeTypeFactory.newAttributeType(
177:                        "testCharacter", Character.class));
178:                typeFactory.addType(AttributeTypeFactory.newAttributeType(
179:                        "testByte", Byte.class));
180:                typeFactory.addType(AttributeTypeFactory.newAttributeType(
181:                        "testShort", Short.class));
182:                typeFactory.addType(AttributeTypeFactory.newAttributeType(
183:                        "testInteger", Integer.class));
184:                typeFactory.addType(AttributeTypeFactory.newAttributeType(
185:                        "testLong", Long.class));
186:                typeFactory.addType(AttributeTypeFactory.newAttributeType(
187:                        "testFloat", Float.class));
188:                typeFactory.addType(AttributeTypeFactory.newAttributeType(
189:                        "testDouble", Double.class));
190:                typeFactory.addType(AttributeTypeFactory.newAttributeType(
191:                        "testString", String.class));
192:                typeFactory
193:                        .setDefaultGeometry((GeometryAttributeType) typeFactory
194:                                .get(0));
195:
196:                return typeFactory.getFeatureType();
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.