View Javadoc
1   /*
2    *    Copyright 2006-2026 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    *       https://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.Map;
19  import java.util.Properties;
20  
21  import org.jspecify.annotations.Nullable;
22  
23  public abstract class PropertyHolder {
24      private final Properties properties;
25  
26      protected PropertyHolder(AbstractBuilder<?> builder) {
27          properties = new Properties();
28          properties.putAll(builder.properties);
29      }
30  
31      public @Nullable String getProperty(String name) {
32          return properties.getProperty(name);
33      }
34  
35      public Properties getProperties() {
36          return properties;
37      }
38  
39      public abstract static class AbstractBuilder<T extends AbstractBuilder<T>> {
40          private final Properties properties = new Properties();
41  
42          @SuppressWarnings("UnusedReturnValue")
43          public T withProperty(Property property) {
44              properties.setProperty(property.name(), property.value());
45              return getThis();
46          }
47  
48          public T withProperties(Map<Object, Object> properties) {
49              this.properties.putAll(properties);
50              return getThis();
51          }
52  
53          protected abstract T getThis();
54      }
55  }