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 @ 46970
History | View | Annotate | Download (2.66 KB)
1 | 44304 | jjdelcerro | package org.gvsig.fmap.dal; |
---|---|---|---|
2 | |||
3 | import java.util.HashMap; |
||
4 | import java.util.Map; |
||
5 | 44408 | jjdelcerro | import java.util.Set; |
6 | 44307 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
7 | 46050 | omartinez | import org.gvsig.tools.util.PropertiesSupport; |
8 | 44304 | jjdelcerro | 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 | 46915 | jjdelcerro | this(name, null, null); |
25 | 46661 | jjdelcerro | } |
26 | |||
27 | public BaseStoresRepository(String name, String label) { |
||
28 | 46915 | jjdelcerro | this(name, label, null); |
29 | } |
||
30 | |||
31 | public BaseStoresRepository(String name, String label, DataServerExplorerParameters serverParameters) { |
||
32 | 46661 | jjdelcerro | super(name, label);
|
33 | 46915 | jjdelcerro | this.setServerParameters(serverParameters);
|
34 | 44304 | jjdelcerro | 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 | 44408 | jjdelcerro | Set<String> keyset = this.repository.keySet(); |
56 | if( keyset == null || keyset.isEmpty() ) { |
||
57 | return UnmodifiableBasicSet.EMPTY_UNMODIFIABLEBASICSET;
|
||
58 | } |
||
59 | return new UnmodifiableBasicSetAdapter<>(keyset); |
||
60 | 44304 | jjdelcerro | } |
61 | 46050 | omartinez | |
62 | public PropertiesSupport getProperties(String name) { |
||
63 | return null; |
||
64 | } |
||
65 | |||
66 | 44304 | jjdelcerro | @Override
|
67 | public void add(String name, DataStoreParameters parameters) { |
||
68 | 46050 | omartinez | this.add(name, parameters, null); |
69 | } |
||
70 | |||
71 | public void add(String name, DataStoreParameters parameters, PropertiesSupport properties) { |
||
72 | 44307 | jjdelcerro | 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 | 44377 | jjdelcerro | if( this.notifyObservers(NOTIFICATION_ADD, name, parameters).isCanceled() ) { |
79 | return;
|
||
80 | } |
||
81 | 44304 | jjdelcerro | this.repository.put(name, parameters);
|
82 | } |
||
83 | |||
84 | @Override
|
||
85 | public void remove(String name) { |
||
86 | 44307 | jjdelcerro | if( StringUtils.isBlank(name) ) {
|
87 | LOGGER.warn("parameter name can't be blank");
|
||
88 | return;
|
||
89 | } |
||
90 | 44377 | jjdelcerro | if( this.notifyObservers(NOTIFICATION_REMOVE, name).isCanceled() ) { |
91 | return;
|
||
92 | } |
||
93 | 44304 | jjdelcerro | this.repository.remove(name);
|
94 | } |
||
95 | 46915 | jjdelcerro | |
96 | 44304 | jjdelcerro | } |