root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / writers / gml / GMLSchemaCreator.java @ 6484
History | View | Annotate | Download (6.06 KB)
1 |
package com.iver.cit.gvsig.fmap.edition.writers.gml; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.FileWriter; |
5 |
import java.io.IOException; |
6 |
import java.io.Writer; |
7 |
|
8 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
9 |
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
10 |
import com.iver.cit.gvsig.fmap.drivers.gml.GMLTypesConversor; |
11 |
|
12 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
13 |
*
|
14 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
15 |
*
|
16 |
* This program is free software; you can redistribute it and/or
|
17 |
* modify it under the terms of the GNU General Public License
|
18 |
* as published by the Free Software Foundation; either version 2
|
19 |
* of the License, or (at your option) any later version.
|
20 |
*
|
21 |
* This program is distributed in the hope that it will be useful,
|
22 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
23 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
24 |
* GNU General Public License for more details.
|
25 |
*
|
26 |
* You should have received a copy of the GNU General Public License
|
27 |
* along with this program; if not, write to the Free Software
|
28 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
29 |
*
|
30 |
* For more information, contact:
|
31 |
*
|
32 |
* Generalitat Valenciana
|
33 |
* Conselleria d'Infraestructures i Transport
|
34 |
* Av. Blasco Ib??ez, 50
|
35 |
* 46010 VALENCIA
|
36 |
* SPAIN
|
37 |
*
|
38 |
* +34 963862235
|
39 |
* gvsig@gva.es
|
40 |
* www.gvsig.gva.es
|
41 |
*
|
42 |
* or
|
43 |
*
|
44 |
* IVER T.I. S.A
|
45 |
* Salamanca 50
|
46 |
* 46005 Valencia
|
47 |
* Spain
|
48 |
*
|
49 |
* +34 963163400
|
50 |
* dac@iver.es
|
51 |
*/
|
52 |
/* CVS MESSAGES:
|
53 |
*
|
54 |
* $Id: GMLSchemaCreator.java 6484 2006-07-21 08:56:59Z jorpiell $
|
55 |
* $Log$
|
56 |
* Revision 1.2 2006-07-21 08:56:59 jorpiell
|
57 |
* Se ha modificado la versi?n del esquema
|
58 |
*
|
59 |
* Revision 1.1 2006/07/19 12:29:39 jorpiell
|
60 |
* A?adido el driver de GML
|
61 |
*
|
62 |
*
|
63 |
*/
|
64 |
/**
|
65 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
66 |
*/
|
67 |
public class GMLSchemaCreator { |
68 |
public final static String GML_SUBSTITUTION_GROUP = "gml:_Feature"; |
69 |
public final static String GML_GEOMETRY = "the_geom"; |
70 |
public final static String NAMESPACE = "cit"; |
71 |
public final static String TARGET_NAMESPACE = "http://www.gvsig.com/cit"; |
72 |
public final static String GML_VERSION = "2.1.2"; |
73 |
|
74 |
private static String featureName = null; |
75 |
private static String featureType = null; |
76 |
|
77 |
private Writer writer = null; |
78 |
|
79 |
|
80 |
public GMLSchemaCreator(File m_File) throws IOException { |
81 |
super();
|
82 |
writer = new FileWriter(m_File); |
83 |
featureName = m_File.getName().replaceAll("\\.xsd",""); |
84 |
featureType = featureName + "_Type";
|
85 |
|
86 |
} |
87 |
|
88 |
public void createFile(LayerDefinition lyrDef) throws IOException{ |
89 |
writer.write(getInitFile()); |
90 |
writer.write(getInitComplexTypes()); |
91 |
|
92 |
writer.write(getAttribute(GML_GEOMETRY, |
93 |
GMLTypesConversor.gvSIGToSchemaShapeTypesConversion(lyrDef.getShapeType()))); |
94 |
FieldDescription[] fieldDescription = lyrDef.getFieldsDesc();
|
95 |
for (int i=0 ; i<fieldDescription.length ; i++){ |
96 |
writer.write(getAttribute(fieldDescription[i])); |
97 |
} |
98 |
|
99 |
writer.write(getEndComplexTypes()); |
100 |
writer.write(getEndFile()); |
101 |
} |
102 |
|
103 |
/**
|
104 |
* Writes the schema file
|
105 |
* @throws IOException
|
106 |
*
|
107 |
*/
|
108 |
public void writeFile() throws IOException { |
109 |
writer.close(); |
110 |
} |
111 |
|
112 |
/**
|
113 |
* Creates the schema header File
|
114 |
* @return
|
115 |
*/
|
116 |
private String getInitFile(){ |
117 |
StringBuffer string = new StringBuffer(); |
118 |
string.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
|
119 |
string.append("<xs:schema targetNamespace=\"" + TARGET_NAMESPACE + "\" "); |
120 |
string.append("xmlns:" + NAMESPACE + "=\"" + TARGET_NAMESPACE + "\" "); |
121 |
string.append("xmlns:gml=\"http://www.opengis.net/gml\" ");
|
122 |
string.append("xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" ");
|
123 |
string.append("elementFormDefault=\"qualified\" ");
|
124 |
string.append("attributeFormDefault=\"unqualified\" version=\"" + GML_VERSION + "\">"); |
125 |
string.append("<xs:import namespace=\"http://www.opengis.net/gml\" ");
|
126 |
string.append("schemaLocation=\"feature.xsd\"/");
|
127 |
string.append(">");
|
128 |
return string.toString();
|
129 |
} |
130 |
|
131 |
|
132 |
/**
|
133 |
* Creates the GML File last line
|
134 |
* @return
|
135 |
*/
|
136 |
private String getEndFile(){ |
137 |
StringBuffer string = new StringBuffer(); |
138 |
string.append("</xs:schema>");
|
139 |
return string.toString();
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* Creates the complex types header
|
144 |
* @return
|
145 |
*/
|
146 |
private String getInitComplexTypes(){ |
147 |
StringBuffer string = new StringBuffer(); |
148 |
string.append("<xs:complexType xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" ");
|
149 |
string.append("name=\"" + getFeatureType() + "\">"); |
150 |
string.append("<xs:complexContent>");
|
151 |
string.append("<xs:extension base=\"gml:AbstractFeatureType\">");
|
152 |
string.append("<xs:sequence>");
|
153 |
return string.toString();
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* Creates the complex types end tag
|
158 |
* @return
|
159 |
*/
|
160 |
private String getEndComplexTypes(){ |
161 |
StringBuffer string = new StringBuffer(); |
162 |
string.append("</xs:sequence>");
|
163 |
string.append("</xs:extension>");
|
164 |
string.append("</xs:complexContent>");
|
165 |
string.append("</xs:complexType>");
|
166 |
string.append("<xs:element name=\"" + getFeatureName() + "\" "); |
167 |
string.append("type=\"" + NAMESPACE + ":" + getFeatureType() + "\" "); |
168 |
string.append("substitutionGroup=\"" + GML_SUBSTITUTION_GROUP + "\"/>"); |
169 |
return string.toString();
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* Creates the attribute description
|
174 |
* @param fieldDescription
|
175 |
* @return
|
176 |
*/
|
177 |
private String getAttribute(FieldDescription fieldDescription){ |
178 |
return getAttribute(fieldDescription.getFieldName(),
|
179 |
GMLTypesConversor.gvSIGToSchemaTypesConversion(fieldDescription.getFieldType())); |
180 |
} |
181 |
|
182 |
/**
|
183 |
* Creates the attribute description
|
184 |
* @param attributeName
|
185 |
* Attribute name
|
186 |
* @param attributeType
|
187 |
* Attribute Type
|
188 |
* @return
|
189 |
*/
|
190 |
private String getAttribute(String attributeName, String attributeType){ |
191 |
StringBuffer string = new StringBuffer(); |
192 |
string.append("<xs:element name=\"" + attributeName + "\" "); |
193 |
string.append("minOccurs=\"0\" ");
|
194 |
string.append("nillable=\"true\" ");
|
195 |
string.append("type=\"" + attributeType + "\"/>"); |
196 |
return string.toString();
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* @return Returns the featureName.
|
201 |
*/
|
202 |
public static String getFeatureName() { |
203 |
return featureName;
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* @return Returns the featureType.
|
208 |
*/
|
209 |
public static String getFeatureType() { |
210 |
return featureType;
|
211 |
} |
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
} |