View Javadoc
1   /*
2    *    Copyright 2009-2023 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.apache.ibatis.reflection.factory;
17  
18  import java.util.List;
19  import java.util.Properties;
20  
21  /**
22   * MyBatis uses an ObjectFactory to create all needed new Objects.
23   *
24   * @author Clinton Begin
25   */
26  public interface ObjectFactory {
27  
28    /**
29     * Sets configuration properties.
30     *
31     * @param properties
32     *          configuration properties
33     */
34    default void setProperties(Properties properties) {
35      // NOP
36    }
37  
38    /**
39     * Creates a new object with default constructor.
40     *
41     * @param <T>
42     *          the generic type
43     * @param type
44     *          Object type
45     *
46     * @return the t
47     */
48    <T> T create(Class<T> type);
49  
50    /**
51     * Creates a new object with the specified constructor and params.
52     *
53     * @param <T>
54     *          the generic type
55     * @param type
56     *          Object type
57     * @param constructorArgTypes
58     *          Constructor argument types
59     * @param constructorArgs
60     *          Constructor argument values
61     *
62     * @return the t
63     */
64    <T> T create(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs);
65  
66    /**
67     * Returns true if this object can have a set of other objects. It's main purpose is to support
68     * non-java.util.Collection objects like Scala collections.
69     *
70     * @param <T>
71     *          the generic type
72     * @param type
73     *          Object type
74     *
75     * @return whether it is a collection or not
76     *
77     * @since 3.1.0
78     */
79    <T> boolean isCollection(Class<T> type);
80  
81  }