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.mc.test.impl.file.dynamic;
037:
038: import com.sun.portal.community.mc.CMCException;
039: import com.sun.portal.community.mc.CMCPrincipal;
040: import com.sun.portal.community.mc.CMCNode;
041: import com.sun.portal.community.mc.ConfigTable;
042: import com.sun.portal.community.mc.ConfigTable.ConfigKey;
043: import com.sun.portal.community.mc.CMCRolePrincipal;
044: import com.sun.portal.community.mc.CMCFactory;
045: import com.sun.portal.community.mc.CMCNodeManager;
046: import java.util.Iterator;
047: import java.util.Properties;
048: import java.util.Set;
049: import java.util.Map;
050: import java.util.HashMap;
051: import java.util.Collections;
052: import java.util.regex.Pattern;
053:
054: /**
055: * AM community node manager contributor, base class
056: *
057: * This class is extended by all AM community node manager
058: * contributors.
059: */
060: public abstract class CMCNodeManagerImpl extends CMCImpl implements
061: CMCNodeManager {
062: public static String getStaticType() {
063: return "filedynamic";
064: }
065:
066: public String getType() {
067: return getStaticType();
068: }
069:
070: public void init(Properties p) throws CMCException {
071: // nothing
072: }
073:
074: //
075: // the two get*Count() methods are suboptimal. they find the answer
076: // using brute-force: they get the users calling getUsers() and then
077: // count the results.
078: //
079: // this most likely could be optimized. however, since these are only
080: // implemented for completeness, we leave this for the future
081: //
082:
083: public Map getUserCounts(Set communityPrincipals)
084: throws CMCException {
085: communityPrincipals = filterPrincipals(communityPrincipals);
086: Map counts = new HashMap();
087:
088: for (Iterator i = communityPrincipals.iterator(); i.hasNext();) {
089: CMCPrincipal cmcp = (CMCPrincipal) i.next();
090: CMCNode cmcn = CMCFactory.getInstance().getCMCNode(cmcp);
091: counts.put(cmcp, new Integer(cmcn.getUsers().size()));
092: }
093:
094: return counts;
095: }
096:
097: public Map getRoleUserCounts(Set communityPrincipals,
098: Set rolePrincipals) throws CMCException {
099: communityPrincipals = filterPrincipals(communityPrincipals);
100: Map counts = new HashMap();
101:
102: for (Iterator i = communityPrincipals.iterator(); i.hasNext();) {
103: CMCPrincipal cmcp = (CMCPrincipal) i.next();
104: for (Iterator j = rolePrincipals.iterator(); j.hasNext();) {
105: CMCRolePrincipal cmcrp = (CMCRolePrincipal) j.next();
106: ConfigKey ck = new ConfigKey(cmcp, cmcrp);
107: CMCNode cmcn = CMCFactory.getInstance()
108: .getCMCNode(cmcp);
109: counts.put(ck, new Integer(cmcn.getUsers(
110: Collections.singleton(cmcrp)).size()));
111: }
112: }
113:
114: return counts;
115: }
116:
117: public Set match(Pattern p) throws CMCException {
118: // NOT IMPLEMENTED
119: return Collections.EMPTY_SET;
120: }
121: }
|