root / tags / v2_0_0_Build_2052 / extensions / extWFS2 / src / org / gvsig / fmap / dal / store / wfs / WFSFeatureFiller.java @ 38828
History | View | Annotate | Download (6.45 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.fmap.dal.store.wfs; |
23 |
|
24 |
import java.io.File; |
25 |
import java.io.FileInputStream; |
26 |
import java.io.FileNotFoundException; |
27 |
import java.util.Iterator; |
28 |
|
29 |
import org.gvsig.remoteclient.wfs.WFSFeature; |
30 |
import org.gvsig.tools.dataTypes.DataType; |
31 |
import org.gvsig.xmlschema.lib.api.XMLSchemaLocator; |
32 |
import org.gvsig.xmlschema.lib.api.XMLSchemaManager; |
33 |
import org.gvsig.xmlschema.lib.api.exceptions.SchemaCreationException; |
34 |
import org.gvsig.xmlschema.lib.api.som.IXSComplexContent; |
35 |
import org.gvsig.xmlschema.lib.api.som.IXSComplexTypeDefinition; |
36 |
import org.gvsig.xmlschema.lib.api.som.IXSContentType; |
37 |
import org.gvsig.xmlschema.lib.api.som.IXSElementDeclaration; |
38 |
import org.gvsig.xmlschema.lib.api.som.IXSExtension; |
39 |
import org.gvsig.xmlschema.lib.api.som.IXSGroup; |
40 |
import org.gvsig.xmlschema.lib.api.som.IXSRestriction; |
41 |
import org.gvsig.xmlschema.lib.api.som.IXSSchema; |
42 |
import org.gvsig.xmlschema.lib.api.som.IXSSimpleContent; |
43 |
import org.gvsig.xmlschema.lib.api.som.IXSSimpleTypeDefinition; |
44 |
import org.gvsig.xmlschema.lib.api.som.IXSTypeDefinition; |
45 |
import org.slf4j.Logger; |
46 |
import org.slf4j.LoggerFactory; |
47 |
|
48 |
|
49 |
/**
|
50 |
* @author gvSIG Team
|
51 |
* @version $Id$
|
52 |
*
|
53 |
*/
|
54 |
public class WFSFeatureFiller { |
55 |
private static final Logger LOG = LoggerFactory.getLogger(WFSFeatureFiller.class); |
56 |
private XMLSchemaManager xmlSchemaManager = null; |
57 |
private static final String XMLSCHEMA_PARSER_PROVIDER_NAME = "xmlschema.providers.kxml"; |
58 |
private WFSFeature feature;
|
59 |
|
60 |
public WFSFeatureFiller(WFSFeature feature) {
|
61 |
super();
|
62 |
xmlSchemaManager = XMLSchemaLocator.getXMLSchemaManager(); |
63 |
this.feature = feature;
|
64 |
} |
65 |
|
66 |
/**
|
67 |
* @param describeFeatureTypeFile
|
68 |
* @param feature
|
69 |
* @throws FileNotFoundException
|
70 |
* @throws SchemaCreationException
|
71 |
*/
|
72 |
public void fill(File describeFeatureTypeFile) throws SchemaCreationException, FileNotFoundException { |
73 |
IXSSchema schema = xmlSchemaManager.parse(XMLSCHEMA_PARSER_PROVIDER_NAME, new FileInputStream(describeFeatureTypeFile)); |
74 |
IXSElementDeclaration elementDeclaration = null;
|
75 |
if (feature.getNamespace() == null){ |
76 |
elementDeclaration = schema.getElementDeclarationByName(null, feature.getName());
|
77 |
}else{
|
78 |
elementDeclaration = schema.getElementDeclarationByName(feature.getNamespace().getLocation(), feature.getLocalName()); |
79 |
} |
80 |
if (elementDeclaration == null){ |
81 |
return;
|
82 |
} |
83 |
IXSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition(); |
84 |
if (typeDefinition == null){ |
85 |
return;
|
86 |
} |
87 |
if (typeDefinition instanceof IXSSimpleTypeDefinition){ |
88 |
|
89 |
}else if (typeDefinition instanceof IXSComplexTypeDefinition){ |
90 |
fill((IXSComplexTypeDefinition)typeDefinition); |
91 |
} |
92 |
feature.setCompleted(true);
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* @param typeDefinition
|
97 |
*/
|
98 |
private void fill(IXSComplexTypeDefinition complexTypeDefinition) { |
99 |
IXSContentType contentType = complexTypeDefinition.getContentType(); |
100 |
if (contentType != null){ |
101 |
fill((IXSContentType)contentType); |
102 |
} |
103 |
IXSGroup group = complexTypeDefinition.getGroup(); |
104 |
if (group != null){ |
105 |
fill((IXSGroup)contentType); |
106 |
} |
107 |
} |
108 |
|
109 |
/**
|
110 |
* @param complexTypeDefinition
|
111 |
*/
|
112 |
private void fill(IXSGroup group) { |
113 |
Iterator it = group.getItems().iterator();
|
114 |
while (it.hasNext()){
|
115 |
Object item = it.next();
|
116 |
if (item instanceof IXSElementDeclaration){ |
117 |
IXSElementDeclaration elementDeclaration = (IXSElementDeclaration)item; |
118 |
DataType dataType = null;
|
119 |
if (elementDeclaration.getTypeDefinition() != null){ |
120 |
dataType = elementDeclaration.getTypeDefinition().getDataType(); |
121 |
} |
122 |
feature.addField(elementDeclaration.getNodeName(), elementDeclaration.getTypeName(), dataType); |
123 |
}else {
|
124 |
LOG.warn("Feature attribute not recognized");
|
125 |
} |
126 |
} |
127 |
} |
128 |
|
129 |
/**
|
130 |
* @param complexTypeDefinition
|
131 |
*/
|
132 |
private void fill(IXSContentType contentType) { |
133 |
if (contentType instanceof IXSSimpleContent){ |
134 |
fill((IXSSimpleContent)contentType); |
135 |
}else if (contentType instanceof IXSComplexContent){ |
136 |
fill((IXSComplexContent)contentType); |
137 |
}else if (contentType instanceof IXSGroup){ |
138 |
fill((IXSGroup)contentType); |
139 |
} |
140 |
} |
141 |
|
142 |
private void fill(IXSSimpleContent simpleContent) { |
143 |
IXSRestriction restriction = simpleContent.getRestriction(); |
144 |
if (restriction != null){ |
145 |
fill(restriction); |
146 |
} |
147 |
IXSExtension extension = simpleContent.getExtension(); |
148 |
if (extension != null){ |
149 |
fill(extension); |
150 |
} |
151 |
} |
152 |
|
153 |
private void fill(IXSComplexContent complexContent) { |
154 |
IXSRestriction restriction = complexContent.getRestriction(); |
155 |
if (restriction != null){ |
156 |
fill(restriction); |
157 |
} |
158 |
IXSExtension extension = complexContent.getExtension(); |
159 |
if (extension != null){ |
160 |
fill(extension); |
161 |
} |
162 |
} |
163 |
|
164 |
/**
|
165 |
* @param extension
|
166 |
*/
|
167 |
private void fill(IXSExtension extension) { |
168 |
IXSGroup group = extension.getGroup(); |
169 |
if (group != null){ |
170 |
fill(group); |
171 |
} |
172 |
} |
173 |
|
174 |
/**
|
175 |
* @param restriction
|
176 |
*/
|
177 |
private void fill(IXSRestriction restriction) { |
178 |
IXSGroup group = restriction.getGroup(); |
179 |
if (group != null){ |
180 |
fill(group); |
181 |
} |
182 |
} |
183 |
} |