001: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.services.persondir.support;
007:
008: import java.util.Collections;
009: import java.util.Map;
010:
011: import org.apache.commons.logging.Log;
012: import org.apache.commons.logging.LogFactory;
013: import org.jasig.portal.security.IPerson;
014: import org.jasig.portal.services.persondir.IPersonAttributeDao;
015:
016: /**
017: * Abstract class implementing the IPersonAttributeDao method
018: * {@link IPersonAttributeDao#getUserAttributes(String)} by delegation to
019: * {@link IPersonAttributeDao#getUserAttributes(Map)} using a configurable
020: * default attribute name.
021: *
022: * <br>
023: * <br>
024: * Configuration:
025: * <table border="1">
026: * <tr>
027: * <th align="left">Property</th>
028: * <th align="left">Description</th>
029: * <th align="left">Required</th>
030: * <th align="left">Default</th>
031: * </tr>
032: * <tr>
033: * <td align="right" valign="top">defaultAttributeName</td>
034: * <td>
035: * The attribute name to use for {@link #getUserAttributes(String)} queries.
036: * May not be null.
037: * </td>
038: * <td valign="top">No</td>
039: * <td valign="top">{@link org.jasig.portal.security.IPerson#USERNAME}</td>
040: * </tr>
041: * </table>
042: *
043: * @author Eric Dalquist <a href="mailto:edalquist@unicon.net">edalquist@unicon.net</a>
044: * @version $Revision: 36183 $ $Date: 2005-10-12 16:18:32 -0700 (Wed, 12 Oct 2005) $
045: * @since uPortal 2.5
046: */
047: public abstract class AbstractDefaultQueryPersonAttributeDao implements
048: IPersonAttributeDao {
049:
050: protected final Log log = LogFactory.getLog(getClass());
051:
052: /**
053: * Defaults attribute to use for a simple query
054: */
055: private String defaultAttribute = IPerson.USERNAME;
056:
057: /**
058: * Implements this interface method by creating a seed Map from the
059: * uid argument and delegating to getUserAttributes() on that Map.
060: *
061: * Uses {@link Collections#singletonMap(java.lang.Object, java.lang.Object)}
062: * to create a seed with the value rerturned by
063: * {@link #getDefaultAttributeName()} as the key and <code>uid</code>
064: * as the value. Returns the result of invoking
065: * {@link IPersonAttributeDao#getUserAttributes(Map)} with the new
066: * {@link Map} as the argument.
067: *
068: * @see org.jasig.portal.services.persondir.IPersonAttributeDao#getUserAttributes(java.lang.String)
069: */
070: public final Map getUserAttributes(final String uid) {
071:
072: if (uid == null) {
073: throw new IllegalArgumentException(
074: "Illegal to invoke getUserAttributes(String) with null argument.");
075: }
076:
077: final Map seed = Collections.singletonMap(this
078: .getDefaultAttributeName(), uid);
079:
080: return this .getUserAttributes(seed);
081: }
082:
083: /**
084: * Returns the attribute set by {@link #setDefaultAttributeName(String)} or
085: * if it has not been called the default value "uid" is returned.
086: *
087: * @return The default single string query attribute
088: */
089: public final String getDefaultAttributeName() {
090: return this .defaultAttribute;
091: }
092:
093: /**
094: * Sets the attribute to use for {@link #getUserAttributes(String)} queries.
095: * It cannot be <code>null</code>.
096: *
097: * @param name The attribute name to set as default.
098: * @throws IllegalArgumentException if <code>name</code> is <code>null</code>.
099: */
100: public final void setDefaultAttributeName(final String name) {
101: if (name == null)
102: throw new IllegalArgumentException(
103: "The defaultAttributeName may not be null");
104:
105: this.defaultAttribute = name;
106: }
107: }
|