Advanced Edition of IBM WebSphere Application Server

package com.ibm.servlet.personalization.userprofile;

/**
 * This is an Entity Bean class with CMP fields
 **/
import java.rmi.RemoteException;
import java.security.Identity;
import java.util.*;
import javax.ejb.*;
import java.lang.*;
import java.io.*;

public class UPBaseBean implements EntityBean {
    protected javax.ejb.EntityContext entityContext = null;

    //To handle the case where user specifies  a
    //field in extended class which is already in 
    //list of managed fields
    static Vector fields=new Vector(1);
    static {
        fields.addElement("userName");
        fields.addElement("language");
        fields.addElement("address1");
        fields.addElement("address2");
        fields.addElement("city");
        fields.addElement("stateOrProvince");
        fields.addElement("nation");
        fields.addElement("postalCode");
        fields.addElement("employer");
        fields.addElement("email");
        fields.addElement("dayPhone");
        fields.addElement("nightPhone");
        fields.addElement("fax");
        fields.addElement("firstName");
        fields.addElement("surName");
        //fields.addElement("groups");
    }



    public java.lang.String userName;
    public String language;
    public String address1;
    public String address2;
    public String city;
    public String stateOrProvince;
    public String nation;
    public String postalCode;
    public String employer;
    public String email;
    public String dayPhone;
    public String nightPhone;
    public String fax;
    public String firstName;
    public String surName;
    //public String groups;

    public String legacyPrimayKey;

    Hashtable newColumnValues;


    /**
    * ejbActivate method comment.
    */
    public void ejbActivate() throws java.rmi.RemoteException {
        UserProfileKey key =    (UserProfileKey) entityContext.getPrimaryKey();
        this.userName = key.userName;
        newColumnValues = new Hashtable();
    }


    /**
     * ejbCreate method comment for a CMP entity bean
     *
     */
    public void ejbCreate(java.lang.String key) throws javax.ejb.CreateException{

        //  All CMP  fields should be intialized here.
        userName = key;
        language=null;
        address1=null;
        address2 = null;
        city = null;
        stateOrProvince = null;
        nation = null;
        postalCode = null;
        employer = null;
        email = null;
        dayPhone = null;
        nightPhone = null;
        fax = null;
        firstName = null;
        //midName = null;
        surName = null;
        //groups = null;

        newColumnValues= new Hashtable();
    }


    /**
     * ejbLoad method comment.
     */
    public void ejbLoad () throws java.rmi.RemoteException {

    }




    /**
     * ejbPassivate method comment.
     */
    public void ejbPassivate() throws java.rmi.RemoteException {
        newColumnValues = null;
        language=null;
        address1=null;
        address2 = null;
        city = null;
        stateOrProvince = null;
        nation = null;
        postalCode = null;
        employer = null;
        email = null;
        dayPhone = null;
        nightPhone = null;
        fax = null;
        firstName = null;
        //midName = null;
        surName = null;
        //groups = null;
    }



    /**
     * ejbPostCreate method for a CMP entity bean
     */
    public void ejbPostCreate(java.lang.String key) throws java.rmi.RemoteException {
    }


    /**
     * ejbRemove method comment.
     */
    public void ejbRemove() throws java.rmi.RemoteException {
        newColumnValues = null;
    }


    /**
     * ejbStore method comment.
     */
    public void ejbStore () throws java.rmi.RemoteException {
    }


    /**
 * ejbCreate method comment for a CMP entity bean
 *
 */
    public void ejbCreate(java.lang.String key, String lKey) {

        //  All CMP  fields should be intialized here.
        userName = key;
        legacyPrimayKey=lKey; //not a CMP field

        language=null;
        address1=null;
        address2 = null;
        city = null;
        stateOrProvince = null;
        nation = null;
        postalCode = null;
        employer = null;
        email = null;
        dayPhone = null;
        nightPhone = null;
        fax = null;
        firstName = null;
        //midName = null;
        surName = null;
        //groups = null;

        newColumnValues= new Hashtable();
    }

    /**
      * ejbPostCreate method for a CMP entity bean
      */
    public void ejbPostCreate(java.lang.String key, String lKey) {
    }





