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

cn.sylinx.hbatis.plugin.PluginStarter Maven / Gradle / Ivy

The newest version!
package cn.sylinx.hbatis.plugin;

import java.util.List;

import cn.sylinx.hbatis.exception.HbatisException;
import cn.sylinx.hbatis.log.GLog;

public class PluginStarter {
	
	private List	pluginList	= null;
	
	private Object[]		params		= null;
	
	public PluginStarter() {
		
	}
	
	public PluginStarter(List pluginList) {
		this.pluginList = pluginList;
	}
	
	public PluginStarter(List pluginList, Object[] params) {
		this.pluginList = pluginList;
		this.params = params;
	}
	
	public void setPluginList(List pluginList) {
		this.pluginList = pluginList;
	}
	
	public boolean start() {
		
		if (pluginList != null) {
			
			for (IPlugin plugin : pluginList) {
				try {
					
					boolean success = plugin.start(params);
					if (!success) {
						String message = "Plugin start error: "
								+ plugin.getClass().getName();
						GLog.error(message);
						throw new HbatisException(message);
					} else {
						
						GLog.info("Plugin[{}] started", plugin.getClass().getName()); 
					}
					
				} catch (Exception e) {
					String message = "Plugin start error: "
							+ plugin.getClass().getName() + ". \n"
							+ e.getMessage();
					GLog.error(message, e);
					throw new HbatisException(message, e);
				}
			}
		}
		
		return true;
	}
	
	public boolean stop() {
		
		if (pluginList != null) {
			
			for (IPlugin plugin : pluginList) {
				try {
					
					boolean success = plugin.stop();
					if (!success) {
						String message = "Plugin stop error: "
								+ plugin.getClass().getName();
						GLog.error(message);
						throw new HbatisException(message);
					}
				} catch (Exception e) {
					String message = "Plugin stop error: "
							+ plugin.getClass().getName() + ". \n"
							+ e.getMessage();
					GLog.error(message, e);
					throw new HbatisException(message, e);
				}
			}
		}
		
		return false;
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy