root / trunk / libraries / libGPE / src-test / org / gvsig / gpe / writers / schemas / GPEFeatureWithSequenceElementTest.java @ 12418
History | View | Annotate | Download (6.54 KB)
1 |
package org.gvsig.gpe.writers.schemas; |
---|---|
2 |
|
3 |
import org.gvsig.gpe.containers.Element; |
4 |
import org.gvsig.gpe.containers.Feature; |
5 |
import org.gvsig.gpe.containers.Layer; |
6 |
import org.gvsig.xmlschema.som.IXSComplexTypeDefinition; |
7 |
import org.gvsig.xmlschema.som.IXSContentType; |
8 |
import org.gvsig.xmlschema.som.IXSElementDeclaration; |
9 |
import org.gvsig.xmlschema.utils.TypeUtils; |
10 |
|
11 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
12 |
*
|
13 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
14 |
*
|
15 |
* This program is free software; you can redistribute it and/or
|
16 |
* modify it under the terms of the GNU General Public License
|
17 |
* as published by the Free Software Foundation; either version 2
|
18 |
* of the License, or (at your option) any later version.
|
19 |
*
|
20 |
* This program is distributed in the hope that it will be useful,
|
21 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
* GNU General Public License for more details.
|
24 |
*
|
25 |
* You should have received a copy of the GNU General Public License
|
26 |
* along with this program; if not, write to the Free Software
|
27 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
28 |
*
|
29 |
* For more information, contact:
|
30 |
*
|
31 |
* Generalitat Valenciana
|
32 |
* Conselleria d'Infraestructures i Transport
|
33 |
* Av. Blasco Ib??ez, 50
|
34 |
* 46010 VALENCIA
|
35 |
* SPAIN
|
36 |
*
|
37 |
* +34 963862235
|
38 |
* gvsig@gva.es
|
39 |
* www.gvsig.gva.es
|
40 |
*
|
41 |
* or
|
42 |
*
|
43 |
* IVER T.I. S.A
|
44 |
* Salamanca 50
|
45 |
* 46005 Valencia
|
46 |
* Spain
|
47 |
*
|
48 |
* +34 963163400
|
49 |
* dac@iver.es
|
50 |
*/
|
51 |
/* CVS MESSAGES:
|
52 |
*
|
53 |
* $Id: GPEFeatureWithSequenceElementTest.java 12418 2007-06-29 12:19:48Z jorpiell $
|
54 |
* $Log$
|
55 |
* Revision 1.5 2007-06-29 12:19:14 jorpiell
|
56 |
* The schema validation is made independently of the concrete writer
|
57 |
*
|
58 |
* Revision 1.4 2007/06/22 12:21:18 jorpiell
|
59 |
* The typeNotFoundException has been deleted. It never was thrown
|
60 |
*
|
61 |
* Revision 1.3 2007/06/14 13:50:06 jorpiell
|
62 |
* The schema jar name has been changed
|
63 |
*
|
64 |
* Revision 1.2 2007/06/08 11:34:57 jorpiell
|
65 |
* IXSSchema interface updated
|
66 |
*
|
67 |
* Revision 1.1 2007/06/07 14:52:28 jorpiell
|
68 |
* Add the schema support
|
69 |
*
|
70 |
* Revision 1.2 2007/05/15 09:52:00 jorpiell
|
71 |
* The namespace is deleted from the element name
|
72 |
*
|
73 |
* Revision 1.1 2007/05/02 11:46:07 jorpiell
|
74 |
* Writing tests updated
|
75 |
*
|
76 |
*
|
77 |
*/
|
78 |
/**
|
79 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
80 |
*/
|
81 |
public abstract class GPEFeatureWithSequenceElementTest extends GPEWriterWithSchemaBaseTest { |
82 |
private String layerId = "l1"; |
83 |
private String layerName = "Points Layer"; |
84 |
private String layerDescription = "This is a test of a points layer"; |
85 |
private String layerSrs = "EPSG:23030"; |
86 |
private String layerXsElementName = "cities"; |
87 |
private String feature1Name = "city"; |
88 |
private String feature1Id = "f1"; |
89 |
private String point1Id = "p1"; |
90 |
private double point1X = generateRandomPoint(); |
91 |
private double point1Y = generateRandomPoint(); |
92 |
private double point1Z = generateRandomPoint(); |
93 |
private String element1Name = "Population"; |
94 |
private Integer element1Value = new Integer(30000); |
95 |
private String element1Type = TypeUtils.getXSType(element1Value.getClass()); |
96 |
private String element2Name = "Country"; |
97 |
private String element2Value = "USA"; |
98 |
private String element2Type = TypeUtils.getXSType(element2Value.getClass()); |
99 |
private String element3Name = "Capital"; |
100 |
private Boolean element3Value = new Boolean(false); |
101 |
private String element3Type = TypeUtils.getXSType(element3Value.getClass()); |
102 |
//Schema
|
103 |
private String xsLayerName = "cities"; |
104 |
private String xsLayerType = "citiesType"; |
105 |
private String xsLayerType_ = IXSComplexTypeDefinition.SEQUENCE; |
106 |
private String xsFeature1Name = "city"; |
107 |
private String xsFeature1Type = "cityType"; |
108 |
private String xsFeature1Type_ = IXSComplexTypeDefinition.SEQUENCE; |
109 |
private String xsFeature1ContentType = IXSContentType.WITOUT_CONTENT; |
110 |
private String xsFeature1ContentRestriction = IXSContentType.WITOUT_RESTRICTION; |
111 |
private String xsFeature1Element1Name = "Population"; |
112 |
private String xsFeature1Element1Type = "xs:integer"; |
113 |
private String xsFeature1Element2Name = "Country"; |
114 |
private String xsFeature1Element2Type = "xs:string"; |
115 |
private String xsFeature1Element3Name = "Capital"; |
116 |
private String xsFeature1Element3Type = "xs:boolean"; |
117 |
|
118 |
|
119 |
/*
|
120 |
* (non-Javadoc)
|
121 |
* @see org.gvsig.gpe.writers.GPEWriterBaseTest#readObjects()
|
122 |
*/
|
123 |
public void readObjects() { |
124 |
Layer[] layers = getLayers();
|
125 |
assertEquals(layers.length, 1);
|
126 |
Layer layer = layers[0];
|
127 |
|
128 |
assertEquals(layer.getFeatures().size(), 1);
|
129 |
//FEATURE 1
|
130 |
Feature feature1 = (Feature)layer.getFeatures().get(0);
|
131 |
Element element1 = feature1.getElementAt(0); |
132 |
assertEquals(element1.getName(), element1Name); |
133 |
assertEquals(element1.getValue(), element1Value); |
134 |
assertEquals(element1.getType(), element1Type); |
135 |
Element element2 = feature1.getElementAt(1); |
136 |
assertEquals(element2.getName(), element2Name); |
137 |
assertEquals(element2.getValue(), element2Value); |
138 |
assertEquals(element2.getType(), element2Type); |
139 |
Element element3 = feature1.getElementAt(2); |
140 |
assertEquals(element3.getName(), element3Name); |
141 |
assertEquals(element3.getValue(), element3Value); |
142 |
assertEquals(element3.getType(), element3Type); |
143 |
|
144 |
} |
145 |
|
146 |
/*
|
147 |
* (non-Javadoc)
|
148 |
* @see org.gvsig.gpe.writers.GPEWriterBaseTest#writeObjects()
|
149 |
*/
|
150 |
public void writeObjects() { |
151 |
getWriterHandler().initialize(); |
152 |
getWriterHandler().startLayer(layerId, layerName, layerDescription, layerSrs, null);
|
153 |
getWriterHandler().startFeature(feature1Id,feature1Name, xsFeature1Name); |
154 |
getWriterHandler().startPoint(point1Id, point1X, point1Y, point1Z, layerSrs); |
155 |
getWriterHandler().endPoint(); |
156 |
getWriterHandler().startElement(element1Name, |
157 |
element1Value, |
158 |
element1Type); |
159 |
getWriterHandler().endElement(); |
160 |
getWriterHandler().startElement(element2Name, |
161 |
element2Value, |
162 |
element2Type); |
163 |
getWriterHandler().endElement(); |
164 |
getWriterHandler().startElement(element3Name, |
165 |
element3Value, |
166 |
element3Type); |
167 |
getWriterHandler().endElement(); |
168 |
getWriterHandler().endFeature(); |
169 |
getWriterHandler().endLayer(); |
170 |
getWriterHandler().close(); |
171 |
} |
172 |
|
173 |
/*
|
174 |
* (non-Javadoc)
|
175 |
* @see org.gvsig.gpe.writers.schemas.GPEWriterWithSchemaBaseTest#writeSchema()
|
176 |
*/
|
177 |
public void writeSchema(){ |
178 |
getSchema().addElement( |
179 |
xsFeature1Name, |
180 |
xsFeature1Type); |
181 |
IXSComplexTypeDefinition complexType = getSchema().addComplexType(xsFeature1Type, xsFeature1Type_, xsFeature1ContentType, xsFeature1ContentRestriction); |
182 |
complexType.addElement( |
183 |
xsFeature1Element1Name, |
184 |
xsFeature1Element1Type); |
185 |
complexType.addElement( |
186 |
xsFeature1Element2Name, |
187 |
xsFeature1Element2Type); |
188 |
complexType.addElement( |
189 |
xsFeature1Element3Name, |
190 |
xsFeature1Element3Type); |
191 |
} |
192 |
} |