001:
002: /*
003: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * - Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.getc
011: *
012: * - Redistribution in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in
014: * the documentation and/or other materials provided with the
015: * distribution.
016: *
017: * Neither the name of Sun Microsystems, Inc. or the names of
018: * contributors may be used to endorse or promote products derived
019: * from this software without specific prior written permission.
020: *
021: * This software is provided "AS IS," without a warranty of any
022: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
023: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
024: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
025: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
026: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
027: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
028: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
029: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
030: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
031: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
032: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
033: *
034: * You acknowledge that Software is not designed, licensed or intended
035: * any nuclear facility.
036: */
037:
038: package com.sun.portal.community.impl;
039:
040: import com.sun.portal.community.CommunityId;
041: import com.sun.portal.community.RoleId;
042:
043: import java.util.HashMap;
044:
045: public class RoleAssignment {
046: public static Integer REPLACE = new Integer(0);
047: public static Integer INVALID = new Integer(1);
048: public static Integer ADD = new Integer(2);
049: public static Integer NOOP = new Integer(3);
050:
051: //------------------------------------------------------------------
052: // Role Assignment Rules
053: //-------------------------------------------------------------------
054: //
055: // NewRole(across)| OWNER MEMBER INVITED PENDI REJECT BANNED
056: // OrigRole(down) |
057: //------------------------------------------------------------------
058: // OWNER | NOOP ADD INVAL INVAL INVAL ADD
059: // MEMBER | ADD NOOP INVAL INVAL INVAL ADD
060: // INVITED| REPL REPL NOOP INVAL INVAL ADD
061: // PENDING| REPL REPL REPL NOOP REPL ADD
062: // REJECTE| REPL REPL REPL REPL NOOP ADD
063: // BANNED | INVAL INVAL INVAL INVAL INVAL NOOP
064: //-----------------------------------------------------------------
065:
066: private static HashMap roleRuleGrid = new HashMap();
067: static {
068:
069: roleRuleGrid.put(new RolePair(RoleId.OWNER_ROLE,
070: RoleId.OWNER_ROLE), NOOP);
071: roleRuleGrid.put(new RolePair(RoleId.OWNER_ROLE,
072: RoleId.MEMBER_ROLE), ADD);
073: roleRuleGrid.put(new RolePair(RoleId.OWNER_ROLE,
074: RoleId.INVITED_ROLE), INVALID);
075: roleRuleGrid.put(new RolePair(RoleId.OWNER_ROLE,
076: RoleId.PENDING_ROLE), INVALID);
077: roleRuleGrid.put(new RolePair(RoleId.OWNER_ROLE,
078: RoleId.REJECTED_ROLE), INVALID);
079: roleRuleGrid.put(new RolePair(RoleId.OWNER_ROLE,
080: RoleId.BANNED_ROLE), ADD);
081:
082: roleRuleGrid.put(new RolePair(RoleId.MEMBER_ROLE,
083: RoleId.OWNER_ROLE), ADD);
084: roleRuleGrid.put(new RolePair(RoleId.MEMBER_ROLE,
085: RoleId.MEMBER_ROLE), NOOP);
086: roleRuleGrid.put(new RolePair(RoleId.MEMBER_ROLE,
087: RoleId.INVITED_ROLE), INVALID);
088: roleRuleGrid.put(new RolePair(RoleId.MEMBER_ROLE,
089: RoleId.PENDING_ROLE), INVALID);
090: roleRuleGrid.put(new RolePair(RoleId.MEMBER_ROLE,
091: RoleId.REJECTED_ROLE), INVALID);
092: roleRuleGrid.put(new RolePair(RoleId.MEMBER_ROLE,
093: RoleId.BANNED_ROLE), ADD);
094:
095: roleRuleGrid.put(new RolePair(RoleId.INVITED_ROLE,
096: RoleId.OWNER_ROLE), REPLACE);
097: roleRuleGrid.put(new RolePair(RoleId.INVITED_ROLE,
098: RoleId.MEMBER_ROLE), REPLACE);
099: roleRuleGrid.put(new RolePair(RoleId.INVITED_ROLE,
100: RoleId.INVITED_ROLE), NOOP);
101: roleRuleGrid.put(new RolePair(RoleId.INVITED_ROLE,
102: RoleId.PENDING_ROLE), INVALID);
103: roleRuleGrid.put(new RolePair(RoleId.INVITED_ROLE,
104: RoleId.REJECTED_ROLE), INVALID);
105: roleRuleGrid.put(new RolePair(RoleId.INVITED_ROLE,
106: RoleId.BANNED_ROLE), ADD);
107:
108: roleRuleGrid.put(new RolePair(RoleId.PENDING_ROLE,
109: RoleId.OWNER_ROLE), REPLACE);
110: roleRuleGrid.put(new RolePair(RoleId.PENDING_ROLE,
111: RoleId.MEMBER_ROLE), REPLACE);
112: roleRuleGrid.put(new RolePair(RoleId.PENDING_ROLE,
113: RoleId.INVITED_ROLE), REPLACE);
114: roleRuleGrid.put(new RolePair(RoleId.PENDING_ROLE,
115: RoleId.PENDING_ROLE), NOOP);
116: roleRuleGrid.put(new RolePair(RoleId.PENDING_ROLE,
117: RoleId.REJECTED_ROLE), REPLACE);
118: roleRuleGrid.put(new RolePair(RoleId.PENDING_ROLE,
119: RoleId.BANNED_ROLE), ADD);
120:
121: roleRuleGrid.put(new RolePair(RoleId.REJECTED_ROLE,
122: RoleId.OWNER_ROLE), REPLACE);
123: roleRuleGrid.put(new RolePair(RoleId.REJECTED_ROLE,
124: RoleId.MEMBER_ROLE), REPLACE);
125: roleRuleGrid.put(new RolePair(RoleId.REJECTED_ROLE,
126: RoleId.INVITED_ROLE), REPLACE);
127: roleRuleGrid.put(new RolePair(RoleId.REJECTED_ROLE,
128: RoleId.PENDING_ROLE), REPLACE);
129: roleRuleGrid.put(new RolePair(RoleId.REJECTED_ROLE,
130: RoleId.REJECTED_ROLE), NOOP);
131: roleRuleGrid.put(new RolePair(RoleId.REJECTED_ROLE,
132: RoleId.BANNED_ROLE), ADD);
133:
134: roleRuleGrid.put(new RolePair(RoleId.BANNED_ROLE,
135: RoleId.OWNER_ROLE), INVALID);
136: roleRuleGrid.put(new RolePair(RoleId.BANNED_ROLE,
137: RoleId.MEMBER_ROLE), INVALID);
138: roleRuleGrid.put(new RolePair(RoleId.BANNED_ROLE,
139: RoleId.INVITED_ROLE), INVALID);
140: roleRuleGrid.put(new RolePair(RoleId.BANNED_ROLE,
141: RoleId.PENDING_ROLE), INVALID);
142: roleRuleGrid.put(new RolePair(RoleId.BANNED_ROLE,
143: RoleId.REJECTED_ROLE), INVALID);
144: roleRuleGrid.put(new RolePair(RoleId.BANNED_ROLE,
145: RoleId.BANNED_ROLE), NOOP);
146: }
147:
148: public static Integer validate(RoleId oldRole, RoleId newRole) {
149: RolePair pair = new RolePair(oldRole, newRole);
150:
151: return (Integer) roleRuleGrid.get(pair);
152:
153: }
154:
155: }
156:
157: class RolePair {
158:
159: RoleId _oldRole;
160: RoleId _newRole;
161:
162: RolePair(RoleId oldRole, RoleId newRole) {
163: _oldRole = oldRole;
164: _newRole = newRole;
165: }
166:
167: public boolean equals(Object p) {
168: if ((p != null) && (p instanceof RolePair)) {
169: RolePair q = (RolePair) p;
170: if ((q._oldRole.equals(this ._oldRole))
171: && q._newRole.equals(this ._newRole)) {
172: return true;
173: }
174: }
175: return false;
176:
177: }
178:
179: public int hashCode() {
180: return toString().hashCode();
181: }
182:
183: /**
184: * Get the string representation of this role ID.
185: */
186: public String toString() {
187: return _oldRole.toString() + ":" + _newRole.toString();
188: }
189:
190: }
|