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