root / trunk / libraries / libGPE / src / org / gvsig / xmlschema / som / impl / XSSchemaDocumentImpl.java @ 12175
History | View | Annotate | Download (7.83 KB)
1 |
package org.gvsig.xmlschema.som.impl; |
---|---|
2 |
|
3 |
import java.io.FileInputStream; |
4 |
import java.net.URI; |
5 |
import java.util.Enumeration; |
6 |
import java.util.Hashtable; |
7 |
|
8 |
import org.gvsig.xmlschema.exceptions.NotDownloadFileException; |
9 |
import org.gvsig.xmlschema.exceptions.SchemaCreationException; |
10 |
import org.gvsig.xmlschema.exceptions.TypeNotFoundException; |
11 |
import org.gvsig.xmlschema.som.IXSElementDeclaration; |
12 |
import org.gvsig.xmlschema.som.IXSSchema; |
13 |
import org.gvsig.xmlschema.som.IXSSchemaDocument; |
14 |
import org.gvsig.xmlschema.utils.SchemaDocumentBuilder; |
15 |
|
16 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
17 |
*
|
18 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
19 |
*
|
20 |
* This program is free software; you can redistribute it and/or
|
21 |
* modify it under the terms of the GNU General Public License
|
22 |
* as published by the Free Software Foundation; either version 2
|
23 |
* of the License, or (at your option) any later version.
|
24 |
*
|
25 |
* This program is distributed in the hope that it will be useful,
|
26 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
27 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
28 |
* GNU General Public License for more details.
|
29 |
*
|
30 |
* You should have received a copy of the GNU General Public License
|
31 |
* along with this program; if not, write to the Free Software
|
32 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
33 |
*
|
34 |
* For more information, contact:
|
35 |
*
|
36 |
* Generalitat Valenciana
|
37 |
* Conselleria d'Infraestructures i Transport
|
38 |
* Av. Blasco Ib??ez, 50
|
39 |
* 46010 VALENCIA
|
40 |
* SPAIN
|
41 |
*
|
42 |
* +34 963862235
|
43 |
* gvsig@gva.es
|
44 |
* www.gvsig.gva.es
|
45 |
*
|
46 |
* or
|
47 |
*
|
48 |
* IVER T.I. S.A
|
49 |
* Salamanca 50
|
50 |
* 46005 Valencia
|
51 |
* Spain
|
52 |
*
|
53 |
* +34 963163400
|
54 |
* dac@iver.es
|
55 |
*/
|
56 |
/* CVS MESSAGES:
|
57 |
*
|
58 |
* $Id: XSSchemaDocumentImpl.java 12175 2007-06-14 16:15:05Z jorpiell $
|
59 |
* $Log$
|
60 |
* Revision 1.1 2007-06-14 16:15:03 jorpiell
|
61 |
* builds to create the jars generated and add the schema code to the libGPEProject
|
62 |
*
|
63 |
* Revision 1.1 2007/06/14 13:50:07 jorpiell
|
64 |
* The schema jar name has been changed
|
65 |
*
|
66 |
* Revision 1.3 2007/06/08 13:00:40 jorpiell
|
67 |
* Add the targetNamespace to the file
|
68 |
*
|
69 |
* Revision 1.2 2007/06/08 11:59:18 jorpiell
|
70 |
* Add the default schema location
|
71 |
*
|
72 |
* Revision 1.1 2007/06/07 14:54:13 jorpiell
|
73 |
* Add the schema support
|
74 |
*
|
75 |
*
|
76 |
*/
|
77 |
/**
|
78 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
79 |
*/
|
80 |
public class XSSchemaDocumentImpl implements IXSSchemaDocument{ |
81 |
private Hashtable schemas = null; |
82 |
private Hashtable prefixes = null; |
83 |
private Hashtable schemaLocations = null; |
84 |
private boolean isElementQualified = false; |
85 |
private String targetNamespace = null; |
86 |
|
87 |
public XSSchemaDocumentImpl(){
|
88 |
schemas = new Hashtable(); |
89 |
prefixes = new Hashtable(); |
90 |
schemaLocations = new Hashtable(); |
91 |
} |
92 |
|
93 |
/*
|
94 |
* (non-Javadoc)
|
95 |
* @see org.gvsig.gpe.schema.som.IXSSchemaMap#addSchema(java.lang.String, org.gvsig.gpe.schema.som.IXSSchema)
|
96 |
*/
|
97 |
public void addSchema(URI uri, IXSSchema schema){ |
98 |
schemas.put(uri, schema); |
99 |
schemaLocations.put(uri, uri.toString()); |
100 |
} |
101 |
|
102 |
/*
|
103 |
* (non-Javadoc)
|
104 |
* @see org.gvsig.gpe.schema.som.IXSSchemaMap#hasSchema(java.lang.String)
|
105 |
*/
|
106 |
public boolean hasSchema(URI uri){ |
107 |
return schemas.get(uri) != null; |
108 |
} |
109 |
|
110 |
/*
|
111 |
* (non-Javadoc)
|
112 |
* @see org.gvsig.gpe.schema.som.IXSSchemaMap#getURIs()
|
113 |
*/
|
114 |
public Enumeration getURIs(){ |
115 |
return schemas.keys();
|
116 |
} |
117 |
|
118 |
/*
|
119 |
* (non-Javadoc)
|
120 |
* @see org.gvsig.gpe.schema.som.IXSSchemaMap#getSchemas()
|
121 |
*/
|
122 |
public Enumeration getSchemas(){ |
123 |
return schemas.elements();
|
124 |
} |
125 |
|
126 |
/*
|
127 |
* (non-Javadoc)
|
128 |
* @see org.gvsig.gpe.schema.som.IXSSchemaMap#getSchema(java.lang.String)
|
129 |
*/
|
130 |
public IXSSchema getSchema(URI uri){ |
131 |
return (IXSSchema)schemas.get(uri);
|
132 |
} |
133 |
|
134 |
/*
|
135 |
* (non-Javadoc)
|
136 |
* @see org.gvsig.gpe.schema.som.IXSSchemaMap#remove(java.lang.String)
|
137 |
*/
|
138 |
public void remove(URI uri){ |
139 |
schemas.remove(uri); |
140 |
} |
141 |
|
142 |
/*
|
143 |
* (non-Javadoc)
|
144 |
* @see org.gvsig.gpe.schema.som.IXSSchemaMap#addNamespacePrefix(java.lang.String, java.lang.String)
|
145 |
*/
|
146 |
public void addNamespacePrefix(String prefix, String namespaceURI) { |
147 |
prefixes.put(prefix, namespaceURI); |
148 |
} |
149 |
|
150 |
/*
|
151 |
* (non-Javadoc)
|
152 |
* @see org.gvsig.gpe.schema.som.IXSSchemaMap#getNamespaceURI(java.lang.String)
|
153 |
*/
|
154 |
public String getNamespaceURI(String prefix) { |
155 |
if (prefixes.get(prefix) != null){ |
156 |
return (String)prefixes.get(prefix); |
157 |
} |
158 |
return null; |
159 |
} |
160 |
|
161 |
/*
|
162 |
* (non-Javadoc)
|
163 |
* @see org.gvsig.gpe.schema.som.IXSSchemaMap#addSchema(java.lang.String)
|
164 |
*/
|
165 |
public void addSchema(URI uri) throws SchemaCreationException{ |
166 |
try {
|
167 |
IXSSchema schema = SchemaDocumentBuilder.getInstance().parse(new FileInputStream(uri.getPath())); |
168 |
addSchema(uri, schema); |
169 |
} catch (Exception e){ |
170 |
throw new SchemaCreationException(new NotDownloadFileException(e)); |
171 |
} |
172 |
} |
173 |
|
174 |
/*
|
175 |
* (non-Javadoc)
|
176 |
* @see org.gvsig.gpe.schema.som.IXSSchemaMap#getElementDeclarationByName(java.lang.String, java.lang.String)
|
177 |
*/
|
178 |
public IXSElementDeclaration getElementDeclarationByName(String namespacePrefix, String elementName) throws TypeNotFoundException { |
179 |
Enumeration it = getSchemas();
|
180 |
String namespaceURI = null; |
181 |
if (namespacePrefix != null){ |
182 |
namespaceURI = getNamespaceURI(namespacePrefix); |
183 |
} |
184 |
if (namespaceURI == null){ |
185 |
namespaceURI = getTargetNamespace(); |
186 |
} |
187 |
while (it.hasMoreElements()){
|
188 |
IXSSchema schema = (IXSSchema)it.nextElement(); |
189 |
if (schema.getTargetNamespace().compareTo(namespaceURI) == 0){ |
190 |
return schema.getElementDeclarationByName(namespaceURI, elementName);
|
191 |
} |
192 |
} |
193 |
return null; |
194 |
} |
195 |
|
196 |
/*
|
197 |
* (non-Javadoc)
|
198 |
* @see org.gvsig.gpe.schema.som.IXSSchemaMap#getElementDeclarationByName(java.lang.String)
|
199 |
*/
|
200 |
public IXSElementDeclaration getElementDeclarationByName(String elementName) |
201 |
throws TypeNotFoundException {
|
202 |
int index = elementName.indexOf(":"); |
203 |
//If is a qualified name
|
204 |
if (index == -1){ |
205 |
return getElementDeclarationByName(
|
206 |
null,
|
207 |
elementName); |
208 |
}else{
|
209 |
String prefix = elementName.substring(0, index); |
210 |
return getElementDeclarationByName(
|
211 |
prefix, |
212 |
elementName.substring(index + 1,elementName.length()));
|
213 |
} |
214 |
} |
215 |
|
216 |
/*
|
217 |
* (non-Javadoc)
|
218 |
* @see org.gvsig.gpe.schema.som.IXSSchemaMap#isElementQualified()
|
219 |
*/
|
220 |
public boolean isElementFormDefault() { |
221 |
return isElementQualified;
|
222 |
} |
223 |
|
224 |
/*
|
225 |
* (non-Javadoc)
|
226 |
* @see org.gvsig.gpe.schema.som.IXSSchemaMap#setElementQualified(boolean)
|
227 |
*/
|
228 |
public void setElementFormDefault(boolean isElementQualified) { |
229 |
this.isElementQualified = isElementQualified;
|
230 |
} |
231 |
|
232 |
/*
|
233 |
* (non-Javadoc)
|
234 |
* @see org.gvsig.gpe.schema.som.IXSSchemaDocument#addSchemaLocation(java.net.URI, java.lang.String)
|
235 |
*/
|
236 |
public void addSchemaLocation(URI uri, String schemaLocation) { |
237 |
schemaLocations.put(uri, schemaLocation); |
238 |
} |
239 |
|
240 |
/*
|
241 |
* (non-Javadoc)
|
242 |
* @see org.gvsig.gpe.schema.som.IXSSchemaDocument#getSchemaLocation(java.net.URI)
|
243 |
*/
|
244 |
public String getSchemaLocation(URI uri) { |
245 |
Object obj = schemaLocations.get(uri);
|
246 |
if (obj != null){ |
247 |
return (String)obj; |
248 |
} |
249 |
return null; |
250 |
} |
251 |
|
252 |
/*
|
253 |
* (non-Javadoc)
|
254 |
* @see org.gvsig.gpe.schema.som.IXSSchemaDocument#hasSchemaLocation(java.net.URI)
|
255 |
*/
|
256 |
public boolean hasSchemaLocation(URI uri) { |
257 |
return (schemaLocations.get(uri) != null); |
258 |
} |
259 |
|
260 |
/*
|
261 |
* (non-Javadoc)
|
262 |
* @see org.gvsig.gpe.schema.som.IXSSchemaDocument#getTargetNamespace()
|
263 |
*/
|
264 |
public String getTargetNamespace() { |
265 |
return targetNamespace;
|
266 |
} |
267 |
|
268 |
/*
|
269 |
* (non-Javadoc)
|
270 |
* @see org.gvsig.gpe.schema.som.IXSSchemaDocument#setTargetNamespace(java.lang.String)
|
271 |
*/
|
272 |
public void setTargetNamespace(String targetNamespace) { |
273 |
this.targetNamespace = targetNamespace;
|
274 |
} |
275 |
|
276 |
/*
|
277 |
* (non-Javadoc)
|
278 |
* @see org.gvsig.gpe.schema.som.IXSSchemaDocument#hasSchemas()
|
279 |
*/
|
280 |
public boolean hasSchemas() { |
281 |
return (schemas.size() > 0); |
282 |
} |
283 |
|
284 |
/*
|
285 |
* (non-Javadoc)
|
286 |
* @see org.gvsig.gpe.schema.som.IXSSchemaDocument#getPrefixes()
|
287 |
*/
|
288 |
public Enumeration getPrefixes() { |
289 |
return prefixes.elements();
|
290 |
} |
291 |
|
292 |
/*
|
293 |
* (non-Javadoc)
|
294 |
* @see org.gvsig.gpe.schema.som.IXSSchemaDocument#hasPrefixes()
|
295 |
*/
|
296 |
public boolean hasPrefixes() { |
297 |
return (prefixes.size() > 0); |
298 |
} |
299 |
|
300 |
} |
301 |
|