svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.lib / src / main / java / org / gvsig / fmap / dal / resource / file / FileResource.java @ 40596
History | View | Annotate | Download (3.05 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.dal.resource.file; |
25 |
|
26 |
import java.io.File; |
27 |
import java.io.FileInputStream; |
28 |
import java.io.FileNotFoundException; |
29 |
import java.text.MessageFormat; |
30 |
|
31 |
import org.gvsig.fmap.dal.exception.InitializeException; |
32 |
import org.gvsig.fmap.dal.resource.ResourceParameters; |
33 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
34 |
import org.gvsig.fmap.dal.resource.exception.PrepareResourceException; |
35 |
import org.gvsig.fmap.dal.resource.exception.ResourceException; |
36 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyOpenException; |
37 |
import org.gvsig.fmap.dal.resource.spi.AbstractResource; |
38 |
|
39 |
/**
|
40 |
* @author jmvivo
|
41 |
*
|
42 |
*/
|
43 |
public class FileResource extends AbstractResource { |
44 |
|
45 |
final public static String NAME = "file"; |
46 |
final public static String DESCRIPTION = "File of filesystem"; |
47 |
|
48 |
private File file; |
49 |
|
50 |
public FileResource(FileResourceParameters params)
|
51 |
throws InitializeException {
|
52 |
super(params);
|
53 |
file = null;
|
54 |
} |
55 |
|
56 |
public Object get() throws AccessResourceException { |
57 |
return getFile();
|
58 |
} |
59 |
|
60 |
public String getFileName() throws AccessResourceException { |
61 |
return (String) getFile().getPath(); |
62 |
} |
63 |
|
64 |
public File getFile() throws AccessResourceException { |
65 |
|
66 |
try {
|
67 |
prepare(); |
68 |
} catch (PrepareResourceException e) {
|
69 |
throw new AccessResourceException(this, e); |
70 |
} |
71 |
return ((FileResourceParameters)getParameters()).getFile();
|
72 |
} |
73 |
|
74 |
// TODO ???
|
75 |
public FileInputStream getFileInputStream() throws AccessResourceException, |
76 |
FileNotFoundException {
|
77 |
FileInputStream fis = new FileInputStream(getFile()); |
78 |
try {
|
79 |
notifyOpen(); |
80 |
} catch (ResourceNotifyOpenException e) {
|
81 |
throw new AccessResourceException(this, e); |
82 |
} |
83 |
return fis;
|
84 |
} |
85 |
|
86 |
public String getName() throws AccessResourceException { |
87 |
return MessageFormat.format("FileResource({0})", |
88 |
new Object[] { getFileName() }); |
89 |
} |
90 |
|
91 |
public boolean isThis(ResourceParameters parameters) |
92 |
throws ResourceException {
|
93 |
if (!(parameters instanceof FileResourceParameters)) { |
94 |
return false; |
95 |
} |
96 |
FileResourceParameters params; |
97 |
params = (FileResourceParameters) parameters.getCopy(); |
98 |
prepare(params); |
99 |
return params.getFileName().equals(this.getFileName()); |
100 |
|
101 |
} |
102 |
|
103 |
} |
104 |
|