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 @ 46426
History | View | Annotate | Download (2.36 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 |
super(name);
|
25 |
this.repository = new HashMap<>(); |
26 |
} |
27 |
|
28 |
|
29 |
@Override
|
30 |
protected DataStoreParameters getMyParameters(String name) { |
31 |
return this.repository.get(name); |
32 |
} |
33 |
|
34 |
@Override
|
35 |
protected boolean isEmptyMyRepository() { |
36 |
return this.repository.isEmpty(); |
37 |
} |
38 |
|
39 |
@Override
|
40 |
protected int getMySize() { |
41 |
return this.repository.size(); |
42 |
} |
43 |
|
44 |
@Override
|
45 |
protected UnmodifiableBasicSet<String> getMyKeySet() { |
46 |
Set<String> keyset = this.repository.keySet(); |
47 |
if( keyset == null || keyset.isEmpty() ) { |
48 |
return UnmodifiableBasicSet.EMPTY_UNMODIFIABLEBASICSET;
|
49 |
} |
50 |
return new UnmodifiableBasicSetAdapter<>(keyset); |
51 |
} |
52 |
|
53 |
public PropertiesSupport getProperties(String name) { |
54 |
return null; |
55 |
} |
56 |
|
57 |
@Override
|
58 |
public void add(String name, DataStoreParameters parameters) { |
59 |
this.add(name, parameters, null); |
60 |
} |
61 |
|
62 |
public void add(String name, DataStoreParameters parameters, PropertiesSupport properties) { |
63 |
if( parameters == null ) { |
64 |
throw new IllegalArgumentException("parameters can't be null."); |
65 |
} |
66 |
if( StringUtils.isBlank(name) ) {
|
67 |
throw new IllegalArgumentException("name can't be blank."); |
68 |
} |
69 |
if( this.notifyObservers(NOTIFICATION_ADD, name, parameters).isCanceled() ) { |
70 |
return;
|
71 |
} |
72 |
this.repository.put(name, parameters);
|
73 |
} |
74 |
|
75 |
@Override
|
76 |
public void remove(String name) { |
77 |
if( StringUtils.isBlank(name) ) {
|
78 |
LOGGER.warn("parameter name can't be blank");
|
79 |
return;
|
80 |
} |
81 |
if( this.notifyObservers(NOTIFICATION_REMOVE, name).isCanceled() ) { |
82 |
return;
|
83 |
} |
84 |
this.repository.remove(name);
|
85 |
} |
86 |
|
87 |
} |