root / trunk / libraries / libGPE / src-test / org / gvsig / gpe / writers / schemas / GPEWriterWithSchemaBaseTest.java @ 12418
History | View | Annotate | Download (4.17 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 12418 2007-06-29 12:19:48Z jorpiell $
|
57 |
* $Log$
|
58 |
* Revision 1.6 2007-06-29 12:19:14 jorpiell
|
59 |
* The schema validation is made independently of the concrete writer
|
60 |
*
|
61 |
* Revision 1.5 2007/06/22 12:38:59 jorpiell
|
62 |
* The typeNotFoundException has been deleted. It never was thrown
|
63 |
*
|
64 |
* Revision 1.4 2007/06/22 12:21:18 jorpiell
|
65 |
* The typeNotFoundException has been deleted. It never was thrown
|
66 |
*
|
67 |
* Revision 1.3 2007/06/14 13:50:06 jorpiell
|
68 |
* The schema jar name has been changed
|
69 |
*
|
70 |
* Revision 1.2 2007/06/07 14:55:21 jorpiell
|
71 |
* Add the schema support
|
72 |
*
|
73 |
* Revision 1.1 2007/06/07 14:52:28 jorpiell
|
74 |
* Add the schema support
|
75 |
*
|
76 |
*
|
77 |
*/
|
78 |
/**
|
79 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
80 |
*/
|
81 |
public abstract class GPEWriterWithSchemaBaseTest extends GPEWriterBaseTest{ |
82 |
private IXSSchema schema = null; |
83 |
private String schemafileName = "SCHEMAFILETEMP"; |
84 |
private SchemaDocumentBuilder documentBuilder = null; |
85 |
private DOMObjectsFactory elementsFactory = null; |
86 |
private File schemaFile = null; |
87 |
|
88 |
/**
|
89 |
* Initialize the schemas factory
|
90 |
*/
|
91 |
public void setUp() throws Exception{ |
92 |
documentBuilder = SchemaDocumentBuilder.getInstance(); |
93 |
schema = documentBuilder.createXSSchema(getNamespaceURI()); |
94 |
elementsFactory = DOMObjectsFactory.getInstance(); |
95 |
super.setUp();
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* Delete the schema file
|
100 |
*/
|
101 |
public void tearDown() throws Exception{ |
102 |
// getSchemaFile().delete();
|
103 |
// super.tearDown();
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* Writes the schema a parses the file
|
108 |
*/
|
109 |
public void testWriter() throws Exception{ |
110 |
writeSchema(); |
111 |
getSchema().write(new FileOutputStream(getSchemaFile())); |
112 |
GPEDefaults.setProperty(GPEDefaults.XSD_SCHEMA_FILE, getSchemaFile().getAbsolutePath()); |
113 |
getWriterHandler().getSchemaDocument().addSchema( |
114 |
new URI(getSchemaFile().getAbsolutePath()), |
115 |
getSchema()); |
116 |
getWriterHandler().getSchemaDocument().setTargetNamespace(getNamespaceURI()); |
117 |
super.testWriter();
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* Writes the schema
|
122 |
* @throws TypeNotFoundException
|
123 |
*/
|
124 |
public abstract void writeSchema(); |
125 |
|
126 |
/**
|
127 |
* Gets the namespace URI
|
128 |
* @return
|
129 |
*/
|
130 |
public String getNamespaceURI(){ |
131 |
return "http://www.gvsig.org/cit"; |
132 |
} |
133 |
|
134 |
/**
|
135 |
* Gets the namespace prefix
|
136 |
* @return
|
137 |
*/
|
138 |
public String getNamespacePrefix(){ |
139 |
return "cit"; |
140 |
} |
141 |
|
142 |
/**
|
143 |
* @return the schemaFile
|
144 |
* @throws IOException
|
145 |
*/
|
146 |
public File getSchemaFile() throws IOException { |
147 |
if (schemaFile == null){ |
148 |
schemaFile = new File(schemafileName); |
149 |
} |
150 |
return schemaFile;
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* @return the elementsFactory
|
155 |
*/
|
156 |
public DOMObjectsFactory getElementsFactory() {
|
157 |
return elementsFactory;
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* @return the schema
|
162 |
*/
|
163 |
public IXSSchema getSchema() {
|
164 |
return schema;
|
165 |
} |
166 |
|
167 |
|
168 |
} |