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 @ 46050
History | View | Annotate | Download (2.36 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 | 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 | 44408 | jjdelcerro | Set<String> keyset = this.repository.keySet(); |
47 | if( keyset == null || keyset.isEmpty() ) { |
||
48 | return UnmodifiableBasicSet.EMPTY_UNMODIFIABLEBASICSET;
|
||
49 | } |
||
50 | return new UnmodifiableBasicSetAdapter<>(keyset); |
||
51 | 44304 | jjdelcerro | } |
52 | 46050 | omartinez | |
53 | public PropertiesSupport getProperties(String name) { |
||
54 | return null; |
||
55 | } |
||
56 | |||
57 | 44304 | jjdelcerro | @Override
|
58 | public void add(String name, DataStoreParameters parameters) { |
||
59 | 46050 | omartinez | this.add(name, parameters, null); |
60 | } |
||
61 | |||
62 | public void add(String name, DataStoreParameters parameters, PropertiesSupport properties) { |
||
63 | 44307 | jjdelcerro | 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 | 44377 | jjdelcerro | if( this.notifyObservers(NOTIFICATION_ADD, name, parameters).isCanceled() ) { |
70 | return;
|
||
71 | } |
||
72 | 44304 | jjdelcerro | this.repository.put(name, parameters);
|
73 | } |
||
74 | |||
75 | @Override
|
||
76 | public void remove(String name) { |
||
77 | 44307 | jjdelcerro | if( StringUtils.isBlank(name) ) {
|
78 | LOGGER.warn("parameter name can't be blank");
|
||
79 | return;
|
||
80 | } |
||
81 | 44377 | jjdelcerro | if( this.notifyObservers(NOTIFICATION_REMOVE, name).isCanceled() ) { |
82 | return;
|
||
83 | } |
||
84 | 44304 | jjdelcerro | this.repository.remove(name);
|
85 | } |
||
86 | |||
87 | } |