View Javadoc
1   /**
2    *    Copyright 2009-2019 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.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     * @param properties configuration properties
31     */
32    default void setProperties(Properties properties) {
33      // NOP
34    }
35  
36    /**
37     * Creates a new object with default constructor.
38     * @param type Object type
39     * @return
40     */
41    <T> T create(Class<T> type);
42  
43    /**
44     * Creates a new object with the specified constructor and params.
45     * @param type Object type
46     * @param constructorArgTypes Constructor argument types
47     * @param constructorArgs Constructor argument values
48     * @return
49     */
50    <T> T create(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs);
51  
52    /**
53     * Returns true if this object can have a set of other objects.
54     * It's main purpose is to support non-java.util.Collection objects like Scala collections.
55     *
56     * @param type Object type
57     * @return whether it is a collection or not
58     * @since 3.1.0
59     */
60    <T> boolean isCollection(Class<T> type);
61  
62  }