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 java.util.Enumeration;
19  import java.util.Properties;
20  
21  import org.mybatis.generator.api.dom.xml.Attribute;
22  import org.mybatis.generator.api.dom.xml.XmlElement;
23  
24  /**
25   * @author Jeff Butler
26   */
27  public abstract class PropertyHolder {
28      private Properties properties;
29  
30      /**
31  	 *  
32  	 */
33      public PropertyHolder() {
34          super();
35          properties = new Properties();
36      }
37  
38      public void addProperty(String name, String value) {
39          properties.setProperty(name, value);
40      }
41  
42      public String getProperty(String name) {
43          return properties.getProperty(name);
44      }
45  
46      public Properties getProperties() {
47          return properties;
48      }
49  
50      protected void addPropertyXmlElements(XmlElement xmlElement) {
51          Enumeration<?> enumeration = properties.propertyNames();
52          while (enumeration.hasMoreElements()) {
53              String propertyName = (String) enumeration.nextElement();
54  
55              XmlElement propertyElement = new XmlElement("property"); //$NON-NLS-1$
56              propertyElement.addAttribute(new Attribute("name", propertyName)); //$NON-NLS-1$
57              propertyElement.addAttribute(new Attribute(
58                      "value", properties.getProperty(propertyName))); //$NON-NLS-1$
59              xmlElement.addElement(propertyElement);
60          }
61      }
62  }