<commit_before>/**
 * Copyright ? 2001 The JA-SIG Collaborative.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by the JA-SIG Collaborative
 *    (http://www.jasig.org/)."
 *
 * THIS SOFTWARE IS PROVIDED BY THE JA-SIG COLLABORATIVE "AS IS" AND ANY
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE JA-SIG COLLABORATIVE OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */


package  org.jasig.portal.security.provider;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;

import org.jasig.portal.EntityIdentifier;
import org.jasig.portal.security.IPerson;
import org.jasig.portal.security.ISecurityContext;
import org.jasig.portal.security.PersonFactory;
import org.jasig.portal.services.*;


/**
 * This is a reference IPerson implementation.
 * @author Adam Rybicki, <EMAIL>
 * @version $Revision$
 */
public class PersonImpl implements IPerson {
  protected Hashtable m_Attributes = null;
  protected String m_FullName = null;
  protected int m_ID = -1;
  protected ISecurityContext m_securityContext = null;
  protected EntityIdentifier m_eid= new EntityIdentifier(null,IPerson.class);
  
  public ISecurityContext getSecurityContext () {
    return m_securityContext;
  }

  public void setSecurityContext (ISecurityContext securityContext) {
    m_securityContext = securityContext;
  }

  /**
   * Returns an attribute for a key.  For multivalue attributes, this will be
   * a <code>java.util.Vector</code>.  For objects represented as strings,
   * a <code>java.lang.String</code> will be returned.  Binary values will
   * be represented a byte arrays.
   * This reference implementation supports the attribute: Email
   * corresponding to the eduPerson attribute: mail.
   * @param key Attribute's name.
   * @return Value of an attribute identified by the key.
   */
  public Object getAttribute (String key) {
    if (m_Attributes == null)
      return  null;
    Object value = m_Attributes.get(key);
    if (value instanceof List)
      return ((List)value).get(0);
    else
      return value;
  }
  
  /**
   * Returns multiple attributes for a key.  If only one
   * value exists, it will be stuffed into a Vector and
   * returned.
   * 
   */
  public Object[] getAttributeValues (String key) {
     if (m_Attributes == null)
       return null;
     Object value = m_Attributes.get(key);
     if (value == null) {
        return null;
     } else if (value instanceof List) {
       return ((List)value).toArray();
     } else {
       Vector rval = new Vector();
       rval.add(value);
       return rval.toArray();
     } 
  }

  /**
   * Returns a <code>java.util.Enumeration</code> of all the attribute values.
   * @return <code>java.util.Enumeration</code> of the attributes.
   */
  public Enumeration getAttributes () {
    if (m_Attributes == null)
      return  null;
    return  m_Attributes.elements();
  }

  /**
   * Returns an enumeration of all of the attribute names associated with the user
   * @return enumeration of all of the attribute names associated with the user
   */
  public Enumeration getAttributeNames () {
    if (m_Attributes == null) {
      return  (null);
    }
    else {
      return  (m_Attributes.keys());
    }
  }

  /**
   * Sets the specified attribute to a value.
   * This reference implementation supports the attribute: Email
   * corresponding to the eduPerson attribute: mail.
   * 
   * Reference impementation checks for the setting of the username attribute
   * and updates the EntityIdentifier accordingly<commit_msg>Restored the copyright symbol. Removed javadoc comments referring to Email attribute.  Removed use of Vector in getAttributeValues().<commit_after>/**
 * Copyright  2001 The JA-SIG Collaborative.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by the JA-SIG Collaborative
 *    (http://www.jasig.org/)."
 *
 * THIS SOFTWARE IS PROVIDED BY THE JA-SIG COLLABORATIVE "AS IS" AND ANY
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE JA-SIG COLLABORATIVE OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */


package  org.jasig.portal.security.provider;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;

import org.jasig.portal.EntityIdentifier;
import org.jasig.portal.security.IPerson;
import org.jasig.portal.security.ISecurityContext;
import org.jasig.portal.security.PersonFactory;


/**
 * This is a reference IPerson implementation.
 * @author <NAME>, <EMAIL>
 * @version $Revision$
 */
public class PersonImpl implements IPerson {
  protected Hashtable m_Attributes = null;
  protected String m_FullName = null;
  protected int m_ID = -1;
  protected ISecurityContext m_securityContext = null;
  protected EntityIdentifier m_eid= new EntityIdentifier(null,IPerson.class);
  
  public ISecurityContext getSecurityContext () {
    return m_securityContext;
  }

  public void setSecurityContext (ISecurityContext securityContext) {
    m_securityContext = securityContext;
  }

  /**
   * Returns an attribute for a key.  For objects represented as strings,
   * a <code>java.lang.String</code> will be returned.  Binary values will
   * be represented as byte arrays.
   * @param key the attribute name.
   * @return value the attribute value identified by the key.
   */
  public Object getAttribute (String key) {
    if (m_Attributes == null)
      return null;
    Object value = m_Attributes.get(key);
    if (value instanceof List)
      return ((List)value).get(0);
    else
      return value;
  }
  
  /**
   * Returns multiple attributes for a key.  If only one
   * value exists, it will be returned in an array of size one.
   * @param key the attribute name
   * @return the array of attribute values identified by the key
   */
  public Object[] getAttributeValues (String key) {
     if (m_Attributes == null)
       return null;
     Object value = m_Attributes.get(key);
     if (value == null) {
        return null;
     } else if (value instanceof List) {
       return ((List)value).toArray();
     } else {
       return new Object[] { value };
     } 
  }

  /**
   * Returns a <code>java.util.Enumeration</code> of all the attribute values.
   * @return <code>java.util.Enumeration</code> of the attributes.
   */
  public Enumeration getAttributes () {
    if (m_Attributes == null)
      return  null;
    return  m_Attributes.elements();
  }

  /**
   * Returns an enumeration of all of the attribute names associated with the user
   * @return enumeration of all of the attribute names associated with the user
   */
  public Enumeration getAttributeNames () {
    if (m_Attributes == null) {
      return  (null);
    }
    else {
      return  (m_Attributes.keys());
    }
  }

  /**
   * Sets the specified attribute to a value.
   * 
   * Reference impementation checks for the setting of the username attribute
   * and updates the EntityIdentifier accordingly
{'fraction_non_alphanumeric': 0.0795515216230646, 'fraction_numerical': 0.0019220501868659904, 'mean_word_length': 3.413760603204524, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4040960', 'n_tokens_mistral': 2636, 'n_tokens_neox': 2486, 'n_words': 1012}