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

pro.jk.ejoker.common.context.dev2.EJokerInstanceBuilder Maven / Gradle / Ivy

There is a newer version: 3.0.7.1
Show newest version
package pro.jk.ejoker.common.context.dev2;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import pro.jk.ejoker.common.context.ContextRuntimeException;
import pro.jk.ejoker.common.system.enhance.StringUtilx;
import pro.jk.ejoker.common.system.functional.IVoidFunction1;

public class EJokerInstanceBuilder {
	
	private final static Logger logger = LoggerFactory.getLogger(EJokerInstanceBuilder.class);

	private final Class clazz;
	
	public EJokerInstanceBuilder(Class clazz) {
		this.clazz = clazz;
	}
	
	public Object doCreate(IVoidFunction1 afterEffector) {
		Object newInstance;
		try {
			newInstance = clazz.newInstance();
		} catch (InstantiationException | IllegalAccessException ex) {
			String errInfo = StringUtilx.fmt("Cannot create new instance!!! [type: {}]", clazz.getName());
			logger.error(errInfo, ex);
			throw new ContextRuntimeException(errInfo, ex);
		}
		afterEffector.trigger(newInstance);
		return newInstance;
	}

}