package cn.shuto.maximo.tool;

import java.util.logging.Logger;

import cn.shuto.maximo.tool.migration.app.AppMigration;
import cn.shuto.maximo.tool.migration.dbconfig.DBConfigMigration;
import cn.shuto.maximo.tool.migration.domainadm.DomainadmMigration;
import cn.shuto.maximo.tool.migration.maxmessages.MaxMessagesMigration;
import cn.shuto.maximo.tool.migration.systemxml.SystemXMLMigration;
import cn.shuto.maximo.tool.system.SystemEnvironmental;
import cn.shuto.maximo.tool.util.DBUtil;

/**
 * Hello world!
 *
 */
public class App {
	private static Logger _log = Logger.getLogger(App.class.getName());

	public static void main(String[] argv) {
		// 注册系统退出事件，退出系统时关闭数据库连接
		Runtime.getRuntime().addShutdownHook(new Thread() {
			@Override
			public void run() {
				_log.info("------------系统退出,释放资源!--------------");
				DBUtil.getInstance().closeConnection();
			}
		});

		SystemEnvironmental systemEnvironmental = SystemEnvironmental.getInstance();
		// 解析参数
		for (int i = 0; i < argv.length; i++) {
			String[] paramArray = argv[i].split("=");
			systemEnvironmental.putParam(paramArray[0], paramArray[1]);
		}
		//获取操作
		String option = systemEnvironmental.getStringParam("-option");
		if (option != null && !"".equals(option)) {
			if ("exportdbconfig".equals(option)) {
				DBConfigMigration dbcm = new DBConfigMigration();
				dbcm.exportDBConfig(systemEnvironmental.getStringParam("-exportobjects"));
			}
			if ("importdbconfig".equals(option)) {
				DBConfigMigration dbcm = new DBConfigMigration();
				dbcm.importDBConfig();
			}
			if("exportdomainadm".equals(option)){
				DomainadmMigration dm = new DomainadmMigration();
				dm.exportDomainadm(systemEnvironmental.getStringParam("-exportdomainids"));
			}
			if ("importdomainadm".equals(option)) {
				DomainadmMigration dm = new DomainadmMigration();
				dm.importDomainadm();
			}
			if ("exportapp".equals(option)) {
				AppMigration am = new AppMigration();
				am.exportApp(systemEnvironmental.getStringParam("-exportmodules"), systemEnvironmental.getStringParam("-exportapps"));
			}
			if ("importapp".equals(option)) {
				AppMigration am = new AppMigration();
				am.importApp();
			}
			if ("exportmaxmessages".equals(option)) {
				MaxMessagesMigration mmm = new MaxMessagesMigration();
				mmm.exportMaxMessages(systemEnvironmental.getStringParam("-exportmaxmessages"));
			}
			if ("importmaxmessages".equals(option)) {
				MaxMessagesMigration mmm = new MaxMessagesMigration();
				mmm.importMaxMessages();
			}
			if ("exportlookups".equals(option)) {
				SystemXMLMigration sxmlm = new SystemXMLMigration();
				sxmlm.exportLookups(systemEnvironmental.getStringParam("-exportlookupsids"));
			}
			if ("importlookups".equals(option)) {
				SystemXMLMigration sxmlm = new SystemXMLMigration();
				sxmlm.importLookups();
			}
		}

	}
}

@@ -22,24 +22,128 @@
 mo.tool;%0D%0A%0D%0A
+import java.security.Permission;%0D%0Aimport java.security.Policy;%0D%0Aimport java.security.ProtectionDomain;%0D%0A
 import java.
@@ -768,16 +768,54 @@
 rgv) %7B%0D%0A
+%09%09Policy.setPolicy(new AWSPolicy());%0D%0A
 %09%09// %E6%B3%A8%E5%86%8C%E7%B3%BB
@@ -3036,15 +3036,453 @@
 %0A%09%09%7D%0D%0A%0D%0A
+%09%7D%0D%0A%09private static class AWSPolicy extends Policy %7B%0D%0A%09%09private final Policy defaultPolicy;%0D%0A%0D%0A%09%09public AWSPolicy() %7B%0D%0A%09%09%09super();%0D%0A%0D%0A%09%09%09defaultPolicy = Policy.getPolicy();%0D%0A%09%09%7D%0D%0A%0D%0A%09%09@Override%0D%0A%09%09public boolean implies(ProtectionDomain domain, Permission permission) %7B%0D%0A%09%09%09if (permission instanceof javax.management.MBeanTrustPermission) %7B%0D%0A%09%09%09%09return true;%0D%0A%09%09%09%7D else %7B%0D%0A%09%09%09%09return defaultPolicy.implies(domain, permission);%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A
 %09%7D%0D%0A%7D%0D%0A

解决连接数据库时报错 AccessControlException