Source Code Cross Referenced for AgentAssetData.java in  » Science » Cougaar12_4 » org » cougaar » tools » csmart » core » 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.core.cdata 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:
027:        package org.cougaar.tools.csmart.core.cdata;
028:
029:        import java.io.Serializable;
030:        import java.util.ArrayList;
031:        import java.util.Iterator;
032:        import java.util.List;
033:
034:        /**
035:         * Hold the data to describe the local Asset in an Agent. <br>
036:         * This is usually an Organization or Entity, such as would be described
037:         * in a prototype-ini.dat file.<br>
038:         * Elements:<ul>
039:         * <li><b>Class:</b> Class of Asset to instantiate.</li>
040:         * <li><b>Type:</b> Entity, Organization, or Organization with Time-Phased Relationships. This governs what data should be sent to the Agent.</li>
041:         * <li><b>Agent:</b> The Agent containing this Asset.</li>
042:         * <li><b>AgentID:</b> Calculated from the Agent.</li>
043:         * <li><b>UniqueID:</b> (Orgs only, unused) UTC/RTOrg or UTC/CombatOrg usually</li>
044:         * <li><b>UnitName:</b> (Orgs only, optional)</li>
045:         * <li><b>UIC:</b> (Orgs only) Usually UIC/[AgentID]</li>
046:         * <li><b>Roles:</b> A collection of String role names.</li>
047:         * <li><b>Relationships:</b> The relationships this Asset has with others.
048:         * The format of these differs based on the Asset type.</li>
049:         * <li><b>PropertyGroups:</b> The remainder of the data is a set of PropertyGroups.<br>
050:         * These PGs have a name, and then a collection of properties.
051:         * They always include a ClusterPG, and often include a TypeIdentificationPG
052:         * (Entities only), ItemIdentificationPG (Entities only), OrganizationPG
053:         * or EntityPG as appropriate, CommunityPG, MilitaryOrgPG (for
054:         * Organizations only), etc.</li>
055:         * </ul><br>
056:         *
057:         */
058:        public class AgentAssetData implements  Serializable {
059:
060:            /** All Possible Entity Types **/
061:
062:            // Item & type should be specified explicitly
063:            // EntityPG not OrgPG will be included
064:            // UniqueID, UnitName & UIC will be excluded
065:            // Relationships will include type, item, start, & end
066:            /** Asset of type Entity**/
067:            public static final int ENTITY = 0;
068:
069:            /** Asset of type Organization **/
070:            public static final int ORG = 1;
071:
072:            /** Asset of type Organization with Time-Phased Relationships **/
073:            // The -relationships.ini file will be written out
074:            public static final int TPORG = 2;
075:
076:            /** Ini file format is new style (uses AssetDataPlugin) **/
077:            public static final int NEW_FORMAT = 0;
078:
079:            /** Ini file format is the old style **/
080:            public static final int OLD_FORMAT = 1;
081:
082:            /** Common Asset Class Types **/
083:
084:            /** Entity Asset Class **/
085:            public static final String ENTITY_ASSETCLASS = "Entity";
086:
087:            /** Combat Asset Class **/
088:            public static final String COMBAT_ASSETCLASS = "CombatOrganization";
089:
090:            // The default type is ENTITY
091:            private int type = AgentAssetData.ENTITY;
092:
093:            private String assetClass = null; // CombatOrganization, Entity, etc
094:            private String uniqID = null; // For Orgs only, not used, UTC/RTOrg or CombatOrg
095:            private String unitname = null; // Org only, optional
096:            private String uic = null; // Org only, usu UIC/AgentID
097:
098:            // Note: AgentID is retrieved from the parent
099:            private AgentComponentData agent; // The Agent in which this sits
100:
101:            private List roles; // Strings
102:            private List propGroups; // PropGroupData objects
103:            private List relats; // RelatData objects
104:
105:            private int iniStyle = AgentAssetData.NEW_FORMAT;
106:
107:            // Flag if this object has been modified and needs to be (re) saved
108:            private boolean modified = false;
109:
110:            /**
111:             * Creates a new <code>AgentAssetData</code> instance.
112:             * Assigned to a specific agent.
113:             *
114:             * @param parent an <code>AgentComponentData</code> value
115:             * indicating the agent that owns this asset data.
116:             */
117:            public AgentAssetData(AgentComponentData parent) {
118:                roles = new ArrayList();
119:                propGroups = new ArrayList();
120:                relats = new ArrayList();
121:                agent = parent;
122:            }
123:
124:            /**
125:             * Returns the parent of this asset.
126:             * (This is the same value as {@link #getAgent})
127:             *
128:             * @return an <code>AgentComponentData</code> value
129:             * for the parent of this asset.
130:             */
131:            public AgentComponentData getParent() {
132:                return agent;
133:            }
134:
135:            /**
136:             * Returns the agent associated with this asset.
137:             * (This is the same value as {@link #getParent})
138:             *
139:             * @return an <code>AgentComponentData</code> for the
140:             * agent of this asset.
141:             */
142:            public AgentComponentData getAgent() {
143:                return agent;
144:            }
145:
146:            /**
147:             * Returns the type of asset.  Currently, there are
148:             * three possible agent types:
149:             * <ul>
150:             *   <li>{@link #ORG} - Organization</li>
151:             *   <li>{@link #ENTITY} - Entity</li>
152:             *   <li>{@link #TPORG} - Time Phased Organization</li>
153:             * </ul>
154:             *
155:             * @return an <code>int</code> value
156:             * Representating the type of this asset.
157:             */
158:            public int getType() {
159:                return type;
160:            }
161:
162:            /**
163:             * Sets the type of this asset.
164:             *
165:             * @see #getType for possible types.
166:             * @param type an <code>int</code> value
167:             * representating the type of this asset.
168:             */
169:            public void setType(int type) {
170:                this .type = type;
171:            }
172:
173:            /**
174:             * Indicates if this asset is an Entity Asset.
175:             *
176:             * @return a <code>boolean</code> value
177:             */
178:            public boolean isEntity() {
179:                return this .type == AgentAssetData.ENTITY;
180:            }
181:
182:            /**
183:             * Indicates if this asset is an Org Asset.
184:             *
185:             * @return a <code>boolean</code> value
186:             */
187:            public boolean isOrg() {
188:                return this .type == AgentAssetData.ORG;
189:            }
190:
191:            /**
192:             * Indicates if this asset is an Time-Phased Org Asset.
193:             *
194:             * @return a <code>boolean</code> value
195:             */
196:            public boolean isTPOrg() {
197:                return this .type == AgentAssetData.TPORG;
198:            }
199:
200:            /**
201:             * Gets the AgentID for this asset.
202:             * This field is auto-calculated from the agent name.
203:             *
204:             * @return a <code>String</code> value of the AgentID
205:             */
206:            public String getAgentID() {
207:                if (agent != null) {
208:                    return agent.getName();
209:                } else {
210:                    return null;
211:                }
212:            }
213:
214:            /**
215:             * Sets the ini file format style.
216:             *
217:             * @param style 
218:             */
219:            public void setIniFormat(int style) {
220:                this .iniStyle = style;
221:            }
222:
223:            /**
224:             * Gets the current ini format style
225:             *
226:             * @return an <code>int</code> value
227:             */
228:            public int getIniFormat() {
229:                return this .iniStyle;
230:            }
231:
232:            /**
233:             * Returns true if the ini file is of the new
234:             * format.  
235:             *
236:             * @return a <code>boolean</code> value
237:             */
238:            public boolean isNewIniFormat() {
239:                return (this .iniStyle == AgentAssetData.NEW_FORMAT);
240:            }
241:
242:            /**
243:             * Gets the Asset Class for this asset.
244:             *
245:             * @return a <code>String</code> value of the Asset Class
246:             */
247:            public String getAssetClass() {
248:                return assetClass;
249:            }
250:
251:            /**
252:             * Sets the asset class for this asset.
253:             *
254:             * @param clss a <code>String</code> value of the Asset Class
255:             */
256:            public void setAssetClass(String clss) {
257:                assetClass = clss;
258:                fireModified();
259:            }
260:
261:            /**
262:             * Gets the UniqueID for this asset.
263:             * This field is only in Org Assets and
264:             * it is <b>REQUIRED</b>.
265:             *
266:             * @return a <code>String</code> value of the UniqueID
267:             */
268:            public String getUniqueID() {
269:                return uniqID;
270:            }
271:
272:            /**
273:             * Sets the UniqueID for this asset.
274:             * This field is only in Org Assets and
275:             * it is <b>REQUIRED</b>.
276:             *
277:             * @param uid a <code>String</code> value of the UniqueID
278:             */
279:            public void setUniqueID(String uid) {
280:                uniqID = uid;
281:                fireModified();
282:            }
283:
284:            /**
285:             * Gets the Unit name for this asset.
286:             * This field is only on Org assets, and it
287:             * is optional.
288:             *
289:             * @return a <code>String</code> value of the Unit Name
290:             */
291:            public String getUnitName() {
292:                return unitname;
293:            }
294:
295:            /**
296:             * Sets the unit name for this asset.
297:             * This field is only on Org assets, and it
298:             * is optional.
299:             *
300:             * @param unit a <code>String</code> value of the Unit Name
301:             */
302:            public void setUnitName(String unit) {
303:                unitname = unit;
304:                fireModified();
305:            }
306:
307:            /**
308:             * Gets the UIC for this asset.
309:             * Only Org assets have a UIC.
310:             *
311:             * @return a <code>String</code> value of the UIC
312:             */
313:            public String getUIC() {
314:                return (uic == null ? ((!isEntity()) && (getAgentID() != null) ? "UIC/"
315:                        + getAgentID()
316:                        : null)
317:                        : uic);
318:            }
319:
320:            /**
321:             * Sets the UIC for this asset.
322:             * Only Org assets have a UIC.
323:             *
324:             * @param uic a <code>String</code> value of the UIC
325:             */
326:            public void setUIC(String uic) {
327:                this .uic = uic;
328:                fireModified();
329:            }
330:
331:            // Add stuff to set the list of roles/relats/pgs, 
332:            // clear the list, add to the list, get the list, get by index
333:            // Add convenience methods to get/set values in the common PGs
334:
335:            /**
336:             * Sets all property groups for this Agent.  Any
337:             * previous property groups are removed before this
338:             * set takes place.
339:             *
340:             * @see PropGroupData
341:             * @param newPropgroups array of property groups
342:             */
343:            public void setPropGroups(PropGroupData[] newPropgroups) {
344:                propGroups.clear();
345:                for (int i = 0; i < newPropgroups.length; i++) {
346:                    propGroups.add(newPropgroups[i]);
347:                }
348:                fireModified();
349:            }
350:
351:            /**
352:             * Adds a property group for this Agent.  The
353:             * new property group is added to the end of
354:             * the list.
355:             *
356:             * @param propgroup property group to add
357:             */
358:            public void addPropertyGroup(PropGroupData propgroup) {
359:                this .propGroups.add(propgroup);
360:                fireModified();
361:            }
362:
363:            /**
364:             * Sets a property group for this Agent, 
365:             * replacing the previous PG at the specified index
366:             *
367:             * @param index for the Property Group
368:             * @param propgroup new Property Group for the specified index
369:             */
370:            public void setPropertyGroup(int index, PropGroupData propgroup)
371:                    throws IndexOutOfBoundsException {
372:                this .propGroups.set(index, propgroup);
373:                fireModified();
374:            }
375:
376:            /**
377:             * Returns an array of all property groups for this agent.
378:             *
379:             * @see PropGroupData
380:             * @return all property groups
381:             */
382:            public PropGroupData[] getPropGroups() {
383:                return (PropGroupData[]) propGroups
384:                        .toArray(new PropGroupData[propGroups.size()]);
385:            }
386:
387:            /**
388:             * Returns an <code>Iterator</code> of all property groups for this agent.
389:             *
390:             * @return <code>Iterator</code> of all property groups
391:             */
392:            public Iterator getPropGroupsIterator() {
393:                return propGroups.iterator();
394:            }
395:
396:            /**
397:             * Returns a count of all property groups for this agent.
398:             *
399:             * @return number of property groups
400:             */
401:            public int getPGCount() {
402:                return propGroups.size();
403:            }
404:
405:            ////////////////////////////
406:
407:            /**
408:             * Sets all roles for this Agent.  Any previous roles are deleted.
409:             *
410:             * @param newRoles array of role names
411:             */
412:            public void setRoles(String[] newRoles) {
413:                roles.clear();
414:                for (int i = 0; i < newRoles.length; i++) {
415:                    roles.add(newRoles[i]);
416:                }
417:                fireModified();
418:            }
419:
420:            /**
421:             * Adds a role for this Agent
422:             *
423:             * @param role new role to add
424:             */
425:            public void addRole(String role) {
426:                this .roles.add(role);
427:                fireModified();
428:            }
429:
430:            /**
431:             * Sets a role for this Agent, replacing the previous role at this index
432:             *
433:             * @param index for role
434:             * @param role to replace with
435:             */
436:            public void setRole(int index, String role)
437:                    throws IndexOutOfBoundsException {
438:                this .roles.set(index, role);
439:                fireModified();
440:            }
441:
442:            /**
443:             * Returns an array of all roles for this agent.
444:             *
445:             * @return all roles for this agent
446:             */
447:            public String[] getRoles() {
448:                return (String[]) roles.toArray(new String[roles.size()]);
449:            }
450:
451:            /**
452:             * Returns an <code>Iterator</code> of all roles for this agent.
453:             *
454:             * @return </code>Iterator</code> of all roles
455:             */
456:            public Iterator getRolesIterator() {
457:                return roles.iterator();
458:            }
459:
460:            /**
461:             * Returns a count of all roles for this agent.
462:             *
463:             * @return number of roles in this agent
464:             */
465:            public int getRoleCount() {
466:                return roles.size();
467:            }
468:
469:            /**
470:             * Sets the Relationship information for this agent.
471:             *
472:             * @see RelationshipData
473:             * @param relationships array of relationship objects.
474:             */
475:            public void setRelationshipData(RelationshipData[] relationships) {
476:                this .relats.clear();
477:                for (int i = 0; i < relationships.length; i++) {
478:                    this .relats.add(relationships[i]);
479:                }
480:                fireModified();
481:            }
482:
483:            /**
484:             * Adds a relationship for this Agent
485:             *
486:             * @see RelationshipData
487:             * @param relationship new relationship for this agent
488:             */
489:            public void addRelationship(RelationshipData relationship) {
490:                this .relats.add(relationship);
491:                fireModified();
492:            }
493:
494:            /**
495:             * Sets a relationship for this Agent, replacing the previous relationship
496:             * at this index.
497:             *
498:             * @see RelationshipData
499:             * @param index for new relationship
500:             * @param relationship new relationship
501:             */
502:            public void setRelationship(int index, RelationshipData relationship)
503:                    throws IndexOutOfBoundsException {
504:                this .relats.set(index, relationship);
505:                fireModified();
506:            }
507:
508:            /**
509:             * Gets a specific Relationship, based on an index, for this agent.
510:             *
511:             * @see RelationshipData
512:             * @param index Index of the relationship.
513:             * @return <code>RelationshipData</code> value from the given index
514:             */
515:            public RelationshipData getRelationship(int index) {
516:                return (RelationshipData) relats.get(index);
517:            }
518:
519:            /**
520:             * Returns a count of all relationships for this agent.
521:             *
522:             * @return number of relationships for this agent
523:             */
524:            public int getRelationshipCount() {
525:                return relats.size();
526:            }
527:
528:            /**
529:             * Returns an <code>Iterator</code> of all relationships for this agent.
530:             *
531:             * @return <code>Iterator</code> of all relationships
532:             */
533:            public Iterator getRelationshipIterator() {
534:                return relats.iterator();
535:            }
536:
537:            /**
538:             * Returns an array of <code>RelationshipData</code> for this agent.
539:             *
540:             * @see RelationshipData
541:             * @return <code>RelationshipData</code> array containing all relationships.
542:             */
543:            public RelationshipData[] getRelationshipData() {
544:                return (RelationshipData[]) relats
545:                        .toArray(new RelationshipData[relats.size()]);
546:            }
547:
548:            /**
549:             * Has this Component been modified by a recipe, requiring possible save?
550:             */
551:            public boolean isModified() {
552:                return modified;
553:            }
554:
555:            /**
556:             * The component has been modified from its initial state.
557:             * Mark it and all ancestors modified.
558:             **/
559:            public void fireModified() {
560:                // Problem: I only want to call this after the society generates
561:                // the CData, and before the recipes are applied....
562:
563:                // make this private?
564:
565:                // If this is already modified, so will the parents
566:                if (modified)
567:                    return;
568:                modified = true;
569:                // recurse _up_
570:                if (agent != null)
571:                    agent.fireModified();
572:            }
573:
574:            /**
575:             * The component has been saved. Mark it as saved.
576:             */
577:            public void resetModified() {
578:                modified = false;
579:            }
580:        } // end of AgentAssetData.java
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.