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:
037: package com.sun.portal.community.impl;
038:
039: import com.sun.portal.community.mc.CMCPrincipal;
040: import com.sun.portal.community.mc.CMCRolePrincipal;
041:
042: import com.sun.portal.community.CommunityId;
043: import com.sun.portal.community.RoleId;
044: import com.sun.portal.community.DPName;
045:
046: import java.util.Set;
047: import java.util.HashSet;
048: import java.util.Iterator;
049: import java.util.Map;
050: import java.util.HashMap;
051:
052: public class TypeConverter {
053: public static CMCPrincipal communityIdToPrincipal(CommunityId cid) {
054: return new CMCPrincipal(cid.getType(), cid.getName());
055: }
056:
057: public static CMCRolePrincipal roleIdToPrincipal(RoleId rid) {
058: return CMCRolePrincipal.valueOf(rid.getName());
059: }
060:
061: public static CMCRolePrincipal dpNameToCMCRolePrincipal(
062: DPName dpName) {
063: return CMCRolePrincipal.valueOf(dpName.getName());
064: }
065:
066: public static Set roleIdsToPrincipals(Set roleIds) {
067: Set principals = new HashSet();
068: for (Iterator i = roleIds.iterator(); i.hasNext();) {
069: RoleId rid = (RoleId) i.next();
070: CMCRolePrincipal rp = roleIdToPrincipal(rid);
071: principals.add(rp);
072: }
073:
074: return principals;
075: }
076:
077: public static Set communityIdsToPrincipals(Set communityIds) {
078: Set principals = new HashSet();
079: for (Iterator i = communityIds.iterator(); i.hasNext();) {
080: CommunityId cid = (CommunityId) i.next();
081: CMCPrincipal cmcp = communityIdToPrincipal(cid);
082: principals.add(cmcp);
083: }
084:
085: return principals;
086: }
087:
088: public static Set communityPrincipalsToIds(Set principals) {
089: Set ids = new HashSet();
090: for (Iterator i = principals.iterator(); i.hasNext();) {
091: CMCPrincipal principal = (CMCPrincipal) i.next();
092: CommunityId id = communityPrincipalToId(principal);
093: ids.add(id);
094: }
095:
096: return ids;
097: }
098:
099: public static CommunityId communityPrincipalToId(CMCPrincipal cp) {
100: return new CommunityId(cp.getType(), cp.getName());
101: }
102:
103: public static RoleId rolePrincipalToId(CMCRolePrincipal rp) {
104: return RoleId.valueOf(rp.getName());
105: }
106:
107: public static Map communityPrincipalKeysToIds(
108: Map communityPrincipalMap) {
109: Map communityIdMap = new HashMap();
110: for (Iterator i = communityPrincipalMap.keySet().iterator(); i
111: .hasNext();) {
112: CMCPrincipal cmcp = (CMCPrincipal) i.next();
113: CommunityId cid = communityPrincipalToId(cmcp);
114: communityIdMap.put(cid, communityPrincipalMap.get(cmcp));
115: }
116:
117: return communityIdMap;
118: }
119: }
|