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

cn.sylinx.hbatis.plugin.model.ModelPreloadPlugin Maven / Gradle / Ivy

There is a newer version: 2.0.0.RELEASE
Show newest version
package cn.sylinx.hbatis.plugin.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import cn.sylinx.hbatis.io.ClasspathResourceScanner;
import cn.sylinx.hbatis.log.GLog;
import cn.sylinx.hbatis.plugin.IPlugin;

public class ModelPreloadPlugin implements IPlugin {

	/**
	 * 扫描包路径
	 */
	private List scanPackageList;

	/**
	 * 指定类名称
	 */
	private Set clzSets;

	// 对象模型字段映射类
	private String acmStrategyClass;

	public List getScanPackageList() {
		return scanPackageList;
	}

	public void setScanPackageList(List scanPackageList) {
		this.scanPackageList = scanPackageList;
	}

	public String getAcmStrategyClass() {
		return acmStrategyClass;
	}

	public void setAcmStrategyClass(String acmStrategyClass) {
		this.acmStrategyClass = acmStrategyClass;
	}

	public Set getClzSets() {
		return clzSets;
	}

	public void setClzSets(Set clzSets) {
		this.clzSets = clzSets;
	}

	@Override
	public boolean start(Object... objects) {

		if (clzSets == null) {
			clzSets = new HashSet();
		}

		if (acmStrategyClass != null) {
			// 设置全局字段映射策略
			ModelConst.ME.setAcmStrategy(acmStrategyClass);
		}

		if (scanPackageList != null && !scanPackageList.isEmpty()) {

			for (String scanOnePackage : scanPackageList) {
				scanOnePackage(scanOnePackage);
			}
		}

		ModelCacheManager.get().init(clzSets);

		return true;
	}

	private void scanOnePackage(String scanPackage) {

		GLog.debug("扫描包[{}]...", scanPackage);
		ClasspathResourceScanner cp = new ClasspathResourceScanner(scanPackage, ".class", true);
		List rList = null;
		try {
			rList = cp.getResourceNameList();
		} catch (Exception e) {
		}

		if (rList == null) {
			rList = new ArrayList();
		}

		for (String rs : rList) {
			String pt1 = rs.replaceAll("/", "\\.");
			int index = pt1.lastIndexOf(".class");
			pt1 = pt1.substring(0, index);
			
			clzSets.add(pt1);
		}

	}

	@Override
	public boolean stop() {
		return true;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy