KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > common > users > AbstractDatabaseUser


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): ______________________________________.
23  */

24
25 package org.objectweb.cjdbc.common.users;
26
27 import java.io.Serializable JavaDoc;
28 import java.security.Principal JavaDoc;
29
30 /**
31  * An <code>AbstractDatabaseUser</code> is just a login/password combination
32  * to represent an abstract database user.
33  *
34  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
35  * @version 1.0
36  */

37 public abstract class AbstractDatabaseUser implements Serializable JavaDoc, Principal JavaDoc
38 {
39   /** Login name. */
40   protected String JavaDoc login;
41
42   /** Password. */
43   protected String JavaDoc password;
44
45   /**
46    * Creates a new <code>AbstractDatabaseUser</code> instance. The caller must
47    * ensure that the parameters are not <code>null</code>.
48    *
49    * @param login the user name.
50    * @param password the password.
51    */

52   protected AbstractDatabaseUser(String JavaDoc login, String JavaDoc password)
53   {
54     this.login = login;
55     this.password = password;
56   }
57
58   /**
59    * Gets the login name.
60    *
61    * @return the login name.
62    */

63   public String JavaDoc getLogin()
64   {
65     return login;
66   }
67
68   /**
69    * Gets the login name.
70    *
71    * @return the login name.
72    */

73   public String JavaDoc getName()
74   {
75     return getLogin();
76   }
77
78   /**
79    * Gets the password.
80    *
81    * @return the password.
82    */

83   public String JavaDoc getPassword()
84   {
85     return password;
86   }
87
88   /**
89    * Tests if the login and password provided matches the login/password of this
90    * object.
91    *
92    * @param login a user name.
93    * @param password a password.
94    * @return <code>true</code> if it matches this object's login/password.
95    */

96   public boolean matches(String JavaDoc login, String JavaDoc password)
97   {
98     return (this.login.equals(login) && this.password.equals(password));
99   }
100
101   /**
102    * Two <code>AbstractDatabaseUser</code> are equals if both objects have
103    * same login & password.
104    *
105    * @param other the object to compare with.
106    * @return <code>true</code> if both objects have same login & password.
107    */

108   public boolean equals(Object JavaDoc other)
109   {
110     if ((other == null) || !(other instanceof AbstractDatabaseUser))
111       return false;
112
113     AbstractDatabaseUser user = (AbstractDatabaseUser) other;
114     return matches(user.login, user.password);
115   }
116
117   /**
118    * @see org.objectweb.cjdbc.common.xml.XmlComponent#getXml()
119    */

120   public abstract String JavaDoc getXml();
121 }
122
Popular Tags