001 package com.sptci.rwt;
002
003 import java.io.Serializable;
004
005 import com.sptci.util.AESEncrypt;
006
007 /**
008 * A simple bean used to represent different types of database engines
009 * that the application can connect to.
010 *
011 * <p>© Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
012 * @author Rakesh Vidyadharan 2007-09-24
013 * @version $Id: ConnectionData.java 4123 2008-05-25 21:49:01Z rakesh $
014 */
015 public class ConnectionData implements Serializable
016 {
017 /**
018 * The key used to encrypt {@link #password}.
019 */
020 private static final String PASSWORD_KEY = ")4m&s#R4s0%c*c(m";
021
022 /**
023 * The fully qualified hostname of the database server to connect to.
024 */
025 private String host;
026
027 /**
028 * The name of the database to connect to.
029 */
030 private String database;
031
032 /**
033 * The port to connect to.
034 */
035 private int port;
036
037 /**
038 * The database user to connect as.
039 */
040 private String userName;
041
042 /**
043 * The password for the database user to connect as.
044 */
045 private byte[] password;
046
047 /**
048 * Default constructor. Not publicly instantiable.
049 */
050 protected ConnectionData() {}
051
052 /**
053 * Returns {@link #host}.
054 *
055 * @return The value/reference of/to host.
056 */
057 public String getHost()
058 {
059 return host;
060 }
061
062 /**
063 * Set {@link #host}.
064 *
065 * @param host The value to set.
066 */
067 protected void setHost( final String host )
068 {
069 this.host = host;
070 }
071
072 /**
073 * Returns {@link #database}.
074 *
075 * @return The value/reference of/to database.
076 */
077 public String getDatabase()
078 {
079 return database;
080 }
081
082 /**
083 * Set {@link #database}.
084 *
085 * @param database The value to set.
086 */
087 protected void setDatabase( final String database )
088 {
089 this.database = database;
090 }
091
092 /**
093 * Returns {@link #port}.
094 *
095 * @return The value/reference of/to port.
096 */
097 public int getPort()
098 {
099 return port;
100 }
101
102 /**
103 * Set {@link #port}.
104 *
105 * @param port The value to set.
106 */
107 protected void setPort( final int port )
108 {
109 this.port = port;
110 }
111
112 /**
113 * Returns {@link #userName}.
114 *
115 * @return The value/reference of/to userName.
116 */
117 public String getUserName()
118 {
119 return userName;
120 }
121
122 /**
123 * Set {@link #userName}.
124 *
125 * @param userName The value to set.
126 */
127 protected void setUserName( final String userName )
128 {
129 this.userName = userName;
130 }
131
132 /**
133 * Returns {@link #password}.
134 *
135 * @return The value/reference of/to password.
136 * @throws RuntimeException If the password value cannot be decrypted.
137 */
138 public String getPassword() throws RuntimeException
139 {
140 try
141 {
142 return new AESEncrypt().decrypt( PASSWORD_KEY, password );
143 }
144 catch ( Throwable t )
145 {
146 throw new RuntimeException( "Error decrypting password.", t );
147 }
148 }
149
150 /**
151 * Set {@link #password}.
152 *
153 * @param password The value to set.
154 * @throws RuntimeException If errors are encountered while encrypting the
155 * <code>password</code> value.
156 */
157 protected void setPassword( final String password ) throws RuntimeException
158 {
159 try
160 {
161 this.password = new AESEncrypt().encrypt( PASSWORD_KEY, password );
162 }
163 catch ( Throwable t )
164 {
165 throw new RuntimeException( "Error encrypting password.", t );
166 }
167 }
168 }