com.iqiny.silly.spring.scan.ScanSillyFactory Maven / Gradle / Ivy
/*
* Copyright iqiny.com
*
* https://gitee.com/iqiny/silly
*
* project name:silly-spring
* project description:top silly project pom.xml file
*/
package com.iqiny.silly.spring.scan;
import com.iqiny.silly.common.util.SillyReflectUtil;
import com.iqiny.silly.core.base.SillyFactory;
import com.iqiny.silly.core.base.core.SillyMaster;
import com.iqiny.silly.core.base.core.SillyNode;
import com.iqiny.silly.core.base.core.SillyVariable;
import com.iqiny.silly.core.resume.SillyResume;
/**
* 通过扫描包 生产的实体工厂
*
* @param
* @param
* @param
* @param
*/
public class ScanSillyFactory, V extends SillyVariable, R extends SillyResume>
implements SillyFactory {
private final String category;
private Class masterClazz;
private Class nodeClazz;
private Class variableClazz;
private Class resumeClazz;
public ScanSillyFactory(String category) {
this.category = category;
}
@Override
public String usedCategory() {
return category;
}
@Override
public M newMaster() {
return SillyReflectUtil.newInstance(masterClazz);
}
@Override
public Class masterClass() {
return masterClazz;
}
@Override
public N newNode() {
return SillyReflectUtil.newInstance(nodeClazz);
}
@Override
public Class nodeClass() {
return nodeClazz;
}
@Override
public V newVariable() {
return SillyReflectUtil.newInstance(variableClazz);
}
@Override
public Class variableClass() {
return variableClazz;
}
@Override
public R newResume() {
return SillyReflectUtil.newInstance(resumeClazz);
}
@Override
public Class resumeClass() {
return resumeClazz;
}
public void setMasterClazz(Class masterClazz) {
this.masterClazz = masterClazz;
}
public void setNodeClazz(Class nodeClazz) {
this.nodeClazz = nodeClazz;
}
public void setVariableClazz(Class variableClazz) {
this.variableClazz = variableClazz;
}
public void setResumeClazz(Class resumeClazz) {
this.resumeClazz = resumeClazz;
}
@SuppressWarnings("all")
public void setEntityClazz(Class> clazz) {
if (SillyMaster.class.isAssignableFrom(clazz)) {
masterClazz = (Class) clazz;
} else if (SillyNode.class.isAssignableFrom(clazz)) {
nodeClazz = (Class) clazz;
} else if (SillyVariable.class.isAssignableFrom(clazz)) {
variableClazz = (Class) clazz;
} else if (SillyResume.class.isAssignableFrom(clazz)) {
resumeClazz = (Class) clazz;
}
}
@SuppressWarnings("all")
public void setDefaultClazz(ScanSillyFactory supportAll) {
if (masterClazz == null) {
masterClazz = supportAll.masterClazz;
}
if (nodeClazz == null) {
nodeClazz = supportAll.nodeClazz;
}
if (variableClazz == null) {
variableClazz = supportAll.variableClazz;
}
if (resumeClazz == null) {
resumeClazz = supportAll.resumeClazz;
}
}
}