svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.api / src / main / java / org / gvsig / fmap / dal / BaseStoresRepository.java @ 47080
History | View | Annotate | Download (2.66 KB)
1 |
package org.gvsig.fmap.dal; |
---|---|
2 |
|
3 |
import java.util.HashMap; |
4 |
import java.util.Map; |
5 |
import java.util.Set; |
6 |
import org.apache.commons.lang3.StringUtils; |
7 |
import org.gvsig.tools.util.PropertiesSupport; |
8 |
import org.gvsig.tools.util.UnmodifiableBasicSet; |
9 |
import org.gvsig.tools.util.UnmodifiableBasicSetAdapter; |
10 |
|
11 |
/**
|
12 |
*
|
13 |
* @author jjdelcerro
|
14 |
*/
|
15 |
@SuppressWarnings("UseSpecificCatch") |
16 |
public class BaseStoresRepository |
17 |
extends AbstractStoresRepository
|
18 |
implements StoresRepository
|
19 |
{ |
20 |
|
21 |
private final Map<String,DataStoreParameters> repository; |
22 |
|
23 |
public BaseStoresRepository(String name) { |
24 |
this(name, null, null); |
25 |
} |
26 |
|
27 |
public BaseStoresRepository(String name, String label) { |
28 |
this(name, label, null); |
29 |
} |
30 |
|
31 |
public BaseStoresRepository(String name, String label, DataServerExplorerParameters serverParameters) { |
32 |
super(name, label);
|
33 |
this.setServerParameters(serverParameters);
|
34 |
this.repository = new HashMap<>(); |
35 |
} |
36 |
|
37 |
|
38 |
@Override
|
39 |
protected DataStoreParameters getMyParameters(String name) { |
40 |
return this.repository.get(name); |
41 |
} |
42 |
|
43 |
@Override
|
44 |
protected boolean isEmptyMyRepository() { |
45 |
return this.repository.isEmpty(); |
46 |
} |
47 |
|
48 |
@Override
|
49 |
protected int getMySize() { |
50 |
return this.repository.size(); |
51 |
} |
52 |
|
53 |
@Override
|
54 |
protected UnmodifiableBasicSet<String> getMyKeySet() { |
55 |
Set<String> keyset = this.repository.keySet(); |
56 |
if( keyset == null || keyset.isEmpty() ) { |
57 |
return UnmodifiableBasicSet.EMPTY_UNMODIFIABLEBASICSET;
|
58 |
} |
59 |
return new UnmodifiableBasicSetAdapter<>(keyset); |
60 |
} |
61 |
|
62 |
public PropertiesSupport getProperties(String name) { |
63 |
return null; |
64 |
} |
65 |
|
66 |
@Override
|
67 |
public void add(String name, DataStoreParameters parameters) { |
68 |
this.add(name, parameters, null); |
69 |
} |
70 |
|
71 |
public void add(String name, DataStoreParameters parameters, PropertiesSupport properties) { |
72 |
if( parameters == null ) { |
73 |
throw new IllegalArgumentException("parameters can't be null."); |
74 |
} |
75 |
if( StringUtils.isBlank(name) ) {
|
76 |
throw new IllegalArgumentException("name can't be blank."); |
77 |
} |
78 |
if( this.notifyObservers(NOTIFICATION_ADD, name, parameters).isCanceled() ) { |
79 |
return;
|
80 |
} |
81 |
this.repository.put(name, parameters);
|
82 |
} |
83 |
|
84 |
@Override
|
85 |
public void remove(String name) { |
86 |
if( StringUtils.isBlank(name) ) {
|
87 |
LOGGER.warn("parameter name can't be blank");
|
88 |
return;
|
89 |
} |
90 |
if( this.notifyObservers(NOTIFICATION_REMOVE, name).isCanceled() ) { |
91 |
return;
|
92 |
} |
93 |
this.repository.remove(name);
|
94 |
} |
95 |
|
96 |
} |