Revision 28113

View differences:

branches/v2_0_0_prep/extensions/extGPE-gvSIG/src-test/org/gvsig/fmap/dal/store/gpe/GPETest.java
1 1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22 22

  
23 23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28 28
package org.gvsig.fmap.dal.store.gpe;
29 29

  
30 30
import java.io.File;
31 31

  
32
import org.gvsig.compat.se.SECompatLibrary;
32 33
import org.gvsig.fmap.dal.DALFileLibrary;
33 34
import org.gvsig.fmap.dal.DataStoreParameters;
34 35
import org.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.feature.BaseTestFeatureStore;
36
import org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore;
37
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
38
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
36 39
import org.gvsig.fmap.geom.impl.DefaultGeometryLibrary;
37
import org.gvsig.gpe.GPERegister;
40
import org.gvsig.gpe.GPELocator;
41
import org.gvsig.gpe.GPEManager;
42
import org.gvsig.gpe.gml.impl.DefaultGmlLibrary;
43
import org.gvsig.gpe.impl.DefaultGPELibrary;
44
import org.gvsig.gpe.kml.impl.DefaultKmlLibrary;
38 45

  
39 46
/**
40 47
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
41 48
 */
42
public class GPETest extends BaseTestFeatureStore {
43
	public static final File file_prueba = new File("testdata/GML-points.gml"); // FIXME
44
	private String parsersFile = "config" + File.separatorChar + "parser.properties";
45
	
49
public class GPETest extends BaseTestEditableFeatureStore {
50
	public static final File file_prueba = new File("testdata/GML-points.gml"); 
51
	//public static final File dbf_prueba_destino= new File(GPETest.class.getResource("data").getFile()+"/testTemp.gpe");
52
		
53
	private FilesystemServerExplorer myExplorer = null;
54
	private GPEManager gpeManager = GPELocator.getGPEManager();
55

  
46 56
	protected void setUp() throws Exception {
47
		super.setUp();
48
			
49
		GPERegister.addParsersFile(new File(parsersFile));
50
		
57
		super.setUp();		
58

  
51 59
		DALFileLibrary libFile = new DALFileLibrary();
52 60
		libFile.initialize();
53 61
		libFile.postInitialize();
......
55 63
		DefaultGeometryLibrary geoLib = new DefaultGeometryLibrary();
56 64
		geoLib.initialize();
57 65
		geoLib.postInitialize();
66

  
67
		SECompatLibrary compatLibrary = new SECompatLibrary();
68
		compatLibrary.initialize();
69
		compatLibrary.postInitialize();
70

  
71
		DefaultGPELibrary lib = new DefaultGPELibrary();
72
		lib.initialize();
73
		lib.postInitialize();
58 74
		
59
		GPELibrary lib = new GPELibrary();
60
		lib.initialize();
61
		lib.postInitialize();	
75
		DefaultGmlLibrary gmlLib = new DefaultGmlLibrary();
76
		gmlLib.initialize();
77
		gmlLib.postInitialize();
78
		
79
		DefaultKmlLibrary kmlLib = new DefaultKmlLibrary();
80
		kmlLib.initialize();
81
		kmlLib.postInitialize();
62 82
	}
63 83

  
64 84
	/*
......
69 89
	 * ()
70 90
	 */
71 91
	public DataStoreParameters getDefaultDataStoreParameters()
72
			throws DataException {
92
	throws DataException {
73 93
		GPEStoreParameters parameters = null;
74 94

  
75 95
		parameters = (GPEStoreParameters) dataManager
76
				.createStoreParameters(GPEStoreProvider.NAME);
96
		.createStoreParameters(GPEStoreProvider.NAME);
77 97

  
78 98
		parameters.setFileName(file_prueba.getAbsolutePath());
79 99
		return parameters;
......
84 104
	 *
85 105
	 * @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer()
86 106
	 */
87
	public boolean hasExplorer() {
107
	public boolean hasExplorer() {	
108
		return false;
109
	}
110

  
111
	/* (non-Javadoc)
112
	 * @see org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore#getDefaultNewDataStoreParameters()
113
	 */
114
	public NewFeatureStoreParameters getDefaultNewDataStoreParameters()
115
	throws Exception {
116
		return null;
117
//		if (this.myExplorer == null) {
118
//			GPEStoreParameters gpeStoreParameters = (GPEStoreParameters) this
119
//			.getDefaultDataStoreParameters();
120
//			FeatureStore store = (FeatureStore) dataManager
121
//			.createStore(gpeStoreParameters);
122
//			myExplorer = (FilesystemServerExplorer) store.getExplorer();
123
//			store.dispose();
124
//		}
125
//
126
//		return (NewFeatureStoreParameters) myExplorer
127
//		.getAddParameters(dbf_prueba_destino);
128
	}
129

  
130
	/* (non-Javadoc)
131
	 * @see org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore#usesResources()
132
	 */
133
	public boolean usesResources() {
88 134
		// TODO Auto-generated method stub
89 135
		return false;
90 136
	}
branches/v2_0_0_prep/extensions/extGPE-gvSIG/config/parser.properties
1
GML=org.gvsig.gpe.gml.parser.GPEGmlSFP0Parser
2
KML=org.gvsig.gpe.kml.parser.GPEKml2_1_Parser
branches/v2_0_0_prep/extensions/extGPE-gvSIG/config/writer.properties
1
GMLv2=org.gvsig.gpe.gml.writer.GPEGmlv2WriterHandlerImplementor
2
GMLSFP0=org.gvsig.gpe.gml.writer.GPEGmlSFP0WriterHandlerImplementor
3
KML=org.gvsig.gpe.kml.writer.GPEKml21WriterHandlerImplementor
branches/v2_0_0_prep/extensions/extGPE-gvSIG/src/org/gvsig/gpe/GPELibraryExtension.java
27 27
 
28 28
package org.gvsig.gpe;
29 29

  
30
import java.io.File;
31
import java.io.FileNotFoundException;
32

  
33 30
import org.gvsig.fmap.dal.store.gpe.GPELibrary;
34 31

  
35
import com.iver.andami.messages.NotificationManager;
36 32
import com.iver.andami.plugins.Extension;
37 33

  
38 34
/**
......
40 36
 */
41 37
public class GPELibraryExtension extends Extension{
42 38
	private GPELibrary lib = null;
43
	private String parsersFile = "gvSIG" + File.separatorChar + "extensiones" + File.separatorChar + 
44
	"org.gvsig.gpe" + File.separatorChar + "parser.properties";
45
	
39
		
46 40
	/* (non-Javadoc)
47 41
	 * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
48 42
	 */
......
55 49
	 * @see com.iver.andami.plugins.IExtension#initialize()
56 50
	 */
57 51
	public void initialize() {
58
		File file = new File(parsersFile);
59
		if (!file.exists()){
60
			NotificationManager.addWarning("File not found",
61
					new FileNotFoundException());
62
			return;
63
		}
64
		try {
65
			GPERegister.addParsersFile(file);
66
		} catch (Exception e) {
67
			NotificationManager.addWarning("GPE parsers file not found",
68
					new FileNotFoundException());
69
		}
70
		
71 52
		lib = new GPELibrary();
72 53
		lib.initialize();		
73 54
	}	
branches/v2_0_0_prep/extensions/extGPE-gvSIG/src/org/gvsig/fmap/dal/store/gpe/GPELibrary.java
32 32
import org.gvsig.fmap.dal.DALLocator;
33 33
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
34 34
import org.gvsig.gpe.gml.GmlLibrary;
35
import org.gvsig.gpe.gml.impl.DefaultGmlLibrary;
36
import org.gvsig.gpe.impl.DefaultGPELibrary;
35 37
import org.gvsig.gpe.kml.KmlLibrary;
38
import org.gvsig.gpe.kml.impl.DefaultKmlLibrary;
39
import org.gvsig.gpe.xml.impl.DefaultXmlLibrary;
36 40
import org.gvsig.tools.locator.BaseLibrary;
37 41
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
38 42

  
......
40 44
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
41 45
 */
42 46
public class GPELibrary extends BaseLibrary {
43
	private GmlLibrary gmlLib = null;
44
	private KmlLibrary kmlLib = null;
47
	private DefaultGmlLibrary gmlLib = null;
48
	private DefaultKmlLibrary kmlLib = null;
49
	private DefaultGPELibrary gpeLib = null;
50
	private DefaultXmlLibrary xmlLib = null;
45 51
	
46 52
	public void initialize() throws ReferenceNotRegisteredException {
47 53
		super.initialize();
......
49 55
		DALLibrary dal = new DALLibrary();
50 56
		dal.initialize();
51 57
		
52
		gmlLib = new GmlLibrary();
58
		gpeLib = new DefaultGPELibrary();
59
		gpeLib.initialize();
60
		
61
		xmlLib = new DefaultXmlLibrary();
62
		xmlLib.initialize();
63
		
64
		gmlLib = new DefaultGmlLibrary();
53 65
		gmlLib.initialize();
54 66
		
55
		kmlLib = new KmlLibrary();
67
		kmlLib = new DefaultKmlLibrary();
56 68
		kmlLib.initialize();
57 69
	}
58 70

  
59 71
	public void postInitialize() throws ReferenceNotRegisteredException {     
60 72
		super.postInitialize();
61 73

  
74
		gpeLib.postInitialize();
75
		xmlLib.postInitialize();
62 76
		gmlLib.postInitialize();
63 77
		kmlLib.postInitialize();
64 78
		
branches/v2_0_0_prep/extensions/extGPE-gvSIG/src/org/gvsig/fmap/dal/store/gpe/handlers/FmapContentHandler.java
10 10

  
11 11
import org.gvsig.fmap.dal.DataTypes;
12 12
import org.gvsig.fmap.dal.exception.DataException;
13
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
13 14
import org.gvsig.fmap.dal.feature.EditableFeatureType;
14 15
import org.gvsig.fmap.dal.feature.Feature;
15 16
import org.gvsig.fmap.dal.feature.FeatureType;
......
337 338
			Map elements = gpefeature.getelements();
338 339
			Iterator keys = elements.keySet().iterator();
339 340
			featureType = store.createFeatureType();
340
			featureType.add("the_geom", DataTypes.GEOMETRY).setGeometryType(TYPES.GEOMETRY);			
341
			EditableFeatureAttributeDescriptor attributeDescriptor = featureType.add("the_geom", DataTypes.GEOMETRY).setGeometryType(TYPES.GEOMETRY);
342
			attributeDescriptor.setGeometrySubType(SUBTYPES.GEOM2D);
341 343
			featureType.setDefaultGeometryAttributeName("the_geom");
342 344
			featureType.setHasOID(true);
343 345
			while (keys.hasNext()){
branches/v2_0_0_prep/extensions/extGPE-gvSIG/src/org/gvsig/fmap/dal/store/gpe/GPEStoreProvider.java
342 342
	public void setEnvelope(Envelope envelope) {
343 343
		this.dynObject.setDynValue("Envelope", envelope);		
344 344
	}
345

  
346
	/* (non-Javadoc)
347
	 * @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState)
348
	 */
349
	public void saveToState(PersistentState state) throws PersistenceException {
350
		// TODO Auto-generated method stub
351
		
352
	}
345 353
	
346 354
	
347 355
}
branches/v2_0_0_prep/libraries/libGPE-KML/src/org/gvsig/gpe/kml/utils/KMLUtilsParser.java
5 5
import javax.xml.namespace.QName;
6 6

  
7 7
import org.gvsig.compat.CompatLocator;
8
import org.gvsig.gpe.GPEDefaults;
8
import org.gvsig.gpe.GPELocator;
9
import org.gvsig.gpe.GPEManager;
9 10
import org.gvsig.gpe.xml.XmlProperties;
10 11
import org.gvsig.gpe.xml.stream.IXmlStreamReader;
11 12
import org.gvsig.gpe.xml.stream.XmlStreamException;
......
98 99
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
99 100
 */
100 101
public class KMLUtilsParser {
101

  
102
	private static GPEManager gpeManager = GPELocator.getGPEManager();
103
	
102 104
	/**
103 105
	 * It returns a HashTable with the XML attributes. It has been 
104 106
	 * created because the parser doesn't has a getAttribiute(AttributeName)
......
131 133
		if (tag == null){
132 134
			return null;
133 135
		}
134
		String blancSpace = GPEDefaults.getStringProperty(XmlProperties.DEFAULT_BLANC_SPACE);
136
		String blancSpace = gpeManager.getStringProperty(XmlProperties.DEFAULT_BLANC_SPACE);
135 137
		if (blancSpace == null){
136 138
			blancSpace = Kml2_1_Tags.DEFAULT_BLANC_SPACE;
137 139
		}
......
152 154
		if (name == null){
153 155
			return null;
154 156
		}
155
		String blancSpace = GPEDefaults.getStringProperty(XmlProperties.DEFAULT_BLANC_SPACE);
157
		String blancSpace = gpeManager.getStringProperty(XmlProperties.DEFAULT_BLANC_SPACE);
156 158
		if (blancSpace == null){
157 159
			blancSpace = Kml2_1_Tags.DEFAULT_BLANC_SPACE;
158 160
		}
branches/v2_0_0_prep/libraries/libGPE-KML/src/org/gvsig/gpe/kml/impl/DefaultKmlLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.gpe.kml.impl;
29

  
30
import org.gvsig.gpe.GPELocator;
31
import org.gvsig.gpe.GPEManager;
32
import org.gvsig.gpe.exceptions.ParserNotRegisteredException;
33
import org.gvsig.gpe.kml.KmlLibrary;
34
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37

  
38
/**
39
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
40
 */
41
public class DefaultKmlLibrary extends KmlLibrary {
42
	private static final Logger logger = LoggerFactory.getLogger(DefaultKmlLibrary.class);
43
	
44
	/*
45
	 * (non-Javadoc)
46
	 * @see org.gvsig.tools.locator.BaseLibrary#initialize()
47
	 */
48
	public void initialize() throws ReferenceNotRegisteredException {
49
        super.initialize();		
50
    }
51

  
52
	/*
53
	 * (non-Javadoc)
54
	 * @see org.gvsig.tools.locator.BaseLibrary#postInitialize()
55
	 */
56
	public void postInitialize() {
57
		super.postInitialize();
58

  
59
		// Validate there is any implementation registered.
60
		GPEManager gpeManager = GPELocator.getGPEManager();
61
		if (gpeManager == null) {
62
			throw new ReferenceNotRegisteredException(
63
					GPELocator.GPE_MANAGER_NAME, GPELocator.getInstance());
64
		}	
65
		
66
		try {
67
			gpeManager.addGpeParser("KML", "Parser for KML", org.gvsig.gpe.kml.parser.GPEKml2_1_Parser.class);
68
		} catch (ParserNotRegisteredException e) {
69
			logger.error("Impossible to register a KML parser");
70
		}
71
		try {			
72
			gpeManager.addGpeParser("KML", "Writer for KML", org.gvsig.gpe.kml.writer.GPEKml21WriterHandlerImplementor.class);
73
		} catch (ParserNotRegisteredException e) {
74
			logger.error("Impossible to register a KML writer");
75
		}
76
	}
77
}
78

  
0 79

  
branches/v2_0_0_prep/libraries/libGPE-KML/src-test/org/gvsig/gpe/kml/AllKMLTests.java
1
package org.gvsig.gpe.kml;
2

  
3
import junit.framework.Test;
4
import junit.framework.TestSuite;
5

  
6
import org.gvsig.gpe.kml.parser.v21.kml.KMLReaderv21TestSuite;
7
import org.gvsig.gpe.kml.parser.v21.kmz.KMZReaderv21TestSuite;
8
import org.gvsig.gpe.kml.writer.v21.kml.KMLWriterv21TestSuite;
9
import org.gvsig.gpe.kml.writer.v21.kmz.KMZWriterv21TestSuite;
10
import org.gvsig.gpe.xml.XMLLibrary;
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: AllKMLTests.java 359 2008-01-09 17:51:16Z jpiera $
55
 * $Log$
56
 * Revision 1.1  2007/05/16 09:57:10  jorpiell
57
 * Tests refactoring
58
 *
59
 *
60
 */
61
/**
62
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
63
 */
64
public class AllKMLTests {
65

  
66
	public static Test suite() {
67
		KmlLibrary lib = new KmlLibrary();
68
		lib.initialize();
69
		lib.postInitialize();
70
		
71
		XMLLibrary xmlLibrary = new XMLLibrary();
72
		xmlLibrary.initialize();
73
		xmlLibrary.postInitialize();
74
		
75
		TestSuite suite = new TestSuite("Test for org.gvsig.gpe.kml");
76
		//$JUnit-BEGIN$		
77
		suite.addTest(KMLReaderv21TestSuite.suite());
78
		suite.addTest(KMLWriterv21TestSuite.suite());
79
		suite.addTest(KMZReaderv21TestSuite.suite());
80
		suite.addTest(KMZWriterv21TestSuite.suite());
81
		//$JUnit-END$
82
		return suite;
83
	}
84

  
85
}
branches/v2_0_0_prep/libraries/libGPE-KML/src-test/org/gvsig/gpe/kml/parser/v21/kml/KMLBaseTest.java
1 1
package org.gvsig.gpe.kml.parser.v21.kml;
2 2

  
3
import org.gvsig.gpe.kml.KmlLibrary;
3
import org.gvsig.gpe.kml.impl.DefaultKmlLibrary;
4 4
import org.gvsig.gpe.parser.GPEReaderBaseTest;
5
import org.gvsig.gpe.xml.XMLLibrary;
5
import org.gvsig.gpe.xml.impl.DefaultXmlLibrary;
6 6

  
7 7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8 8
 *
......
70 70
	public void setUp() throws Exception {
71 71
		super.setUp();
72 72
		
73
		KmlLibrary lib = new KmlLibrary();
73
		DefaultKmlLibrary lib = new DefaultKmlLibrary();
74 74
		lib.initialize();
75 75
		lib.postInitialize();
76 76
		
77
		XMLLibrary xmlLibrary = new XMLLibrary();
77
		DefaultXmlLibrary xmlLibrary = new DefaultXmlLibrary();
78 78
		xmlLibrary.initialize();
79 79
		xmlLibrary.postInitialize();
80 80
	}
branches/v2_0_0_prep/libraries/libGPE-XML/src/org/gvsig/gpe/xml/XMLLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.gpe.xml;
29

  
30
import java.util.Properties;
31

  
32
import org.gvsig.gpe.GPELibrary;
33
import org.gvsig.tools.locator.BaseLibrary;
34
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
35

  
36
/**
37
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
38
 */
39
public class XMLLibrary extends GPELibrary  {
40
	/*
41
	 * (non-Javadoc)
42
	 * @see org.gvsig.tools.locator.BaseLibrary#initialize()
43
	 */
44
	public void initialize() throws ReferenceNotRegisteredException {
45
		super.initialize();	
46
		addProperties(XmlProperties.getInstance());		
47
	}
48

  
49
	/*
50
	 * (non-Javadoc)
51
	 * @see org.gvsig.tools.locator.BaseLibrary#postInitialize()
52
	 */
53
	public void postInitialize() {
54
		super.postInitialize();		
55
	}
56
}
57

  
branches/v2_0_0_prep/libraries/libGPE-XML/src/org/gvsig/gpe/xml/parser/GPEXmlParser.java
6 6
import java.io.InputStream;
7 7
import java.io.PushbackInputStream;
8 8

  
9
import org.gvsig.gpe.GPEDefaults;
10
import org.gvsig.gpe.GPEProperties;
11 9
import org.gvsig.gpe.parser.GPEParser;
12 10
import org.gvsig.gpe.xml.XmlProperties;
13 11
import org.gvsig.gpe.xml.exceptions.GPEXmlEmptyFileException;
......
115 113
        try {
116 114
            parser = getXmlReader();            
117 115
            //Check the XMLSchema
118
             if (GPEDefaults.getBooleanProperty(XmlProperties.XML_SCHEMA_VALIDATED) == true){
116
             if (getGpeManager().getBooleanProperty(XmlProperties.XML_SCHEMA_VALIDATED) == true){
119 117
            	 
120 118
             }
121 119
            initParse();
branches/v2_0_0_prep/libraries/libGPE-XML/src/org/gvsig/gpe/xml/parser/GPEXmlSchemaDocument.java
1 1
package org.gvsig.gpe.xml.parser;
2 2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.net.URI;
6
import java.net.URISyntaxException;
7
import java.net.URL;
8
import java.util.StringTokenizer;
9

  
10
import javax.xml.namespace.QName;
11

  
12
import org.gvsig.compat.CompatLocator;
13
import org.gvsig.gpe.GPEDefaults;
14
import org.gvsig.gpe.parser.GPEErrorHandler;
15
import org.gvsig.gpe.xml.XmlProperties;
16
import org.gvsig.gpe.xml.stream.IXmlStreamReader;
17
import org.gvsig.gpe.xml.stream.XmlStreamException;
18
import org.gvsig.gpe.xml.utils.XMLTags;
19 3
//import org.gvsig.xmlschema.exceptions.SchemaCreationException;
20 4
//import org.gvsig.xmlschema.som.impl.XSSchemaDocumentImpl;
21 5
//import org.gvsig.xmlschema.utils.DownloadUtilities;
branches/v2_0_0_prep/libraries/libGPE-XML/src/org/gvsig/gpe/xml/writer/GPEXmlWriterHandlerImplementor.java
1 1
package org.gvsig.gpe.xml.writer;
2 2

  
3
import org.gvsig.gpe.GPEDefaults;
4 3
import org.gvsig.gpe.writer.GPEWriterHandlerImplementor;
5 4
import org.gvsig.gpe.xml.XmlProperties;
6 5
import org.gvsig.gpe.xml.parser.GPEXmlParserFactory;
......
151 150
//				prefix = getSchemaDocument().getNamespacePrefix(
152 151
//						getSchemaDocument().getTargetNamespace());
153 152
//			}else{
154
				prefix = GPEDefaults.getStringProperty(XmlProperties.DEFAULT_NAMESPACE_PREFIX);
153
				prefix = getGpeManager().getStringProperty(XmlProperties.DEFAULT_NAMESPACE_PREFIX);
155 154
//			}
156 155
			if (prefix != null){
157 156
				targetNamespacePrefix = prefix + ":";
branches/v2_0_0_prep/libraries/libGPE-XML/src/org/gvsig/gpe/xml/XmlProperties.java
27 27
 
28 28
package org.gvsig.gpe.xml;
29 29

  
30
import java.util.Properties;
31 30

  
32
import org.gvsig.gpe.GPEDefaults;
33
import org.gvsig.gpe.IGPEProperties;
34

  
35 31
/**
36 32
 * This class contains the properties for the XML
37
 * parsers and writers. This class has been registered using
38
 * the SPI (Service Provider Interface) and the values of their
39
 * properties can be configured using {@link GPEDefaults}.
33
 * parsers and writers. 
40 34
 */
41
public class XmlProperties implements IGPEProperties{
42
	private Properties properties = null;
43
	private static XmlProperties instance = null;
44
	
45
	private XmlProperties(){
46
		properties = new Properties();
47
		properties.put(DEFAULT_NAMESPACE_PREFIX, DEFAULT_NAMESPACE_PREFIX_VALUE);
48
		properties.put(DEFAULT_NAMESPACE_URI, DEFAULT_NAMESPACE_URI_VALUE);
49
		properties.put(XSD_SCHEMA_FILE, XSD_SCHEMA_FILE_VALUE);
50
		properties.put(XML_VERSION, XML_VERSION_VALUE);
51
		properties.put(XML_ENCODING, XML_ENCODING_VALUE);
52
		properties.put(DEFAULT_BLANC_SPACE, DEFAULT_BLANC_SPACE_VALUE);
53
		properties.put(XML_SCHEMA_VALIDATED, XML_SCHEMA_VALIDATED_VALUE);
54
	}
55
	
56
	public static IGPEProperties getInstance(){
57
		if (instance == null){
58
			instance = new XmlProperties();
59
		}
60
		return instance;
61
	}
62
	
35
public class XmlProperties{
63 36
	/**
64 37
	 * XML Schema prefix that have to be used to generate the file for the
65 38
	 * formats based on XML.
......
67 40
	 * <a href="http://www.w3.org/XML/Schema">XML Schema</a> 
68 41
	 */
69 42
	public static final String DEFAULT_NAMESPACE_PREFIX = "namespacePrefix";
70
	private static final String DEFAULT_NAMESPACE_PREFIX_VALUE = "cit";
71
	
43
		
72 44
	/**
73 45
	 * Default namespace of the files based on XML.
74 46
	 * @see 
75 47
	 * <a href="http://www.w3.org/XML/Schema">XML Schema</a> 
76 48
	 */
77 49
	public static final String DEFAULT_NAMESPACE_URI= "namespaceURI";
78
	private static final String DEFAULT_NAMESPACE_URI_VALUE=  "http://www.gvsig.org/cit";
79
	
50
		
80 51
	/**
81 52
	 * Place where the XML Schema is located.
82 53
	 * @see 
83 54
	 * <a href="http://www.w3.org/XML/Schema">XML Schema</a> 
84 55
	 */
85 56
	public static final String XSD_SCHEMA_FILE = "schemaName";
86
	private static final String XSD_SCHEMA_FILE_VALUE = "cit.xsd";
87 57
		
88 58
	/**
89 59
	 * XML number of version.
......
91 61
	 * <a href=" http://www.w3.org/XML/">XML</a> 
92 62
	 */
93 63
	public static final String XML_VERSION = "xmlVersion";
94
	private static final String XML_VERSION_VALUE =  "1.0";
95 64
	
96 65
	/**
97 66
	 * Encoding of the generated XML files.
......
99 68
	 * <a href=" http://www.w3.org/XML/">XML</a> 
100 69
	 */
101 70
	public static final String XML_ENCODING = "xmlEncoding";
102
	private static final String XML_ENCODING_VALUE = "UTF-8";
103 71
	
104 72
	/**
105 73
	 * Character to replace the blank spaces in the names that
......
109 77
	 * space.
110 78
	 */
111 79
	public static final String DEFAULT_BLANC_SPACE = "defaultBlancSpace";
112
	private static final String DEFAULT_BLANC_SPACE_VALUE = "_";
113 80
	
114 81
	/**
115 82
	 * If the parser can download XML Schemas. 
116 83
	 */
117 84
	public static final String XML_SCHEMA_VALIDATED  = "xmlSchemaValidated";
118
	private static final Boolean XML_SCHEMA_VALIDATED_VALUE = new Boolean(true);
119
	
120
	/*
121
	 * (non-Javadoc)
122
	 * @see org.gvsig.gpe.IGPEProperties#getProperties()
123
	 */
124
	public Properties getProperties() {
125
		return properties;
126
	}
127

  
128 85
}
129 86

  
branches/v2_0_0_prep/libraries/libGPE-XML/src/org/gvsig/gpe/xml/impl/DefaultXmlLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.gpe.xml.impl;
29

  
30
import org.gvsig.gpe.GPELocator;
31
import org.gvsig.gpe.GPEManager;
32
import org.gvsig.gpe.GPEProperties;
33
import org.gvsig.gpe.impl.DefaultGPEManager;
34
import org.gvsig.gpe.xml.XmlLibrary;
35
import org.gvsig.gpe.xml.XmlProperties;
36
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
37

  
38
/**
39
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
40
 */
41
public class DefaultXmlLibrary extends XmlLibrary{
42
	/*
43
	 * (non-Javadoc)
44
	 * @see org.gvsig.tools.locator.BaseLibrary#initialize()
45
	 */
46
	public void initialize() throws ReferenceNotRegisteredException {
47
        super.initialize();		
48
    }
49

  
50
	/*
51
	 * (non-Javadoc)
52
	 * @see org.gvsig.tools.locator.BaseLibrary#postInitialize()
53
	 */
54
	public void postInitialize() {
55
		super.postInitialize();
56

  
57
		// Validate there is any implementation registered.
58
		GPEManager gpeManager = GPELocator.getGPEManager();
59
		if (gpeManager == null) {
60
			throw new ReferenceNotRegisteredException(
61
					GPELocator.GPE_MANAGER_NAME, GPELocator.getInstance());
62
		}
63
		
64
		gpeManager.setProperty(XmlProperties.DEFAULT_NAMESPACE_PREFIX, "cit");
65
		gpeManager.setProperty(XmlProperties.DEFAULT_NAMESPACE_URI, "http://www.gvsig.org/cit");
66
		gpeManager.setProperty(XmlProperties.XSD_SCHEMA_FILE, "cit.xsd");
67
		gpeManager.setProperty(XmlProperties.XML_VERSION, "1.0");
68
		gpeManager.setProperty(XmlProperties.XML_ENCODING, "UTF-8");
69
		gpeManager.setProperty(XmlProperties.DEFAULT_BLANC_SPACE, "_");
70
		gpeManager.setProperty(XmlProperties.XML_SCHEMA_VALIDATED, new Boolean(true));
71
	}
72
}
73

  
0 74

  
branches/v2_0_0_prep/libraries/libGPE-XML/src/org/gvsig/gpe/xml/XmlLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.gpe.xml;
29

  
30
import java.util.Properties;
31

  
32
import org.gvsig.gpe.GPELibrary;
33
import org.gvsig.tools.locator.BaseLibrary;
34
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
35

  
36
/**
37
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
38
 */
39
public class XmlLibrary extends GPELibrary  {
40
	/*
41
	 * (non-Javadoc)
42
	 * @see org.gvsig.tools.locator.BaseLibrary#initialize()
43
	 */
44
	public void initialize() throws ReferenceNotRegisteredException {
45
		super.initialize();			
46
	}
47

  
48
	/*
49
	 * (non-Javadoc)
50
	 * @see org.gvsig.tools.locator.BaseLibrary#postInitialize()
51
	 */
52
	public void postInitialize() {
53
		super.postInitialize();		
54
	}
55
}
56

  
0 57

  
branches/v2_0_0_prep/libraries/libGPE/src-test/org/gvsig/gpe/parser/GPEReaderBaseTest.java
8 8

  
9 9
import junit.framework.TestCase;
10 10

  
11
import org.gvsig.compat.CompatLibrary;
12
import org.gvsig.gpe.GPEFactory;
13
import org.gvsig.gpe.GPELibrary;
11
import org.gvsig.gpe.GPELocator;
12
import org.gvsig.gpe.GPEManager;
14 13
import org.gvsig.gpe.containers.Layer;
15 14

  
16 15
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
......
92 91
	private GPEErrorHandler errorHandler = null;
93 92
	private String parserName="FORMAT VERSION";
94 93
	private String parserDescription="default parser description";
95
	
94
	private GPEManager gpeManager = null;
95

  
96 96
	public void setUp() throws Exception{
97 97
		GPELibraryTest lib = new GPELibraryTest();
98 98
		lib.initialize();
99
		lib.postInitialize();		
99
		lib.postInitialize();
100
		gpeManager = GPELocator.getGPEManager();
100 101
		System.out.println("INFO: Parser registrado");
101 102
		file = new File(getFile());
102 103
		System.out.println("INFO: Abriendo Fichero: "+file.getName());
103
		assertEquals(GPEFactory.accept(file.toURI()),true);
104
		assertEquals(gpeManager.accept(file.toURI()),true);
104 105
		System.out.println("INFO: Existe parser registrado para el fomato ");
105
		parser = GPEFactory.createParserByClass(getGPEParserClass().getName());
106
		parser = gpeManager.createParserByClass(getGPEParserClass().getName());
106 107
		System.out.println("INFO: Creado el parser ");
107 108
		assertNotNull(parser);
109
	}	
110
	
111
	/**
112
	 * @return the gpeManager
113
	 */
114
	public GPEManager getGpeManager() {
115
		return gpeManager;
108 116
	}
109 117
	
110 118
	/**
branches/v2_0_0_prep/libraries/libGPE/src-test/org/gvsig/gpe/parser/GPELibraryTest.java
30 30
import org.gvsig.compat.CompatLibrary;
31 31
import org.gvsig.compat.se.SECompatLibrary;
32 32
import org.gvsig.gpe.GPELibrary;
33
import org.gvsig.gpe.impl.DefaultGPELibrary;
33 34
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
34 35

  
35 36
/**
36 37
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
37 38
 */
38
public class GPELibraryTest extends GPELibrary  {
39
public class GPELibraryTest extends DefaultGPELibrary  {
39 40
	private static CompatLibrary compatLibrary;
40 41
	
41 42
	/* (non-Javadoc)
branches/v2_0_0_prep/libraries/libGPE/src-test/org/gvsig/gpe/writer/GPEWriterBaseTest.java
10 10

  
11 11
import junit.framework.TestCase;
12 12

  
13
import org.gvsig.gpe.GPEFactory;
14
import org.gvsig.gpe.GPELibrary;
13
import org.gvsig.gpe.GPELocator;
14
import org.gvsig.gpe.GPEManager;
15 15
import org.gvsig.gpe.containers.Layer;
16 16
import org.gvsig.gpe.parser.GPEContentHandler;
17 17
import org.gvsig.gpe.parser.GPEContentHandlerTest;
......
118 118
	private GPEErrorHandler errorHandler = null;
119 119
	private GPEParser parser = null;
120 120
	private File outputFile = null;
121
	
121
	private GPEManager gpeManager = null;
122

  
122 123
	/**
123 124
	 * Register the driver and gets the handler
124 125
	 * @throws Exception 
......
127 128
		GPELibraryTest lib = new GPELibraryTest();
128 129
		lib.initialize();
129 130
		lib.postInitialize();	
131
		gpeManager = GPELocator.getGPEManager();
130 132
		outputFile = new File(this.getClass().getName() + Math.random());
133
	}	
134
	
135
	/**
136
	 * @return the gpeManager
137
	 */
138
	public GPEManager getGpeManager() {
139
		return gpeManager;
131 140
	}
132 141
	
133 142
	/**
......
151 160
		getWriterHandler().setOutputStream(os);
152 161
		writeObjects();		
153 162
		
154
		parser = GPEFactory.createParserByClass(getGPEParserClass().getName());
163
		parser = gpeManager.createParserByClass(getGPEParserClass().getName());
155 164
		InputStream is = createInputStream(outputFile);
156 165
		parser.parse(getContenHandler(),getErrorHandler() ,is);
157 166
		readObjects();
......
323 332
	public GPEWriterHandler getWriterHandler() {
324 333
		if (writerHandler == null){
325 334
			try {
326
				writerHandler = GPEFactory.createWriterByClass(getGPEWriterHandlerClass().getName());
335
				writerHandler = gpeManager.createWriterByClass(getGPEWriterHandlerClass().getName());
327 336
				writerHandler.setErrorHandler(getErrorHandler());
328 337
			} catch (Exception e) {
329 338
				//never throwed
branches/v2_0_0_prep/libraries/libGPE/src-test/org/gvsig/gpe/writer/schemas/GPEWriterWithSchemaBaseTest.java
3 3
import java.io.File;
4 4
import java.io.FileOutputStream;
5 5
import java.io.IOException;
6
import java.net.URI;
7 6

  
8
import org.gvsig.gpe.GPEDefaults;
9 7
import org.gvsig.gpe.writer.GPEWriterBaseTest;
10 8
import org.gvsig.xmlschema.som.IXSSchema;
11 9
import org.gvsig.xmlschema.utils.DOMObjectsFactory;
......
115 113
	public void testWriter() throws Exception{
116 114
		writeSchema();
117 115
		getSchema().write(new FileOutputStream(getSchemaFile()));
118
		GPEDefaults.setProperty("schemaName", getSchemaFile().getAbsolutePath());
116
		getGpeManager().setProperty("schemaName", getSchemaFile().getAbsolutePath());
119 117
		//getWriterHandler().getSchemaDocument().addSchema(
120 118
		//		new URI(getSchemaFile().getPath()), 
121 119
		//		getSchema());
branches/v2_0_0_prep/libraries/libGPE/src/org/gvsig/gpe/GPERegister.java
1
package org.gvsig.gpe;
2

  
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FileNotFoundException;
6
import java.io.IOException;
7
import java.lang.reflect.InvocationTargetException;
8
import java.net.URI;
9
import java.util.ArrayList;
10
import java.util.Enumeration;
11
import java.util.Hashtable;
12
import java.util.Iterator;
13
import java.util.Properties;
14

  
15
import org.gvsig.gpe.exceptions.ParserCreationException;
16
import org.gvsig.gpe.exceptions.ParserNotRegisteredException;
17
import org.gvsig.gpe.exceptions.WriterHandlerCreationException;
18
import org.gvsig.gpe.exceptions.WriterHandlerNotRegisteredException;
19
import org.gvsig.gpe.parser.GPEParser;
20
import org.gvsig.gpe.writer.GPEWriterHandler;
21
import org.gvsig.gpe.writer.GPEWriterHandlerImplementor;
22
import org.gvsig.gpe.writer.IGPEWriterHandlerImplementor;
23

  
24
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
25
 *
26
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
27
 *
28
 * This program is free software; you can redistribute it and/or
29
 * modify it under the terms of the GNU General Public License
30
 * as published by the Free Software Foundation; either version 2
31
 * of the License, or (at your option) any later version.
32
 *
33
 * This program is distributed in the hope that it will be useful,
34
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36
 * GNU General Public License for more details.
37
 *
38
 * You should have received a copy of the GNU General Public License
39
 * along with this program; if not, write to the Free Software
40
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
41
 *
42
 * For more information, contact:
43
 *
44
 *  Generalitat Valenciana
45
 *   Conselleria d'Infraestructures i Transport
46
 *   Av. Blasco Ib??ez, 50
47
 *   46010 VALENCIA
48
 *   SPAIN
49
 *
50
 *      +34 963862235
51
 *   gvsig@gva.es
52
 *      www.gvsig.gva.es
53
 *
54
 *    or
55
 *
56
 *   IVER T.I. S.A
57
 *   Salamanca 50
58
 *   46005 Valencia
59
 *   Spain
60
 *
61
 *   +34 963163400
62
 *   dac@iver.es
63
 */
64
/* CVS MESSAGES:
65
 *
66
 * $Id: GPERegister.java 282 2007-12-20 11:55:56Z jpiera $
67
 * $Log$
68
 * Revision 1.16  2007/06/28 13:04:33  jorpiell
69
 * The Qname has been updated to the 1.5 JVM machine. The schema validation is made in the GPEWriterHandlerImplementor class
70
 *
71
 * Revision 1.15  2007/06/20 09:35:37  jorpiell
72
 * Add the javadoc comments
73
 *
74
 * Revision 1.14  2007/05/16 12:34:55  csanchez
75
 * GPEParser Prototipo final de lectura
76
 *
77
 * Revision 1.13  2007/05/09 06:54:07  jorpiell
78
 * Change the File by URI
79
 *
80
 * Revision 1.12  2007/05/08 12:57:14  jorpiell
81
 * Add the register exceptions
82
 *
83
 * Revision 1.11  2007/05/07 07:06:26  jorpiell
84
 * Add a constructor with the name and the description fields
85
 *
86
 * Revision 1.10  2007/04/19 11:50:20  csanchez
87
 * Actualizacion protoripo libGPE
88
 *
89
 * Revision 1.9  2007/04/19 07:23:20  jorpiell
90
 * Add the add methods to teh contenhandler and change the register mode
91
 *
92
 * Revision 1.8  2007/04/18 12:54:45  csanchez
93
 * Actualizacion protoripo libGPE
94
 *
95
 * Revision 1.7  2007/04/17 07:53:55  jorpiell
96
 * Before to start a new parsing process, the initialize method of the content handlers is throwed
97
 *
98
 * Revision 1.6  2007/04/17 06:26:54  jorpiell
99
 * Fixed one problem with a index
100
 *
101
 * Revision 1.5  2007/04/14 16:06:13  jorpiell
102
 * The writer handler has been updated
103
 *
104
 * Revision 1.4  2007/04/12 17:06:42  jorpiell
105
 * First GML writing tests
106
 *
107
 * Revision 1.3  2007/04/11 11:10:27  jorpiell
108
 * Cambiado el nombre de getDriver a GetParser
109
 *
110
 * Revision 1.2  2007/04/11 08:54:24  jorpiell
111
 * A?adidos algunos comentarios
112
 *
113
 * Revision 1.1  2007/04/11 08:52:55  jorpiell
114
 * Se puede registrar una clase por nombre
115
 *
116
 * Revision 1.1  2007/04/11 08:22:41  jorpiell
117
 * GPE clase para registrar los drivers
118
 *
119
 *
120
 */
121
/**
122
 * This class is used to register the GPE parsers. All the 
123
 * parsers must be registered in this class before to be
124
 * used for the consumer application
125
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
126
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
127
 */
128
public class GPERegister {
129
	private static Hashtable parsers = new Hashtable();
130
	private static Hashtable writers = new Hashtable();
131
	private static GPEParser gpeParser=null; 
132
	
133
	/**
134
	 * Adds a new GPE parser
135
	 * @param name
136
	 * Driver name. It must be written like FORMAT VERSION
137
	 * @param description
138
	 * Driver description. Just a descriptive text
139
	 * @param clazz
140
	 * The parser class	
141
	 * @throws ParserNotRegisteredException 
142
	 * @throws GPEParserRegisterException
143
	 */
144
	public static void addGpeParser(String name, String description,Class clazz) throws ParserNotRegisteredException { 
145
		try{
146
			if (clazz != null){
147
				GPEParser parser = (GPEParser)clazz.getConstructor(null).newInstance(null);
148
				parsers.put(name, parser);
149
			}	
150
		}catch (Exception e){
151
			throw new ParserNotRegisteredException(clazz.getName());
152
		}
153
	}
154
	
155
	/**
156
	 * Adds a new GPE parser
157
	 * @param clazz
158
	 * The parser class	
159
	 * @throws ParserNotRegisteredException 
160
	 * @throws GPEParserRegisterException
161
	 */
162
	public static void addGpeParser(Class clazz) throws ParserNotRegisteredException { 
163
		try{
164
			if (clazz != null){
165
				GPEParser parser = (GPEParser)clazz.getConstructor(null).newInstance(null);
166
				parsers.put(parser.getName(), parser);
167
			}	
168
		}catch (Exception e){
169
			throw new ParserNotRegisteredException(clazz.getName());
170
		}
171
	}
172
	
173
	/**
174
	 * It loads the parsers of a parsers file. The file is
175
	 * a properties file. Every line has the structure: 
176
	 * Parser=Parser class
177
	 * @param file
178
	 * File that contains the parsers list
179
	 * @throws IOException 
180
	 * @throws FileNotFoundException 
181
	 * @throws ParserNotRegisteredException 
182
	 */
183
	public static void addParsersFile(File file) throws FileNotFoundException, IOException{
184
		if (!file.exists()){
185
			return;
186
		}
187
		Properties properties = new Properties();
188
		properties.load(new FileInputStream(file));
189
		for (Enumeration e = properties.keys(); e.hasMoreElements() ; ) {
190
		    String key = e.nextElement().toString();
191
		    Class clazz;
192
			try {
193
				clazz = Class.forName(properties.getProperty(key).toString());
194
				addGpeParser(clazz);
195
			} catch (ClassNotFoundException ex) {
196
				//Next class
197
			} catch (ParserNotRegisteredException ex) {
198
				//Next class
199
			} 	    
200
		}
201
	}	
202

  
203
	/**
204
	 * It loads the writers of a writers file. The file is
205
	 * a properties file. Every line has the structure: 
206
	 * Writer=Parser class
207
	 * @param file
208
	 * File that contains the writers list
209
	 * @throws IOException 
210
	 * @throws FileNotFoundException 
211
	 */
212
	public static void addWritersFile(File file) throws FileNotFoundException, IOException{
213
		if (!file.exists()){
214
			return;
215
		}
216
		Properties properties = new Properties();
217
		properties.load(new FileInputStream(file));
218
		for (Enumeration e = properties.keys(); e.hasMoreElements() ; ) {
219
		    String key = e.nextElement().toString();
220
		    Class clazz;
221
			try {
222
				clazz = Class.forName(properties.getProperty(key).toString());
223
				addGpeWriterHandler(clazz);
224
			} catch (ClassNotFoundException ex){
225
				//Next class
226
			} catch (WriterHandlerNotRegisteredException ex){
227
				//Next class
228
			}		    
229
		}
230
	}
231
	
232
	/**
233
	 * @return all the registered parsers
234
	 */
235
	public static GPEParser[] getAllParsers(){
236
		GPEParser[] auxParsers = new GPEParser[parsers.size()];
237
		Iterator it = parsers.keySet().iterator();
238
		int i=0;
239
		while (it.hasNext()){
240
			String key = (String)it.next();
241
			auxParsers[i] = (GPEParser)parsers.get(key);
242
			i++;
243
		}
244
		return auxParsers;
245
	}
246
		
247
	/**
248
	 * Adds a new GPEWriterHandlerImplementor
249
	 * @param name
250
	 * Driver name. It must be written like FORMAT VERSION
251
	 * @param description
252
	 * Driver description. Just a descriptive text
253
	 * @param clazz
254
	 * The parser class	
255
	 * @throws WriterHandlerNotRegisteredException 
256
	 * @throws GPEWriterHandlerRegisterException 
257
	 */
258
	public static void addGpeWriterHandler(String name, String description,Class clazz) throws WriterHandlerNotRegisteredException {
259
		try{
260
			if (clazz != null){
261
				GPEWriterHandlerImplementor writerImplementor = (GPEWriterHandlerImplementor)clazz.getConstructor(null).newInstance(null);
262
				writers.put(name, writerImplementor);
263
			}
264
		}catch (Exception e){
265
			throw new WriterHandlerNotRegisteredException(clazz.getName());
266
		}
267
	}
268
	
269
	/**
270
	 * Adds a new GPEWriterHandlerImplementor
271
	 * @param clazz
272
	 * The parser class	
273
	 * @throws WriterHandlerNotRegisteredException 
274
	 * @throws GPEWriterHandlerRegisterException 
275
	 */
276
	public static void addGpeWriterHandler(Class clazz) throws WriterHandlerNotRegisteredException {
277
		try{
278
			if (clazz != null){
279
				GPEWriterHandlerImplementor writerImplementor = (GPEWriterHandlerImplementor)clazz.getConstructor(null).newInstance(null);
280
				writers.put(writerImplementor.getName(), writerImplementor);
281
			}
282
		}catch (Exception e){
283
			throw new WriterHandlerNotRegisteredException(clazz.getName());
284
		}
285
	}
286
	
287
	/**
288
	 * Create a new parser from a name
289
	 * @param name
290
	 * GPEParser name
291
	 * @param contenHandler
292
	 * Application contenHandler usett to throw the parsing events
293
	 * @param errorHandler
294
	 * Application errror handler used to put errors and warnings
295
	 * @throws ParserCreationException 
296
	 * @throws GPEParserCreationException 
297
	 */
298
	public static GPEParser createParser(String name) throws ParserCreationException  {
299
		if((gpeParser!=null)&&(gpeParser.getName()==name))
300
			return gpeParser;
301
		Object parser =  parsers.get(name);
302
		try{
303
			if (parser != null){
304
				return (GPEParser)parser.getClass().getConstructor(null).newInstance(null);
305
			}else{
306
				Exception e = new ParserNotRegisteredException(name);
307
				throw new ParserCreationException(e);
308
			}
309
		}catch (Exception e) {
310
			throw new ParserCreationException(e);
311
		}
312
		
313
	}
314
	/**
315
	 * Create a new parser from a name
316
	 * @param name
317
	 * GPEParser name
318
	 * @param contenHandler
319
	 * Application contenHandler usett to throw the parsing events
320
	 * @param errorHandler
321
	 * Application errror handler used to put errors and warnings
322
	 * @throws ParserCreationException 
323
	 * @throws GPEParserCreationException 
324
	 */
325
	public static GPEParser createParser() throws ParserCreationException  {
326
		try {
327
			if(gpeParser!=null){
328
				return (GPEParser) gpeParser.getClass().getConstructor(null).newInstance(null);
329
			}else{
330
				Throwable e = new Exception("Fail Registering Parser");
331
				throw new ParserCreationException(e);
332
			}
333
		}catch (Exception e){
334
			throw new ParserCreationException(e);
335
		}
336
	}
337
		
338
	/**
339
	 * Gets the parser that can open the file (if it exists)
340
	 * @param uri
341
	 * File to open
342
	 * @return
343
	 * Null if the driver doesn't exist
344
	 * @throws GPEParserCreationException 
345
	 * @throws NoSuchMethodException 
346
	 * @throws InvocationTargetException 
347
	 * @throws IllegalAccessException 
348
	 * @throws InstantiationException 
349
	 * @throws SecurityException 
350
	 * @throws IllegalArgumentException 
351
	 */
352
	public static GPEParser createParser(URI uri) throws ParserCreationException {
353
		Iterator keys = parsers.keySet().iterator();
354
		while (keys.hasNext()){
355
			String key = (String)keys.next();
356
			GPEParser parser = (GPEParser)parsers.get(key);
357
			if (parser.accept(uri)){
358
				return createParser(key);
359
			}
360
		}
361
		return null;
362
	}
363
	
364
	/**
365
	 * Create a new content writer from a name
366
	 * @param name
367
	 * GPEWriterHandler name
368
	 * GPEParser name
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff