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 / FileResourceParameters.java @ 40559
History | View | Annotate | Download (3.61 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 |
|
28 |
import org.gvsig.fmap.dal.resource.spi.AbstractResourceParameters; |
29 |
import org.gvsig.tools.ToolsLocator; |
30 |
import org.gvsig.tools.dataTypes.DataTypes; |
31 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
32 |
import org.gvsig.tools.dynobject.DynClass; |
33 |
import org.gvsig.tools.persistence.PersistenceManager; |
34 |
|
35 |
|
36 |
public class FileResourceParameters extends AbstractResourceParameters { |
37 |
|
38 |
public static final String DYNCLASS_NAME = "FileResourceParameters"; |
39 |
|
40 |
private static final String DYNFIELDNAME_FILE = "file"; |
41 |
|
42 |
private DelegatedDynObject delegatedDynObject;
|
43 |
|
44 |
public FileResourceParameters() {
|
45 |
this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
|
46 |
.getDynObjectManager() |
47 |
.createDynObject(registerDynClass()); |
48 |
} |
49 |
|
50 |
public FileResourceParameters(Object[] params) { |
51 |
this();
|
52 |
// XXX puede que sobre
|
53 |
setDynValue(DYNFIELDNAME_FILE, params[0]);
|
54 |
} |
55 |
|
56 |
public FileResourceParameters(String name) { |
57 |
this();
|
58 |
setDynValue(DYNFIELDNAME_FILE, name); |
59 |
} |
60 |
|
61 |
public String getFileName() { |
62 |
if( this.getFile()== null ) { |
63 |
return null; |
64 |
} |
65 |
return this.getFile().getPath(); |
66 |
} |
67 |
|
68 |
public FileResourceParameters setFileName(String fileName) { |
69 |
this.setDynValue(DYNFIELDNAME_FILE, fileName);
|
70 |
return this; |
71 |
} |
72 |
|
73 |
public File getFile() { |
74 |
return (File) this.getDynValue(DYNFIELDNAME_FILE); |
75 |
} |
76 |
|
77 |
public FileResourceParameters setFile(File file) { |
78 |
this.setDynValue(DYNFIELDNAME_FILE, file);
|
79 |
return this; |
80 |
} |
81 |
|
82 |
public FileResourceParameters setFile(String fileName) { |
83 |
this.setDynValue(DYNFIELDNAME_FILE, fileName);
|
84 |
return this; |
85 |
} |
86 |
|
87 |
public String getTypeName() { |
88 |
return FileResource.NAME;
|
89 |
} |
90 |
|
91 |
protected DelegatedDynObject getDelegatedDynObject() {
|
92 |
return delegatedDynObject;
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Added "static synchronized" because sometimes
|
97 |
* there is a "DuplicateDynClassException" when user
|
98 |
* selects more than one file (SHP, for example) to be
|
99 |
* added to the view. "definition" is null but then there is
|
100 |
* an exception because in the meantime another thread has registered it
|
101 |
* (I'm not sure this is the cause, but I cannot imagine another
|
102 |
* reason)
|
103 |
*/
|
104 |
private static synchronized DynClass registerDynClass() { |
105 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
106 |
DynClass definition = (DynClass) manager.getDefinition(DYNCLASS_NAME); |
107 |
if( definition == null ) { |
108 |
definition = (DynClass) manager.addDefinition( |
109 |
FileResourceParameters.class, |
110 |
DYNCLASS_NAME, |
111 |
DYNCLASS_NAME+" persistence definition",
|
112 |
null,
|
113 |
null
|
114 |
); |
115 |
|
116 |
definition.addDynField(DYNFIELDNAME_FILE).setType(DataTypes.FILE) |
117 |
.setDescription("The file");
|
118 |
} |
119 |
return definition;
|
120 |
} |
121 |
} |