Source code: com/panacya/platform/service/bus/client/ClientArgs.java
1 /**
2 *
3 * Copyright 2004 Michael Gaffney
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 package com.panacya.platform.service.bus.client;
19
20 /**
21 * @author <a href="mailto:michael.gaffney@panacya.com">Michael Gaffney </a>
22 */
23 public class ClientArgs {
24 private long timeout = -1;
25 private String command;
26 private String destination;
27
28 private int noOfMessages = 1;
29
30 public ClientArgs(String[] args) {
31 /*
32 int argCount = args.length;
33
34 System.out.println(argCount);
35 for(int i = 0 ; i < argCount; i++){
36 System.out.println(args[i] + " ..........");
37 }
38 */
39 switch (args.length) {
40 case 4:
41 setNoOfMessages(args[3]);
42 case 3:
43 setTimeout(args[2]);
44 case 2:
45 destination = args[1];
46 command = args[0];
47 break;
48 default :
49 printHelp();
50 }
51 }
52
53 public String getCommand() {
54 return command;
55 }
56
57 public String getDestination() {
58 return destination;
59 }
60
61 public long getTimeout() {
62 return timeout;
63 }
64
65 private void setTimeout(String timout) {
66 if (!isEmpty(timout)) {
67 try {
68 timeout = Long.valueOf(timout).longValue();
69 } catch (NumberFormatException e) {
70 System.err.println(e.toString());
71 }
72 }
73 }
74
75 public int getNoOfMessages() {
76 return noOfMessages;
77 }
78
79 public void setNoOfMessages(String count) {
80 System.out.println("noOfMessage " + count);
81 this.noOfMessages = Integer.parseInt(count);
82 }
83
84 private static boolean isEmpty(String value) {
85 return value == null || "".equals(value.trim());
86 }
87
88 private static void printHelp() {
89 System.out.println("JmsSimpleClient command(send | receive | send-receive) noOfMessages destination timeout");
90 }
91 }
92