001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions
006: * are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.getc
010: *
011: * - Redistribution in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the
014: * distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032: *
033: * You acknowledge that Software is not designed, licensed or intended
034: * any nuclear facility.
035: */
036: package com.sun.portal.community;
037:
038: import java.security.Principal;
039:
040: import java.util.Map;
041: import java.util.HashMap;
042: import java.util.Iterator;
043: import java.util.HashSet;
044: import java.util.Set;
045:
046: /**
047: * Uniquely identifies a string that can have a DP attached to it.
048: */
049: public class DPName implements Principal {
050: public static final DPName BANNED_DP_NAME = new DPName("banned");
051: public static final DPName DELETED_DP_NAME = new DPName("deleted");
052: public static final DPName DISABLED_DP_NAME = new DPName("disabled");
053: public static final DPName INVITED_DP_NAME = new DPName("invited");
054: public static final DPName MEMBER_DP_NAME = new DPName("member");
055: public static final DPName OWNER_DP_NAME = new DPName("owner");
056: public static final DPName PENDING_DP_NAME = new DPName("pending");
057: public static final DPName REJECTED_DP_NAME = new DPName("rejected");
058: public static final DPName VISITOR_DP_NAME = new DPName("visitor");
059:
060: private static final Map ALL_DP_NAME_MAP;
061:
062: static {
063: ALL_DP_NAME_MAP = new HashMap();
064: // ALL_DP_NAME_MAP.put(BANNED_DP_NAME.toString(), BANNED_DP_NAME);
065: ALL_DP_NAME_MAP
066: .put(DELETED_DP_NAME.toString(), DELETED_DP_NAME);
067: ALL_DP_NAME_MAP.put(DISABLED_DP_NAME.toString(),
068: DISABLED_DP_NAME);
069: // ALL_DP_NAME_MAP.put(INVITED_DP_NAME.toString(), INVITED_DP_NAME);
070: ALL_DP_NAME_MAP.put(MEMBER_DP_NAME.toString(), MEMBER_DP_NAME);
071: ALL_DP_NAME_MAP.put(OWNER_DP_NAME.toString(), OWNER_DP_NAME);
072: // ALL_DP_NAME_MAP.put(PENDING_DP_NAME.toString(), PENDING_DP_NAME);
073: // ALL_DP_NAME_MAP.put(REJECTED_DP_NAME.toString(), REJECTED_DP_NAME);
074: ALL_DP_NAME_MAP
075: .put(VISITOR_DP_NAME.toString(), VISITOR_DP_NAME);
076: }
077:
078: public static final Set ALL_DP_NAMES = new HashSet(ALL_DP_NAME_MAP
079: .values());
080:
081: private String name;
082:
083: private DPName(String name) {
084: this .name = name;
085: }
086:
087: public boolean equals(Object o) {
088: if (!(o instanceof DPName)) {
089: return false;
090: }
091:
092: DPName other = (DPName) o;
093:
094: if (getName().equals(other.getName())) {
095: return true;
096: }
097:
098: return false;
099: }
100:
101: public String getName() {
102: return name;
103: }
104:
105: public int hashCode() {
106: return toString().hashCode();
107: }
108:
109: /**
110: * Get the string representation of this dpname ID.
111: */
112: public String toString() {
113: return name;
114: }
115:
116: /**
117: * Get the DPName
118: * object based on the given string dpname ID.
119: */
120: public static DPName valueOf(String r) {
121: return (DPName) ALL_DP_NAME_MAP.get(r);
122: }
123:
124: /**
125: * Get the DPName
126: * objects based on the given dpname ID strings.
127: */
128: public static Set valueSet(Set dpnameStrings) {
129: Set dpnameIds = new HashSet();
130: for (Iterator i = dpnameStrings.iterator(); i.hasNext();) {
131: String dpnameString = (String) i.next();
132: DPName rid = DPName.valueOf(dpnameString);
133: dpnameIds.add(rid);
134: }
135:
136: return dpnameIds;
137: }
138: }
|