KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > DatabaseProfile


1 /*
2  *
3  * The DbUnit Database Testing Framework
4  * Copyright (C)2002-2004, DbUnit.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */

21
22 package org.dbunit;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Properties JavaDoc;
27 import java.util.StringTokenizer JavaDoc;
28
29 /**
30  * @author Manuel Laflamme
31  * @version $Revision: 1.9 $
32  * @since Feb 20, 2002
33  */

34 public class DatabaseProfile
35 {
36     private static final String JavaDoc PROFILE_PREFIX = "dbunit.profile";
37
38     private static final String JavaDoc DRIVER_CLASS = "driverClass";
39     private static final String JavaDoc CONNECTION_URL = "connectionUrl";
40     private static final String JavaDoc SCHEMA = "schema";
41     private static final String JavaDoc USER = "user";
42     private static final String JavaDoc PASSWORD = "password";
43     private static final String JavaDoc UNSUPPORTED_FEATURES = "unsupportedFeatures";
44
45     private final Properties JavaDoc _properties;
46
47     public DatabaseProfile(Properties JavaDoc properties)
48     {
49         _properties = properties;
50     }
51
52     private String JavaDoc getPropertyKey(String JavaDoc name)
53     {
54         return PROFILE_PREFIX + "." + getActiveProfile() + "." + name;
55     }
56
57     public String JavaDoc getActiveProfile()
58     {
59         return _properties.getProperty(PROFILE_PREFIX);
60     }
61
62     public String JavaDoc getDriverClass()
63     {
64         return _properties.getProperty(getPropertyKey(DRIVER_CLASS));
65     }
66
67     public String JavaDoc getConnectionUrl()
68     {
69         return _properties.getProperty(getPropertyKey(CONNECTION_URL));
70     }
71
72     public String JavaDoc getSchema()
73     {
74         return _properties.getProperty(getPropertyKey(SCHEMA), null);
75     }
76
77     public String JavaDoc getUser()
78     {
79         return _properties.getProperty(getPropertyKey(USER));
80     }
81
82     public String JavaDoc getPassword()
83     {
84         return _properties.getProperty(getPropertyKey(PASSWORD));
85     }
86
87     public String JavaDoc[] getUnsupportedFeatures()
88     {
89         String JavaDoc property = _properties.getProperty(
90                 getPropertyKey(UNSUPPORTED_FEATURES));
91
92         List JavaDoc stringList = new ArrayList JavaDoc();
93         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(property, ",");
94         while(tokenizer.hasMoreTokens())
95         {
96             stringList.add(tokenizer.nextToken().trim());
97         }
98         return (String JavaDoc[])stringList.toArray(new String JavaDoc[0]);
99     }
100
101 }
102
103
104
105
106
107
Popular Tags