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      private static final String PROFILE_DDL = "dbunit.profile.ddl";
43      private static final String PROFILE_MULTILINE_SUPPORT = "dbunit.profile.multiLineSupport";
44  
45      private final Properties _properties;
46  
47      public DatabaseProfile(Properties properties)
48      {
49          _properties = properties;
50  //        ArrayList keys = new ArrayList(properties.keySet());
51  //        for (int i = 0; i < keys.size(); i++) {
52  //            System.out.println("key = " + keys.get(i) + ", value = " + properties.get(keys.get(i)));
53  //        }
54  
55      }
56  
57      public String getActiveProfile()
58      {
59          return _properties.getProperty(DATABASE_PROFILE);
60      }
61  
62      public String getDriverClass()
63      {
64          return _properties.getProperty(PROFILE_DRIVER_CLASS);
65      }
66  
67      public String getConnectionUrl()
68      {
69          return _properties.getProperty(PROFILE_URL);
70      }
71  
72      public String getSchema()
73      {
74          return _properties.getProperty(PROFILE_SCHEMA, null);
75      }
76  
77      public String getUser()
78      {
79          return _properties.getProperty(PROFILE_USER);
80      }
81  
82      public String getPassword()
83      {
84          return _properties.getProperty(PROFILE_PASSWORD);
85      }
86  
87      public String getProfileDdl()
88      {
89          return _properties.getProperty(PROFILE_DDL);
90      }
91  
92      public boolean getProfileMultilineSupport()
93      {
94          return Boolean.valueOf(_properties.getProperty(PROFILE_MULTILINE_SUPPORT));
95      }
96  
97      public String[] getUnsupportedFeatures()
98      {
99          String property = _properties.getProperty(PROFILE_UNSUPPORTED_FEATURES);
100         
101         // If property is not set return an empty array
102         if(property == null){
103         	return EMPTY_ARRAY;
104         }
105         
106         List<String> stringList = new ArrayList<String>();
107         StringTokenizer tokenizer = new StringTokenizer(property, ",");
108         while(tokenizer.hasMoreTokens())
109         {
110             stringList.add(tokenizer.nextToken().trim());
111         }
112         return stringList.toArray(new String[stringList.size()]);
113     }
114 
115 }