KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > driver > DatabaseUser


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 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): Julie Marguerite.
22  * Contributor(s): Mathieu Peltier.
23  */

24
25 package org.objectweb.cjdbc.driver;
26
27 import java.io.Serializable JavaDoc;
28
29 /**
30  * A <code>DatabaseUser</code> is just a login/password combination to
31  * represent database user.
32  *
33  * @author <a HREF="mailto:Julie.Marguerite@inria.fr">Julie Marguerite</a>
34  * @author <a HREF="Mathieu.Peltier@inrialpes.fr">Mathieu Peltier</a>
35  * @version 1.0
36  */

37 public class DatabaseUser implements Serializable JavaDoc
38 {
39   private static final long serialVersionUID = 4733183236454586066L;
40
41   /** Virtual database name. */
42   private String JavaDoc dbName;
43
44   /** User name. */
45   private String JavaDoc login;
46
47   /** Password. */
48   private String JavaDoc password;
49
50   /**
51    * Creates a new <code>DatabaseUser</code> instance.
52    *
53    * @param dbName The virtual database name
54    * @param login User name
55    * @param password Password
56    */

57   public DatabaseUser(String JavaDoc dbName, String JavaDoc login, String JavaDoc password)
58   {
59     this.dbName = dbName;
60     this.login = login;
61     this.password = password;
62   }
63
64   /**
65    * Tests if the virtual database name login and password provided matches the
66    * virtual database name/login/password of this object.
67    *
68    * @param dbName virtual database name
69    * @param login a user name
70    * @param password a password
71    * @return <code>true</code> if it matches this object's virtual database
72    * name/login/password
73    */

74   public boolean matches(String JavaDoc dbName, String JavaDoc login, String JavaDoc password)
75   {
76     return (this.dbName.equals(dbName) && this.login.equals(login) && this.password
77         .equals(password));
78   }
79
80   /**
81    * Compares an object with this object.
82    *
83    * @param other an <code>Object</code>
84    * @return <code>true</code> if both objects have same virtual database
85    * name, login and password
86    */

87   public boolean equals(Object JavaDoc other)
88   {
89     if (!(other instanceof DatabaseUser))
90       return false;
91
92     DatabaseUser castOther = (DatabaseUser) other;
93     return matches(castOther.dbName, castOther.login, castOther.password);
94   }
95
96   /**
97    * Returns the virtual database name.
98    *
99    * @return database name
100    */

101   public String JavaDoc getDbName()
102   {
103     return dbName;
104   }
105
106   /**
107    * Gets the login name.
108    *
109    * @return login name
110    */

111   public String JavaDoc getLogin()
112   {
113     return login;
114   }
115
116   /**
117    * Gets the password.
118    *
119    * @return password
120    */

121   public String JavaDoc getPassword()
122   {
123     return password;
124   }
125 }
126
Popular Tags