View Javadoc
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.*;
25  
26  /**
27   * @author Manuel Laflamme
28   * @version $Revision$
29   * @since Feb 20, 2002
30   */
31  public class DatabaseProfile
32  {
33  	private static final String[] EMPTY_ARRAY = new String[0];
34  	
35      private static final String DATABASE_PROFILE = "dbunit.profile";
36      private static final String PROFILE_DRIVER_CLASS = "dbunit.profile.driverClass";
37      private static final String PROFILE_URL = "dbunit.profile.url";
38      private static final String PROFILE_SCHEMA = "dbunit.profile.schema";
39      private static final String PROFILE_USER = "dbunit.profile.user";
40      private static final String PROFILE_PASSWORD = "dbunit.profile.password";
41      private static final String PROFILE_UNSUPPORTED_FEATURES = "dbunit.profile.unsupportedFeatures";
42  
43      private final Properties _properties;
44  
45      public DatabaseProfile(Properties properties)
46      {
47          _properties = properties;
48  //        ArrayList keys = new ArrayList(properties.keySet());
49  //        for (int i = 0; i < keys.size(); i++) {
50  //            System.out.println("key = " + keys.get(i) + ", value = " + properties.get(keys.get(i)));
51  //        }
52  
53      }
54  
55      public String getActiveProfile()
56      {
57          return _properties.getProperty(DATABASE_PROFILE);
58      }
59  
60      public String getDriverClass()
61      {
62          return _properties.getProperty(PROFILE_DRIVER_CLASS);
63      }
64  
65      public String getConnectionUrl()
66      {
67          return _properties.getProperty(PROFILE_URL);
68      }
69  
70      public String getSchema()
71      {
72          return _properties.getProperty(PROFILE_SCHEMA, null);
73      }
74  
75      public String getUser()
76      {
77          return _properties.getProperty(PROFILE_USER);
78      }
79  
80      public String getPassword()
81      {
82          return _properties.getProperty(PROFILE_PASSWORD);
83      }
84  
85      public String[] getUnsupportedFeatures()
86      {
87          String property = _properties.getProperty(PROFILE_UNSUPPORTED_FEATURES);
88          
89          // If property is not set return an empty array
90          if(property == null){
91          	return EMPTY_ARRAY;
92          }
93          
94          List stringList = new ArrayList();
95          StringTokenizer tokenizer = new StringTokenizer(property, ",");
96          while(tokenizer.hasMoreTokens())
97          {
98              stringList.add(tokenizer.nextToken().trim());
99          }
100         return (String[])stringList.toArray(new String[stringList.size()]);
101     }
102 
103 }
104 
105 
106 
107 
108