01: /*
02: * <copyright>
03: *
04: * Copyright 2000-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26: package org.cougaar.core.component;
27:
28: import java.util.List;
29: import java.util.Map;
30:
31: import org.cougaar.util.Arguments;
32: import org.cougaar.util.GenericStateModelAdapter;
33: import org.cougaar.util.annotations.Argument;
34:
35: /**
36: * Simple Component base class that provides named paramater support. Parameters
37: * should take the form <var>=<value>.
38: */
39: abstract public class ParameterizedComponent extends
40: GenericStateModelAdapter implements Component {
41: protected Arguments args;
42:
43: public void setArguments(Arguments args) {
44: this .args = args;
45: try {
46: new Argument(args).setAllFields(this );
47: } catch (Exception e) {
48: // TODO: Add Logging support when it's ready
49: throw new RuntimeException(
50: "Exception during field initialization", e);
51: }
52: }
53:
54: /** @see Arguments#getString(String) */
55: protected String getParameter(String key) {
56: return args.getString(key);
57: }
58:
59: /** @see Arguments#getString(String,String) */
60: protected String getParameter(String key, String defaultValue) {
61: return args.getString(key, defaultValue);
62: }
63:
64: /** @see Arguments#getLong(String,long) */
65: public long getParameter(String key, long defaultValue) {
66: return args.getLong(key, defaultValue);
67: }
68:
69: /** @see Arguments#getDouble(String,double) */
70: public double getParameter(String key, double defaultValue) {
71: return args.getDouble(key, defaultValue);
72: }
73:
74: /** @see Arguments#getStrings(String) */
75: public List<String> getParameterValues(String key) {
76: return args.getStrings(key);
77: }
78:
79: /** @see Arguments */
80: public Map<String, List<String>> getParameterMap() {
81: return args;
82: }
83: }
|