Statistics
| Revision:

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 @ 40435

History | View | Annotate | Download (3.06 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
* 2008 IVER T.I   {{Task}}
26
*/
27

    
28
/**
29
 *
30
 */
31
package org.gvsig.fmap.dal.resource.file;
32

    
33
import java.io.File;
34
import java.io.FileInputStream;
35
import java.io.FileNotFoundException;
36
import java.text.MessageFormat;
37

    
38
import org.gvsig.fmap.dal.exception.InitializeException;
39
import org.gvsig.fmap.dal.resource.ResourceParameters;
40
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
41
import org.gvsig.fmap.dal.resource.exception.PrepareResourceException;
42
import org.gvsig.fmap.dal.resource.exception.ResourceException;
43
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyOpenException;
44
import org.gvsig.fmap.dal.resource.spi.AbstractResource;
45

    
46
/**
47
 * @author jmvivo
48
 *
49
 */
50
public class FileResource extends AbstractResource {
51

    
52
        final public static String NAME = "file";
53
        final public static String DESCRIPTION = "File of filesystem";
54

    
55
        private File file;
56

    
57
        public FileResource(FileResourceParameters params)
58
                        throws InitializeException {
59
                super(params);
60
                file = null;
61
        }
62

    
63
        public Object get() throws AccessResourceException {
64
                return getFile();
65
        }
66

    
67
        public String getFileName() throws AccessResourceException {
68
                return (String) getFile().getPath();
69
        }
70

    
71
        public File getFile() throws AccessResourceException {
72

    
73
                try {
74
                        prepare();
75
                } catch (PrepareResourceException e) {
76
                        throw new AccessResourceException(this, e);
77
                }
78
                return ((FileResourceParameters)getParameters()).getFile();
79
        }
80

    
81
        // TODO ???
82
        public FileInputStream getFileInputStream() throws AccessResourceException,
83
                        FileNotFoundException {
84
                FileInputStream fis = new FileInputStream(getFile());
85
                try {
86
                        notifyOpen();
87
                } catch (ResourceNotifyOpenException e) {
88
                        throw new AccessResourceException(this, e);
89
                }
90
                return fis;
91
        }
92

    
93
        public String getName() throws AccessResourceException {
94
                return MessageFormat.format("FileResource({0})",
95
                                new Object[] { getFileName() });
96
        }
97

    
98
        public boolean isThis(ResourceParameters parameters)
99
                        throws ResourceException {
100
                if (!(parameters instanceof FileResourceParameters)) {
101
                        return false;
102
                }
103
                FileResourceParameters params;
104
                params = (FileResourceParameters) parameters.getCopy();
105
                prepare(params);
106
                return params.getFileName().equals(this.getFileName());
107

    
108
        }
109

    
110
}
111