/* Copyright 2012-2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.snaker.jfinal.plugin;

import javax.sql.DataSource;

import org.snaker.engine.SnakerEngine;
import org.snaker.engine.cfg.Configuration;

import com.jfinal.plugin.IPlugin;
import com.jfinal.plugin.activerecord.IDataSourceProvider;

/**
 * 基于Jfinal的Snaker插件
 * 通过调用getEngine方法获取引擎的服务入口
 * @author yuqs
 * @since 2.0
 */
public class SnakerPlugin implements IPlugin {
	private static boolean isStarted = false;
	private static DataSource dataSource;
	private static IDataSourceProvider dataSourceProvider;
	private static SnakerEngine engine;
	
	/**
	 * 根据DataSource构造插件
	 * @param dataSource 数据源
	 */
	public SnakerPlugin(DataSource dataSource) {
		SnakerPlugin.dataSource = dataSource;
	}
	
	/**
	 * 根据数据源提供者构造插件
	 * @param dataSourceProvider 数据源提供接口
	 */
	public SnakerPlugin(IDataSourceProvider dataSourceProvider) {
		SnakerPlugin.dataSourceProvider = dataSourceProvider;
	}
	
	/**
	 * 启动插件
	 */
	public boolean start() {
		if (isStarted)
			return true;
		if (dataSourceProvider != null)
			dataSource = dataSourceProvider.getDataSource();
		if (dataSource == null)
			throw new RuntimeException("SnakerPlugin start error: SnakerPlugin need DataSource");
		engine = new Configuration()
			.initAccessDBObject(dataSource)
			.buildSnakerEngine();
		isStarted = true;
		return true;
	}
	
	/**
	 * 获取snaker的流程引擎
	 * @return
	 */
	public static SnakerEngine getEngine() {
		return engine;
	}

	/**
	 * 停止插件
	 */
	public boolean stop() {
		isStarted = false;
		return true;
	}
}

@@ -853,16 +853,46 @@
 vider;%0A%0A
+import java.util.Properties;%0A%0A
 /**%0A * %E5%9F%BA
@@ -1099,16 +1099,58 @@
 Source;%0A
+    private static Properties properties;%0A
 %09private
@@ -1377,24 +1377,264 @@
 taSource;%0A%09%7D
+%0A%0A    /**%0A     * %E6%A0%B9%E6%8D%AEDataSource%E6%9E%84%E9%80%A0%E6%8F%92%E4%BB%B6%0A     * @param dataSource %E6%95%B0%E6%8D%AE%E6%BA%90%0A     */%0A    public SnakerPlugin(DataSource dataSource, Properties properties) %7B%0A        SnakerPlugin.dataSource = dataSource;%0A        SnakerPlugin.properties = properties;%0A    %7D
 %0A%09%0A%09/**%0A%09 * 
@@ -2096,16 +2096,36 @@
 %22);%0A
-%09%09engine
+        Configuration config
  = n
@@ -2142,20 +2142,16 @@
 ration()
-%0A%09%09%09
 .initAcc
@@ -2173,20 +2173,101 @@
 aSource)
-%0A%09%09%09
+;%0A        if(properties != null) config.initProperties(properties);%0A%09%09engine = config
 .buildSn

version 2.4.0