1   /*
2    * Created by IntelliJ IDEA.
3    * User: owen
4    * Date: Nov 22, 2002
5    * Time: 3:33:27 PM
6    * CVS Revision: $Revision: 1.6 $
7    * Last CVS Commit: $Date: 2006/09/29 02:48:01 $
8    * Author of last CVS Commit: $Author: cowen $
9    * To change this template use Options | File Templates.
10   */
11  package com.atlassian.mail.server;
12  
13  import com.opensymphony.util.TextUtils;
14  import org.apache.commons.lang.builder.ToStringBuilder;
15  import org.apache.log4j.Category;
16  
17  import java.io.Serializable;
18  import java.io.ObjectInputStream;
19  import java.io.IOException;
20  
21  public abstract class AbstractMailServer implements MailServer, Serializable
22  {
23      protected transient Category LOG = Category.getInstance(this.getClass());
24  
25      private Long id;
26      private String name;
27      private String description;
28      private String hostname;
29      private String username = null;
30      private String password = null;
31  
32      public AbstractMailServer()
33      {
34      }
35  
36      public AbstractMailServer(Long id, String name, String description, String hostName, String username, String password)
37      {
38          setId(id);
39          setName(name);
40          setDescription(description);
41          setHostname(hostName);
42          setUsername(username);
43          setPassword(password);
44      }
45  
46      public Long getId()
47      {
48          return id;
49      }
50  
51      public void setId(Long id)
52      {
53          this.id = id;
54          propertyChanged();
55      }
56  
57      public String getName()
58      {
59          return name;
60      }
61  
62      public void setName(String name)
63      {
64          this.name = name;
65          propertyChanged();
66      }
67  
68      public String getDescription()
69      {
70          return description;
71      }
72  
73      public void setDescription(String description)
74      {
75          this.description = description;
76          propertyChanged();
77      }
78  
79      public String getHostname()
80      {
81          return hostname;
82      }
83  
84      public void setHostname(String serverName)
85      {
86          this.hostname = serverName;
87          propertyChanged();
88      }
89  
90      public String getUsername()
91      {
92          return username;
93      }
94  
95      public void setUsername(String username)
96      {
97          if (TextUtils.stringSet(username))
98              this.username = username;
99          else
100             this.username = null;
101         propertyChanged();
102     }
103 
104     public String getPassword()
105     {
106         return password;
107     }
108 
109     public void setPassword(String password)
110     {
111         if (TextUtils.stringSet(password))
112             this.password = password;
113         else
114             this.password = null;
115         propertyChanged();
116     }
117 
118     ///CLOVER:OFF
119     public boolean equals(Object o)
120     {
121         if (this == o) return true;
122         if (!(o instanceof AbstractMailServer)) return false;
123 
124         final AbstractMailServer abstractMailServer = (AbstractMailServer) o;
125 
126         if (description != null ? !description.equals(abstractMailServer.description) : abstractMailServer.description != null) return false;
127         if (id != null ? !id.equals(abstractMailServer.id) : abstractMailServer.id != null) return false;
128         if (name != null ? !name.equals(abstractMailServer.name) : abstractMailServer.name != null) return false;
129         if (password != null ? !password.equals(abstractMailServer.password) : abstractMailServer.password != null) return false;
130         if (hostname != null ? !hostname.equals(abstractMailServer.hostname) : abstractMailServer.hostname != null) return false;
131         if (username != null ? !username.equals(abstractMailServer.username) : abstractMailServer.username != null) return false;
132 
133         return true;
134     }
135 
136     public int hashCode()
137     {
138         int result;
139         result = (id != null ? id.hashCode() : 0);
140         result = 29 * result + (name != null ? name.hashCode() : 0);
141         result = 29 * result + (description != null ? description.hashCode() : 0);
142         result = 29 * result + (hostname != null ? hostname.hashCode() : 0);
143         result = 29 * result + (username != null ? username.hashCode() : 0);
144         result = 29 * result + (password != null ? password.hashCode() : 0);
145         return result;
146     }
147 
148     public String toString()
149     {
150         return new ToStringBuilder(this).append("id", id).append("name", name).append("description", description).append("server name", hostname).append("username", username).append("password", password).toString();
151     }
152 
153     /**
154      * Call this method whenever a property of the server changes.
155      * Subclasses should override it to clear any cached information.
156      */
157     protected void propertyChanged()
158     {
159 
160     }
161 
162     private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException
163     {
164         ois.defaultReadObject();
165         LOG = Category.getInstance(this.getClass());
166     }
167 }