Source Code Cross Referenced for AbstractGMLBindingTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » gml2 » bindings » 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.gml2.bindings 
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;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.gml2.bindings;
017:
018:        import junit.framework.TestCase;
019:        import org.eclipse.xsd.XSDAttributeDeclaration;
020:        import org.eclipse.xsd.XSDElementDeclaration;
021:        import org.eclipse.xsd.XSDFactory;
022:        import org.eclipse.xsd.XSDSchema;
023:        import org.eclipse.xsd.XSDSimpleTypeDefinition;
024:        import org.eclipse.xsd.XSDTypeDefinition;
025:        import org.eclipse.xsd.util.XSDSchemaLocationResolver;
026:        import org.picocontainer.MutablePicoContainer;
027:        import org.picocontainer.defaults.DefaultPicoContainer;
028:        import java.util.Iterator;
029:        import java.util.List;
030:        import javax.xml.namespace.QName;
031:        import com.vividsolutions.jts.geom.Coordinate;
032:        import com.vividsolutions.jts.geom.CoordinateSequence;
033:        import com.vividsolutions.jts.geom.CoordinateSequenceFactory;
034:        import com.vividsolutions.jts.geom.impl.CoordinateArraySequenceFactory;
035:        import org.geotools.feature.AttributeTypeFactory;
036:        import org.geotools.feature.DefaultAttributeTypeFactory;
037:        import org.geotools.feature.DefaultFeatureTypeFactory;
038:        import org.geotools.feature.Feature;
039:        import org.geotools.feature.FeatureType;
040:        import org.geotools.feature.FeatureTypeBuilder;
041:        import org.geotools.gml2.GMLConfiguration;
042:        import org.geotools.xml.AttributeInstance;
043:        import org.geotools.xml.Binding;
044:        import org.geotools.xml.ElementInstance;
045:        import org.geotools.xml.InstanceComponent;
046:        import org.geotools.xml.Node;
047:        import org.geotools.xml.Schemas;
048:        import org.geotools.xml.impl.AttributeImpl;
049:        import org.geotools.xml.impl.ElementImpl;
050:        import org.geotools.xml.impl.NodeImpl;
051:
052:        public class AbstractGMLBindingTest extends TestCase {
053:            XSDSchema schema;
054:            MutablePicoContainer container;
055:            FeatureTypeBuilder ftBuilder;
056:            AttributeTypeFactory attFactory;
057:
058:            protected void setUp() throws Exception {
059:                String loc = GMLConfiguration.class.getResource("feature.xsd")
060:                        .toString();
061:
062:                GMLConfiguration configuration = new GMLConfiguration();
063:                schema = configuration.schema();
064:                container = new DefaultPicoContainer();
065:
066:                configuration.getBindingConfiguration().configure(container);
067:
068:                ftBuilder = new DefaultFeatureTypeFactory();
069:                attFactory = new DefaultAttributeTypeFactory();
070:            }
071:
072:            protected void tearDown() throws Exception {
073:                container.dispose();
074:            }
075:
076:            Binding getBinding(QName type) {
077:                return (Binding) container.getComponentInstance(type);
078:            }
079:
080:            Node createNode(InstanceComponent instance,
081:                    ElementInstance[] elements, Object[] elementValues,
082:                    AttributeInstance[] attributes, Object[] attValues) {
083:                NodeImpl node = new NodeImpl(instance);
084:
085:                if ((elements != null) && (elements.length > 0)) {
086:                    for (int i = 0; i < elements.length; i++) {
087:                        node.addChild(new NodeImpl(elements[i],
088:                                elementValues[i]));
089:                    }
090:                }
091:
092:                if ((attributes != null) && (attributes.length > 0)) {
093:                    for (int i = 0; i < attributes.length; i++) {
094:                        node.addAttribute(new NodeImpl(attributes[i],
095:                                attValues[i]));
096:                    }
097:                }
098:
099:                return node;
100:            }
101:
102:            AttributeInstance createAtribute(String namespace, String name,
103:                    QName type, String text) {
104:                XSDAttributeDeclaration declaration = XSDFactory.eINSTANCE
105:                        .createXSDAttributeDeclaration();
106:                declaration.setName(name);
107:                declaration.setTargetNamespace(namespace);
108:                declaration
109:                        .setTypeDefinition((XSDSimpleTypeDefinition) findTypeDefinition(
110:                                schema, type));
111:
112:                AttributeInstance attribute = new AttributeImpl(declaration);
113:                attribute.setName(name);
114:                attribute.setNamespace(namespace);
115:                attribute.setText(text);
116:
117:                return attribute;
118:            }
119:
120:            ElementInstance createElement(String namespace, String name,
121:                    QName type, String text) {
122:                XSDElementDeclaration declaration = XSDFactory.eINSTANCE
123:                        .createXSDElementDeclaration();
124:                declaration.setName(name);
125:                declaration.setTargetNamespace(namespace);
126:                declaration.setTypeDefinition(findTypeDefinition(schema, type));
127:
128:                ElementInstance element = new ElementImpl(declaration);
129:
130:                element.setName(name);
131:                element.setNamespace(namespace);
132:                element.setText(text);
133:
134:                return element;
135:            }
136:
137:            public CoordinateSequence createCoordinateSequence(Coordinate c) {
138:                return createCoordinateSequence(new Coordinate[] { c });
139:            }
140:
141:            public CoordinateSequence createCoordinateSequence(Coordinate[] c) {
142:                CoordinateSequenceFactory csFactory = CoordinateArraySequenceFactory
143:                        .instance();
144:
145:                return csFactory.create(c);
146:            }
147:
148:            public Feature createFeature(String[] names, Class[] types,
149:                    Object[] values) {
150:                ftBuilder.setName("test");
151:
152:                for (int i = 0; i < names.length; i++) {
153:                    ftBuilder.addType(attFactory.newAttributeType(names[i],
154:                            values[i].getClass()));
155:                }
156:
157:                try {
158:                    FeatureType fType = ftBuilder.getFeatureType();
159:
160:                    return fType.create(values);
161:                } catch (Exception e) {
162:                    throw new RuntimeException(e);
163:                }
164:            }
165:
166:            XSDTypeDefinition findTypeDefinition(XSDSchema schema, QName type) {
167:                List types = schema.getTypeDefinitions();
168:
169:                for (Iterator itr = types.iterator(); itr.hasNext();) {
170:                    XSDTypeDefinition typeDef = (XSDTypeDefinition) itr.next();
171:
172:                    if (type.getNamespaceURI().equals(
173:                            typeDef.getTargetNamespace())
174:                            && type.getLocalPart().equals(typeDef.getName())) {
175:                        return typeDef;
176:                    }
177:                }
178:
179:                return null;
180:            }
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.