01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.security;
11:
12: import java.util.*;
13:
14: import org.mmbase.util.logging.Logger;
15: import org.mmbase.util.logging.Logging;
16:
17: /**
18: * This is the most simple way to store 'actions', namely simply in memory. Config files may fill
19: * this repository on startup.
20: *
21: * @author Michiel Meeuwissen
22: * @version $Id: MemoryActionRepository.java,v 1.7 2008/01/21 17:28:15 michiel Exp $
23: * @since MMBase-1.9
24: */
25: public class MemoryActionRepository extends ActionRepository {
26: private static final Logger log = Logging
27: .getLoggerInstance(MMBaseCop.class);
28:
29: private final Map<String, Map<String, Action>> store = new HashMap<String, Map<String, Action>>();
30:
31: public MemoryActionRepository() {
32: }
33:
34: public void load() {
35: }
36:
37: public void add(Action a) {
38: log.info("Adding " + a + " to " + this );
39: Map<String, Action> map = store.get(a.getNameSpace());
40: if (map == null) {
41: map = new HashMap<String, Action>();
42: store.put(a.getNameSpace(), map);
43: }
44: map.put(a.getName(), a);
45: }
46:
47: public Map<String, Action> get(String nameSpace) {
48: Map<String, Action> map = store.get(nameSpace);
49: if (map == null) {
50: return Collections.emptyMap();
51: } else {
52: return Collections.unmodifiableMap(map);
53: }
54: }
55:
56: public Action get(String nameSpace, String name) {
57: return get(nameSpace).get(name);
58: }
59:
60: public Collection<Map<String, Action>> getActions() {
61: return store.values();
62: }
63:
64: }
|