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.ui;
027:
028: import org.cougaar.tools.csmart.core.cdata.AgentAssetData;
029: import org.cougaar.tools.csmart.core.cdata.AgentComponentData;
030: import org.cougaar.tools.csmart.core.cdata.ComponentData;
031: import org.cougaar.tools.csmart.core.cdata.RelationshipData;
032: import org.cougaar.tools.csmart.core.property.ModifiableConfigurableComponent;
033: import org.cougaar.tools.csmart.core.property.Property;
034: import org.cougaar.tools.csmart.society.AssetComponent;
035: import org.cougaar.tools.csmart.society.ContainerBase;
036: import org.cougaar.tools.csmart.society.PropGroupBase;
037: import org.cougaar.tools.csmart.society.RelationshipBase;
038: import org.cougaar.util.TimeSpan;
039:
040: import java.text.DateFormat;
041: import java.text.ParseException;
042: import java.util.Collection;
043: import java.util.Date;
044: import java.util.Iterator;
045:
046: public class AssetUIComponent extends ModifiableConfigurableComponent
047: implements AssetComponent {
048:
049: // private Property propAssetType;
050: private Property propAssetClass;
051: private Property propUniqueID;
052: private Property propUnitName;
053: private Property propUIC;
054:
055: public AssetUIComponent() {
056: super ("AssetData");
057: }
058:
059: public void initProperties() {
060: // propAssetType = addProperty(AssetComponent.PROP_TYPE, new Integer(0));
061: // propAssetType.setToolTip(PROP_TYPE_DESC);
062: propAssetClass = addProperty(AssetComponent.PROP_CLASS,
063: "MilitaryOrganization");
064: propAssetClass.setToolTip(PROP_CLASS_DESC);
065: propUniqueID = addProperty(AssetComponent.PROP_UID, "UTC/RTOrg");
066: propUniqueID.setToolTip(PROP_UID_DESC);
067: propUnitName = addProperty(AssetComponent.PROP_UNITNAME, "");
068: propUnitName.setToolTip(PROP_UNITNAME_DESC);
069: propUIC = addProperty(PROP_UIC, "");
070: propUIC.setToolTip(PROP_UIC_DESC);
071: }
072:
073: /**
074: * Add component data for asset properties, relationships,
075: * and property groups.
076: */
077: public ComponentData addComponentData(ComponentData data) {
078: AgentAssetData assetData = new AgentAssetData(
079: (AgentComponentData) data);
080:
081: // String agent = data.getName();
082:
083: // FIXME: IF asset class is null or empty, perhaps abort? Or
084: // fill in the agent name inside these?
085: // Of course, doing it in the addComponentData is bad,
086: // cause it modifies the Component
087:
088: // assetData.setType(((Integer)propAssetType.getValue()).intValue());
089: assetData.setAssetClass((String) propAssetClass.getValue());
090: assetData.setUniqueID((String) propUniqueID.getValue());
091: assetData.setUnitName((String) propUnitName.getValue());
092: assetData.setUIC((String) propUIC.getValue());
093:
094: // Add Relationships.
095: Iterator iter = ((Collection) getDescendentsOfClass(ContainerBase.class))
096: .iterator();
097: while (iter.hasNext()) {
098: ContainerBase container = (ContainerBase) iter.next();
099: if (container.getShortName().equals("Relationships")) {
100: for (int i = 0; i < container.getChildCount(); i++) {
101: RelationshipBase rel = (RelationshipBase) container
102: .getChild(i);
103: RelationshipData rData = new RelationshipData();
104: rData.setType((String) rel.getProperty(
105: RelationshipBase.PROP_TYPE).getValue());
106: rData.setRole((String) rel.getProperty(
107: RelationshipBase.PROP_ROLE).getValue());
108: rData.setItemId((String) rel.getProperty(
109: RelationshipBase.PROP_ITEM).getValue());
110: rData.setTypeId((String) rel.getProperty(
111: RelationshipBase.PROP_TYPEID).getValue());
112: rData
113: .setSupported((String) rel.getProperty(
114: RelationshipBase.PROP_SUPPORTED)
115: .getValue());
116:
117: DateFormat df = DateFormat.getInstance();
118: try {
119: Date start = df.parse((String) rel.getProperty(
120: RelationshipBase.PROP_STARTTIME)
121: .getValue());
122: Date end = df.parse((String) rel.getProperty(
123: RelationshipBase.PROP_STOPTIME)
124: .getValue());
125: rData.setStartTime(start.getTime());
126: rData.setEndTime(end.getTime());
127: } catch (ParseException pe) {
128: if (log.isErrorEnabled()) {
129: log
130: .error(
131: "Caught Exception parsing Date, using default dates.",
132: pe);
133: }
134: rData.setStartTime(TimeSpan.MIN_VALUE);
135: rData.setEndTime(TimeSpan.MAX_VALUE);
136: }
137: assetData.addRelationship(rData);
138: }
139: }
140: }
141:
142: // FIXME: Perhaps check that ClusterPG (MessageAddress),
143: // ItemIdentificationPG (ItemIdentifiation), TypeIdentificationPG (TypeIdentification)
144: // are, at a minimum, among those filled in?
145: // What would I do though if they're not?
146:
147: // Add Property Groups.
148: iter = ((Collection) getDescendentsOfClass(ContainerBase.class))
149: .iterator();
150: while (iter.hasNext()) {
151: ContainerBase container = (ContainerBase) iter.next();
152: if (container.getShortName().equals("Property Groups")) {
153: for (int i = 0; i < container.getChildCount(); i++) {
154: PropGroupBase pg = (PropGroupBase) container
155: .getChild(i);
156: assetData.addPropertyGroup(pg.getPropGroupData());
157: }
158: }
159: }
160:
161: data.addAgentAssetData(assetData);
162: return data;
163: }
164:
165: }
|