<commit_before>package org.bpm.spring;

import org.bpm.common.exception.PlatformException;
import org.bpm.engine.BpmEngine;
import org.bpm.spring.cfg.BpmConfiguration;
import org.bpm.spring.cfg.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternUtils;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * 引擎工厂,生成各种service接口,及
 * Created by serv on 14-5-7.
 */
public class BpmEngineFactory implements FactoryBean<BpmEngine>, ApplicationContextAware,InitializingBean, DisposableBean,ResourceLoaderAware {


    protected final Logger log = LoggerFactory.getLogger(getClass());

    protected ApplicationContext applicationContext;

    private DataSource dataSource;

    private Properties properties;

    private PlatformTransactionManager transactionManager;

    /**
     * bpm服务提供者
     */
    protected BpmEngine bpmEngine;


    protected ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();

    /**
     * bpm 配置
     */
    protected Configuration configuration;


    public Configuration getConfiguration(){
        if(configuration==null){
            BpmConfiguration bpmConfiguration =  new BpmConfiguration();
            bpmConfiguration.setApplicationContext(applicationContext);
            bpmConfiguration.setTransactionManager(transactionManager);
            bpmConfiguration.setDataSource(dataSource);
            configuration = bpmConfiguration;
        }
        return this.configuration;
    }

    public void setConfiguration(Configuration configuration) {
        this.configuration = configuration;
    }




    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    public DataSource getDataSource() {
        return this.dataSource;
    }
    public PlatformTransactionManager getTransactionManager() {
        return transactionManager;
    }

    public void setTransactionManager(PlatformTransactionManager transactionManager) {
        this.transactionManager = transactionManager;
    }


    public Properties getProperties() {
        if (this.properties == null) {
            this.properties = new Properties();
        }
        return this.properties;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        BpmEngine be = buildBpmEngine();
        this.bpmEngine = wrapBpmEngineIfNecessary(be);
        afterBpmEngineCreation();
    }


    /**
     * 如果需要子类可以覆盖该方法,围绕be 进行一些自定义的事情
     * @param be bpmEngine
     * @return bpmEngine
     */
    protected BpmEngine wrapBpmEngineIfNecessary(BpmEngine be) {
        return be;
    }


    protected final BpmEngine getBpmEngine() {
        if (this.bpmEngine == null) {
            throw new IllegalStateException("BpmEngine 没有初始化");
        }
        return this.bpmEngine;
    }


    @Override
    public void destroy() throws PlatformException {
        log.info("销毁bpmEngine引擎!");
        try {
            beforeBpmEngineDestruction();
        }
        finally {
            this.bpmEngine.close();
        }
    }

    /**
     * 工厂对象
     */
    @Override
    public BpmEngine getObject() {
        return this.bpmEngine;
    }

    @Override
    public Class<BpmEngine> getObjectType() {
        return BpmEngine.class;
    }

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


    /**
     * 覆盖该方法来触发引擎创建之前的事件
     * @throws Exception
     */
    protected void afterBpmEngineCreation() throws Exception {
    }

    /**
     * 覆盖该方法来触发销毁的事件
     */
    protected void beforeBpmEngineDestruction() {
    }



    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
    }


    protected BpmEngine buildBpmEngine() throws Exception {
        Configuration cfg = getConfiguration();
        cfg.addProperties(getProperties());
        configuration = cfg;
        return buildBpmEngine(cfg);
    }

    private BpmEngine buildBpmEngine(Configuration cfg) {
        return cfg.buildBpmEngine();
    }


}<commit_msg>去掉无用的代码块<commit_after>package org.bpm.spring;

import org.bpm.common.exception.PlatformException;
import org.bpm.engine.BpmEngine;
import org.bpm.spring.cfg.BpmConfiguration;
import org.bpm.spring.cfg.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternUtils;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * 引擎工厂,生成各种service接口,及
 * Created by serv on 14-5-7.
 */
public class BpmEngineFactory implements FactoryBean<BpmEngine>, ApplicationContextAware,InitializingBean, DisposableBean,ResourceLoaderAware {


    protected final Logger log = LoggerFactory.getLogger(getClass());

    protected ApplicationContext applicationContext;

    private DataSource dataSource;

    private Properties properties;

    private PlatformTransactionManager transactionManager;

    /**
     * bpm服务提供者
     */
    protected BpmEngine bpmEngine;


    protected ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();

    /**
     * bpm 配置
     */
    protected Configuration configuration;


    public Configuration getConfiguration(){
        if(configuration==null){
            BpmConfiguration bpmConfiguration =  new BpmConfiguration();
            bpmConfiguration.setApplicationContext(applicationContext);
            bpmConfiguration.setTransactionManager(transactionManager);
            bpmConfiguration.setDataSource(dataSource);
            configuration = bpmConfiguration;
        }
        return this.configuration;
    }

    public void setConfiguration(Configuration configuration) {
        this.configuration = configuration;
    }




    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    public DataSource getDataSource() {
        return this.dataSource;
    }
    public PlatformTransactionManager getTransactionManager() {
        return transactionManager;
    }

    public void setTransactionManager(PlatformTransactionManager transactionManager) {
        this.transactionManager = transactionManager;
    }


    public Properties getProperties() {
        if (this.properties == null) {
            this.properties = new Properties();
        }
        return this.properties;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        BpmEngine be = buildBpmEngine();
        this.bpmEngine = wrapBpmEngineIfNecessary(be);
        afterBpmEngineCreation();
    }


    /**
     * 如果需要子类可以覆盖该方法,围绕be 进行一些自定义的事情
     * @param be bpmEngine
     * @return bpmEngine
     */
    protected BpmEngine wrapBpmEngineIfNecessary(BpmEngine be) {
        return be;
    }


    protected final BpmEngine getBpmEngine() {
        if (this.bpmEngine == null) {
            throw new IllegalStateException("BpmEngine 没有初始化");
        }
        return this.bpmEngine;
    }


    @Override
    public void destroy() throws PlatformException {
        log.info("销毁bpmEngine引擎!");
        try {
            beforeBpmEngineDestruction();
        }
        finally {
            this.bpmEngine.close();
        }
    }

    /**
     * 工厂对象
     */
    @Override
    public BpmEngine getObject() {
        return this.bpmEngine;
    }

    @Override
    public Class<BpmEngine> getObjectType() {
        return BpmEngine.class;
    }

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


    /**
     * 覆盖该方法来触发引擎创建之前的事件
     * @throws Exception
     */
    protected void afterBpmEngineCreation() throws Exception {
    }

    /**
     * 覆盖该方法来触发销毁的事件
     */
    protected void beforeBpmEngineDestruction() {
    }



    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
    }


    protected BpmEngine buildBpmEngine() throws Exception {
        configuration = getConfiguration();
        configuration.addProperties(getProperties());

        return buildBpmEngine(configuration);
    }

    private BpmEngine buildBpmEngine(Configuration cfg) {
        return cfg.buildBpmEngine();
    }


}
{'fraction_non_alphanumeric': 0.07882458056189814, 'fraction_numerical': 0.0011913034845626924, 'mean_word_length': 3.1490939044481054, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4333718', 'n_tokens_mistral': 2728, 'n_tokens_neox': 2655, 'n_words': 511}