Revision 43215 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
ExtendedPropertiesHelper.java | ||
---|---|---|
24 | 24 |
package org.gvsig.fmap.mapcontext.layers; |
25 | 25 |
|
26 | 26 |
import java.util.HashMap; |
27 |
import java.util.Hashtable; |
|
28 |
import java.util.Iterator; |
|
29 | 27 |
import java.util.Map; |
28 |
import java.util.Map.Entry; |
|
29 |
import java.util.Set; |
|
30 | 30 |
|
31 | 31 |
import org.slf4j.Logger; |
32 | 32 |
import org.slf4j.LoggerFactory; |
... | ... | |
78 | 78 |
*/ |
79 | 79 |
private Map properties = new HashMap(); |
80 | 80 |
|
81 |
@Override |
|
81 | 82 |
public Object getProperty(Object key) { |
82 | 83 |
return properties.get(key); |
83 | 84 |
} |
84 | 85 |
|
86 |
@Override |
|
85 | 87 |
public void setProperty(Object key, Object val) { |
86 | 88 |
properties.put(key, val); |
87 | 89 |
} |
88 | 90 |
|
91 |
@Override |
|
89 | 92 |
public Map getExtendedProperties() { |
90 | 93 |
return properties; |
91 | 94 |
} |
92 | 95 |
|
93 | 96 |
public void setExtendedProperties(Map properties) { |
94 | 97 |
this.properties = new HashMap(); |
95 |
this.properties.putAll(properties); |
|
98 |
if( properties!=null ) { |
|
99 |
// this.properties.putAll(properties); |
|
100 |
this.copyFrom(properties); |
|
101 |
} |
|
96 | 102 |
} |
97 | 103 |
|
104 |
private void copyFrom(Map properties) { |
|
105 |
for(Entry entry : (Set<Entry>)properties.entrySet() ) { |
|
106 |
Object key = entry.getKey(); |
|
107 |
if( key == null ) { |
|
108 |
continue; |
|
109 |
} |
|
110 |
Object value; |
|
111 |
try { |
|
112 |
value = entry.getValue(); |
|
113 |
} catch(Throwable th) { |
|
114 |
if( logger.isDebugEnabled() ) { |
|
115 |
logger.warn("Can't get property "+key.toString()+".",th); |
|
116 |
} else { |
|
117 |
logger.warn("Can't get property "+key.toString()+"."); |
|
118 |
} |
|
119 |
value = null; |
|
120 |
} |
|
121 |
this.properties.put(key, value); |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
@Override |
|
98 | 126 |
public void saveToState(PersistentState state) throws PersistenceException { |
99 | 127 |
state.set("properties", properties); |
100 | 128 |
} |
101 | 129 |
|
130 |
@Override |
|
102 | 131 |
public void loadFromState(PersistentState state) throws PersistenceException { |
103 | 132 |
this.properties = new HashMap(); |
104 |
|
|
105 | 133 |
Map props = (Map) state.get("properties"); |
106 |
Iterator it = props.keySet().iterator(); |
|
107 |
while(it.hasNext()){ |
|
108 |
Object key = it.next(); |
|
109 |
if (key == null){ |
|
110 |
continue; |
|
111 |
} |
|
112 |
try { |
|
113 |
Object value = props.get(key); |
|
114 |
this.properties.put(key, value); |
|
115 |
} catch (Exception e) { |
|
116 |
logger.warn("Can't read property "+key.toString()+" from persistence.",e); |
|
117 |
} |
|
118 |
} |
|
134 |
if( props != null) { |
|
135 |
copyFrom(props); |
|
136 |
} |
|
119 | 137 |
} |
120 | 138 |
|
121 | 139 |
public static class RegisterPersistence implements Callable { |
122 | 140 |
|
141 |
@Override |
|
123 | 142 |
public Object call() { |
124 | 143 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
125 | 144 |
DynStruct definition = manager.addDefinition( |
Also available in: Unified diff