svn-gvsig-desktop / trunk / libraries / libFMap_dataFile / src / org / gvsig / data / datastores / vectorial / file / FileResource.java @ 20660
History | View | Annotate | Download (2.82 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.data.datastores.vectorial.file; |
32 |
|
33 |
import java.io.File; |
34 |
|
35 |
import org.gvsig.data.Resource; |
36 |
import org.gvsig.data.exception.CloseException; |
37 |
import org.gvsig.data.exception.DataException; |
38 |
import org.gvsig.data.exception.InitializeException; |
39 |
import org.gvsig.data.exception.OpenException; |
40 |
import org.gvsig.data.exception.ResourceChangedException; |
41 |
|
42 |
/**
|
43 |
* @author jmvivo
|
44 |
*
|
45 |
*/
|
46 |
public abstract class FileResource extends Resource implements IFileResource { |
47 |
|
48 |
protected File file; |
49 |
private long fileLastModified=0; |
50 |
private boolean opened; |
51 |
|
52 |
public FileResource(File aFile){ |
53 |
this.file = aFile;
|
54 |
} |
55 |
|
56 |
public void setFile(File aFile) throws InitializeException{ |
57 |
if (this.getRefencesCount() > 0){ |
58 |
throw new InitializeException("Resource in use",this.description()); |
59 |
} |
60 |
this.file=aFile;
|
61 |
} |
62 |
|
63 |
public File getFile(){ |
64 |
return this.file; |
65 |
} |
66 |
|
67 |
/* (non-Javadoc)
|
68 |
* @see org.gvsig.data.Resource#isOpen()
|
69 |
*/
|
70 |
public boolean isOpen() { |
71 |
return this.opened; |
72 |
} |
73 |
|
74 |
/* (non-Javadoc)
|
75 |
* @see org.gvsig.data.Resource#doChanged()
|
76 |
*/
|
77 |
protected void doChanged() { |
78 |
this.updateLastModified();
|
79 |
} |
80 |
|
81 |
protected void updateLastModified(){ |
82 |
this.fileLastModified = this.file.lastModified(); |
83 |
} |
84 |
|
85 |
protected void checkChanged() throws ResourceChangedException{ |
86 |
if (this.fileLastModified == 0){ |
87 |
return;
|
88 |
} |
89 |
if (this.fileLastModified < this.file.lastModified()){ |
90 |
this.changed();
|
91 |
throw new ResourceChangedException(this.description()); |
92 |
} |
93 |
} |
94 |
|
95 |
protected void setOpened(){ |
96 |
this.opened=true; |
97 |
} |
98 |
|
99 |
/* (non-Javadoc)
|
100 |
* @see org.gvsig.data.Resource#doDispose()
|
101 |
*/
|
102 |
protected void doDispose() throws DataException{ |
103 |
this.file = null; |
104 |
} |
105 |
|
106 |
/* (non-Javadoc)
|
107 |
* @see org.gvsig.data.Resource#doClose()
|
108 |
*/
|
109 |
protected boolean doClose() throws CloseException{ |
110 |
this.opened= false; |
111 |
return true; |
112 |
} |
113 |
|
114 |
|
115 |
protected synchronized void checkOpen() throws OpenException{ |
116 |
if (!this.isOpen()){ |
117 |
this.open();
|
118 |
} |
119 |
|
120 |
} |
121 |
|
122 |
} |
123 |
|