List of usage examples for java.util Properties setProperty
public synchronized Object setProperty(String key, String value)
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSaxDb2LUWLoaderCLI.CFAsteriskSaxDb2LUWLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxDb2LUWLoaderCLI.main() "; initConsoleLog();/*from ww w . j ava 2 s.c om*/ int numArgs = args.length; if (numArgs >= 2) { String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskConfigurationFile cFAsteriskConfig = new CFAsteriskConfigurationFile(); String cFAsteriskConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskdb2luwrc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("127.0.0.1"); cFAsteriskConfig.setDbPort(5432); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("luw"); cFAsteriskConfig.setDbPassword("edit-me-please"); cFAsteriskConfig.save(); log.message(S_ProcName + "INFO: Created configuration file " + cFAsteriskConfigFileName + ", please edit configuration and restart."); return; } if (!cFAsteriskConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed configuration file " + cFAsteriskConfigFileName + " is not a file."); return; } if (!cFAsteriskConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read configuration file " + cFAsteriskConfigFileName); return; } cFAsteriskConfig.load(); boolean fastExit = false; CFAsteriskClientConfigurationFile cFDbTestClientConfig = new CFAsteriskClientConfigurationFile(); String cFDbTestClientConfigFileName = homeDir.getPath() + File.separator + ".cfdbtestclientrc"; cFDbTestClientConfig.setFileName(cFDbTestClientConfigFileName); File cFDbTestClientConfigFile = new File(cFDbTestClientConfigFileName); if (!cFDbTestClientConfigFile.exists()) { String cFDbTestKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFDbTestClientConfig.setKeyStore(cFDbTestKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFDbTestClientConfig.setDeviceName(deviceName); cFDbTestClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } if (!cFDbTestClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFDbTestClientConfigFileName + " is not a file."); fastExit = true; } if (!cFDbTestClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } cFDbTestClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); ICFAsteriskSchema cFAsteriskSchema = new CFAsteriskDb2LUWSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxDb2LUWLoaderCLI(); CFAsteriskSaxLoader loader = cli.getSaxLoader(); loader.setSchemaObj(cFAsteriskSchemaObj); cFAsteriskSchema.connect(); String url = args[1]; if (numArgs >= 5) { cli.setClusterName(args[2]); cli.setTenantName(args[3]); cli.setSecUserName(args[4]); } else { cli.setClusterName("default"); cli.setTenantName("system"); cli.setSecUserName("system"); } loader.setUseCluster(cli.getClusterObj()); loader.setUseTenant(cli.getTenantObj()); try { cFAsteriskSchema.beginTransaction(); cFAsteriskSchemaObj.setSecCluster(cli.getClusterObj()); cFAsteriskSchemaObj.setSecTenant(cli.getTenantObj()); cFAsteriskSchemaObj.setSecUser(cli.getSecUserObj()); cFAsteriskSchemaObj.setSecSession(cli.getSecSessionObj()); CFSecurityAuthorization auth = new CFSecurityAuthorization(); auth.setSecCluster(cFAsteriskSchemaObj.getSecCluster()); auth.setSecTenant(cFAsteriskSchemaObj.getSecTenant()); auth.setSecSession(cFAsteriskSchemaObj.getSecSession()); cFAsteriskSchemaObj.setAuthorization(auth); applyLoaderOptions(loader, args[0]); if (numArgs >= 5) { cli.evaluateRemainingArgs(args, 5); } else { cli.evaluateRemainingArgs(args, 2); } loader.parseFile(url); cFAsteriskSchema.commit(); cFAsteriskSchema.disconnect(true); } catch (Exception e) { log.message(S_ProcName + "EXCEPTION: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } catch (Error e) { log.message(S_ProcName + "ERROR: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } finally { if (cFAsteriskSchema.isConnected()) { cFAsteriskSchema.rollback(); cFAsteriskSchema.disconnect(false); } } } else { log.message(S_ProcName + "ERROR: Expected at least two argument specifying the loader options and the name of the XML file to parse. The first argument may be empty."); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSaxMSSqlLoaderCLI.CFAsteriskSaxMSSqlLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxMSSqlLoaderCLI.main() "; initConsoleLog();// w w w . ja va2 s. c o m int numArgs = args.length; if (numArgs >= 2) { String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskConfigurationFile cFAsteriskConfig = new CFAsteriskConfigurationFile(); String cFAsteriskConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskmssqlrc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("127.0.0.1"); cFAsteriskConfig.setDbPort(1433); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("sa"); cFAsteriskConfig.setDbPassword("edit-me-please"); cFAsteriskConfig.save(); log.message(S_ProcName + "INFO: Created configuration file " + cFAsteriskConfigFileName + ", please edit configuration and restart."); return; } if (!cFAsteriskConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed configuration file " + cFAsteriskConfigFileName + " is not a file."); return; } if (!cFAsteriskConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read configuration file " + cFAsteriskConfigFileName); return; } cFAsteriskConfig.load(); boolean fastExit = false; CFAsteriskClientConfigurationFile cFDbTestClientConfig = new CFAsteriskClientConfigurationFile(); String cFDbTestClientConfigFileName = homeDir.getPath() + File.separator + ".cfdbtestclientrc"; cFDbTestClientConfig.setFileName(cFDbTestClientConfigFileName); File cFDbTestClientConfigFile = new File(cFDbTestClientConfigFileName); if (!cFDbTestClientConfigFile.exists()) { String cFDbTestKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFDbTestClientConfig.setKeyStore(cFDbTestKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFDbTestClientConfig.setDeviceName(deviceName); cFDbTestClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } if (!cFDbTestClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFDbTestClientConfigFileName + " is not a file."); fastExit = true; } if (!cFDbTestClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } cFDbTestClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); ICFAsteriskSchema cFAsteriskSchema = new CFAsteriskMSSqlSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxMSSqlLoaderCLI(); CFAsteriskSaxLoader loader = cli.getSaxLoader(); loader.setSchemaObj(cFAsteriskSchemaObj); cFAsteriskSchema.connect(); String url = args[1]; if (numArgs >= 5) { cli.setClusterName(args[2]); cli.setTenantName(args[3]); cli.setSecUserName(args[4]); } else { cli.setClusterName("default"); cli.setTenantName("system"); cli.setSecUserName("system"); } loader.setUseCluster(cli.getClusterObj()); loader.setUseTenant(cli.getTenantObj()); try { cFAsteriskSchema.beginTransaction(); cFAsteriskSchemaObj.setSecCluster(cli.getClusterObj()); cFAsteriskSchemaObj.setSecTenant(cli.getTenantObj()); cFAsteriskSchemaObj.setSecUser(cli.getSecUserObj()); cFAsteriskSchemaObj.setSecSession(cli.getSecSessionObj()); CFSecurityAuthorization auth = new CFSecurityAuthorization(); auth.setSecCluster(cFAsteriskSchemaObj.getSecCluster()); auth.setSecTenant(cFAsteriskSchemaObj.getSecTenant()); auth.setSecSession(cFAsteriskSchemaObj.getSecSession()); cFAsteriskSchemaObj.setAuthorization(auth); applyLoaderOptions(loader, args[0]); if (numArgs >= 5) { cli.evaluateRemainingArgs(args, 5); } else { cli.evaluateRemainingArgs(args, 2); } loader.parseFile(url); cFAsteriskSchema.commit(); cFAsteriskSchema.disconnect(true); } catch (Exception e) { log.message(S_ProcName + "EXCEPTION: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } catch (Error e) { log.message(S_ProcName + "ERROR: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } finally { if (cFAsteriskSchema.isConnected()) { cFAsteriskSchema.rollback(); cFAsteriskSchema.disconnect(false); } } } else { log.message(S_ProcName + "ERROR: Expected at least two argument specifying the loader options and the name of the XML file to parse. The first argument may be empty."); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSaxMySqlLoaderCLI.CFAsteriskSaxMySqlLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxMySqlLoaderCLI.main() "; initConsoleLog();/*from w w w. ja v a2 s . c o m*/ int numArgs = args.length; if (numArgs >= 2) { String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskConfigurationFile cFAsteriskConfig = new CFAsteriskConfigurationFile(); String cFAsteriskConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskmysqlrc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("127.0.0.1"); cFAsteriskConfig.setDbPort(3306); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("root"); cFAsteriskConfig.setDbPassword("edit-me-please"); cFAsteriskConfig.save(); log.message(S_ProcName + "INFO: Created configuration file " + cFAsteriskConfigFileName + ", please edit configuration and restart."); return; } if (!cFAsteriskConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed configuration file " + cFAsteriskConfigFileName + " is not a file."); return; } if (!cFAsteriskConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read configuration file " + cFAsteriskConfigFileName); return; } cFAsteriskConfig.load(); boolean fastExit = false; CFAsteriskClientConfigurationFile cFDbTestClientConfig = new CFAsteriskClientConfigurationFile(); String cFDbTestClientConfigFileName = homeDir.getPath() + File.separator + ".cfdbtestclientrc"; cFDbTestClientConfig.setFileName(cFDbTestClientConfigFileName); File cFDbTestClientConfigFile = new File(cFDbTestClientConfigFileName); if (!cFDbTestClientConfigFile.exists()) { String cFDbTestKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFDbTestClientConfig.setKeyStore(cFDbTestKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFDbTestClientConfig.setDeviceName(deviceName); cFDbTestClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } if (!cFDbTestClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFDbTestClientConfigFileName + " is not a file."); fastExit = true; } if (!cFDbTestClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } cFDbTestClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); ICFAsteriskSchema cFAsteriskSchema = new CFAsteriskMySqlSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxMySqlLoaderCLI(); CFAsteriskSaxLoader loader = cli.getSaxLoader(); loader.setSchemaObj(cFAsteriskSchemaObj); cFAsteriskSchema.connect(); String url = args[1]; if (numArgs >= 5) { cli.setClusterName(args[2]); cli.setTenantName(args[3]); cli.setSecUserName(args[4]); } else { cli.setClusterName("default"); cli.setTenantName("system"); cli.setSecUserName("system"); } loader.setUseCluster(cli.getClusterObj()); loader.setUseTenant(cli.getTenantObj()); try { cFAsteriskSchema.beginTransaction(); cFAsteriskSchemaObj.setSecCluster(cli.getClusterObj()); cFAsteriskSchemaObj.setSecTenant(cli.getTenantObj()); cFAsteriskSchemaObj.setSecUser(cli.getSecUserObj()); cFAsteriskSchemaObj.setSecSession(cli.getSecSessionObj()); CFSecurityAuthorization auth = new CFSecurityAuthorization(); auth.setSecCluster(cFAsteriskSchemaObj.getSecCluster()); auth.setSecTenant(cFAsteriskSchemaObj.getSecTenant()); auth.setSecSession(cFAsteriskSchemaObj.getSecSession()); cFAsteriskSchemaObj.setAuthorization(auth); applyLoaderOptions(loader, args[0]); if (numArgs >= 5) { cli.evaluateRemainingArgs(args, 5); } else { cli.evaluateRemainingArgs(args, 2); } loader.parseFile(url); cFAsteriskSchema.commit(); cFAsteriskSchema.disconnect(true); } catch (Exception e) { log.message(S_ProcName + "EXCEPTION: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } catch (Error e) { log.message(S_ProcName + "ERROR: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } finally { if (cFAsteriskSchema.isConnected()) { cFAsteriskSchema.rollback(); cFAsteriskSchema.disconnect(false); } } } else { log.message(S_ProcName + "ERROR: Expected at least two argument specifying the loader options and the name of the XML file to parse. The first argument may be empty."); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSaxOracleLoaderCLI.CFAsteriskSaxOracleLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxOracleLoaderCLI.main() "; initConsoleLog();/*from w w w. j a v a 2s. c om*/ int numArgs = args.length; if (numArgs >= 2) { String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskConfigurationFile cFAsteriskConfig = new CFAsteriskConfigurationFile(); String cFAsteriskConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskoraclerc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("127.0.0.1"); cFAsteriskConfig.setDbPort(1526); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("system"); cFAsteriskConfig.setDbPassword("edit-me-please"); cFAsteriskConfig.save(); log.message(S_ProcName + "INFO: Created configuration file " + cFAsteriskConfigFileName + ", please edit configuration and restart."); return; } if (!cFAsteriskConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed configuration file " + cFAsteriskConfigFileName + " is not a file."); return; } if (!cFAsteriskConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read configuration file " + cFAsteriskConfigFileName); return; } cFAsteriskConfig.load(); boolean fastExit = false; CFAsteriskClientConfigurationFile cFDbTestClientConfig = new CFAsteriskClientConfigurationFile(); String cFDbTestClientConfigFileName = homeDir.getPath() + File.separator + ".cfdbtestclientrc"; cFDbTestClientConfig.setFileName(cFDbTestClientConfigFileName); File cFDbTestClientConfigFile = new File(cFDbTestClientConfigFileName); if (!cFDbTestClientConfigFile.exists()) { String cFDbTestKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFDbTestClientConfig.setKeyStore(cFDbTestKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFDbTestClientConfig.setDeviceName(deviceName); cFDbTestClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } if (!cFDbTestClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFDbTestClientConfigFileName + " is not a file."); fastExit = true; } if (!cFDbTestClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } cFDbTestClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); ICFAsteriskSchema cFAsteriskSchema = new CFAsteriskOracleSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxOracleLoaderCLI(); CFAsteriskSaxLoader loader = cli.getSaxLoader(); loader.setSchemaObj(cFAsteriskSchemaObj); cFAsteriskSchema.connect(); String url = args[1]; if (numArgs >= 5) { cli.setClusterName(args[2]); cli.setTenantName(args[3]); cli.setSecUserName(args[4]); } else { cli.setClusterName("default"); cli.setTenantName("system"); cli.setSecUserName("system"); } loader.setUseCluster(cli.getClusterObj()); loader.setUseTenant(cli.getTenantObj()); try { cFAsteriskSchema.beginTransaction(); cFAsteriskSchemaObj.setSecCluster(cli.getClusterObj()); cFAsteriskSchemaObj.setSecTenant(cli.getTenantObj()); cFAsteriskSchemaObj.setSecUser(cli.getSecUserObj()); cFAsteriskSchemaObj.setSecSession(cli.getSecSessionObj()); CFSecurityAuthorization auth = new CFSecurityAuthorization(); auth.setSecCluster(cFAsteriskSchemaObj.getSecCluster()); auth.setSecTenant(cFAsteriskSchemaObj.getSecTenant()); auth.setSecSession(cFAsteriskSchemaObj.getSecSession()); cFAsteriskSchemaObj.setAuthorization(auth); applyLoaderOptions(loader, args[0]); if (numArgs >= 5) { cli.evaluateRemainingArgs(args, 5); } else { cli.evaluateRemainingArgs(args, 2); } loader.parseFile(url); cFAsteriskSchema.commit(); cFAsteriskSchema.disconnect(true); } catch (Exception e) { log.message(S_ProcName + "EXCEPTION: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } catch (Error e) { log.message(S_ProcName + "ERROR: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } finally { if (cFAsteriskSchema.isConnected()) { cFAsteriskSchema.rollback(); cFAsteriskSchema.disconnect(false); } } } else { log.message(S_ProcName + "ERROR: Expected at least two argument specifying the loader options and the name of the XML file to parse. The first argument may be empty."); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSaxSybaseLoaderCLI.CFAsteriskSaxSybaseLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxSybaseLoaderCLI.main() "; initConsoleLog();/*from w w w .j a va 2 s .com*/ int numArgs = args.length; if (numArgs >= 2) { String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskConfigurationFile cFAsteriskConfig = new CFAsteriskConfigurationFile(); String cFAsteriskConfigFileName = homeDir.getPath() + File.separator + ".cfasterisksybaserc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("localhost"); cFAsteriskConfig.setDbPort(2345); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("sa"); cFAsteriskConfig.setDbPassword("edit-me-please"); cFAsteriskConfig.save(); log.message(S_ProcName + "INFO: Created configuration file " + cFAsteriskConfigFileName + ", please edit configuration and restart."); return; } if (!cFAsteriskConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed configuration file " + cFAsteriskConfigFileName + " is not a file."); return; } if (!cFAsteriskConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read configuration file " + cFAsteriskConfigFileName); return; } cFAsteriskConfig.load(); boolean fastExit = false; CFAsteriskClientConfigurationFile cFDbTestClientConfig = new CFAsteriskClientConfigurationFile(); String cFDbTestClientConfigFileName = homeDir.getPath() + File.separator + ".cfdbtestclientrc"; cFDbTestClientConfig.setFileName(cFDbTestClientConfigFileName); File cFDbTestClientConfigFile = new File(cFDbTestClientConfigFileName); if (!cFDbTestClientConfigFile.exists()) { String cFDbTestKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFDbTestClientConfig.setKeyStore(cFDbTestKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFDbTestClientConfig.setDeviceName(deviceName); cFDbTestClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } if (!cFDbTestClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFDbTestClientConfigFileName + " is not a file."); fastExit = true; } if (!cFDbTestClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } cFDbTestClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); ICFAsteriskSchema cFAsteriskSchema = new CFAsteriskSybaseSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxSybaseLoaderCLI(); CFAsteriskSaxLoader loader = cli.getSaxLoader(); loader.setSchemaObj(cFAsteriskSchemaObj); cFAsteriskSchema.connect(); String url = args[1]; if (numArgs >= 5) { cli.setClusterName(args[2]); cli.setTenantName(args[3]); cli.setSecUserName(args[4]); } else { cli.setClusterName("default"); cli.setTenantName("system"); cli.setSecUserName("system"); } loader.setUseCluster(cli.getClusterObj()); loader.setUseTenant(cli.getTenantObj()); try { cFAsteriskSchema.beginTransaction(); cFAsteriskSchemaObj.setSecCluster(cli.getClusterObj()); cFAsteriskSchemaObj.setSecTenant(cli.getTenantObj()); cFAsteriskSchemaObj.setSecUser(cli.getSecUserObj()); cFAsteriskSchemaObj.setSecSession(cli.getSecSessionObj()); CFSecurityAuthorization auth = new CFSecurityAuthorization(); auth.setSecCluster(cFAsteriskSchemaObj.getSecCluster()); auth.setSecTenant(cFAsteriskSchemaObj.getSecTenant()); auth.setSecSession(cFAsteriskSchemaObj.getSecSession()); cFAsteriskSchemaObj.setAuthorization(auth); applyLoaderOptions(loader, args[0]); if (numArgs >= 5) { cli.evaluateRemainingArgs(args, 5); } else { cli.evaluateRemainingArgs(args, 2); } loader.parseFile(url); cFAsteriskSchema.commit(); cFAsteriskSchema.disconnect(true); } catch (Exception e) { log.message(S_ProcName + "EXCEPTION: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } catch (Error e) { log.message(S_ProcName + "ERROR: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } finally { if (cFAsteriskSchema.isConnected()) { cFAsteriskSchema.rollback(); cFAsteriskSchema.disconnect(false); } } } else { log.message(S_ProcName + "ERROR: Expected at least two argument specifying the loader options and the name of the XML file to parse. The first argument may be empty."); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSaxPgSqlLoaderCLI.CFAsteriskSaxPgSqlLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxPgSqlLoaderCLI.main() "; initConsoleLog();/*from w w w. j a v a2s .c o m*/ int numArgs = args.length; if (numArgs >= 2) { String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskConfigurationFile cFAsteriskConfig = new CFAsteriskConfigurationFile(); String cFAsteriskConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskpgsqlrc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("127.0.0.1"); cFAsteriskConfig.setDbPort(5432); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("postgres"); cFAsteriskConfig.setDbPassword("edit-me-please"); cFAsteriskConfig.save(); log.message(S_ProcName + "INFO: Created configuration file " + cFAsteriskConfigFileName + ", please edit configuration and restart."); return; } if (!cFAsteriskConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed configuration file " + cFAsteriskConfigFileName + " is not a file."); return; } if (!cFAsteriskConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read configuration file " + cFAsteriskConfigFileName); return; } cFAsteriskConfig.load(); boolean fastExit = false; CFAsteriskClientConfigurationFile cFDbTestClientConfig = new CFAsteriskClientConfigurationFile(); String cFDbTestClientConfigFileName = homeDir.getPath() + File.separator + ".cfdbtestclientrc"; cFDbTestClientConfig.setFileName(cFDbTestClientConfigFileName); File cFDbTestClientConfigFile = new File(cFDbTestClientConfigFileName); if (!cFDbTestClientConfigFile.exists()) { String cFDbTestKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFDbTestClientConfig.setKeyStore(cFDbTestKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFDbTestClientConfig.setDeviceName(deviceName); cFDbTestClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } if (!cFDbTestClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFDbTestClientConfigFileName + " is not a file."); fastExit = true; } if (!cFDbTestClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } cFDbTestClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); ICFAsteriskSchema cFAsteriskSchema = new CFAsteriskPgSqlSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxPgSqlLoaderCLI(); CFAsteriskSaxLoader loader = cli.getSaxLoader(); loader.setSchemaObj(cFAsteriskSchemaObj); cFAsteriskSchema.connect(); String url = args[1]; if (numArgs >= 5) { cli.setClusterName(args[2]); cli.setTenantName(args[3]); cli.setSecUserName(args[4]); } else { cli.setClusterName("default"); cli.setTenantName("system"); cli.setSecUserName("system"); } loader.setUseCluster(cli.getClusterObj()); loader.setUseTenant(cli.getTenantObj()); try { cFAsteriskSchema.beginTransaction(); cFAsteriskSchemaObj.setSecCluster(cli.getClusterObj()); cFAsteriskSchemaObj.setSecTenant(cli.getTenantObj()); cFAsteriskSchemaObj.setSecUser(cli.getSecUserObj()); cFAsteriskSchemaObj.setSecSession(cli.getSecSessionObj()); CFSecurityAuthorization auth = new CFSecurityAuthorization(); auth.setSecCluster(cFAsteriskSchemaObj.getSecCluster()); auth.setSecTenant(cFAsteriskSchemaObj.getSecTenant()); auth.setSecSession(cFAsteriskSchemaObj.getSecSession()); cFAsteriskSchemaObj.setAuthorization(auth); applyLoaderOptions(loader, args[0]); if (numArgs >= 5) { cli.evaluateRemainingArgs(args, 5); } else { cli.evaluateRemainingArgs(args, 2); } loader.parseFile(url); cFAsteriskSchema.commit(); cFAsteriskSchema.disconnect(true); } catch (Exception e) { log.message(S_ProcName + "EXCEPTION: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } catch (Error e) { log.message(S_ProcName + "ERROR: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } finally { if (cFAsteriskSchema.isConnected()) { cFAsteriskSchema.rollback(); cFAsteriskSchema.disconnect(false); } } } else { log.message(S_ProcName + "ERROR: Expected at least two argument specifying the loader options and the name of the XML file to parse. The first argument may be empty."); } }
From source file:de.tu_berlin.dima.oligos.Oligos.java
public static void main(String[] args) throws TypeNotSupportedException { BasicConfigurator.configure();//from w ww . j av a2 s .c o m // TODO create cmdline option for setting logger level Logger.getRootLogger().setLevel(Level.INFO); CommandLineInterface cli = new CommandLineInterface(args); try { // TODO hard exit if the parsing fails! // better catch exceptions and log them if (!cli.parse()) { System.exit(2); } Properties props = new Properties(); props.setProperty("user", cli.getUsername()); props.setProperty("password", cli.getPassword()); Connection connection = DriverManager.getConnection(cli.getConnectionString(), props); JdbcConnector jdbcConnector = new JdbcConnector(connection); MetaConnector metaConnector = null; Driver dbDriver = cli.dbDriver; switch (dbDriver.driverName) { case db2: LOGGER.trace("metaConnector = Db2MetaConnector"); metaConnector = new Db2MetaConnector(jdbcConnector); break; case oracle: metaConnector = new OracleMetaConnector(jdbcConnector); break; default: LOGGER.error("Unknown database driver. Supported drivers are: " + DriverName.values()); } // validating schema LOGGER.info("Validating input schema ..."); SparseSchema sparseSchema = cli.getInputSchema(); LOGGER.trace("User specified schema " + sparseSchema); DenseSchema inputSchema = DbUtils.populateSchema(sparseSchema, jdbcConnector, metaConnector); LOGGER.trace("Populated and validated schema " + inputSchema); // obtaining type information/ column meta data LOGGER.info("Retrieving column meta data ..."); Map<ColumnId, TypeInfo> columnTypes = Maps.newLinkedHashMap(); for (ColumnId columnId : inputSchema) { TypeInfo type = metaConnector.getColumnType(columnId); columnTypes.put(columnId, type); } // creating connectors and profilers LOGGER.info("Establashing database connection ..."); SchemaConnector schemaConnector = null; TableConnector tableConnector = null; switch (dbDriver.driverName) { case db2: schemaConnector = new Db2SchemaConnector(jdbcConnector); tableConnector = new Db2TableConnector(jdbcConnector); break; case oracle: schemaConnector = new OracleSchemaConnector(jdbcConnector); tableConnector = new OracleTableConnector(jdbcConnector); } Set<SchemaProfiler> profilers = Sets.newLinkedHashSet(); for (String schema : inputSchema.schemas()) { SchemaProfiler schemaProfiler = new SchemaProfiler(schema, schemaConnector); profilers.add(schemaProfiler); for (String table : inputSchema.tablesIn(schema)) { TableProfiler tableProfiler = new TableProfiler(schema, table, tableConnector); schemaProfiler.add(tableProfiler); for (String column : inputSchema.columnsIn(schema, table)) { ColumnId columnId = new ColumnId(schema, table, column); TypeInfo type = columnTypes.get(columnId); ColumnProfiler<?> columnProfiler = null; switch (dbDriver.driverName) { case db2: columnProfiler = getProfiler(schema, table, column, type, jdbcConnector, metaConnector); break; case oracle: columnProfiler = getProfilerOracle(schema, table, column, type, jdbcConnector, metaConnector); } tableProfiler.addColumnProfiler(columnProfiler); } } } // profiling statistical data LOGGER.info("Profiling schema ..."); Set<Schema> profiledSchemas = Sets.newLinkedHashSet(); for (SchemaProfiler schemaProfiler : profilers) { Schema profiledSchema = schemaProfiler.profile(); profiledSchemas.add(profiledSchema); } LOGGER.info("Generating generator specification ..."); File outputDir = cli.getOutputDirectory(); String generatorName = cli.getGeneratorName(); LOGGER.info("Writing generator specification ..."); for (Schema schema : profiledSchemas) { MyriadWriter writer = new MyriadWriter(schema, outputDir, generatorName); writer.write(); } LOGGER.info("Closing database connection ..."); connection.close(); } catch (SQLException e) { LOGGER.error(e.getLocalizedMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } catch (IOException e) { LOGGER.error(e.getLocalizedMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } catch (ParseException e) { LOGGER.error(e.getMessage()); cli.printHelpMessage(); } }
From source file:com.l2jfree.loginserver.tools.L2GameServerRegistrar.java
/** * Launches the interactive game server registration. * //from w w w. j a v a2s .com * @param args ignored */ public static void main(String[] args) { // LOW rework this crap Util.printSection("Game Server Registration"); _log.info("Please choose:"); _log.info("list - list registered game servers"); _log.info("reg - register a game server"); _log.info("rem - remove a registered game server"); _log.info("hexid - generate a legacy hexid file"); _log.info("quit - exit this application"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); L2GameServerRegistrar reg = new L2GameServerRegistrar(); String line; try { RegistrationState next = RegistrationState.INITIAL_CHOICE; while ((line = br.readLine()) != null) { line = line.trim().toLowerCase(); switch (reg.getState()) { case GAMESERVER_ID: try { int id = Integer.parseInt(line); if (id < 1 || id > 127) throw new IllegalArgumentException("ID must be in [1;127]."); reg.setId(id); reg.setState(next); } catch (RuntimeException e) { _log.info("You must input a number between 1 and 127"); } if (reg.getState() == RegistrationState.ALLOW_BANS) { Connection con = null; try { con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("SELECT allowBans FROM gameserver WHERE id = ?"); ps.setInt(1, reg.getId()); ResultSet rs = ps.executeQuery(); if (rs.next()) { _log.info("A game server is already registered on ID " + reg.getId()); reg.setState(RegistrationState.INITIAL_CHOICE); } else _log.info("Allow account bans from this game server? [y/n]:"); ps.close(); } catch (SQLException e) { _log.error("Could not remove a game server!", e); } finally { L2Database.close(con); } } else if (reg.getState() == RegistrationState.REMOVE) { Connection con = null; try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement("DELETE FROM gameserver WHERE id = ?"); ps.setInt(1, reg.getId()); int cnt = ps.executeUpdate(); if (cnt == 0) _log.info("No game server registered on ID " + reg.getId()); else _log.info("Game server removed."); ps.close(); } catch (SQLException e) { _log.error("Could not remove a game server!", e); } finally { L2Database.close(con); } reg.setState(RegistrationState.INITIAL_CHOICE); } else if (reg.getState() == RegistrationState.GENERATE) { Connection con = null; try { con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("SELECT authData FROM gameserver WHERE id = ?"); ps.setInt(1, reg.getId()); ResultSet rs = ps.executeQuery(); if (rs.next()) { reg.setAuth(rs.getString("authData")); byte[] b = HexUtil.hexStringToBytes(reg.getAuth()); Properties pro = new Properties(); pro.setProperty("ServerID", String.valueOf(reg.getId())); pro.setProperty("HexID", HexUtil.hexToString(b)); BufferedOutputStream os = new BufferedOutputStream( new FileOutputStream("hexid.txt")); pro.store(os, "the hexID to auth into login"); IOUtils.closeQuietly(os); _log.info("hexid.txt has been generated."); } else _log.info("No game server registered on ID " + reg.getId()); rs.close(); ps.close(); } catch (SQLException e) { _log.error("Could not generate hexid.txt!", e); } finally { L2Database.close(con); } reg.setState(RegistrationState.INITIAL_CHOICE); } break; case ALLOW_BANS: try { if (line.length() != 1) throw new IllegalArgumentException("One char required."); else if (line.charAt(0) == 'y') reg.setTrusted(true); else if (line.charAt(0) == 'n') reg.setTrusted(false); else throw new IllegalArgumentException("Invalid choice."); byte[] auth = Rnd.nextBytes(new byte[BYTES]); reg.setAuth(HexUtil.bytesToHexString(auth)); Connection con = null; try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement( "INSERT INTO gameserver (id, authData, allowBans) VALUES (?, ?, ?)"); ps.setInt(1, reg.getId()); ps.setString(2, reg.getAuth()); ps.setBoolean(3, reg.isTrusted()); ps.executeUpdate(); ps.close(); _log.info("Registered game server on ID " + reg.getId()); _log.info("The authorization string is:"); _log.info(reg.getAuth()); _log.info("Use it when registering this login server."); _log.info("If you need a legacy hexid file, use the 'hexid' command."); } catch (SQLException e) { _log.error("Could not register gameserver!", e); } finally { L2Database.close(con); } reg.setState(RegistrationState.INITIAL_CHOICE); } catch (IllegalArgumentException e) { _log.info("[y/n]?"); } break; default: if (line.equals("list")) { Connection con = null; try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement("SELECT id, allowBans FROM gameserver"); ResultSet rs = ps.executeQuery(); while (rs.next()) _log.info("ID: " + rs.getInt("id") + ", trusted: " + rs.getBoolean("allowBans")); rs.close(); ps.close(); } catch (SQLException e) { _log.error("Could not register gameserver!", e); } finally { L2Database.close(con); } reg.setState(RegistrationState.INITIAL_CHOICE); } else if (line.equals("reg")) { _log.info("Enter the desired ID:"); reg.setState(RegistrationState.GAMESERVER_ID); next = RegistrationState.ALLOW_BANS; } else if (line.equals("rem")) { _log.info("Enter game server ID:"); reg.setState(RegistrationState.GAMESERVER_ID); next = RegistrationState.REMOVE; } else if (line.equals("hexid")) { _log.info("Enter game server ID:"); reg.setState(RegistrationState.GAMESERVER_ID); next = RegistrationState.GENERATE; } else if (line.equals("quit")) Shutdown.exit(TerminationStatus.MANUAL_SHUTDOWN); else _log.info("Incorrect command."); break; } } } catch (IOException e) { _log.fatal("Could not process input!", e); } finally { IOUtils.closeQuietly(br); } }
From source file:es.eucm.ead.exporter.ExporterMain.java
@SuppressWarnings("all") public static void main(String args[]) { Options options = new Options(); Option help = new Option("h", "help", false, "print this message"); Option quiet = new Option("q", "quiet", false, "be extra quiet"); Option verbose = new Option("v", "verbose", false, "be extra verbose"); Option legacy = OptionBuilder.withArgName("s> <t").hasArgs(3) .withDescription(/*from www . j a v a 2s. c o m*/ "source is a version 1.x game; must specify\n" + "<simplify> if 'true', simplifies result\n" + "<translate> if 'true', enables translation") .withLongOpt("import").create("i"); Option war = OptionBuilder.withArgName("web-base").hasArg() .withDescription("WAR packaging (web app); " + "must specify\n<web-base> the base WAR directory") .withLongOpt("war").create("w"); Option jar = OptionBuilder.withDescription("JAR packaging (desktop)").withLongOpt("jar").create("j"); Option apk = OptionBuilder.withArgName("props> <adk> <d").hasArgs(3) .withDescription("APK packaging (android); must specify \n" + "<props> (a properties file) \n" + "<adk> (location of the ADK to use) \n" + "<deploy> ('true' to install & deploy)") .withLongOpt("apk").create("a"); // EAD option Option ead = OptionBuilder.withDescription("EAD packaging (eAdventure)").withLongOpt("ead").create("e"); options.addOption(legacy); options.addOption(help); options.addOption(quiet); options.addOption(verbose); options.addOption(jar); options.addOption(war); options.addOption(apk); options.addOption(ead); CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException pe) { System.err.println("Error parsing command-line: " + pe.getMessage()); showHelp(options); return; } // general options String[] extras = cmd.getArgs(); if (cmd.hasOption(help.getOpt()) || extras.length < 2) { showHelp(options); return; } if (cmd.hasOption(verbose.getOpt())) { verbosity = Verbose; } if (cmd.hasOption(quiet.getOpt())) { verbosity = Quiet; } // import String source = extras[0]; // optional import step if (cmd.hasOption(legacy.getOpt())) { String[] values = cmd.getOptionValues(legacy.getOpt()); AdventureConverter converter = new AdventureConverter(); if (values.length > 0 && values[0].equalsIgnoreCase("true")) { converter.setEnableSimplifications(true); } if (values.length > 1 && values[1].equalsIgnoreCase("true")) { converter.setEnableTranslations(true); } // set source for next steps to import-target source = converter.convert(source, null); } if (cmd.hasOption(jar.getOpt())) { if (checkFilesExist(cmd, options, source)) { JarExporter e = new JarExporter(); e.export(source, extras[1], verbosity.equals(Quiet) ? new QuietStream() : System.err); } } else if (cmd.hasOption(apk.getOpt())) { String[] values = cmd.getOptionValues(apk.getOpt()); if (checkFilesExist(cmd, options, values[0], values[1], source)) { AndroidExporter e = new AndroidExporter(); Properties props = new Properties(); File propsFile = new File(values[0]); try { props.load(new FileReader(propsFile)); props.setProperty(AndroidExporter.SDK_HOME, props.getProperty(AndroidExporter.SDK_HOME, values[1])); } catch (IOException ioe) { System.err.println("Could not load properties from " + propsFile.getAbsolutePath()); return; } e.export(source, extras[1], props, values.length > 2 && values[2].equalsIgnoreCase("true")); } } else if (cmd.hasOption(war.getOpt())) { if (checkFilesExist(cmd, options, extras[0])) { WarExporter e = new WarExporter(); e.setWarPath(cmd.getOptionValue(war.getOpt())); e.export(source, extras[1]); } } else if (cmd.hasOption(ead.getOpt())) { String destiny = extras[1]; if (!destiny.endsWith(".ead")) { destiny += ".ead"; } FileUtils.zip(new File(destiny), new File(source)); } else { showHelp(options); } }
From source file:com.yahoo.ycsb.db.AsyncHBaseClient.java
public static void main(String[] args) { if (args.length != 4) { System.out.println("usage: ahc zkquorum zkpath threadcount operation_count"); System.exit(0);// w w w . j av a 2 s.c om } final int keyspace = 10000; //120000000; final String zkQuorum = args[0]; final String zkPath = args[1]; final int threadcount = Integer.parseInt(args[2]); final int opcount = Integer.parseInt(args[3]) / threadcount; Vector<Thread> allthreads = new Vector<Thread>(); for (int i = 0; i < threadcount; i++) { Thread t = new Thread() { public void run() { try { Random random = new Random(); AsyncHBaseClient cli = new AsyncHBaseClient(); Properties props = new Properties(); props.setProperty("columnfamily", "f1"); props.setProperty("zkquorum", zkQuorum); props.setProperty("zkpath", zkPath); props.setProperty("debug", "true"); cli.setProperties(props); cli.init(); HashMap<String, ByteIterator> result = Maps.newHashMap(); long accum = 0; for (int i = 0; i < opcount; i++) { int keynum = random.nextInt(keyspace); String key = "user" + keynum; long st = System.currentTimeMillis(); int rescode; HashMap<String, ByteIterator> hm = Maps.newHashMap(); hm.put("field1", new ByteArrayByteIterator("value1".getBytes("UTF-8"))); hm.put("field2", new ByteArrayByteIterator("value2".getBytes("UTF-8"))); hm.put("field3", new ByteArrayByteIterator("value3".getBytes("UTF-8"))); hm.put("efield", new ByteArrayByteIterator(HBaseClient.EMPTY_ARRAY)); rescode = cli.insert("bench", key, hm); HashSet<String> s = Sets.newHashSet(); s.add("field1"); s.add("field2"); rescode = cli.read("bench", key, s, result); rescode = cli.delete("bench", key); rescode = cli.read("bench", key, s, result); HashSet<String> scanFields = Sets.newHashSet(); scanFields.add("field1"); scanFields.add("field3"); Vector<HashMap<String, ByteIterator>> scanResults = new Vector<HashMap<String, ByteIterator>>(); rescode = cli.scan("bench", "user2", 20, null, scanResults); long en = System.currentTimeMillis(); accum += (en - st); if (rescode != Ok) { System.out.println("Error " + rescode + " for " + key); } if (i % 10 == 0) { System.out.println( i + " operations, average latency: " + (((double) accum) / ((double) i))); } } System.out.println(new ToStringBuilder(cli._client.stats(), ToStringStyle.MULTI_LINE_STYLE) .toString()); } catch (Exception e) { e.printStackTrace(); } } }; allthreads.add(t); } long st = System.currentTimeMillis(); for (Thread t : allthreads) { t.start(); } for (Thread t : allthreads) { try { t.join(); } catch (InterruptedException e) { } } long en = System.currentTimeMillis(); System.out.println("Throughput: " + ((1000.0) * (((double) (opcount * threadcount)) / ((double) (en - st)))) + " ops/sec"); }