    /**
      * Gets the user's first line of address.
      * 
      */
    public String getAddress1() {
        return address1;
    }


    /**
      * Gets the second line if the user's address.
      */
    public String getAddress2() {
        return address2;
    }



    /**
     * This is used to handle Columns added by Extending DataWrapper. 
    * If UserProfile enterprise bean is extended, extending datawrapper 
    * with UserProfileExtender for adding columns from datawrapper is
    * not supported.
    *
     * @param field java.lang.String
     */
    public Object getByType(String field) {

        return newColumnValues.get(field);
    }


    /**
      * Gets the user's country.
      */
    public String getNation() {
        return nation;
    }


    /**
      * Gets the user's daytime telephone number.
      */
    public String getDayPhone() {
        return dayPhone;
    }


    /**
      * Gets the user's e-mail address.
      */
    public String getEmail() {
        return email;
    }



    /**
      * Gets the name of the user's employer.
      */
    public String getEmployer() {
        return employer;
    }



    /**
      * Gets the user's fax number.
      */
    public String getFax() {
        return fax;
    }


    /**
     * Gets the user's first name.
     */
    public String getFirstName() {
        return firstName;
    }


    /**
     * Get the user's language of choice.
    */
    public String getLanguage() {
        return language;
    }


    /**
    *	Gets the user's sur name.
    */
    public String getSurName() {
        return surName;
    }

    /**
      * Gets the user's nighttime telephone number.
      */
    public String getNightPhone() {
        return nightPhone;
    }


    /**
      * Gets the user's state or province.
      */
    public String getStateOrProvince() {
        return stateOrProvince;
    }


    /**
      * Gets the user's town or city.
      */

    public String getCity() {
        return city;
    }


    /**
      * Gets the user's unique userName.
      */
    public String getUserName() {
        return userName;
    }


    /**
      * Gets the user's zip code or postal code.
      */
    public String getPostalCode() {
        return postalCode;
    }

    /**
      * Sets the first line of the user's street address.
      * @param value  New first line of the street address
      */
    public void setAddress1(String value) {
        address1 = value; 
    }


    /**
      * Sets the user's second street address.
      * @param value  New second line of the street address
      */
    public void setAddress2(String value) {
        address2 = value; 
    }
    /**
     * This method is used in handling columns added by  user by extending
    * datawrapper. If UserProfile enterprise bean is extended, extending 
    * datawrapper with UserProfileExtender for adding columns from datawrapper is
    * not supported.
    *
     * @param fieldName java.lang.String
     * @param value java.lang.String
     */
    public void setByType(String fieldName, Object value) {
        if ( fields.contains(fieldName) )
            throw new UserProfileException("Cannot update the field "+fieldName+" Using this method, Use its set method ");

        newColumnValues.put(fieldName,value);
    }
    /**
      * Sets the user's country.
      * @param value  New country
      */
    public void setNation(String value) {
        nation = value; 
    }


    /**
      * Sets the user's daytime telephone number.
      * @param value  New daytime telephone number
      */
    public  void setDayPhone(String value) {
        dayPhone = value; 
    }


    /**
      * Sets the user's e-mail address.
      * @param value  New e-mail address
      */

    public  void setEmail(String value) {
        email = value; 
    }
    /**
      * Sets the name of the user's employer.
      * @param value  New employer or company name
      */


    public void setEmployer(String value) {
        employer = value; 
    }
    /**
     * setEntityContext method comment.
     */
    public void setEntityContext(javax.ejb.EntityContext ctx) throws java.rmi.RemoteException {
        entityContext = ctx;
    }
    /**
      * Sets the user's fax number.
      * @param value  New fax number
      */
    public void setFax(String value) {
        fax = value; 
    }
    /**
      * Sets the user's first name.
      * @param value - New first name
      */
    public void setFirstName(String value) {
        firstName = value; 
    }

    /**
        Sets the user's language of choice.
        * @param value Language identifier
        */
    public void setLanguage(String value) {
        language = value; 
    }
    /**
        Sets the user's sur name.
        * @param value New sur name
        */
    public void setSurName(String value) {
        surName = value;
    }

