root / trunk / libraries / libGPE / src-test / org / gvsig / gpe / writers / schemas / GPEWriterWithSchemaBaseTest.java @ 12439
History | View | Annotate | Download (4.4 KB)
1 |
package org.gvsig.gpe.writers.schemas; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.FileOutputStream; |
5 |
import java.io.IOException; |
6 |
import java.net.URI; |
7 |
|
8 |
import org.gvsig.gpe.GPEDefaults; |
9 |
import org.gvsig.gpe.writers.GPEWriterBaseTest; |
10 |
import org.gvsig.xmlschema.som.IXSSchema; |
11 |
import org.gvsig.xmlschema.utils.DOMObjectsFactory; |
12 |
import org.gvsig.xmlschema.utils.SchemaDocumentBuilder; |
13 |
|
14 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
15 |
*
|
16 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
17 |
*
|
18 |
* This program is free software; you can redistribute it and/or
|
19 |
* modify it under the terms of the GNU General Public License
|
20 |
* as published by the Free Software Foundation; either version 2
|
21 |
* of the License, or (at your option) any later version.
|
22 |
*
|
23 |
* This program is distributed in the hope that it will be useful,
|
24 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
25 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
26 |
* GNU General Public License for more details.
|
27 |
*
|
28 |
* You should have received a copy of the GNU General Public License
|
29 |
* along with this program; if not, write to the Free Software
|
30 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
31 |
*
|
32 |
* For more information, contact:
|
33 |
*
|
34 |
* Generalitat Valenciana
|
35 |
* Conselleria d'Infraestructures i Transport
|
36 |
* Av. Blasco Ib??ez, 50
|
37 |
* 46010 VALENCIA
|
38 |
* SPAIN
|
39 |
*
|
40 |
* +34 963862235
|
41 |
* gvsig@gva.es
|
42 |
* www.gvsig.gva.es
|
43 |
*
|
44 |
* or
|
45 |
*
|
46 |
* IVER T.I. S.A
|
47 |
* Salamanca 50
|
48 |
* 46005 Valencia
|
49 |
* Spain
|
50 |
*
|
51 |
* +34 963163400
|
52 |
* dac@iver.es
|
53 |
*/
|
54 |
/* CVS MESSAGES:
|
55 |
*
|
56 |
* $Id: GPEWriterWithSchemaBaseTest.java 12439 2007-07-02 10:00:46Z jorpiell $
|
57 |
* $Log$
|
58 |
* Revision 1.8 2007-07-02 10:00:46 jorpiell
|
59 |
* The generated xsd schemas have to be valid
|
60 |
*
|
61 |
* Revision 1.7 2007/06/29 12:20:41 jorpiell
|
62 |
* The schema validation is made independently of the concrete writer
|
63 |
*
|
64 |
* Revision 1.6 2007/06/29 12:19:14 jorpiell
|
65 |
* The schema validation is made independently of the concrete writer
|
66 |
*
|
67 |
* Revision 1.5 2007/06/22 12:38:59 jorpiell
|
68 |
* The typeNotFoundException has been deleted. It never was thrown
|
69 |
*
|
70 |
* Revision 1.4 2007/06/22 12:21:18 jorpiell
|
71 |
* The typeNotFoundException has been deleted. It never was thrown
|
72 |
*
|
73 |
* Revision 1.3 2007/06/14 13:50:06 jorpiell
|
74 |
* The schema jar name has been changed
|
75 |
*
|
76 |
* Revision 1.2 2007/06/07 14:55:21 jorpiell
|
77 |
* Add the schema support
|
78 |
*
|
79 |
* Revision 1.1 2007/06/07 14:52:28 jorpiell
|
80 |
* Add the schema support
|
81 |
*
|
82 |
*
|
83 |
*/
|
84 |
/**
|
85 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
86 |
*/
|
87 |
public abstract class GPEWriterWithSchemaBaseTest extends GPEWriterBaseTest{ |
88 |
private IXSSchema schema = null; |
89 |
private String schemafileName = "SCHEMAFILETEMP"; |
90 |
private SchemaDocumentBuilder documentBuilder = null; |
91 |
private DOMObjectsFactory elementsFactory = null; |
92 |
private File schemaFile = null; |
93 |
|
94 |
/**
|
95 |
* Initialize the schemas factory
|
96 |
*/
|
97 |
public void setUp() throws Exception{ |
98 |
documentBuilder = SchemaDocumentBuilder.getInstance(); |
99 |
schema = documentBuilder.createXSSchema(getNamespaceURI(),getNamespacePrefix()); |
100 |
elementsFactory = DOMObjectsFactory.getInstance(); |
101 |
super.setUp();
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* Delete the schema file
|
106 |
*/
|
107 |
public void tearDown() throws Exception{ |
108 |
getSchemaFile().delete(); |
109 |
super.tearDown();
|
110 |
} |
111 |
|
112 |
/**
|
113 |
* Writes the schema a parses the file
|
114 |
*/
|
115 |
public void testWriter() throws Exception{ |
116 |
writeSchema(); |
117 |
getSchema().write(new FileOutputStream(getSchemaFile())); |
118 |
GPEDefaults.setProperty(GPEDefaults.XSD_SCHEMA_FILE, getSchemaFile().getAbsolutePath()); |
119 |
getWriterHandler().getSchemaDocument().addSchema( |
120 |
new URI(getSchemaFile().getAbsolutePath()), |
121 |
getSchema()); |
122 |
getWriterHandler().getSchemaDocument().setTargetNamespace(getNamespaceURI()); |
123 |
super.testWriter();
|
124 |
} |
125 |
|
126 |
/**
|
127 |
* Writes the schema
|
128 |
* @throws TypeNotFoundException
|
129 |
*/
|
130 |
public abstract void writeSchema(); |
131 |
|
132 |
/**
|
133 |
* Gets the namespace URI
|
134 |
* @return
|
135 |
*/
|
136 |
public String getNamespaceURI(){ |
137 |
return "http://www.gvsig.org/cit"; |
138 |
} |
139 |
|
140 |
/**
|
141 |
* Gets the namespace prefix
|
142 |
* @return
|
143 |
*/
|
144 |
public String getNamespacePrefix(){ |
145 |
return "cit"; |
146 |
} |
147 |
|
148 |
/**
|
149 |
* @return the schemaFile
|
150 |
* @throws IOException
|
151 |
*/
|
152 |
public File getSchemaFile() throws IOException { |
153 |
if (schemaFile == null){ |
154 |
schemaFile = new File(schemafileName); |
155 |
} |
156 |
return schemaFile;
|
157 |
} |
158 |
|
159 |
/**
|
160 |
* @return the elementsFactory
|
161 |
*/
|
162 |
public DOMObjectsFactory getElementsFactory() {
|
163 |
return elementsFactory;
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* @return the schema
|
168 |
*/
|
169 |
public IXSSchema getSchema() {
|
170 |
return schema;
|
171 |
} |
172 |
|
173 |
|
174 |
} |