List of usage examples for java.util Enumeration hasMoreElements
boolean hasMoreElements();
From source file:com.fonoster.astive.server.AstiveServer.java
public static void main(String[] args) throws Exception { DOMConfigurator.configure(AbstractAstiveServer.ASTIVE_HOME + "/conf/log4j.xml"); astivedSP = getServiceProperties(ASTIVED_PROPERTIES, "astived"); adminDaemonSP = getServiceProperties(ADMIN_DAEMON_PROPERTIES, "admin thread"); telnedSP = getServiceProperties(TELNED_PROPERTIES, "telned"); ArrayList<ServiceProperties> serviceProperties = new ArrayList(); serviceProperties.add(astivedSP);/*from w ww . j ava 2 s .c o m*/ // Adding security measure AstPolicy ap = AstPolicy.getInstance(); ap.addPermissions(astivedSP); ap.addPermissions(adminDaemonSP); ap.addPermissions(telnedSP); if (!adminDaemonSP.isDisabled()) { serviceProperties.add(adminDaemonSP); } if (!telnedSP.isDisabled()) { serviceProperties.add(telnedSP); } if ((args.length == 0) || args[0].equals("-h") || args[0].equals("--help")) { printUsage(); System.exit(1); } // Create a Parser CommandLineParser parser = new BasicParser(); Options start = new Options(); start.addOption("h", "help", false, AppLocale.getI18n("optionHelp")); start.addOption("v", "version", false, AppLocale.getI18n("optionVersion")); start.addOption("d", "debug", false, AppLocale.getI18n("optionDebug")); start.addOption("q", "quiet", false, AppLocale.getI18n("optionQuiet")); start.addOption(OptionBuilder.hasArg(true).withArgName("host").withLongOpt("admin-bind") .withDescription(AppLocale.getI18n("optionBind", new Object[] { "admin" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("port").withLongOpt("admin-port") .withDescription(AppLocale.getI18n("optionPort", new Object[] { "admin" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("port").withLongOpt("astived-port") .withDescription(AppLocale.getI18n("optionPort", new Object[] { "astived" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("host").withLongOpt("astived-host") .withDescription(AppLocale.getI18n("optionBind", new Object[] { "astived" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("port").withLongOpt("telned-port") .withDescription(AppLocale.getI18n("optionPort", new Object[] { "telned" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("host").withLongOpt("telned-host") .withDescription(AppLocale.getI18n("optionBind", new Object[] { "telned" })).create()); Options stop = new Options(); stop.addOption(OptionBuilder.hasArg(true).withArgName("host").withLongOpt("host") .withDescription(AppLocale.getI18n("optionHelp")).create()); stop.addOption("h", "host", false, AppLocale.getI18n("optionStopHost", new Object[] { DEFAULT_AGI_SERVER_BIND_ADDR })); stop.addOption("p", "port", false, AppLocale.getI18n("optionStopPort", new Object[] { DEFAULT_AGI_SERVER_PORT })); Options deploy = new Options(); deploy.addOption("h", "help", false, AppLocale.getI18n("optionHelp")); Options undeploy = new Options(); undeploy.addOption("h", "help", false, AppLocale.getI18n("optionHelp")); if (args.length == 0) { printUsage(); System.exit(1); } else if (!isCommand(args[0])) { printUnavailableCmd(args[0]); System.exit(1); } AdminCommand cmd = AdminCommand.get(args[0]); // Parse the program arguments try { if (cmd.equals(AdminCommand.START)) { CommandLine commandLine = parser.parse(start, args); Logger root = LogManager.getRootLogger(); Enumeration allLoggers = root.getLoggerRepository().getCurrentLoggers(); if (commandLine.hasOption('q')) { root.setLevel(Level.ERROR); while (allLoggers.hasMoreElements()) { Category tmpLogger = (Category) allLoggers.nextElement(); tmpLogger.setLevel(Level.ERROR); } } else if (commandLine.hasOption('d')) { root.setLevel(Level.DEBUG); while (allLoggers.hasMoreElements()) { Category tmpLogger = (Category) allLoggers.nextElement(); tmpLogger.setLevel(Level.DEBUG); } } else { root.setLevel(Level.INFO); while (allLoggers.hasMoreElements()) { Category tmpLogger = (Category) allLoggers.nextElement(); tmpLogger.setLevel(Level.INFO); } } if (commandLine.hasOption('h')) { printUsage(cmd, start); System.exit(0); } if (commandLine.hasOption('v')) { out.println(AppLocale.getI18n("astivedVersion", new String[] { Version.VERSION, Version.BUILD_TIME })); System.exit(0); } if (commandLine.hasOption("astived-bind")) { astivedSP.setBindAddr(InetAddress.getByName(commandLine.getOptionValue("astived-port"))); } if (commandLine.hasOption("astived-port")) { astivedSP.setPort(Integer.parseInt(commandLine.getOptionValue("astived-port"))); } if (commandLine.hasOption("admin-bind")) { adminDaemonSP.setBindAddr(InetAddress.getByName(commandLine.getOptionValue("admin-bind"))); } if (commandLine.hasOption("admin-port")) { adminDaemonSP.setPort(Integer.parseInt(commandLine.getOptionValue("admin-port"))); } if (commandLine.hasOption("telned-bind")) { telnedSP.setBindAddr(InetAddress.getByName(commandLine.getOptionValue("telned-bind"))); } if (commandLine.hasOption("telned-port")) { telnedSP.setPort(Integer.parseInt(commandLine.getOptionValue("telned-port"))); } if (!NetUtil.isPortAvailable(astivedSP.getPort())) { out.println(AppLocale.getI18n("errorCantStartFastAgiServerSocket", new Object[] { astivedSP.getBindAddr().getHostAddress(), astivedSP.getPort() })); System.exit(-1); } if (!NetUtil.isPortAvailable(adminDaemonSP.getPort())) { adminDaemonSP.setUnableToOpen(true); } if (!NetUtil.isPortAvailable(telnedSP.getPort())) { telnedSP.setUnableToOpen(true); } new InitOutput().printInit(serviceProperties); AstiveServer server = new AstiveServer(astivedSP.getPort(), astivedSP.getBacklog(), astivedSP.getBindAddr()); server.start(); } if (!cmd.equals(AdminCommand.START) && adminDaemonSP.isDisabled()) { LOG.warn("errorUnableToAccessAdminDaemon"); } if (cmd.equals(AdminCommand.STOP)) { CommandLine commandLine = parser.parse(stop, args); if (commandLine.hasOption("--help")) { printUsage(cmd, stop); System.exit(0); } if (commandLine.hasOption('h')) { if (commandLine.getOptionValue('h') == null) { printUsage(cmd, stop); System.exit(0); } astivedSP.setBindAddr(InetAddress.getByName(commandLine.getOptionValue('h'))); } if (commandLine.hasOption('p')) { if (commandLine.getOptionValue('p') == null) { printUsage(cmd, stop); System.exit(0); } astivedSP.setPort(Integer.parseInt(commandLine.getOptionValue('p'))); } AdminDaemonClient adClient = new AdminDaemonClient(adminDaemonSP.getBindAddr(), adminDaemonSP.getPort()); adClient.stop(); } // TODO: This needs to be researched before a full implementation. // for now is only possible to do deployments into a local server. if (cmd.equals(AdminCommand.DEPLOY)) { CommandLine commandLine = parser.parse(deploy, args); if (args.length < 2) { printUsage(cmd, deploy); System.exit(1); } else if (commandLine.hasOption('h')) { printUsage(cmd, deploy); System.exit(0); } AdminDaemonClient adClient = new AdminDaemonClient(adminDaemonSP.getBindAddr(), adminDaemonSP.getPort()); adClient.deploy(args[1]); } if (cmd.equals(AdminCommand.UNDEPLOY)) { CommandLine commandLine = parser.parse(undeploy, args); if (args.length < 2) { printUsage(cmd, undeploy); System.exit(1); } else if (commandLine.hasOption('h')) { printUsage(cmd, undeploy); System.exit(0); } AdminDaemonClient adClient = new AdminDaemonClient(adminDaemonSP.getBindAddr(), adminDaemonSP.getPort()); adClient.undeploy(args[1]); } } catch (java.net.ConnectException ex) { LOG.error(AppLocale.getI18n("errorServerNotRunning")); } catch (Exception ex) { LOG.error(AppLocale.getI18n("errorUnexpectedFailure", new Object[] { ex.getMessage() })); } }
From source file:examples.mail.java
public final static void main(String[] args) { String sender, recipient, subject, filename, server, cc; Vector ccList = new Vector(); BufferedReader stdin;/*from w ww . j av a 2 s.c o m*/ FileReader fileReader = null; Writer writer; SimpleSMTPHeader header; SMTPClient client; Enumeration en; if (args.length < 1) { System.err.println("Usage: mail smtpserver"); System.exit(1); } server = args[0]; stdin = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("From: "); System.out.flush(); sender = stdin.readLine(); System.out.print("To: "); System.out.flush(); recipient = stdin.readLine(); System.out.print("Subject: "); System.out.flush(); subject = stdin.readLine(); header = new SimpleSMTPHeader(sender, recipient, subject); while (true) { System.out.print("CC <enter one address per line, hit enter to end>: "); System.out.flush(); // Of course you don't want to do this because readLine() may be null cc = stdin.readLine().trim(); if (cc.length() == 0) break; header.addCC(cc); ccList.addElement(cc); } System.out.print("Filename: "); System.out.flush(); filename = stdin.readLine(); try { fileReader = new FileReader(filename); } catch (FileNotFoundException e) { System.err.println("File not found. " + e.getMessage()); } client = new SMTPClient(); client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); client.connect(server); if (!SMTPReply.isPositiveCompletion(client.getReplyCode())) { client.disconnect(); System.err.println("SMTP server refused connection."); System.exit(1); } client.login(); client.setSender(sender); client.addRecipient(recipient); en = ccList.elements(); while (en.hasMoreElements()) client.addRecipient((String) en.nextElement()); writer = client.sendMessageData(); if (writer != null) { writer.write(header.toString()); Util.copyReader(fileReader, writer); writer.close(); client.completePendingCommand(); } fileReader.close(); client.logout(); client.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } }
From source file:ru.apertum.qsystem.client.forms.FAdmin.java
/** * @param args the command line arguments * @throws Exception/* ww w . j av a 2 s. co m*/ */ public static void main(String args[]) throws Exception { QLog.initial(args, 3); Locale.setDefault(Locales.getInstance().getLangCurrent()); //? ? , ? final Thread tPager = new Thread(() -> { FAbout.loadVersionSt(); String result = ""; try { final URL url = new URL(PAGER_URL + "/qskyapi/getpagerdata?qsysver=" + FAbout.VERSION_); final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("User-Agent", "Java bot"); conn.connect(); final int code = conn.getResponseCode(); if (code == 200) { try (BufferedReader in = new BufferedReader( new InputStreamReader(conn.getInputStream(), "utf8"))) { String inputLine; while ((inputLine = in.readLine()) != null) { result += inputLine; } } } conn.disconnect(); } catch (Exception e) { System.err.println("Pager not enabled. " + e); return; } final Gson gson = GsonPool.getInstance().borrowGson(); try { final Answer answer = gson.fromJson(result, Answer.class); forPager = answer; if (answer.getData().size() > 0) { forPager.start(); } } catch (Exception e) { System.err.println("Pager not enabled but working. " + e); } finally { GsonPool.getInstance().returnGson(gson); } }); tPager.setDaemon(true); tPager.start(); Uses.startSplash(); // plugins Uses.loadPlugins("./plugins/"); // ?. FLogin.logining(QUserList.getInstance(), null, true, 3, FLogin.LEVEL_ADMIN); Uses.showSplash(); java.awt.EventQueue.invokeLater(() -> { try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager .getInstalledLookAndFeels()) { System.out.println(info.getName()); /*Metal Nimbus CDE/Motif Windows Windows Classic //GTK+*/ if ("Windows".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } if ("/".equals(File.separator)) { final FontUIResource f = new FontUIResource(new Font("Serif", Font.PLAIN, 10)); final Enumeration<Object> keys = UIManager.getDefaults().keys(); while (keys.hasMoreElements()) { final Object key = keys.nextElement(); final Object value = UIManager.get(key); if (value instanceof FontUIResource) { final FontUIResource orig = (FontUIResource) value; final Font font1 = new Font(f.getFontName(), orig.getStyle(), f.getSize()); UIManager.put(key, new FontUIResource(font1)); } } } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { } try { form = new FAdmin(); if (forPager != null) { forPager.showData(false); } else { form.panelPager.setVisible(false); } form.setVisible(true); } catch (Exception ex) { QLog.l().logger().error(" ? ?? . ", ex); } finally { Uses.closeSplash(); } }); }
From source file:Main.java
static Properties convertResourceBundleToProperties(ResourceBundle resource) { Properties properties = new Properties(); Enumeration<String> keys = resource.getKeys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); properties.put(key, resource.getString(key)); }/*from w ww .j a v a 2 s .co m*/ return properties; }
From source file:Main.java
public static final <T, K> boolean containsKey(Dictionary<T, K> collection, T key) { Enumeration<T> e = collection.keys(); while (e.hasMoreElements()) { if (e.nextElement().equals(key)) { return true; }//from www . ja v a2 s .c om } return false; }
From source file:Main.java
public static boolean hasNotItems(Enumeration<?> enums) { return (enums == null) || (!enums.hasMoreElements()); }
From source file:Main.java
static Hashtable hashtableMerge(Hashtable dst, Hashtable src) { if (dst == null) return src; if (src == null) return dst; Enumeration e = src.keys(); while (e.hasMoreElements()) { Object element = e.nextElement(); dst.put(element, src.get(element)); }/* w ww. j a v a 2 s . c om*/ return dst; }
From source file:Main.java
/** * Convention is to use class name of the class performing the task as thread name * @param threadName/*w w w.j a va2 s.c om*/ */ public static void interrupt(String threadName) { Enumeration e = threads.elements(); while (e.hasMoreElements()) { Thread t = (Thread) e.nextElement(); if (t.getName().equals(threadName)) { t.interrupt(); } } }
From source file:Main.java
public static DefaultMutableTreeNode buscarNodeByNombre(JTree jtree, String nodeStr) { DefaultMutableTreeNode node = null; TreeNode root = (TreeNode) jtree.getModel().getRoot(); Enumeration<?> e = root.children(); while (e.hasMoreElements()) { node = (DefaultMutableTreeNode) e.nextElement(); if ((node.getUserObject().toString()).contains(nodeStr)) { return node; }//from w w w. j ava 2 s. c o m } return null; }
From source file:Main.java
public static <T> Collection<T> collectionEnumerationElements(Enumeration<T> source, Collection<T> target) { while (source.hasMoreElements()) { target.add(source.nextElement()); }/*from w w w. j av a 2 s . c o m*/ return target; }