1 package org.jacorb.notification; 2 3 22 23 import java.util.Properties ; 24 25 import org.jacorb.notification.conf.Attributes; 26 27 31 32 public class ConsoleMain 33 { 34 private static void help() 35 { 36 System.out.println("Usage: ntfy [-printIOR] [-printCorbaloc] " + "[-writeIOR <filename>] " 37 + "[-registerName <nameId>[.<nameKind>]] " 38 + "[-port <oaPort>] [-channels <channels>] [-help]"); 39 System.exit(0); 40 } 41 42 private static class CmdLineParser 43 { 44 private boolean doHelp = false; 45 46 private Properties props = new Properties (); 47 48 public boolean getDoHelp() 49 { 50 return (doHelp); 51 } 52 53 public Properties getProps() 54 { 55 return (props); 56 } 57 58 CmdLineParser(String [] args) 59 { 60 perform(args); 61 } 62 63 private void perform(String [] args) throws IllegalArgumentException 64 { 65 try 66 { 67 for (int i = 0; i < args.length; i++) 69 { 70 if (args[i].equals("-printIOR")) 71 { 72 props.put(Attributes.PRINT_IOR, "on"); 73 } 74 else if (args[i].equals("-printCorbaloc")) 75 { 76 props.put(Attributes.PRINT_CORBALOC, "on"); 77 } 78 else if (args[i].equals("-help")) 79 { 80 doHelp = true; 81 } 82 else if (args[i].equals("-port")) 83 { 84 props.put("OAPort", args[++i]); 85 } 86 else if (args[i].equals("-channels")) 87 { 88 props.put(Attributes.START_CHANNELS, args[++i]); 89 } 90 else if (args[i].equals("-writeIOR")) 91 { 92 props.put(Attributes.IOR_FILE, args[++i]); 93 } 94 else if (args[i].equals("-registerName")) 95 { 96 String name = args[++i]; 97 98 int index = name.indexOf("."); 99 100 if (name.lastIndexOf(".") != index) 101 { 102 throw new IllegalArgumentException (name 103 + ": argument to -registerName should be " 104 + "<nameId> or <nameId>.<nameKind>"); 105 } 106 107 if (index != -1) 108 { 109 props.put(Attributes.REGISTER_NAME_ID, name.substring(0, index)); 110 111 props.put(Attributes.REGISTER_NAME_KIND, name.substring(index + 1)); 112 } 113 else 114 { 115 props.put(Attributes.REGISTER_NAME_ID, name); 116 } 117 } 118 else if (args[i].equals("-typed")) 119 { 120 props.put(Attributes.ENABLE_TYPED_CHANNEL, "on"); 121 } 122 else 123 { 124 System.out.println("Unknown argument: " + args[i]); 125 126 doHelp = true; 127 } 128 } 129 } catch (ArrayIndexOutOfBoundsException e) 130 { 131 doHelp = true; 132 } 133 } 134 } 135 136 public static AbstractChannelFactory newFactory(String [] args) throws Exception 137 { 138 CmdLineParser _cmdLineParser = new CmdLineParser(args); 139 140 if (_cmdLineParser.getDoHelp()) 141 { 142 help(); 143 144 System.exit(0); 145 } 146 147 Properties props = _cmdLineParser.getProps(); 148 149 AbstractChannelFactory _factory = AbstractChannelFactory.newFactory(props); 150 151 return _factory; 152 } 153 154 public static final void main(String [] args) throws Exception 155 { 156 newFactory(args); 157 } 158 } | Popular Tags |