KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > repository > DjRepositoryDescriptor


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, is permitted
5  * provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice, this list of conditions
7  * and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * - All advertising materials mentioning features or use of this software must display the
12  * following acknowledgment: "This product includes Djeneric."
13  * - Products derived from this software may not be called "Djeneric" nor may
14  * "Djeneric" appear in their names without prior written permission of Genimen BV.
15  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
16  * product includes Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.repository;
31
32 /**
33  * Description of the Class
34  *
35  *@author Wido Riezebos
36  *@created 10 jan 2002
37  */

38 public class DjRepositoryDescriptor implements Comparable JavaDoc, Cloneable JavaDoc
39 {
40   public static final String JavaDoc JNDI_DATASOURCE_KEY = "jndi";
41   public static final String JavaDoc TEXTUAL_JNDI_DATASOURCE_KEY = "[JNDI Datasource]";
42   String JavaDoc _name;
43   String JavaDoc _driver;
44   String JavaDoc _url;
45   String JavaDoc _location;
46   String JavaDoc _user = null;
47   String JavaDoc _password = null;
48   String JavaDoc _sharedUser = "";
49   String JavaDoc _sharedPassword = "";
50   boolean _sharedConnection = false;
51   int _traceLevel = DjPersistenceManager.TRACE_NOTHING;
52
53   /**
54    * Constructor for the DjRepositoryDescriptor object
55    *
56    *@param name Description of the Parameter
57    *@param location Description of the Parameter
58    *@param driver Description of the Parameter
59    *@param url Description of the Parameter
60    */

61   public DjRepositoryDescriptor(String JavaDoc name, String JavaDoc location, String JavaDoc driver, String JavaDoc url)
62   {
63     _name = name;
64     _location = location;
65     _driver = driver;
66     _url = url;
67     _sharedConnection = false;
68   }
69
70   /**
71    * Description of the Method
72    *
73    *@return Description of the Return Value
74    */

75   public Object JavaDoc clone()
76   {
77     DjRepositoryDescriptor nrd = new DjRepositoryDescriptor(getName(), getRepositoryLocation(), getDriver(), getUrl());
78     nrd.setSharedConnection(isSharedConnection());
79     nrd.setSharedPassword(getSharedPassword());
80     nrd.setSharedUser(getSharedUser());
81
82     return nrd;
83   }
84
85   /**
86    * Sets the sharedConnection of the DjRepositoryDescriptor object
87    *
88    *@param isShared The new sharedConnection value
89    */

90   public void setSharedConnection(boolean isShared)
91   {
92     _sharedConnection = isShared;
93   }
94
95   /**
96    * Returns the sharedConnection of the DjRepositoryDescriptor object
97    *
98    *@return The sharedConnection value
99    */

100   public boolean isSharedConnection()
101   {
102     return _sharedConnection;
103   }
104
105   /**
106    * Returns the name of the DjRepositoryDescriptor object
107    *
108    *@return The name value
109    */

110   public String JavaDoc getName()
111   {
112     return _name;
113   }
114
115   /**
116    * Sets the name of the DjRepositoryDescriptor object
117    *
118    *@param name The new name value
119    */

120   public void setName(String JavaDoc name)
121   {
122     _name = name;
123   }
124
125   /**
126    * Sets the traceLevel of the DjRepositoryDescriptor object
127    *
128    *@param level The new traceLevel value
129    */

130   public void setTraceLevel(int level)
131   {
132     _traceLevel = level;
133   }
134
135   /**
136    * Returns the traceLevel of the DjRepositoryDescriptor object
137    *
138    *@return The traceLevel value
139    */

140   public int getTraceLevel()
141   {
142     return _traceLevel;
143   }
144
145   /**
146    * Returns the repositoryLocation of the DjRepositoryDescriptor object
147    *
148    *@return The repositoryLocation value
149    */

150   public String JavaDoc getRepositoryLocation()
151   {
152     return _location;
153   }
154
155   /**
156    * Sets the repositoryLocation of the DjRepositoryDescriptor object
157    *
158    *@param location The new repositoryLocation value
159    */

160   public void setRepositoryLocation(String JavaDoc location)
161   {
162     _location = location;
163   }
164
165   /**
166    * Returns the driver of the DjRepositoryDescriptor object
167    *
168    *@return The driver value
169    */

170   public String JavaDoc getDriver()
171   {
172     return _driver;
173   }
174
175   /**
176    * Sets the driver of the DjRepositoryDescriptor object
177    *
178    *@param driver The new driver value
179    */

180   public void setDriver(String JavaDoc driver)
181   {
182     _driver = driver;
183   }
184
185   /**
186    * Returns the url of the DjRepositoryDescriptor object
187    *
188    *@return The url value
189    */

190   public String JavaDoc getUrl()
191   {
192     return _url;
193   }
194
195   /**
196    * Sets the url of the DjRepositoryDescriptor object
197    *
198    *@param url The new url value
199    */

200   public void setUrl(String JavaDoc url)
201   {
202     _url = url;
203   }
204
205   /**
206    * Sets the user of the DjRepositoryDescriptor object
207    *
208    *@param user The new user value
209    */

210   public void setUser(String JavaDoc user)
211   {
212     _user = user;
213   }
214
215   /**
216    * Returns the user of the DjRepositoryDescriptor object
217    *
218    *@return The user value
219    */

220   public String JavaDoc getUser()
221   {
222     return _user;
223   }
224
225   /**
226    * Sets the password of the DjRepositoryDescriptor object
227    *
228    *@param password The new password value
229    */

230   public void setPassword(String JavaDoc password)
231   {
232     _password = password;
233   }
234
235   /**
236    * Returns the password of the DjRepositoryDescriptor object
237    *
238    *@return The password value
239    */

240   public String JavaDoc getPassword()
241   {
242     return _password;
243   }
244
245   // The following sharedXX setters/getters are for use with a
246
// shared connection
247
/**
248    * Sets the sharedUser of the DjRepositoryDescriptor object
249    *
250    *@param user The new sharedUser value
251    */

252   public void setSharedUser(String JavaDoc user)
253   {
254     _sharedUser = user;
255   }
256
257   /**
258    * Returns the sharedUser of the DjRepositoryDescriptor object
259    *
260    *@return The sharedUser value
261    */

262   public String JavaDoc getSharedUser()
263   {
264     return _sharedUser;
265   }
266
267   /**
268    * Sets the sharedPassword of the DjRepositoryDescriptor object
269    *
270    *@param password The new sharedPassword value
271    */

272   public void setSharedPassword(String JavaDoc password)
273   {
274     _sharedPassword = password;
275   }
276
277   /**
278    * Returns the sharedPassword of the DjRepositoryDescriptor object
279    *
280    *@return The sharedPassword value
281    */

282   public String JavaDoc getSharedPassword()
283   {
284     return _sharedPassword;
285   }
286
287   /**
288    * Description of the Method
289    *
290    *@param obj Description of the Parameter
291    *@return Description of the Return Value
292    */

293   public boolean equals(Object JavaDoc obj)
294   {
295     if (!(obj instanceof DjRepositoryDescriptor)) return false;
296     DjRepositoryDescriptor r = (DjRepositoryDescriptor) obj;
297
298     return getName().equals(r.getName()) && getDriver().equals(r.getDriver())
299            && getRepositoryLocation().equals(r.getRepositoryLocation()) && getSharedUser().equals(r.getSharedUser())
300            && getSharedPassword().equals(r.getSharedPassword()) && isSharedConnection() == r.isSharedConnection()
301            && getUrl().equals(r.getUrl());
302   }
303
304   public int hashCode()
305   {
306     return getName().hashCode();
307   }
308
309   /**
310    * Description of the Method
311    *
312    *@param obj Description of the Parameter
313    *@return Description of the Return Value
314    */

315   public int compareTo(Object JavaDoc obj)
316   {
317     if (!(obj instanceof DjRepositoryDescriptor)) return -1;
318     DjRepositoryDescriptor r = (DjRepositoryDescriptor) obj;
319
320     return getName().toLowerCase().compareTo(r.getName().toLowerCase());
321   }
322
323   /**
324    * Description of the Method
325    *
326    *@return Description of the Return Value
327    */

328   public String JavaDoc toString()
329   {
330     return getName();
331   }
332
333   /**
334    * @return True if the definition of the repository is in a Datasource
335    */

336   public boolean isDatasource()
337   {
338     return JNDI_DATASOURCE_KEY.equals(getDriver()) || TEXTUAL_JNDI_DATASOURCE_KEY.equals(getDriver());
339   }
340
341 }
Popular Tags