<commit_before>/*
 *
 *  * Copyright 2002-2007 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.suren.autotest.web.framework.settings;

import org.dom4j.*;
import org.dom4j.io.SAXReader;
import org.dom4j.xpath.DefaultXPath;
import org.jaxen.SimpleNamespaceContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.suren.autotest.web.framework.AutoApplication;
import org.suren.autotest.web.framework.annotation.AutoDataSource;
import org.suren.autotest.web.framework.annotation.AutoLocator;
import org.suren.autotest.web.framework.annotation.AutoPage;
import org.suren.autotest.web.framework.core.*;
import org.suren.autotest.web.framework.core.ui.AbstractElement;
import org.suren.autotest.web.framework.core.ui.Text;
import org.suren.autotest.web.framework.data.*;
import org.suren.autotest.web.framework.hook.ShutdownHook;
import org.suren.autotest.web.framework.page.Page;
import org.suren.autotest.web.framework.selenium.SeleniumEngine;
import org.suren.autotest.web.framework.spring.AutotestScope;
import org.suren.autotest.web.framework.util.BeanUtil;
import org.suren.autotest.web.framework.util.StringUtils;
import org.suren.autotest.web.framework.validation.Validation;
import org.xml.sax.SAXException;

import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;

/**
 * 页面（page）以及数据配置加载
 * @author suren
 * @date Jul 17, 2016 9:01:51 AM
 */
public class SettingUtil implements Closeable
{
	private static final Logger logger = LoggerFactory.getLogger(SettingUtil.class);
	
	private Map<String, Page>			pageMap	= new HashMap<String, Page>();
	private Map<String, DataSourceInfo>	dataSourceMap = new HashMap<String, DataSourceInfo>();
	private Map<String, DynamicDataSource> dynamicDataSourceMap;
	private ApplicationContext			context;
	private ShutdownHook shutdownHook;
	
	/** 系统配置路径 */
	private File configFile;
	
	private boolean closed = false;
	
	/** 不希望被加载数据的Page集合 */
	private Set<String> excludePageSet = new HashSet<String>();

	/**
	 * 初始化bean容器，初始化上下文对象，增加JMX管理模块，增加程序关闭钩子。
	 */
	public SettingUtil(Class<?> ... annotatedClasses)
	{
		context = SpringUtils.getApplicationContext();
		if(context == null || !((AbstractApplicationContext) context).isActive())
		{
		    if(annotatedClasses == null)
			{
				annotatedClasses = new Class[]{AutoApplication.class};
			}
			else
			{
			    int len = annotatedClasses.length;
				annotatedClasses = Arrays.copyOf(annotatedClasses, len + 1);
				annotatedClasses[len] = AutoApplication.class;
			}
			context = new AnnotationConfigApplicationContext(annotatedClasses);<commit_msg>代码整理；<commit_after>/*
 *
 *  * Copyright 2002-2007 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.suren.autotest.web.framework.settings;

import org.dom4j.*;
import org.dom4j.io.SAXReader;
import org.dom4j.xpath.DefaultXPath;
import org.jaxen.SimpleNamespaceContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.suren.autotest.web.framework.AutoApplicationConfig;
import org.suren.autotest.web.framework.annotation.AutoDataSource;
import org.suren.autotest.web.framework.annotation.AutoLocator;
import org.suren.autotest.web.framework.annotation.AutoPage;
import org.suren.autotest.web.framework.core.*;
import org.suren.autotest.web.framework.core.ui.AbstractElement;
import org.suren.autotest.web.framework.core.ui.Text;
import org.suren.autotest.web.framework.data.*;
import org.suren.autotest.web.framework.hook.ShutdownHook;
import org.suren.autotest.web.framework.page.Page;
import org.suren.autotest.web.framework.selenium.SeleniumEngine;
import org.suren.autotest.web.framework.spring.AutotestScope;
import org.suren.autotest.web.framework.util.BeanUtil;
import org.suren.autotest.web.framework.util.StringUtils;
import org.suren.autotest.web.framework.validation.Validation;
import org.xml.sax.SAXException;

import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;

/**
 * 页面（page）以及数据配置加载
 * @author suren
 * @date Jul 17, 2016 9:01:51 AM
 */
public class SettingUtil implements Closeable
{
	private static final Logger logger = LoggerFactory.getLogger(SettingUtil.class);
	
	private Map<String, Page>			pageMap	= new HashMap<String, Page>();
	private Map<String, DataSourceInfo>	dataSourceMap = new HashMap<String, DataSourceInfo>();
	private Map<String, DynamicDataSource> dynamicDataSourceMap;
	private ApplicationContext			context;
	private ShutdownHook shutdownHook;
	
	/** 系统配置路径 */
	private File configFile;
	
	private boolean closed = false;
	
	/** 不希望被加载数据的Page集合 */
	private Set<String> excludePageSet = new HashSet<String>();

	/**
	 * 初始化bean容器，初始化上下文对象，增加JMX管理模块，增加程序关闭钩子。
	 */
	public SettingUtil(Class<?> ... annotatedClasses)
	{
		context = SpringUtils.getApplicationContext();
		if(context == null || !((AbstractApplicationContext) context).isActive())
		{
		    if(annotatedClasses == null)
			{
				annotatedClasses = new Class[]{AutoApplicationConfig.class};
			}
			else
			{
			    int len = annotatedClasses.length;
				annotatedClasses = Arrays.copyOf(annotatedClasses, len + 1);
				annotatedClasses[len] = AutoApplicationConfig.class;
			}
			context = new AnnotationConfigApplicationContext(annotatedClasses);
{'fraction_non_alphanumeric': 0.10704924817216167, 'fraction_numerical': 0.00800110360049662, 'mean_word_length': 4.986787778695293, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '2372158', 'n_tokens_mistral': 2352, 'n_tokens_neox': 2243, 'n_words': 477}