01 /*
02 *
03 * Licensed to the Apache Software Foundation (ASF) under one
04 * or more contributor license agreements. See the NOTICE file
05 * distributed with this work for additional information
06 * regarding copyright ownership. The ASF licenses this file
07 * to you under the Apache License, Version 2.0 (the
08 * "License"); you may not use this file except in compliance
09 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21 package org.apache.qpid.config;
22
23 public abstract class AbstractConfig
24 {
25 public boolean setOptions(String[] argv)
26 {
27 try
28 {
29 for(int i = 0; i < argv.length - 1; i += 2)
30 {
31 String key = argv[i];
32 String value = argv[i+1];
33 setOption(key, value);
34 }
35 return true;
36 }
37 catch(Exception e)
38 {
39 System.out.println(e.getMessage());
40 }
41 return false;
42 }
43
44 protected int parseInt(String msg, String i)
45 {
46 try
47 {
48 return Integer.parseInt(i);
49 }
50 catch(NumberFormatException e)
51 {
52 throw new RuntimeException(msg + ": " + i, e);
53 }
54 }
55
56 protected long parseLong(String msg, String i)
57 {
58 try
59 {
60 return Long.parseLong(i);
61 }
62 catch(NumberFormatException e)
63 {
64 throw new RuntimeException(msg + ": " + i, e);
65 }
66 }
67
68 public abstract void setOption(String key, String value);
69 }
|