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 @ 41810
History | View | Annotate | Download (3.62 KB)
1 | 41350 | jjdelcerro | /**
|
---|---|---|---|
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 | |||
36 | public class ExtendedPropertiesHelper implements ExtendedPropertiesSupport, Persistent { |
||
37 | |||
38 | /*
|
||
39 | Add this to class that implements ExtendedPropertiesSupport
|
||
40 | |||
41 | private ExtendedPropertiesHelper propertiesHelper = new ExtendedPropertiesHelper();
|
||
42 | |||
43 | This methods
|
||
44 | |||
45 | public Object getProperty(Object key) {
|
||
46 | return this.propertiesHelper.getProperty(key);
|
||
47 | }
|
||
48 | |||
49 | public void setProperty(Object key, Object obj) {
|
||
50 | this.propertiesHelper.setProperty(key, obj);
|
||
51 | }
|
||
52 | |||
53 | public Map getExtendedProperties() {
|
||
54 | return this.propertiesHelper.getExtendedProperties();
|
||
55 | }
|
||
56 | |||
57 | To the persistence defnition
|
||
58 | |||
59 | definition.addDynFieldObject("propertiesHelper").setClassOfValue(ExtendedPropertiesHelper.class)
|
||
60 | .setMandatory(false);
|
||
61 | |||
62 | To the loadFromState
|
||
63 | |||
64 | this.propertiesHelper = (ExtendedPropertiesHelper) state.get("propertiesHelper");
|
||
65 | |||
66 | And to the saveToState
|
||
67 | |||
68 | state.set("propertiesHelper",propertiesHelper);
|
||
69 | |||
70 | */
|
||
71 | 41810 | jjdelcerro | private Map properties = new HashMap(); |
72 | 41350 | jjdelcerro | |
73 | public Object getProperty(Object key) { |
||
74 | return properties.get(key);
|
||
75 | } |
||
76 | |||
77 | public void setProperty(Object key, Object val) { |
||
78 | properties.put(key, val); |
||
79 | } |
||
80 | |||
81 | public Map getExtendedProperties() { |
||
82 | return properties;
|
||
83 | } |
||
84 | |||
85 | public void setExtendedProperties(Map properties) { |
||
86 | 41810 | jjdelcerro | this.properties = new HashMap(); |
87 | this.properties.putAll(properties);
|
||
88 | 41350 | jjdelcerro | } |
89 | |||
90 | public void saveToState(PersistentState state) throws PersistenceException { |
||
91 | state.set("properties", properties);
|
||
92 | } |
||
93 | |||
94 | public void loadFromState(PersistentState state) throws PersistenceException { |
||
95 | this.properties = new Hashtable((Map) state.get("properties")); |
||
96 | } |
||
97 | |||
98 | public static void registerPersistent() { |
||
99 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
100 | DynStruct definition = manager.addDefinition( |
||
101 | ExtendedPropertiesHelper.class, |
||
102 | "ExtendedPropertiesHelper",
|
||
103 | "ExtendedPropertiesHelper Persistence definition",
|
||
104 | null,
|
||
105 | null
|
||
106 | ); |
||
107 | definition.addDynFieldMap("properties").setClassOfItems(Object.class) |
||
108 | .setMandatory(true);
|
||
109 | } |
||
110 | |||
111 | } |