001package systems.dmx.core.service.accesscontrol;
002
003import java.util.HashMap;
004import java.util.Map;
005
006
007
008public enum SharingMode {
009
010    // ### TODO: move to dmx.core namespace?
011    PRIVATE("dmx.workspaces.private"),
012    CONFIDENTIAL("dmx.workspaces.confidential"),
013    COLLABORATIVE("dmx.workspaces.collaborative"),
014    PUBLIC("dmx.workspaces.public"),
015    COMMON("dmx.workspaces.common");
016
017    // ------------------------------------------------------------------------------------------------- Class Variables
018
019    private static Map<String, SharingMode> sharingModes;
020
021    // ---------------------------------------------------------------------------------------------- Instance Variables
022
023    private final String uri;
024
025    // ---------------------------------------------------------------------------------------------------- Constructors
026
027    private SharingMode(String uri) {
028        this.uri = uri;
029        put(uri, this);
030        // sharingModes.put(uri, this);   // ### "illegal reference to static field from initializer"
031    }
032
033    // -------------------------------------------------------------------------------------------------- Public Methods
034
035    public String getUri() {
036        return uri;
037    }
038
039    // Called also by JAX-RS container to get a SharingMode instance from a @PathParam or @QueryParam
040    public static SharingMode fromString(String uri) {
041        SharingMode sharingMode = sharingModes.get(uri);
042        if (sharingMode == null) {
043            throw new RuntimeException("\"" + uri + "\" is an unexpected sharing mode URI");
044        }
045        return sharingMode;
046    }
047
048    // ------------------------------------------------------------------------------------------------- Private Methods
049
050    private void put(String uri, SharingMode sharingMode) {
051        if (sharingModes == null) {
052            sharingModes = new HashMap();
053        }
054        sharingModes.put(uri, sharingMode);
055    }
056}