View Javadoc
1   /**
2    *    Copyright 2006-2016 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.generator.config;
17  
18  import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
19  import static org.mybatis.generator.internal.util.messages.Messages.getString;
20  
21  import java.util.List;
22  
23  import org.mybatis.generator.api.dom.xml.Attribute;
24  import org.mybatis.generator.api.dom.xml.XmlElement;
25  
26  /**
27   * 
28   * @author Jeff Butler
29   */
30  public class JDBCConnectionConfiguration extends PropertyHolder {
31  
32      private String driverClass;
33  
34      private String connectionURL;
35  
36      private String userId;
37  
38      private String password;
39  
40      public JDBCConnectionConfiguration() {
41          super();
42      }
43  
44      public String getConnectionURL() {
45          return connectionURL;
46      }
47  
48      public void setConnectionURL(String connectionURL) {
49          this.connectionURL = connectionURL;
50      }
51  
52      public String getPassword() {
53          return password;
54      }
55  
56      public void setPassword(String password) {
57          this.password = password;
58      }
59  
60      public String getUserId() {
61          return userId;
62      }
63  
64      public void setUserId(String userId) {
65          this.userId = userId;
66      }
67  
68      public String getDriverClass() {
69          return driverClass;
70      }
71  
72      public void setDriverClass(String driverClass) {
73          this.driverClass = driverClass;
74      }
75  
76      public XmlElement toXmlElement() {
77          XmlElement xmlElement = new XmlElement("jdbcConnection"); //$NON-NLS-1$
78          xmlElement.addAttribute(new Attribute("driverClass", driverClass)); //$NON-NLS-1$
79          xmlElement.addAttribute(new Attribute("connectionURL", connectionURL)); //$NON-NLS-1$
80  
81          if (stringHasValue(userId)) {
82              xmlElement.addAttribute(new Attribute("userId", userId)); //$NON-NLS-1$
83          }
84  
85          if (stringHasValue(password)) {
86              xmlElement.addAttribute(new Attribute("password", password)); //$NON-NLS-1$
87          }
88  
89          addPropertyXmlElements(xmlElement);
90  
91          return xmlElement;
92      }
93  
94      public void validate(List<String> errors) {
95          if (!stringHasValue(driverClass)) {
96              errors.add(getString("ValidationError.4")); //$NON-NLS-1$
97          }
98  
99          if (!stringHasValue(connectionURL)) {
100             errors.add(getString("ValidationError.5")); //$NON-NLS-1$
101         }
102     }
103 }