ObjectFactory.java

  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. import java.util.List;
  18. import java.util.Properties;

  19. /**
  20.  * MyBatis uses an ObjectFactory to create all needed new Objects.
  21.  *
  22.  * @author Clinton Begin
  23.  */
  24. public interface ObjectFactory {

  25.   /**
  26.    * Sets configuration properties.
  27.    *
  28.    * @param properties
  29.    *          configuration properties
  30.    */
  31.   default void setProperties(Properties properties) {
  32.     // NOP
  33.   }

  34.   /**
  35.    * Creates a new object with default constructor.
  36.    *
  37.    * @param <T>
  38.    *          the generic type
  39.    * @param type
  40.    *          Object type
  41.    *
  42.    * @return the t
  43.    */
  44.   <T> T create(Class<T> type);

  45.   /**
  46.    * Creates a new object with the specified constructor and params.
  47.    *
  48.    * @param <T>
  49.    *          the generic type
  50.    * @param type
  51.    *          Object type
  52.    * @param constructorArgTypes
  53.    *          Constructor argument types
  54.    * @param constructorArgs
  55.    *          Constructor argument values
  56.    *
  57.    * @return the t
  58.    */
  59.   <T> T create(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs);

  60.   /**
  61.    * Returns true if this object can have a set of other objects. It's main purpose is to support
  62.    * non-java.util.Collection objects like Scala collections.
  63.    *
  64.    * @param <T>
  65.    *          the generic type
  66.    * @param type
  67.    *          Object type
  68.    *
  69.    * @return whether it is a collection or not
  70.    *
  71.    * @since 3.1.0
  72.    */
  73.   <T> boolean isCollection(Class<T> type);

  74. }