Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE / src-test / org / gvsig / gpe / writers / schemas / GPEWriterWithSchemaBaseTest.java @ 12072

History | View | Annotate | Download (3.65 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.schema.exceptions.TypeNotFoundException;
10
import org.gvsig.gpe.schema.som.IXSSchema;
11
import org.gvsig.gpe.schema.utils.DOMObjectsFactory;
12
import org.gvsig.gpe.schema.utils.SchemaDocumentBuilder;
13
import org.gvsig.gpe.writers.GPEWriterBaseTest;
14

    
15
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
16
 *
17
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
18
 *
19
 * This program is free software; you can redistribute it and/or
20
 * modify it under the terms of the GNU General Public License
21
 * as published by the Free Software Foundation; either version 2
22
 * of the License, or (at your option) any later version.
23
 *
24
 * This program is distributed in the hope that it will be useful,
25
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
 * GNU General Public License for more details.
28
 *
29
 * You should have received a copy of the GNU General Public License
30
 * along with this program; if not, write to the Free Software
31
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
32
 *
33
 * For more information, contact:
34
 *
35
 *  Generalitat Valenciana
36
 *   Conselleria d'Infraestructures i Transport
37
 *   Av. Blasco Ib??ez, 50
38
 *   46010 VALENCIA
39
 *   SPAIN
40
 *
41
 *      +34 963862235
42
 *   gvsig@gva.es
43
 *      www.gvsig.gva.es
44
 *
45
 *    or
46
 *
47
 *   IVER T.I. S.A
48
 *   Salamanca 50
49
 *   46005 Valencia
50
 *   Spain
51
 *
52
 *   +34 963163400
53
 *   dac@iver.es
54
 */
55
/* CVS MESSAGES:
56
 *
57
 * $Id: GPEWriterWithSchemaBaseTest.java 12072 2007-06-07 14:55:21Z jorpiell $
58
 * $Log$
59
 * Revision 1.2  2007-06-07 14:55:21  jorpiell
60
 * Add the schema support
61
 *
62
 * Revision 1.1  2007/06/07 14:52:28  jorpiell
63
 * Add the schema support
64
 *
65
 *
66
 */
67
/**
68
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
69
 */
70
public abstract class GPEWriterWithSchemaBaseTest extends GPEWriterBaseTest{
71
        private IXSSchema schema = null;
72
        private String schemafileName = "SCHEMAFILETEMP";
73
        private SchemaDocumentBuilder documentBuilder = null;
74
        private DOMObjectsFactory elementsFactory = null;
75
        private File schemaFile = null;
76
        
77
        /**
78
         * Initialize the schemas factory
79
         */
80
        public void setUp() throws Exception{
81
                documentBuilder = SchemaDocumentBuilder.getInstance();
82
                schema = documentBuilder.createXSSchema(getNamespaceURI());        
83
                elementsFactory = DOMObjectsFactory.getInstance();
84
                super.setUp();
85
        }
86
        
87
        /**
88
         * Delete the schema file
89
         */
90
        public void tearDown() throws Exception{
91
                getSchemaFile().delete();
92
                super.tearDown();
93
        }
94
        
95
        /**
96
         * Writes the schema a parses the file
97
         */
98
        public void testWriter() throws Exception{
99
                writeSchema();
100
                getSchema().write(new FileOutputStream(getSchemaFile()));
101
                GPEDefaults.setProperty(GPEDefaults.XSD_SCHEMA_FILE, getSchemaFile().getAbsolutePath());
102
                getWriterHandler().getSchemaMap().addSchema(
103
                                new URI(getSchemaFile().getAbsolutePath()), 
104
                                getSchema());
105
                super.testWriter();
106
        }
107
        
108
        /**
109
         * Writes the schema
110
         * @throws TypeNotFoundException
111
         */
112
        public abstract void writeSchema() throws TypeNotFoundException;
113
        
114
        /**
115
         * Gets the namespace URI
116
         * @return
117
         */
118
        public String getNamespaceURI(){
119
                return "http://www.gvsig.org/cit";
120
        }
121

    
122
        /**
123
         * @return the schemaFile
124
         * @throws IOException 
125
         */
126
        public File getSchemaFile() throws IOException {
127
                if (schemaFile == null){
128
                        schemaFile = new File(schemafileName + Math.random());                                        
129
                }
130
                return schemaFile;
131
        }
132
        
133
        /**
134
         * @return the elementsFactory
135
         */
136
        public DOMObjectsFactory getElementsFactory() {
137
                return elementsFactory;
138
        }
139

    
140
        /**
141
         * @return the schema
142
         */
143
        public IXSSchema getSchema() {
144
                return schema;
145
        }
146
        
147
        
148
}