KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > ConsoleMain


1 package org.jacorb.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2003 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import java.util.Properties JavaDoc;
24
25 import org.jacorb.notification.conf.Attributes;
26
27 /**
28  * @author Alphonse Bendt
29  * @version $Id: ConsoleMain.java,v 1.2 2005/02/13 23:56:59 alphonse.bendt Exp $
30  */

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 JavaDoc props = new Properties JavaDoc();
47
48         public boolean getDoHelp()
49         {
50             return (doHelp);
51         }
52
53         public Properties JavaDoc getProps()
54         {
55             return (props);
56         }
57
58         CmdLineParser(String JavaDoc[] args)
59         {
60             perform(args);
61         }
62
63         private void perform(String JavaDoc[] args) throws IllegalArgumentException JavaDoc
64         {
65             try
66             {
67                 // process arguments
68
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 JavaDoc name = args[++i];
97
98                         int index = name.indexOf(".");
99
100                         if (name.lastIndexOf(".") != index)
101                         {
102                             throw new IllegalArgumentException JavaDoc(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 JavaDoc e)
130             {
131                 doHelp = true;
132             }
133         }
134     }
135
136     public static AbstractChannelFactory newFactory(String JavaDoc[] args) throws Exception JavaDoc
137     {
138         CmdLineParser _cmdLineParser = new CmdLineParser(args);
139
140         if (_cmdLineParser.getDoHelp())
141         {
142             help();
143
144             System.exit(0);
145         }
146
147         Properties JavaDoc props = _cmdLineParser.getProps();
148
149         AbstractChannelFactory _factory = AbstractChannelFactory.newFactory(props);
150
151         return _factory;
152     }
153
154     public static final void main(String JavaDoc[] args) throws Exception JavaDoc
155     {
156         newFactory(args);
157     }
158 }
Popular Tags