root / org.gvsig.gpe / library / trunk / org.gvsig.gpe / org.gvsig.gpe.lib / org.gvsig.gpe.lib.impl / src / main / java / org / gvsig / gpe / lib / impl / DefaultGPEManager.java @ 264
History | View | Annotate | Download (5.54 KB)
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.lib.impl; |
29 |
|
30 |
import java.io.File; |
31 |
import java.io.FileInputStream; |
32 |
import java.io.FileNotFoundException; |
33 |
import java.net.URI; |
34 |
import java.util.Iterator; |
35 |
import java.util.Properties; |
36 |
|
37 |
import org.gvsig.gpe.lib.api.GPEManager; |
38 |
import org.gvsig.gpe.lib.api.exceptions.ParserCreationException; |
39 |
import org.gvsig.gpe.lib.api.exceptions.WriterHandlerCreationException; |
40 |
import org.gvsig.gpe.lib.api.parser.IGPEContentHandler; |
41 |
import org.gvsig.gpe.lib.api.parser.IGPEContentHandlerInmGeom; |
42 |
import org.gvsig.gpe.lib.api.parser.IGPEErrorHandler; |
43 |
import org.gvsig.gpe.lib.api.writer.IGPEWriterHandler; |
44 |
import org.gvsig.gpe.lib.impl.parser.GPEContentHandlerAdapter; |
45 |
import org.gvsig.gpe.lib.impl.writer.GPEWriterHandler; |
46 |
import org.gvsig.gpe.lib.spi.GPEProviderLocator; |
47 |
import org.gvsig.gpe.lib.spi.GPEProviderManager; |
48 |
import org.gvsig.gpe.lib.spi.parser.IGPEParser; |
49 |
|
50 |
/**
|
51 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
52 |
*/
|
53 |
public class DefaultGPEManager implements GPEManager { |
54 |
private GPEProviderManager gpeProviderManager = null; |
55 |
private Properties properties = new Properties(); |
56 |
|
57 |
/*
|
58 |
* (non-Javadoc)
|
59 |
*
|
60 |
* @see org.gvsig.gpe.GPEManager#getKeys()
|
61 |
*/
|
62 |
public Iterator getKeys() { |
63 |
return properties.keySet().iterator();
|
64 |
} |
65 |
|
66 |
/*
|
67 |
* (non-Javadoc)
|
68 |
*
|
69 |
* @see org.gvsig.gpe.GPEManager#getStringProperty(java.lang.String)
|
70 |
*/
|
71 |
public String getStringProperty(String key) { |
72 |
Object obj = getProperty(key);
|
73 |
if (obj == null) { |
74 |
return null; |
75 |
} |
76 |
return (String) obj; |
77 |
} |
78 |
|
79 |
/*
|
80 |
* (non-Javadoc)
|
81 |
*
|
82 |
* @see org.gvsig.gpe.GPEManager#getIntPropertyProperty(java.lang.String)
|
83 |
*/
|
84 |
public int getIntPropertyProperty(String key) { |
85 |
Object obj = getProperty(key);
|
86 |
if (obj == null) { |
87 |
return -1; |
88 |
} |
89 |
if (obj instanceof Integer) { |
90 |
return ((Integer) obj).intValue(); |
91 |
} |
92 |
return -1; |
93 |
} |
94 |
|
95 |
/*
|
96 |
* (non-Javadoc)
|
97 |
*
|
98 |
* @see org.gvsig.gpe.GPEManager#getBooleanProperty(java.lang.String)
|
99 |
*/
|
100 |
public boolean getBooleanProperty(String key) { |
101 |
Object obj = getProperty(key);
|
102 |
if (obj == null) { |
103 |
return false; |
104 |
} |
105 |
if (obj instanceof Boolean) { |
106 |
return ((Boolean) obj).booleanValue(); |
107 |
} |
108 |
return false; |
109 |
} |
110 |
|
111 |
/*
|
112 |
* (non-Javadoc)
|
113 |
*
|
114 |
* @see org.gvsig.gpe.GPEManager#getProperty(java.lang.String)
|
115 |
*/
|
116 |
public Object getProperty(String key) { |
117 |
return properties.get(key);
|
118 |
} |
119 |
|
120 |
/*
|
121 |
* (non-Javadoc)
|
122 |
*
|
123 |
* @see org.gvsig.gpe.GPEManager#setProperty(java.lang.String,
|
124 |
* java.lang.Object)
|
125 |
*/
|
126 |
public void setProperty(String key, Object value) { |
127 |
properties.put(key, value); |
128 |
} |
129 |
|
130 |
public IGPEWriterHandler createWriter(String name) |
131 |
throws WriterHandlerCreationException {
|
132 |
return new GPEWriterHandler(getGPEProviderManager() |
133 |
.createWriterHandlerImplementor(name)); |
134 |
} |
135 |
|
136 |
public IGPEWriterHandler createWriterByClass(String prefferredImplClassName) |
137 |
throws WriterHandlerCreationException {
|
138 |
return new GPEWriterHandler(getGPEProviderManager() |
139 |
.createWriterHandlerImplementorByClass(prefferredImplClassName)); |
140 |
} |
141 |
|
142 |
public IGPEWriterHandler createWriterByMimeType(String mimeType) |
143 |
throws WriterHandlerCreationException {
|
144 |
return new GPEWriterHandler(getGPEProviderManager() |
145 |
.createWriterHandlerImplementorByMimeType(mimeType)); |
146 |
} |
147 |
|
148 |
public void parse(IGPEContentHandler contents, IGPEErrorHandler errors, |
149 |
URI uri) throws ParserCreationException { |
150 |
IGPEParser parser = getGPEProviderManager().createParser(uri); |
151 |
parser.parse(new GPEContentHandlerAdapter(contents), errors, uri);
|
152 |
} |
153 |
|
154 |
private GPEProviderManager getGPEProviderManager() {
|
155 |
if (gpeProviderManager == null) { |
156 |
gpeProviderManager = GPEProviderLocator.getGPEProviderManager(); |
157 |
} |
158 |
return gpeProviderManager;
|
159 |
} |
160 |
|
161 |
public void parse(IGPEContentHandler contents, IGPEErrorHandler errors, |
162 |
File file) throws ParserCreationException { |
163 |
IGPEParser parser = getGPEProviderManager().createParser(file); |
164 |
try {
|
165 |
parser.parse(new GPEContentHandlerAdapter(contents), errors,
|
166 |
new FileInputStream(file)); |
167 |
} catch (FileNotFoundException e) { |
168 |
throw new ParserCreationException(e); |
169 |
} |
170 |
} |
171 |
|
172 |
public boolean accept(URI uri) { |
173 |
return getGPEProviderManager().accept(uri);
|
174 |
} |
175 |
|
176 |
public void parse(IGPEContentHandlerInmGeom contents, |
177 |
IGPEErrorHandler errors, URI uri) throws ParserCreationException { |
178 |
IGPEParser parser = getGPEProviderManager().createParser(uri); |
179 |
parser.parse(contents, errors, uri); |
180 |
} |
181 |
|
182 |
public void parse(IGPEContentHandlerInmGeom contents, |
183 |
IGPEErrorHandler errors, File file) throws ParserCreationException { |
184 |
IGPEParser parser = getGPEProviderManager().createParser(file); |
185 |
try {
|
186 |
parser.parse(contents, errors, new FileInputStream(file)); |
187 |
} catch (FileNotFoundException e) { |
188 |
throw new ParserCreationException(e); |
189 |
} |
190 |
} |
191 |
|
192 |
} |