    /**
      * Sets the user's nighttime telephone number.
      * @param value  New nighttime telephone number
      */
    public  void setNightPhone(String value) {
        nightPhone = value;
    }
    /**
      * Sets the user's state or province.
      * @param value  New state or province
      */
    public  void setStateOrProvince(String value) {
        stateOrProvince = value;
    }
    /**
      * Sets the user's town or city.
      * @param value  New town or city
      */
    public  void setCity(String value) {
        city = value;
    }

    /**
      * Sets the user's zip code or postal code.
      * @param value  New zip code or postal code
      */
    public  void setPostalCode(String value) {
        postalCode = value;
    }


    /**
     * unsetEntityContext method comment.
     */
    public void unsetEntityContext() throws java.rmi.RemoteException {
        entityContext = null;
    }


    /**
     * To update all the properties in a single method call. This is used
     * When userprofile is created/accessed with autoCommit = false;
     * i.e UserProfileManager.addUserProfile(String userName,boolean mode,boolean autoCommit)
     *     UserProfileManager.getUserProfile(String userName,boolean mode,boolean autoCommit)
     *
     *   @param address1  New first line of the street address 
     *   @param address2  New second line of the street address
     *   @param nation    New country
     *   @param dayPhone  New daytime telephone number
     *   @param email     New e-mail address
     *   @param employer  New employer or company name
     *   @param fax       New fax number
     *   @param firstName New first Name
     *   @param language  New Language
     *   @param surName   New Surname
     *   @param nightPhone New night-phone
     *   @param stateOrProvince new State Or Province
     *   @param city       New Town or City
     *   @param postalCode New postal code or zip
     *   @param newColumns New values of columns added by user by extending datawrapper
     *
     */
    public void sync(String address1, String address2, String nation,
                     String dayPhone,String email,String employer, String fax, String firstName,
                     String language, String surName, String nightPhone, String stateOrProvince,
                     String city, String postalCode, Hashtable newColumns) {

        //this.userName = userName;
        this.address1 =address1;
        this.address2= address2;
        this.nation= nation;
        this.dayPhone = dayPhone;
        this.email = email;
        this.employer= employer;
        this.fax=fax;
        this.firstName = firstName;
        this.language = language;
        this.surName = surName;
        this.nightPhone = nightPhone;
        this.city=city;
        this.postalCode=postalCode;
        this.stateOrProvince=stateOrProvince;

        if ( newColumns != null ) {
            Enumeration enum = newColumns.keys();
            while ( enum.hasMoreElements() ) {
                String key = (String) enum.nextElement();
                if ( fields.contains(key) )
                    throw new UserProfileException("Cannot update  the field inside hashtable, as it is duplicate field ");


                newColumnValues.put(key, newColumns.get(key));
            }

        }




    }

    /**
     * To get all the demographic properties in a single call.
     * Demographic properties are stored as key value pairs.
     * Getter methods are used as keys for storing 
     * demographic properties.For ex: for email, key used is
     * "getEmail".
     *
     */
    public Hashtable getAllProperties() throws RemoteException{
        Hashtable props = new Hashtable();

        props.put("newColumns",newColumnValues);

        //props.put("getUserName",userName); 
        if ( city != null )
            props.put("getCity",city);

        if ( dayPhone != null )
            props.put("getDayPhone",dayPhone);

        if ( email != null )
            props.put("getEmail",email);

        if ( employer != null )
            props.put("getEmployer",employer);

        if ( fax != null )
            props.put("getFax",fax);

        if ( firstName != null )
            props.put("getFirstName",firstName);

        if ( language != null )
            props.put("getLanguage",language);

        if ( nation != null )
            props.put("getNation",nation);

        if ( nightPhone != null )
            props.put("getNightPhone",nightPhone);

        if ( postalCode != null )
            props.put("getPostalCode",postalCode);

        if ( stateOrProvince != null )
            props.put("getStateOrProvince",stateOrProvince);

        if ( surName != null )
            props.put("getSurName",surName);

        if ( address1 != null )
            props.put("getAddress1",address1);

        if ( address2 != null )
            props.put("getAddress2",address2);


        return props;

    }


    void initializeFromPersistentStore(Hashtable h) {
        newColumnValues=h;
    }

    Hashtable getNewColumnValues() {
        return newColumnValues;
    }



}