svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extWFS2 / src / org / gvsig / fmap / dal / store / wfs / WFSFeatureFiller.java @ 34026
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.slf4j.Logger; |
30 |
import org.slf4j.LoggerFactory; |
31 |
|
32 |
import org.gvsig.remoteclient.wfs.WFSFeature; |
33 |
import org.gvsig.tools.dataTypes.DataType; |
34 |
import org.gvsig.xmlschema.lib.api.XMLSchemaLocator; |
35 |
import org.gvsig.xmlschema.lib.api.XMLSchemaManager; |
36 |
import org.gvsig.xmlschema.lib.api.exceptions.SchemaCreationException; |
37 |
import org.gvsig.xmlschema.lib.api.som.IXSComplexContent; |
38 |
import org.gvsig.xmlschema.lib.api.som.IXSComplexTypeDefinition; |
39 |
import org.gvsig.xmlschema.lib.api.som.IXSContentType; |
40 |
import org.gvsig.xmlschema.lib.api.som.IXSElementDeclaration; |
41 |
import org.gvsig.xmlschema.lib.api.som.IXSExtension; |
42 |
import org.gvsig.xmlschema.lib.api.som.IXSGroup; |
43 |
import org.gvsig.xmlschema.lib.api.som.IXSRestriction; |
44 |
import org.gvsig.xmlschema.lib.api.som.IXSSchema; |
45 |
import org.gvsig.xmlschema.lib.api.som.IXSSimpleContent; |
46 |
import org.gvsig.xmlschema.lib.api.som.IXSSimpleTypeDefinition; |
47 |
import org.gvsig.xmlschema.lib.api.som.IXSTypeDefinition; |
48 |
|
49 |
|
50 |
/**
|
51 |
* @author gvSIG Team
|
52 |
* @version $Id$
|
53 |
*
|
54 |
*/
|
55 |
public class WFSFeatureFiller { |
56 |
private static final Logger LOG = LoggerFactory.getLogger(WFSFeatureFiller.class); |
57 |
private XMLSchemaManager xmlSchemaManager = null; |
58 |
private static final String XMLSCHEMA_PARSER_PROVIDER_NAME = "xmlschema.providers.kxml"; |
59 |
private WFSFeature feature;
|
60 |
|
61 |
public WFSFeatureFiller(WFSFeature feature) {
|
62 |
super();
|
63 |
xmlSchemaManager = XMLSchemaLocator.getXMLSchemaManager(); |
64 |
this.feature = feature;
|
65 |
} |
66 |
|
67 |
/**
|
68 |
* @param describeFeatureTypeFile
|
69 |
* @param feature
|
70 |
* @throws FileNotFoundException
|
71 |
* @throws SchemaCreationException
|
72 |
*/
|
73 |
public void fill(File describeFeatureTypeFile) throws SchemaCreationException, FileNotFoundException { |
74 |
IXSSchema schema = xmlSchemaManager.parse(XMLSCHEMA_PARSER_PROVIDER_NAME, new FileInputStream(describeFeatureTypeFile)); |
75 |
IXSElementDeclaration elementDeclaration = null;
|
76 |
if (feature.getNamespace() == null){ |
77 |
elementDeclaration = schema.getElementDeclarationByName(null, feature.getName());
|
78 |
}else{
|
79 |
elementDeclaration = schema.getElementDeclarationByName(feature.getNamespace().getLocation(), feature.getLocalName()); |
80 |
} |
81 |
if (elementDeclaration == null){ |
82 |
return;
|
83 |
} |
84 |
IXSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition(); |
85 |
if (typeDefinition == null){ |
86 |
return;
|
87 |
} |
88 |
if (typeDefinition instanceof IXSSimpleTypeDefinition){ |
89 |
|
90 |
}else if (typeDefinition instanceof IXSComplexTypeDefinition){ |
91 |
fill((IXSComplexTypeDefinition)typeDefinition); |
92 |
} |
93 |
feature.setCompleted(true);
|
94 |
} |
95 |
|
96 |
/**
|
97 |
* @param typeDefinition
|
98 |
*/
|
99 |
private void fill(IXSComplexTypeDefinition complexTypeDefinition) { |
100 |
IXSContentType contentType = complexTypeDefinition.getContentType(); |
101 |
if (contentType != null){ |
102 |
fill((IXSContentType)contentType); |
103 |
} |
104 |
IXSGroup group = complexTypeDefinition.getGroup(); |
105 |
if (group != null){ |
106 |
fill((IXSGroup)contentType); |
107 |
} |
108 |
} |
109 |
|
110 |
/**
|
111 |
* @param complexTypeDefinition
|
112 |
*/
|
113 |
private void fill(IXSGroup group) { |
114 |
Iterator it = group.getItems().iterator();
|
115 |
while (it.hasNext()){
|
116 |
Object item = it.next();
|
117 |
if (item instanceof IXSElementDeclaration){ |
118 |
IXSElementDeclaration elementDeclaration = (IXSElementDeclaration)item; |
119 |
DataType dataType = null;
|
120 |
if (elementDeclaration.getTypeDefinition() != null){ |
121 |
dataType = elementDeclaration.getTypeDefinition().getDataType(); |
122 |
} |
123 |
feature.addField(elementDeclaration.getNodeName(), elementDeclaration.getTypeName(), dataType); |
124 |
}else {
|
125 |
LOG.warn("Feature attribute not recognized");
|
126 |
} |
127 |
} |
128 |
} |
129 |
|
130 |
/**
|
131 |
* @param complexTypeDefinition
|
132 |
*/
|
133 |
private void fill(IXSContentType contentType) { |
134 |
if (contentType instanceof IXSSimpleContent){ |
135 |
fill((IXSSimpleContent)contentType); |
136 |
}else if (contentType instanceof IXSComplexContent){ |
137 |
fill((IXSComplexContent)contentType); |
138 |
}else if (contentType instanceof IXSGroup){ |
139 |
fill((IXSGroup)contentType); |
140 |
} |
141 |
} |
142 |
|
143 |
private void fill(IXSSimpleContent simpleContent) { |
144 |
IXSRestriction restriction = simpleContent.getRestriction(); |
145 |
if (restriction != null){ |
146 |
fill(restriction); |
147 |
} |
148 |
IXSExtension extension = simpleContent.getExtension(); |
149 |
if (extension != null){ |
150 |
fill(extension); |
151 |
} |
152 |
} |
153 |
|
154 |
private void fill(IXSComplexContent complexContent) { |
155 |
IXSRestriction restriction = complexContent.getRestriction(); |
156 |
if (restriction != null){ |
157 |
fill(restriction); |
158 |
} |
159 |
IXSExtension extension = complexContent.getExtension(); |
160 |
if (extension != null){ |
161 |
fill(extension); |
162 |
} |
163 |
} |
164 |
|
165 |
/**
|
166 |
* @param extension
|
167 |
*/
|
168 |
private void fill(IXSExtension extension) { |
169 |
IXSGroup group = extension.getGroup(); |
170 |
if (group != null){ |
171 |
fill(group); |
172 |
} |
173 |
} |
174 |
|
175 |
/**
|
176 |
* @param restriction
|
177 |
*/
|
178 |
private void fill(IXSRestriction restriction) { |
179 |
IXSGroup group = restriction.getGroup(); |
180 |
if (group != null){ |
181 |
fill(group); |
182 |
} |
183 |
} |
184 |
} |