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 @ 40435
History | View | Annotate | Download (2.68 KB)
1 |
package org.gvsig.fmap.dal.resource.file; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
|
5 |
import org.gvsig.fmap.dal.resource.spi.AbstractResourceParameters; |
6 |
import org.gvsig.tools.ToolsLocator; |
7 |
import org.gvsig.tools.dataTypes.DataTypes; |
8 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
9 |
import org.gvsig.tools.dynobject.DynClass; |
10 |
import org.gvsig.tools.persistence.PersistenceManager; |
11 |
|
12 |
|
13 |
public class FileResourceParameters extends AbstractResourceParameters { |
14 |
|
15 |
public static final String DYNCLASS_NAME = "FileResourceParameters"; |
16 |
|
17 |
private static final String DYNFIELDNAME_FILE = "file"; |
18 |
|
19 |
private DelegatedDynObject delegatedDynObject;
|
20 |
|
21 |
public FileResourceParameters() {
|
22 |
this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
|
23 |
.getDynObjectManager() |
24 |
.createDynObject(registerDynClass()); |
25 |
} |
26 |
|
27 |
public FileResourceParameters(Object[] params) { |
28 |
this();
|
29 |
// XXX puede que sobre
|
30 |
setDynValue(DYNFIELDNAME_FILE, params[0]);
|
31 |
} |
32 |
|
33 |
public FileResourceParameters(String name) { |
34 |
this();
|
35 |
setDynValue(DYNFIELDNAME_FILE, name); |
36 |
} |
37 |
|
38 |
public String getFileName() { |
39 |
if( this.getFile()== null ) { |
40 |
return null; |
41 |
} |
42 |
return this.getFile().getPath(); |
43 |
} |
44 |
|
45 |
public FileResourceParameters setFileName(String fileName) { |
46 |
this.setDynValue(DYNFIELDNAME_FILE, fileName);
|
47 |
return this; |
48 |
} |
49 |
|
50 |
public File getFile() { |
51 |
return (File) this.getDynValue(DYNFIELDNAME_FILE); |
52 |
} |
53 |
|
54 |
public FileResourceParameters setFile(File file) { |
55 |
this.setDynValue(DYNFIELDNAME_FILE, file);
|
56 |
return this; |
57 |
} |
58 |
|
59 |
public FileResourceParameters setFile(String fileName) { |
60 |
this.setDynValue(DYNFIELDNAME_FILE, fileName);
|
61 |
return this; |
62 |
} |
63 |
|
64 |
public String getTypeName() { |
65 |
return FileResource.NAME;
|
66 |
} |
67 |
|
68 |
protected DelegatedDynObject getDelegatedDynObject() {
|
69 |
return delegatedDynObject;
|
70 |
} |
71 |
|
72 |
/**
|
73 |
* Added "static synchronized" because sometimes
|
74 |
* there is a "DuplicateDynClassException" when user
|
75 |
* selects more than one file (SHP, for example) to be
|
76 |
* added to the view. "definition" is null but then there is
|
77 |
* an exception because in the meantime another thread has registered it
|
78 |
* (I'm not sure this is the cause, but I cannot imagine another
|
79 |
* reason)
|
80 |
*/
|
81 |
private static synchronized DynClass registerDynClass() { |
82 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
83 |
DynClass definition = (DynClass) manager.getDefinition(DYNCLASS_NAME); |
84 |
if( definition == null ) { |
85 |
definition = (DynClass) manager.addDefinition( |
86 |
FileResourceParameters.class, |
87 |
DYNCLASS_NAME, |
88 |
DYNCLASS_NAME+" persistence definition",
|
89 |
null,
|
90 |
null
|
91 |
); |
92 |
|
93 |
definition.addDynField(DYNFIELDNAME_FILE).setType(DataTypes.FILE) |
94 |
.setDescription("The file");
|
95 |
} |
96 |
return definition;
|
97 |
} |
98 |
} |