001: /*
002: * <copyright>
003: *
004: * Copyright 2001-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.tools.csmart.core.cdata;
027:
028: import java.util.ArrayList;
029:
030: /**
031: * <code>AgentComponentData</code> extends <code>GenericComponentData</code>
032: * and sets the Component Type to {@link ComponentData#AGENT} and the
033: * class name to <code>org.cougaar.core.agent.SimpleAgent</code>.
034: * <br><br>
035: * This class also provides access to the agents plugins and their arguments.
036: *
037: * @see GenericComponentData
038: */
039: public class AgentComponentData extends GenericComponentData {
040:
041: private static final String defClassName = "org.cougaar.core.agent.SimpleAgent";
042:
043: /** Default Constructor **/
044: public AgentComponentData() {
045: type = ComponentData.AGENT;
046: className = defClassName;
047: }
048:
049: // FIXME: Do we need equivalent methods for Binders
050: // and other Misc components?
051:
052: /**
053: * Returns a list of all plugin names for this agent.
054: *
055: * @return a <code>String[]</code> array of all plugin names
056: */
057: public String[] getPluginNames() {
058: ArrayList names = new ArrayList();
059: ComponentData[] plugins = getChildren();
060:
061: for (int i = 0; i < plugins.length; i++) {
062: ComponentData plugin = plugins[i];
063: if (plugin.getType().equals(ComponentData.PLUGIN)) {
064: names.add(plugin.getName());
065: }
066: }
067:
068: return (String[]) names.toArray(new String[names.size()]);
069: }
070:
071: /**
072: * Returns all arguments for a specific plugin
073: *
074: * @param name Name of the plugin
075: * @return an <code>Object[]</code> array of all plugin arguments
076: */
077: public Object[] getPluginArgs(String name) {
078: ComponentData plugin = findPlugin(name);
079: if (plugin != null) {
080: return plugin.getParameters();
081: }
082: return null;
083: }
084:
085: /**
086: * Finds a specific plugin, for this agent, based
087: * on a name and returns the <code>ComponentData</code>
088: * for that plugin.
089: *
090: * @param name Name of the plugin to search for.
091: * @return a <code>ComponentData</code> for the specified plugin
092: */
093: private ComponentData findPlugin(String name) {
094: ComponentData[] plugins = getChildren();
095: for (int i = 0; i < plugins.length; i++) {
096: if (plugins[i].getName().equals(name)) {
097: return plugins[i];
098: }
099: }
100: return null;
101: }
102:
103: }
|