001: /**
002: * $Id: CMCUserImpl.java,v 1.5 2007/01/26 03:47:54 portalbld Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.community.mc.impl.manager;
014:
015: import java.util.Properties;
016: import java.util.Map;
017: import java.util.HashMap;
018: import java.util.Set;
019: import java.util.HashSet;
020: import java.util.Iterator;
021: import java.util.Collection;
022: import com.sun.portal.community.mc.impl.Debug;
023: import com.sun.portal.community.mc.impl.CMCProperties;
024: import com.sun.portal.community.mc.impl.CMCUserManager;
025: import com.sun.portal.community.mc.CMCUser;
026: import com.sun.portal.community.mc.CMCException;
027: import com.sun.portal.community.mc.CMCPrincipal;
028: import com.sun.portal.community.mc.CMCRolePrincipal;
029: import com.sun.portal.community.mc.ConfigTable;
030:
031: import java.util.logging.Logger;
032: import java.util.logging.Level;
033:
034: import com.sun.portal.log.common.PortalLogger;
035:
036: /**
037: * Community MC community user manager implementation.
038: *
039: * This class delegates to one or all (depending on the operation)
040: * of its contributors for the operations in the
041: * <code>CommunityUser</code> interface.
042: */
043: public class CMCUserImpl extends CMCImpl implements CMCUserManager {
044: private static Logger logger = PortalLogger
045: .getLogger(CMCUserImpl.class);
046:
047: private Map contributors = new HashMap();
048: private String userId = null;
049:
050: public void init(Properties p, String userId) throws CMCException {
051: init(p, userId, CMCProperties.getContributorNames());
052: }
053:
054: public void init(Properties p, String userId, Iterator types)
055: throws CMCException {
056: this .userId = userId;
057: loadContributors(types);
058: }
059:
060: protected Class getClass(String type) {
061: return CMCProperties.getUserClass(type);
062: }
063:
064: protected void initContributor(Object c) throws CMCException {
065: CMCUser cu = (CMCUser) c;
066: cu.init(CMCProperties.getProperties(), getUserId());
067: }
068:
069: public String getUserId() {
070: return userId;
071: }
072:
073: public Set getMembership() throws CMCException {
074: Set membership = new HashSet();
075:
076: for (Iterator i = contributors.keySet().iterator(); i.hasNext();) {
077: String type = (String) i.next();
078: CMCUser user = (CMCUser) contributors.get(type);
079: try {
080: Set m = user.getMembership();
081: membership.addAll(m);
082: } catch (CMCException cmce) {
083: if (logger.isLoggable(Level.WARNING)) {
084: Object[] tokens = { type };
085: logger.log(Level.WARNING, "PSCMC_CSPCMM0004",
086: tokens);
087: logger.log(Level.WARNING, "PSCMC_CSPCMM0000", cmce);
088: }
089: }
090: }
091:
092: return membership;
093: }
094:
095: public Set getMembershipByName() throws CMCException {
096: Set membership = new HashSet();
097:
098: for (Iterator i = contributors.keySet().iterator(); i.hasNext();) {
099: String type = (String) i.next();
100: CMCUser user = (CMCUser) contributors.get(type);
101: try {
102: Set m = user.getMembershipByName();
103: membership.addAll(m);
104: } catch (CMCException cmce) {
105: if (logger.isLoggable(Level.WARNING)) {
106: Object[] tokens = { type };
107: logger.log(Level.WARNING, "PSCMC_CSPCMM0004",
108: tokens);
109: logger.log(Level.WARNING, "PSCMC_CSPCMM0000", cmce);
110: }
111: }
112: }
113:
114: return membership;
115: }
116:
117: public Set getMembershipByRole() throws CMCException {
118: Set membership = new HashSet();
119:
120: for (Iterator i = contributors.keySet().iterator(); i.hasNext();) {
121: String type = (String) i.next();
122: CMCUser user = (CMCUser) contributors.get(type);
123: try {
124: Set m = user.getMembershipByRole();
125: membership.addAll(m);
126: } catch (CMCException cmce) {
127: if (logger.isLoggable(Level.WARNING)) {
128: Object[] tokens = { type };
129: logger.log(Level.WARNING, "PSCMC_CSPCMM0004",
130: tokens);
131: logger.log(Level.WARNING, "PSCMC_CSPCMM0000", cmce);
132: }
133: }
134: }
135:
136: return membership;
137: }
138:
139: public Set getMembership(Set rps) throws CMCException {
140: Set membership = new HashSet();
141:
142: for (Iterator i = contributors.keySet().iterator(); i.hasNext();) {
143: String type = (String) i.next();
144: CMCUser user = (CMCUser) contributors.get(type);
145: try {
146: Set m = user.getMembership(rps);
147: membership.addAll(m);
148: } catch (CMCException cmce) {
149: if (logger.isLoggable(Level.WARNING)) {
150: Object[] tokens = { type };
151: logger.log(Level.WARNING, "PSCMC_CSPCMM0004",
152: tokens);
153: logger.log(Level.WARNING, "PSCMC_CSPCMM0000", cmce);
154: }
155: }
156: }
157:
158: return membership;
159: }
160:
161: public Set getMembershipByName(Set rps) throws CMCException {
162: Set membership = new HashSet();
163:
164: for (Iterator i = contributors.keySet().iterator(); i.hasNext();) {
165: String type = (String) i.next();
166: CMCUser user = (CMCUser) contributors.get(type);
167: try {
168: Set m = user.getMembershipByName(rps);
169: membership.addAll(m);
170: } catch (CMCException cmce) {
171: if (logger.isLoggable(Level.WARNING)) {
172: Object[] tokens = { type };
173: logger.log(Level.WARNING, "PSCMC_CSPCMM0004",
174: tokens);
175: logger.log(Level.WARNING, "PSCMC_CSPCMM0000", cmce);
176: }
177: }
178: }
179:
180: return membership;
181: }
182:
183: public Set getMembershipByRole(Set rps) throws CMCException {
184: Set membership = new HashSet();
185:
186: for (Iterator i = contributors.keySet().iterator(); i.hasNext();) {
187: String type = (String) i.next();
188: CMCUser user = (CMCUser) contributors.get(type);
189: try {
190: Set m = user.getMembershipByRole(rps);
191: membership.addAll(m);
192: } catch (CMCException cmce) {
193: if (logger.isLoggable(Level.WARNING)) {
194: Object[] tokens = { type };
195: logger.log(Level.WARNING, "PSCMC_CSPCMM0004",
196: tokens);
197: logger.log(Level.WARNING, "PSCMC_CSPCMM0000", cmce);
198: }
199: }
200: }
201:
202: return membership;
203: }
204:
205: public Set getAvailable() throws CMCException {
206: Set available = new HashSet();
207:
208: for (Iterator i = contributors.keySet().iterator(); i.hasNext();) {
209: String type = (String) i.next();
210: CMCUser user = (CMCUser) contributors.get(type);
211: try {
212: Set m = user.getAvailable();
213: available.addAll(m);
214: } catch (CMCException cmce) {
215: if (logger.isLoggable(Level.WARNING)) {
216: Object[] tokens = { type };
217: logger.log(Level.WARNING, "PSCMC_CSPCMM0003",
218: tokens);
219: logger.log(Level.WARNING, "PSCMC_CSPCMM0000", cmce);
220: }
221: }
222: }
223:
224: return available;
225: }
226:
227: private CMCUser getUserContributor(String type) throws CMCException {
228: CMCUser cu = (CMCUser) contributors.get(type);
229: if (cu == null) {
230: throw new CMCException("contributor not found for type: "
231: + type);
232: }
233:
234: return cu;
235: }
236:
237: public boolean hasRole(CMCPrincipal cp, CMCRolePrincipal rp)
238: throws CMCException {
239: CMCUser contributor = getUserContributor(cp.getType());
240: return contributor.hasRole(cp, rp);
241: }
242:
243: public long getRoleCreationTime(CMCPrincipal cp,
244: CMCRolePrincipal rolePrincipal) throws CMCException {
245: CMCUser contributor = getUserContributor(cp.getType());
246: return contributor.getRoleCreationTime(cp, rolePrincipal);
247: }
248:
249: public ConfigTable getDPDocuments(ConfigTable lastReadTimes)
250: throws CMCException {
251: ConfigTable dps = new ConfigTable();
252: for (Iterator i = contributors.keySet().iterator(); i.hasNext();) {
253: String type = (String) i.next();
254: CMCUser user = (CMCUser) contributors.get(type);
255: try {
256: dps.putAll(user.getDPDocuments(lastReadTimes));
257: } catch (CMCException cmce) {
258: if (logger.isLoggable(Level.WARNING)) {
259: Object[] tokens = { type };
260: logger.log(Level.WARNING, "PSCMC_CSPCMM0002",
261: tokens);
262: logger.log(Level.WARNING, "PSCMC_CSPCMM0000", cmce);
263: }
264: }
265: }
266:
267: return dps;
268: }
269:
270: public ConfigTable getDPDocuments(ConfigTable lastReadTimes,
271: Set membership) throws CMCException {
272: ConfigTable dps = new ConfigTable();
273: for (Iterator i = contributors.keySet().iterator(); i.hasNext();) {
274: String type = (String) i.next();
275: CMCUser user = (CMCUser) contributors.get(type);
276: try {
277: dps.putAll(user.getDPDocuments(lastReadTimes,
278: membership));
279: } catch (CMCException cmce) {
280: if (logger.isLoggable(Level.WARNING)) {
281: Object[] tokens = { type };
282: logger.log(Level.WARNING, "PSCMC_CSPCMM0002",
283: tokens);
284: logger.log(Level.WARNING, "PSCMC_CSPCMM0000", cmce);
285: }
286: }
287: }
288:
289: return dps;
290: }
291:
292: /**
293: * Load and initialize all contributors.
294: */
295: private void loadContributors(Iterator types) throws CMCException {
296: while (types.hasNext()) {
297: String type = (String) types.next();
298: try {
299: CMCUser cu = (CMCUser) createContributor(type);
300: contributors.put(type, cu);
301: } catch (CMCException cmce) {
302: if (logger.isLoggable(Level.WARNING)) {
303: Object[] tokens = { type };
304: logger.log(Level.WARNING, "PSCMC_CSPCMM0001",
305: tokens);
306: logger.log(Level.WARNING, "PSCMC_CSPCMM0000", cmce);
307: }
308: }
309: }
310: }
311:
312: private Collection getContributors() {
313: return contributors.values();
314: }
315: }
|