All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.mmm.util.pojo.api.PojoFactory Maven / Gradle / Ivy

There is a newer version: 8.7.0
Show newest version
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0 */
package net.sf.mmm.util.pojo.api;

import net.sf.mmm.util.component.api.ComponentSpecification;
import net.sf.mmm.util.reflect.api.InstantiationFailedException;

/**
 * This is the interface for a generic factory used to {@link #newInstance(Class) create new instances} of
 * {@link net.sf.mmm.util.pojo.api.Pojo}s. 
* Typically a {@link net.sf.mmm.util.pojo.api.Pojo} has a public non-arg constructor. However there can be arbitrary * reasons why {@link Class#newInstance()} might NOT do it and you want some abstraction like this interface. Here are * just a few of them. *
    *
  • Reflection is NOT available (e.g. in GWT environments)
  • *
  • The provided {@link Class} is an {@link Class#isInterface() interface} such as {@link java.util.List}.
  • *
  • The provided {@link Class} does not have a non-arg constructor.
  • *
  • {@link Class#newInstance()} is throwing ugly checked exceptions.
  • *
  • You might need specific permissions to instantiate the provided {@link Class}.
  • *
* This library comes with simple implementations of {@link PojoFactory}. You might want to hide * objenesis behind this interface to combine its features with the * power of {@code mmm}. * * @author Joerg Hohwiller (hohwille at users.sourceforge.net) * @since 1.1.0 */ @ComponentSpecification public interface PojoFactory { /** * This method creates a new instance of the given {@code pojoType}.
* The simplest implementation may just delegate to {@link Class#newInstance()}. However implementations can solve * arbitrary problems such as if the given {@code pojoType} has no non-arg constructor, or it is an interface or * abstract class. * * @param is the generic type of the {@link net.sf.mmm.util.pojo.api.Pojo} to create. * @param pojoType is the {@link Class} reflecting the {@link net.sf.mmm.util.pojo.api.Pojo} to create. * @return the new instance of the given {@code pojoType}. * @throws InstantiationFailedException if the instantiation failed. */ POJO newInstance(Class pojoType) throws InstantiationFailedException; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy