svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / main / java / org / gvsig / fmap / mapcontext / layers / ExtendedPropertiesHelper.java @ 41840
History | View | Annotate | Download (3.8 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.mapcontext.layers; |
25 |
|
26 |
import java.util.HashMap; |
27 |
import java.util.Hashtable; |
28 |
import java.util.Map; |
29 |
import org.gvsig.tools.ToolsLocator; |
30 |
import org.gvsig.tools.dynobject.DynStruct; |
31 |
import org.gvsig.tools.persistence.PersistenceManager; |
32 |
import org.gvsig.tools.persistence.Persistent; |
33 |
import org.gvsig.tools.persistence.PersistentState; |
34 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
35 |
import org.gvsig.tools.util.Callable; |
36 |
|
37 |
public class ExtendedPropertiesHelper implements ExtendedPropertiesSupport, Persistent { |
38 |
|
39 |
/*
|
40 |
Add this to class that implements ExtendedPropertiesSupport
|
41 |
|
42 |
private ExtendedPropertiesHelper propertiesHelper = new ExtendedPropertiesHelper();
|
43 |
|
44 |
This methods
|
45 |
|
46 |
public Object getProperty(Object key) {
|
47 |
return this.propertiesHelper.getProperty(key);
|
48 |
}
|
49 |
|
50 |
public void setProperty(Object key, Object obj) {
|
51 |
this.propertiesHelper.setProperty(key, obj);
|
52 |
}
|
53 |
|
54 |
public Map getExtendedProperties() {
|
55 |
return this.propertiesHelper.getExtendedProperties();
|
56 |
}
|
57 |
|
58 |
To the persistence defnition
|
59 |
|
60 |
definition.addDynFieldObject("propertiesHelper").setClassOfValue(ExtendedPropertiesHelper.class)
|
61 |
.setMandatory(false);
|
62 |
|
63 |
To the loadFromState
|
64 |
|
65 |
this.propertiesHelper = (ExtendedPropertiesHelper) state.get("propertiesHelper");
|
66 |
|
67 |
And to the saveToState
|
68 |
|
69 |
state.set("propertiesHelper",propertiesHelper);
|
70 |
|
71 |
*/
|
72 |
private Map properties = new HashMap(); |
73 |
|
74 |
public Object getProperty(Object key) { |
75 |
return properties.get(key);
|
76 |
} |
77 |
|
78 |
public void setProperty(Object key, Object val) { |
79 |
properties.put(key, val); |
80 |
} |
81 |
|
82 |
public Map getExtendedProperties() { |
83 |
return properties;
|
84 |
} |
85 |
|
86 |
public void setExtendedProperties(Map properties) { |
87 |
this.properties = new HashMap(); |
88 |
this.properties.putAll(properties);
|
89 |
} |
90 |
|
91 |
public void saveToState(PersistentState state) throws PersistenceException { |
92 |
state.set("properties", properties);
|
93 |
} |
94 |
|
95 |
public void loadFromState(PersistentState state) throws PersistenceException { |
96 |
this.properties = new Hashtable((Map) state.get("properties")); |
97 |
} |
98 |
|
99 |
public static class RegisterPersistence implements Callable { |
100 |
|
101 |
public Object call() { |
102 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
103 |
DynStruct definition = manager.addDefinition( |
104 |
ExtendedPropertiesHelper.class, |
105 |
"ExtendedPropertiesHelper",
|
106 |
"ExtendedPropertiesHelper Persistence definition",
|
107 |
null,
|
108 |
null
|
109 |
); |
110 |
definition.addDynFieldMap("properties").setClassOfItems(Object.class) |
111 |
.setMandatory(true);
|
112 |
|
113 |
return Boolean.TRUE; |
114 |
} |
115 |
} |
116 |
|
117 |
} |