001: /*
002: * <copyright>
003: *
004: * Copyright 2000-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.society.cdata;
027:
028: import org.cougaar.tools.csmart.core.cdata.ComponentData;
029: import org.cougaar.tools.csmart.core.property.BaseComponent;
030: import org.cougaar.tools.csmart.core.property.Property;
031: import org.cougaar.tools.csmart.society.AgentBase;
032: import org.cougaar.tools.csmart.society.AgentComponent;
033: import org.cougaar.tools.csmart.society.BinderBase;
034: import org.cougaar.tools.csmart.society.ComponentBase;
035: import org.cougaar.tools.csmart.society.ContainerBase;
036: import org.cougaar.tools.csmart.society.PluginBase;
037:
038: /**
039: * Create a ConfigurableComponent which represents an Agent
040: * from ComponentData.
041: */
042: public class AgentCDataComponent extends AgentBase implements
043: AgentComponent {
044:
045: ComponentData cdata;
046:
047: /**
048: * Creates a new <code>AgentCDataComponent</code> instance.
049: *
050: * @param cdata <code>ComponentData</code> to use as base.
051: */
052: public AgentCDataComponent(ComponentData cdata) {
053: super (cdata.getName());
054: this .cdata = cdata;
055: }
056:
057: /**
058: * Initializes all <code>Property</code> values for this class.
059: *
060: */
061: public void initProperties() {
062: super .initProperties();
063: Property p = addProperty(PROP_CLASSNAME, new String(cdata
064: .getClassName()));
065: p.setToolTip(PROP_CLASSNAME_DESC);
066:
067: addComponent(ComponentData.AGENTBINDER, "Binders");
068: addComponent(ComponentData.PLUGIN, "Plugins");
069: addComponents();
070: addAssetData();
071: }
072:
073: protected void addComponent(String typeid, String containerName) {
074: ContainerBase container = new ContainerBase(containerName);
075: container.initProperties();
076: addChild(container);
077:
078: ComponentData[] childCData = cdata.getChildren();
079: ComponentBase component = null;
080: for (int i = 0; i < childCData.length; i++) {
081: if (childCData[i].getType().equals(typeid)) {
082:
083: if (typeid.equals(ComponentData.PLUGIN)) {
084: component = new PluginBase(childCData[i].getName(),
085: childCData[i].getClassName(), childCData[i]
086: .getPriority());
087: } else if (typeid.equals(ComponentData.AGENTBINDER)) {
088: component = new BinderBase(childCData[i].getName(),
089: childCData[i].getClassName(), childCData[i]
090: .getPriority());
091: }
092: component.initProperties();
093: component.setComponentType(childCData[i].getType());
094:
095: Object[] parameters = childCData[i].getParameters();
096: for (int j = 0; j < parameters.length; j++)
097: // component.addProperty(ComponentBase.PROP_PARAM + j, parameters[j]);
098: component.addParameter(parameters[j]);
099: container.addChild(component);
100: }
101: }
102: }
103:
104: // FIXME: Add misc components -- how do I find the type though?
105: protected void addComponents() {
106: // add plugins
107: ContainerBase container = new ContainerBase("Other Components");
108: container.initProperties();
109: addChild(container);
110:
111: ComponentData[] childCData = cdata.getChildren();
112: for (int i = 0; i < childCData.length; i++) {
113: if (childCData[i].getType().equals(ComponentData.PLUGIN)
114: || childCData[i].getType().equals(
115: ComponentData.AGENTBINDER)
116: || !childCData[i].getParent().getType().equals(
117: ComponentData.AGENT)) {
118: // not added here
119: } else {
120: ComponentBase plugin = new ComponentBase(childCData[i]
121: .getName(), childCData[i].getClassName(),
122: childCData[i].getPriority(), childCData[i]
123: .getType());
124: plugin.initProperties();
125: // plugin.setComponentType(childCData[i].getType());
126: Object[] parameters = childCData[i].getParameters();
127: for (int j = 0; j < parameters.length; j++)
128: // plugin.addProperty(ComponentBase.PROP_PARAM + j, parameters[j]);
129: plugin.addParameter(parameters[j]);
130: container.addChild(plugin);
131: }
132: }
133:
134: }
135:
136: protected void addAssetData() {
137: // add asset data components
138: if (cdata.getAgentAssetData() != null) {
139: BaseComponent asset = (BaseComponent) new AssetCDataComponent(
140: cdata.getAgentAssetData());
141: asset.initProperties();
142: addChild(asset);
143: }
144: }
145: } // End of AgentCDataComponent
|