Statistics
| Revision:

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 @ 44644

History | View | Annotate | Download (2.08 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 44304 jjdelcerro
import org.gvsig.tools.util.UnmodifiableBasicSet;
8
import org.gvsig.tools.util.UnmodifiableBasicSetAdapter;
9
10
/**
11
 *
12
 * @author jjdelcerro
13
 */
14
@SuppressWarnings("UseSpecificCatch")
15
public class BaseStoresRepository
16
        extends AbstractStoresRepository
17
        implements StoresRepository
18
    {
19
20
    private final Map<String,DataStoreParameters> repository;
21
22
    public BaseStoresRepository(String name) {
23
        super(name);
24
        this.repository = new HashMap<>();
25
    }
26
27
28
    @Override
29
    protected DataStoreParameters getMyParameters(String name) {
30
        return this.repository.get(name);
31
    }
32
33
    @Override
34
    protected boolean isEmptyMyRepository() {
35
        return this.repository.isEmpty();
36
    }
37
38
    @Override
39
    protected int getMySize() {
40
        return this.repository.size();
41
    }
42
43
    @Override
44
    protected UnmodifiableBasicSet<String> getMyKeySet() {
45 44408 jjdelcerro
        Set<String> keyset = this.repository.keySet();
46
        if( keyset == null || keyset.isEmpty() ) {
47
            return UnmodifiableBasicSet.EMPTY_UNMODIFIABLEBASICSET;
48
        }
49
        return new UnmodifiableBasicSetAdapter<>(keyset);
50 44304 jjdelcerro
    }
51
52
    @Override
53
    public void add(String name, DataStoreParameters parameters) {
54 44307 jjdelcerro
        if( parameters == null ) {
55
            throw new IllegalArgumentException("parameters can't be null.");
56
        }
57
        if( StringUtils.isBlank(name) ) {
58
            throw new IllegalArgumentException("name can't be blank.");
59
        }
60 44377 jjdelcerro
        if( this.notifyObservers(NOTIFICATION_ADD, name, parameters).isCanceled() ) {
61
            return;
62
        }
63 44304 jjdelcerro
        this.repository.put(name, parameters);
64
    }
65
66
    @Override
67
    public void remove(String name) {
68 44307 jjdelcerro
        if( StringUtils.isBlank(name) ) {
69
            LOGGER.warn("parameter name can't be blank");
70
            return;
71
        }
72 44377 jjdelcerro
        if( this.notifyObservers(NOTIFICATION_REMOVE, name).isCanceled() ) {
73
            return;
74
        }
75 44304 jjdelcerro
        this.repository.remove(name);
76
    }
77
78
}