FileDocCategorySizeDatePackage
MemoryUser.javaAPI DocExample7078Tue Jul 27 06:01:18 BST 2004org.apache.struts.webapp.example.memory

MemoryUser

public final class MemoryUser extends Object implements org.apache.struts.webapp.example.User

Concrete implementation of {@link User} for an in-memory database backed by an XML data file.

version
$Revision: 1.6 $ $Date: 2004/03/14 06:23:50 $
since
Struts 1.1

Fields Summary
private MemoryUserDatabase
database
The {@link UserDatabase} with which we are associated.
private HashMap
subscriptions
The {@link Subscription}s for this User, keyed by hostname.
private String
username
The username for this user.
private String
fromAddress
The email address from which messages are sent.
private String
fullName
The full name of this user, included in from addresses.
private String
password
The password (in clear text).
private String
replyToAddress
The EMAIL address to which replies should be sent.
Constructors Summary
public MemoryUser(MemoryUserDatabase database, String username)

Construct a new User associated with the specified {@link UserDatabase}.

param
database The user database with which we are associated
param
username The username of this user


        super();
        this.database = database;
        this.username = username;

    
Methods Summary
public org.apache.struts.webapp.example.SubscriptioncreateSubscription(java.lang.String host)
Create and return a new {@link Subscription} associated with this User, for the specified host name.

param
host Host name for which to create a subscription
exception
IllegalArgumentException if the host name is not unique for this user


        synchronized (subscriptions) {
            if (subscriptions.get(host) != null) {
                throw new IllegalArgumentException("Duplicate host '" + host
                                                   + "' for user '" +
                                                   username + "'");
            }
            MemorySubscription subscription =
                new MemorySubscription(this, host);
            synchronized (subscriptions) {
                subscriptions.put(host, subscription);
            }
            return (subscription);
        }

    
public org.apache.struts.webapp.example.SubscriptionfindSubscription(java.lang.String host)
Find and return the {@link Subscription} associated with the specified host. If none is found, return null.

param
host Host name to look up


        synchronized (subscriptions) {
            return ((Subscription) subscriptions.get(host));
        }

    
public org.apache.struts.webapp.example.UserDatabasegetDatabase()
The {@link UserDatabase} with which we are associated.



    // ------------------------------------------------------------- Properties


                 
       
        return (this.database);
    
public java.lang.StringgetFromAddress()


       
        return (this.fromAddress);
    
public java.lang.StringgetFullName()


       
        return (this.fullName);
    
public java.lang.StringgetPassword()


       
        return (this.password);
    
public java.lang.StringgetReplyToAddress()


       
        return (this.replyToAddress);
    
public org.apache.struts.webapp.example.Subscription[]getSubscriptions()
Find and return all {@link Subscription}s associated with this user. If there are none, a zero-length array is returned.


        synchronized (subscriptions) {
            Subscription results[] = new Subscription[subscriptions.size()];
            return ((Subscription[]) subscriptions.values().toArray(results));
        }

    
public java.lang.StringgetUsername()
The username (must be unique).

        return (this.username);
    
public voidremoveSubscription(org.apache.struts.webapp.example.Subscription subscription)
Remove the specified {@link Subscription} from being associated with this User.

param
subscription Subscription to be removed
exception
IllegalArgumentException if the specified subscription is not associated with this User


        if (!(this == subscription.getUser())) {
            throw new IllegalArgumentException
                ("Subscription not associated with this user");
        }
        synchronized (subscriptions) {
            subscriptions.remove(subscription.getHost());
        }

    
public voidsetFromAddress(java.lang.String fromAddress)

        this.fromAddress = fromAddress;
    
public voidsetFullName(java.lang.String fullName)

        this.fullName = fullName;
    
public voidsetPassword(java.lang.String password)

        this.password = password;
    
public voidsetReplyToAddress(java.lang.String replyToAddress)

        this.replyToAddress = replyToAddress;
    
public java.lang.StringtoString()
Return a String representation of this object.


        StringBuffer sb = new StringBuffer("<user username=\"");
        sb.append(username);
        sb.append("\"");
        if (fromAddress != null) {
            sb.append(" fromAddress=\"");
            sb.append(fromAddress);
            sb.append("\"");
        }
        if (fullName != null) {
            sb.append(" fullName=\"");
            sb.append(fullName);
            sb.append("\"");
        }
        if (password != null) {
            sb.append(" password=\"");
            sb.append(password);
            sb.append("\"");
        }
        if (replyToAddress != null) {
            sb.append(" replyToAddress=\"");
            sb.append(replyToAddress);
            sb.append("\"");
        }
        sb.append(">");
        return (sb.toString());