Source Code Cross Referenced for Main.java in  » Net » Coadunation_1.0.1 » com » rift » coad » commandline » timercommandlinetool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Coadunation_1.0.1 » com.rift.coad.commandline.timercommandlinetool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Timer: The timer class
003:         * Copyright (C) 2006-2007  Rift IT Contracting
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
018:         *
019:         * Main.java
020:         */
021:
022:        // package path
023:        package com.rift.coad.commandline.timercommandlinetool;
024:
025:        // java imports
026:        import com.rift.coad.daemon.timer.TimerEvent;
027:        import java.io.Serializable;
028:        import java.util.ArrayList;
029:        import java.util.Hashtable;
030:        import java.util.List;
031:        import javax.naming.Context;
032:        import javax.naming.InitialContext;
033:        import javax.rmi.PortableRemoteObject;
034:        import com.rift.coad.daemon.timer.Timer;
035:
036:        // log4j
037:        import org.apache.log4j.BasicConfigurator;
038:
039:        /**
040:         *
041:         * @author Glynn Chaldecott
042:         *
043:         * This class is a command line tool for the Timer Daemon and gives a user basic
044:         * functionality through the command line.
045:         */
046:        public class Main {
047:            public String[] args = null;
048:            public String url = "";
049:            public String host = "";
050:            public String username = "";
051:            public String password = "";
052:
053:            /** Creates a new instance of Main */
054:            public Main() {
055:            }
056:
057:            /**
058:             * @param args the command line arguments
059:             */
060:            public static void main(String[] args) {
061:                BasicConfigurator.configure();
062:                Main mainProgram = new Main();
063:                mainProgram.setArgs(args);
064:                mainProgram.commandLine();
065:            }
066:
067:            /**
068:             * This method simple sets the public args variable.
069:             *
070:             * @param args This is the args passed into the main method.
071:             */
072:            public void setArgs(String[] args) {
073:                this .args = args;
074:            }
075:
076:            /**
077:             * This method breaks the arguments down and uses them to perform the
078:             * necessary task.
079:             */
080:            public void commandLine() {
081:                try {
082:                    Timer sb = null;
083:                    int choice = -1;
084:                    List service = new ArrayList();
085:                    String jndi = "";
086:                    Serializable event = null;
087:                    boolean recure = false;
088:                    int minute = -1;
089:                    int hour = -1;
090:                    int day = -1;
091:                    int month = -1;
092:                    int id = 0;
093:
094:                    for (int i = 0; i < args.length; i++) {
095:                        if (args[i].equals("-r")) {
096:                            choice = 0;
097:                        } else if (args[i].equals("-l")) {
098:                            choice = 1;
099:                        } else if (args[i].equals("-d")) {
100:                            choice = 2;
101:                        } else if (args[i].equals("-m")) {
102:                            i++;
103:                            month = Integer.parseInt(args[i]);
104:                        } else if (args[i].equals("-da")) {
105:                            i++;
106:                            day = Integer.parseInt(args[i]);
107:                        } else if (args[i].equals("-ho")) {
108:                            i++;
109:                            hour = Integer.parseInt(args[i]);
110:                        } else if (args[i].equals("-mi")) {
111:                            i++;
112:                            minute = Integer.parseInt(args[i]);
113:                        } else if (args[i].equals("-id")) {
114:                            i++;
115:                            id = Integer.parseInt(args[i]);
116:                        } else if (args[i].equals("-j")) {
117:                            i++;
118:                            jndi = args[i];
119:                        } else if (args[i].equals("-e")) {
120:                            i++;
121:                            String temp = "";
122:                            boolean flag = true;
123:                            while (flag) {
124:                                String temp2 = args[i];
125:                                if (temp2.charAt(0) == '-') {
126:                                    flag = false;
127:                                    i--;
128:                                } else {
129:                                    temp += temp2;
130:                                    i++;
131:                                }
132:                            }
133:                            event = (Serializable) temp;
134:                        } else if (args[i].equals("-re")) {
135:                            i++;
136:                            String temp = args[i];
137:                            if (temp.toUpperCase().equals("FALSE")
138:                                    || temp.toUpperCase().equals("F")) {
139:                                recure = false;
140:                            } else if (temp.toUpperCase().equals("TRUE")
141:                                    || temp.toUpperCase().equals("T")) {
142:                                recure = true;
143:                            }
144:                        } else if (args[i].equals("-h")) {
145:                            choice = 3;
146:                        } else if (args[i].equals("-s")) {
147:                            i++;
148:                            host = args[i];
149:                            if (host.indexOf(":") == -1) {
150:                                host += ":2000";
151:                            }
152:                        } else if (args[i].equals("-u")) {
153:                            i++;
154:                            url = args[i];
155:                        } else if (args[i].equals("-U")) {
156:                            i++;
157:                            username = args[i];
158:                        } else if (args[i].equals("-P")) {
159:                            i++;
160:                            password = args[i];
161:                        }
162:                    }
163:                    switch (choice) {
164:                    case 0:
165:                        if (!url.equals("") && !host.equals("")) {
166:                            sb = createConnection();
167:                            sb.register(jndi, month, day, hour, minute, event,
168:                                    recure);
169:                            System.out
170:                                    .println("The event has been registered.");
171:                        } else {
172:                            System.out.println("Statment missing elements.");
173:                            help();
174:                        }
175:                        break;
176:                    case 1:
177:                        if (!url.equals("") && !host.equals("")) {
178:                            sb = createConnection();
179:                            TimerEvent[] temp = sb.listEvents();
180:                            for (int i = 0; i < temp.length; i++) {
181:                                System.out.println(temp[i].getId() + " "
182:                                        + temp[i].getJndi() + " "
183:                                        + temp[i].getMonth() + "-"
184:                                        + temp[i].getDay() + "-"
185:                                        + temp[i].getHour() + "-"
186:                                        + temp[i].getMinute() + " "
187:                                        + temp[i].getEvent());
188:                            }
189:                        } else {
190:                            System.out.println("Statment missing elements.");
191:                            help();
192:                        }
193:                        break;
194:                    case 2:
195:                        if (!url.equals("") && !host.equals("")) {
196:                            sb = createConnection();
197:                            sb.deleteEvent(id);
198:                            System.out.println("The event has been deleted.");
199:                        } else {
200:                            System.out.println("Statment missing elements.");
201:                            help();
202:                        }
203:                        break;
204:                    case 3:
205:                        help();
206:                        break;
207:                    default:
208:                        System.out.println("There was a problem with the "
209:                                + "statement");
210:                        help();
211:                        break;
212:                    }
213:                } catch (Exception ex) {
214:                    ex.printStackTrace();
215:                }
216:            }
217:
218:            public void help() {
219:                System.out.println("Help");
220:                System.out
221:                        .println("\t-r \tThis is to be used to Register an event.");
222:                System.out
223:                        .println("\t-l \tThis is to be used to retrieve a list of "
224:                                + "events.");
225:                System.out
226:                        .println("\t-d \tThis is to be used to delete an event.");
227:                System.out
228:                        .println("\t-m \tThis is to be followed by the month.");
229:                System.out
230:                        .println("\t-da \tThis is to be followed by the day.");
231:                System.out
232:                        .println("\t-ho \tThis is to be followed by the hour.");
233:                System.out
234:                        .println("\t-mi \tThis is to be followed by the minute.");
235:                System.out
236:                        .println("\t-id \tThis is to be followed by the event id.");
237:                System.out
238:                        .println("\t-j \tThis is to be followed by the JNDI for "
239:                                + "the service. This can only be called once in a statment.");
240:                System.out
241:                        .println("\t-s \tThis is to be followed by the host and "
242:                                + "port on which the Timer Daemon is running and is required.");
243:                System.out
244:                        .println("\t-u \tThis is to be followed by the JNDI for "
245:                                + "the Timer Daemon and is required.");
246:                System.out
247:                        .println("\t-U \tThis must be followed by the username for "
248:                                + "the connection and is required.");
249:                System.out
250:                        .println("\t-P \tThis must be followed by the password for "
251:                                + "the connection and is required.");
252:            }
253:
254:            /**
255:             * This method connects to the Timer Daemon and then returns the Object.
256:             *
257:             * @return This method returns a connection to the Timer Daemon.
258:             */
259:            public com.rift.coad.daemon.timer.Timer createConnection()
260:                    throws Exception {
261:                try {
262:                    Hashtable env = new Hashtable();
263:                    env.put(Context.INITIAL_CONTEXT_FACTORY,
264:                            "com.rift.coad.client.naming."
265:                                    + "CoadunationInitialContextFactory");
266:                    env.put(Context.PROVIDER_URL, host);
267:                    env.put("com.rift.coad.username", username);
268:                    env.put("com.rift.coad.password", password);
269:                    Context ctx = new InitialContext(env);
270:
271:                    Object obj = ctx.lookup(url);
272:                    com.rift.coad.daemon.timer.Timer beanInterface = (com.rift.coad.daemon.timer.Timer) PortableRemoteObject
273:                            .narrow(obj, com.rift.coad.daemon.timer.Timer.class);
274:
275:                    if (beanInterface == null) {
276:                        throw new Exception("narrow failed.");
277:                    } else {
278:                        return beanInterface;
279:                    }
280:                } catch (Exception ex) {
281:                    System.out.println(ex.getMessage());
282:                    ex.printStackTrace(System.out);
283:                    throw new Exception(ex);
284:                }
285:            }
286:
287:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.