Source Code Cross Referenced for AssetCDataComponent.java in  » Science » Cougaar12_4 » org » cougaar » tools » csmart » society » cdata » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.tools.csmart.society.cdata 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.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.PropGroupData;
032:        import org.cougaar.tools.csmart.core.cdata.RelationshipData;
033:        import org.cougaar.tools.csmart.core.property.ModifiableConfigurableComponent;
034:        import org.cougaar.tools.csmart.core.property.Property;
035:        import org.cougaar.tools.csmart.society.AssetComponent;
036:        import org.cougaar.tools.csmart.society.ContainerBase;
037:        import org.cougaar.tools.csmart.society.PropGroupBase;
038:        import org.cougaar.tools.csmart.society.RelationshipBase;
039:        import org.cougaar.tools.csmart.ui.viewer.CSMART;
040:        import org.cougaar.util.TimeSpan;
041:
042:        import java.text.DateFormat;
043:        import java.text.ParseException;
044:        import java.util.Collection;
045:        import java.util.Date;
046:        import java.util.Iterator;
047:
048:        /**
049:         * ConfigurableComponent that represents an <code>AssetComponentData</code>
050:         */
051:        public class AssetCDataComponent extends
052:                ModifiableConfigurableComponent implements  AssetComponent {
053:
054:            /** Property Definitions **/
055:
056:            /** Type Property Definition **/
057:            //  public static final String PROP_TYPE = "Asset Type";
058:            /** Type Description Definition **/
059:            //  public static final String PROP_TYPE_DESC = "Type of Asset";
060:            /** Class Definition **/
061:            public static final String PROP_CLASS = "Asset Class";
062:
063:            /** Class Description Definition **/
064:            public static final String PROP_CLASS_DESC = "Class of the Asset";
065:
066:            /** UID Definition **/
067:            public static final String PROP_UID = "UID";
068:
069:            /** UID Description Definition **/
070:            public static final String PROP_UID_DESC = "UID of the Asset";
071:
072:            /** Unit Name Definition **/
073:            public static final String PROP_UNITNAME = "Unit Name";
074:
075:            /** Unit Name Description Definition **/
076:            public static final String PROP_UNITNAME_DESC = "Unit Name of the Asset";
077:
078:            /** UIC Definition **/
079:            public static final String PROP_UIC = "UIC";
080:
081:            /** UID Description Definition **/
082:            public static final String PROP_UIC_DESC = "UIC of the Asset";
083:
084:            //  private Property propAssetType;
085:            private Property propAssetClass;
086:            private Property propUniqueID;
087:            private Property propUnitName;
088:            private Property propUIC;
089:            private AgentAssetData createdFromData;
090:
091:            /**
092:             * Creates a new <code>AssetCDataComponent</code> instance.
093:             *
094:             * @param data <code>AgentAssetData</code> to create from
095:             */
096:            public AssetCDataComponent(AgentAssetData data) {
097:                super ("AssetData");
098:                createdFromData = data;
099:            }
100:
101:            /**
102:             * Init properties from AgentAssetData
103:             */
104:
105:            public void initProperties() {
106:                //    propAssetType = addProperty(PROP_TYPE, 
107:                //                                new Integer(createdFromData.getType()));
108:                //    propAssetType.setToolTip(PROP_TYPE_DESC);
109:                if (createdFromData == null)
110:                    return;
111:                propAssetClass = addProperty(PROP_CLASS, createdFromData
112:                        .getAssetClass());
113:                propAssetClass.setToolTip(PROP_CLASS_DESC);
114:                if (createdFromData.getUniqueID() != null) {
115:                    propUniqueID = addProperty(PROP_UID, createdFromData
116:                            .getUniqueID());
117:                    propUniqueID.setToolTip(PROP_UID_DESC);
118:                }
119:                // Unit name is allowed to be null, if it is, give an empty string.
120:                String unitname = (createdFromData.getUnitName() == null) ? ""
121:                        : createdFromData.getUnitName();
122:                propUnitName = addProperty(PROP_UNITNAME, unitname);
123:                propUnitName.setToolTip(PROP_UNITNAME_DESC);
124:
125:                if (createdFromData.getUIC() != null) {
126:                    propUIC = addProperty(PROP_UIC, createdFromData.getUIC());
127:                    propUIC.setToolTip(PROP_UIC_DESC);
128:                }
129:
130:                addPropGroups(createdFromData);
131:                addRelationships(createdFromData.getRelationshipData());
132:            }
133:
134:            /**
135:             * Add component data for asset properties, relationships,
136:             * and property groups. Only additions are made in this method,
137:             * no modifications to existing data.
138:             *
139:             * @param data Pointer to the global <code>ComponentData</code> tree
140:             * @return an updated <code>ComponentData</code> value
141:             */
142:            public ComponentData addComponentData(ComponentData data) {
143:                AgentAssetData assetData = new AgentAssetData(
144:                        (AgentComponentData) data);
145:                //    assetData.setType(((Integer)propAssetType.getValue()).intValue());
146:                assetData.setAssetClass((String) propAssetClass.getValue());
147:                assetData.setUniqueID((String) propUniqueID.getValue());
148:                assetData.setUnitName((String) propUnitName.getValue());
149:                assetData.setUIC((String) propUIC.getValue());
150:
151:                // Add Relationships.
152:                Iterator iter = ((Collection) getDescendentsOfClass(ContainerBase.class))
153:                        .iterator();
154:                while (iter.hasNext()) {
155:                    ContainerBase container = (ContainerBase) iter.next();
156:                    if (container.getShortName().equals("Relationships")) {
157:                        for (int i = 0; i < container.getChildCount(); i++) {
158:                            RelationshipBase rel = (RelationshipBase) container
159:                                    .getChild(i);
160:                            RelationshipData rData = new RelationshipData();
161:                            if (rel != null) {
162:                                if (rel.getProperty(RelationshipBase.PROP_TYPE) == null) {
163:                                    if (log.isErrorEnabled()) {
164:                                        log
165:                                                .error(this 
166:                                                        + " using CSMART "
167:                                                        + CSMART.writeDebug()
168:                                                        + " got null relationship type for "
169:                                                        + data.getName()
170:                                                        + " in rel #"
171:                                                        + i
172:                                                        + " with role="
173:                                                        + rel
174:                                                                .getProperty(RelationshipBase.PROP_ROLE)
175:                                                        + ", ItemId="
176:                                                        + rel
177:                                                                .getProperty(RelationshipBase.PROP_ITEM)
178:                                                        + ", please report this on bug# 1304");
179:                                    }
180:                                } else {
181:                                    rData.setType((String) rel.getProperty(
182:                                            RelationshipBase.PROP_TYPE)
183:                                            .getValue());
184:                                }
185:                                rData.setRole((String) rel.getProperty(
186:                                        RelationshipBase.PROP_ROLE).getValue());
187:                                rData.setItemId((String) rel.getProperty(
188:                                        RelationshipBase.PROP_ITEM).getValue());
189:                                rData.setTypeId((String) rel.getProperty(
190:                                        RelationshipBase.PROP_TYPEID)
191:                                        .getValue());
192:                                rData.setSupported((String) rel.getProperty(
193:                                        RelationshipBase.PROP_SUPPORTED)
194:                                        .getValue());
195:
196:                                DateFormat df = DateFormat.getInstance();
197:                                try {
198:                                    Date start = df
199:                                            .parse((String) rel
200:                                                    .getProperty(
201:                                                            RelationshipBase.PROP_STARTTIME)
202:                                                    .getValue());
203:                                    Date end = df
204:                                            .parse((String) rel
205:                                                    .getProperty(
206:                                                            RelationshipBase.PROP_STOPTIME)
207:                                                    .getValue());
208:                                    rData.setStartTime(start.getTime());
209:                                    rData.setEndTime(end.getTime());
210:                                } catch (ParseException pe) {
211:                                    if (log.isErrorEnabled()) {
212:                                        log
213:                                                .error(
214:                                                        "Caught Exception parsing Date, using default dates.",
215:                                                        pe);
216:                                    }
217:                                    rData.setStartTime(TimeSpan.MIN_VALUE);
218:                                    rData.setEndTime(TimeSpan.MAX_VALUE);
219:                                }
220:
221:                                assetData.addRelationship(rData);
222:                            } else {
223:                                // null relationship?
224:                                if (log.isErrorEnabled()) {
225:                                    log.error(this  + " Got null relationship #"
226:                                            + i);
227:                                }
228:                            }
229:                        }
230:                    }
231:                }
232:
233:                // Add Property Groups.
234:                iter = ((Collection) getDescendentsOfClass(ContainerBase.class))
235:                        .iterator();
236:                while (iter.hasNext()) {
237:                    ContainerBase container = (ContainerBase) iter.next();
238:                    if (container.getShortName().equals("Property Groups")) {
239:                        for (int i = 0; i < container.getChildCount(); i++) {
240:                            PropGroupBase pg = (PropGroupBase) container
241:                                    .getChild(i);
242:                            assetData.addPropertyGroup(pg.getPropGroupData());
243:                        }
244:                    }
245:                }
246:
247:                data.addAgentAssetData(assetData);
248:                return data;
249:            }
250:
251:            private void addRelationships(RelationshipData[] rel) {
252:                ContainerBase relContainer = new ContainerBase("Relationships");
253:                relContainer.initProperties();
254:                addChild(relContainer);
255:                for (int i = 0; i < rel.length; i++) {
256:                    RelationshipBase newR = new RelationshipBase(rel[i]);
257:                    newR.initProperties();
258:                    relContainer.addChild(newR);
259:                }
260:            }
261:
262:            private void addPropGroups(AgentAssetData aad) {
263:                ContainerBase pgContainer = new ContainerBase("Property Groups");
264:                pgContainer.initProperties();
265:                addChild(pgContainer);
266:                Iterator iter = aad.getPropGroupsIterator();
267:                while (iter.hasNext()) {
268:                    PropGroupData pgd = (PropGroupData) iter.next();
269:                    PropGroupBase newPG = new PropGroupBase(pgd);
270:                    if (log.isDebugEnabled()) {
271:                        log.debug("Adding: " + pgd.getName());
272:                    }
273:                    newPG.initProperties();
274:                    pgContainer.addChild(newPG);
275:                }
276:            }
277:
278:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.